xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_config.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2013 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 #ifndef QUICHE_QUIC_CORE_QUIC_CONFIG_H_
6 #define QUICHE_QUIC_CORE_QUIC_CONFIG_H_
7 
8 #include <cstddef>
9 #include <cstdint>
10 #include <optional>
11 #include <string>
12 
13 #include "quiche/quic/core/crypto/transport_parameters.h"
14 #include "quiche/quic/core/quic_connection_id.h"
15 #include "quiche/quic/core/quic_packets.h"
16 #include "quiche/quic/core/quic_time.h"
17 #include "quiche/quic/core/quic_types.h"
18 #include "quiche/quic/platform/api/quic_export.h"
19 
20 namespace quic {
21 
22 namespace test {
23 class QuicConfigPeer;
24 }  // namespace test
25 
26 class CryptoHandshakeMessage;
27 
28 // Describes whether or not a given QuicTag is required or optional in the
29 // handshake message.
30 enum QuicConfigPresence : uint8_t {
31   // This negotiable value can be absent from the handshake message. Default
32   // value is selected as the negotiated value in such a case.
33   PRESENCE_OPTIONAL,
34   // This negotiable value is required in the handshake message otherwise the
35   // Process*Hello function returns an error.
36   PRESENCE_REQUIRED,
37 };
38 
39 // Whether the CryptoHandshakeMessage is from the client or server.
40 enum HelloType {
41   CLIENT,
42   SERVER,
43 };
44 
45 // An abstract base class that stores a value that can be sent in CHLO/SHLO
46 // message. These values can be OPTIONAL or REQUIRED, depending on |presence_|.
47 class QUICHE_EXPORT QuicConfigValue {
48  public:
49   QuicConfigValue(QuicTag tag, QuicConfigPresence presence);
50   virtual ~QuicConfigValue();
51 
52   // Serialises tag name and value(s) to |out|.
53   virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const = 0;
54 
55   // Selects a mutually acceptable value from those offered in |peer_hello|
56   // and those defined in the subclass.
57   virtual QuicErrorCode ProcessPeerHello(
58       const CryptoHandshakeMessage& peer_hello, HelloType hello_type,
59       std::string* error_details) = 0;
60 
61  protected:
62   const QuicTag tag_;
63   const QuicConfigPresence presence_;
64 };
65 
66 // Stores uint32_t from CHLO or SHLO messages that are not negotiated.
67 class QUICHE_EXPORT QuicFixedUint32 : public QuicConfigValue {
68  public:
69   QuicFixedUint32(QuicTag tag, QuicConfigPresence presence);
70   ~QuicFixedUint32() override;
71 
72   bool HasSendValue() const;
73 
74   uint32_t GetSendValue() const;
75 
76   void SetSendValue(uint32_t value);
77 
78   bool HasReceivedValue() const;
79 
80   uint32_t GetReceivedValue() const;
81 
82   void SetReceivedValue(uint32_t value);
83 
84   // If has_send_value is true, serialises |tag_| and |send_value_| to |out|.
85   void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
86 
87   // Sets |value_| to the corresponding value from |peer_hello_| if it exists.
88   QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
89                                  HelloType hello_type,
90                                  std::string* error_details) override;
91 
92  private:
93   bool has_send_value_;
94   bool has_receive_value_;
95   uint32_t send_value_;
96   uint32_t receive_value_;
97 };
98 
99 // Stores 62bit numbers from handshake messages that unilaterally shared by each
100 // endpoint. IMPORTANT: these are serialized as 32-bit unsigned integers when
101 // using QUIC_CRYPTO versions and CryptoHandshakeMessage.
102 class QUICHE_EXPORT QuicFixedUint62 : public QuicConfigValue {
103  public:
104   QuicFixedUint62(QuicTag name, QuicConfigPresence presence);
105   ~QuicFixedUint62() override;
106 
107   bool HasSendValue() const;
108 
109   uint64_t GetSendValue() const;
110 
111   void SetSendValue(uint64_t value);
112 
113   bool HasReceivedValue() const;
114 
115   uint64_t GetReceivedValue() const;
116 
117   void SetReceivedValue(uint64_t value);
118 
119   // If has_send_value is true, serialises |tag_| and |send_value_| to |out|.
120   // IMPORTANT: this method serializes |send_value_| as an unsigned 32bit
121   // integer.
122   void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
123 
124   // Sets |value_| to the corresponding value from |peer_hello_| if it exists.
125   QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
126                                  HelloType hello_type,
127                                  std::string* error_details) override;
128 
129  private:
130   bool has_send_value_;
131   bool has_receive_value_;
132   uint64_t send_value_;
133   uint64_t receive_value_;
134 };
135 
136 // Stores StatelessResetToken from CHLO or SHLO messages that are not
137 // negotiated.
138 class QUICHE_EXPORT QuicFixedStatelessResetToken : public QuicConfigValue {
139  public:
140   QuicFixedStatelessResetToken(QuicTag tag, QuicConfigPresence presence);
141   ~QuicFixedStatelessResetToken() override;
142 
143   bool HasSendValue() const;
144 
145   const StatelessResetToken& GetSendValue() const;
146 
147   void SetSendValue(const StatelessResetToken& value);
148 
149   bool HasReceivedValue() const;
150 
151   const StatelessResetToken& GetReceivedValue() const;
152 
153   void SetReceivedValue(const StatelessResetToken& value);
154 
155   // If has_send_value is true, serialises |tag_| and |send_value_| to |out|.
156   void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
157 
158   // Sets |value_| to the corresponding value from |peer_hello_| if it exists.
159   QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
160                                  HelloType hello_type,
161                                  std::string* error_details) override;
162 
163  private:
164   bool has_send_value_;
165   bool has_receive_value_;
166   StatelessResetToken send_value_;
167   StatelessResetToken receive_value_;
168 };
169 
170 // Stores tag from CHLO or SHLO messages that are not negotiated.
171 class QUICHE_EXPORT QuicFixedTagVector : public QuicConfigValue {
172  public:
173   QuicFixedTagVector(QuicTag name, QuicConfigPresence presence);
174   QuicFixedTagVector(const QuicFixedTagVector& other);
175   ~QuicFixedTagVector() override;
176 
177   bool HasSendValues() const;
178 
179   const QuicTagVector& GetSendValues() const;
180 
181   void SetSendValues(const QuicTagVector& values);
182 
183   bool HasReceivedValues() const;
184 
185   const QuicTagVector& GetReceivedValues() const;
186 
187   void SetReceivedValues(const QuicTagVector& values);
188 
189   // If has_send_value is true, serialises |tag_vector_| and |send_value_| to
190   // |out|.
191   void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
192 
193   // Sets |receive_values_| to the corresponding value from |client_hello_| if
194   // it exists.
195   QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
196                                  HelloType hello_type,
197                                  std::string* error_details) override;
198 
199  private:
200   bool has_send_values_;
201   bool has_receive_values_;
202   QuicTagVector send_values_;
203   QuicTagVector receive_values_;
204 };
205 
206 // Stores QuicSocketAddress from CHLO or SHLO messages that are not negotiated.
207 class QUICHE_EXPORT QuicFixedSocketAddress : public QuicConfigValue {
208  public:
209   QuicFixedSocketAddress(QuicTag tag, QuicConfigPresence presence);
210   ~QuicFixedSocketAddress() override;
211 
212   bool HasSendValue() const;
213 
214   const QuicSocketAddress& GetSendValue() const;
215 
216   void SetSendValue(const QuicSocketAddress& value);
217 
218   void ClearSendValue();
219 
220   bool HasReceivedValue() const;
221 
222   const QuicSocketAddress& GetReceivedValue() const;
223 
224   void SetReceivedValue(const QuicSocketAddress& value);
225 
226   void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
227 
228   QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
229                                  HelloType hello_type,
230                                  std::string* error_details) override;
231 
232  private:
233   bool has_send_value_;
234   bool has_receive_value_;
235   QuicSocketAddress send_value_;
236   QuicSocketAddress receive_value_;
237 };
238 
239 // QuicConfig contains non-crypto configuration options that are negotiated in
240 // the crypto handshake.
241 class QUICHE_EXPORT QuicConfig {
242  public:
243   QuicConfig();
244   QuicConfig(const QuicConfig& other);
245   ~QuicConfig();
246 
247   void SetConnectionOptionsToSend(const QuicTagVector& connection_options);
248 
249   bool HasReceivedConnectionOptions() const;
250 
251   void SetGoogleHandshakeMessageToSend(std::string message);
252 
253   const std::optional<std::string>& GetReceivedGoogleHandshakeMessage() const;
254 
255   // Sets initial received connection options.  All received connection options
256   // will be initialized with these fields. Initial received options may only be
257   // set once per config, prior to the setting of any other options.  If options
258   // have already been set (either by previous calls or via handshake), this
259   // function does nothing and returns false.
260   bool SetInitialReceivedConnectionOptions(const QuicTagVector& tags);
261 
262   const QuicTagVector& ReceivedConnectionOptions() const;
263 
264   bool HasSendConnectionOptions() const;
265 
266   const QuicTagVector& SendConnectionOptions() const;
267 
268   // Returns true if the client is sending or the server has received a
269   // connection option.
270   // TODO(ianswett): Rename to HasClientRequestedSharedOption
271   bool HasClientSentConnectionOption(QuicTag tag,
272                                      Perspective perspective) const;
273 
274   void SetClientConnectionOptions(
275       const QuicTagVector& client_connection_options);
276 
277   // Returns true if the client has requested the specified connection option.
278   // Checks the client connection options if the |perspective| is client and
279   // connection options if the |perspective| is the server.
280   bool HasClientRequestedIndependentOption(QuicTag tag,
281                                            Perspective perspective) const;
282 
283   const QuicTagVector& ClientRequestedIndependentOptions(
284       Perspective perspective) const;
285 
286   void SetIdleNetworkTimeout(QuicTime::Delta idle_network_timeout);
287 
288   QuicTime::Delta IdleNetworkTimeout() const;
289 
290   // Sets the max bidirectional stream count that this endpoint supports.
291   void SetMaxBidirectionalStreamsToSend(uint32_t max_streams);
292   uint32_t GetMaxBidirectionalStreamsToSend() const;
293 
294   bool HasReceivedMaxBidirectionalStreams() const;
295   // Gets the max bidirectional stream limit imposed by the peer.
296   uint32_t ReceivedMaxBidirectionalStreams() const;
297 
298   // Sets the max unidirectional stream count that this endpoint supports.
299   void SetMaxUnidirectionalStreamsToSend(uint32_t max_streams);
300   uint32_t GetMaxUnidirectionalStreamsToSend() const;
301 
302   bool HasReceivedMaxUnidirectionalStreams() const;
303   // Gets the max unidirectional stream limit imposed by the peer.
304   uint32_t ReceivedMaxUnidirectionalStreams() const;
305 
set_max_time_before_crypto_handshake(QuicTime::Delta max_time_before_crypto_handshake)306   void set_max_time_before_crypto_handshake(
307       QuicTime::Delta max_time_before_crypto_handshake) {
308     max_time_before_crypto_handshake_ = max_time_before_crypto_handshake;
309   }
310 
max_time_before_crypto_handshake()311   QuicTime::Delta max_time_before_crypto_handshake() const {
312     return max_time_before_crypto_handshake_;
313   }
314 
set_max_idle_time_before_crypto_handshake(QuicTime::Delta max_idle_time_before_crypto_handshake)315   void set_max_idle_time_before_crypto_handshake(
316       QuicTime::Delta max_idle_time_before_crypto_handshake) {
317     max_idle_time_before_crypto_handshake_ =
318         max_idle_time_before_crypto_handshake;
319   }
320 
max_idle_time_before_crypto_handshake()321   QuicTime::Delta max_idle_time_before_crypto_handshake() const {
322     return max_idle_time_before_crypto_handshake_;
323   }
324 
set_max_undecryptable_packets(size_t max_undecryptable_packets)325   void set_max_undecryptable_packets(size_t max_undecryptable_packets) {
326     max_undecryptable_packets_ = max_undecryptable_packets;
327   }
328 
max_undecryptable_packets()329   size_t max_undecryptable_packets() const {
330     return max_undecryptable_packets_;
331   }
332 
333   // Peer's connection id length, in bytes. Only used in Q043 and Q046.
334   bool HasSetBytesForConnectionIdToSend() const;
335   void SetBytesForConnectionIdToSend(uint32_t bytes);
336   bool HasReceivedBytesForConnectionId() const;
337   uint32_t ReceivedBytesForConnectionId() const;
338 
339   // Estimated initial round trip time in us.
340   void SetInitialRoundTripTimeUsToSend(uint64_t rtt_us);
341   bool HasReceivedInitialRoundTripTimeUs() const;
342   uint64_t ReceivedInitialRoundTripTimeUs() const;
343   bool HasInitialRoundTripTimeUsToSend() const;
344   uint64_t GetInitialRoundTripTimeUsToSend() const;
345 
346   // Sets an initial stream flow control window size to transmit to the peer.
347   void SetInitialStreamFlowControlWindowToSend(uint64_t window_bytes);
348   uint64_t GetInitialStreamFlowControlWindowToSend() const;
349   bool HasReceivedInitialStreamFlowControlWindowBytes() const;
350   uint64_t ReceivedInitialStreamFlowControlWindowBytes() const;
351 
352   // Specifies the initial flow control window (max stream data) for
353   // incoming bidirectional streams. Incoming means streams initiated by our
354   // peer. If not set, GetInitialMaxStreamDataBytesIncomingBidirectionalToSend
355   // returns the value passed to SetInitialStreamFlowControlWindowToSend.
356   void SetInitialMaxStreamDataBytesIncomingBidirectionalToSend(
357       uint64_t window_bytes);
358   uint64_t GetInitialMaxStreamDataBytesIncomingBidirectionalToSend() const;
359   bool HasReceivedInitialMaxStreamDataBytesIncomingBidirectional() const;
360   uint64_t ReceivedInitialMaxStreamDataBytesIncomingBidirectional() const;
361 
362   // Specifies the initial flow control window (max stream data) for
363   // outgoing bidirectional streams. Outgoing means streams initiated by us.
364   // If not set, GetInitialMaxStreamDataBytesOutgoingBidirectionalToSend
365   // returns the value passed to SetInitialStreamFlowControlWindowToSend.
366   void SetInitialMaxStreamDataBytesOutgoingBidirectionalToSend(
367       uint64_t window_bytes);
368   uint64_t GetInitialMaxStreamDataBytesOutgoingBidirectionalToSend() const;
369   bool HasReceivedInitialMaxStreamDataBytesOutgoingBidirectional() const;
370   uint64_t ReceivedInitialMaxStreamDataBytesOutgoingBidirectional() const;
371 
372   // Specifies the initial flow control window (max stream data) for
373   // unidirectional streams. If not set,
374   // GetInitialMaxStreamDataBytesUnidirectionalToSend returns the value passed
375   // to SetInitialStreamFlowControlWindowToSend.
376   void SetInitialMaxStreamDataBytesUnidirectionalToSend(uint64_t window_bytes);
377   uint64_t GetInitialMaxStreamDataBytesUnidirectionalToSend() const;
378   bool HasReceivedInitialMaxStreamDataBytesUnidirectional() const;
379   uint64_t ReceivedInitialMaxStreamDataBytesUnidirectional() const;
380 
381   // Sets an initial session flow control window size to transmit to the peer.
382   void SetInitialSessionFlowControlWindowToSend(uint64_t window_bytes);
383   uint64_t GetInitialSessionFlowControlWindowToSend() const;
384   bool HasReceivedInitialSessionFlowControlWindowBytes() const;
385   uint64_t ReceivedInitialSessionFlowControlWindowBytes() const;
386 
387   // Disable connection migration.
388   void SetDisableConnectionMigration();
389   bool DisableConnectionMigration() const;
390 
391   // IPv6 alternate server address.
392   void SetIPv6AlternateServerAddressToSend(
393       const QuicSocketAddress& alternate_server_address_ipv6);
394   bool HasReceivedIPv6AlternateServerAddress() const;
395   const QuicSocketAddress& ReceivedIPv6AlternateServerAddress() const;
396 
397   // IPv4 alternate server address.
398   void SetIPv4AlternateServerAddressToSend(
399       const QuicSocketAddress& alternate_server_address_ipv4);
400   bool HasReceivedIPv4AlternateServerAddress() const;
401   const QuicSocketAddress& ReceivedIPv4AlternateServerAddress() const;
402 
403   // Called to set |connection_id| and |stateless_reset_token| if server
404   // preferred address has been set via SetIPv(4|6)AlternateServerAddressToSend.
405   // Please note, this is different from SetStatelessResetTokenToSend(const
406   // StatelessResetToken&) which is used to send the token corresponding to the
407   // existing server_connection_id.
408   void SetPreferredAddressConnectionIdAndTokenToSend(
409       const QuicConnectionId& connection_id,
410       const StatelessResetToken& stateless_reset_token);
411 
412   // Preferred Address Connection ID and Token.
413   bool HasReceivedPreferredAddressConnectionIdAndToken() const;
414   const std::pair<QuicConnectionId, StatelessResetToken>&
415   ReceivedPreferredAddressConnectionIdAndToken() const;
416   std::optional<QuicSocketAddress> GetPreferredAddressToSend(
417       quiche::IpAddressFamily address_family) const;
418   void ClearAlternateServerAddressToSend(
419       quiche::IpAddressFamily address_family);
420 
421   // Sets the alternate server addresses to be used for a server behind a
422   // DNAT. The `to_send` address will be sent to the client, and the
423   // `mapped` address will be the corresponding internal address. Server-only.
424   void SetIPv4AlternateServerAddressForDNat(
425       const QuicSocketAddress& alternate_server_address_ipv4_to_send,
426       const QuicSocketAddress& mapped_alternate_server_address_ipv4);
427   void SetIPv6AlternateServerAddressForDNat(
428       const QuicSocketAddress& alternate_server_address_ipv6_to_send,
429       const QuicSocketAddress& mapped_alternate_server_address_ipv6);
430 
431   // Returns the address the the server will receive packest from
432   // when the client is sending to the preferred address. Will be
433   // the mapped address, if present, or the alternate address otherwise.
434   std::optional<QuicSocketAddress> GetMappedAlternativeServerAddress(
435       quiche::IpAddressFamily address_family) const;
436 
437   // Returns true if this config supports server preferred address,
438   // either via the kSPAD connection option or the QUIC protocol flag
439   // quic_always_support_server_preferred_address.
440   bool SupportsServerPreferredAddress(Perspective perspective) const;
441 
442   // Original destination connection ID.
443   void SetOriginalConnectionIdToSend(
444       const QuicConnectionId& original_destination_connection_id);
445   bool HasReceivedOriginalConnectionId() const;
446   QuicConnectionId ReceivedOriginalConnectionId() const;
447 
448   // Stateless reset token.
449   void SetStatelessResetTokenToSend(
450       const StatelessResetToken& stateless_reset_token);
451   bool HasStatelessResetTokenToSend() const;
452   bool HasReceivedStatelessResetToken() const;
453   const StatelessResetToken& ReceivedStatelessResetToken() const;
454 
455   // Manage the IETF QUIC Max ACK Delay transport parameter.
456   // The sent value is the delay that this node uses
457   // (QuicSentPacketManager::local_max_ack_delay_).
458   // The received delay is the value received from
459   // the peer (QuicSentPacketManager::peer_max_ack_delay_).
460   void SetMaxAckDelayToSendMs(uint32_t max_ack_delay_ms);
461   uint32_t GetMaxAckDelayToSendMs() const;
462   bool HasReceivedMaxAckDelayMs() const;
463   uint32_t ReceivedMaxAckDelayMs() const;
464 
465   // Manage the IETF QUIC extension Min Ack Delay transport parameter.
466   // An endpoint uses min_ack_delay to advsertise its support for
467   // AckFrequencyFrame sent by peer.
468   void SetMinAckDelayMs(uint32_t min_ack_delay_ms);
469   uint32_t GetMinAckDelayToSendMs() const;
470   bool HasReceivedMinAckDelayMs() const;
471   uint32_t ReceivedMinAckDelayMs() const;
472 
473   void SetAckDelayExponentToSend(uint32_t exponent);
474   uint32_t GetAckDelayExponentToSend() const;
475   bool HasReceivedAckDelayExponent() const;
476   uint32_t ReceivedAckDelayExponent() const;
477 
478   // IETF QUIC max_udp_payload_size transport parameter.
479   void SetMaxPacketSizeToSend(uint64_t max_udp_payload_size);
480   uint64_t GetMaxPacketSizeToSend() const;
481   bool HasReceivedMaxPacketSize() const;
482   uint64_t ReceivedMaxPacketSize() const;
483 
484   // IETF QUIC max_datagram_frame_size transport parameter.
485   void SetMaxDatagramFrameSizeToSend(uint64_t max_datagram_frame_size);
486   uint64_t GetMaxDatagramFrameSizeToSend() const;
487   bool HasReceivedMaxDatagramFrameSize() const;
488   uint64_t ReceivedMaxDatagramFrameSize() const;
489 
490   // IETF QUIC active_connection_id_limit transport parameter.
491   void SetActiveConnectionIdLimitToSend(uint64_t active_connection_id_limit);
492   uint64_t GetActiveConnectionIdLimitToSend() const;
493   bool HasReceivedActiveConnectionIdLimit() const;
494   uint64_t ReceivedActiveConnectionIdLimit() const;
495 
496   // Initial source connection ID.
497   void SetInitialSourceConnectionIdToSend(
498       const QuicConnectionId& initial_source_connection_id);
499   bool HasReceivedInitialSourceConnectionId() const;
500   QuicConnectionId ReceivedInitialSourceConnectionId() const;
501 
502   // Retry source connection ID.
503   void SetRetrySourceConnectionIdToSend(
504       const QuicConnectionId& retry_source_connection_id);
505   bool HasReceivedRetrySourceConnectionId() const;
506   QuicConnectionId ReceivedRetrySourceConnectionId() const;
507 
508   bool negotiated() const;
509 
510   void SetCreateSessionTagIndicators(QuicTagVector tags);
511 
512   const QuicTagVector& create_session_tag_indicators() const;
513 
514   // ToHandshakeMessage serialises the settings in this object as a series of
515   // tags /value pairs and adds them to |out|.
516   void ToHandshakeMessage(CryptoHandshakeMessage* out,
517                           QuicTransportVersion transport_version) const;
518 
519   // Calls ProcessPeerHello on each negotiable parameter. On failure returns
520   // the corresponding QuicErrorCode and sets detailed error in |error_details|.
521   QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
522                                  HelloType hello_type,
523                                  std::string* error_details);
524 
525   // FillTransportParameters writes the values to send for ICSL, MIDS, CFCW, and
526   // SFCW to |*params|, returning true if the values could be written and false
527   // if something prevents them from being written (e.g. a value is too large).
528   bool FillTransportParameters(TransportParameters* params) const;
529 
530   // ProcessTransportParameters reads from |params| which were received from a
531   // peer. If |is_resumption|, some configs will not be processed.
532   // On failure, it returns a QuicErrorCode and puts a detailed error in
533   // |*error_details|.
534   QuicErrorCode ProcessTransportParameters(const TransportParameters& params,
535                                            bool is_resumption,
536                                            std::string* error_details);
537 
custom_transport_parameters_to_send()538   TransportParameters::ParameterMap& custom_transport_parameters_to_send() {
539     return custom_transport_parameters_to_send_;
540   }
541   const TransportParameters::ParameterMap&
received_custom_transport_parameters()542   received_custom_transport_parameters() const {
543     return received_custom_transport_parameters_;
544   }
545 
546   // Called to clear google_handshake_message to send or received.
547   void ClearGoogleHandshakeMessage();
548 
549  private:
550   friend class test::QuicConfigPeer;
551 
552   // SetDefaults sets the members to sensible, default values.
553   void SetDefaults();
554 
555   // Whether we've received the peer's config.
556   bool negotiated_;
557 
558   // Configurations options that are not negotiated.
559   // Maximum time the session can be alive before crypto handshake is finished.
560   QuicTime::Delta max_time_before_crypto_handshake_;
561   // Maximum idle time before the crypto handshake has completed.
562   QuicTime::Delta max_idle_time_before_crypto_handshake_;
563   // Maximum number of undecryptable packets stored before CHLO/SHLO.
564   size_t max_undecryptable_packets_;
565 
566   // Connection options which affect the server side.  May also affect the
567   // client side in cases when identical behavior is desirable.
568   QuicFixedTagVector connection_options_;
569   // Connection options which only affect the client side.
570   QuicFixedTagVector client_connection_options_;
571   // Maximum idle network timeout.
572   // Uses the max_idle_timeout transport parameter in IETF QUIC.
573   // Note that received_max_idle_timeout_ is only populated if we receive the
574   // peer's value, which isn't guaranteed in IETF QUIC as sending is optional.
575   QuicTime::Delta max_idle_timeout_to_send_;
576   std::optional<QuicTime::Delta> received_max_idle_timeout_;
577   // Maximum number of dynamic streams that a Google QUIC connection
578   // can support or the maximum number of bidirectional streams that
579   // an IETF QUIC connection can support.
580   // The SendValue is the limit on peer-created streams that this endpoint is
581   // advertising.
582   // The ReceivedValue is the limit on locally-created streams that
583   // the peer advertised.
584   // Uses the initial_max_streams_bidi transport parameter in IETF QUIC.
585   QuicFixedUint32 max_bidirectional_streams_;
586   // Maximum number of unidirectional streams that the connection can
587   // support.
588   // The SendValue is the limit on peer-created streams that this endpoint is
589   // advertising.
590   // The ReceivedValue is the limit on locally-created streams that the peer
591   // advertised.
592   // Uses the initial_max_streams_uni transport parameter in IETF QUIC.
593   QuicFixedUint32 max_unidirectional_streams_;
594   // The number of bytes required for the connection ID. This is only used in
595   // the legacy header format used only by Q043 at this point.
596   QuicFixedUint32 bytes_for_connection_id_;
597   // Initial round trip time estimate in microseconds.
598   QuicFixedUint62 initial_round_trip_time_us_;
599 
600   // Initial IETF QUIC stream flow control receive windows in bytes.
601   // Incoming bidirectional streams.
602   // Uses the initial_max_stream_data_bidi_{local,remote} transport parameter
603   // in IETF QUIC, depending on whether we're sending or receiving.
604   QuicFixedUint62 initial_max_stream_data_bytes_incoming_bidirectional_;
605   // Outgoing bidirectional streams.
606   // Uses the initial_max_stream_data_bidi_{local,remote} transport parameter
607   // in IETF QUIC, depending on whether we're sending or receiving.
608   QuicFixedUint62 initial_max_stream_data_bytes_outgoing_bidirectional_;
609   // Unidirectional streams.
610   // Uses the initial_max_stream_data_uni transport parameter in IETF QUIC.
611   QuicFixedUint62 initial_max_stream_data_bytes_unidirectional_;
612 
613   // Initial Google QUIC stream flow control receive window in bytes.
614   QuicFixedUint62 initial_stream_flow_control_window_bytes_;
615 
616   // Initial session flow control receive window in bytes.
617   // Uses the initial_max_data transport parameter in IETF QUIC.
618   QuicFixedUint62 initial_session_flow_control_window_bytes_;
619 
620   // Whether active connection migration is allowed.
621   // Uses the disable_active_migration transport parameter in IETF QUIC.
622   QuicFixedUint32 connection_migration_disabled_;
623 
624   // Alternate server addresses the client could connect to.
625   // Uses the preferred_address transport parameter in IETF QUIC.
626   // Note that when QUIC_CRYPTO is in use, only one of the addresses is sent.
627   QuicFixedSocketAddress alternate_server_address_ipv6_;
628   QuicFixedSocketAddress alternate_server_address_ipv4_;
629 
630   // When a server is behind DNAT, the addresses it sends to the client will
631   // not be the source address recevied in packets from the client. These
632   // two optional members capture the internal addresses which map to
633   // the addresses sent on the wire.
634   std::optional<QuicSocketAddress> mapped_alternate_server_address_ipv6_;
635   std::optional<QuicSocketAddress> mapped_alternate_server_address_ipv4_;
636 
637   // Connection Id data to send from the server or receive at the client as part
638   // of the preferred address transport parameter.
639   std::optional<std::pair<QuicConnectionId, StatelessResetToken>>
640       preferred_address_connection_id_and_token_;
641 
642   // Stateless reset token used in IETF public reset packet.
643   // Uses the stateless_reset_token transport parameter in IETF QUIC.
644   QuicFixedStatelessResetToken stateless_reset_token_;
645 
646   // List of QuicTags whose presence immediately causes the session to
647   // be created. This allows for CHLOs that are larger than a single
648   // packet to be processed.
649   QuicTagVector create_session_tag_indicators_;
650 
651   // Maximum ack delay. The sent value is the value used on this node.
652   // The received value is the value received from the peer and used by
653   // the peer.
654   // Uses the max_ack_delay transport parameter in IETF QUIC.
655   QuicFixedUint32 max_ack_delay_ms_;
656 
657   // Minimum ack delay. Used to enable sender control of max_ack_delay.
658   // Uses the min_ack_delay transport parameter in IETF QUIC extension.
659   QuicFixedUint32 min_ack_delay_ms_;
660 
661   // The sent exponent is the exponent that this node uses when serializing an
662   // ACK frame (and the peer should use when deserializing the frame);
663   // the received exponent is the value the peer uses to serialize frames and
664   // this node uses to deserialize them.
665   // Uses the ack_delay_exponent transport parameter in IETF QUIC.
666   QuicFixedUint32 ack_delay_exponent_;
667 
668   // Maximum packet size in bytes.
669   // Uses the max_udp_payload_size transport parameter in IETF QUIC.
670   QuicFixedUint62 max_udp_payload_size_;
671 
672   // Maximum DATAGRAM/MESSAGE frame size in bytes.
673   // Uses the max_datagram_frame_size transport parameter in IETF QUIC.
674   QuicFixedUint62 max_datagram_frame_size_;
675 
676   // Maximum number of connection IDs from the peer.
677   // Uses the active_connection_id_limit transport parameter in IETF QUIC.
678   QuicFixedUint62 active_connection_id_limit_;
679 
680   // The value of the Destination Connection ID field from the first
681   // Initial packet sent by the client.
682   // Uses the original_destination_connection_id transport parameter in
683   // IETF QUIC.
684   std::optional<QuicConnectionId> original_destination_connection_id_to_send_;
685   std::optional<QuicConnectionId> received_original_destination_connection_id_;
686 
687   // The value that the endpoint included in the Source Connection ID field of
688   // the first Initial packet it sent.
689   // Uses the initial_source_connection_id transport parameter in IETF QUIC.
690   std::optional<QuicConnectionId> initial_source_connection_id_to_send_;
691   std::optional<QuicConnectionId> received_initial_source_connection_id_;
692 
693   // The value that the server included in the Source Connection ID field of a
694   // Retry packet it sent.
695   // Uses the retry_source_connection_id transport parameter in IETF QUIC.
696   std::optional<QuicConnectionId> retry_source_connection_id_to_send_;
697   std::optional<QuicConnectionId> received_retry_source_connection_id_;
698 
699   // Custom transport parameters that can be sent and received in the TLS
700   // handshake.
701   TransportParameters::ParameterMap custom_transport_parameters_to_send_;
702   TransportParameters::ParameterMap received_custom_transport_parameters_;
703 
704   // Google internal handshake message.
705   std::optional<std::string> google_handshake_message_to_send_;
706   std::optional<std::string> received_google_handshake_message_;
707 };
708 
709 }  // namespace quic
710 
711 #endif  // QUICHE_QUIC_CORE_QUIC_CONFIG_H_
712