proxygen
fizz::client::AsyncFizzClientT< SM > Class Template Reference

#include <AsyncFizzClient.h>

Inheritance diagram for fizz::client::AsyncFizzClientT< SM >:
fizz::AsyncFizzBase folly::AsyncSocket::ConnectCallback folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper > folly::AsyncWriter::WriteCallback folly::AsyncReader::ReadCallback folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper > folly::AsyncTransportWrapper folly::AsyncTransport folly::AsyncReader folly::AsyncWriter folly::DelayedDestruction folly::AsyncSocketBase folly::DelayedDestructionBase fizz::client::test::MockAsyncFizzClient

Classes

class  ActionMoveVisitor
 
struct  EarlyDataState
 
class  HandshakeCallback
 

Public Types

using UniquePtr = std::unique_ptr< AsyncFizzClientT, folly::DelayedDestruction::Destructor >
 
- Public Types inherited from fizz::AsyncFizzBase
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, DestructorUniquePtr
 

Public Member Functions

 AsyncFizzClientT (folly::AsyncTransportWrapper::UniquePtr socket, std::shared_ptr< const FizzClientContext > fizzContext, const std::shared_ptr< ClientExtensions > &extensions=nullptr)
 
 AsyncFizzClientT (folly::EventBase *eventBase, std::shared_ptr< const FizzClientContext > fizzContext, const std::shared_ptr< ClientExtensions > &extensions=nullptr)
 
virtual void connect (HandshakeCallback *callback, std::shared_ptr< const CertificateVerifier > verifier, folly::Optional< std::string > sni, folly::Optional< std::string > pskIdentity, std::chrono::milliseconds=std::chrono::milliseconds(0))
 
virtual void connect (const folly::SocketAddress &connectAddr, folly::AsyncSocket::ConnectCallback *callback, std::shared_ptr< const CertificateVerifier > verifier, folly::Optional< std::string > sni, folly::Optional< std::string > pskIdentity, std::chrono::milliseconds totalTimeout=std::chrono::milliseconds(0), std::chrono::milliseconds socketTimeout=std::chrono::milliseconds(0), const folly::AsyncSocket::OptionMap &options=folly::AsyncSocket::emptyOptionMap, const folly::SocketAddress &bindAddr=folly::AsyncSocket::anyAddress())
 
virtual void connect (HandshakeCallback *callback, folly::Optional< std::string > hostname, std::chrono::milliseconds=std::chrono::milliseconds(0))
 
bool good () const override
 
bool readable () const override
 
bool connecting () const override
 
bool error () const override
 
folly::ssl::X509UniquePtr getPeerCert () const override
 
const X509 * getSelfCert () const override
 
const CertgetPeerCertificate () const override
 
const CertgetSelfCertificate () const override
 
bool isReplaySafe () const override
 
void setReplaySafetyCallback (folly::AsyncTransport::ReplaySafetyCallback *callback) override
 
std::string getApplicationProtocol () const noexceptoverride
 
void close () override
 
void closeWithReset () override
 
void closeNow () override
 
void setEarlyDataRejectionPolicy (EarlyDataRejectionPolicy policy)
 
const StategetState () const
 
folly::Optional< CipherSuitegetCipher () const override
 
std::vector< SignatureSchemegetSupportedSigSchemes () const override
 
Buf getEkm (folly::StringPiece label, const Buf &context, uint16_t length) const override
 
Buf getEarlyEkm (folly::StringPiece label, const Buf &context, uint16_t length) const
 
bool pskResumed () const
 
- Public Member Functions inherited from fizz::AsyncFizzBase
 AsyncFizzBase (folly::AsyncTransportWrapper::UniquePtr transport)
 
 ~AsyncFizzBase () override
 
ReadCallbackgetReadCallback () const override
 
void setReadCB (ReadCallback *callback) override
 
void writeChain (folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE) override
 
size_t getAppBytesWritten () const override
 
size_t getAppBytesReceived () const override
 
void destroy () override
 
std::string getSecurityProtocol () const override
 
void attachTimeoutManager (folly::TimeoutManager *manager)
 
void detachTimeoutManager ()
 
void attachEventBase (folly::EventBase *eventBase) override
 
void detachEventBase () override
 
bool isDetachable () const override
 
- Public Member Functions inherited from folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper >
void write (folly::AsyncTransportWrapper::WriteCallback *callback, const void *buf, size_t bytes, folly::WriteFlags flags=folly::WriteFlags::NONE) override
 
void writev (folly::AsyncTransportWrapper::WriteCallback *callback, const iovec *vec, size_t count, folly::WriteFlags flags=folly::WriteFlags::NONE) override
 
- Public Member Functions inherited from folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >
 DecoratedAsyncTransportWrapper (typename folly::AsyncTransportWrapper::UniquePtr transport)
 
const AsyncTransportWrappergetWrappedTransport () const override
 
ReadCallbackgetReadCallback () const override
 
void setReadCB (folly::AsyncTransportWrapper::ReadCallback *callback) override
 
folly::EventBasegetEventBase () const override
 
void attachEventBase (folly::EventBase *eventBase) override
 
void close () override
 
void closeNow () override
 
void closeWithReset () override
 
bool connecting () const override
 
void detachEventBase () override
 
bool error () const override
 
size_t getAppBytesReceived () const override
 
size_t getAppBytesWritten () const override
 
void getLocalAddress (folly::SocketAddress *address) const override
 
void getPeerAddress (folly::SocketAddress *address) const override
 
folly::ssl::X509UniquePtr getPeerCert () const override
 
size_t getRawBytesReceived () const override
 
size_t getRawBytesWritten () const override
 
uint32_t getSendTimeout () const override
 
bool good () const override
 
bool isDetachable () const override
 
bool isEorTrackingEnabled () const override
 
bool readable () const override
 
bool writable () const override
 
void setEorTracking (bool track) override
 
void setSendTimeout (uint32_t timeoutInMs) override
 
void shutdownWrite () override
 
void shutdownWriteNow () override
 
std::string getApplicationProtocol () const noexceptoverride
 
std::string getSecurityProtocol () const override
 
bool isReplaySafe () const override
 
void setReplaySafetyCallback (folly::AsyncTransport::ReplaySafetyCallback *callback) override
 
const AsyncTransportCertificategetPeerCertificate () const override
 
const AsyncTransportCertificategetSelfCertificate () const override
 
- Public Member Functions inherited from folly::AsyncTransportWrapper
template<class T >
const TgetUnderlyingTransport () const
 
template<class T >
TgetUnderlyingTransport ()
 
- Public Member Functions inherited from folly::AsyncTransport
virtual bool isPending () const
 
SocketAddress getLocalAddress () const
 
void getAddress (SocketAddress *address) const override
 
SocketAddress getPeerAddress () const
 
- Public Member Functions inherited from folly::DelayedDestruction
bool getDestroyPending () const
 
- Public Member Functions inherited from folly::DelayedDestructionBase
virtual ~DelayedDestructionBase ()=default
 
- Public Member Functions inherited from folly::AsyncSocketBase
virtual ~AsyncSocketBase ()=default
 

Protected Member Functions

void writeAppData (folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE) override
 
void transportError (const folly::AsyncSocketException &ex) override
 
void transportDataAvailable () override
 
- Protected Member Functions inherited from fizz::AsyncFizzBase
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)
 
- 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
 

Private Member Functions

void deliverAllErrors (const folly::AsyncSocketException &ex, bool closeTransport=true)
 
void deliverHandshakeError (folly::exception_wrapper ex)
 
void connectErr (const folly::AsyncSocketException &ex) noexceptoverride
 
void connectSuccess () noexceptoverride
 
folly::Optional< folly::AsyncSocketExceptionhandleEarlyReject ()
 
- Private Member Functions inherited from folly::AsyncSocket::ConnectCallback
virtual ~ConnectCallback ()=default
 

Private Attributes

folly::Optional< boost::variant< HandshakeCallback *, folly::AsyncSocket::ConnectCallback * > > callback_
 
std::shared_ptr< const FizzClientContextfizzContext_
 
std::shared_ptr< ClientExtensionsextensions_
 
folly::Optional< std::stringsni_
 
folly::Optional< std::stringpskIdentity_
 
State state_
 
ActionMoveVisitor visitor_
 
FizzClient< ActionMoveVisitor, SM > fizzClient_
 
folly::Optional< EarlyDataStateearlyDataState_
 
EarlyDataRejectionPolicy earlyDataRejectionPolicy_
 
folly::AsyncTransport::ReplaySafetyCallbackreplaySafetyCallback_ {nullptr}
 
std::shared_ptr< const CertificateVerifierverifier_
 

Additional Inherited Members

- Protected Attributes inherited from fizz::AsyncFizzBase
folly::IOBufQueue transportReadBuf_ {folly::IOBufQueue::cacheChainLength()}
 
- Protected Attributes inherited from folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >
folly::AsyncTransportWrapper::UniquePtr transport_
 

Detailed Description

template<typename SM>
class fizz::client::AsyncFizzClientT< SM >

Definition at line 23 of file AsyncFizzClient.h.

Member Typedef Documentation

Definition at line 38 of file AsyncFizzClient.h.

Constructor & Destructor Documentation

template<typename SM >
fizz::client::AsyncFizzClientT< SM >::AsyncFizzClientT ( folly::AsyncTransportWrapper::UniquePtr  socket,
std::shared_ptr< const FizzClientContext fizzContext,
const std::shared_ptr< ClientExtensions > &  extensions = nullptr 
)

Creates an AsyncFizzClient using an open socket. Connections are made using connect() APIs taking a HandshakeCallback.

Definition at line 13 of file AsyncFizzClient-inl.h.

18  fizzContext_(std::move(fizzContext)),
19  extensions_(extensions),
20  visitor_(*this),
std::shared_ptr< const FizzClientContext > fizzContext_
folly::IOBufQueue transportReadBuf_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AsyncFizzBase(folly::AsyncTransportWrapper::UniquePtr transport)
FizzClient< ActionMoveVisitor, SM > fizzClient_
std::shared_ptr< ClientExtensions > extensions_
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
template<typename SM >
fizz::client::AsyncFizzClientT< SM >::AsyncFizzClientT ( folly::EventBase eventBase,
std::shared_ptr< const FizzClientContext fizzContext,
const std::shared_ptr< ClientExtensions > &  extensions = nullptr 
)

Creates an AsyncFizzClient using an event base. This will open the socket for you when you call the connec() API taking a SocketAddress and ConnectCallback.

Definition at line 24 of file AsyncFizzClient-inl.h.

28  : AsyncFizzBase(
30  fizzContext_(std::move(fizzContext)),
31  extensions_(extensions),
32  visitor_(*this),
std::shared_ptr< const FizzClientContext > fizzContext_
folly::IOBufQueue transportReadBuf_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AsyncFizzBase(folly::AsyncTransportWrapper::UniquePtr transport)
FizzClient< ActionMoveVisitor, SM > fizzClient_
std::shared_ptr< ClientExtensions > extensions_
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
Definition: AsyncSocket.h:83

Member Function Documentation

template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::close ( )
overridevirtual

Close the transport.

This gracefully closes the transport, waiting for all pending write requests to complete before actually closing the underlying transport.

If a read callback is set, readEOF() will be called immediately. If there are outstanding write requests, the close will be delayed until all remaining writes have completed. No new writes may be started after close() has been called.

Implements folly::AsyncTransport.

Definition at line 216 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), folly::AsyncSocketException::END_OF_FILE, fizz::client::AsyncFizzClientT< SM >::fizzClient_, and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

216  {
217  if (transport_->good()) {
218  fizzClient_.appClose();
219  } else {
220  DelayedDestruction::DestructorGuard dg(this);
222  folly::AsyncSocketException::END_OF_FILE, "socket closed locally");
223  deliverAllErrors(ase, false);
224  transport_->close();
225  }
226 }
FizzClient< ActionMoveVisitor, SM > fizzClient_
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::closeNow ( )
overridevirtual

Close the transport immediately.

This closes the transport immediately, dropping any outstanding data waiting to be written.

If a read callback is set, readEOF() will be called immediately. If there are outstanding write requests, these requests will be aborted and writeError() will be invoked immediately on all outstanding write callbacks.

Implements folly::AsyncTransport.

Definition at line 241 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), folly::AsyncSocketException::END_OF_FILE, fizz::client::AsyncFizzClientT< SM >::fizzClient_, and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

241  {
242  DelayedDestruction::DestructorGuard dg(this);
243  if (transport_->good()) {
244  fizzClient_.appClose();
245  }
247  folly::AsyncSocketException::END_OF_FILE, "socket closed locally");
248  deliverAllErrors(ase, false);
249  transport_->closeNow();
250 }
FizzClient< ActionMoveVisitor, SM > fizzClient_
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::closeWithReset ( )
overridevirtual

Reset the transport immediately.

This closes the transport immediately, sending a reset to the remote peer if possible to indicate abnormal shutdown.

Note that not all subclasses implement this reset functionality: some subclasses may treat reset() the same as closeNow(). Subclasses that use TCP transports should terminate the connection with a TCP reset.

Reimplemented from folly::AsyncTransport.

Definition at line 229 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), folly::AsyncSocketException::END_OF_FILE, fizz::client::AsyncFizzClientT< SM >::fizzClient_, and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

229  {
230  DelayedDestruction::DestructorGuard dg(this);
231  if (transport_->good()) {
232  fizzClient_.appClose();
233  }
235  folly::AsyncSocketException::END_OF_FILE, "socket closed locally");
236  deliverAllErrors(ase, false);
237  transport_->closeWithReset();
238 }
FizzClient< ActionMoveVisitor, SM > fizzClient_
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::connect ( HandshakeCallback callback,
std::shared_ptr< const CertificateVerifier verifier,
folly::Optional< std::string sni,
folly::Optional< std::string pskIdentity,
std::chrono::milliseconds  timeout = std::chrono::milliseconds(0) 
)
virtual

Performs a TLS handshake using the open socket passed into the constructor.

Definition at line 50 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::callback_, fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), fizz::client::AsyncFizzClientT< SM >::extensions_, fizz::client::AsyncFizzClientT< SM >::fizzClient_, fizz::client::AsyncFizzClientT< SM >::fizzContext_, folly::gen::move, folly::none, folly::AsyncSocketException::NOT_OPEN, fizz::client::AsyncFizzClientT< SM >::pskIdentity_, sni, fizz::client::AsyncFizzClientT< SM >::sni_, fizz::AsyncFizzBase::startHandshakeTimeout(), fizz::AsyncFizzBase::startTransportReads(), and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

Referenced by fizz::client::AsyncFizzClientT< SM >::connect().

55  {
56  DelayedDestruction::DestructorGuard dg(this);
57 
58  CHECK(callback);
59  CHECK(!callback_);
60  callback_ = callback;
61 
62  if (!transport_->good()) {
65  "handshake connect called but socket isn't open");
66  deliverAllErrors(ase, false);
67  return;
68  }
69 
70  sni_ = sni;
71  pskIdentity_ = pskIdentity;
72 
73  if (timeout != std::chrono::milliseconds::zero()) {
74  startHandshakeTimeout(timeout);
75  }
76 
78 
80  if (pskIdentity) {
81  cachedPsk = fizzContext_->getPsk(*pskIdentity);
82  }
83  fizzClient_.connect(
85  std::move(verifier),
86  std::move(sni),
87  std::move(cachedPsk),
88  extensions_);
89 }
std::shared_ptr< const FizzClientContext > fizzContext_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void startHandshakeTimeout(std::chrono::milliseconds)
FizzClient< ActionMoveVisitor, SM > fizzClient_
folly::Optional< boost::variant< HandshakeCallback *, folly::AsyncSocket::ConnectCallback * > > callback_
std::shared_ptr< ClientExtensions > extensions_
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
virtual void startTransportReads()
StringPiece sni
folly::Optional< std::string > pskIdentity_
folly::Optional< std::string > sni_
constexpr None none
Definition: Optional.h:87
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::connect ( const folly::SocketAddress connectAddr,
folly::AsyncSocket::ConnectCallback callback,
std::shared_ptr< const CertificateVerifier verifier,
folly::Optional< std::string sni,
folly::Optional< std::string pskIdentity,
std::chrono::milliseconds  totalTimeout = std::chrono::milliseconds(0),
std::chrono::milliseconds  socketTimeout = std::chrono::milliseconds(0),
const folly::AsyncSocket::OptionMap options = folly::AsyncSocket::emptyOptionMap,
const folly::SocketAddress bindAddr = folly::AsyncSocket::anyAddress() 
)
virtual

Opens a socket to the given address and performs a TLS handshake.

Definition at line 92 of file AsyncFizzClient-inl.h.

References folly::AsyncSocketException::BAD_ARGS, fizz::client::AsyncFizzClientT< SM >::callback_, fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), folly::AsyncSocket::disableTransparentTls(), folly::gen::move, fizz::client::AsyncFizzClientT< SM >::pskIdentity_, sni, fizz::client::AsyncFizzClientT< SM >::sni_, fizz::AsyncFizzBase::startHandshakeTimeout(), folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_, and fizz::client::AsyncFizzClientT< SM >::verifier_.

101  {
102  DelayedDestruction::DestructorGuard dg(this);
103 
104  CHECK(callback);
105  CHECK(!callback_);
106  callback_ = callback;
107 
108  verifier_ = std::move(verifier);
109  sni_ = sni;
110  pskIdentity_ = pskIdentity;
111 
112  if (totalTimeout != std::chrono::milliseconds::zero()) {
113  startHandshakeTimeout(std::move(totalTimeout));
114  }
115 
116  auto underlyingSocket =
117  transport_->getUnderlyingTransport<folly::AsyncSocket>();
118  if (underlyingSocket) {
119  underlyingSocket->disableTransparentTls();
120  underlyingSocket->connect(
121  this,
122  connectAddr,
123  static_cast<int>(socketTimeout.count()),
124  options,
125  bindAddr);
126  } else {
129  "could not find underlying socket");
130  deliverAllErrors(ase, false);
131  }
132 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void startHandshakeTimeout(std::chrono::milliseconds)
folly::Optional< boost::variant< HandshakeCallback *, folly::AsyncSocket::ConnectCallback * > > callback_
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
void disableTransparentTls()
Definition: AsyncSocket.h:789
std::shared_ptr< const CertificateVerifier > verifier_
StringPiece sni
folly::Optional< std::string > pskIdentity_
folly::Optional< std::string > sni_
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::connect ( HandshakeCallback callback,
folly::Optional< std::string hostname,
std::chrono::milliseconds  timeout = std::chrono::milliseconds(0) 
)
virtual

Variant of the TLS handshake connect() API above that uses the default certificate verifier implementation.

Definition at line 36 of file AsyncFizzClient-inl.h.

References fizz::Client, fizz::client::AsyncFizzClientT< SM >::connect(), and folly::gen::move.

39  {
40  auto pskIdentity = hostname;
41  connect(
42  callback,
43  std::make_shared<DefaultCertificateVerifier>(VerificationContext::Client),
44  std::move(hostname),
45  std::move(pskIdentity),
46  std::move(timeout));
47 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void connect(HandshakeCallback *callback, std::shared_ptr< const CertificateVerifier > verifier, folly::Optional< std::string > sni, folly::Optional< std::string > pskIdentity, std::chrono::milliseconds=std::chrono::milliseconds(0))
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::connectErr ( const folly::AsyncSocketException ex)
overrideprivatevirtualnoexcept

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

Parameters
exAn exception describing the error that occurred.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 269 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::deliverAllErrors().

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

270  {
271  deliverAllErrors(ex, false);
272 }
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
template<typename SM >
bool fizz::client::AsyncFizzClientT< SM >::connecting ( ) const
overridevirtual

Determine if transport is connected to the endpoint

Returns
false iff the transport is connected, otherwise true

Implements fizz::AsyncFizzBase.

Definition at line 145 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::callback_, and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

145  {
146  return callback_ || transport_->connecting();
147 }
folly::Optional< boost::variant< HandshakeCallback *, folly::AsyncSocket::ConnectCallback * > > callback_
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::connectSuccess ( )
overrideprivatevirtualnoexcept

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

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 253 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::extensions_, fizz::client::AsyncFizzClientT< SM >::fizzClient_, fizz::client::AsyncFizzClientT< SM >::fizzContext_, folly::gen::move, folly::none, fizz::client::AsyncFizzClientT< SM >::pskIdentity_, fizz::client::AsyncFizzClientT< SM >::sni_, fizz::AsyncFizzBase::startTransportReads(), and fizz::client::AsyncFizzClientT< SM >::verifier_.

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

253  {
255 
257  if (pskIdentity_) {
258  cachedPsk = fizzContext_->getPsk(*pskIdentity_);
259  }
260  fizzClient_.connect(
261  fizzContext_,
263  sni_,
264  std::move(cachedPsk),
265  extensions_);
266 }
std::shared_ptr< const FizzClientContext > fizzContext_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FizzClient< ActionMoveVisitor, SM > fizzClient_
std::shared_ptr< ClientExtensions > extensions_
virtual void startTransportReads()
std::shared_ptr< const CertificateVerifier > verifier_
folly::Optional< std::string > pskIdentity_
folly::Optional< std::string > sni_
constexpr None none
Definition: Optional.h:87
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::deliverAllErrors ( const folly::AsyncSocketException ex,
bool  closeTransport = true 
)
private

Definition at line 344 of file AsyncFizzClient-inl.h.

References fizz::AsyncFizzBase::deliverError(), fizz::client::AsyncFizzClientT< SM >::deliverHandshakeError(), fizz::client::AsyncFizzClientT< SM >::earlyDataState_, fizz::client::AsyncFizzClientT< SM >::fizzClient_, folly::gen::move, and fizz::client::AsyncFizzClientT< SM >::replaySafetyCallback_.

Referenced by fizz::client::AsyncFizzClientT< SM >::close(), fizz::client::AsyncFizzClientT< SM >::closeNow(), fizz::client::AsyncFizzClientT< SM >::closeWithReset(), fizz::client::AsyncFizzClientT< SM >::connect(), fizz::client::AsyncFizzClientT< SM >::connectErr(), fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState(), and fizz::client::AsyncFizzClientT< SM >::transportError().

346  {
347  DelayedDestruction::DestructorGuard dg(this);
349 
350  if (replaySafetyCallback_) {
351  replaySafetyCallback_ = nullptr;
352  }
353 
354  while (earlyDataState_ && !earlyDataState_->pendingAppWrites.empty()) {
355  auto w = std::move(earlyDataState_->pendingAppWrites.front());
356  earlyDataState_->pendingAppWrites.pop_front();
357  if (w.callback) {
358  w.callback->writeErr(0, ex);
359  }
360  }
361  fizzClient_.moveToErrorState(ex);
362  deliverError(ex, closeTransport);
363 }
virtual void deliverError(const folly::AsyncSocketException &ex, bool closeTransport=true)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::AsyncTransport::ReplaySafetyCallback * replaySafetyCallback_
FizzClient< ActionMoveVisitor, SM > fizzClient_
folly::Optional< EarlyDataState > earlyDataState_
void deliverHandshakeError(folly::exception_wrapper ex)
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::deliverHandshakeError ( folly::exception_wrapper  ex)
private

Definition at line 366 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::callback_, fizz::AsyncFizzBase::cancelHandshakeTimeout(), fizz::client::AsyncFizzClientT< SM >::HandshakeCallback::fizzHandshakeError(), folly::exception_wrapper::handle(), folly::gen::move, folly::none, folly::AsyncSocketException::SSL_ERROR, and folly::variant_match().

Referenced by fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), and fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

366  {
367  if (callback_) {
369  auto cb = *callback_;
372  cb,
373  [this, &ex](HandshakeCallback* callback) {
374  callback->fizzHandshakeError(this, std::move(ex));
375  },
376  [&ex](folly::AsyncSocket::ConnectCallback* callback) {
377  ex.handle(
378  [callback](const folly::AsyncSocketException& ase) {
379  callback->connectErr(ase);
380  },
381  [callback](const std::exception& stdEx) {
384  callback->connectErr(ase);
385  },
386  [callback](...) {
388  folly::AsyncSocketException::SSL_ERROR, "unknown error");
389  callback->connectErr(ase);
390  });
391  });
392  }
393 }
void handle(CatchFns...fns)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void cancelHandshakeTimeout()
folly::Optional< boost::variant< HandshakeCallback *, folly::AsyncSocket::ConnectCallback * > > callback_
decltype(auto) variant_match(Variant &&variant, Cases &&...cases)
Definition: Overload.h:74
constexpr None none
Definition: Optional.h:87
template<typename SM >
bool fizz::client::AsyncFizzClientT< SM >::error ( ) const
overridevirtual

Determine if an error has occurred with this transport.

Returns
true iff an error has occurred (not EOF).

Implements fizz::AsyncFizzBase.

Definition at line 150 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::fizzClient_, and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

Referenced by fizz::client::AsyncFizzClientT< SM >::good(), and fizz::client::AsyncFizzClientT< SM >::writeAppData().

150  {
151  return transport_->error() || fizzClient_.inErrorState();
152 }
FizzClient< ActionMoveVisitor, SM > fizzClient_
template<typename SM >
std::string fizz::client::AsyncFizzClientT< SM >::getApplicationProtocol ( ) const
overridevirtualnoexcept

Return the application protocol being used by the underlying transport protocol. This is useful for transports which are used to tunnel other protocols.

Implements fizz::AsyncFizzBase.

Definition at line 199 of file AsyncFizzClient-inl.h.

References alpn, fizz::client::State::alpn(), fizz::client::State::earlyDataParams(), fizz::client::AsyncFizzClientT< SM >::earlyDataState_, and fizz::client::AsyncFizzClientT< SM >::getState().

199  {
200  if (earlyDataState_) {
201  if (getState().earlyDataParams()->alpn) {
202  return *getState().earlyDataParams()->alpn;
203  } else {
204  return "";
205  }
206  } else {
207  if (getState().alpn()) {
208  return *getState().alpn();
209  } else {
210  return "";
211  }
212  }
213 }
StringPiece alpn
const folly::Optional< std::string > & alpn() const
Definition: State.h:170
const folly::Optional< EarlyDataParams > & earlyDataParams() const
Definition: State.h:163
folly::Optional< EarlyDataState > earlyDataState_
const State & getState() const
template<typename SM >
folly::Optional< CipherSuite > fizz::client::AsyncFizzClientT< SM >::getCipher ( ) const
overridevirtual

Get the CipherSuite negotiated in this transport.

Implements fizz::AsyncFizzBase.

Definition at line 548 of file AsyncFizzClient-inl.h.

References fizz::client::State::cipher(), and fizz::client::AsyncFizzClientT< SM >::getState().

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

548  {
549  return getState().cipher();
550 }
folly::Optional< CipherSuite > cipher() const
Definition: State.h:113
const State & getState() const
template<typename SM >
Buf fizz::client::AsyncFizzClientT< SM >::getEarlyEkm ( folly::StringPiece  label,
const Buf context,
uint16_t  length 
) const

Definition at line 567 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::fizzClient_.

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

570  {
571  return fizzClient_.getEarlyEkm(label, context, length);
572 }
context
Definition: CMakeCache.txt:563
FizzClient< ActionMoveVisitor, SM > fizzClient_
template<typename SM >
Buf fizz::client::AsyncFizzClientT< SM >::getEkm ( folly::StringPiece  label,
const Buf context,
uint16_t  length 
) const
overridevirtual

Get the exported material.

Implements fizz::AsyncFizzBase.

Definition at line 559 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::fizzClient_.

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

562  {
563  return fizzClient_.getEkm(label, context, length);
564 }
context
Definition: CMakeCache.txt:563
FizzClient< ActionMoveVisitor, SM > fizzClient_
template<typename SM >
folly::ssl::X509UniquePtr fizz::client::AsyncFizzClientT< SM >::getPeerCert ( ) const
overridevirtual

Information about the current security state. To be implemented by derived classes.

Implements fizz::AsyncFizzBase.

Definition at line 155 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::getPeerCertificate(), and serverCert.

155  {
157  if (serverCert) {
158  return serverCert->getX509();
159  } else {
160  return nullptr;
161  }
162 }
std::shared_ptr< const Cert > serverCert
const Cert * getPeerCertificate() const override
template<typename SM >
const Cert * fizz::client::AsyncFizzClientT< SM >::getPeerCertificate ( ) const
overridevirtual

Get the certificates in fizz::Cert form.

Implements fizz::AsyncFizzBase.

Definition at line 175 of file AsyncFizzClient-inl.h.

References fizz::client::State::earlyDataParams(), fizz::client::AsyncFizzClientT< SM >::earlyDataState_, fizz::client::AsyncFizzClientT< SM >::getState(), and fizz::client::State::serverCert().

Referenced by fizz::client::AsyncFizzClientT< SM >::getPeerCert().

175  {
176  return earlyDataState_ ? getState().earlyDataParams()->serverCert.get()
177  : getState().serverCert().get();
178 }
const folly::Optional< EarlyDataParams > & earlyDataParams() const
Definition: State.h:163
folly::Optional< EarlyDataState > earlyDataState_
std::shared_ptr< const Cert > serverCert() const
Definition: State.h:77
const State & getState() const
template<typename SM >
const X509 * fizz::client::AsyncFizzClientT< SM >::getSelfCert ( ) const
overridevirtual

The local certificate used for this connection. May be null

Implements fizz::AsyncFizzBase.

Definition at line 165 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::getSelfCertificate().

165  {
166  auto cert = getSelfCertificate();
167  if (cert) {
168  return cert->getX509().get();
169  } else {
170  return nullptr;
171  }
172 }
const Cert * getSelfCertificate() const override
template<typename SM >
const Cert * fizz::client::AsyncFizzClientT< SM >::getSelfCertificate ( ) const
overridevirtual

Get the certificate information of this transport, if any

Implements fizz::AsyncFizzBase.

Definition at line 181 of file AsyncFizzClient-inl.h.

References fizz::client::State::clientCert(), fizz::client::State::earlyDataParams(), fizz::client::AsyncFizzClientT< SM >::earlyDataState_, and fizz::client::AsyncFizzClientT< SM >::getState().

Referenced by fizz::client::AsyncFizzClientT< SM >::getSelfCert().

181  {
182  return earlyDataState_ ? getState().earlyDataParams()->clientCert.get()
183  : getState().clientCert().get();
184 }
std::shared_ptr< const Cert > clientCert() const
Definition: State.h:84
const folly::Optional< EarlyDataParams > & earlyDataParams() const
Definition: State.h:163
folly::Optional< EarlyDataState > earlyDataState_
const State & getState() const
template<typename SM >
std::vector< SignatureScheme > fizz::client::AsyncFizzClientT< SM >::getSupportedSigSchemes ( ) const
overridevirtual

Get the supported signature schemes in this transport.

Implements fizz::AsyncFizzBase.

Definition at line 553 of file AsyncFizzClient-inl.h.

References fizz::client::State::context(), fizz::client::AsyncFizzClientT< SM >::getState(), and fizz::client::FizzClientContext::getSupportedSigSchemes().

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

554  {
556 }
const auto & getSupportedSigSchemes() const
const FizzClientContext * context() const
Definition: State.h:70
const State & getState() const
template<typename SM >
bool fizz::client::AsyncFizzClientT< SM >::good ( ) const
overridevirtual

Information about the current transport state. To be implemented by derived classes.

Implements fizz::AsyncFizzBase.

Definition at line 135 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::error(), and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

135  {
136  return !error() && transport_->good();
137 }
template<typename SM >
folly::Optional< folly::AsyncSocketException > fizz::client::AsyncFizzClientT< SM >::handleEarlyReject ( )
private

Definition at line 431 of file AsyncFizzClient-inl.h.

References fizz::client::AutomaticResend, fizz::AppWrite::data, folly::AsyncSocketException::EARLY_DATA_REJECTED, fizz::client::AsyncFizzClientT< SM >::earlyDataRejectionPolicy_, fizz::client::AsyncFizzClientT< SM >::earlyDataState_, fizz::client::earlyParametersMatch(), fizz::client::FatalConnectionError, fizz::client::AsyncFizzClientT< SM >::fizzClient_, fizz::client::AsyncFizzClientT< SM >::getState(), folly::gen::move, and folly::none.

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

431  {
432  switch (earlyDataRejectionPolicy_) {
436  "fizz early data rejected");
437  }
440  if (!earlyDataState_->resendBuffer.empty()) {
441  AppWrite resend;
442  resend.data = earlyDataState_->resendBuffer.move();
443  fizzClient_.appWrite(std::move(resend));
444  }
445  } else {
448  "fizz early data rejected, could not be resent");
449  }
450  break;
451  }
452  }
453  return folly::none;
454 }
EarlyDataRejectionPolicy earlyDataRejectionPolicy_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FizzClient< ActionMoveVisitor, SM > fizzClient_
bool earlyParametersMatch(const State &state)
folly::Optional< EarlyDataState > earlyDataState_
const State & getState() const
constexpr None none
Definition: Optional.h:87
template<typename SM >
bool fizz::client::AsyncFizzClientT< SM >::isReplaySafe ( ) const
overridevirtual

False if the transport does not have replay protection, but will in the future.

Implements fizz::AsyncFizzBase.

Definition at line 187 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::earlyDataState_.

Referenced by fizz::client::AsyncFizzClientT< SM >::setReplaySafetyCallback().

187  {
188  return !earlyDataState_.hasValue();
189 }
folly::Optional< EarlyDataState > earlyDataState_
template<typename SM >
bool fizz::client::AsyncFizzClientT< SM >::pskResumed ( ) const

Definition at line 575 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::getState(), folly::Optional< Value >::has_value(), and fizz::client::State::pskMode().

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

575  {
576  return getState().pskMode().has_value();
577 }
FOLLY_CPP14_CONSTEXPR bool has_value() const noexcept
Definition: Optional.h:296
folly::Optional< PskKeyExchangeMode > pskMode() const
Definition: State.h:142
const State & getState() const
template<typename SM >
bool fizz::client::AsyncFizzClientT< SM >::readable ( ) const
overridevirtual

Determine if the transport is readable or not.

Returns
true iff the transport is readable, false otherwise.

Implements fizz::AsyncFizzBase.

Definition at line 140 of file AsyncFizzClient-inl.h.

References folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

140  {
141  return transport_->readable();
142 }
template<typename SM>
void fizz::client::AsyncFizzClientT< SM >::setEarlyDataRejectionPolicy ( EarlyDataRejectionPolicy  policy)
inline

Set the policy for dealing with rejected early data.

Note that early data must be also be enabled on the FizzClientContext for early data to be used.

Definition at line 119 of file AsyncFizzClient.h.

119  {
120  CHECK(!earlyDataState_);
121  earlyDataRejectionPolicy_ = policy;
122  }
EarlyDataRejectionPolicy earlyDataRejectionPolicy_
folly::Optional< EarlyDataState > earlyDataState_
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::setReplaySafetyCallback ( folly::AsyncTransport::ReplaySafetyCallback callback)
overridevirtual

Set the ReplaySafeCallback on this transport.

This should only be called if isReplaySafe() returns false.

Implements fizz::AsyncFizzBase.

Definition at line 192 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::isReplaySafe(), and fizz::client::AsyncFizzClientT< SM >::replaySafetyCallback_.

193  {
194  DCHECK(!callback || !isReplaySafe());
195  replaySafetyCallback_ = callback;
196 }
bool isReplaySafe() const override
folly::AsyncTransport::ReplaySafetyCallback * replaySafetyCallback_
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::transportDataAvailable ( )
overrideprotectedvirtual

Alert the derived class that additional data is available in transportReadBuf_.

Implements fizz::AsyncFizzBase.

Definition at line 339 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::fizzClient_.

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

339  {
340  fizzClient_.newTransportData();
341 }
FizzClient< ActionMoveVisitor, SM > fizzClient_
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::transportError ( const folly::AsyncSocketException ex)
overrideprotectedvirtual

Alert the derived class that a transport error occured.

Implements fizz::AsyncFizzBase.

Definition at line 332 of file AsyncFizzClient-inl.h.

References fizz::client::AsyncFizzClientT< SM >::deliverAllErrors().

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

333  {
334  DelayedDestruction::DestructorGuard dg(this);
335  deliverAllErrors(ex);
336 }
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
template<typename SM >
void fizz::client::AsyncFizzClientT< SM >::writeAppData ( folly::AsyncTransportWrapper::WriteCallback callback,
std::unique_ptr< folly::IOBuf > &&  buf,
folly::WriteFlags  flags = folly::WriteFlags::NONE 
)
overrideprotectedvirtual

Interface for the derived class to implement to receive app data from the app layer.

Implements fizz::AsyncFizzBase.

Definition at line 275 of file AsyncFizzClient-inl.h.

References fizz::client::AutomaticResend, fizz::EarlyAppWrite::callback, fizz::AppWrite::callback, fizz::EarlyAppWrite::data, fizz::AppWrite::data, fizz::client::AsyncFizzClientT< SM >::earlyDataRejectionPolicy_, fizz::client::AsyncFizzClientT< SM >::earlyDataState_, fizz::client::AsyncFizzClientT< SM >::error(), fizz::client::AsyncFizzClientT< SM >::fizzClient_, fizz::EarlyAppWrite::flags, fizz::AppWrite::flags, folly::AsyncSocketException::INVALID_STATE, folly::gen::move, folly::size(), and folly::AsyncWriter::WriteCallback::writeErr().

Referenced by fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >::getState().

278  {
279  if (error()) {
280  if (callback) {
281  callback->writeErr(
282  0,
285  "fizz app write in error state"));
286  }
287  return;
288  }
289 
290  if (earlyDataState_) {
291  auto size = buf->computeChainDataLength();
292  if (!earlyDataState_->pendingAppWrites.empty() ||
293  size > earlyDataState_->remainingEarlyData) {
294  AppWrite w;
295  w.callback = callback;
296  w.data = std::move(buf);
297  w.flags = flags;
298 
299  earlyDataState_->remainingEarlyData = 0;
300  earlyDataState_->pendingAppWrites.push_back(std::move(w));
301  } else {
302  EarlyAppWrite w;
303  w.callback = callback;
304  w.data = std::move(buf);
305  w.flags = flags;
306 
309  // We need to call unshare() to make a copy of the data here since we
310  // may need to resend it after we've already called writeSuccess().
311  // Particularly when using the write and writev interfaces, the
312  // application is allowed to delete the underlying buffer after getting
313  // the write callback.
314  auto writeCopy = w.data->clone();
315  writeCopy->unshare();
316  earlyDataState_->resendBuffer.append(std::move(writeCopy));
317  }
318 
319  earlyDataState_->remainingEarlyData -= size;
320  fizzClient_.earlyAppWrite(std::move(w));
321  }
322  } else {
323  AppWrite w;
324  w.callback = callback;
325  w.data = std::move(buf);
326  w.flags = flags;
327  fizzClient_.appWrite(std::move(w));
328  }
329 }
flags
Definition: http_parser.h:127
EarlyDataRejectionPolicy earlyDataRejectionPolicy_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
FizzClient< ActionMoveVisitor, SM > fizzClient_
folly::Optional< EarlyDataState > earlyDataState_
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
virtual void writeErr(size_t bytesWritten, const AsyncSocketException &ex) noexcept=0

Member Data Documentation

template<typename SM>
std::shared_ptr<ClientExtensions> fizz::client::AsyncFizzClientT< SM >::extensions_
private
template<typename SM>
std::shared_ptr<const FizzClientContext> fizz::client::AsyncFizzClientT< SM >::fizzContext_
private
template<typename SM>
std::shared_ptr<const CertificateVerifier> fizz::client::AsyncFizzClientT< SM >::verifier_
private
template<typename SM>
ActionMoveVisitor fizz::client::AsyncFizzClientT< SM >::visitor_
private

Definition at line 197 of file AsyncFizzClient.h.


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