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 <folly/Expected.h> 12 #include <quic/QuicException.h> 13 #include <quic/codec/QuicConnectionId.h> 14 15 namespace quic { 16 17 /** 18 * Interface to encode and decode algorithms for ConnectionId given routing 19 * info (embedded in ServerConnectionIdParams) 20 * 21 * NOTE: since several of these methods are called for every single packets, 22 * and every single connection, it is important to not do any 23 * blocking call in any of the implementation of these methods. 24 */ 25 class ConnectionIdAlgo { 26 public: 27 virtual ~ConnectionIdAlgo() = default; 28 29 /** 30 * Check if this implementation of algorithm can parse the given ConnectionId 31 */ 32 virtual bool canParse(const ConnectionId& id) const noexcept = 0; 33 34 /** 35 * Parses ServerConnectionIdParams from the given connection id. 36 */ 37 virtual folly::Expected<ServerConnectionIdParams, QuicInternalException> 38 parseConnectionId(const ConnectionId& id) noexcept = 0; 39 40 /** 41 * Encodes the given ServerConnectionIdParams into connection id 42 */ 43 virtual folly::Expected<ConnectionId, QuicInternalException> 44 encodeConnectionId(const ServerConnectionIdParams& params) noexcept = 0; 45 }; 46 47 /** 48 * Factory interface to create ConnectionIdAlgo instance. 49 */ 50 class ConnectionIdAlgoFactory { 51 public: 52 virtual ~ConnectionIdAlgoFactory() = default; 53 54 virtual std::unique_ptr<ConnectionIdAlgo> make() = 0; 55 }; 56 57 } // namespace quic 58