| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_config.h" | 5 #include "net/quic/quic_config.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/quic/crypto/crypto_handshake_message.h" | 10 #include "net/quic/crypto/crypto_handshake_message.h" |
| 11 #include "net/quic/crypto/crypto_protocol.h" | 11 #include "net/quic/crypto/crypto_protocol.h" |
| 12 #include "net/quic/quic_utils.h" | 12 #include "net/quic/quic_utils.h" |
| 13 | 13 |
| 14 using std::min; | 14 using std::min; |
| 15 using std::string; | 15 using std::string; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 // Reads the value corresponding to |name_| from |msg| into |out|. If the | 19 // Reads the value corresponding to |name_| from |msg| into |out|. If the |
| 20 // |name_| is absent in |msg| and |presence| is set to OPTIONAL |out| is set | 20 // |name_| is absent in |msg| and |presence| is set to OPTIONAL |out| is set |
| 21 // to |default_value|. | 21 // to |default_value|. |
| 22 QuicErrorCode ReadUint32(const CryptoHandshakeMessage& msg, | 22 QuicErrorCode ReadUint32(const CryptoHandshakeMessage& msg, |
| 23 QuicTag tag, | 23 QuicTag tag, |
| 24 QuicConfigPresence presence, | 24 QuicConfigPresence presence, |
| 25 uint32 default_value, | 25 uint32_t default_value, |
| 26 uint32* out, | 26 uint32_t* out, |
| 27 string* error_details) { | 27 string* error_details) { |
| 28 DCHECK(error_details != nullptr); | 28 DCHECK(error_details != nullptr); |
| 29 QuicErrorCode error = msg.GetUint32(tag, out); | 29 QuicErrorCode error = msg.GetUint32(tag, out); |
| 30 switch (error) { | 30 switch (error) { |
| 31 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: | 31 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
| 32 if (presence == PRESENCE_REQUIRED) { | 32 if (presence == PRESENCE_REQUIRED) { |
| 33 *error_details = "Missing " + QuicUtils::TagToString(tag); | 33 *error_details = "Missing " + QuicUtils::TagToString(tag); |
| 34 break; | 34 break; |
| 35 } | 35 } |
| 36 error = QUIC_NO_ERROR; | 36 error = QUIC_NO_ERROR; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 QuicNegotiableValue::~QuicNegotiableValue() {} | 55 QuicNegotiableValue::~QuicNegotiableValue() {} |
| 56 | 56 |
| 57 QuicNegotiableUint32::QuicNegotiableUint32(QuicTag tag, | 57 QuicNegotiableUint32::QuicNegotiableUint32(QuicTag tag, |
| 58 QuicConfigPresence presence) | 58 QuicConfigPresence presence) |
| 59 : QuicNegotiableValue(tag, presence), | 59 : QuicNegotiableValue(tag, presence), |
| 60 max_value_(0), | 60 max_value_(0), |
| 61 default_value_(0), | 61 default_value_(0), |
| 62 negotiated_value_(0) {} | 62 negotiated_value_(0) {} |
| 63 QuicNegotiableUint32::~QuicNegotiableUint32() {} | 63 QuicNegotiableUint32::~QuicNegotiableUint32() {} |
| 64 | 64 |
| 65 void QuicNegotiableUint32::set(uint32 max, uint32 default_value) { | 65 void QuicNegotiableUint32::set(uint32_t max, uint32_t default_value) { |
| 66 DCHECK_LE(default_value, max); | 66 DCHECK_LE(default_value, max); |
| 67 max_value_ = max; | 67 max_value_ = max; |
| 68 default_value_ = default_value; | 68 default_value_ = default_value; |
| 69 } | 69 } |
| 70 | 70 |
| 71 uint32 QuicNegotiableUint32::GetUint32() const { | 71 uint32_t QuicNegotiableUint32::GetUint32() const { |
| 72 if (negotiated()) { | 72 if (negotiated()) { |
| 73 return negotiated_value_; | 73 return negotiated_value_; |
| 74 } | 74 } |
| 75 return default_value_; | 75 return default_value_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void QuicNegotiableUint32::ToHandshakeMessage( | 78 void QuicNegotiableUint32::ToHandshakeMessage( |
| 79 CryptoHandshakeMessage* out) const { | 79 CryptoHandshakeMessage* out) const { |
| 80 if (negotiated()) { | 80 if (negotiated()) { |
| 81 out->SetValue(tag_, negotiated_value_); | 81 out->SetValue(tag_, negotiated_value_); |
| 82 } else { | 82 } else { |
| 83 out->SetValue(tag_, max_value_); | 83 out->SetValue(tag_, max_value_); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 QuicErrorCode QuicNegotiableUint32::ProcessPeerHello( | 87 QuicErrorCode QuicNegotiableUint32::ProcessPeerHello( |
| 88 const CryptoHandshakeMessage& peer_hello, | 88 const CryptoHandshakeMessage& peer_hello, |
| 89 HelloType hello_type, | 89 HelloType hello_type, |
| 90 string* error_details) { | 90 string* error_details) { |
| 91 DCHECK(!negotiated()); | 91 DCHECK(!negotiated()); |
| 92 DCHECK(error_details != nullptr); | 92 DCHECK(error_details != nullptr); |
| 93 uint32 value; | 93 uint32_t value; |
| 94 QuicErrorCode error = ReadUint32(peer_hello, tag_, presence_, default_value_, | 94 QuicErrorCode error = ReadUint32(peer_hello, tag_, presence_, default_value_, |
| 95 &value, error_details); | 95 &value, error_details); |
| 96 if (error != QUIC_NO_ERROR) { | 96 if (error != QUIC_NO_ERROR) { |
| 97 return error; | 97 return error; |
| 98 } | 98 } |
| 99 if (hello_type == SERVER && value > max_value_) { | 99 if (hello_type == SERVER && value > max_value_) { |
| 100 *error_details = | 100 *error_details = |
| 101 "Invalid value received for " + QuicUtils::TagToString(tag_); | 101 "Invalid value received for " + QuicUtils::TagToString(tag_); |
| 102 return QUIC_INVALID_NEGOTIATED_VALUE; | 102 return QUIC_INVALID_NEGOTIATED_VALUE; |
| 103 } | 103 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) | 195 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) |
| 196 : QuicConfigValue(tag, presence), | 196 : QuicConfigValue(tag, presence), |
| 197 has_send_value_(false), | 197 has_send_value_(false), |
| 198 has_receive_value_(false) {} | 198 has_receive_value_(false) {} |
| 199 QuicFixedUint32::~QuicFixedUint32() {} | 199 QuicFixedUint32::~QuicFixedUint32() {} |
| 200 | 200 |
| 201 bool QuicFixedUint32::HasSendValue() const { | 201 bool QuicFixedUint32::HasSendValue() const { |
| 202 return has_send_value_; | 202 return has_send_value_; |
| 203 } | 203 } |
| 204 | 204 |
| 205 uint32 QuicFixedUint32::GetSendValue() const { | 205 uint32_t QuicFixedUint32::GetSendValue() const { |
| 206 LOG_IF(DFATAL, !has_send_value_) << "No send value to get for tag:" | 206 LOG_IF(DFATAL, !has_send_value_) << "No send value to get for tag:" |
| 207 << QuicUtils::TagToString(tag_); | 207 << QuicUtils::TagToString(tag_); |
| 208 return send_value_; | 208 return send_value_; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void QuicFixedUint32::SetSendValue(uint32 value) { | 211 void QuicFixedUint32::SetSendValue(uint32_t value) { |
| 212 has_send_value_ = true; | 212 has_send_value_ = true; |
| 213 send_value_ = value; | 213 send_value_ = value; |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool QuicFixedUint32::HasReceivedValue() const { | 216 bool QuicFixedUint32::HasReceivedValue() const { |
| 217 return has_receive_value_; | 217 return has_receive_value_; |
| 218 } | 218 } |
| 219 | 219 |
| 220 uint32 QuicFixedUint32::GetReceivedValue() const { | 220 uint32_t QuicFixedUint32::GetReceivedValue() const { |
| 221 LOG_IF(DFATAL, !has_receive_value_) << "No receive value to get for tag:" | 221 LOG_IF(DFATAL, !has_receive_value_) << "No receive value to get for tag:" |
| 222 << QuicUtils::TagToString(tag_); | 222 << QuicUtils::TagToString(tag_); |
| 223 return receive_value_; | 223 return receive_value_; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void QuicFixedUint32::SetReceivedValue(uint32 value) { | 226 void QuicFixedUint32::SetReceivedValue(uint32_t value) { |
| 227 has_receive_value_ = true; | 227 has_receive_value_ = true; |
| 228 receive_value_ = value; | 228 receive_value_ = value; |
| 229 } | 229 } |
| 230 | 230 |
| 231 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const { | 231 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
| 232 if (has_send_value_) { | 232 if (has_send_value_) { |
| 233 out->SetValue(tag_, send_value_); | 233 out->SetValue(tag_, send_value_); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 ContainsQuicTag(SendConnectionOptions(), tag)) { | 392 ContainsQuicTag(SendConnectionOptions(), tag)) { |
| 393 return true; | 393 return true; |
| 394 } | 394 } |
| 395 return false; | 395 return false; |
| 396 } | 396 } |
| 397 | 397 |
| 398 void QuicConfig::SetIdleConnectionStateLifetime( | 398 void QuicConfig::SetIdleConnectionStateLifetime( |
| 399 QuicTime::Delta max_idle_connection_state_lifetime, | 399 QuicTime::Delta max_idle_connection_state_lifetime, |
| 400 QuicTime::Delta default_idle_conection_state_lifetime) { | 400 QuicTime::Delta default_idle_conection_state_lifetime) { |
| 401 idle_connection_state_lifetime_seconds_.set( | 401 idle_connection_state_lifetime_seconds_.set( |
| 402 static_cast<uint32>(max_idle_connection_state_lifetime.ToSeconds()), | 402 static_cast<uint32_t>(max_idle_connection_state_lifetime.ToSeconds()), |
| 403 static_cast<uint32>(default_idle_conection_state_lifetime.ToSeconds())); | 403 static_cast<uint32_t>(default_idle_conection_state_lifetime.ToSeconds())); |
| 404 } | 404 } |
| 405 | 405 |
| 406 QuicTime::Delta QuicConfig::IdleConnectionStateLifetime() const { | 406 QuicTime::Delta QuicConfig::IdleConnectionStateLifetime() const { |
| 407 return QuicTime::Delta::FromSeconds( | 407 return QuicTime::Delta::FromSeconds( |
| 408 idle_connection_state_lifetime_seconds_.GetUint32()); | 408 idle_connection_state_lifetime_seconds_.GetUint32()); |
| 409 } | 409 } |
| 410 | 410 |
| 411 // TODO(ianswett) Use this for silent close on mobile, or delete. | 411 // TODO(ianswett) Use this for silent close on mobile, or delete. |
| 412 void QuicConfig::SetSilentClose(bool silent_close) { | 412 void QuicConfig::SetSilentClose(bool silent_close) { |
| 413 silent_close_.set(silent_close ? 1 : 0, silent_close ? 1 : 0); | 413 silent_close_.set(silent_close ? 1 : 0, silent_close ? 1 : 0); |
| 414 } | 414 } |
| 415 | 415 |
| 416 bool QuicConfig::SilentClose() const { | 416 bool QuicConfig::SilentClose() const { |
| 417 return silent_close_.GetUint32() > 0; | 417 return silent_close_.GetUint32() > 0; |
| 418 } | 418 } |
| 419 | 419 |
| 420 void QuicConfig::SetMaxStreamsPerConnection(size_t max_streams, | 420 void QuicConfig::SetMaxStreamsPerConnection(size_t max_streams, |
| 421 size_t default_streams) { | 421 size_t default_streams) { |
| 422 max_streams_per_connection_.set(max_streams, default_streams); | 422 max_streams_per_connection_.set(max_streams, default_streams); |
| 423 } | 423 } |
| 424 | 424 |
| 425 uint32 QuicConfig::MaxStreamsPerConnection() const { | 425 uint32_t QuicConfig::MaxStreamsPerConnection() const { |
| 426 return max_streams_per_connection_.GetUint32(); | 426 return max_streams_per_connection_.GetUint32(); |
| 427 } | 427 } |
| 428 | 428 |
| 429 bool QuicConfig::HasSetBytesForConnectionIdToSend() const { | 429 bool QuicConfig::HasSetBytesForConnectionIdToSend() const { |
| 430 return bytes_for_connection_id_.HasSendValue(); | 430 return bytes_for_connection_id_.HasSendValue(); |
| 431 } | 431 } |
| 432 | 432 |
| 433 void QuicConfig::SetBytesForConnectionIdToSend(uint32 bytes) { | 433 void QuicConfig::SetBytesForConnectionIdToSend(uint32_t bytes) { |
| 434 bytes_for_connection_id_.SetSendValue(bytes); | 434 bytes_for_connection_id_.SetSendValue(bytes); |
| 435 } | 435 } |
| 436 | 436 |
| 437 bool QuicConfig::HasReceivedBytesForConnectionId() const { | 437 bool QuicConfig::HasReceivedBytesForConnectionId() const { |
| 438 return bytes_for_connection_id_.HasReceivedValue(); | 438 return bytes_for_connection_id_.HasReceivedValue(); |
| 439 } | 439 } |
| 440 | 440 |
| 441 uint32 QuicConfig::ReceivedBytesForConnectionId() const { | 441 uint32_t QuicConfig::ReceivedBytesForConnectionId() const { |
| 442 return bytes_for_connection_id_.GetReceivedValue(); | 442 return bytes_for_connection_id_.GetReceivedValue(); |
| 443 } | 443 } |
| 444 | 444 |
| 445 void QuicConfig::SetInitialRoundTripTimeUsToSend(uint32 rtt) { | 445 void QuicConfig::SetInitialRoundTripTimeUsToSend(uint32_t rtt) { |
| 446 initial_round_trip_time_us_.SetSendValue(rtt); | 446 initial_round_trip_time_us_.SetSendValue(rtt); |
| 447 } | 447 } |
| 448 | 448 |
| 449 bool QuicConfig::HasReceivedInitialRoundTripTimeUs() const { | 449 bool QuicConfig::HasReceivedInitialRoundTripTimeUs() const { |
| 450 return initial_round_trip_time_us_.HasReceivedValue(); | 450 return initial_round_trip_time_us_.HasReceivedValue(); |
| 451 } | 451 } |
| 452 | 452 |
| 453 uint32 QuicConfig::ReceivedInitialRoundTripTimeUs() const { | 453 uint32_t QuicConfig::ReceivedInitialRoundTripTimeUs() const { |
| 454 return initial_round_trip_time_us_.GetReceivedValue(); | 454 return initial_round_trip_time_us_.GetReceivedValue(); |
| 455 } | 455 } |
| 456 | 456 |
| 457 bool QuicConfig::HasInitialRoundTripTimeUsToSend() const { | 457 bool QuicConfig::HasInitialRoundTripTimeUsToSend() const { |
| 458 return initial_round_trip_time_us_.HasSendValue(); | 458 return initial_round_trip_time_us_.HasSendValue(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 uint32 QuicConfig::GetInitialRoundTripTimeUsToSend() const { | 461 uint32_t QuicConfig::GetInitialRoundTripTimeUsToSend() const { |
| 462 return initial_round_trip_time_us_.GetSendValue(); | 462 return initial_round_trip_time_us_.GetSendValue(); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void QuicConfig::SetInitialStreamFlowControlWindowToSend(uint32 window_bytes) { | 465 void QuicConfig::SetInitialStreamFlowControlWindowToSend( |
| 466 uint32_t window_bytes) { |
| 466 if (window_bytes < kMinimumFlowControlSendWindow) { | 467 if (window_bytes < kMinimumFlowControlSendWindow) { |
| 467 LOG(DFATAL) << "Initial stream flow control receive window (" | 468 LOG(DFATAL) << "Initial stream flow control receive window (" |
| 468 << window_bytes << ") cannot be set lower than default (" | 469 << window_bytes << ") cannot be set lower than default (" |
| 469 << kMinimumFlowControlSendWindow << ")."; | 470 << kMinimumFlowControlSendWindow << ")."; |
| 470 window_bytes = kMinimumFlowControlSendWindow; | 471 window_bytes = kMinimumFlowControlSendWindow; |
| 471 } | 472 } |
| 472 initial_stream_flow_control_window_bytes_.SetSendValue(window_bytes); | 473 initial_stream_flow_control_window_bytes_.SetSendValue(window_bytes); |
| 473 } | 474 } |
| 474 | 475 |
| 475 uint32 QuicConfig::GetInitialStreamFlowControlWindowToSend() const { | 476 uint32_t QuicConfig::GetInitialStreamFlowControlWindowToSend() const { |
| 476 return initial_stream_flow_control_window_bytes_.GetSendValue(); | 477 return initial_stream_flow_control_window_bytes_.GetSendValue(); |
| 477 } | 478 } |
| 478 | 479 |
| 479 bool QuicConfig::HasReceivedInitialStreamFlowControlWindowBytes() const { | 480 bool QuicConfig::HasReceivedInitialStreamFlowControlWindowBytes() const { |
| 480 return initial_stream_flow_control_window_bytes_.HasReceivedValue(); | 481 return initial_stream_flow_control_window_bytes_.HasReceivedValue(); |
| 481 } | 482 } |
| 482 | 483 |
| 483 uint32 QuicConfig::ReceivedInitialStreamFlowControlWindowBytes() const { | 484 uint32_t QuicConfig::ReceivedInitialStreamFlowControlWindowBytes() const { |
| 484 return initial_stream_flow_control_window_bytes_.GetReceivedValue(); | 485 return initial_stream_flow_control_window_bytes_.GetReceivedValue(); |
| 485 } | 486 } |
| 486 | 487 |
| 487 void QuicConfig::SetInitialSessionFlowControlWindowToSend(uint32 window_bytes) { | 488 void QuicConfig::SetInitialSessionFlowControlWindowToSend( |
| 489 uint32_t window_bytes) { |
| 488 if (window_bytes < kMinimumFlowControlSendWindow) { | 490 if (window_bytes < kMinimumFlowControlSendWindow) { |
| 489 LOG(DFATAL) << "Initial session flow control receive window (" | 491 LOG(DFATAL) << "Initial session flow control receive window (" |
| 490 << window_bytes << ") cannot be set lower than default (" | 492 << window_bytes << ") cannot be set lower than default (" |
| 491 << kMinimumFlowControlSendWindow << ")."; | 493 << kMinimumFlowControlSendWindow << ")."; |
| 492 window_bytes = kMinimumFlowControlSendWindow; | 494 window_bytes = kMinimumFlowControlSendWindow; |
| 493 } | 495 } |
| 494 initial_session_flow_control_window_bytes_.SetSendValue(window_bytes); | 496 initial_session_flow_control_window_bytes_.SetSendValue(window_bytes); |
| 495 } | 497 } |
| 496 | 498 |
| 497 uint32 QuicConfig::GetInitialSessionFlowControlWindowToSend() const { | 499 uint32_t QuicConfig::GetInitialSessionFlowControlWindowToSend() const { |
| 498 return initial_session_flow_control_window_bytes_.GetSendValue(); | 500 return initial_session_flow_control_window_bytes_.GetSendValue(); |
| 499 } | 501 } |
| 500 | 502 |
| 501 bool QuicConfig::HasReceivedInitialSessionFlowControlWindowBytes() const { | 503 bool QuicConfig::HasReceivedInitialSessionFlowControlWindowBytes() const { |
| 502 return initial_session_flow_control_window_bytes_.HasReceivedValue(); | 504 return initial_session_flow_control_window_bytes_.HasReceivedValue(); |
| 503 } | 505 } |
| 504 | 506 |
| 505 uint32 QuicConfig::ReceivedInitialSessionFlowControlWindowBytes() const { | 507 uint32_t QuicConfig::ReceivedInitialSessionFlowControlWindowBytes() const { |
| 506 return initial_session_flow_control_window_bytes_.GetReceivedValue(); | 508 return initial_session_flow_control_window_bytes_.GetReceivedValue(); |
| 507 } | 509 } |
| 508 | 510 |
| 509 void QuicConfig::SetSocketReceiveBufferToSend(uint32 tcp_receive_window) { | 511 void QuicConfig::SetSocketReceiveBufferToSend(uint32_t tcp_receive_window) { |
| 510 socket_receive_buffer_.SetSendValue(tcp_receive_window); | 512 socket_receive_buffer_.SetSendValue(tcp_receive_window); |
| 511 } | 513 } |
| 512 | 514 |
| 513 bool QuicConfig::HasReceivedSocketReceiveBuffer() const { | 515 bool QuicConfig::HasReceivedSocketReceiveBuffer() const { |
| 514 return socket_receive_buffer_.HasReceivedValue(); | 516 return socket_receive_buffer_.HasReceivedValue(); |
| 515 } | 517 } |
| 516 | 518 |
| 517 uint32 QuicConfig::ReceivedSocketReceiveBuffer() const { | 519 uint32_t QuicConfig::ReceivedSocketReceiveBuffer() const { |
| 518 return socket_receive_buffer_.GetReceivedValue(); | 520 return socket_receive_buffer_.GetReceivedValue(); |
| 519 } | 521 } |
| 520 | 522 |
| 521 bool QuicConfig::negotiated() const { | 523 bool QuicConfig::negotiated() const { |
| 522 // TODO(ianswett): Add the negotiated parameters once and iterate over all | 524 // TODO(ianswett): Add the negotiated parameters once and iterate over all |
| 523 // of them in negotiated, ToHandshakeMessage, ProcessClientHello, and | 525 // of them in negotiated, ToHandshakeMessage, ProcessClientHello, and |
| 524 // ProcessServerHello. | 526 // ProcessServerHello. |
| 525 return idle_connection_state_lifetime_seconds_.negotiated() && | 527 return idle_connection_state_lifetime_seconds_.negotiated() && |
| 526 max_streams_per_connection_.negotiated(); | 528 max_streams_per_connection_.negotiated(); |
| 527 } | 529 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 error_details); | 596 error_details); |
| 595 } | 597 } |
| 596 if (error == QUIC_NO_ERROR) { | 598 if (error == QUIC_NO_ERROR) { |
| 597 error = connection_options_.ProcessPeerHello(peer_hello, hello_type, | 599 error = connection_options_.ProcessPeerHello(peer_hello, hello_type, |
| 598 error_details); | 600 error_details); |
| 599 } | 601 } |
| 600 return error; | 602 return error; |
| 601 } | 603 } |
| 602 | 604 |
| 603 } // namespace net | 605 } // namespace net |
| OLD | NEW |