proxygen
AsyncFizzBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <fizz/record/Types.h>
12 #include <folly/io/IOBufQueue.h>
15 
16 namespace fizz {
17 
19 
25  folly::AsyncTransportWrapper>,
28  public:
29  using UniquePtr =
30  std::unique_ptr<AsyncFizzBase, folly::DelayedDestruction::Destructor>;
32 
34  public:
36  : folly::AsyncTimeout(eventBase), transport_(transport) {}
37 
38  ~HandshakeTimeout() override = default;
39 
40  void timeoutExpired() noexcept override {
42  }
43 
44  private:
46  };
47 
49 
50  ~AsyncFizzBase() override;
51 
55  ReadCallback* getReadCallback() const override;
56  void setReadCB(ReadCallback* callback) override;
57  void writeChain(
59  std::unique_ptr<folly::IOBuf>&& buf,
61 
65  size_t getAppBytesWritten() const override;
66  size_t getAppBytesReceived() const override;
67 
72  bool good() const override = 0;
73  bool readable() const override = 0;
74  bool connecting() const override = 0;
75  bool error() const override = 0;
76 
81  folly::ssl::X509UniquePtr getPeerCert() const override = 0;
82  const X509* getSelfCert() const override = 0;
83 
87  const Cert* getPeerCertificate() const override = 0;
88 
89  const Cert* getSelfCertificate() const override = 0;
90 
91  bool isReplaySafe() const override = 0;
93  folly::AsyncTransport::ReplaySafetyCallback* callback) override = 0;
95 
99  virtual folly::Optional<CipherSuite> getCipher() const = 0;
100 
104  virtual std::vector<SignatureScheme> getSupportedSigSchemes() const = 0;
105 
109  virtual Buf getEkm(
111  const Buf& context,
112  uint16_t length) const = 0;
113 
117  void destroy() override;
118 
122  std::string getSecurityProtocol() const override {
123  return "Fizz";
124  }
125 
131  }
134  }
135  void attachEventBase(folly::EventBase* eventBase) override {
137  transport_->attachEventBase(eventBase);
138  // we want to avoid setting a read cb on a bad transport (i.e. closed or
139  // disconnected) unless we have a read callback we can pass the errors to.
140  if (transport_->good() || readCallback_) {
142  }
143  }
144  void detachEventBase() override {
146  transport_->setReadCB(nullptr);
148  }
149  bool isDetachable() const override {
151  return false;
152  }
153  // Since we always have a read callback on the underlying transport,
154  // transport_->isDetachable() would always return false. We need to see if
155  // the transport is detachable independent of our callback.
156  auto readCb = transport_->getReadCallback();
157  transport_->setReadCB(nullptr);
158  auto result = transport_->isDetachable();
159  transport_->setReadCB(readCb);
160  return result;
161  }
162 
163  protected:
167  virtual void startTransportReads();
168 
175  virtual void startHandshakeTimeout(std::chrono::milliseconds);
176  virtual void cancelHandshakeTimeout();
177 
182  virtual void deliverAppData(std::unique_ptr<folly::IOBuf> buf);
183  virtual void deliverError(
184  const folly::AsyncSocketException& ex,
185  bool closeTransport = true);
186 
191  virtual void writeAppData(
193  std::unique_ptr<folly::IOBuf>&& buf,
195 
199  virtual void transportError(const folly::AsyncSocketException& ex) = 0;
204  virtual void transportDataAvailable() = 0;
205 
207 
208  private:
212  void getReadBuffer(void** bufReturn, size_t* lenReturn) override;
213  void readDataAvailable(size_t len) noexcept override;
214  bool isBufferMovable() noexcept override;
215  void readBufferAvailable(
216  std::unique_ptr<folly::IOBuf> data) noexcept override;
217  void readEOF() noexcept override;
218  void readErr(const folly::AsyncSocketException& ex) noexcept override;
219 
223  void writeSuccess() noexcept override;
224  void writeErr(
225  size_t bytesWritten,
226  const folly::AsyncSocketException& ex) noexcept override;
227 
228  void checkBufLen();
229 
231 
233  std::unique_ptr<folly::IOBuf> appDataBuf_;
234 
235  size_t appBytesWritten_{0};
236  size_t appBytesReceived_{0};
237 
239 };
240 } // namespace fizz
virtual std::vector< SignatureScheme > getSupportedSigSchemes() const =0
HandshakeTimeout(AsyncFizzBase &transport, folly::EventBase *eventBase)
Definition: AsyncFizzBase.h:35
virtual void deliverError(const folly::AsyncSocketException &ex, bool closeTransport=true)
folly::IOBufQueue transportReadBuf_
flags
Definition: http_parser.h:127
std::unique_ptr< folly::IOBuf > appDataBuf_
void destroy() override
ReadCallback * getReadCallback() const override
std::unique_ptr< X509, X509Deleter > X509UniquePtr
void attachTimeoutManager(folly::TimeoutManager *manager)
context
Definition: CMakeCache.txt:563
SignatureScheme
Definition: Types.h:257
CipherSuite
Definition: Types.h:153
AsyncFizzBase(folly::AsyncTransportWrapper::UniquePtr transport)
STL namespace.
void readErr(const folly::AsyncSocketException &ex) noexceptoverride
folly::AsyncTransportCertificate Cert
void setReplaySafetyCallback(folly::AsyncTransport::ReplaySafetyCallback *callback) override=0
virtual void startHandshakeTimeout(std::chrono::milliseconds)
const Cert * getPeerCertificate() const override=0
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
bool good() const override=0
void readEOF() noexceptoverride
void detachEventBase() override
void setReadCB(ReadCallback *callback) override
void attachEventBase(folly::EventBase *eventBase) override
virtual void cancelHandshakeTimeout()
void writeErr(size_t bytesWritten, const folly::AsyncSocketException &ex) noexceptoverride
~AsyncFizzBase() override
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
static Options cacheChainLength()
Definition: IOBufQueue.h:83
void writeSuccess() noexceptoverride
const X509 * getSelfCert() const override=0
void attachTimeoutManager(TimeoutManager *timeoutManager, InternalEnum internal=InternalEnum::NORMAL)
void readDataAvailable(size_t len) noexceptoverride
void handshakeTimeoutExpired() noexcept
virtual Buf getEkm(folly::StringPiece label, const Buf &context, uint16_t length) const =0
const Cert * getSelfCertificate() const override=0
Definition: Actions.h:16
HandshakeTimeout handshakeTimeout_
void writeChain(folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE) override
Definition: Traits.h:588
void timeoutExpired() noexceptoverride
Definition: AsyncFizzBase.h:40
size_t getAppBytesWritten() const override
virtual void startTransportReads()
bool error() const override=0
void attachEventBase(EventBase *eventBase, InternalEnum internal=InternalEnum::NORMAL)
bool isBufferMovable() noexceptoverride
AsyncReader::ReadCallback ReadCallback
std::unique_ptr< AsyncFizzBase, folly::DelayedDestruction::Destructor > UniquePtr
Definition: AsyncFizzBase.h:30
const char * string
Definition: Conv.cpp:212
void getReadBuffer(void **bufReturn, size_t *lenReturn) override
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
const
Definition: upload.py:398
std::string getSecurityProtocol() const override
bool isReplaySafe() const override=0
void readBufferAvailable(std::unique_ptr< folly::IOBuf > data) noexceptoverride
bool connecting() const override=0
folly::ssl::X509UniquePtr getPeerCert() const override=0
bool isScheduled() const
std::string getApplicationProtocol() const noexceptoverride=0
size_t getAppBytesReceived() const override
Range< const char * > StringPiece
virtual void transportError(const folly::AsyncSocketException &ex)=0
virtual folly::Optional< CipherSuite > getCipher() const =0
bool isDetachable() const override
virtual void transportDataAvailable()=0
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
virtual void writeAppData(folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE)=0
bool readable() const override=0
ReadCallback * readCallback_
StringPiece label
virtual void deliverAppData(std::unique_ptr< folly::IOBuf > buf)