proxygen
SSLCacheClient Class Reference
Inheritance diagram for SSLCacheClient:
folly::AsyncSocket::ConnectCallback folly::AsyncSSLSocket::HandshakeCB

Public Member Functions

 SSLCacheClient (EventBase *eventBase, SSL_SESSION **pSess, ClientRunner *cr)
 
 ~SSLCacheClient () override
 
void start ()
 
void connectSuccess () noexceptoverride
 
void connectErr (const AsyncSocketException &ex) noexceptoverride
 
void handshakeSuc (AsyncSSLSocket *sock) noexceptoverride
 
void handshakeErr (AsyncSSLSocket *sock, const AsyncSocketException &ex) noexceptoverride
 
- Public Member Functions inherited from folly::AsyncSocket::ConnectCallback
virtual ~ConnectCallback ()=default
 
- Public Member Functions inherited from folly::AsyncSSLSocket::HandshakeCB
virtual ~HandshakeCB ()=default
 
virtual bool handshakeVer (AsyncSSLSocket *, bool preverifyOk, X509_STORE_CTX *) noexcept
 

Private Attributes

EventBaseeventBase_
 
int currReq_
 
int serverIdx_
 
AsyncSocketsocket_
 
AsyncSSLSocketsslSocket_
 
SSL_SESSION * session_
 
SSL_SESSION ** pSess_
 
std::shared_ptr< SSLContextctx_
 
ClientRunnercr_
 

Detailed Description

Definition at line 52 of file SSLCacheTest.cpp.

Constructor & Destructor Documentation

SSLCacheClient::SSLCacheClient ( EventBase eventBase,
SSL_SESSION **  pSess,
ClientRunner cr 
)

Definition at line 182 of file SSLCacheTest.cpp.

References ctx_.

185  : eventBase_(eb),
186  currReq_(0),
187  serverIdx_(0),
188  socket_(nullptr),
189  sslSocket_(nullptr),
190  session_(nullptr),
191  pSess_(pSess),
192  cr_(cr)
193 {
194  ctx_.reset(new SSLContext());
195  ctx_->setOptions(SSL_OP_NO_TICKET);
196 }
std::shared_ptr< SSLContext > ctx_
SSL_SESSION * session_
SSL_SESSION ** pSess_
EventBase * eventBase_
AsyncSocket * socket_
ClientRunner * cr_
AsyncSSLSocket * sslSocket_
SSLCacheClient::~SSLCacheClient ( )
inlineoverride

Definition at line 68 of file SSLCacheTest.cpp.

References folly::AsyncSocket::destroy(), folly::pushmi::__adl::noexcept(), and start.

68  {
69  if (session_ && !FLAGS_global)
70  SSL_SESSION_free(session_);
71  if (socket_ != nullptr) {
72  if (sslSocket_ != nullptr) {
74  sslSocket_ = nullptr;
75  }
76  socket_->destroy();
77  socket_ = nullptr;
78  }
79  }
SSL_SESSION * session_
void destroy() override
AsyncSocket * socket_
AsyncSSLSocket * sslSocket_

Member Function Documentation

void SSLCacheClient::connectErr ( const AsyncSocketException ex)
overridevirtualnoexcept

connectErr() will be invoked if the connection attempt fails.

Parameters
exAn exception describing the error that occurred.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 237 of file SSLCacheTest.cpp.

239 {
240  cout << "connectError: " << ex.what() << endl;
241 }
void SSLCacheClient::connectSuccess ( )
overridevirtualnoexcept

connectSuccess() will be invoked when the connection has been successfully established.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 222 of file SSLCacheTest.cpp.

References ctx_, folly::AsyncSocket::detachFd(), eventBase_, pSess_, session_, folly::AsyncSSLSocket::setSSLSession(), socket_, folly::AsyncSSLSocket::sslConn(), and sslSocket_.

223 {
225  false);
226 
227  if (!FLAGS_handshakes) {
228  if (session_ != nullptr)
230  else if (FLAGS_global && pSess_ != nullptr)
232  }
233  sslSocket_->sslConn(this);
234 }
virtual int detachFd()
std::shared_ptr< SSLContext > ctx_
virtual void sslConn(HandshakeCB *callback, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero(), const folly::SSLContext::SSLVerifyPeerEnum &verifyPeer=folly::SSLContext::SSLVerifyPeerEnum::USE_CTX)
SSL_SESSION * session_
SSL_SESSION ** pSess_
EventBase * eventBase_
AsyncSocket * socket_
void setSSLSession(SSL_SESSION *session, bool takeOwnership=false)
AsyncSSLSocket * sslSocket_
void SSLCacheClient::handshakeErr ( AsyncSSLSocket sock,
const AsyncSocketException ex 
)
overridevirtualnoexcept

handshakeErr() is called if an error occurs while establishing the SSL connection.

The HandshakeCB will be uninstalled before handshakeErr() is called.

Parameters
sockSSL socket on which the handshake was initiated
exAn exception representing the error.

Implements folly::AsyncSSLSocket::HandshakeCB.

Definition at line 268 of file SSLCacheTest.cpp.

272 {
273  cout << "handshakeError: " << ex.what() << endl;
274 }
void SSLCacheClient::handshakeSuc ( AsyncSSLSocket sock)
overridevirtualnoexcept

handshakeSuc() is called when a new SSL connection is established, i.e., after SSL_accept/connect() returns successfully.

The HandshakeCB will be uninstalled before handshakeSuc() is called.

Parameters
sockSSL socket on which the handshake was initiated

Implements folly::AsyncSSLSocket::HandshakeCB.

Definition at line 244 of file SSLCacheTest.cpp.

References folly::AsyncSSLSocket::closeNow(), cr_, currReq_, folly::AsyncSSLSocket::getSSLSession(), folly::AsyncSSLSocket::getSSLSessionReused(), ClientRunner::hits, ClientRunner::miss, ClientRunner::num, pSess_, session_, sslSocket_, and start().

245 {
247  cr_->hits++;
248  } else {
249  cr_->miss++;
250  if (session_ != nullptr) {
251  SSL_SESSION_free(session_);
252  }
254  if (FLAGS_global && pSess_ != nullptr && *pSess_ == nullptr) {
255  *pSess_ = session_;
256  }
257  }
258  if ( ((cr_->hits + cr_->miss) % 100) == ((100 / FLAGS_threads) * cr_->num)) {
259  cout << ".";
260  cout.flush();
261  }
262  sslSocket_->closeNow();
263  currReq_++;
264  this->start();
265 }
SSL_SESSION * session_
SSL_SESSION ** pSess_
virtual bool getSSLSessionReused() const
ClientRunner * cr_
SSL_SESSION * getSSLSession()
AsyncSSLSocket * sslSocket_
void closeNow() override
void SSLCacheClient::start ( )

Definition at line 199 of file SSLCacheTest.cpp.

References folly::AsyncSocket::connect(), currReq_, folly::AsyncSocket::destroy(), eventBase_, f_num_servers, f_servers, serverIdx_, socket_, sslSocket_, and uint16_t.

Referenced by handshakeSuc(), and ClientRunner::run().

200 {
201  if (currReq_ >= FLAGS_requests) {
202  cout << "+";
203  return;
204  }
205 
206  if (currReq_ == 0 || !FLAGS_sticky) {
207  serverIdx_ = rand() % f_num_servers;
208  }
209  if (socket_ != nullptr) {
210  if (sslSocket_ != nullptr) {
211  sslSocket_->destroy();
212  sslSocket_ = nullptr;
213  }
214  socket_->destroy();
215  socket_ = nullptr;
216  }
218  socket_->connect(this, f_servers[serverIdx_], (uint16_t)FLAGS_port);
219 }
string f_servers[10]
int f_num_servers
virtual void connect(ConnectCallback *callback, const folly::SocketAddress &address, int timeout=0, const OptionMap &options=emptyOptionMap, const folly::SocketAddress &bindAddr=anyAddress()) noexcept
void destroy() override
EventBase * eventBase_
AsyncSocket * socket_
AsyncSSLSocket * sslSocket_

Member Data Documentation

ClientRunner* SSLCacheClient::cr_
private

Definition at line 64 of file SSLCacheTest.cpp.

Referenced by handshakeSuc().

std::shared_ptr<SSLContext> SSLCacheClient::ctx_
private

Definition at line 63 of file SSLCacheTest.cpp.

Referenced by connectSuccess(), and SSLCacheClient().

int SSLCacheClient::currReq_
private

Definition at line 57 of file SSLCacheTest.cpp.

Referenced by handshakeSuc(), and start().

EventBase* SSLCacheClient::eventBase_
private

Definition at line 56 of file SSLCacheTest.cpp.

Referenced by connectSuccess(), and start().

SSL_SESSION** SSLCacheClient::pSess_
private

Definition at line 62 of file SSLCacheTest.cpp.

Referenced by connectSuccess(), and handshakeSuc().

int SSLCacheClient::serverIdx_
private

Definition at line 58 of file SSLCacheTest.cpp.

Referenced by start().

SSL_SESSION* SSLCacheClient::session_
private

Definition at line 61 of file SSLCacheTest.cpp.

Referenced by connectSuccess(), and handshakeSuc().

AsyncSocket* SSLCacheClient::socket_
private

Definition at line 59 of file SSLCacheTest.cpp.

Referenced by connectSuccess(), and start().

AsyncSSLSocket* SSLCacheClient::sslSocket_
private

Definition at line 60 of file SSLCacheTest.cpp.

Referenced by connectSuccess(), handshakeSuc(), and start().


The documentation for this class was generated from the following file: