1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_QUIC_QUIC_CONFIG_H_
#define NET_QUIC_QUIC_CONFIG_H_
#include <string>
#include "base/basictypes.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_time.h"
namespace net {
class CryptoHandshakeMessage;
// Describes whether or not a given QuicTag is required or optional in the
// handshake message.
enum QuicConfigPresence {
// This negotiable value can be absent from the handshake message. Default
// value is selected as the negotiated value in such a case.
PRESENCE_OPTIONAL,
// This negotiable value is required in the handshake message otherwise the
// Process*Hello function returns an error.
PRESENCE_REQUIRED,
};
// An abstract base class that stores a value that can be sent in CHLO/SHLO
// message. These values can be OPTIONAL or REQUIRED, depending on |presence_|.
class NET_EXPORT_PRIVATE QuicConfigValue {
public:
QuicConfigValue(QuicTag tag, QuicConfigPresence presence);
virtual ~QuicConfigValue();
// Serialises tag name and value(s) to |out|.
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const = 0;
// Selects a mutually acceptable value from those offered in |client_hello|
// and those defined in the subclass.
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) = 0;
// Selects a mutually acceptable value from those offered in |server_hello|
// and those defined in the subclass.
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) = 0;
protected:
const QuicTag tag_;
const QuicConfigPresence presence_;
};
class NET_EXPORT_PRIVATE QuicNegotiableValue : public QuicConfigValue {
public:
QuicNegotiableValue(QuicTag tag, QuicConfigPresence presence);
virtual ~QuicNegotiableValue();
bool negotiated() const {
return negotiated_;
}
protected:
bool negotiated_;
};
class NET_EXPORT_PRIVATE QuicNegotiableUint32 : public QuicNegotiableValue {
public:
// Default and max values default to 0.
QuicNegotiableUint32(QuicTag name, QuicConfigPresence presence);
virtual ~QuicNegotiableUint32();
// Sets the maximum possible value that can be achieved after negotiation and
// also the default values to be assumed if PRESENCE_OPTIONAL and the *HLO msg
// doesn't contain a value corresponding to |name_|. |max| is serialised via
// ToHandshakeMessage call if |negotiated_| is false.
void set(uint32 max, uint32 default_value);
// Returns the value negotiated if |negotiated_| is true, otherwise returns
// default_value_ (used to set default values before negotiation finishes).
uint32 GetUint32() const;
// Serialises |name_| and value to |out|. If |negotiated_| is true then
// |negotiated_value_| is serialised, otherwise |max_value_| is serialised.
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const OVERRIDE;
// Sets |negotiated_value_| to the minimum of |max_value_| and the
// corresponding value from |client_hello|. If the corresponding value is
// missing and PRESENCE_OPTIONAL then |negotiated_value_| is set to
// |default_value_|.
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) OVERRIDE;
// Sets the |negotiated_value_| to the corresponding value from
// |server_hello|. Returns error if the value received in |server_hello| is
// greater than |max_value_|. If the corresponding value is missing and
// PRESENCE_OPTIONAL then |negotiated_value_| is set to |0|,
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) OVERRIDE;
private:
uint32 max_value_;
uint32 default_value_;
uint32 negotiated_value_;
};
class NET_EXPORT_PRIVATE QuicNegotiableTag : public QuicNegotiableValue {
public:
QuicNegotiableTag(QuicTag name, QuicConfigPresence presence);
virtual ~QuicNegotiableTag();
// Sets the possible values that |negotiated_tag_| can take after negotiation
// and the default value that |negotiated_tag_| takes if OPTIONAL and *HLO
// msg doesn't contain tag |name_|.
void set(const QuicTagVector& possible_values, QuicTag default_value);
// Returns the negotiated tag if |negotiated_| is true, otherwise returns
// |default_value_| (used to set default values before negotiation finishes).
QuicTag GetTag() const;
// Serialises |name_| and vector (either possible or negotiated) to |out|. If
// |negotiated_| is true then |negotiated_tag_| is serialised, otherwise
// |possible_values_| is serialised.
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const OVERRIDE;
// Selects the tag common to both tags in |client_hello| for |name_| and
// |possible_values_| with preference to tag in |possible_values_|. The
// selected tag is set as |negotiated_tag_|.
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) OVERRIDE;
// Sets the value for |name_| tag in |server_hello| as |negotiated_value_|.
// Returns error if the value received in |server_hello| isn't present in
// |possible_values_|.
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) OVERRIDE;
private:
// Reads the vector corresponding to |name_| from |msg| into |out|. If the
// |name_| is absent in |msg| and |presence_| is set to OPTIONAL |out| is set
// to |possible_values_|.
QuicErrorCode ReadVector(const CryptoHandshakeMessage& msg,
const QuicTag** out,
size_t* out_length,
std::string* error_details) const;
QuicTag negotiated_tag_;
QuicTagVector possible_values_;
QuicTag default_value_;
};
// Stores uint32 from CHLO or SHLO messages that are not negotiated.
class NET_EXPORT_PRIVATE QuicFixedUint32 : public QuicConfigValue {
public:
QuicFixedUint32(QuicTag name,
QuicConfigPresence presence,
uint32 default_value);
virtual ~QuicFixedUint32();
// Returns the value in the *HLO message (or the default if not).
uint32 GetUint32() const;
void set_value(uint32 value) { value_ = value; }
// Serialises |tag_| and |value_| to |out|.
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const OVERRIDE;
// Sets |value_| to the corresponding value from |client_hello_| if it exists.
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) OVERRIDE;
// Sets |value_| to the corresponding value from |server_hello_| if it exists.
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) OVERRIDE;
private:
uint32 value_;
};
// QuicConfig contains non-crypto configuration options that are negotiated in
// the crypto handshake.
class NET_EXPORT_PRIVATE QuicConfig {
public:
QuicConfig();
~QuicConfig();
void set_congestion_control(const QuicTagVector& congestion_control,
QuicTag default_congestion_control);
QuicTag congestion_control() const;
void set_loss_detection(const QuicTagVector& loss_detection,
QuicTag default_loss_detection);
QuicTag loss_detection() const;
void set_idle_connection_state_lifetime(
QuicTime::Delta max_idle_connection_state_lifetime,
QuicTime::Delta default_idle_conection_state_lifetime);
QuicTime::Delta idle_connection_state_lifetime() const;
QuicTime::Delta keepalive_timeout() const;
void set_max_streams_per_connection(size_t max_streams,
size_t default_streams);
uint32 max_streams_per_connection() const;
void set_max_time_before_crypto_handshake(
QuicTime::Delta max_time_before_crypto_handshake);
QuicTime::Delta max_time_before_crypto_handshake() const;
// Sets the server's TCP sender's max and default initial congestion window
// in packets.
void set_server_initial_congestion_window(size_t max_initial_window,
size_t default_initial_window);
uint32 server_initial_congestion_window() const;
// Sets an estimated initial round trip time in us.
void set_initial_round_trip_time_us(size_t max_rtt, size_t default_rtt);
uint32 initial_round_trip_time_us() const;
void set_peer_initial_flow_control_window_bytes(uint32 window);
uint32 peer_initial_flow_control_window_bytes() const;
bool negotiated();
// SetDefaults sets the members to sensible, default values.
void SetDefaults();
// Enabled pacing.
void EnablePacing(bool enable_pacing);
// ToHandshakeMessage serializes the settings in this object as a series of
// tags /value pairs and adds them to |out|.
void ToHandshakeMessage(CryptoHandshakeMessage* out) const;
// Calls ProcessClientHello on each negotiable parameter. On failure returns
// the corresponding QuicErrorCode and sets detailed error in |error_details|.
QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello,
std::string* error_details);
// Calls ProcessServerHello on each negotiable parameter. On failure returns
// the corresponding QuicErrorCode and sets detailed error in |error_details|.
QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello,
std::string* error_details);
private:
// Congestion control feedback type.
QuicNegotiableTag congestion_control_;
// Loss detection feedback type.
QuicNegotiableTag loss_detection_;
// Idle connection state lifetime
QuicNegotiableUint32 idle_connection_state_lifetime_seconds_;
// Keepalive timeout, or 0 to turn off keepalive probes
QuicNegotiableUint32 keepalive_timeout_seconds_;
// Maximum number of streams that the connection can support.
QuicNegotiableUint32 max_streams_per_connection_;
// Maximum time till the session can be alive before crypto handshake is
// finished. (Not negotiated).
QuicTime::Delta max_time_before_crypto_handshake_;
// Initial congestion window in packets.
QuicNegotiableUint32 server_initial_congestion_window_;
// Initial round trip time estimate in microseconds.
QuicNegotiableUint32 initial_round_trip_time_us_;
// Peer's initial flow control receive window in bytes.
QuicFixedUint32 peer_initial_flow_control_window_bytes_;
};
} // namespace net
#endif // NET_QUIC_QUIC_CONFIG_H_
|