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