proxygen
BogoTestServer Class Reference
Inheritance diagram for BogoTestServer:
folly::AsyncSocket::ConnectCallback fizz::server::AsyncFizzServerT< SM >::HandshakeCallback folly::AsyncSSLSocket::HandshakeCB folly::AsyncReader::ReadCallback

Public Member Functions

 BogoTestServer (EventBase *evb, uint16_t port, std::shared_ptr< FizzServerContext > serverContext, std::shared_ptr< SSLContext > sslContext)
 
void connectSuccess () noexceptoverride
 
void connectErr (const AsyncSocketException &ex) noexceptoverride
 
void fizzHandshakeSuccess (AsyncFizzServer *) noexceptoverride
 
void fizzHandshakeError (AsyncFizzServer *, folly::exception_wrapper ex) noexceptoverride
 
void fizzHandshakeAttemptFallback (std::unique_ptr< folly::IOBuf > clientHello) override
 
void getReadBuffer (void **, size_t *) override
 
void readDataAvailable (size_t) noexceptoverride
 
bool isBufferMovable () noexceptoverride
 
void readBufferAvailable (std::unique_ptr< IOBuf > buf) noexceptoverride
 
void readEOF () noexceptoverride
 
void readErr (const AsyncSocketException &) noexceptoverride
 
void handshakeSuc (folly::AsyncSSLSocket *) noexceptoverride
 
void handshakeErr (folly::AsyncSSLSocket *, const folly::AsyncSocketException &ex) noexceptoverride
 
bool unimplemented () const
 
bool success () const
 
- Public Member Functions inherited from folly::AsyncSocket::ConnectCallback
virtual ~ConnectCallback ()=default
 
- Public Member Functions inherited from fizz::server::AsyncFizzServerT< SM >::HandshakeCallback
virtual ~HandshakeCallback ()=default
 
virtual void fizzHandshakeSuccess (AsyncFizzServerT *transport) noexcept=0
 
virtual void fizzHandshakeError (AsyncFizzServerT *transport, folly::exception_wrapper ex) noexcept=0
 
- Public Member Functions inherited from folly::AsyncSSLSocket::HandshakeCB
virtual ~HandshakeCB ()=default
 
virtual bool handshakeVer (AsyncSSLSocket *, bool preverifyOk, X509_STORE_CTX *) noexcept
 
- Public Member Functions inherited from folly::AsyncReader::ReadCallback
virtual ~ReadCallback ()=default
 
virtual size_t maxBufferSize () const
 

Private Attributes

EventBaseevb_
 
AsyncSocket::UniquePtr socket_
 
std::shared_ptr< FizzServerContextserverContext_
 
AsyncFizzServer::UniquePtr transport_
 
std::shared_ptr< SSLContextsslContext_
 
AsyncSSLSocket::UniquePtr sslSocket_
 
bool unimplemented_ {false}
 
Optional< bool > success_
 

Detailed Description

Definition at line 40 of file BogoShim.cpp.

Constructor & Destructor Documentation

BogoTestServer::BogoTestServer ( EventBase evb,
uint16_t  port,
std::shared_ptr< FizzServerContext serverContext,
std::shared_ptr< SSLContext sslContext 
)
inline

Definition at line 45 of file BogoShim.cpp.

References socket_.

50  : evb_(evb), serverContext_(serverContext), sslContext_(sslContext) {
52  socket_->connect(this, "::", port, 1000);
53  }
EventBase * evb_
Definition: BogoShim.cpp:144
AsyncSocket::UniquePtr socket_
Definition: BogoShim.cpp:145
std::shared_ptr< FizzServerContext > serverContext_
Definition: BogoShim.cpp:147
std::shared_ptr< SSLContext > sslContext_
Definition: BogoShim.cpp:150
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
Definition: AsyncSocket.h:83

Member Function Documentation

void BogoTestServer::connectErr ( const AsyncSocketException ex)
inlineoverridevirtualnoexcept

connectErr() will be invoked if the connection attempt fails.

Parameters
exAn exception describing the error that occurred.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 61 of file BogoShim.cpp.

References folly::INFO, and socket_.

61  {
62  LOG(INFO) << "TCP connect failed: " << ex.what();
63  socket_.reset();
64  success_ = false;
65  }
Optional< bool > success_
Definition: BogoShim.cpp:154
AsyncSocket::UniquePtr socket_
Definition: BogoShim.cpp:145
void BogoTestServer::connectSuccess ( )
inlineoverridevirtualnoexcept

connectSuccess() will be invoked when the connection has been successfully established.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 55 of file BogoShim.cpp.

References folly::gen::move, socket_, and transport_.

55  {
58  transport_->accept(this);
59  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AsyncSocket::UniquePtr socket_
Definition: BogoShim.cpp:145
AsyncFizzServer::UniquePtr transport_
Definition: BogoShim.cpp:148
std::shared_ptr< FizzServerContext > serverContext_
Definition: BogoShim.cpp:147
std::unique_ptr< AsyncFizzServerT, folly::DelayedDestruction::Destructor > UniquePtr
AsyncFizzServerT< ServerStateMachine > AsyncFizzServer
void BogoTestServer::fizzHandshakeAttemptFallback ( std::unique_ptr< folly::IOBuf clientHello)
inlineoverridevirtual

Implements fizz::server::AsyncFizzServerT< SM >::HandshakeCallback.

Definition at line 80 of file BogoShim.cpp.

References evb_, folly::gen::move, sslSocket_, and transport_.

81  {
82  auto fd = transport_->getUnderlyingTransport<AsyncSocket>()->detachFd();
83  transport_.reset();
84  if (!sslContext_) {
85  unimplemented_ = true;
86  } else {
87  sslSocket_ =
89  sslSocket_->setPreReceivedData(std::move(clientHello));
90  sslSocket_->sslAccept(this);
91  }
92  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool unimplemented_
Definition: BogoShim.cpp:153
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
EventBase * evb_
Definition: BogoShim.cpp:144
AsyncFizzServer::UniquePtr transport_
Definition: BogoShim.cpp:148
std::shared_ptr< SSLContext > sslContext_
Definition: BogoShim.cpp:150
AsyncSSLSocket::UniquePtr sslSocket_
Definition: BogoShim.cpp:151
void BogoTestServer::fizzHandshakeError ( AsyncFizzServer ,
folly::exception_wrapper  ex 
)
inlineoverridenoexcept

Definition at line 72 of file BogoShim.cpp.

References folly::INFO, and transport_.

74  {
75  LOG(INFO) << "Handshake error: " << ex.what();
76  transport_.reset();
77  success_ = false;
78  }
folly::fbstring what() const
Optional< bool > success_
Definition: BogoShim.cpp:154
AsyncFizzServer::UniquePtr transport_
Definition: BogoShim.cpp:148
void BogoTestServer::fizzHandshakeSuccess ( AsyncFizzServer )
inlineoverridenoexcept

Definition at line 67 of file BogoShim.cpp.

References transport_.

67  {
68  success_ = true;
69  transport_->setReadCB(this);
70  }
Optional< bool > success_
Definition: BogoShim.cpp:154
AsyncFizzServer::UniquePtr transport_
Definition: BogoShim.cpp:148
void BogoTestServer::getReadBuffer ( void **  bufReturn,
size_t *  lenReturn 
)
inlineoverridevirtual

When data becomes available, getReadBuffer() will be invoked to get the buffer into which data should be read.

This method allows the ReadCallback to delay buffer allocation until data becomes available. This allows applications to manage large numbers of idle connections, without having to maintain a separate read buffer for each idle connection.

It is possible that in some cases, getReadBuffer() may be called multiple times before readDataAvailable() is invoked. In this case, the data will be written to the buffer returned from the most recent call to readDataAvailable(). If the previous calls to readDataAvailable() returned different buffers, the ReadCallback is responsible for ensuring that they are not leaked.

If getReadBuffer() throws an exception, returns a nullptr buffer, or returns a 0 length, the ReadCallback will be uninstalled and its readError() method will be invoked.

getReadBuffer() is not allowed to change the transport state before it returns. (For example, it should never uninstall the read callback, or set a different read callback.)

Parameters
bufReturngetReadBuffer() should update *bufReturn to contain the address of the read buffer. This parameter will never be nullptr.
lenReturngetReadBuffer() should update *lenReturn to contain the maximum number of bytes that may be written to the read buffer. This parameter will never be nullptr.

Implements folly::AsyncReader::ReadCallback.

Definition at line 94 of file BogoShim.cpp.

94  {
95  throw std::runtime_error("getReadBuffer not implemented");
96  }
void BogoTestServer::handshakeErr ( folly::AsyncSSLSocket sock,
const folly::AsyncSocketException ex 
)
inlineoverridevirtualnoexcept

handshakeErr() is called if an error occurs while establishing the SSL connection.

The HandshakeCB will be uninstalled before handshakeErr() is called.

Parameters
sockSSL socket on which the handshake was initiated
exAn exception representing the error.

Implements folly::AsyncSSLSocket::HandshakeCB.

Definition at line 127 of file BogoShim.cpp.

References folly::INFO, and sslSocket_.

129  {
130  LOG(INFO) << "SSL Handshake error: " << ex.what();
131  sslSocket_.reset();
132  success_ = false;
133  }
Optional< bool > success_
Definition: BogoShim.cpp:154
AsyncSSLSocket::UniquePtr sslSocket_
Definition: BogoShim.cpp:151
void BogoTestServer::handshakeSuc ( folly::AsyncSSLSocket sock)
inlineoverridevirtualnoexcept

handshakeSuc() is called when a new SSL connection is established, i.e., after SSL_accept/connect() returns successfully.

The HandshakeCB will be uninstalled before handshakeSuc() is called.

Parameters
sockSSL socket on which the handshake was initiated

Implements folly::AsyncSSLSocket::HandshakeCB.

Definition at line 123 of file BogoShim.cpp.

123  {
124  success_ = true;
125  }
Optional< bool > success_
Definition: BogoShim.cpp:154
bool BogoTestServer::isBufferMovable ( )
inlineoverridevirtualnoexcept

When data becomes available, isBufferMovable() will be invoked to figure out which API will be used, readBufferAvailable() or readDataAvailable(). If isBufferMovable() returns true, that means ReadCallback supports the IOBuf ownership transfer and readBufferAvailable() will be used. Otherwise, not.

By default, isBufferMovable() always return false. If readBufferAvailable() is implemented and to be invoked, You should overwrite isBufferMovable() and return true in the inherited class.

This method allows the AsyncSocket/AsyncSSLSocket do buffer allocation by itself until data becomes available. Compared with the pre/post buffer allocation in getReadBuffer()/readDataAvailabe(), readBufferAvailable() has two advantages. First, this can avoid memcpy. E.g., in AsyncSSLSocket, the decrypted data was copied from the openssl internal buffer to the readbuf buffer. With the buffer ownership transfer, the internal buffer can be directly "moved" to ReadCallback. Second, the memory allocation can be more precise. The reason is AsyncSocket/AsyncSSLSocket can allocate the memory of precise size because they have more context about the available data than ReadCallback. Think about the getReadBuffer() pre-allocate 4072 bytes buffer, but the available data is always 16KB (max OpenSSL record size).

Reimplemented from folly::AsyncReader::ReadCallback.

Definition at line 102 of file BogoShim.cpp.

102  {
103  return true;
104  }
void BogoTestServer::readBufferAvailable ( std::unique_ptr< IOBuf )
inlineoverridevirtualnoexcept

readBufferAvailable() will be invoked when data has been successfully read.

Note that only either readBufferAvailable() or readDataAvailable() will be invoked according to the return value of isBufferMovable(). The timing and aftereffect of readBufferAvailable() are the same as readDataAvailable()

Parameters
readBufThe unique pointer of read buffer.

Reimplemented from folly::AsyncReader::ReadCallback.

Definition at line 106 of file BogoShim.cpp.

References folly::gen::move, transport_, uint8_t, and fizz::detail::write().

106  {
107  io::Cursor cursor(buf.get());
108  std::unique_ptr<IOBuf> write = IOBuf::create(0);
109  io::Appender appender(write.get(), 50);
110  while (!cursor.isAtEnd()) {
111  uint8_t byte;
112  cursor.pull(&byte, 1);
113  byte ^= 0xff;
114  appender.push(&byte, 1);
115  }
116  transport_->writeChain(nullptr, std::move(write));
117  }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AsyncFizzServer::UniquePtr transport_
Definition: BogoShim.cpp:148
void BogoTestServer::readDataAvailable ( size_t  len)
inlineoverridevirtualnoexcept

readDataAvailable() will be invoked when data has been successfully read into the buffer returned by the last call to getReadBuffer().

The read callback remains installed after readDataAvailable() returns. It must be explicitly uninstalled to stop receiving read events. getReadBuffer() will be called at least once before each call to readDataAvailable(). getReadBuffer() will also be called before any call to readEOF().

Parameters
lenThe number of bytes placed in the buffer.

Implements folly::AsyncReader::ReadCallback.

Definition at line 98 of file BogoShim.cpp.

98  {
99  CHECK(false) << "readDataAvailable not implemented";
100  }
void BogoTestServer::readEOF ( )
inlineoverridevirtualnoexcept

readEOF() will be invoked when the transport is closed.

The read callback will be automatically uninstalled immediately before readEOF() is invoked.

Implements folly::AsyncReader::ReadCallback.

Definition at line 119 of file BogoShim.cpp.

119 {}
void BogoTestServer::readErr ( const AsyncSocketException ex)
inlineoverridevirtualnoexcept

readError() will be invoked if an error occurs reading from the transport.

The read callback will be automatically uninstalled immediately before readError() is invoked.

Parameters
exAn exception describing the error that occurred.

Implements folly::AsyncReader::ReadCallback.

Definition at line 121 of file BogoShim.cpp.

121 {}
bool BogoTestServer::success ( ) const
inline

Definition at line 139 of file BogoShim.cpp.

139  {
140  return *success_;
141  }
Optional< bool > success_
Definition: BogoShim.cpp:154
bool BogoTestServer::unimplemented ( ) const
inline

Definition at line 135 of file BogoShim.cpp.

135  {
136  return unimplemented_;
137  }
bool unimplemented_
Definition: BogoShim.cpp:153

Member Data Documentation

EventBase* BogoTestServer::evb_
private

Definition at line 144 of file BogoShim.cpp.

std::shared_ptr<FizzServerContext> BogoTestServer::serverContext_
private

Definition at line 147 of file BogoShim.cpp.

AsyncSocket::UniquePtr BogoTestServer::socket_
private

Definition at line 145 of file BogoShim.cpp.

std::shared_ptr<SSLContext> BogoTestServer::sslContext_
private

Definition at line 150 of file BogoShim.cpp.

AsyncSSLSocket::UniquePtr BogoTestServer::sslSocket_
private

Definition at line 151 of file BogoShim.cpp.

Optional<bool> BogoTestServer::success_
private

Definition at line 154 of file BogoShim.cpp.

AsyncFizzServer::UniquePtr BogoTestServer::transport_
private

Definition at line 148 of file BogoShim.cpp.

bool BogoTestServer::unimplemented_ {false}
private

Definition at line 153 of file BogoShim.cpp.


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