MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / net / quic / quic_config.h
blob5328ef61710a68caa059f8171f3122274c9c5c27
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 namespace test {
17 class QuicConfigPeer;
18 } // namespace test
20 class CryptoHandshakeMessage;
22 // Describes whether or not a given QuicTag is required or optional in the
23 // handshake message.
24 enum QuicConfigPresence {
25 // This negotiable value can be absent from the handshake message. Default
26 // value is selected as the negotiated value in such a case.
27 PRESENCE_OPTIONAL,
28 // This negotiable value is required in the handshake message otherwise the
29 // Process*Hello function returns an error.
30 PRESENCE_REQUIRED,
33 // Whether the CryptoHandshakeMessage is from the client or server.
34 enum HelloType {
35 CLIENT,
36 SERVER,
39 // An abstract base class that stores a value that can be sent in CHLO/SHLO
40 // message. These values can be OPTIONAL or REQUIRED, depending on |presence_|.
41 class NET_EXPORT_PRIVATE QuicConfigValue {
42 public:
43 QuicConfigValue(QuicTag tag, QuicConfigPresence presence);
44 virtual ~QuicConfigValue();
46 // Serialises tag name and value(s) to |out|.
47 virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const = 0;
49 // Selects a mutually acceptable value from those offered in |peer_hello|
50 // and those defined in the subclass.
51 virtual QuicErrorCode ProcessPeerHello(
52 const CryptoHandshakeMessage& peer_hello,
53 HelloType hello_type,
54 std::string* error_details) = 0;
56 protected:
57 const QuicTag tag_;
58 const QuicConfigPresence presence_;
61 class NET_EXPORT_PRIVATE QuicNegotiableValue : public QuicConfigValue {
62 public:
63 QuicNegotiableValue(QuicTag tag, QuicConfigPresence presence);
64 ~QuicNegotiableValue() override;
66 bool negotiated() const {
67 return negotiated_;
70 protected:
71 bool negotiated_;
74 class NET_EXPORT_PRIVATE QuicNegotiableUint32 : public QuicNegotiableValue {
75 public:
76 // Default and max values default to 0.
77 QuicNegotiableUint32(QuicTag name, QuicConfigPresence presence);
78 ~QuicNegotiableUint32() override;
80 // Sets the maximum possible value that can be achieved after negotiation and
81 // also the default values to be assumed if PRESENCE_OPTIONAL and the *HLO msg
82 // doesn't contain a value corresponding to |name_|. |max| is serialised via
83 // ToHandshakeMessage call if |negotiated_| is false.
84 void set(uint32 max, uint32 default_value);
86 // Returns the value negotiated if |negotiated_| is true, otherwise returns
87 // default_value_ (used to set default values before negotiation finishes).
88 uint32 GetUint32() const;
90 // Serialises |name_| and value to |out|. If |negotiated_| is true then
91 // |negotiated_value_| is serialised, otherwise |max_value_| is serialised.
92 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
94 // Sets |negotiated_value_| to the minimum of |max_value_| and the
95 // corresponding value from |peer_hello|. If the corresponding value is
96 // missing and PRESENCE_OPTIONAL then |negotiated_value_| is set to
97 // |default_value_|.
98 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
99 HelloType hello_type,
100 std::string* error_details) override;
102 private:
103 uint32 max_value_;
104 uint32 default_value_;
105 uint32 negotiated_value_;
108 class NET_EXPORT_PRIVATE QuicNegotiableTag : public QuicNegotiableValue {
109 public:
110 QuicNegotiableTag(QuicTag name, QuicConfigPresence presence);
111 ~QuicNegotiableTag() override;
113 // Sets the possible values that |negotiated_tag_| can take after negotiation
114 // and the default value that |negotiated_tag_| takes if OPTIONAL and *HLO
115 // msg doesn't contain tag |name_|.
116 void set(const QuicTagVector& possible_values, QuicTag default_value);
118 // Returns the negotiated tag if |negotiated_| is true, otherwise returns
119 // |default_value_| (used to set default values before negotiation finishes).
120 QuicTag GetTag() const;
122 // Serialises |name_| and vector (either possible or negotiated) to |out|. If
123 // |negotiated_| is true then |negotiated_tag_| is serialised, otherwise
124 // |possible_values_| is serialised.
125 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
127 // Selects the tag common to both tags in |client_hello| for |name_| and
128 // |possible_values_| with preference to tag in |possible_values_|. The
129 // selected tag is set as |negotiated_tag_|.
130 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
131 HelloType hello_type,
132 std::string* error_details) override;
134 private:
135 // Reads the vector corresponding to |name_| from |msg| into |out|. If the
136 // |name_| is absent in |msg| and |presence_| is set to OPTIONAL |out| is set
137 // to |possible_values_|.
138 QuicErrorCode ReadVector(const CryptoHandshakeMessage& msg,
139 const QuicTag** out,
140 size_t* out_length,
141 std::string* error_details) const;
143 QuicTag negotiated_tag_;
144 QuicTagVector possible_values_;
145 QuicTag default_value_;
148 // Stores uint32 from CHLO or SHLO messages that are not negotiated.
149 class NET_EXPORT_PRIVATE QuicFixedUint32 : public QuicConfigValue {
150 public:
151 QuicFixedUint32(QuicTag name, QuicConfigPresence presence);
152 ~QuicFixedUint32() override;
154 bool HasSendValue() const;
156 uint32 GetSendValue() const;
158 void SetSendValue(uint32 value);
160 bool HasReceivedValue() const;
162 uint32 GetReceivedValue() const;
164 void SetReceivedValue(uint32 value);
166 // If has_send_value is true, serialises |tag_| and |send_value_| to |out|.
167 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
169 // Sets |value_| to the corresponding value from |peer_hello_| if it exists.
170 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
171 HelloType hello_type,
172 std::string* error_details) override;
174 private:
175 uint32 send_value_;
176 bool has_send_value_;
177 uint32 receive_value_;
178 bool has_receive_value_;
181 // Stores tag from CHLO or SHLO messages that are not negotiated.
182 class NET_EXPORT_PRIVATE QuicFixedTag : public QuicConfigValue {
183 public:
184 QuicFixedTag(QuicTag name, QuicConfigPresence presence);
185 ~QuicFixedTag() override;
187 bool HasSendValue() const;
189 QuicTag GetSendValue() const;
191 void SetSendValue(QuicTag value);
193 bool HasReceivedValue() const;
195 QuicTag GetReceivedValue() const;
197 void SetReceivedValue(QuicTag value);
199 // If has_send_value is true, serialises |tag_| and |send_value_| to |out|.
200 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
202 // Sets |value_| to the corresponding value from |client_hello_| if it exists.
203 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
204 HelloType hello_type,
205 std::string* error_details) override;
207 private:
208 QuicTag send_value_;
209 bool has_send_value_;
210 QuicTag receive_value_;
211 bool has_receive_value_;
214 // Stores tag from CHLO or SHLO messages that are not negotiated.
215 class NET_EXPORT_PRIVATE QuicFixedTagVector : public QuicConfigValue {
216 public:
217 QuicFixedTagVector(QuicTag name, QuicConfigPresence presence);
218 ~QuicFixedTagVector() override;
220 bool HasSendValues() const;
222 QuicTagVector GetSendValues() const;
224 void SetSendValues(const QuicTagVector& values);
226 bool HasReceivedValues() const;
228 QuicTagVector GetReceivedValues() const;
230 void SetReceivedValues(const QuicTagVector& values);
232 // If has_send_value is true, serialises |tag_vector_| and |send_value_| to
233 // |out|.
234 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override;
236 // Sets |receive_values_| to the corresponding value from |client_hello_| if
237 // it exists.
238 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
239 HelloType hello_type,
240 std::string* error_details) override;
242 private:
243 QuicTagVector send_values_;
244 bool has_send_values_;
245 QuicTagVector receive_values_;
246 bool has_receive_values_;
249 // QuicConfig contains non-crypto configuration options that are negotiated in
250 // the crypto handshake.
251 class NET_EXPORT_PRIVATE QuicConfig {
252 public:
253 QuicConfig();
254 ~QuicConfig();
256 void SetCongestionFeedback(const QuicTagVector& congestion_feedback,
257 QuicTag default_congestion_feedback);
259 QuicTag CongestionFeedback() const;
261 void SetConnectionOptionsToSend(const QuicTagVector& connection_options);
263 bool HasReceivedConnectionOptions() const;
265 QuicTagVector ReceivedConnectionOptions() const;
267 bool HasSendConnectionOptions() const;
269 QuicTagVector SendConnectionOptions() const;
271 void SetIdleConnectionStateLifetime(
272 QuicTime::Delta max_idle_connection_state_lifetime,
273 QuicTime::Delta default_idle_conection_state_lifetime);
275 QuicTime::Delta IdleConnectionStateLifetime() const;
277 QuicTime::Delta KeepaliveTimeout() const;
279 void SetMaxStreamsPerConnection(size_t max_streams, size_t default_streams);
281 uint32 MaxStreamsPerConnection() const;
283 void set_max_time_before_crypto_handshake(
284 QuicTime::Delta max_time_before_crypto_handshake) {
285 max_time_before_crypto_handshake_ = max_time_before_crypto_handshake;
288 QuicTime::Delta max_time_before_crypto_handshake() const {
289 return max_time_before_crypto_handshake_;
292 void set_max_idle_time_before_crypto_handshake(
293 QuicTime::Delta max_idle_time_before_crypto_handshake) {
294 max_idle_time_before_crypto_handshake_ =
295 max_idle_time_before_crypto_handshake;
298 QuicTime::Delta max_idle_time_before_crypto_handshake() const {
299 return max_idle_time_before_crypto_handshake_;
302 void set_max_undecryptable_packets(size_t max_undecryptable_packets) {
303 max_undecryptable_packets_ = max_undecryptable_packets;
306 size_t max_undecryptable_packets() const {
307 return max_undecryptable_packets_;
310 // Sets the peer's default initial congestion window in packets.
311 void SetInitialCongestionWindowToSend(size_t initial_window);
313 bool HasReceivedInitialCongestionWindow() const;
315 uint32 ReceivedInitialCongestionWindow() const;
317 // Sets an estimated initial round trip time in us.
318 void SetInitialRoundTripTimeUsToSend(size_t rtt_us);
320 bool HasReceivedInitialRoundTripTimeUs() const;
322 uint32 ReceivedInitialRoundTripTimeUs() const;
324 bool HasInitialRoundTripTimeUsToSend() const;
326 uint32 GetInitialRoundTripTimeUsToSend() const;
328 // TODO(rjshade): Remove all InitialFlowControlWindow methods when removing
329 // QUIC_VERSION_19.
330 // Sets an initial stream flow control window size to transmit to the peer.
331 void SetInitialFlowControlWindowToSend(uint32 window_bytes);
333 uint32 GetInitialFlowControlWindowToSend() const;
335 bool HasReceivedInitialFlowControlWindowBytes() const;
337 uint32 ReceivedInitialFlowControlWindowBytes() const;
339 // Sets an initial stream flow control window size to transmit to the peer.
340 void SetInitialStreamFlowControlWindowToSend(uint32 window_bytes);
342 uint32 GetInitialStreamFlowControlWindowToSend() const;
344 bool HasReceivedInitialStreamFlowControlWindowBytes() const;
346 uint32 ReceivedInitialStreamFlowControlWindowBytes() const;
348 // Sets an initial session flow control window size to transmit to the peer.
349 void SetInitialSessionFlowControlWindowToSend(uint32 window_bytes);
351 uint32 GetInitialSessionFlowControlWindowToSend() const;
353 bool HasReceivedInitialSessionFlowControlWindowBytes() const;
355 uint32 ReceivedInitialSessionFlowControlWindowBytes() const;
357 // Sets socket receive buffer to transmit to the peer.
358 void SetSocketReceiveBufferToSend(uint32 window_bytes);
360 uint32 GetSocketReceiveBufferToSend() const;
362 bool HasReceivedSocketReceiveBuffer() const;
364 uint32 ReceivedSocketReceiveBuffer() const;
366 bool negotiated() const;
368 // ToHandshakeMessage serialises the settings in this object as a series of
369 // tags /value pairs and adds them to |out|.
370 void ToHandshakeMessage(CryptoHandshakeMessage* out) const;
372 // Calls ProcessPeerHello on each negotiable parameter. On failure returns
373 // the corresponding QuicErrorCode and sets detailed error in |error_details|.
374 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello,
375 HelloType hello_type,
376 std::string* error_details);
378 private:
379 friend class test::QuicConfigPeer;
381 // SetDefaults sets the members to sensible, default values.
382 void SetDefaults();
384 // Configurations options that are not negotiated.
385 // Maximum time the session can be alive before crypto handshake is finished.
386 QuicTime::Delta max_time_before_crypto_handshake_;
387 // Maximum idle time before the crypto handshake has completed.
388 QuicTime::Delta max_idle_time_before_crypto_handshake_;
389 // Maximum number of undecryptable packets stored before CHLO/SHLO.
390 size_t max_undecryptable_packets_;
392 // Congestion control feedback type.
393 QuicNegotiableTag congestion_feedback_;
394 // Connection options.
395 QuicFixedTagVector connection_options_;
396 // Idle connection state lifetime
397 QuicNegotiableUint32 idle_connection_state_lifetime_seconds_;
398 // Keepalive timeout, or 0 to turn off keepalive probes
399 QuicNegotiableUint32 keepalive_timeout_seconds_;
400 // Maximum number of streams that the connection can support.
401 QuicNegotiableUint32 max_streams_per_connection_;
402 // Initial congestion window in packets.
403 QuicFixedUint32 initial_congestion_window_;
404 // Initial round trip time estimate in microseconds.
405 QuicFixedUint32 initial_round_trip_time_us_;
407 // TODO(rjshade): Remove when removing QUIC_VERSION_19.
408 // Initial flow control receive window in bytes.
409 QuicFixedUint32 initial_flow_control_window_bytes_;
411 // Initial stream flow control receive window in bytes.
412 QuicFixedUint32 initial_stream_flow_control_window_bytes_;
413 // Initial session flow control receive window in bytes.
414 QuicFixedUint32 initial_session_flow_control_window_bytes_;
416 // Socket receive buffer in bytes.
417 QuicFixedUint32 socket_receive_buffer_;
420 } // namespace net
422 #endif // NET_QUIC_QUIC_CONFIG_H_