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/quic_protocol.h"
13 #include "net/quic/quic_time.h"
14 #include "net/quic/quic_utils.h"
18 class NET_EXPORT_PRIVATE QuicNegotiableValue
{
21 // This negotiable value can be absent from the handshake message. Default
22 // value is selected as the negotiated value in such a case.
24 // This negotiable value is required in the handshake message otherwise the
25 // Process*Hello function returns an error.
29 QuicNegotiableValue(QuicTag tag
, Presence presence
);
31 bool negotiated() const {
37 const Presence presence_
;
41 class NET_EXPORT_PRIVATE QuicNegotiableUint32
: public QuicNegotiableValue
{
43 // Default and max values default to 0.
44 QuicNegotiableUint32(QuicTag name
, Presence presence
);
46 // Sets the maximum possible value that can be achieved after negotiation and
47 // also the default values to be assumed if PRESENCE_OPTIONAL and the *HLO msg
48 // doesn't contain a value corresponding to |name_|. |max| is serialised via
49 // ToHandshakeMessage call if |negotiated_| is false.
50 void set(uint32 max
, uint32 default_value
);
52 // Returns the value negotiated if |negotiated_| is true, otherwise returns
53 // default_value_ (used to set default values before negotiation finishes).
54 uint32
GetUint32() const;
56 // Serialises |name_| and value to |out|. If |negotiated_| is true then
57 // |negotiated_value_| is serialised, otherwise |max_value_| is serialised.
58 void ToHandshakeMessage(CryptoHandshakeMessage
* out
) const;
60 // Sets |negotiated_value_| to the minimum of |max_value_| and the
61 // corresponding value from |client_hello|. If the corresponding value is
62 // missing and PRESENCE_OPTIONAL then |negotiated_value_| is set to
64 QuicErrorCode
ProcessClientHello(const CryptoHandshakeMessage
& client_hello
,
65 std::string
* error_details
);
67 // Sets the |negotiated_value_| to the corresponding value from
68 // |server_hello|. Returns error if the value received in |server_hello| is
69 // greater than |max_value_|. If the corresponding value is missing and
70 // PRESENCE_OPTIONAL then |negotiated_value_| is set to |0|,
71 QuicErrorCode
ProcessServerHello(const CryptoHandshakeMessage
& server_hello
,
72 std::string
* error_details
);
75 // Reads the value corresponding to |name_| from |msg| into |out|. If the
76 // |name_| is absent in |msg| and |presence_| is set to OPTIONAL |out| is set
78 QuicErrorCode
ReadUint32(const CryptoHandshakeMessage
& msg
,
80 std::string
* error_details
) const;
83 uint32 default_value_
;
84 uint32 negotiated_value_
;
87 class NET_EXPORT_PRIVATE QuicNegotiableTag
: public QuicNegotiableValue
{
89 QuicNegotiableTag(QuicTag name
, Presence presence
);
92 // Sets the possible values that |negotiated_tag_| can take after negotiation
93 // and the default value that |negotiated_tag_| takes if OPTIONAL and *HLO
94 // msg doesn't contain tag |name_|.
95 void set(const QuicTagVector
& possible_values
, QuicTag default_value
);
97 // Returns the negotiated tag if |negotiated_| is true, otherwise returns
98 // |default_value_| (used to set default values before negotiation finishes).
99 QuicTag
GetTag() const;
101 // Serialises |name_| and vector (either possible or negotiated) to |out|. If
102 // |negotiated_| is true then |negotiated_tag_| is serialised, otherwise
103 // |possible_values_| is serialised.
104 void ToHandshakeMessage(CryptoHandshakeMessage
* out
) const;
106 // Selects the tag common to both tags in |client_hello| for |name_| and
107 // |possible_values_| with preference to tag in |possible_values_|. The
108 // selected tag is set as |negotiated_tag_|.
109 QuicErrorCode
ProcessClientHello(const CryptoHandshakeMessage
& client_hello
,
110 std::string
* error_details
);
112 // Sets the value for |name_| tag in |server_hello| as |negotiated_value_|.
113 // Returns error if the value received in |server_hello| isn't present in
114 // |possible_values_|.
115 QuicErrorCode
ProcessServerHello(const CryptoHandshakeMessage
& server_hello
,
116 std::string
* error_details
);
119 // Reads the vector corresponding to |name_| from |msg| into |out|. If the
120 // |name_| is absent in |msg| and |presence_| is set to OPTIONAL |out| is set
121 // to |possible_values_|.
122 QuicErrorCode
ReadVector(const CryptoHandshakeMessage
& msg
,
125 std::string
* error_details
) const;
127 QuicTag negotiated_tag_
;
128 QuicTagVector possible_values_
;
129 QuicTag default_value_
;
132 // QuicConfig contains non-crypto configuration options that are negotiated in
133 // the crypto handshake.
134 class NET_EXPORT_PRIVATE QuicConfig
{
139 void set_congestion_control(const QuicTagVector
& congestion_control
,
140 QuicTag default_congestion_control
);
142 QuicTag
congestion_control() const;
144 void set_idle_connection_state_lifetime(
145 QuicTime::Delta max_idle_connection_state_lifetime
,
146 QuicTime::Delta default_idle_conection_state_lifetime
);
148 QuicTime::Delta
idle_connection_state_lifetime() const;
150 QuicTime::Delta
keepalive_timeout() const;
152 void set_max_streams_per_connection(size_t max_streams
,
153 size_t default_streams
);
155 uint32
max_streams_per_connection() const;
157 void set_max_time_before_crypto_handshake(
158 QuicTime::Delta max_time_before_crypto_handshake
);
160 QuicTime::Delta
max_time_before_crypto_handshake() const;
162 // Sets the server's TCP sender's max and default initial congestion window
164 void set_server_initial_congestion_window(size_t max_initial_window
,
165 size_t default_initial_window
);
167 uint32
server_initial_congestion_window() const;
169 // Sets an estimated initial round trip time in us.
170 void set_initial_round_trip_time_us(size_t max_rtt
, size_t default_rtt
);
172 uint32
initial_round_trip_time_us() const;
176 // SetDefaults sets the members to sensible, default values.
179 // ToHandshakeMessage serializes the settings in this object as a series of
180 // tags /value pairs and adds them to |out|.
181 void ToHandshakeMessage(CryptoHandshakeMessage
* out
) const;
183 // Calls ProcessClientHello on each negotiable parameter. On failure returns
184 // the corresponding QuicErrorCode and sets detailed error in |error_details|.
185 QuicErrorCode
ProcessClientHello(const CryptoHandshakeMessage
& client_hello
,
186 std::string
* error_details
);
188 // Calls ProcessServerHello on each negotiable parameter. On failure returns
189 // the corresponding QuicErrorCode and sets detailed error in |error_details|.
190 QuicErrorCode
ProcessServerHello(const CryptoHandshakeMessage
& server_hello
,
191 std::string
* error_details
);
194 // Congestion control feedback type.
195 QuicNegotiableTag congestion_control_
;
196 // Idle connection state lifetime
197 QuicNegotiableUint32 idle_connection_state_lifetime_seconds_
;
198 // Keepalive timeout, or 0 to turn off keepalive probes
199 QuicNegotiableUint32 keepalive_timeout_seconds_
;
200 // Maximum number of streams that the connection can support.
201 QuicNegotiableUint32 max_streams_per_connection_
;
202 // Maximum time till the session can be alive before crypto handshake is
203 // finished. (Not negotiated).
204 QuicTime::Delta max_time_before_crypto_handshake_
;
205 // Initial congestion window in packets.
206 QuicNegotiableUint32 server_initial_congestion_window_
;
207 // Initial round trip time estimate in microseconds.
208 QuicNegotiableUint32 initial_round_trip_time_us_
;
213 #endif // NET_QUIC_QUIC_CONFIG_H_