proxygen
|
#include <AsyncFizzBase.h>
Classes | |
class | HandshakeTimeout |
Public Types | |
using | UniquePtr = std::unique_ptr< AsyncFizzBase, folly::DelayedDestruction::Destructor > |
using | ReadCallback = folly::AsyncTransportWrapper::ReadCallback |
Public Types inherited from folly::AsyncTransportWrapper | |
using | UniquePtr = std::unique_ptr< AsyncTransportWrapper, Destructor > |
using | ReadCallback = AsyncReader::ReadCallback |
using | WriteCallback = AsyncWriter::WriteCallback |
Public Types inherited from folly::AsyncTransport | |
typedef std::unique_ptr< AsyncTransport, Destructor > | UniquePtr |
Protected Member Functions | |
virtual void | startTransportReads () |
virtual void | startHandshakeTimeout (std::chrono::milliseconds) |
virtual void | cancelHandshakeTimeout () |
virtual void | deliverAppData (std::unique_ptr< folly::IOBuf > buf) |
virtual void | deliverError (const folly::AsyncSocketException &ex, bool closeTransport=true) |
virtual void | writeAppData (folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE)=0 |
virtual void | transportError (const folly::AsyncSocketException &ex)=0 |
virtual void | transportDataAvailable ()=0 |
Protected Member Functions inherited from folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper > | |
~DecoratedAsyncTransportWrapper () override | |
Protected Member Functions inherited from folly::AsyncTransport | |
~AsyncTransport () override=default | |
Protected Member Functions inherited from folly::DelayedDestruction | |
~DelayedDestruction () override=default | |
DelayedDestruction () | |
Protected Member Functions inherited from folly::DelayedDestructionBase | |
DelayedDestructionBase () | |
uint32_t | getDestructorGuardCount () const |
Protected Member Functions inherited from folly::AsyncReader | |
virtual | ~AsyncReader ()=default |
Protected Member Functions inherited from folly::AsyncWriter | |
virtual | ~AsyncWriter ()=default |
Protected Member Functions inherited from folly::AsyncWriter::WriteCallback | |
virtual | ~WriteCallback ()=default |
Protected Attributes | |
folly::IOBufQueue | transportReadBuf_ {folly::IOBufQueue::cacheChainLength()} |
Protected Attributes inherited from folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper > | |
folly::AsyncTransportWrapper::UniquePtr | transport_ |
Private Member Functions | |
void | getReadBuffer (void **bufReturn, size_t *lenReturn) override |
void | readDataAvailable (size_t len) noexceptoverride |
bool | isBufferMovable () noexceptoverride |
void | readBufferAvailable (std::unique_ptr< folly::IOBuf > data) noexceptoverride |
void | readEOF () noexceptoverride |
void | readErr (const folly::AsyncSocketException &ex) noexceptoverride |
void | writeSuccess () noexceptoverride |
void | writeErr (size_t bytesWritten, const folly::AsyncSocketException &ex) noexceptoverride |
void | checkBufLen () |
void | handshakeTimeoutExpired () noexcept |
Private Member Functions inherited from folly::AsyncReader::ReadCallback | |
virtual | ~ReadCallback ()=default |
virtual size_t | maxBufferSize () const |
Private Attributes | |
ReadCallback * | readCallback_ {nullptr} |
std::unique_ptr< folly::IOBuf > | appDataBuf_ |
size_t | appBytesWritten_ {0} |
size_t | appBytesReceived_ {0} |
HandshakeTimeout | handshakeTimeout_ |
This class is a wrapper around AsyncTransportWrapper to handle most app level interactions so that the derived client and server classes
Definition at line 24 of file AsyncFizzBase.h.
Definition at line 31 of file AsyncFizzBase.h.
using fizz::AsyncFizzBase::UniquePtr = std::unique_ptr<AsyncFizzBase, folly::DelayedDestruction::Destructor> |
Definition at line 30 of file AsyncFizzBase.h.
|
explicit |
Definition at line 30 of file AsyncFizzBase.cpp.
|
override |
Definition at line 35 of file AsyncFizzBase.cpp.
References folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.
|
inlineoverridevirtual |
Attach the transport to a EventBase.
This may only be called if the transport is not currently attached to a EventBase (by an earlier call to detachEventBase()).
This method must be invoked in the EventBase's thread.
Implements folly::AsyncTransport.
Reimplemented in fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 135 of file AsyncFizzBase.h.
References folly::AsyncTimeout::attachEventBase(), attachEventBase(), good(), handshakeTimeout_, readCallback_, startTransportReads(), and fizz::AsyncFizzBase::HandshakeTimeout::transport_.
Referenced by fizz::server::AsyncFizzServerT< SM >::attachEventBase(), and attachEventBase().
|
inline |
EventBase operations.
Definition at line 129 of file AsyncFizzBase.h.
References folly::AsyncTimeout::attachTimeoutManager(), and handshakeTimeout_.
|
protectedvirtual |
Definition at line 96 of file AsyncFizzBase.cpp.
References folly::AsyncTimeout::cancelTimeout(), and handshakeTimeout_.
Referenced by fizz::client::AsyncFizzClientT< SM >::deliverHandshakeError(), and isDetachable().
|
private |
Definition at line 222 of file AsyncFizzBase.cpp.
References appDataBuf_, folly::IOBufQueue::chainLength(), fizz::kMaxBufSize, readCallback_, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_, and transportReadBuf_.
Referenced by deliverAppData(), readBufferAvailable(), and readDataAvailable().
|
overridepure virtual |
Determine if transport is connected to the endpoint
Implements folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
protectedvirtual |
Interfaces for the derived class to interact with the app level read callback.
Definition at line 100 of file AsyncFizzBase.cpp.
References appBytesReceived_, appDataBuf_, folly::AsyncSocketException::BAD_ARGS, checkBufLen(), folly::IOBuf::computeChainDataLength(), deliverError(), folly::AsyncReader::ReadCallback::getReadBuffer(), folly::AsyncReader::ReadCallback::isBufferMovable(), min, folly::gen::move, folly::AsyncReader::ReadCallback::readBufferAvailable(), readCallback_, and folly::AsyncReader::ReadCallback::readDataAvailable().
Referenced by isDetachable(), and setReadCB().
|
protectedvirtual |
Definition at line 158 of file AsyncFizzBase.cpp.
References folly::AsyncSocketException::END_OF_FILE, folly::AsyncSocketException::getType(), readCallback_, folly::AsyncReader::ReadCallback::readEOF(), and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.
Referenced by fizz::server::AsyncFizzServerT< SM >::deliverAllErrors(), fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), deliverAppData(), isDetachable(), and setReadCB().
|
overridevirtual |
Clean up transport on destruction
Reimplemented from folly::DelayedDestruction.
Definition at line 39 of file AsyncFizzBase.cpp.
References destroy(), and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.
|
inlineoverridevirtual |
Detach the transport from its EventBase.
This may only be called when the transport is idle and has no reads or writes pending. Once detached, the transport may not be used again until it is re-attached to a EventBase by calling attachEventBase().
This method must be called from the current EventBase's thread.
Implements folly::AsyncTransport.
Definition at line 144 of file AsyncFizzBase.h.
References folly::AsyncTimeout::detachEventBase(), detachEventBase(), handshakeTimeout_, setReadCB(), and fizz::AsyncFizzBase::HandshakeTimeout::transport_.
Referenced by detachEventBase().
|
inline |
Definition at line 132 of file AsyncFizzBase.h.
References folly::AsyncTimeout::detachTimeoutManager(), and handshakeTimeout_.
|
overridepure virtual |
Determine if an error has occurred with this transport.
Implements folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
overridevirtual |
Implements folly::AsyncTransport.
Definition at line 84 of file AsyncFizzBase.cpp.
References appBytesReceived_.
|
overridevirtual |
App data usage accounting.
Implements folly::AsyncTransport.
Definition at line 80 of file AsyncFizzBase.cpp.
References appBytesWritten_.
|
overridepure virtualnoexcept |
Return the application protocol being used by the underlying transport protocol. This is useful for transports which are used to tunnel other protocols.
Reimplemented from folly::AsyncTransport.
Implemented in fizz::test::MockAsyncFizzBase, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >, and fizz::test::AsyncFizzBaseTest.
|
pure virtual |
Get the CipherSuite negotiated in this transport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by fizz::ExportedAuthenticator::getAuthenticator(), and fizz::ExportedAuthenticator::validateAuthenticator().
|
pure virtual |
Get the exported material.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by fizz::ExportedAuthenticator::getAuthenticator(), and fizz::ExportedAuthenticator::validateAuthenticator().
|
overridepure virtual |
Information about the current security state. To be implemented by derived classes.
Reimplemented from folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
overridepure virtual |
Get the certificates in fizz::Cert form.
Reimplemented from folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
overrideprivatevirtual |
ReadCallback implementation.
Implements folly::AsyncReader::ReadCallback.
Definition at line 177 of file AsyncFizzBase.cpp.
References folly::IOBufQueue::preallocate(), and transportReadBuf_.
|
overridevirtual |
App level information for reading/writing app data.
Implements folly::AsyncTransportWrapper.
Definition at line 45 of file AsyncFizzBase.cpp.
References readCallback_.
Referenced by isDetachable().
|
inlineoverridevirtual |
Identify the transport as Fizz.
Reimplemented from folly::AsyncTransport.
Definition at line 122 of file AsyncFizzBase.h.
|
overridepure virtual |
The local certificate used for this connection. May be null
Reimplemented from folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
overridepure virtual |
Get the certificate information of this transport, if any
Reimplemented from folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
pure virtual |
Get the supported signature schemes in this transport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by fizz::ExportedAuthenticator::getAuthenticator().
|
overridepure virtual |
Information about the current transport state. To be implemented by derived classes.
Implements folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by attachEventBase(), and setReadCB().
|
privatenoexcept |
Definition at line 230 of file AsyncFizzBase.cpp.
References folly::AsyncSocketException::TIMED_OUT, and transportError().
Referenced by fizz::AsyncFizzBase::HandshakeTimeout::timeoutExpired().
|
overrideprivatevirtualnoexcept |
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 192 of file AsyncFizzBase.cpp.
|
inlineoverridevirtual |
Determine if the transport can be detached.
This method must be called from the current EventBase's thread.
Implements folly::AsyncTransport.
Reimplemented in fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 149 of file AsyncFizzBase.h.
References cancelHandshakeTimeout(), deliverAppData(), deliverError(), getReadCallback(), handshakeTimeout_, isDetachable(), folly::AsyncTimeout::isScheduled(), folly::NONE, setReadCB(), startHandshakeTimeout(), startTransportReads(), fizz::AsyncFizzBase::HandshakeTimeout::transport_, transportDataAvailable(), transportError(), and writeAppData().
Referenced by fizz::server::AsyncFizzServerT< SM >::isDetachable(), and isDetachable().
|
overridepure virtual |
False if the transport does not have replay protection, but will in the future.
Reimplemented from folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
overridepure virtual |
Determine if the transport is readable or not.
Implements folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
overrideprivatevirtualnoexcept |
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()
readBuf | The unique pointer of read buffer. |
Reimplemented from folly::AsyncReader::ReadCallback.
Definition at line 196 of file AsyncFizzBase.cpp.
References folly::IOBufQueue::append(), checkBufLen(), data, folly::gen::move, transportDataAvailable(), and transportReadBuf_.
|
overrideprivatevirtualnoexcept |
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().
len | The number of bytes placed in the buffer. |
Implements folly::AsyncReader::ReadCallback.
Definition at line 184 of file AsyncFizzBase.cpp.
References checkBufLen(), folly::IOBufQueue::postallocate(), transportDataAvailable(), and transportReadBuf_.
|
overrideprivatevirtualnoexcept |
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 205 of file AsyncFizzBase.cpp.
References folly::AsyncSocketException::END_OF_FILE, and transportError().
|
overrideprivatevirtualnoexcept |
readError() will be invoked if an error occurs reading from the transport.
The read callback will be automatically uninstalled immediately before readError() is invoked.
ex | An exception describing the error that occurred. |
Implements folly::AsyncReader::ReadCallback.
Definition at line 210 of file AsyncFizzBase.cpp.
References transportError().
|
overridevirtual |
Implements folly::AsyncTransportWrapper.
Definition at line 49 of file AsyncFizzBase.cpp.
References appDataBuf_, deliverAppData(), deliverError(), good(), folly::AsyncSocketException::NOT_OPEN, readCallback_, and startTransportReads().
Referenced by detachEventBase(), and isDetachable().
|
overridepure virtual |
Set the ReplaySafeCallback on this transport.
This should only be called if isReplaySafe() returns false.
Reimplemented from folly::AsyncTransport.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
|
protectedvirtual |
Interface for the derived class to schedule a handshake timeout.
transportError() will be called if the timeout fires before it is cancelled.
Definition at line 92 of file AsyncFizzBase.cpp.
References handshakeTimeout_, and folly::AsyncTimeout::scheduleTimeout().
Referenced by fizz::client::AsyncFizzClientT< SM >::connect(), and isDetachable().
|
protectedvirtual |
Start reading raw data from the transport.
Definition at line 88 of file AsyncFizzBase.cpp.
References folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.
Referenced by fizz::server::AsyncFizzServerT< SM >::accept(), attachEventBase(), fizz::client::AsyncFizzClientT< SM >::connect(), fizz::client::AsyncFizzClientT< SM >::connectSuccess(), isDetachable(), and setReadCB().
|
protectedpure virtual |
Alert the derived class that additional data is available in transportReadBuf_.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by isDetachable(), readBufferAvailable(), and readDataAvailable().
|
protectedpure virtual |
Alert the derived class that a transport error occured.
Implemented in fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by handshakeTimeoutExpired(), isDetachable(), readEOF(), readErr(), and writeErr().
|
protectedpure virtual |
Interface for the derived class to implement to receive app data from the app layer.
Implemented in fizz::test::MockAsyncFizzBase, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::server::AsyncFizzServerT< SM >, fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >, and fizz::test::AsyncFizzBaseTest.
Referenced by isDetachable(), and writeChain().
|
overridevirtual |
It only makes sense to use this class if you override writeChain, so force derived classes to do that.
Implements folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper >.
Definition at line 69 of file AsyncFizzBase.cpp.
References appBytesWritten_, folly::gen::move, and writeAppData().
|
overrideprivatevirtualnoexcept |
writeError() will be invoked if an error occurs writing the data.
bytesWritten | The number of bytes that were successfull |
ex | An exception describing the error that occurred. |
Implements folly::AsyncWriter::WriteCallback.
Definition at line 216 of file AsyncFizzBase.cpp.
References transportError().
|
overrideprivatevirtualnoexcept |
WriteCallback implementation, for use with handshake messages.
Implements folly::AsyncWriter::WriteCallback.
Definition at line 214 of file AsyncFizzBase.cpp.
|
private |
Definition at line 236 of file AsyncFizzBase.h.
Referenced by deliverAppData(), and getAppBytesReceived().
|
private |
Definition at line 235 of file AsyncFizzBase.h.
Referenced by getAppBytesWritten(), and writeChain().
|
private |
Definition at line 233 of file AsyncFizzBase.h.
Referenced by checkBufLen(), deliverAppData(), and setReadCB().
|
private |
Definition at line 238 of file AsyncFizzBase.h.
Referenced by attachEventBase(), attachTimeoutManager(), cancelHandshakeTimeout(), detachEventBase(), detachTimeoutManager(), isDetachable(), and startHandshakeTimeout().
|
private |
Definition at line 232 of file AsyncFizzBase.h.
Referenced by attachEventBase(), checkBufLen(), deliverAppData(), deliverError(), getReadCallback(), and setReadCB().
|
protected |
Definition at line 206 of file AsyncFizzBase.h.
Referenced by checkBufLen(), getReadBuffer(), readBufferAvailable(), and readDataAvailable().