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.
5 #ifndef NET_QUIC_QUIC_CONFIG_H_
6 #define NET_QUIC_QUIC_CONFIG_H_
10 #include "base/basictypes.h"
11 #include "net/quic/crypto/crypto_handshake.h"
12 #include "net/quic/crypto/crypto_utils.h"
13 #include "net/quic/quic_protocol.h"
14 #include "net/quic/quic_time.h"
15 #include "net/quic/quic_utils.h"
19 class NET_EXPORT_PRIVATE QuicNegotiableValue {
22 // This negotiable value can be absent from the handshake message. Default
23 // value is selected as the negotiated value in such a case.
25 // This negotiable value is required in the handshake message otherwise the
26 // Process*Hello function returns an error.
30 QuicNegotiableValue(QuicTag tag, Presence presence);
32 bool negotiated() const {
38 const Presence presence_;
42 class NET_EXPORT_PRIVATE QuicNegotiableUint32 : public QuicNegotiableValue {
44 // Default and max values default to 0.
45 QuicNegotiableUint32(QuicTag name, Presence presence);
47 // Sets the maximum possible value that can be achieved after negotiation and
48 // also the default values to be assumed if PRESENCE_OPTIONAL and the *HLO msg
49 // doesn't contain a value corresponding to |name_|. |max| is serialised via
50 // ToHandshakeMessage call if |negotiated_| is false.
51 void set(uint32 max, uint32 default_value);
53 // Returns the value negotiated if |negotiated_| is true, otherwise returns
54 // default_value_ (used to set default values before negotiation finishes).
55 uint32 GetUint32() const;
57 // Serialises |name_| and value to |out|. If |negotiated_| is true then
58 // |negotiated_value_| is serialised, otherwise |max_value_| is serialised.
59 void ToHandshakeMessage(CryptoHandshakeMessage* out) const;
61 // Sets |negotiated_value_| to the minimum of |max_value_| and the
62 // corresponding value from |client_hello|. If the corresponding value is
63 // missing and PRESENCE_OPTIONAL then |negotiated_value_| is set to
65 QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello,
66 std::string* error_details);
68 // Sets the |negotiated_value_| to the corresponding value from
69 // |server_hello|. Returns error if the value received in |server_hello| is
70 // greater than |max_value_|. If the corresponding value is missing and
71 // PRESENCE_OPTIONAL then |negotiated_value_| is set to |0|,
72 QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello,
73 std::string* error_details);
76 // Reads the value corresponding to |name_| from |msg| into |out|. If the
77 // |name_| is absent in |msg| and |presence_| is set to OPTIONAL |out| is set
79 QuicErrorCode ReadUint32(const CryptoHandshakeMessage& msg,
81 std::string* error_details) const;
84 uint32 default_value_;
85 uint32 negotiated_value_;
88 class NET_EXPORT_PRIVATE QuicNegotiableTag : public QuicNegotiableValue {
90 QuicNegotiableTag(QuicTag name, Presence presence);
93 // Sets the possible values that |negotiated_tag_| can take after negotiation
94 // and the default value that |negotiated_tag_| takes if OPTIONAL and *HLO
95 // msg doesn't contain tag |name_|.
96 void set(const QuicTagVector& possible_values, QuicTag default_value);
98 // Returns the negotiated tag if |negotiated_| is true, otherwise returns
99 // |default_value_| (used to set default values before negotiation finishes).
100 QuicTag GetTag() const;
102 // Serialises |name_| and vector (either possible or negotiated) to |out|. If
103 // |negotiated_| is true then |negotiated_tag_| is serialised, otherwise
104 // |possible_values_| is serialised.
105 void ToHandshakeMessage(CryptoHandshakeMessage* out) const;
107 // Selects the tag common to both tags in |client_hello| for |name_| and
108 // |possible_values_| with preference to tag in |possible_values_|. The
109 // selected tag is set as |negotiated_tag_|.
110 QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello,
111 std::string* error_details);
113 // Sets the value for |name_| tag in |server_hello| as |negotiated_value_|.
114 // Returns error if the value received in |server_hello| isn't present in
115 // |possible_values_|.
116 QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello,
117 std::string* error_details);
120 // Reads the vector corresponding to |name_| from |msg| into |out|. If the
121 // |name_| is absent in |msg| and |presence_| is set to OPTIONAL |out| is set
122 // to |possible_values_|.
123 QuicErrorCode ReadVector(const CryptoHandshakeMessage& msg,
126 std::string* error_details) const;
128 QuicTag negotiated_tag_;
129 QuicTagVector possible_values_;
130 QuicTag default_value_;
133 // QuicConfig contains non-crypto configuration options that are negotiated in
134 // the crypto handshake.
135 class NET_EXPORT_PRIVATE QuicConfig {
140 void set_congestion_control(const QuicTagVector& congestion_control,
141 QuicTag default_congestion_control);
143 QuicTag congestion_control() const;
145 void set_idle_connection_state_lifetime(
146 QuicTime::Delta max_idle_connection_state_lifetime,
147 QuicTime::Delta default_idle_conection_state_lifetime);
149 QuicTime::Delta idle_connection_state_lifetime() const;
151 QuicTime::Delta keepalive_timeout() const;
153 void set_max_streams_per_connection(size_t max_streams,
154 size_t default_streams);
156 uint32 max_streams_per_connection() const;
158 void set_max_time_before_crypto_handshake(
159 QuicTime::Delta max_time_before_crypto_handshake);
161 QuicTime::Delta max_time_before_crypto_handshake() const;
163 // Sets the server's TCP sender's max and default initial congestion window
165 void set_server_initial_congestion_window(size_t max_initial_window,
166 size_t default_initial_window);
168 uint32 server_initial_congestion_window() const;
170 // Sets the server's max packet size and default max packet size in bytes.
171 void set_server_max_packet_size(size_t max_bytes, size_t default_bytes);
173 uint32 server_max_packet_size() const;
175 // Sets an estimated initial round trip time in us.
176 void set_initial_round_trip_time_us(size_t max_rtt, size_t default_rtt);
178 uint32 initial_round_trip_time_us() const;
182 // SetDefaults sets the members to sensible, default values.
185 // ToHandshakeMessage serializes the settings in this object as a series of
186 // tags /value pairs and adds them to |out|.
187 void ToHandshakeMessage(CryptoHandshakeMessage* out) const;
189 // Calls ProcessClientHello on each negotiable parameter. On failure returns
190 // the corresponding QuicErrorCode and sets detailed error in |error_details|.
191 QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello,
192 std::string* error_details);
194 // Calls ProcessServerHello on each negotiable parameter. On failure returns
195 // the corresponding QuicErrorCode and sets detailed error in |error_details|.
196 QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello,
197 std::string* error_details);
200 // Congestion control feedback type.
201 QuicNegotiableTag congestion_control_;
202 // Idle connection state lifetime
203 QuicNegotiableUint32 idle_connection_state_lifetime_seconds_;
204 // Keepalive timeout, or 0 to turn off keepalive probes
205 QuicNegotiableUint32 keepalive_timeout_seconds_;
206 // Maximum number of streams that the connection can support.
207 QuicNegotiableUint32 max_streams_per_connection_;
208 // Maximum time till the session can be alive before crypto handshake is
209 // finished. (Not negotiated).
210 QuicTime::Delta max_time_before_crypto_handshake_;
211 // Initial congestion window in packets.
212 QuicNegotiableUint32 server_initial_congestion_window_;
213 // Maximum packet size for the server to send in bytes.
214 QuicNegotiableUint32 server_max_packet_size_;
215 // Initial round trip time estimate in microseconds.
216 QuicNegotiableUint32 initial_round_trip_time_us_;
221 #endif // NET_QUIC_QUIC_CONFIG_H_