1 // Copyright (c) 2022 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // A Connection ID generator that generates deterministic connection IDs for
6 // QUIC servers.
7 
8 #ifndef QUICHE_QUIC_CORE_CONNECTION_ID_GENERATOR_DETERMINISTIC_H_
9 #define QUICHE_QUIC_CORE_CONNECTION_ID_GENERATOR_DETERMINISTIC_H_
10 
11 #include "quiche/quic/core/connection_id_generator.h"
12 
13 namespace quic {
14 
15 // Generates connection IDs deterministically from the provided original
16 // connection ID.
17 class QUICHE_EXPORT DeterministicConnectionIdGenerator
18     : public ConnectionIdGeneratorInterface {
19  public:
20   DeterministicConnectionIdGenerator(uint8_t expected_connection_id_length);
21 
22   // Hashes |original| to create a new connection ID.
23   std::optional<QuicConnectionId> GenerateNextConnectionId(
24       const QuicConnectionId& original) override;
25   // Replace the connection ID if and only if |original| is not of the expected
26   // length.
27   std::optional<QuicConnectionId> MaybeReplaceConnectionId(
28       const QuicConnectionId& original,
29       const ParsedQuicVersion& version) override;
ConnectionIdLength(uint8_t)30   uint8_t ConnectionIdLength(uint8_t /*first_byte*/) const override {
31     return expected_connection_id_length_;
32   }
33 
34  private:
35   const uint8_t expected_connection_id_length_;
36 };
37 
38 }  // namespace quic
39 
40 #endif  // QUICHE_QUIC_CORE__CONNECTION_ID_GENERATOR_DETERMINISTIC_H_
41