1 /* 2 * Copyright (c) Facebook, Inc. and its affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 */ 8 9 #pragma once 10 11 #include <fizz/server/FizzServerContext.h> 12 #include <quic/fizz/handshake/FizzCryptoFactory.h> 13 #include <quic/server/handshake/ServerHandshakeFactory.h> 14 15 namespace quic { 16 17 class FizzServerHandshake; 18 19 class FizzServerQuicHandshakeContext 20 : public ServerHandshakeFactory, 21 public std::enable_shared_from_this<FizzServerQuicHandshakeContext> { 22 public: 23 std::unique_ptr<ServerHandshake> 24 makeServerHandshake(QuicServerConnectionState* conn) && override; 25 getContext()26 const std::shared_ptr<const fizz::server::FizzServerContext>& getContext() 27 const { 28 return context_; 29 } 30 31 private: 32 /** 33 * We make the constructor private so that users have to use the Builder 34 * facility. This ensures that 35 * - This will ALWAYS be managed by a shared_ptr, which the implementation 36 * expects. 37 * - We can enforce that the internal state of FizzServerContext is always 38 * sane. 39 */ 40 FizzServerQuicHandshakeContext( 41 std::shared_ptr<const fizz::server::FizzServerContext> context); 42 43 FizzServerQuicHandshakeContext( 44 std::shared_ptr<const fizz::server::FizzServerContext> context, 45 std::unique_ptr<CryptoFactory> cryptoFactory); 46 47 std::shared_ptr<const fizz::server::FizzServerContext> context_; 48 49 std::unique_ptr<CryptoFactory> cryptoFactory_; 50 51 public: 52 class Builder { 53 public: setFizzServerContext(std::shared_ptr<const fizz::server::FizzServerContext> context)54 Builder&& setFizzServerContext( 55 std::shared_ptr<const fizz::server::FizzServerContext> context) && { 56 context_ = std::move(context); 57 return std::move(*this); 58 } 59 setCryptoFactory(std::unique_ptr<CryptoFactory> cryptoFactory)60 Builder&& setCryptoFactory( 61 std::unique_ptr<CryptoFactory> cryptoFactory) && { 62 cryptoFactory_ = std::move(cryptoFactory); 63 return std::move(*this); 64 } 65 66 std::shared_ptr<FizzServerQuicHandshakeContext> build() &&; 67 68 private: 69 std::shared_ptr<const fizz::server::FizzServerContext> context_; 70 std::unique_ptr<CryptoFactory> cryptoFactory_; 71 }; 72 }; 73 74 } // namespace quic 75