proxygen
wangle::PeekingAcceptorHandshakeHelper Class Reference

#include <PeekingAcceptorHandshakeHelper.h>

Inheritance diagram for wangle::PeekingAcceptorHandshakeHelper:
wangle::AcceptorHandshakeHelper wangle::SocketPeeker::Callback folly::DelayedDestruction folly::DelayedDestructionBase

Classes

class  PeekCallback
 

Public Member Functions

 PeekingAcceptorHandshakeHelper (const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo, const std::vector< PeekCallback * > &peekCallbacks, size_t numBytes)
 
void start (folly::AsyncSSLSocket::UniquePtr sock, AcceptorHandshakeHelper::Callback *callback) noexceptoverride
 
void dropConnection (SSLErrorEnum reason=SSLErrorEnum::NO_ERROR) override
 
void peekSuccess (std::vector< uint8_t > peekBytes) noexceptoverride
 
void peekError (const folly::AsyncSocketException &ex) noexceptoverride
 
- Public Member Functions inherited from folly::DelayedDestruction
virtual void destroy ()
 
bool getDestroyPending () const
 
- Public Member Functions inherited from folly::DelayedDestructionBase
virtual ~DelayedDestructionBase ()=default
 
- Public Member Functions inherited from wangle::SocketPeeker::Callback
virtual ~Callback ()=default
 

Private Member Functions

 ~PeekingAcceptorHandshakeHelper () override=default
 

Private Attributes

folly::AsyncSSLSocket::UniquePtr socket_
 
AcceptorHandshakeHelper::UniquePtr helper_
 
SocketPeeker::UniquePtr peeker_
 
AcceptorHandshakeHelper::Callbackcallback_
 
const folly::SocketAddressclientAddr_
 
std::chrono::steady_clock::time_point acceptTime_
 
TransportInfotinfo_
 
const std::vector< PeekCallback * > & peekCallbacks_
 
size_t numBytes_
 

Additional Inherited Members

- Public Types inherited from wangle::AcceptorHandshakeHelper
using UniquePtr = std::unique_ptr< AcceptorHandshakeHelper, folly::DelayedDestruction::Destructor >
 
- Protected Member Functions inherited from folly::DelayedDestruction
 ~DelayedDestruction () override=default
 
 DelayedDestruction ()
 
- Protected Member Functions inherited from folly::DelayedDestructionBase
 DelayedDestructionBase ()
 
uint32_t getDestructorGuardCount () const
 

Detailed Description

A hanshake helper which helpes switching between SSL and other protocols, so that we can run both SSL and other protocols over the same port at the same time. The mechanism used by this is to peek the first numBytes bytes of the socket and send it to the peek helper to decide which protocol it is.

Definition at line 32 of file PeekingAcceptorHandshakeHelper.h.

Constructor & Destructor Documentation

wangle::PeekingAcceptorHandshakeHelper::PeekingAcceptorHandshakeHelper ( const folly::SocketAddress clientAddr,
std::chrono::steady_clock::time_point  acceptTime,
TransportInfo tinfo,
const std::vector< PeekCallback * > &  peekCallbacks,
size_t  numBytes 
)
inline

Definition at line 55 of file PeekingAcceptorHandshakeHelper.h.

Referenced by wangle::PeekingAcceptorHandshakeManager::startHelper().

61  : clientAddr_(clientAddr),
62  acceptTime_(acceptTime),
63  tinfo_(tinfo),
64  peekCallbacks_(peekCallbacks),
65  numBytes_(numBytes) {}
std::chrono::steady_clock::time_point acceptTime_
const std::vector< PeekCallback * > & peekCallbacks_
wangle::PeekingAcceptorHandshakeHelper::~PeekingAcceptorHandshakeHelper ( )
overrideprivatedefault

Referenced by peekError().

Member Function Documentation

void wangle::PeekingAcceptorHandshakeHelper::dropConnection ( SSLErrorEnum  reason = SSLErrorEnum::NO_ERROR)
inlineoverridevirtual

Implements wangle::AcceptorHandshakeHelper.

Definition at line 80 of file PeekingAcceptorHandshakeHelper.h.

References helper_, and socket_.

80  {
81  CHECK_NE(socket_.get() == nullptr, helper_.get() == nullptr);
82  if (socket_) {
83  socket_->closeNow();
84  } else if (helper_) {
85  helper_->dropConnection(reason);
86  }
87  }
void wangle::PeekingAcceptorHandshakeHelper::peekError ( const folly::AsyncSocketException ex)
inlineoverridevirtualnoexcept

Implements wangle::SocketPeeker::Callback.

Definition at line 115 of file PeekingAcceptorHandshakeHelper.h.

References callback_, wangle::AcceptorHandshakeHelper::Callback::connectionError(), folly::none, peeker_, socket_, and ~PeekingAcceptorHandshakeHelper().

Referenced by peekSuccess().

115  {
116  peeker_ = nullptr;
117  auto callback = callback_;
118  callback_ = nullptr;
119  callback->connectionError(
121  }
AcceptorHandshakeHelper::Callback * callback_
virtual void connectionError(folly::AsyncTransportWrapper *transport, folly::exception_wrapper ex, folly::Optional< SSLErrorEnum > sslErr) noexcept=0
constexpr None none
Definition: Optional.h:87
void wangle::PeekingAcceptorHandshakeHelper::peekSuccess ( std::vector< uint8_t peekBytes)
inlineoverridevirtualnoexcept

Implements wangle::SocketPeeker::Callback.

Definition at line 89 of file PeekingAcceptorHandshakeHelper.h.

References acceptTime_, callback_, clientAddr_, helper_, folly::gen::move, peekCallbacks_, peeker_, peekError(), socket_, tinfo_, and type.

89  {
91  peeker_ = nullptr;
92 
93  for (auto& peekCallback : peekCallbacks_) {
94  helper_ = peekCallback->getHelper(
95  peekBytes, clientAddr_, acceptTime_, tinfo_);
96  if (helper_) {
97  break;
98  }
99  }
100 
101  if (!helper_) {
102  // could not get a helper, report error.
103  auto type =
104  folly::AsyncSocketException::AsyncSocketExceptionType::CORRUPTED_DATA;
105  return peekError(
106  folly::AsyncSocketException(type, "Unrecognized protocol"));
107  }
108 
109  auto callback = callback_;
110  callback_ = nullptr;
111  helper_->start(std::move(socket_), callback);
112  CHECK(!socket_);
113  }
void peekError(const folly::AsyncSocketException &ex) noexceptoverride
AcceptorHandshakeHelper::Callback * callback_
PskType type
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::chrono::steady_clock::time_point acceptTime_
const std::vector< PeekCallback * > & peekCallbacks_
void wangle::PeekingAcceptorHandshakeHelper::start ( folly::AsyncSSLSocket::UniquePtr  sock,
AcceptorHandshakeHelper::Callback callback 
)
inlineoverridevirtualnoexcept

Implements wangle::AcceptorHandshakeHelper.

Definition at line 68 of file PeekingAcceptorHandshakeHelper.h.

References callback_, folly::gen::move, numBytes_, peeker_, and socket_.

70  {
71  socket_ = std::move(sock);
72  callback_ = callback;
73  CHECK_EQ(
74  socket_->getSSLState(),
75  folly::AsyncSSLSocket::SSLStateEnum::STATE_UNENCRYPTED);
76  peeker_.reset(new SocketPeeker(*socket_, this, numBytes_));
77  peeker_->start();
78  }
AcceptorHandshakeHelper::Callback * callback_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Data Documentation

std::chrono::steady_clock::time_point wangle::PeekingAcceptorHandshakeHelper::acceptTime_
private
AcceptorHandshakeHelper::Callback* wangle::PeekingAcceptorHandshakeHelper::callback_
private

Definition at line 130 of file PeekingAcceptorHandshakeHelper.h.

Referenced by peekError(), peekSuccess(), and start().

const folly::SocketAddress& wangle::PeekingAcceptorHandshakeHelper::clientAddr_
private
AcceptorHandshakeHelper::UniquePtr wangle::PeekingAcceptorHandshakeHelper::helper_
private
size_t wangle::PeekingAcceptorHandshakeHelper::numBytes_
private
const std::vector<PeekCallback*>& wangle::PeekingAcceptorHandshakeHelper::peekCallbacks_
private
SocketPeeker::UniquePtr wangle::PeekingAcceptorHandshakeHelper::peeker_
private

Definition at line 128 of file PeekingAcceptorHandshakeHelper.h.

Referenced by peekError(), peekSuccess(), and start().

folly::AsyncSSLSocket::UniquePtr wangle::PeekingAcceptorHandshakeHelper::socket_
private

Definition at line 126 of file PeekingAcceptorHandshakeHelper.h.

Referenced by dropConnection(), peekError(), peekSuccess(), and start().

TransportInfo& wangle::PeekingAcceptorHandshakeHelper::tinfo_
private

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