proxygen
wangle::ServerAcceptor< Pipeline > Class Template Reference

#include <ServerBootstrap-inl.h>

Inheritance diagram for wangle::ServerAcceptor< Pipeline >:
wangle::Acceptor wangle::InboundHandler< AcceptPipelineType > folly::AsyncServerSocket::AcceptCallback wangle::ConnectionManager::Callback folly::AsyncUDPServerSocket::Callback wangle::HandlerBase< InboundHandlerContext< AcceptPipelineType > >

Classes

class  ServerConnection
 

Public Member Functions

 ServerAcceptor (std::shared_ptr< AcceptPipelineFactory > acceptPipelineFactory, std::shared_ptr< PipelineFactory< Pipeline >> childPipelineFactory, const ServerSocketConfig &accConfig)
 
void init (folly::AsyncServerSocket *serverSocket, folly::EventBase *eventBase, SSLStats *stats=nullptr) override
 
void read (Context *, AcceptPipelineType conn) override
 
void readEOF (Context *) override
 
void readException (Context *, folly::exception_wrapper) override
 
void onNewConnection (folly::AsyncTransportWrapper::UniquePtr transport, const folly::SocketAddress *clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, const TransportInfo &tinfo) override
 
void acceptStopped () noexceptoverride
 
void drainConnections (double pct) noexceptoverride
 
void dropConnections (double pct) noexceptoverride
 
void forceStop () noexceptoverride
 
void onDataAvailable (std::shared_ptr< folly::AsyncUDPSocket > socket, const folly::SocketAddress &addr, std::unique_ptr< folly::IOBuf > buf, bool) noexceptoverride
 
void onConnectionAdded (const ManagedConnection *) override
 
void onConnectionRemoved (const ManagedConnection *) override
 
void sslConnectionError (const folly::exception_wrapper &ex) override
 
- Public Member Functions inherited from wangle::Acceptor
 Acceptor (const ServerSocketConfig &accConfig)
 
 ~Acceptor () override
 
virtual void setSSLCacheProvider (const std::shared_ptr< SSLCacheProvider > &cacheProvider)
 
virtual void resetSSLContextConfigs ()
 
void addSSLContextConfig (const SSLContextConfig &sslCtxConfig)
 
SSLContextManagergetSSLContextManager () const
 
virtual void setTLSTicketSecrets (const std::vector< std::string > &oldSecrets, const std::vector< std::string > &currentSecrets, const std::vector< std::string > &newSecrets)
 
uint32_t getNumConnections () const
 
virtual folly::EventBasegetEventBase () const
 
virtual wangle::ConnectionManagergetConnectionManager ()
 
void addConnection (wangle::ManagedConnection *connection)
 
State getState () const
 
std::chrono::milliseconds getConnTimeout () const
 
const std::stringgetName () const
 
std::chrono::milliseconds getSSLHandshakeTimeout () const
 
void setGracefulShutdownTimeout (std::chrono::milliseconds gracefulShutdown)
 
std::chrono::milliseconds getGracefulShutdownTimeout () const
 
bool isSSL () const
 
const ServerSocketConfiggetConfig () const
 
virtual void onDoneAcceptingConnection (int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime) noexcept
 
void processEstablishedConnection (int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
 
virtual void startHandshakeManager (folly::AsyncSSLSocket::UniquePtr sslSock, Acceptor *acceptor, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
 
void drainAllConnections ()
 
void dropAllConnections ()
 
virtual void plaintextConnectionReady (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
 
void connectionReady (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
 
virtual void sslConnectionReady (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocol, SecureTransportType secureTransportType, TransportInfo &tinfo)
 
virtual void updateSSLStats (const folly::AsyncTransportWrapper *, std::chrono::milliseconds, SSLErrorEnum) noexcept
 
- Public Member Functions inherited from folly::AsyncServerSocket::AcceptCallback
virtual ~AcceptCallback ()=default
 
virtual void acceptStarted () noexcept
 
- Public Member Functions inherited from wangle::ConnectionManager::Callback
virtual ~Callback ()=default
 
- Public Member Functions inherited from folly::AsyncUDPServerSocket::Callback
virtual void onListenPaused () noexcept
 
virtual void onListenResumed () noexcept
 
virtual ~Callback ()=default
 
- Public Member Functions inherited from wangle::InboundHandler< AcceptPipelineType >
 ~InboundHandler () override=default
 
virtual void transportActive (Context *ctx)
 
virtual void transportInactive (Context *ctx)
 
- Public Member Functions inherited from wangle::HandlerBase< InboundHandlerContext< AcceptPipelineType > >
virtual ~HandlerBase ()=default
 
virtual void attachPipeline (InboundHandlerContext< AcceptPipelineType > *)
 
virtual void detachPipeline (InboundHandlerContext< AcceptPipelineType > *)
 
InboundHandlerContext< AcceptPipelineType > * getContext ()
 

Private Attributes

std::shared_ptr< AcceptPipelineFactoryacceptPipelineFactory_
 
std::shared_ptr< AcceptPipelineacceptPipeline_
 
std::shared_ptr< PipelineFactory< Pipeline > > childPipelineFactory_
 

Additional Inherited Members

- Public Types inherited from wangle::Acceptor
enum  State : uint32_t { State::kInit, State::kRunning, State::kDraining, State::kDone }
 
- Public Types inherited from wangle::InboundHandler< AcceptPipelineType >
typedef AcceptPipelineType rin
 
typedef AcceptPipelineType rout
 
typedef folly::Unit win
 
typedef folly::Unit wout
 
typedef InboundHandlerContext< AcceptPipelineTypeContext
 
- Static Public Member Functions inherited from wangle::Acceptor
static uint64_t getTotalNumPendingSSLConns ()
 
- Static Public Attributes inherited from wangle::InboundHandler< AcceptPipelineType >
static const HandlerDir dir
 
- Protected Member Functions inherited from wangle::Acceptor
virtual uint64_t getConnectionCountForLoadShedding (void) const
 
virtual uint64_t getActiveConnectionCountForLoadShedding () const
 
virtual uint64_t getWorkerMaxConnections () const
 
virtual bool canAccept (const folly::SocketAddress &)
 
void onListenStarted () noexceptoverride
 
void onListenStopped () noexceptoverride
 
virtual folly::AsyncSocket::UniquePtr makeNewAsyncSocket (folly::EventBase *base, int fd)
 
virtual folly::AsyncSSLSocket::UniquePtr makeNewAsyncSSLSocket (const std::shared_ptr< folly::SSLContext > &ctx, folly::EventBase *base, int fd)
 
virtual void onConnectionsDrained ()
 
void connectionAccepted (int fd, const folly::SocketAddress &clientAddr) noexceptoverride
 
void acceptError (const std::exception &ex) noexceptoverride
 
void onEmpty (const wangle::ConnectionManager &cm) override
 
void setLoadShedConfig (std::shared_ptr< const LoadShedConfiguration > loadShedConfig, const IConnectionCounter *counter)
 
virtual void initDownstreamConnectionManager (folly::EventBase *eventBase)
 
virtual DefaultToFizzPeekingCallbackgetFizzPeeker ()
 
virtual std::shared_ptr< fizz::server::FizzServerContextcreateFizzContext ()
 
virtual std::shared_ptr< fizz::server::TicketCiphercreateFizzTicketCipher (folly::Optional< std::string >=folly::none)
 
void updateFizzContext (fizz::server::FizzServerContext *)
 
- Protected Attributes inherited from wangle::Acceptor
folly::EventBasebase_ {nullptr}
 
const ServerSocketConfig accConfig_
 
folly::AsyncSocket::OptionMap socketOptions_
 
std::unique_ptr< SSLContextManagersslCtxManager_
 
SecurityProtocolContextManager securityProtocolCtxManager_
 
TLSPlaintextPeekingCallback tlsPlaintextPeekingCallback_
 
DefaultToSSLPeekingCallback defaultPeekingCallback_
 
DefaultToFizzPeekingCallback defaultFizzPeeker_
 
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
 
std::shared_ptr< SSLCacheProvidercacheProvider_
 
wangle::TLSTicketKeySeeds currentSecrets_
 

Detailed Description

template<typename Pipeline>
class wangle::ServerAcceptor< Pipeline >

Definition at line 65 of file ServerBootstrap-inl.h.

Constructor & Destructor Documentation

template<typename Pipeline >
wangle::ServerAcceptor< Pipeline >::ServerAcceptor ( std::shared_ptr< AcceptPipelineFactory acceptPipelineFactory,
std::shared_ptr< PipelineFactory< Pipeline >>  childPipelineFactory,
const ServerSocketConfig accConfig 
)
inlineexplicit

Definition at line 116 of file ServerBootstrap-inl.h.

120  : Acceptor(accConfig),
121  acceptPipelineFactory_(acceptPipelineFactory),
122  childPipelineFactory_(childPipelineFactory) {
123  }
std::shared_ptr< AcceptPipelineFactory > acceptPipelineFactory_
Acceptor(const ServerSocketConfig &accConfig)
Definition: Acceptor.cpp:54
std::shared_ptr< PipelineFactory< Pipeline > > childPipelineFactory_

Member Function Documentation

template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::acceptStopped ( )
inlineoverridevirtualnoexcept

acceptStopped() will be called when this AcceptCallback is removed from the AsyncServerSocket, or when the AsyncServerSocket is destroyed, whichever occurs first.

No more calls to connectionAccepted() or acceptError() will be made after acceptStopped() is invoked.

Reimplemented from wangle::Acceptor.

Definition at line 185 of file ServerBootstrap-inl.h.

References wangle::AcceptorException::ACCEPT_STOPPED, and wangle::Acceptor::acceptStopped().

185  {
186  auto ew = folly::make_exception_wrapper<AcceptorException>(
188  "graceful shutdown timeout");
189 
190  acceptPipeline_->readException(ew);
192  }
void acceptStopped() noexceptoverride
Definition: Acceptor.cpp:441
std::shared_ptr< AcceptPipeline > acceptPipeline_
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::drainConnections ( double  pctToDrain)
inlineoverridevirtualnoexcept

Drain defined percentage of connections.

Reimplemented from wangle::Acceptor.

Definition at line 194 of file ServerBootstrap-inl.h.

References wangle::AcceptorException::DRAIN_CONN_PCT, and wangle::Acceptor::drainConnections().

194  {
195  auto ew = folly::make_exception_wrapper<AcceptorException>(
197  "draining some connections", pct);
198 
199  acceptPipeline_->readException(ew);
201  }
virtual void drainConnections(double pctToDrain)
Definition: Acceptor.cpp:485
std::shared_ptr< AcceptPipeline > acceptPipeline_
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::dropConnections ( double  pctToDrop)
inlineoverridevirtualnoexcept

Force-drop "pct" (0.0 to 1.0) of remaining client connections, regardless of whether they are busy or idle.

Note: unlike dropAllConnections(), this function can be called from any thread.

Reimplemented from wangle::Acceptor.

Definition at line 203 of file ServerBootstrap-inl.h.

References wangle::AcceptorException::DROP_CONN_PCT, and wangle::Acceptor::dropConnections().

203  {
204  auto ew = folly::make_exception_wrapper<AcceptorException>(
206  "dropping some connections", pct);
207 
208  acceptPipeline_->readException(ew);
210  }
virtual void dropConnections(double pctToDrop)
Definition: Acceptor.cpp:530
std::shared_ptr< AcceptPipeline > acceptPipeline_
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::forceStop ( )
inlineoverridevirtualnoexcept

Force the acceptor to drop all connections and stop processing.

This function may be called from any thread. The acceptor will not necessarily stop before this function returns: the stop will be scheduled to run in the acceptor's thread.

Reimplemented from wangle::Acceptor.

Definition at line 212 of file ServerBootstrap-inl.h.

References wangle::AcceptorException::FORCE_STOP, and wangle::Acceptor::forceStop().

212  {
213  auto ew = folly::make_exception_wrapper<AcceptorException>(
215  "hard shutdown timeout");
216 
217  acceptPipeline_->readException(ew);
219  }
virtual void forceStop()
Definition: Acceptor.cpp:508
std::shared_ptr< AcceptPipeline > acceptPipeline_
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::init ( folly::AsyncServerSocket serverSocket,
folly::EventBase eventBase,
SSLStats stats = nullptr 
)
inlineoverridevirtual

Initialize the Acceptor to run in the specified EventBase thread, receiving connections from the specified AsyncServerSocket.

This method will be called from the AsyncServerSocket's primary thread, not the specified EventBase thread.

Reimplemented from wangle::Acceptor.

Definition at line 125 of file ServerBootstrap-inl.h.

References wangle::Acceptor::init().

127  {
128  Acceptor::init(serverSocket, eventBase, stats);
129 
130  acceptPipeline_ = acceptPipelineFactory_->newPipeline(this);
131 
132  if (childPipelineFactory_) {
133  // This means a custom AcceptPipelineFactory was not passed in via
134  // pipeline() and we're using the DefaultAcceptPipelineFactory.
135  // Add the default inbound handler here.
136  acceptPipeline_->addBack(this);
137  }
138  acceptPipeline_->finalize();
139  }
std::shared_ptr< AcceptPipelineFactory > acceptPipelineFactory_
std::shared_ptr< PipelineFactory< Pipeline > > childPipelineFactory_
std::shared_ptr< AcceptPipeline > acceptPipeline_
virtual void init(folly::AsyncServerSocket *serverSocket, folly::EventBase *eventBase, SSLStats *stats=nullptr)
Definition: Acceptor.cpp:60
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::onConnectionAdded ( const ManagedConnection conn)
inlineoverridevirtual

Invoked when a connection is added to the ConnectionManager.

Reimplemented from wangle::Acceptor.

Definition at line 230 of file ServerBootstrap-inl.h.

References wangle::CONN_ADDED.

230  {
232  }
std::shared_ptr< AcceptPipeline > acceptPipeline_
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::onConnectionRemoved ( const ManagedConnection conn)
inlineoverridevirtual

Invoked when a connection is removed from the ConnectionManager.

Reimplemented from wangle::Acceptor.

Definition at line 234 of file ServerBootstrap-inl.h.

References wangle::CONN_REMOVED.

234  {
236  }
std::shared_ptr< AcceptPipeline > acceptPipeline_
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::onDataAvailable ( std::shared_ptr< folly::AsyncUDPSocket socket,
const folly::SocketAddress addr,
std::unique_ptr< folly::IOBuf buf,
bool  truncated 
)
inlineoverridevirtualnoexcept

Invoked when a new packet is received

Reimplemented from wangle::Acceptor.

Definition at line 222 of file ServerBootstrap-inl.h.

References addr, std::tr1::make_tuple(), and folly::netops::socket().

225  {
226  acceptPipeline_->read(
227  AcceptPipelineType(make_tuple(buf.release(), socket, addr)));
228  }
boost::variant< folly::IOBuf *, folly::AsyncTransportWrapper *, ConnInfo &, ConnEvent, std::tuple< folly::IOBuf *, std::shared_ptr< folly::AsyncUDPSocket >, folly::SocketAddress > > AcceptPipelineType
Definition: Pipeline.h:277
tuple make_tuple()
Definition: gtest-tuple.h:675
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
std::shared_ptr< AcceptPipeline > acceptPipeline_
ThreadPoolListHook * addr
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::onNewConnection ( folly::AsyncTransportWrapper::UniquePtr  ,
const folly::SocketAddress ,
const std::string ,
SecureTransportType  ,
const TransportInfo  
)
inlineoverridevirtual

Invoked when a new connection is created. This is where application starts processing a new downstream connection.

NOTE: Application should add the new connection to downstreamConnectionManager so that it can be garbage collected after certain period of idleness.

Parameters
sockthe socket connected to the client
addressthe address of the client
nextProtocolNamethe name of the L6 or L7 protocol to be spoken on the connection, if known (e.g., from TLS NPN during secure connection setup), or an empty string if unknown
secureTransportTypethe name of the secure transport type that was requested by the client.

Reimplemented from wangle::Acceptor.

Definition at line 174 of file ServerBootstrap-inl.h.

178  {
179  ConnInfo connInfo = {transport.release(), clientAddr, nextProtocolName,
180  secureTransportType, tinfo};
181  acceptPipeline_->read(connInfo);
182  }
TotalRequest HTTPRequestExchange HTTPResponseBodyRead PreConnect PostConnect DNSResolution DNSCache RetryingDNSResolution TCPConnect TLSSetup TotalConnect decompression_filter cert_verification proxy_connect push scheduling network_change multi_connector single_connector SessionTransactions TCPInfo ConnInfo
std::shared_ptr< AcceptPipeline > acceptPipeline_
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::read ( Context ,
AcceptPipelineType  conn 
)
inlineoverridevirtual

Implements wangle::InboundHandler< AcceptPipelineType >.

Definition at line 141 of file ServerBootstrap-inl.h.

References wangle::Acceptor::addConnection(), and folly::gen::move.

141  {
142  if (conn.type() != typeid(ConnInfo&)) {
143  return;
144  }
145 
146  auto connInfo = boost::get<ConnInfo&>(conn);
147  folly::AsyncTransportWrapper::UniquePtr transport(connInfo.sock);
148 
149  // Setup local and remote addresses
150  auto tInfoPtr = std::make_shared<TransportInfo>(connInfo.tinfo);
151  tInfoPtr->localAddr =
152  std::make_shared<folly::SocketAddress>(accConfig_.bindAddress);
153  transport->getLocalAddress(tInfoPtr->localAddr.get());
154  tInfoPtr->remoteAddr =
155  std::make_shared<folly::SocketAddress>(*connInfo.clientAddr);
156  tInfoPtr->appProtocol =
157  std::make_shared<std::string>(connInfo.nextProtoName);
158 
159  auto pipeline = childPipelineFactory_->newPipeline(
160  std::shared_ptr<folly::AsyncTransportWrapper>(
161  transport.release(), folly::DelayedDestruction::Destructor()));
162  pipeline->setTransportInfo(tInfoPtr);
163  auto connection = new ServerConnection(std::move(pipeline));
164  Acceptor::addConnection(connection);
165  connection->init();
166  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TotalRequest HTTPRequestExchange HTTPResponseBodyRead PreConnect PostConnect DNSResolution DNSCache RetryingDNSResolution TCPConnect TLSSetup TotalConnect decompression_filter cert_verification proxy_connect push scheduling network_change multi_connector single_connector SessionTransactions TCPInfo ConnInfo
folly::SocketAddress bindAddress
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
std::shared_ptr< PipelineFactory< Pipeline > > childPipelineFactory_
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
void addConnection(wangle::ManagedConnection *connection)
Definition: Acceptor.cpp:501
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::readEOF ( Context )
inlineoverridevirtual

Reimplemented from wangle::InboundHandler< AcceptPipelineType >.

Definition at line 170 of file ServerBootstrap-inl.h.

170 {}
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::readException ( Context ,
folly::exception_wrapper   
)
inlineoverridevirtual

Reimplemented from wangle::InboundHandler< AcceptPipelineType >.

Definition at line 171 of file ServerBootstrap-inl.h.

171 {}
template<typename Pipeline >
void wangle::ServerAcceptor< Pipeline >::sslConnectionError ( const folly::exception_wrapper ex)
inlineoverridevirtual

Notification callback for SSL handshake failures.

Reimplemented from wangle::Acceptor.

Definition at line 238 of file ServerBootstrap-inl.h.

References wangle::Acceptor::sslConnectionError().

238  {
239  acceptPipeline_->readException(ex);
241  }
virtual void sslConnectionError(const folly::exception_wrapper &ex)
Definition: Acceptor.cpp:422
std::shared_ptr< AcceptPipeline > acceptPipeline_

Member Data Documentation

template<typename Pipeline >
std::shared_ptr<AcceptPipeline> wangle::ServerAcceptor< Pipeline >::acceptPipeline_
private

Definition at line 245 of file ServerBootstrap-inl.h.

template<typename Pipeline >
std::shared_ptr<AcceptPipelineFactory> wangle::ServerAcceptor< Pipeline >::acceptPipelineFactory_
private

Definition at line 244 of file ServerBootstrap-inl.h.

template<typename Pipeline >
std::shared_ptr<PipelineFactory<Pipeline> > wangle::ServerAcceptor< Pipeline >::childPipelineFactory_
private

Definition at line 246 of file ServerBootstrap-inl.h.


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