41 using std::chrono::microseconds;
42 using std::chrono::milliseconds;
46 using std::shared_ptr;
55 accConfig_(accConfig),
56 socketOptions_(accConfig.getSocketOptions()) {
99 }
catch (
const std::runtime_error& ex) {
105 LOG(
INFO) <<
"Failed to configure TLS. This is not a fatal error. " 120 opt.first.apply(fd, opt.second);
127 CHECK(
nullptr == this->
base_ || eventBase == this->
base_);
139 std::shared_ptr<fizz::server::TicketCipher>
141 return FizzConfigUtil::createTicketCipher<fizz::server::AES128TicketCipher>(
176 }
catch (
const std::runtime_error& ex) {
177 LOG(ERROR) <<
"Failed to re-configure TLS: " 179 <<
"will keep old config";
196 const std::vector<std::string>& oldSecrets,
197 const std::vector<std::string>& currentSecrets,
198 const std::vector<std::string>& newSecrets) {
209 oldSecrets, currentSecrets, newSecrets);
222 std::shared_ptr<const LoadShedConfiguration> loadShedConfig,
233 const auto totalConnLimit =
235 if (totalConnLimit == 0) {
241 if (currentConnections < maxConnections) {
254 const auto totalConnExceeded =
257 const auto activeConnLimit =
261 const auto activeConnExceeded =
262 !totalConnExceeded &&
263 activeConnLimit > 0 &&
266 if (!activeConnExceeded && !totalConnExceeded) {
269 LOG_EVERY_N(ERROR, 1000) <<
"shedding connection because activeConnExceeded=" 270 << activeConnExceeded <<
"totalConnExceeded=" 271 << totalConnExceeded;
272 VLOG(4) << address.
describe() <<
" not whitelisted";
282 struct linger optLinger = {1, 0};
283 fsp::setsockopt(fd, SOL_SOCKET, SO_LINGER, &optLinger,
sizeof(optLinger));
289 opt.first.apply(fd, opt.second);
298 std::chrono::steady_clock::time_point acceptTime)
noexcept {
307 std::chrono::steady_clock::time_point acceptTime,
309 bool shouldDoSSL =
false;
322 " too many handshakes in progress";
324 auto latency = std::chrono::milliseconds(0);
326 auto ex = folly::make_exception_wrapper<SSLException>(
327 error, latency, sslSock->getRawBytesReceived());
332 tinfo.tfoSucceded = sslSock->getTFOSucceded();
340 tinfo.secure =
false;
341 tinfo.acceptTime = acceptTime;
343 tinfo.tfoSucceded = sock->getTFOSucceded();
357 std::chrono::steady_clock::time_point acceptTime,
360 this, clientAddr, acceptTime, tinfo);
368 const string& nextProtocolName,
374 auto asyncSocket = sock->getUnderlyingTransport<
AsyncSocket>();
377 tinfo.
appProtocol = std::make_shared<std::string>(nextProtocolName);
391 const string& nextProtocolName,
405 const string& nextProtocol,
437 LOG(ERROR) <<
"error accepting on acceptor socket: " << ex.what();
442 VLOG(3) <<
"Acceptor " <<
this <<
" acceptStopped()";
459 VLOG(3) <<
"Acceptor=" <<
this <<
" onEmpty()";
474 VLOG(2) <<
"All connections drained from Acceptor=" <<
this <<
" in thread " 487 LOG(
INFO) <<
"Draining " << pctToDrain * 100 <<
"% of " 489 <<
" in thread " <<
base_;
490 assert(base_->isInEventBaseThread());
515 LOG(
INFO) <<
"Dropping all connections from Acceptor=" <<
this 516 <<
" in thread " <<
base_;
533 LOG(
INFO) <<
"Dropping " << pctToDrop * 100 <<
"% of " 535 <<
" in thread " <<
base_;
536 assert(base_->isInEventBaseThread());
std::chrono::milliseconds getConnTimeout() const
SSLCacheOptions sslCacheOptions
void onEmpty(const wangle::ConnectionManager &cm) override
std::vector< std::string > newSeeds
virtual void start(folly::AsyncSSLSocket::UniquePtr sock) noexcept
std::vector< std::string > currentSeeds
static const std::string empty_string
virtual uint64_t getWorkerMaxConnections() const
virtual folly::AsyncSocket::UniquePtr makeNewAsyncSocket(folly::EventBase *base, int fd)
void connectionReady(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
void setLoadShedConfig(std::shared_ptr< const LoadShedConfiguration > loadShedConfig, const IConnectionCounter *counter)
uint32_t getNumConnections() const
void addSSLContextConfig(const SSLContextConfig &sslCtxConfig)
std::vector< int > getSockets() const
virtual void setTLSTicketSecrets(const std::vector< std::string > &oldSecrets, const std::vector< std::string > ¤tSecrets, const std::vector< std::string > &newSecrets)
int setsockopt(NetworkSocket s, int level, int optname, const void *optval, socklen_t optlen)
std::chrono::milliseconds connectionIdleTimeout
wangle::TLSTicketKeySeeds currentSecrets_
uint64_t numPendingSSLConns_
void processEstablishedConnection(int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
std::chrono::steady_clock::time_point now()
constexpr detail::Map< Move > move
const IConnectionCounter * connectionCounter_
std::shared_ptr< SSLCacheProvider > cacheProvider_
static std::shared_ptr< fizz::server::FizzServerContext > createFizzContext(const wangle::ServerSocketConfig &config, std::unique_ptr< fizz::server::CertManager > certMgr=nullptr)
virtual void initDownstreamConnectionManager(folly::EventBase *eventBase)
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
bool forceShutdownInProgress_
void addPeeker(PeekingCallbackPtr peekingCallback)
std::shared_ptr< const LoadShedConfiguration > loadShedConfig_
virtual void onDoneAcceptingConnection(int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime) noexcept
std::string describe() const
virtual void dropConnections(double pctToDrop)
requires E e noexcept(noexcept(s.error(std::move(e))))
static std::atomic< uint64_t > totalNumPendingSSLConns_
virtual void drainConnections(double pctToDrain)
virtual void updateSSLStats(const folly::AsyncTransportWrapper *, std::chrono::milliseconds, SSLErrorEnum) noexcept
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
virtual std::shared_ptr< fizz::server::TicketCipher > createFizzTicketCipher(folly::Optional< std::string >=folly::none)
void acceptStopped() noexceptoverride
virtual void startHandshakeManager(folly::AsyncSSLSocket::UniquePtr sslSock, Acceptor *acceptor, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
void acceptError(const std::exception &ex) noexceptoverride
folly::AsyncSocket::OptionMap socketOptions_
const std::string & getName() const
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
void setMaxReadsPerEvent(uint16_t maxReads)
bool initWithSocket(const folly::AsyncSocket *sock)
bool isInEventBaseThread() const
folly::SocketAddress bindAddress
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
bool allowInsecureConnectionsOnSecureServer
virtual void onConnectionsDrained()
static UniquePtr makeUnique(Args &&...args)
void updateFizzContext(fizz::server::FizzServerContext *)
Acceptor(const ServerSocketConfig &accConfig)
bool runInEventBaseThread(void(*fn)(T *), T *arg)
void setTicketCipher(std::shared_ptr< TicketCipher > ticketCipher)
virtual DefaultToFizzPeekingCallback * getFizzPeeker()
const ServerSocketConfig accConfig_
void addConnection(wangle::ManagedConnection *connection)
virtual uint64_t getActiveConnectionCountForLoadShedding() const
virtual void plaintextConnectionReady(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
virtual uint64_t getConnectionCountForLoadShedding(void) const
void setContext(std::shared_ptr< fizz::server::FizzServerContext > context)
DefaultToSSLPeekingCallback defaultPeekingCallback_
SecurityProtocolContextManager securityProtocolCtxManager_
virtual void sslConnectionReady(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocol, SecureTransportType secureTransportType, TransportInfo &tinfo)
std::chrono::seconds sslCacheTimeout
AcceptorHandshakeManager * getHandshakeManager(Acceptor *acceptor, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
virtual std::shared_ptr< fizz::server::FizzServerContext > createFizzContext()
std::atomic< int > counter
TLSTicketKeySeeds initialTicketSeeds
std::chrono::milliseconds gracefulShutdownTimeout_
virtual uint64_t getNumConnections() const =0
virtual bool canAccept(const folly::SocketAddress &)
virtual void sslConnectionError(const folly::exception_wrapper &ex)
std::shared_ptr< std::string > appProtocol
std::vector< std::string > oldSeeds
void connectionAccepted(int fd, const folly::SocketAddress &clientAddr) noexceptoverride
Range< const char * > StringPiece
TLSPlaintextPeekingCallback tlsPlaintextPeekingCallback_
uint32_t maxConcurrentSSLHandshakes
int close(NetworkSocket s)
virtual void resetSSLContextConfigs()
std::vector< SSLContextConfig > sslContextConfigs
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
std::unique_ptr< SSLContextManager > sslCtxManager_
virtual folly::AsyncSSLSocket::UniquePtr makeNewAsyncSSLSocket(const std::shared_ptr< folly::SSLContext > &ctx, folly::EventBase *base, int fd)
virtual void init(folly::AsyncServerSocket *serverSocket, folly::EventBase *eventBase, SSLStats *stats=nullptr)
virtual void onNewConnection(folly::AsyncTransportWrapper::UniquePtr, const folly::SocketAddress *, const std::string &, SecureTransportType, const TransportInfo &)
void drainAllConnections()
void dropAllConnections()
virtual void addAcceptCallback(AcceptCallback *callback, EventBase *eventBase, uint32_t maxAtOnce=kDefaultCallbackAcceptAtOnce)