| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef NET_QUIC_QUIC_CONFIG_H_ | |
| 6 #define NET_QUIC_QUIC_CONFIG_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "net/quic/quic_protocol.h" | |
| 12 #include "net/quic/quic_time.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 namespace test { | |
| 17 class QuicConfigPeer; | |
| 18 } // namespace test | |
| 19 | |
| 20 class CryptoHandshakeMessage; | |
| 21 | |
| 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, | |
| 31 }; | |
| 32 | |
| 33 // Whether the CryptoHandshakeMessage is from the client or server. | |
| 34 enum HelloType { | |
| 35 CLIENT, | |
| 36 SERVER, | |
| 37 }; | |
| 38 | |
| 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(); | |
| 45 | |
| 46 // Serialises tag name and value(s) to |out|. | |
| 47 virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const = 0; | |
| 48 | |
| 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; | |
| 55 | |
| 56 protected: | |
| 57 const QuicTag tag_; | |
| 58 const QuicConfigPresence presence_; | |
| 59 }; | |
| 60 | |
| 61 class NET_EXPORT_PRIVATE QuicNegotiableValue : public QuicConfigValue { | |
| 62 public: | |
| 63 QuicNegotiableValue(QuicTag tag, QuicConfigPresence presence); | |
| 64 ~QuicNegotiableValue() override; | |
| 65 | |
| 66 bool negotiated() const { | |
| 67 return negotiated_; | |
| 68 } | |
| 69 | |
| 70 protected: | |
| 71 void set_negotiated(bool negotiated) { negotiated_ = negotiated; } | |
| 72 | |
| 73 private: | |
| 74 bool negotiated_; | |
| 75 }; | |
| 76 | |
| 77 class NET_EXPORT_PRIVATE QuicNegotiableUint32 : public QuicNegotiableValue { | |
| 78 public: | |
| 79 // Default and max values default to 0. | |
| 80 QuicNegotiableUint32(QuicTag name, QuicConfigPresence presence); | |
| 81 ~QuicNegotiableUint32() override; | |
| 82 | |
| 83 // Sets the maximum possible value that can be achieved after negotiation and | |
| 84 // also the default values to be assumed if PRESENCE_OPTIONAL and the *HLO msg | |
| 85 // doesn't contain a value corresponding to |name_|. |max| is serialised via | |
| 86 // ToHandshakeMessage call if |negotiated_| is false. | |
| 87 void set(uint32 max, uint32 default_value); | |
| 88 | |
| 89 // Returns the value negotiated if |negotiated_| is true, otherwise returns | |
| 90 // default_value_ (used to set default values before negotiation finishes). | |
| 91 uint32 GetUint32() const; | |
| 92 | |
| 93 // Serialises |name_| and value to |out|. If |negotiated_| is true then | |
| 94 // |negotiated_value_| is serialised, otherwise |max_value_| is serialised. | |
| 95 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override; | |
| 96 | |
| 97 // Sets |negotiated_value_| to the minimum of |max_value_| and the | |
| 98 // corresponding value from |peer_hello|. If the corresponding value is | |
| 99 // missing and PRESENCE_OPTIONAL then |negotiated_value_| is set to | |
| 100 // |default_value_|. | |
| 101 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello, | |
| 102 HelloType hello_type, | |
| 103 std::string* error_details) override; | |
| 104 | |
| 105 private: | |
| 106 uint32 max_value_; | |
| 107 uint32 default_value_; | |
| 108 uint32 negotiated_value_; | |
| 109 }; | |
| 110 | |
| 111 class NET_EXPORT_PRIVATE QuicNegotiableTag : public QuicNegotiableValue { | |
| 112 public: | |
| 113 QuicNegotiableTag(QuicTag name, QuicConfigPresence presence); | |
| 114 ~QuicNegotiableTag() override; | |
| 115 | |
| 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); | |
| 120 | |
| 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; | |
| 124 | |
| 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 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override; | |
| 129 | |
| 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 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello, | |
| 134 HelloType hello_type, | |
| 135 std::string* error_details) override; | |
| 136 | |
| 137 private: | |
| 138 // Reads the vector corresponding to |name_| from |msg| into |out|. If the | |
| 139 // |name_| is absent in |msg| and |presence_| is set to OPTIONAL |out| is set | |
| 140 // to |possible_values_|. | |
| 141 QuicErrorCode ReadVector(const CryptoHandshakeMessage& msg, | |
| 142 const QuicTag** out, | |
| 143 size_t* out_length, | |
| 144 std::string* error_details) const; | |
| 145 | |
| 146 QuicTag negotiated_tag_; | |
| 147 QuicTagVector possible_values_; | |
| 148 QuicTag default_value_; | |
| 149 }; | |
| 150 | |
| 151 // Stores uint32 from CHLO or SHLO messages that are not negotiated. | |
| 152 class NET_EXPORT_PRIVATE QuicFixedUint32 : public QuicConfigValue { | |
| 153 public: | |
| 154 QuicFixedUint32(QuicTag name, QuicConfigPresence presence); | |
| 155 ~QuicFixedUint32() override; | |
| 156 | |
| 157 bool HasSendValue() const; | |
| 158 | |
| 159 uint32 GetSendValue() const; | |
| 160 | |
| 161 void SetSendValue(uint32 value); | |
| 162 | |
| 163 bool HasReceivedValue() const; | |
| 164 | |
| 165 uint32 GetReceivedValue() const; | |
| 166 | |
| 167 void SetReceivedValue(uint32 value); | |
| 168 | |
| 169 // If has_send_value is true, serialises |tag_| and |send_value_| to |out|. | |
| 170 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override; | |
| 171 | |
| 172 // Sets |value_| to the corresponding value from |peer_hello_| if it exists. | |
| 173 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello, | |
| 174 HelloType hello_type, | |
| 175 std::string* error_details) override; | |
| 176 | |
| 177 private: | |
| 178 uint32 send_value_; | |
| 179 bool has_send_value_; | |
| 180 uint32 receive_value_; | |
| 181 bool has_receive_value_; | |
| 182 }; | |
| 183 | |
| 184 // Stores tag from CHLO or SHLO messages that are not negotiated. | |
| 185 class NET_EXPORT_PRIVATE QuicFixedTag : public QuicConfigValue { | |
| 186 public: | |
| 187 QuicFixedTag(QuicTag name, QuicConfigPresence presence); | |
| 188 ~QuicFixedTag() override; | |
| 189 | |
| 190 bool HasSendValue() const; | |
| 191 | |
| 192 QuicTag GetSendValue() const; | |
| 193 | |
| 194 void SetSendValue(QuicTag value); | |
| 195 | |
| 196 bool HasReceivedValue() const; | |
| 197 | |
| 198 QuicTag GetReceivedValue() const; | |
| 199 | |
| 200 void SetReceivedValue(QuicTag value); | |
| 201 | |
| 202 // If has_send_value is true, serialises |tag_| and |send_value_| to |out|. | |
| 203 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override; | |
| 204 | |
| 205 // Sets |value_| to the corresponding value from |client_hello_| if it exists. | |
| 206 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello, | |
| 207 HelloType hello_type, | |
| 208 std::string* error_details) override; | |
| 209 | |
| 210 private: | |
| 211 QuicTag send_value_; | |
| 212 bool has_send_value_; | |
| 213 QuicTag receive_value_; | |
| 214 bool has_receive_value_; | |
| 215 }; | |
| 216 | |
| 217 // Stores tag from CHLO or SHLO messages that are not negotiated. | |
| 218 class NET_EXPORT_PRIVATE QuicFixedTagVector : public QuicConfigValue { | |
| 219 public: | |
| 220 QuicFixedTagVector(QuicTag name, QuicConfigPresence presence); | |
| 221 ~QuicFixedTagVector() override; | |
| 222 | |
| 223 bool HasSendValues() const; | |
| 224 | |
| 225 QuicTagVector GetSendValues() const; | |
| 226 | |
| 227 void SetSendValues(const QuicTagVector& values); | |
| 228 | |
| 229 bool HasReceivedValues() const; | |
| 230 | |
| 231 QuicTagVector GetReceivedValues() const; | |
| 232 | |
| 233 void SetReceivedValues(const QuicTagVector& values); | |
| 234 | |
| 235 // If has_send_value is true, serialises |tag_vector_| and |send_value_| to | |
| 236 // |out|. | |
| 237 void ToHandshakeMessage(CryptoHandshakeMessage* out) const override; | |
| 238 | |
| 239 // Sets |receive_values_| to the corresponding value from |client_hello_| if | |
| 240 // it exists. | |
| 241 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello, | |
| 242 HelloType hello_type, | |
| 243 std::string* error_details) override; | |
| 244 | |
| 245 private: | |
| 246 QuicTagVector send_values_; | |
| 247 bool has_send_values_; | |
| 248 QuicTagVector receive_values_; | |
| 249 bool has_receive_values_; | |
| 250 }; | |
| 251 | |
| 252 // QuicConfig contains non-crypto configuration options that are negotiated in | |
| 253 // the crypto handshake. | |
| 254 class NET_EXPORT_PRIVATE QuicConfig { | |
| 255 public: | |
| 256 QuicConfig(); | |
| 257 ~QuicConfig(); | |
| 258 | |
| 259 void SetConnectionOptionsToSend(const QuicTagVector& connection_options); | |
| 260 | |
| 261 bool HasReceivedConnectionOptions() const; | |
| 262 | |
| 263 QuicTagVector ReceivedConnectionOptions() const; | |
| 264 | |
| 265 bool HasSendConnectionOptions() const; | |
| 266 | |
| 267 QuicTagVector SendConnectionOptions() const; | |
| 268 | |
| 269 void SetIdleConnectionStateLifetime( | |
| 270 QuicTime::Delta max_idle_connection_state_lifetime, | |
| 271 QuicTime::Delta default_idle_conection_state_lifetime); | |
| 272 | |
| 273 QuicTime::Delta IdleConnectionStateLifetime() const; | |
| 274 | |
| 275 void SetSilentClose(bool silent_close); | |
| 276 | |
| 277 bool SilentClose() const; | |
| 278 | |
| 279 void SetMaxStreamsPerConnection(size_t max_streams, size_t default_streams); | |
| 280 | |
| 281 uint32 MaxStreamsPerConnection() const; | |
| 282 | |
| 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; | |
| 286 } | |
| 287 | |
| 288 QuicTime::Delta max_time_before_crypto_handshake() const { | |
| 289 return max_time_before_crypto_handshake_; | |
| 290 } | |
| 291 | |
| 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; | |
| 296 } | |
| 297 | |
| 298 QuicTime::Delta max_idle_time_before_crypto_handshake() const { | |
| 299 return max_idle_time_before_crypto_handshake_; | |
| 300 } | |
| 301 | |
| 302 void set_max_undecryptable_packets(size_t max_undecryptable_packets) { | |
| 303 max_undecryptable_packets_ = max_undecryptable_packets; | |
| 304 } | |
| 305 | |
| 306 size_t max_undecryptable_packets() const { | |
| 307 return max_undecryptable_packets_; | |
| 308 } | |
| 309 | |
| 310 bool HasSetBytesForConnectionIdToSend() const; | |
| 311 | |
| 312 // Sets the peer's connection id length, in bytes. | |
| 313 void SetBytesForConnectionIdToSend(uint32 bytes); | |
| 314 | |
| 315 bool HasReceivedBytesForConnectionId() const; | |
| 316 | |
| 317 uint32 ReceivedBytesForConnectionId() const; | |
| 318 | |
| 319 // Sets an estimated initial round trip time in us. | |
| 320 void SetInitialRoundTripTimeUsToSend(uint32 rtt_us); | |
| 321 | |
| 322 bool HasReceivedInitialRoundTripTimeUs() const; | |
| 323 | |
| 324 uint32 ReceivedInitialRoundTripTimeUs() const; | |
| 325 | |
| 326 bool HasInitialRoundTripTimeUsToSend() const; | |
| 327 | |
| 328 uint32 GetInitialRoundTripTimeUsToSend() const; | |
| 329 | |
| 330 // Sets an initial stream flow control window size to transmit to the peer. | |
| 331 void SetInitialStreamFlowControlWindowToSend(uint32 window_bytes); | |
| 332 | |
| 333 uint32 GetInitialStreamFlowControlWindowToSend() const; | |
| 334 | |
| 335 bool HasReceivedInitialStreamFlowControlWindowBytes() const; | |
| 336 | |
| 337 uint32 ReceivedInitialStreamFlowControlWindowBytes() const; | |
| 338 | |
| 339 // Sets an initial session flow control window size to transmit to the peer. | |
| 340 void SetInitialSessionFlowControlWindowToSend(uint32 window_bytes); | |
| 341 | |
| 342 uint32 GetInitialSessionFlowControlWindowToSend() const; | |
| 343 | |
| 344 bool HasReceivedInitialSessionFlowControlWindowBytes() const; | |
| 345 | |
| 346 uint32 ReceivedInitialSessionFlowControlWindowBytes() const; | |
| 347 | |
| 348 // Sets socket receive buffer to transmit to the peer. | |
| 349 void SetSocketReceiveBufferToSend(uint32 window_bytes); | |
| 350 | |
| 351 uint32 GetSocketReceiveBufferToSend() const; | |
| 352 | |
| 353 bool HasReceivedSocketReceiveBuffer() const; | |
| 354 | |
| 355 uint32 ReceivedSocketReceiveBuffer() const; | |
| 356 | |
| 357 bool negotiated() const; | |
| 358 | |
| 359 // ToHandshakeMessage serialises the settings in this object as a series of | |
| 360 // tags /value pairs and adds them to |out|. | |
| 361 void ToHandshakeMessage(CryptoHandshakeMessage* out) const; | |
| 362 | |
| 363 // Calls ProcessPeerHello on each negotiable parameter. On failure returns | |
| 364 // the corresponding QuicErrorCode and sets detailed error in |error_details|. | |
| 365 QuicErrorCode ProcessPeerHello(const CryptoHandshakeMessage& peer_hello, | |
| 366 HelloType hello_type, | |
| 367 std::string* error_details); | |
| 368 | |
| 369 private: | |
| 370 friend class test::QuicConfigPeer; | |
| 371 | |
| 372 // SetDefaults sets the members to sensible, default values. | |
| 373 void SetDefaults(); | |
| 374 | |
| 375 // Configurations options that are not negotiated. | |
| 376 // Maximum time the session can be alive before crypto handshake is finished. | |
| 377 QuicTime::Delta max_time_before_crypto_handshake_; | |
| 378 // Maximum idle time before the crypto handshake has completed. | |
| 379 QuicTime::Delta max_idle_time_before_crypto_handshake_; | |
| 380 // Maximum number of undecryptable packets stored before CHLO/SHLO. | |
| 381 size_t max_undecryptable_packets_; | |
| 382 | |
| 383 // Congestion control feedback type. | |
| 384 QuicNegotiableTag congestion_feedback_; | |
| 385 // Connection options. | |
| 386 QuicFixedTagVector connection_options_; | |
| 387 // Idle connection state lifetime | |
| 388 QuicNegotiableUint32 idle_connection_state_lifetime_seconds_; | |
| 389 // Whether to use silent close. Defaults to 0 (false) and is otherwise true. | |
| 390 QuicNegotiableUint32 silent_close_; | |
| 391 // Maximum number of streams that the connection can support. | |
| 392 QuicNegotiableUint32 max_streams_per_connection_; | |
| 393 // The number of bytes required for the connection ID. | |
| 394 QuicFixedUint32 bytes_for_connection_id_; | |
| 395 // Initial round trip time estimate in microseconds. | |
| 396 QuicFixedUint32 initial_round_trip_time_us_; | |
| 397 | |
| 398 // Initial stream flow control receive window in bytes. | |
| 399 QuicFixedUint32 initial_stream_flow_control_window_bytes_; | |
| 400 // Initial session flow control receive window in bytes. | |
| 401 QuicFixedUint32 initial_session_flow_control_window_bytes_; | |
| 402 | |
| 403 // Socket receive buffer in bytes. | |
| 404 QuicFixedUint32 socket_receive_buffer_; | |
| 405 }; | |
| 406 | |
| 407 } // namespace net | |
| 408 | |
| 409 #endif // NET_QUIC_QUIC_CONFIG_H_ | |
| OLD | NEW |