proxygen
fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine > Class Template Reference

#include <FizzBase.h>

Inheritance diagram for fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >:
fizz::client::FizzClient< ActionMoveVisitor, SM > fizz::server::FizzServer< ActionMoveVisitor, SM >

Public Member Functions

 FizzBase (const typename StateMachine::StateType &state, folly::IOBufQueue &transportReadBuf, ActionMoveVisitor &visitor, folly::DelayedDestructionBase *owner)
 
void writeNewSessionTicket (WriteNewSessionTicket writeNewSessionTicket)
 
void appWrite (AppWrite appWrite)
 
void earlyAppWrite (EarlyAppWrite appWrite)
 
void appClose ()
 
void waitForData ()
 
void newTransportData ()
 
void moveToErrorState (const folly::AsyncSocketException &ex)
 
bool inErrorState () const
 
bool actionProcessing () const
 
Buf getEkm (folly::StringPiece label, const Buf &context, uint16_t length) const
 

Protected Member Functions

void processActions (typename StateMachine::CompletedActions actions)
 
void addProcessingActions (typename StateMachine::ProcessingActions actions)
 

Protected Attributes

StateMachine machine_
 
const StateMachine::StateType & state_
 
folly::IOBufQueuetransportReadBuf_
 

Private Types

using PendingEvent = boost::variant< AppWrite, EarlyAppWrite, AppClose, WriteNewSessionTicket >
 

Private Member Functions

void processPendingEvents ()
 

Private Attributes

ActionMoveVisitor & visitor_
 
folly::DelayedDestructionBaseowner_
 
std::deque< PendingEventpendingEvents_
 
bool waitForData_ {true}
 
folly::Optional< folly::DelayedDestruction::DestructorGuardactionGuard_
 
bool inProcessPendingEvents_ {false}
 
bool inErrorState_ {false}
 

Detailed Description

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
class fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >

FizzBase defines an async method of communicating with the fizz state machine. Given a const reference to state, and a reference to transportReadBuf, FizzBase will consume the transportReadBuf and process events as applicable. visitor is variant visitor that is expected to process Actions as they are received. A DestructorGuard on owner will be taken when async actions are in flight, during which time this class must not be deleted.

Definition at line 26 of file FizzBase.h.

Member Typedef Documentation

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
using fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::PendingEvent = boost::variant<AppWrite, EarlyAppWrite, AppClose, WriteNewSessionTicket>
private

Definition at line 112 of file FizzBase.h.

Constructor & Destructor Documentation

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::FizzBase ( const typename StateMachine::StateType &  state,
folly::IOBufQueue transportReadBuf,
ActionMoveVisitor &  visitor,
folly::DelayedDestructionBase owner 
)
inline

Definition at line 28 of file FizzBase.h.

33  : state_(state),
34  transportReadBuf_(transportReadBuf),
35  visitor_(visitor),
36  owner_(owner) {}
ActionMoveVisitor & visitor_
Definition: FizzBase.h:108
folly::DelayedDestructionBase * owner_
Definition: FizzBase.h:109
const StateMachine::StateType & state_
Definition: FizzBase.h:102
folly::IOBufQueue & transportReadBuf_
Definition: FizzBase.h:103
state
Definition: http_parser.c:272

Member Function Documentation

template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
bool fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::actionProcessing ( ) const

Returns true if the state machine is actively processing an event or action.

Definition at line 81 of file FizzBase-inl.h.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

82  {
83  return actionGuard_.hasValue();
84 }
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
folly::Optional< folly::DelayedDestruction::DestructorGuard > actionGuard_
Definition: FizzBase.h:115
template<typename Derived , typename ActionMoveVisitor , typename StateMachine>
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::addProcessingActions ( typename StateMachine::ProcessingActions  actions)
protected

Definition at line 102 of file FizzBase-inl.h.

References folly::gen::move, and fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::processPendingEvents().

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

103  {
104  if (actionGuard_) {
105  throw std::runtime_error("actions already processing");
106  }
107 
109 
110  static_cast<Derived*>(this)->startActions(std::move(actions));
111 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::DelayedDestructionBase * owner_
Definition: FizzBase.h:109
Actions actions(Args &&...act)
Definition: Actions.h:86
folly::Optional< folly::DelayedDestruction::DestructorGuard > actionGuard_
Definition: FizzBase.h:115
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::appClose ( )

Called when the application wants to close the connection.

Definition at line 34 of file FizzBase-inl.h.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

34  {
35  pendingEvents_.push_back(AppClose());
37 }
void processPendingEvents()
Definition: FizzBase-inl.h:115
std::deque< PendingEvent > pendingEvents_
Definition: FizzBase.h:113
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::appWrite ( AppWrite  appWrite)

Called to write application data.

Definition at line 21 of file FizzBase-inl.h.

References folly::gen::move.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

21  {
22  pendingEvents_.push_back(std::move(w));
24 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void processPendingEvents()
Definition: FizzBase-inl.h:115
std::deque< PendingEvent > pendingEvents_
Definition: FizzBase.h:113
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::earlyAppWrite ( EarlyAppWrite  appWrite)

Called to write early application data.

Definition at line 27 of file FizzBase-inl.h.

References folly::gen::move.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

28  {
29  pendingEvents_.push_back(std::move(w));
31 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void processPendingEvents()
Definition: FizzBase-inl.h:115
std::deque< PendingEvent > pendingEvents_
Definition: FizzBase.h:113
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
Buf fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::getEkm ( folly::StringPiece  label,
const Buf context,
uint16_t  length 
) const

Returns an exported key material derived from the 1-RTT secret of the TLS connection.

Definition at line 159 of file FizzBase-inl.h.

References fizz::Exporter::getEkm(), and fizz::test::label.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

162  {
163  return Exporter::getEkm(
164  *state_.cipher(),
165  (*state_.exporterMasterSecret())->coalesce(),
166  label,
167  context ? context->clone() : nullptr,
168  length);
169 }
context
Definition: CMakeCache.txt:563
const StateMachine::StateType & state_
Definition: FizzBase.h:102
static Buf getEkm(CipherSuite cipher, folly::ByteRange exporterMaster, folly::StringPiece label, Buf context, uint16_t length)
Definition: Exporter.cpp:13
StringPiece label
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
bool fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::inErrorState ( ) const

Returns true if in error state where no further events will be processed.

Definition at line 76 of file FizzBase-inl.h.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

76  {
77  return inErrorState_ || state_.state() == decltype(state_.state())::Error;
78 }
error_stage Error
const StateMachine::StateType & state_
Definition: FizzBase.h:102
bool inErrorState_
Definition: FizzBase.h:117
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::moveToErrorState ( const folly::AsyncSocketException ex)

Calls error callbacks on any pending events and prevents any further events from being processed. Should be called when an error is received from either the state machine or the transport that will cause the connection to abort. Note that this does not stop a currently processing event.

Definition at line 51 of file FizzBase-inl.h.

References fizz::AppWrite::callback, folly::gen::move, folly::variant_match(), fizz::detail::write(), and folly::AsyncWriter::WriteCallback::writeErr().

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

52  {
53  // We use a separate flag here rather than just moving the state to Error
54  // since there may be a currently processing action.
55  inErrorState_ = true;
56  while (!pendingEvents_.empty()) {
57  auto event = std::move(pendingEvents_.front());
58  pendingEvents_.pop_front();
60  event,
61  [&ex](AppWrite& write) {
62  if (write.callback) {
63  write.callback->writeErr(0, ex);
64  }
65  },
66  [&ex](EarlyAppWrite& write) {
67  if (write.callback) {
68  write.callback->writeErr(0, ex);
69  }
70  },
71  [](auto&) {});
72  }
73 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::deque< PendingEvent > pendingEvents_
Definition: FizzBase.h:113
decltype(auto) variant_match(Variant &&variant, Cases &&...cases)
Definition: Overload.h:74
bool inErrorState_
Definition: FizzBase.h:117
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::newTransportData ( )

Called to notify that new transport data is available in transportReadBuf.

Definition at line 45 of file FizzBase-inl.h.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

45  {
46  waitForData_ = false;
48 }
bool waitForData_
Definition: FizzBase.h:114
void processPendingEvents()
Definition: FizzBase-inl.h:115
template<typename Derived , typename ActionMoveVisitor , typename StateMachine>
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::processActions ( typename StateMachine::CompletedActions  actions)
protected

Definition at line 87 of file FizzBase-inl.h.

References upload::action, and folly::apply_visitor().

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase(), and fizz::server::FizzServer< ActionMoveVisitor, SM >::startActions().

88  {
89  // This extra DestructorGuard is needed due to the gap between clearing
90  // actionGuard_ and potentially processing another action.
92 
93  for (auto& action : actions) {
95  }
96 
99 }
ActionMoveVisitor & visitor_
Definition: FizzBase.h:108
folly::DelayedDestructionBase * owner_
Definition: FizzBase.h:109
void processPendingEvents()
Definition: FizzBase-inl.h:115
Actions actions(Args &&...act)
Definition: Actions.h:86
decltype(auto) apply_visitor(Visitor &&visitor, const DiscriminatedPtr< Args... > &variant)
folly::Optional< folly::DelayedDestruction::DestructorGuard > actionGuard_
Definition: FizzBase.h:115
void clear() noexcept
Definition: Optional.h:251
action
Definition: upload.py:393
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::processPendingEvents ( )
private

Definition at line 115 of file FizzBase-inl.h.

References fizz::client::detail::actions(), folly::gen::move, SCOPE_EXIT, folly::variant_match(), and fizz::detail::write().

Referenced by fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::addProcessingActions().

115  {
117  return;
118  }
119 
122  SCOPE_EXIT {
123  inProcessPendingEvents_ = false;
124  };
125 
126  while (!actionGuard_ && !inErrorState()) {
129  if (!waitForData_) {
130  actions = machine_.processSocketData(state_, transportReadBuf_);
131  } else if (!pendingEvents_.empty()) {
132  auto event = std::move(pendingEvents_.front());
133  pendingEvents_.pop_front();
135  event,
136  [&actions, this](WriteNewSessionTicket& write) {
137  actions =
138  machine_.processWriteNewSessionTicket(state_, std::move(write));
139  },
140  [&actions, this](AppWrite& write) {
141  actions = machine_.processAppWrite(state_, std::move(write));
142  },
143  [&actions, this](EarlyAppWrite& write) {
144  actions = machine_.processEarlyAppWrite(state_, std::move(write));
145  },
146  [&actions, this](AppClose&) {
147  actions = machine_.processAppClose(state_);
148  });
149  } else {
151  return;
152  }
153 
154  static_cast<Derived*>(this)->startActions(std::move(*actions));
155  }
156 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
bool waitForData_
Definition: FizzBase.h:114
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
folly::DelayedDestructionBase * owner_
Definition: FizzBase.h:109
bool inErrorState() const
Definition: FizzBase-inl.h:76
const StateMachine::StateType & state_
Definition: FizzBase.h:102
std::deque< PendingEvent > pendingEvents_
Definition: FizzBase.h:113
Actions actions(Args &&...act)
Definition: Actions.h:86
folly::IOBufQueue & transportReadBuf_
Definition: FizzBase.h:103
bool inProcessPendingEvents_
Definition: FizzBase.h:116
decltype(auto) variant_match(Variant &&variant, Cases &&...cases)
Definition: Overload.h:74
StateMachine machine_
Definition: FizzBase.h:101
folly::Optional< folly::DelayedDestruction::DestructorGuard > actionGuard_
Definition: FizzBase.h:115
void clear() noexcept
Definition: Optional.h:251
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::waitForData ( )

Called to pause processing of transportReadBuf until new data is available.

Call newTransportData() to resume processing.

Definition at line 40 of file FizzBase-inl.h.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

40  {
41  waitForData_ = true;
42 }
bool waitForData_
Definition: FizzBase.h:114
template<typename Derived , typename ActionMoveVisitor , typename StateMachine >
void fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::writeNewSessionTicket ( WriteNewSessionTicket  writeNewSessionTicket)

Server only: Called to write new session ticket to client.

Definition at line 14 of file FizzBase-inl.h.

References folly::gen::move.

Referenced by fizz::FizzBase< FizzServer< ActionMoveVisitor, SM >, ActionMoveVisitor, SM >::FizzBase().

15  {
16  pendingEvents_.push_back(std::move(w));
18 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void processPendingEvents()
Definition: FizzBase-inl.h:115
std::deque< PendingEvent > pendingEvents_
Definition: FizzBase.h:113

Member Data Documentation

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
folly::Optional<folly::DelayedDestruction::DestructorGuard> fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::actionGuard_
private

Definition at line 115 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
bool fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::inErrorState_ {false}
private

Definition at line 117 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
bool fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::inProcessPendingEvents_ {false}
private

Definition at line 116 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
StateMachine fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::machine_
protected

Definition at line 101 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
folly::DelayedDestructionBase* fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::owner_
private

Definition at line 109 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
std::deque<PendingEvent> fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::pendingEvents_
private

Definition at line 113 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
const StateMachine::StateType& fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::state_
protected

Definition at line 102 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
folly::IOBufQueue& fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::transportReadBuf_
protected

Definition at line 103 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
ActionMoveVisitor& fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::visitor_
private

Definition at line 108 of file FizzBase.h.

template<typename Derived, typename ActionMoveVisitor, typename StateMachine>
bool fizz::FizzBase< Derived, ActionMoveVisitor, StateMachine >::waitForData_ {true}
private

Definition at line 114 of file FizzBase.h.


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