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 <folly/futures/Future.h> 12 13 #include <fizz/protocol/Certificate.h> 14 #include <fizz/protocol/KeyScheduler.h> 15 #include <fizz/protocol/Params.h> 16 #include <fizz/record/RecordLayer.h> 17 #include <fizz/server/Actions.h> 18 #include <fizz/server/FizzServerContext.h> 19 #include <fizz/server/ServerExtensions.h> 20 #include <fizz/server/State.h> 21 22 namespace fizz { 23 namespace server { 24 25 class ServerStateMachine { 26 public: 27 using StateType = State; 28 using ProcessingActions = AsyncActions; 29 using CompletedActions = Actions; 30 31 virtual ~ServerStateMachine() = default; 32 33 virtual AsyncActions processAccept( 34 const State&, 35 folly::Executor* executor, 36 std::shared_ptr<const FizzServerContext> context, 37 const std::shared_ptr<ServerExtensions>& extensions); 38 39 virtual AsyncActions 40 processSocketData(const State&, folly::IOBufQueue&, Aead::AeadOptions); 41 42 virtual AsyncActions processWriteNewSessionTicket( 43 const State&, 44 WriteNewSessionTicket); 45 46 virtual AsyncActions processAppWrite(const State&, AppWrite); 47 48 virtual AsyncActions processEarlyAppWrite(const State&, EarlyAppWrite); 49 50 virtual Actions processAppClose(const State&); 51 virtual Actions processAppCloseImmediate(const State&); 52 }; 53 54 namespace detail { 55 56 AsyncActions processEvent(const State& state, Param param); 57 58 Actions handleError( 59 const State& state, 60 ReportError error, 61 folly::Optional<AlertDescription> alertDesc); 62 63 Actions handleAppCloseImmediate(const State& state); 64 Actions handleAppClose(const State& state); 65 66 Actions handleInvalidEvent(const State& state, Event event, Param param); 67 } // namespace detail 68 69 struct ServerTypes { 70 using State = fizz::server::State; 71 using StateEnum = fizz::server::StateEnum; 72 using Event = fizz::Event; 73 using Param = fizz::Param; 74 using Actions = fizz::server::AsyncActions; 75 static constexpr auto NumStates = 76 static_cast<std::size_t>(StateEnum::NUM_STATES); 77 static constexpr auto NumEvents = static_cast<std::size_t>(Event::NUM_EVENTS); 78 static constexpr auto InvalidEventHandler = 79 &server::detail::handleInvalidEvent; 80 }; 81 } // namespace server 82 } // namespace fizz 83