proxygen
wangle::Acceptor Class Reference

#include <Acceptor.h>

Inheritance diagram for wangle::Acceptor:
folly::AsyncServerSocket::AcceptCallback wangle::ConnectionManager::Callback folly::AsyncUDPServerSocket::Callback proxygen::HTTPAcceptor TestAcceptor TestAcceptor wangle::ServerAcceptor< Pipeline > wangle::TestableAcceptor proxygen::HTTPSessionAcceptor HTTPTargetSessionAcceptor proxygen::HTTPServerAcceptor

Public Types

enum  State : uint32_t { State::kInit, State::kRunning, State::kDraining, State::kDone }
 

Public Member Functions

 Acceptor (const ServerSocketConfig &accConfig)
 
 ~Acceptor () override
 
virtual void setSSLCacheProvider (const std::shared_ptr< SSLCacheProvider > &cacheProvider)
 
virtual void init (folly::AsyncServerSocket *serverSocket, folly::EventBase *eventBase, SSLStats *stats=nullptr)
 
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
 
virtual void forceStop ()
 
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 ()
 
virtual void drainConnections (double pctToDrain)
 
void dropAllConnections ()
 
virtual void dropConnections (double pctToDrop)
 
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 sslConnectionError (const folly::exception_wrapper &ex)
 
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
 

Static Public Member Functions

static uint64_t getTotalNumPendingSSLConns ()
 

Protected Member Functions

virtual uint64_t getConnectionCountForLoadShedding (void) const
 
virtual uint64_t getActiveConnectionCountForLoadShedding () const
 
virtual uint64_t getWorkerMaxConnections () const
 
virtual bool canAccept (const folly::SocketAddress &)
 
virtual void onNewConnection (folly::AsyncTransportWrapper::UniquePtr, const folly::SocketAddress *, const std::string &, SecureTransportType, const TransportInfo &)
 
void onListenStarted () noexceptoverride
 
void onListenStopped () noexceptoverride
 
void onDataAvailable (std::shared_ptr< folly::AsyncUDPSocket >, const folly::SocketAddress &, std::unique_ptr< folly::IOBuf >, bool) 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 acceptStopped () noexceptoverride
 
void onEmpty (const wangle::ConnectionManager &cm) override
 
void onConnectionAdded (const ManagedConnection *) override
 
void onConnectionRemoved (const ManagedConnection *) 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

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_
 

Private Member Functions

 Acceptor (Acceptor const &)=delete
 
Acceptoroperator= (Acceptor const &)=delete
 
void checkDrained ()
 

Private Attributes

State state_ {State::kInit}
 
uint64_t numPendingSSLConns_ {0}
 
bool forceShutdownInProgress_ {false}
 
std::shared_ptr< const LoadShedConfigurationloadShedConfig_ {nullptr}
 
const IConnectionCounterconnectionCounter_ {nullptr}
 
std::chrono::milliseconds gracefulShutdownTimeout_ {5000}
 

Static Private Attributes

static std::atomic< uint64_ttotalNumPendingSSLConns_ {0}
 

Detailed Description

An abstract acceptor for TCP-based network services.

There is one acceptor object per thread for each listening socket. When a new connection arrives on the listening socket, it is accepted by one of the acceptor objects. From that point on the connection will be processed by that acceptor's thread.

The acceptor will call the abstract onNewConnection() method to create a new ManagedConnection object for each accepted socket. The acceptor also tracks all outstanding connections that it has accepted.

Definition at line 58 of file Acceptor.h.

Member Enumeration Documentation

Enumerator
kInit 
kRunning 
kDraining 
kDone 

Definition at line 64 of file Acceptor.h.

64  : uint32_t {
65  kInit, // not yet started
66  kRunning, // processing requests normally
67  kDraining, // processing outstanding conns, but not accepting new ones
68  kDone, // no longer accepting, and all connections finished
69  };

Constructor & Destructor Documentation

wangle::Acceptor::Acceptor ( const ServerSocketConfig accConfig)
explicit

Definition at line 54 of file Acceptor.cpp.

54  :
55  accConfig_(accConfig),
56  socketOptions_(accConfig.getSocketOptions()) {
57 }
folly::AsyncSocket::OptionMap socketOptions_
Definition: Acceptor.h:425
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
wangle::Acceptor::~Acceptor ( void  )
override

Definition at line 184 of file Acceptor.cpp.

184  {
185 }
wangle::Acceptor::Acceptor ( Acceptor const &  )
privatedelete

Member Function Documentation

void wangle::Acceptor::acceptError ( const std::exception &  ex)
overrideprotectedvirtualnoexcept

acceptError() is called if an error occurs while accepting.

The AcceptCallback will remain installed even after an accept error, as the errors are typically somewhat transient, such as being out of file descriptors. The server socket must be explicitly stopped if you wish to stop accepting after an error.

Parameters
exAn exception representing the error.

Implements folly::AsyncServerSocket::AcceptCallback.

Definition at line 432 of file Acceptor.cpp.

Referenced by onConnectionsDrained().

432  {
433  // An error occurred.
434  // The most likely error is out of FDs. AsyncServerSocket will back off
435  // briefly if we are out of FDs, then continue accepting later.
436  // Just log a message here.
437  LOG(ERROR) << "error accepting on acceptor socket: " << ex.what();
438 }
void wangle::Acceptor::acceptStopped ( )
overrideprotectedvirtualnoexcept

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 folly::AsyncServerSocket::AcceptCallback.

Reimplemented in wangle::ServerAcceptor< Pipeline >.

Definition at line 441 of file Acceptor.cpp.

References checkDrained(), drainAllConnections(), kDone, kDraining, and state_.

Referenced by wangle::ServerAcceptor< Pipeline >::acceptStopped(), and onConnectionsDrained().

441  {
442  VLOG(3) << "Acceptor " << this << " acceptStopped()";
443  // Drain the open client connections
445 
446  // If we haven't yet finished draining, begin doing so by marking ourselves
447  // as in the draining state. We must be sure to hit checkDrained() here, as
448  // if we're completely idle, we can should consider ourself drained
449  // immediately (as there is no outstanding work to complete to cause us to
450  // re-evaluate this).
451  if (state_ != State::kDone) {
453  checkDrained();
454  }
455 }
void checkDrained()
Definition: Acceptor.cpp:466
void drainAllConnections()
Definition: Acceptor.cpp:214
void wangle::Acceptor::addConnection ( wangle::ManagedConnection connection)

Invoked when a new ManagedConnection is created.

This allows the Acceptor to track the outstanding connections, for tracking timeouts and for ensuring that all connections have been drained on shutdown.

Definition at line 501 of file Acceptor.cpp.

References downstreamConnectionManager_.

Referenced by getConnectionManager(), and wangle::ServerAcceptor< Pipeline >::read().

501  {
502  // Add the socket to the timeout manager so that it can be cleaned
503  // up after being left idle for a long time.
504  downstreamConnectionManager_->addConnection(conn, true);
505 }
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
void wangle::Acceptor::addSSLContextConfig ( const SSLContextConfig sslCtxConfig)

Dynamically add a new SSLContextConfig

Definition at line 187 of file Acceptor.cpp.

References accConfig_, wangle::ServerSocketConfig::bindAddress, cacheProvider_, wangle::ServerSocketConfig::initialTicketSeeds, wangle::ServerSocketConfig::sslCacheOptions, and sslCtxManager_.

Referenced by setSSLCacheProvider().

187  {
188  sslCtxManager_->addSSLContextConfig(sslCtxConfig,
193 }
std::shared_ptr< SSLCacheProvider > cacheProvider_
Definition: Acceptor.h:440
folly::SocketAddress bindAddress
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
TLSTicketKeySeeds initialTicketSeeds
std::unique_ptr< SSLContextManager > sslCtxManager_
Definition: Acceptor.h:427
bool wangle::Acceptor::canAccept ( const folly::SocketAddress address)
protectedvirtual

Hook for subclasses to drop newly accepted connections prior to handshaking.

Definition at line 228 of file Acceptor.cpp.

References connectionCounter_, folly::SocketAddress::describe(), getActiveConnectionCountForLoadShedding(), getConnectionCountForLoadShedding(), wangle::IConnectionCounter::getNumConnections(), getWorkerMaxConnections(), loadShedConfig_, and uint64_t.

Referenced by connectionAccepted(), and getWorkerMaxConnections().

228  {
229  if (!connectionCounter_) {
230  return true;
231  }
232 
233  const auto totalConnLimit =
234  loadShedConfig_ ? loadShedConfig_->getMaxConnections() : 0;
235  if (totalConnLimit == 0) {
236  return true;
237  }
238 
239  uint64_t currentConnections = connectionCounter_->getNumConnections();
240  uint64_t maxConnections = getWorkerMaxConnections();
241  if (currentConnections < maxConnections) {
242  return true;
243  }
244 
245  if (loadShedConfig_ && loadShedConfig_->isWhitelisted(address)) {
246  return true;
247  }
248 
249  // Take care of the connection counts across all acceptors.
250  // Expensive since a lock must be taken to get the counter.
251 
252  // getConnectionCountForLoadShedding() call can be very expensive,
253  // don't call it if you are not going to use the results.
254  const auto totalConnExceeded =
255  totalConnLimit > 0 && getConnectionCountForLoadShedding() >= totalConnLimit;
256 
257  const auto activeConnLimit =
258  loadShedConfig_ ? loadShedConfig_->getMaxActiveConnections() : 0;
259  // getActiveConnectionCountForLoadShedding() call can be very expensive,
260  // don't call it if you are not going to use the results.
261  const auto activeConnExceeded =
262  !totalConnExceeded &&
263  activeConnLimit > 0 &&
264  getActiveConnectionCountForLoadShedding() >= activeConnLimit;
265 
266  if (!activeConnExceeded && !totalConnExceeded) {
267  return true;
268  }
269  LOG_EVERY_N(ERROR, 1000) << "shedding connection because activeConnExceeded="
270  << activeConnExceeded << "totalConnExceeded="
271  << totalConnExceeded;
272  VLOG(4) << address.describe() << " not whitelisted";
273  return false;
274 }
virtual uint64_t getWorkerMaxConnections() const
Definition: Acceptor.h:323
const IConnectionCounter * connectionCounter_
Definition: Acceptor.h:458
std::shared_ptr< const LoadShedConfiguration > loadShedConfig_
Definition: Acceptor.h:457
std::string describe() const
virtual uint64_t getActiveConnectionCountForLoadShedding() const
Definition: Acceptor.h:322
virtual uint64_t getConnectionCountForLoadShedding(void) const
Definition: Acceptor.h:321
virtual uint64_t getNumConnections() const =0
void wangle::Acceptor::checkDrained ( )
private

Definition at line 466 of file Acceptor.cpp.

References base_, downstreamConnectionManager_, forceShutdownInProgress_, kDone, kDraining, numPendingSSLConns_, onConnectionsDrained(), and state_.

Referenced by acceptStopped(), onEmpty(), sslConnectionError(), and sslConnectionReady().

466  {
467  CHECK(state_ == State::kDraining);
469  (downstreamConnectionManager_->getNumConnections() != 0) ||
470  (numPendingSSLConns_ != 0)) {
471  return;
472  }
473 
474  VLOG(2) << "All connections drained from Acceptor=" << this << " in thread "
475  << base_;
476 
478 
480 
482 }
uint64_t numPendingSSLConns_
Definition: Acceptor.h:452
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
bool forceShutdownInProgress_
Definition: Acceptor.h:456
virtual void onConnectionsDrained()
Definition: Acceptor.h:392
folly::EventBase * base_
Definition: Acceptor.h:319
void wangle::Acceptor::connectionAccepted ( int  fd,
const folly::SocketAddress clientAddr 
)
overrideprotectedvirtualnoexcept

connectionAccepted() is called whenever a new client connection is received.

The AcceptCallback will remain installed after connectionAccepted() returns.

Parameters
fdThe newly accepted client socket. The AcceptCallback assumes ownership of this socket, and is responsible for closing it when done. The newly accepted file descriptor will have already been put into non-blocking mode.
clientAddrA reference to a SocketAddress struct containing the client's address. This struct is only guaranteed to remain valid until connectionAccepted() returns.

Implements folly::AsyncServerSocket::AcceptCallback.

Definition at line 277 of file Acceptor.cpp.

References canAccept(), folly::netops::close(), now(), onDoneAcceptingConnection(), folly::netops::setsockopt(), and socketOptions_.

Referenced by onConnectionsDrained().

278  {
279  namespace fsp = folly::portability::sockets;
280  if (!canAccept(clientAddr)) {
281  // Send a RST to free kernel memory faster
282  struct linger optLinger = {1, 0};
283  fsp::setsockopt(fd, SOL_SOCKET, SO_LINGER, &optLinger, sizeof(optLinger));
284  close(fd);
285  return;
286  }
287  auto acceptTime = std::chrono::steady_clock::now();
288  for (const auto& opt: socketOptions_) {
289  opt.first.apply(fd, opt.second);
290  }
291 
292  onDoneAcceptingConnection(fd, clientAddr, acceptTime);
293 }
int setsockopt(NetworkSocket s, int level, int optname, const void *optval, socklen_t optlen)
Definition: NetOps.cpp:384
std::chrono::steady_clock::time_point now()
virtual void onDoneAcceptingConnection(int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime) noexcept
Definition: Acceptor.cpp:295
folly::AsyncSocket::OptionMap socketOptions_
Definition: Acceptor.h:425
virtual bool canAccept(const folly::SocketAddress &)
Definition: Acceptor.cpp:228
int close(NetworkSocket s)
Definition: NetOps.cpp:90
void wangle::Acceptor::connectionReady ( folly::AsyncTransportWrapper::UniquePtr  sock,
const folly::SocketAddress clientAddr,
const std::string nextProtocolName,
SecureTransportType  secureTransportType,
TransportInfo tinfo 
)

Process a connection that is to ready to receive L7 traffic. This method is called immediately upon accept for plaintext connections and upon completion of SSL handshaking or resumption for SSL connections.

Definition at line 365 of file Acceptor.cpp.

References wangle::TransportInfo::appProtocol, wangle::TransportInfo::initWithSocket(), kDraining, folly::gen::move, onNewConnection(), folly::AsyncSocket::setMaxReadsPerEvent(), and state_.

Referenced by HTTPTargetSessionAcceptor::connectionReady(), getTotalNumPendingSSLConns(), plaintextConnectionReady(), and sslConnectionReady().

370  {
371  // Limit the number of reads from the socket per poll loop iteration,
372  // both to keep memory usage under control and to prevent one fast-
373  // writing client from starving other connections.
374  auto asyncSocket = sock->getUnderlyingTransport<AsyncSocket>();
375  asyncSocket->setMaxReadsPerEvent(16);
376  tinfo.initWithSocket(asyncSocket);
377  tinfo.appProtocol = std::make_shared<std::string>(nextProtocolName);
378  if (state_ < State::kDraining) {
380  std::move(sock),
381  &clientAddr,
382  nextProtocolName,
383  secureTransportType,
384  tinfo);
385  }
386 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void setMaxReadsPerEvent(uint16_t maxReads)
Definition: AsyncSocket.h:451
virtual void onNewConnection(folly::AsyncTransportWrapper::UniquePtr, const folly::SocketAddress *, const std::string &, SecureTransportType, const TransportInfo &)
Definition: Acceptor.h:350
std::shared_ptr< fizz::server::FizzServerContext > wangle::Acceptor::createFizzContext ( )
protectedvirtual

Definition at line 135 of file Acceptor.cpp.

References accConfig_, and wangle::FizzConfigUtil::createFizzContext().

Referenced by getFizzPeeker(), init(), and resetSSLContextConfigs().

135  {
137 }
static std::shared_ptr< fizz::server::FizzServerContext > createFizzContext(const wangle::ServerSocketConfig &config, std::unique_ptr< fizz::server::CertManager > certMgr=nullptr)
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
std::shared_ptr< fizz::server::TicketCipher > wangle::Acceptor::createFizzTicketCipher ( folly::Optional< std::string pskContext = folly::none)
protectedvirtual

Definition at line 140 of file Acceptor.cpp.

References accConfig_, currentSecrets_, wangle::TLSTicketKeySeeds::currentSeeds, folly::gen::move, wangle::TLSTicketKeySeeds::newSeeds, wangle::TLSTicketKeySeeds::oldSeeds, wangle::ServerSocketConfig::sslCacheOptions, and wangle::SSLCacheOptions::sslCacheTimeout.

Referenced by getFizzPeeker(), and updateFizzContext().

140  {
141  return FizzConfigUtil::createTicketCipher<fizz::server::AES128TicketCipher>(
146  std::move(pskContext));
147 }
std::vector< std::string > newSeeds
std::vector< std::string > currentSeeds
wangle::TLSTicketKeySeeds currentSecrets_
Definition: Acceptor.h:441
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
std::chrono::seconds sslCacheTimeout
std::vector< std::string > oldSeeds
void wangle::Acceptor::drainAllConnections ( )

Drains all open connections of their outstanding transactions. When a connection's transaction count reaches zero, the connection closes.

Definition at line 214 of file Acceptor.cpp.

References downstreamConnectionManager_, and gracefulShutdownTimeout_.

Referenced by acceptStopped(), and getTotalNumPendingSSLConns().

214  {
216  downstreamConnectionManager_->initiateGracefulShutdown(
218  }
219 }
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
std::chrono::milliseconds gracefulShutdownTimeout_
Definition: Acceptor.h:459
void wangle::Acceptor::drainConnections ( double  pctToDrain)
virtual

Drain defined percentage of connections.

Reimplemented in wangle::ServerAcceptor< Pipeline >.

Definition at line 485 of file Acceptor.cpp.

References base_, downstreamConnectionManager_, getNumConnections(), gracefulShutdownTimeout_, and folly::INFO.

Referenced by wangle::ServerAcceptor< Pipeline >::drainConnections(), and getTotalNumPendingSSLConns().

485  {
487  LOG(INFO) << "Draining " << pctToDrain * 100 << "% of "
488  << getNumConnections() << " connections from Acceptor=" << this
489  << " in thread " << base_;
490  assert(base_->isInEventBaseThread());
493  }
494 }
uint32_t getNumConnections() const
Definition: Acceptor.h:119
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
virtual void drainConnections(double pctToDrain)
Definition: Acceptor.cpp:485
std::chrono::milliseconds gracefulShutdownTimeout_
Definition: Acceptor.h:459
folly::EventBase * base_
Definition: Acceptor.h:319
void wangle::Acceptor::dropAllConnections ( )

Drop all connections.

forceStop() schedules dropAllConnections() to be called in the acceptor's thread.

Definition at line 513 of file Acceptor.cpp.

References base_, downstreamConnectionManager_, forceShutdownInProgress_, folly::INFO, folly::EventBase::isInEventBaseThread(), kDone, numPendingSSLConns_, onConnectionsDrained(), and state_.

Referenced by forceStop(), and getTotalNumPendingSSLConns().

513  {
515  LOG(INFO) << "Dropping all connections from Acceptor=" << this
516  << " in thread " << base_;
517  assert(base_->isInEventBaseThread());
519  downstreamConnectionManager_->dropAllConnections();
520  CHECK(downstreamConnectionManager_->getNumConnections() == 0);
522  }
523  CHECK(numPendingSSLConns_ == 0);
524 
527 }
uint64_t numPendingSSLConns_
Definition: Acceptor.h:452
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
bool forceShutdownInProgress_
Definition: Acceptor.h:456
bool isInEventBaseThread() const
Definition: EventBase.h:504
virtual void onConnectionsDrained()
Definition: Acceptor.h:392
folly::EventBase * base_
Definition: Acceptor.h:319
void wangle::Acceptor::dropConnections ( double  pctToDrop)
virtual

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 in wangle::ServerAcceptor< Pipeline >.

Definition at line 530 of file Acceptor.cpp.

References base_, downstreamConnectionManager_, forceShutdownInProgress_, getNumConnections(), folly::INFO, and folly::EventBase::runInEventBaseThread().

Referenced by wangle::ServerAcceptor< Pipeline >::dropConnections(), and getTotalNumPendingSSLConns().

530  {
531  base_->runInEventBaseThread([&, pctToDrop] {
533  LOG(INFO) << "Dropping " << pctToDrop * 100 << "% of "
534  << getNumConnections() << " connections from Acceptor=" << this
535  << " in thread " << base_;
536  assert(base_->isInEventBaseThread());
538  downstreamConnectionManager_->dropConnections(pctToDrop);
539  }
540  });
541 }
uint32_t getNumConnections() const
Definition: Acceptor.h:119
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
bool forceShutdownInProgress_
Definition: Acceptor.h:456
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
folly::EventBase * base_
Definition: Acceptor.h:319
void wangle::Acceptor::forceStop ( )
virtual

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 in wangle::ServerAcceptor< Pipeline >.

Definition at line 508 of file Acceptor.cpp.

References base_, dropAllConnections(), and folly::EventBase::runInEventBaseThread().

Referenced by wangle::ServerAcceptor< Pipeline >::forceStop(), getGracefulShutdownTimeout(), and TEST().

508  {
510 }
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
folly::EventBase * base_
Definition: Acceptor.h:319
void dropAllConnections()
Definition: Acceptor.cpp:513
virtual uint64_t wangle::Acceptor::getActiveConnectionCountForLoadShedding ( ) const
inlineprotectedvirtual

Reimplemented in wangle::TestableAcceptor.

Definition at line 322 of file Acceptor.h.

Referenced by canAccept().

322 { return 0; }
const ServerSocketConfig& wangle::Acceptor::getConfig ( ) const
inline

Definition at line 197 of file Acceptor.h.

References accConfig_.

197 { return accConfig_; }
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
virtual uint64_t wangle::Acceptor::getConnectionCountForLoadShedding ( void  ) const
inlineprotectedvirtual

Reimplemented in wangle::TestableAcceptor.

Definition at line 321 of file Acceptor.h.

Referenced by canAccept().

321 { return 0; }
virtual wangle::ConnectionManager* wangle::Acceptor::getConnectionManager ( )
inlinevirtual

Access the Acceptor's downstream (client-side) ConnectionManager

Definition at line 132 of file Acceptor.h.

References addConnection(), and downstreamConnectionManager_.

Referenced by wangle::AcceptorHandshakeManager::startHandshakeTimeout().

132  {
133  return downstreamConnectionManager_.get();
134  }
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
milliseconds wangle::Acceptor::getConnTimeout ( ) const

Get the current connection timeout.

Definition at line 497 of file Acceptor.cpp.

References accConfig_, and wangle::ServerSocketConfig::connectionIdleTimeout.

Referenced by getState().

497  {
499 }
std::chrono::milliseconds connectionIdleTimeout
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
virtual folly::EventBase* wangle::Acceptor::getEventBase ( ) const
inlinevirtual
virtual DefaultToFizzPeekingCallback* wangle::Acceptor::getFizzPeeker ( )
inlineprotectedvirtual

Definition at line 414 of file Acceptor.h.

References createFizzContext(), createFizzTicketCipher(), defaultFizzPeeker_, folly::none, and updateFizzContext().

Referenced by init(), resetSSLContextConfigs(), and setTLSTicketSecrets().

414  {
415  return &defaultFizzPeeker_;
416  }
DefaultToFizzPeekingCallback defaultFizzPeeker_
Definition: Acceptor.h:436
std::chrono::milliseconds wangle::Acceptor::getGracefulShutdownTimeout ( ) const
inline

Definition at line 182 of file Acceptor.h.

References forceStop(), and gracefulShutdownTimeout_.

Referenced by proxygen::SimpleController::getGracefulShutdownTimeout().

182  {
184  }
std::chrono::milliseconds gracefulShutdownTimeout_
Definition: Acceptor.h:459
const std::string& wangle::Acceptor::getName ( ) const
inline

Returns the name of this VIP.

Will return an empty string if no name has been configured.

Definition at line 162 of file Acceptor.h.

References accConfig_, and wangle::ServerSocketConfig::name.

Referenced by proxygen::ServiceWorker::addServiceAcceptor(), and init().

162  {
163  return accConfig_.name;
164  }
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
uint32_t wangle::Acceptor::getNumConnections ( ) const
inline

Return the number of outstanding connections in this service instance.

Definition at line 119 of file Acceptor.h.

References downstreamConnectionManager_, and uint32_t.

Referenced by drainConnections(), dropConnections(), and TEST().

119  {
121  (uint32_t)downstreamConnectionManager_->getNumConnections() : 0;
122  }
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
SSLContextManager* wangle::Acceptor::getSSLContextManager ( ) const
inline

Definition at line 104 of file Acceptor.h.

References setTLSTicketSecrets(), and sslCtxManager_.

104  {
105  return sslCtxManager_.get();
106  }
std::unique_ptr< SSLContextManager > sslCtxManager_
Definition: Acceptor.h:427
std::chrono::milliseconds wangle::Acceptor::getSSLHandshakeTimeout ( ) const
inline

Returns the ssl handshake connection timeout of this VIP

Definition at line 169 of file Acceptor.h.

References accConfig_, and wangle::ServerSocketConfig::sslHandshakeTimeout.

Referenced by wangle::AcceptorHandshakeManager::startHandshakeTimeout().

169  {
171  }
std::chrono::milliseconds sslHandshakeTimeout
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
State wangle::Acceptor::getState ( ) const
inline

Get this acceptor's current state.

Definition at line 148 of file Acceptor.h.

References getConnTimeout(), and state_.

Referenced by TEST().

148  {
149  return state_;
150  }
virtual uint64_t wangle::Acceptor::getWorkerMaxConnections ( ) const
inlineprotectedvirtual

Definition at line 323 of file Acceptor.h.

References canAccept(), connectionCounter_, and wangle::IConnectionCounter::getMaxConnections().

Referenced by canAccept().

323  {
325  }
virtual uint64_t getMaxConnections() const =0
const IConnectionCounter * connectionCounter_
Definition: Acceptor.h:458
void wangle::Acceptor::init ( folly::AsyncServerSocket serverSocket,
folly::EventBase eventBase,
SSLStats stats = nullptr 
)
virtual

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 in wangle::ServerAcceptor< Pipeline >, and proxygen::HTTPAcceptor.

Definition at line 60 of file Acceptor.cpp.

References accConfig_, folly::AsyncServerSocket::addAcceptCallback(), wangle::SecurityProtocolContextManager::addPeeker(), wangle::ServerSocketConfig::allowInsecureConnectionsOnSecureServer, wangle::ServerSocketConfig::bindAddress, cacheProvider_, createFizzContext(), wangle::TLSTicketKeySeeds::currentSeeds, defaultPeekingCallback_, wangle::FizzConfig::enableFizz, wangle::ServerSocketConfig::fizzConfig, getFizzPeeker(), getName(), folly::AsyncServerSocket::getSockets(), folly::INFO, initDownstreamConnectionManager(), wangle::ServerSocketConfig::initialTicketSeeds, wangle::ServerSocketConfig::isSSL(), folly::gen::move, wangle::TLSTicketKeySeeds::newSeeds, wangle::TLSTicketKeySeeds::oldSeeds, securityProtocolCtxManager_, setTLSTicketSecrets(), socketOptions_, wangle::ServerSocketConfig::sslCacheOptions, wangle::ServerSocketConfig::sslContextConfigs, sslCtxManager_, wangle::ServerSocketConfig::strictSSL, and tlsPlaintextPeekingCallback_.

Referenced by wangle::ServerAcceptor< Pipeline >::init(), setSSLCacheProvider(), TEST(), and TestAcceptor::TestAcceptor().

62  {
63  if (accConfig_.isSSL()) {
64 
67  }
68 
70  auto fizzCtx = createFizzContext();
71  auto* peeker = getFizzPeeker();
72  peeker->setContext(std::move(fizzCtx));
78  } else {
80  }
81 
82  if (!sslCtxManager_) {
83  sslCtxManager_ = std::make_unique<SSLContextManager>(
84  eventBase,
85  "vip_" + getName(),
86  accConfig_.strictSSL, stats);
87  }
88  try {
89  for (const auto& sslCtxConfig : accConfig_.sslContextConfigs) {
90  sslCtxManager_->addSSLContextConfig(
91  sslCtxConfig,
96  }
97 
98  CHECK(sslCtxManager_->getDefaultSSLCtx());
99  } catch (const std::runtime_error& ex) {
100  if (accConfig_.strictSSL) {
101  throw;
102  } else {
103  sslCtxManager_->clear();
104  // This is not a Not a fatal error, but useful to know.
105  LOG(INFO) << "Failed to configure TLS. This is not a fatal error. "
106  << ex.what();
107  }
108  }
109  }
110 
112  if (serverSocket) {
113  serverSocket->addAcceptCallback(this, eventBase);
114 
115  for (auto& fd : serverSocket->getSockets()) {
116  if (fd < 0) {
117  continue;
118  }
119  for (const auto& opt: socketOptions_) {
120  opt.first.apply(fd, opt.second);
121  }
122  }
123  }
124 }
std::vector< std::string > newSeeds
std::vector< std::string > currentSeeds
std::vector< int > getSockets() const
virtual void setTLSTicketSecrets(const std::vector< std::string > &oldSecrets, const std::vector< std::string > &currentSecrets, const std::vector< std::string > &newSecrets)
Definition: Acceptor.cpp:195
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< SSLCacheProvider > cacheProvider_
Definition: Acceptor.h:440
virtual void initDownstreamConnectionManager(folly::EventBase *eventBase)
Definition: Acceptor.cpp:126
void addPeeker(PeekingCallbackPtr peekingCallback)
folly::AsyncSocket::OptionMap socketOptions_
Definition: Acceptor.h:425
const std::string & getName() const
Definition: Acceptor.h:162
folly::SocketAddress bindAddress
virtual DefaultToFizzPeekingCallback * getFizzPeeker()
Definition: Acceptor.h:414
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
DefaultToSSLPeekingCallback defaultPeekingCallback_
Definition: Acceptor.h:435
SecurityProtocolContextManager securityProtocolCtxManager_
Definition: Acceptor.h:432
virtual std::shared_ptr< fizz::server::FizzServerContext > createFizzContext()
Definition: Acceptor.cpp:135
TLSTicketKeySeeds initialTicketSeeds
std::vector< std::string > oldSeeds
TLSPlaintextPeekingCallback tlsPlaintextPeekingCallback_
Definition: Acceptor.h:434
std::vector< SSLContextConfig > sslContextConfigs
std::unique_ptr< SSLContextManager > sslCtxManager_
Definition: Acceptor.h:427
virtual void addAcceptCallback(AcceptCallback *callback, EventBase *eventBase, uint32_t maxAtOnce=kDefaultCallbackAcceptAtOnce)
void wangle::Acceptor::initDownstreamConnectionManager ( folly::EventBase eventBase)
protectedvirtual

Definition at line 126 of file Acceptor.cpp.

References accConfig_, base_, wangle::ServerSocketConfig::connectionIdleTimeout, downstreamConnectionManager_, kRunning, wangle::ConnectionManager::makeUnique(), and state_.

Referenced by init().

126  {
127  CHECK(nullptr == this->base_ || eventBase == this->base_);
128  base_ = eventBase;
131  eventBase, accConfig_.connectionIdleTimeout, this);
132 }
std::chrono::milliseconds connectionIdleTimeout
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
static UniquePtr makeUnique(Args &&...args)
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
folly::EventBase * base_
Definition: Acceptor.h:319
bool wangle::Acceptor::isSSL ( ) const
inline

Definition at line 195 of file Acceptor.h.

References accConfig_, and wangle::ServerSocketConfig::isSSL().

Referenced by proxygen::HTTPServer::updateTicketSeeds(), and proxygen::HTTPServer::updateTLSCredentials().

195 { return accConfig_.isSSL(); }
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
virtual folly::AsyncSocket::UniquePtr wangle::Acceptor::makeNewAsyncSocket ( folly::EventBase base,
int  fd 
)
inlineprotectedvirtual

Reimplemented in proxygen::HTTPSessionAcceptor.

Definition at line 365 of file Acceptor.h.

Referenced by processEstablishedConnection().

367  {
369  new folly::AsyncSocket(base, fd));
370  }
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
Definition: AsyncSocket.h:83
virtual folly::AsyncSSLSocket::UniquePtr wangle::Acceptor::makeNewAsyncSSLSocket ( const std::shared_ptr< folly::SSLContext > &  ctx,
folly::EventBase base,
int  fd 
)
inlineprotectedvirtual

Definition at line 372 of file Acceptor.h.

Referenced by processEstablishedConnection().

373  {
376  ctx,
377  base,
378  fd,
379  true, /* set server */
380  true /* defer the security negotiation until sslAccept */));
381  }
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
void wangle::Acceptor::onConnectionAdded ( const ManagedConnection conn)
inlineoverrideprotectedvirtual

Invoked when a connection is added to the ConnectionManager.

Implements wangle::ConnectionManager::Callback.

Reimplemented in wangle::ServerAcceptor< Pipeline >.

Definition at line 403 of file Acceptor.h.

403 {}
void wangle::Acceptor::onConnectionRemoved ( const ManagedConnection conn)
inlineoverrideprotectedvirtual

Invoked when a connection is removed from the ConnectionManager.

Implements wangle::ConnectionManager::Callback.

Reimplemented in wangle::ServerAcceptor< Pipeline >.

Definition at line 404 of file Acceptor.h.

404 {}
virtual void wangle::Acceptor::onConnectionsDrained ( )
inlineprotectedvirtual

onConnectionsDrained() will be called once all connections have been drained while the acceptor is stopping.

Subclasses can override this method to perform any subclass-specific cleanup.

Reimplemented in proxygen::HTTPServerAcceptor.

Definition at line 392 of file Acceptor.h.

References acceptError(), acceptStopped(), connectionAccepted(), and onEmpty().

Referenced by checkDrained(), and dropAllConnections().

392 {}
void wangle::Acceptor::onDataAvailable ( std::shared_ptr< folly::AsyncUDPSocket socket,
const folly::SocketAddress addr,
std::unique_ptr< folly::IOBuf buf,
bool  truncated 
)
inlineoverrideprotectedvirtualnoexcept

Invoked when a new packet is received

Implements folly::AsyncUDPServerSocket::Callback.

Reimplemented in wangle::ServerAcceptor< Pipeline >.

Definition at line 359 of file Acceptor.h.

363  {}
void wangle::Acceptor::onDoneAcceptingConnection ( int  fd,
const folly::SocketAddress clientAddr,
std::chrono::steady_clock::time_point  acceptTime 
)
virtualnoexcept

Called right when the TCP connection has been accepted, before processing the first HTTP bytes (HTTP) or the SSL handshake (HTTPS)

Definition at line 295 of file Acceptor.cpp.

References processEstablishedConnection().

Referenced by connectionAccepted(), and getTotalNumPendingSSLConns().

298  {
299  TransportInfo tinfo;
300  processEstablishedConnection(fd, clientAddr, acceptTime, tinfo);
301 }
void processEstablishedConnection(int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
Definition: Acceptor.cpp:304
void wangle::Acceptor::onEmpty ( const wangle::ConnectionManager cm)
overrideprotectedvirtual

Invoked when the number of connections managed by the ConnectionManager changes from nonzero to zero.

Implements wangle::ConnectionManager::Callback.

Definition at line 458 of file Acceptor.cpp.

References checkDrained(), kDraining, and state_.

Referenced by onConnectionsDrained().

458  {
459  VLOG(3) << "Acceptor=" << this << " onEmpty()";
460  if (state_ == State::kDraining) {
461  checkDrained();
462  }
463 }
void checkDrained()
Definition: Acceptor.cpp:466
void wangle::Acceptor::onListenStarted ( )
inlineoverrideprotectedvirtualnoexcept

Invoked when we start reading data from socket. It is invoked in each acceptors/listeners event base thread.

Implements folly::AsyncUDPServerSocket::Callback.

Definition at line 357 of file Acceptor.h.

357 {}
void wangle::Acceptor::onListenStopped ( )
inlineoverrideprotectedvirtualnoexcept

Invoked when the server socket is closed. It is invoked in each acceptors/listeners event base thread.

Implements folly::AsyncUDPServerSocket::Callback.

Definition at line 358 of file Acceptor.h.

358 {}
virtual void wangle::Acceptor::onNewConnection ( folly::AsyncTransportWrapper::UniquePtr  ,
const folly::SocketAddress ,
const std::string ,
SecureTransportType  ,
const TransportInfo  
)
inlineprotectedvirtual

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 in wangle::ServerAcceptor< Pipeline >, proxygen::HTTPSessionAcceptor, TestAcceptor, proxygen::HTTPServerAcceptor, and TestAcceptor.

Definition at line 350 of file Acceptor.h.

Referenced by connectionReady().

355  {}
Acceptor& wangle::Acceptor::operator= ( Acceptor const &  )
privatedelete
void wangle::Acceptor::plaintextConnectionReady ( folly::AsyncTransportWrapper::UniquePtr  sock,
const folly::SocketAddress clientAddr,
const std::string nextProtocolName,
SecureTransportType  secureTransportType,
TransportInfo tinfo 
)
virtual

Wrapper for connectionReady() that can be overridden by subclasses to deal with plaintext connections.

Definition at line 388 of file Acceptor.cpp.

References connectionReady(), and folly::gen::move.

Referenced by getTotalNumPendingSSLConns(), and processEstablishedConnection().

393  {
395  std::move(sock),
396  clientAddr,
397  nextProtocolName,
398  secureTransportType,
399  tinfo);
400 }
void connectionReady(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
Definition: Acceptor.cpp:365
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void wangle::Acceptor::processEstablishedConnection ( int  fd,
const folly::SocketAddress clientAddr,
std::chrono::steady_clock::time_point  acceptTime,
TransportInfo tinfo 
)
noexcept

Begins either processing HTTP bytes (HTTP) or the SSL handshake (HTTPS)

Definition at line 304 of file Acceptor.cpp.

References accConfig_, base_, wangle::DROPPED, folly::pushmi::operators::error(), wangle::ServerSocketConfig::isSSL(), makeNewAsyncSocket(), makeNewAsyncSSLSocket(), wangle::ServerSocketConfig::maxConcurrentSSLHandshakes, folly::gen::move, wangle::ServerSocketConfig::name, wangle::NONE, numPendingSSLConns_, plaintextConnectionReady(), sslConnectionError(), sslCtxManager_, startHandshakeManager(), totalNumPendingSSLConns_, and updateSSLStats().

Referenced by getTotalNumPendingSSLConns(), and onDoneAcceptingConnection().

308  {
309  bool shouldDoSSL = false;
310  if (accConfig_.isSSL()) {
311  CHECK(sslCtxManager_);
312  shouldDoSSL = sslCtxManager_->getDefaultSSLCtx() != nullptr;
313  }
314  if (shouldDoSSL) {
317  sslCtxManager_->getDefaultSSLCtx(), base_, fd));
321  VLOG(2) << "dropped SSL handshake on " << accConfig_.name <<
322  " too many handshakes in progress";
324  auto latency = std::chrono::milliseconds(0);
325  updateSSLStats(sslSock.get(), latency, error);
326  auto ex = folly::make_exception_wrapper<SSLException>(
327  error, latency, sslSock->getRawBytesReceived());
328  sslConnectionError(ex);
329  return;
330  }
331 
332  tinfo.tfoSucceded = sslSock->getTFOSucceded();
334  std::move(sslSock),
335  this,
336  clientAddr,
337  acceptTime,
338  tinfo);
339  } else {
340  tinfo.secure = false;
341  tinfo.acceptTime = acceptTime;
343  tinfo.tfoSucceded = sock->getTFOSucceded();
345  std::move(sock),
346  clientAddr,
347  empty_string,
349  tinfo);
350  }
351 }
static const std::string empty_string
Definition: Acceptor.cpp:51
virtual folly::AsyncSocket::UniquePtr makeNewAsyncSocket(folly::EventBase *base, int fd)
Definition: Acceptor.h:365
uint64_t numPendingSSLConns_
Definition: Acceptor.h:452
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static std::atomic< uint64_t > totalNumPendingSSLConns_
Definition: Acceptor.h:454
virtual void updateSSLStats(const folly::AsyncTransportWrapper *, std::chrono::milliseconds, SSLErrorEnum) noexcept
Definition: Acceptor.h:305
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
virtual void startHandshakeManager(folly::AsyncSSLSocket::UniquePtr sslSock, Acceptor *acceptor, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
Definition: Acceptor.cpp:353
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
virtual void plaintextConnectionReady(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
Definition: Acceptor.cpp:388
virtual void sslConnectionError(const folly::exception_wrapper &ex)
Definition: Acceptor.cpp:422
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
Definition: AsyncSocket.h:83
std::unique_ptr< SSLContextManager > sslCtxManager_
Definition: Acceptor.h:427
virtual folly::AsyncSSLSocket::UniquePtr makeNewAsyncSSLSocket(const std::shared_ptr< folly::SSLContext > &ctx, folly::EventBase *base, int fd)
Definition: Acceptor.h:372
folly::EventBase * base_
Definition: Acceptor.h:319
void wangle::Acceptor::resetSSLContextConfigs ( )
virtual

Recreates ssl configs, re-reads certs

Definition at line 162 of file Acceptor.cpp.

References accConfig_, wangle::ServerSocketConfig::bindAddress, cacheProvider_, createFizzContext(), wangle::FizzConfig::enableFizz, wangle::ServerSocketConfig::fizzConfig, getFizzPeeker(), folly::gen::move, wangle::DefaultToFizzPeekingCallback::setContext(), wangle::ServerSocketConfig::sslCacheOptions, wangle::ServerSocketConfig::sslContextConfigs, sslCtxManager_, and updateFizzContext().

Referenced by setSSLCacheProvider(), and proxygen::HTTPServer::updateTLSCredentials().

162  {
164  auto ctx = createFizzContext();
165  if (ctx) {
166  updateFizzContext(ctx.get());
168  }
169  }
170  try {
171  sslCtxManager_->resetSSLContextConfigs(accConfig_.sslContextConfigs,
173  nullptr,
176  } catch (const std::runtime_error& ex) {
177  LOG(ERROR) << "Failed to re-configure TLS: "
178  << ex.what()
179  << "will keep old config";
180  }
181 
182 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< SSLCacheProvider > cacheProvider_
Definition: Acceptor.h:440
folly::SocketAddress bindAddress
void updateFizzContext(fizz::server::FizzServerContext *)
Definition: Acceptor.cpp:149
virtual DefaultToFizzPeekingCallback * getFizzPeeker()
Definition: Acceptor.h:414
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
void setContext(std::shared_ptr< fizz::server::FizzServerContext > context)
virtual std::shared_ptr< fizz::server::FizzServerContext > createFizzContext()
Definition: Acceptor.cpp:135
std::vector< SSLContextConfig > sslContextConfigs
std::unique_ptr< SSLContextManager > sslCtxManager_
Definition: Acceptor.h:427
void wangle::Acceptor::setGracefulShutdownTimeout ( std::chrono::milliseconds  gracefulShutdown)
inline

Time after drainAllConnections() or acceptStopped() during which new requests on connections owned by the downstream ConnectionManager will be processed normally.

Definition at line 178 of file Acceptor.h.

References gracefulShutdownTimeout_.

178  {
179  gracefulShutdownTimeout_ = gracefulShutdown;
180  }
std::chrono::milliseconds gracefulShutdownTimeout_
Definition: Acceptor.h:459
void wangle::Acceptor::setLoadShedConfig ( std::shared_ptr< const LoadShedConfiguration loadShedConfig,
const IConnectionCounter counter 
)
protected

Definition at line 221 of file Acceptor.cpp.

References connectionCounter_, counter, and loadShedConfig_.

223  {
224  loadShedConfig_ = loadShedConfig;
226 }
const IConnectionCounter * connectionCounter_
Definition: Acceptor.h:458
std::shared_ptr< const LoadShedConfiguration > loadShedConfig_
Definition: Acceptor.h:457
std::atomic< int > counter
virtual void wangle::Acceptor::setSSLCacheProvider ( const std::shared_ptr< SSLCacheProvider > &  cacheProvider)
inlinevirtual

Supply an SSL cache provider

Note
Call this before init()

Definition at line 78 of file Acceptor.h.

References addSSLContextConfig(), cacheProvider_, init(), and resetSSLContextConfigs().

79  {
80  cacheProvider_ = cacheProvider;
81  }
std::shared_ptr< SSLCacheProvider > cacheProvider_
Definition: Acceptor.h:440
void wangle::Acceptor::setTLSTicketSecrets ( const std::vector< std::string > &  oldSecrets,
const std::vector< std::string > &  currentSecrets,
const std::vector< std::string > &  newSecrets 
)
virtual

Sets TLS ticket secrets to use, or updates previously set secrets.

Definition at line 195 of file Acceptor.cpp.

References accConfig_, currentSecrets_, wangle::TLSTicketKeySeeds::currentSeeds, wangle::FizzConfig::enableFizz, wangle::ServerSocketConfig::fizzConfig, getFizzPeeker(), wangle::TLSTicketKeySeeds::newSeeds, wangle::TLSTicketKeySeeds::oldSeeds, sslCtxManager_, and updateFizzContext().

Referenced by getSSLContextManager(), init(), and proxygen::HTTPServer::updateTicketSeeds().

198  {
199  currentSecrets_.oldSeeds = oldSecrets;
200  currentSecrets_.currentSeeds = currentSecrets;
201  currentSecrets_.newSeeds = newSecrets;
202 
204  updateFizzContext(getFizzPeeker()->getContext().get());
205  }
206 
207  if (sslCtxManager_) {
208  sslCtxManager_->reloadTLSTicketKeys(
209  oldSecrets, currentSecrets, newSecrets);
210  }
211 }
std::vector< std::string > newSeeds
std::vector< std::string > currentSeeds
wangle::TLSTicketKeySeeds currentSecrets_
Definition: Acceptor.h:441
void updateFizzContext(fizz::server::FizzServerContext *)
Definition: Acceptor.cpp:149
virtual DefaultToFizzPeekingCallback * getFizzPeeker()
Definition: Acceptor.h:414
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
std::vector< std::string > oldSeeds
std::unique_ptr< SSLContextManager > sslCtxManager_
Definition: Acceptor.h:427
void wangle::Acceptor::sslConnectionError ( const folly::exception_wrapper ex)
virtual

Notification callback for SSL handshake failures.

Reimplemented in wangle::ServerAcceptor< Pipeline >.

Definition at line 422 of file Acceptor.cpp.

References checkDrained(), kDraining, numPendingSSLConns_, state_, and totalNumPendingSSLConns_.

Referenced by getTotalNumPendingSSLConns(), processEstablishedConnection(), and wangle::ServerAcceptor< Pipeline >::sslConnectionError().

422  {
423  CHECK(numPendingSSLConns_ > 0);
426  if (state_ == State::kDraining) {
427  checkDrained();
428  }
429 }
uint64_t numPendingSSLConns_
Definition: Acceptor.h:452
void checkDrained()
Definition: Acceptor.cpp:466
static std::atomic< uint64_t > totalNumPendingSSLConns_
Definition: Acceptor.h:454
void wangle::Acceptor::sslConnectionReady ( folly::AsyncTransportWrapper::UniquePtr  sock,
const folly::SocketAddress clientAddr,
const std::string nextProtocol,
SecureTransportType  secureTransportType,
TransportInfo tinfo 
)
virtual

Wrapper for connectionReady() that decrements the count of pending SSL connections. This should normally not be overridden.

Definition at line 403 of file Acceptor.cpp.

References checkDrained(), connectionReady(), kDraining, folly::gen::move, numPendingSSLConns_, state_, and totalNumPendingSSLConns_.

Referenced by getTotalNumPendingSSLConns().

407  {
408  CHECK(numPendingSSLConns_ > 0);
412  std::move(sock),
413  clientAddr,
414  nextProtocol,
415  secureTransportType,
416  tinfo);
417  if (state_ == State::kDraining) {
418  checkDrained();
419  }
420 }
void connectionReady(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
Definition: Acceptor.cpp:365
uint64_t numPendingSSLConns_
Definition: Acceptor.h:452
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void checkDrained()
Definition: Acceptor.cpp:466
static std::atomic< uint64_t > totalNumPendingSSLConns_
Definition: Acceptor.h:454
void wangle::Acceptor::startHandshakeManager ( folly::AsyncSSLSocket::UniquePtr  sslSock,
Acceptor acceptor,
const folly::SocketAddress clientAddr,
std::chrono::steady_clock::time_point  acceptTime,
TransportInfo tinfo 
)
virtualnoexcept

Creates and starts the handshake manager.

Definition at line 353 of file Acceptor.cpp.

References wangle::SecurityProtocolContextManager::getHandshakeManager(), folly::gen::move, securityProtocolCtxManager_, and wangle::AcceptorHandshakeManager::start().

Referenced by getTotalNumPendingSSLConns(), and processEstablishedConnection().

358  {
360  this, clientAddr, acceptTime, tinfo);
361  manager->start(std::move(sslSock));
362 }
virtual void start(folly::AsyncSSLSocket::UniquePtr sock) noexcept
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
SecurityProtocolContextManager securityProtocolCtxManager_
Definition: Acceptor.h:432
AcceptorHandshakeManager * getHandshakeManager(Acceptor *acceptor, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
void wangle::Acceptor::updateFizzContext ( fizz::server::FizzServerContext ctx)
protected

Definition at line 149 of file Acceptor.cpp.

References accConfig_, cipher, createFizzTicketCipher(), folly::gen::move, fizz::server::FizzServerContext::setTicketCipher(), wangle::ServerSocketConfig::sslContextConfigs, and string.

Referenced by getFizzPeeker(), resetSSLContextConfigs(), and setTLSTicketSecrets().

149  {
150  if (ctx) {
151  std::string pskContext;
152  if (!accConfig_.sslContextConfigs.empty()) {
153  pskContext = accConfig_.sslContextConfigs.front().sessionContext.value_or(
154  "");
155  }
159  }
160 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual std::shared_ptr< fizz::server::TicketCipher > createFizzTicketCipher(folly::Optional< std::string >=folly::none)
Definition: Acceptor.cpp:140
CipherSuite cipher
void setTicketCipher(std::shared_ptr< TicketCipher > ticketCipher)
const ServerSocketConfig accConfig_
Definition: Acceptor.h:407
const char * string
Definition: Conv.cpp:212
std::vector< SSLContextConfig > sslContextConfigs
virtual void wangle::Acceptor::updateSSLStats ( const folly::AsyncTransportWrapper ,
std::chrono::milliseconds  ,
SSLErrorEnum   
)
inlinevirtualnoexcept

Hook for subclasses to record stats about SSL connection establishment.

sock may be nullptr.

Definition at line 305 of file Acceptor.h.

Referenced by processEstablishedConnection().

308  {}

Member Data Documentation

folly::EventBase* wangle::Acceptor::base_ {nullptr}
protected

Our event loop.

Probably needs to be used to pass to a ManagedConnection implementation. Also visible in case a subclass wishes to do additional things w/ the event loop (e.g. in attach()).

Definition at line 319 of file Acceptor.h.

Referenced by checkDrained(), drainConnections(), dropAllConnections(), dropConnections(), forceStop(), getEventBase(), initDownstreamConnectionManager(), and processEstablishedConnection().

std::shared_ptr<SSLCacheProvider> wangle::Acceptor::cacheProvider_
protected

Definition at line 440 of file Acceptor.h.

Referenced by addSSLContextConfig(), init(), resetSSLContextConfigs(), and setSSLCacheProvider().

const IConnectionCounter* wangle::Acceptor::connectionCounter_ {nullptr}
private

Definition at line 458 of file Acceptor.h.

Referenced by canAccept(), getWorkerMaxConnections(), and setLoadShedConfig().

wangle::TLSTicketKeySeeds wangle::Acceptor::currentSecrets_
protected

Definition at line 441 of file Acceptor.h.

Referenced by createFizzTicketCipher(), and setTLSTicketSecrets().

DefaultToFizzPeekingCallback wangle::Acceptor::defaultFizzPeeker_
protected

Definition at line 436 of file Acceptor.h.

Referenced by getFizzPeeker().

DefaultToSSLPeekingCallback wangle::Acceptor::defaultPeekingCallback_
protected

Definition at line 435 of file Acceptor.h.

Referenced by init().

bool wangle::Acceptor::forceShutdownInProgress_ {false}
private

Definition at line 456 of file Acceptor.h.

Referenced by checkDrained(), dropAllConnections(), and dropConnections().

std::chrono::milliseconds wangle::Acceptor::gracefulShutdownTimeout_ {5000}
private
std::shared_ptr<const LoadShedConfiguration> wangle::Acceptor::loadShedConfig_ {nullptr}
private

Definition at line 457 of file Acceptor.h.

Referenced by canAccept(), and setLoadShedConfig().

uint64_t wangle::Acceptor::numPendingSSLConns_ {0}
private
SecurityProtocolContextManager wangle::Acceptor::securityProtocolCtxManager_
protected

Stores peekers for different security protocols.

Definition at line 432 of file Acceptor.h.

Referenced by init(), and startHandshakeManager().

folly::AsyncSocket::OptionMap wangle::Acceptor::socketOptions_
protected

Socket options to apply to the client socket

Definition at line 425 of file Acceptor.h.

Referenced by connectionAccepted(), and init().

std::unique_ptr<SSLContextManager> wangle::Acceptor::sslCtxManager_
protected
TLSPlaintextPeekingCallback wangle::Acceptor::tlsPlaintextPeekingCallback_
protected

Definition at line 434 of file Acceptor.h.

Referenced by init().

std::atomic< uint64_t > wangle::Acceptor::totalNumPendingSSLConns_ {0}
staticprivate

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