proxygen
folly::TestSSLServer Class Reference

#include <TestSSLServer.h>

Inheritance diagram for folly::TestSSLServer:
folly::TestSSLAsyncCacheServer

Public Member Functions

 TestSSLServer (SSLServerAcceptCallbackBase *acb, bool enableTFO=false)
 
 TestSSLServer (SSLServerAcceptCallbackBase *acb, std::shared_ptr< SSLContext > ctx, bool enableTFO=false)
 
virtual ~TestSSLServer ()
 
EventBasegetEventBase ()
 
void loadTestCerts ()
 
const SocketAddressgetAddress () const
 

Protected Attributes

EventBase evb_
 
std::shared_ptr< SSLContextctx_
 
SSLServerAcceptCallbackBaseacb_
 
std::shared_ptr< AsyncServerSocketsocket_
 
SocketAddress address_
 
std::thread thread_
 

Private Member Functions

void init (bool)
 

Detailed Description

Definition at line 101 of file TestSSLServer.h.

Constructor & Destructor Documentation

folly::TestSSLServer::TestSSLServer ( SSLServerAcceptCallbackBase acb,
bool  enableTFO = false 
)
explicit

Definition at line 36 of file TestSSLServer.cpp.

References ctx_, and init().

37  : acb_(acb) {
38  // Set up a default SSL context
39  ctx_ = std::make_shared<SSLContext>();
40  ctx_->loadCertificate(kTestCert);
41  ctx_->loadPrivateKey(kTestKey);
42  ctx_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
43 
44  init(enableTFO);
45 }
const char * kTestCert
const char * kTestKey
SSLServerAcceptCallbackBase * acb_
std::shared_ptr< SSLContext > ctx_
folly::TestSSLServer::TestSSLServer ( SSLServerAcceptCallbackBase acb,
std::shared_ptr< SSLContext ctx,
bool  enableTFO = false 
)
explicit

Definition at line 52 of file TestSSLServer.cpp.

References init().

56  : ctx_(ctx), acb_(acb) {
57  init(enableTFO);
58 }
SSLServerAcceptCallbackBase * acb_
std::shared_ptr< SSLContext > ctx_
folly::TestSSLServer::~TestSSLServer ( )
virtual

Definition at line 28 of file TestSSLServer.cpp.

References evb_, folly::INFO, folly::EventBase::runInEventBaseThread(), socket_, and thread_.

28  {
29  if (thread_.joinable()) {
30  evb_.runInEventBaseThread([&]() { socket_->stopAccepting(); });
31  LOG(INFO) << "Waiting for server thread to exit";
32  thread_.join();
33  }
34 }
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
std::shared_ptr< AsyncServerSocket > socket_

Member Function Documentation

const SocketAddress& folly::TestSSLServer::getAddress ( ) const
inline

Definition at line 122 of file TestSSLServer.h.

Referenced by folly::TEST().

122  {
123  return address_;
124  }
SocketAddress address_
EventBase& folly::TestSSLServer::getEventBase ( )
inline

Definition at line 116 of file TestSSLServer.h.

References evb_.

Referenced by folly::TEST().

116  {
117  return evb_;
118  }
void folly::TestSSLServer::init ( bool  enableTFO)
private

Definition at line 60 of file TestSSLServer.cpp.

References acb_, address_, folly::SSLServerAcceptCallbackBase::base_, folly::SSLServerAcceptCallbackBase::ctx_, ctx_, folly::SSLServerAcceptCallbackBase::detach(), evb_, folly::INFO, folly::EventBase::loop(), folly::AsyncServerSocket::newSocket(), socket_, and thread_.

Referenced by TestSSLServer().

60  {
62 
63  acb_->ctx_ = ctx_;
64  acb_->base_ = &evb_;
65 
66  // Enable TFO
67  if (enableTFO) {
68  LOG(INFO) << "server TFO enabled";
69  socket_->setTFOEnabled(true, 1000);
70  }
71 
72  // set up the listening socket
73  socket_->bind(0);
74  socket_->getAddress(&address_);
75  socket_->listen(100);
76  socket_->addAcceptCallback(acb_, &evb_);
77  socket_->startAccepting();
78 
79  thread_ = std::thread([&] {
80  evb_.loop();
81  acb_->detach();
82  LOG(INFO) << "Server thread exited event loop";
83  });
84  LOG(INFO) << "Accepting connections on " << address_;
85 }
SSLServerAcceptCallbackBase * acb_
std::shared_ptr< SSLContext > ctx_
std::shared_ptr< AsyncServerSocket > socket_
static std::shared_ptr< AsyncServerSocket > newSocket(EventBase *evb=nullptr)
SocketAddress address_
std::shared_ptr< SSLContext > ctx_
Definition: TestSSLServer.h:96
void folly::TestSSLServer::loadTestCerts ( )

Definition at line 47 of file TestSSLServer.cpp.

References ctx_.

47  {
48  ctx_->loadCertificate(kTestCert);
49  ctx_->loadPrivateKey(kTestKey);
50 }
const char * kTestCert
const char * kTestKey
std::shared_ptr< SSLContext > ctx_

Member Data Documentation

SSLServerAcceptCallbackBase* folly::TestSSLServer::acb_
protected

Definition at line 129 of file TestSSLServer.h.

Referenced by init().

SocketAddress folly::TestSSLServer::address_
protected

Definition at line 131 of file TestSSLServer.h.

Referenced by init().

std::shared_ptr<SSLContext> folly::TestSSLServer::ctx_
protected

Definition at line 128 of file TestSSLServer.h.

Referenced by init(), loadTestCerts(), and TestSSLServer().

EventBase folly::TestSSLServer::evb_
protected

Definition at line 127 of file TestSSLServer.h.

Referenced by init(), and ~TestSSLServer().

std::shared_ptr<AsyncServerSocket> folly::TestSSLServer::socket_
protected

Definition at line 130 of file TestSSLServer.h.

Referenced by init(), and ~TestSSLServer().

std::thread folly::TestSSLServer::thread_
protected

Definition at line 132 of file TestSSLServer.h.

Referenced by init(), and ~TestSSLServer().


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