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" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 QuicNegotiableUint32::~QuicNegotiableUint32() {} | 70 QuicNegotiableUint32::~QuicNegotiableUint32() {} |
71 | 71 |
72 void QuicNegotiableUint32::set(uint32 max, uint32 default_value) { | 72 void QuicNegotiableUint32::set(uint32 max, uint32 default_value) { |
73 DCHECK_LE(default_value, max); | 73 DCHECK_LE(default_value, max); |
74 max_value_ = max; | 74 max_value_ = max; |
75 default_value_ = default_value; | 75 default_value_ = default_value; |
76 } | 76 } |
77 | 77 |
78 uint32 QuicNegotiableUint32::GetUint32() const { | 78 uint32 QuicNegotiableUint32::GetUint32() const { |
79 if (negotiated_) { | 79 if (negotiated()) { |
80 return negotiated_value_; | 80 return negotiated_value_; |
81 } | 81 } |
82 return default_value_; | 82 return default_value_; |
83 } | 83 } |
84 | 84 |
85 void QuicNegotiableUint32::ToHandshakeMessage( | 85 void QuicNegotiableUint32::ToHandshakeMessage( |
86 CryptoHandshakeMessage* out) const { | 86 CryptoHandshakeMessage* out) const { |
87 if (negotiated_) { | 87 if (negotiated()) { |
88 out->SetValue(tag_, negotiated_value_); | 88 out->SetValue(tag_, negotiated_value_); |
89 } else { | 89 } else { |
90 out->SetValue(tag_, max_value_); | 90 out->SetValue(tag_, max_value_); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 QuicErrorCode QuicNegotiableUint32::ProcessPeerHello( | 94 QuicErrorCode QuicNegotiableUint32::ProcessPeerHello( |
95 const CryptoHandshakeMessage& peer_hello, | 95 const CryptoHandshakeMessage& peer_hello, |
96 HelloType hello_type, | 96 HelloType hello_type, |
97 string* error_details) { | 97 string* error_details) { |
98 DCHECK(!negotiated_); | 98 DCHECK(!negotiated()); |
99 DCHECK(error_details != nullptr); | 99 DCHECK(error_details != nullptr); |
100 uint32 value; | 100 uint32 value; |
101 QuicErrorCode error = ReadUint32(peer_hello, | 101 QuicErrorCode error = ReadUint32(peer_hello, |
102 tag_, | 102 tag_, |
103 presence_, | 103 presence_, |
104 default_value_, | 104 default_value_, |
105 &value, | 105 &value, |
106 error_details); | 106 error_details); |
107 if (error != QUIC_NO_ERROR) { | 107 if (error != QUIC_NO_ERROR) { |
108 return error; | 108 return error; |
109 } | 109 } |
110 if (hello_type == SERVER && value > max_value_) { | 110 if (hello_type == SERVER && value > max_value_) { |
111 *error_details = | 111 *error_details = |
112 "Invalid value received for " + QuicUtils::TagToString(tag_); | 112 "Invalid value received for " + QuicUtils::TagToString(tag_); |
113 return QUIC_INVALID_NEGOTIATED_VALUE; | 113 return QUIC_INVALID_NEGOTIATED_VALUE; |
114 } | 114 } |
115 | 115 |
116 negotiated_ = true; | 116 set_negotiated(true); |
117 negotiated_value_ = min(value, max_value_); | 117 negotiated_value_ = min(value, max_value_); |
118 return QUIC_NO_ERROR; | 118 return QUIC_NO_ERROR; |
119 } | 119 } |
120 | 120 |
121 QuicNegotiableTag::QuicNegotiableTag(QuicTag tag, QuicConfigPresence presence) | 121 QuicNegotiableTag::QuicNegotiableTag(QuicTag tag, QuicConfigPresence presence) |
122 : QuicNegotiableValue(tag, presence), | 122 : QuicNegotiableValue(tag, presence), |
123 negotiated_tag_(0), | 123 negotiated_tag_(0), |
124 default_value_(0) { | 124 default_value_(0) { |
125 } | 125 } |
126 | 126 |
127 QuicNegotiableTag::~QuicNegotiableTag() {} | 127 QuicNegotiableTag::~QuicNegotiableTag() {} |
128 | 128 |
129 void QuicNegotiableTag::set(const QuicTagVector& possible, | 129 void QuicNegotiableTag::set(const QuicTagVector& possible, |
130 QuicTag default_value) { | 130 QuicTag default_value) { |
131 DCHECK(ContainsQuicTag(possible, default_value)); | 131 DCHECK(ContainsQuicTag(possible, default_value)); |
132 possible_values_ = possible; | 132 possible_values_ = possible; |
133 default_value_ = default_value; | 133 default_value_ = default_value; |
134 } | 134 } |
135 | 135 |
136 QuicTag QuicNegotiableTag::GetTag() const { | 136 QuicTag QuicNegotiableTag::GetTag() const { |
137 if (negotiated_) { | 137 if (negotiated()) { |
138 return negotiated_tag_; | 138 return negotiated_tag_; |
139 } | 139 } |
140 return default_value_; | 140 return default_value_; |
141 } | 141 } |
142 | 142 |
143 void QuicNegotiableTag::ToHandshakeMessage(CryptoHandshakeMessage* out) const { | 143 void QuicNegotiableTag::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
144 if (negotiated_) { | 144 if (negotiated()) { |
145 // Because of the way we serialize and parse handshake messages we can | 145 // Because of the way we serialize and parse handshake messages we can |
146 // serialize this as value and still parse it as a vector. | 146 // serialize this as value and still parse it as a vector. |
147 out->SetValue(tag_, negotiated_tag_); | 147 out->SetValue(tag_, negotiated_tag_); |
148 } else { | 148 } else { |
149 out->SetVector(tag_, possible_values_); | 149 out->SetVector(tag_, possible_values_); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 QuicErrorCode QuicNegotiableTag::ReadVector( | 153 QuicErrorCode QuicNegotiableTag::ReadVector( |
154 const CryptoHandshakeMessage& msg, | 154 const CryptoHandshakeMessage& msg, |
(...skipping 18 matching lines...) Expand all Loading... |
173 *error_details = "Bad " + QuicUtils::TagToString(tag_); | 173 *error_details = "Bad " + QuicUtils::TagToString(tag_); |
174 break; | 174 break; |
175 } | 175 } |
176 return error; | 176 return error; |
177 } | 177 } |
178 | 178 |
179 QuicErrorCode QuicNegotiableTag::ProcessPeerHello( | 179 QuicErrorCode QuicNegotiableTag::ProcessPeerHello( |
180 const CryptoHandshakeMessage& peer_hello, | 180 const CryptoHandshakeMessage& peer_hello, |
181 HelloType hello_type, | 181 HelloType hello_type, |
182 string* error_details) { | 182 string* error_details) { |
183 DCHECK(!negotiated_); | 183 DCHECK(!negotiated()); |
184 DCHECK(error_details != nullptr); | 184 DCHECK(error_details != nullptr); |
185 const QuicTag* received_tags; | 185 const QuicTag* received_tags; |
186 size_t received_tags_length; | 186 size_t received_tags_length; |
187 QuicErrorCode error = ReadVector(peer_hello, &received_tags, | 187 QuicErrorCode error = ReadVector(peer_hello, &received_tags, |
188 &received_tags_length, error_details); | 188 &received_tags_length, error_details); |
189 if (error != QUIC_NO_ERROR) { | 189 if (error != QUIC_NO_ERROR) { |
190 return error; | 190 return error; |
191 } | 191 } |
192 | 192 |
193 if (hello_type == SERVER) { | 193 if (hello_type == SERVER) { |
(...skipping 10 matching lines...) Expand all Loading... |
204 received_tags_length, | 204 received_tags_length, |
205 QuicUtils::LOCAL_PRIORITY, | 205 QuicUtils::LOCAL_PRIORITY, |
206 &negotiated_tag, | 206 &negotiated_tag, |
207 nullptr)) { | 207 nullptr)) { |
208 *error_details = "Unsupported " + QuicUtils::TagToString(tag_); | 208 *error_details = "Unsupported " + QuicUtils::TagToString(tag_); |
209 return QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP; | 209 return QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP; |
210 } | 210 } |
211 negotiated_tag_ = negotiated_tag; | 211 negotiated_tag_ = negotiated_tag; |
212 } | 212 } |
213 | 213 |
214 negotiated_ = true; | 214 set_negotiated(true); |
215 return QUIC_NO_ERROR; | 215 return QUIC_NO_ERROR; |
216 } | 216 } |
217 | 217 |
218 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) | 218 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) |
219 : QuicConfigValue(tag, presence), | 219 : QuicConfigValue(tag, presence), |
220 has_send_value_(false), | 220 has_send_value_(false), |
221 has_receive_value_(false) { | 221 has_receive_value_(false) { |
222 } | 222 } |
223 QuicFixedUint32::~QuicFixedUint32() {} | 223 QuicFixedUint32::~QuicFixedUint32() {} |
224 | 224 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 426 |
427 QuicConfig::QuicConfig() | 427 QuicConfig::QuicConfig() |
428 : max_time_before_crypto_handshake_(QuicTime::Delta::Zero()), | 428 : max_time_before_crypto_handshake_(QuicTime::Delta::Zero()), |
429 max_idle_time_before_crypto_handshake_(QuicTime::Delta::Zero()), | 429 max_idle_time_before_crypto_handshake_(QuicTime::Delta::Zero()), |
430 max_undecryptable_packets_(0), | 430 max_undecryptable_packets_(0), |
431 congestion_feedback_(kCGST, PRESENCE_REQUIRED), | 431 congestion_feedback_(kCGST, PRESENCE_REQUIRED), |
432 connection_options_(kCOPT, PRESENCE_OPTIONAL), | 432 connection_options_(kCOPT, PRESENCE_OPTIONAL), |
433 idle_connection_state_lifetime_seconds_(kICSL, PRESENCE_REQUIRED), | 433 idle_connection_state_lifetime_seconds_(kICSL, PRESENCE_REQUIRED), |
434 keepalive_timeout_seconds_(kKATO, PRESENCE_OPTIONAL), | 434 keepalive_timeout_seconds_(kKATO, PRESENCE_OPTIONAL), |
435 max_streams_per_connection_(kMSPC, PRESENCE_REQUIRED), | 435 max_streams_per_connection_(kMSPC, PRESENCE_REQUIRED), |
| 436 bytes_for_connection_id_(kTCID, PRESENCE_OPTIONAL), |
436 initial_congestion_window_(kSWND, PRESENCE_OPTIONAL), | 437 initial_congestion_window_(kSWND, PRESENCE_OPTIONAL), |
437 initial_round_trip_time_us_(kIRTT, PRESENCE_OPTIONAL), | 438 initial_round_trip_time_us_(kIRTT, PRESENCE_OPTIONAL), |
438 // TODO(rjshade): Remove this when retiring QUIC_VERSION_19. | 439 // TODO(rjshade): Remove this when retiring QUIC_VERSION_19. |
439 initial_flow_control_window_bytes_(kIFCW, PRESENCE_OPTIONAL), | 440 initial_flow_control_window_bytes_(kIFCW, PRESENCE_OPTIONAL), |
440 // TODO(rjshade): Make this PRESENCE_REQUIRED when retiring | 441 // TODO(rjshade): Make this PRESENCE_REQUIRED when retiring |
441 // QUIC_VERSION_19. | 442 // QUIC_VERSION_19. |
442 initial_stream_flow_control_window_bytes_(kSFCW, PRESENCE_OPTIONAL), | 443 initial_stream_flow_control_window_bytes_(kSFCW, PRESENCE_OPTIONAL), |
443 // TODO(rjshade): Make this PRESENCE_REQUIRED when retiring | 444 // TODO(rjshade): Make this PRESENCE_REQUIRED when retiring |
444 // QUIC_VERSION_19. | 445 // QUIC_VERSION_19. |
445 initial_session_flow_control_window_bytes_(kCFCW, PRESENCE_OPTIONAL), | 446 initial_session_flow_control_window_bytes_(kCFCW, PRESENCE_OPTIONAL), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 501 |
501 void QuicConfig::SetMaxStreamsPerConnection(size_t max_streams, | 502 void QuicConfig::SetMaxStreamsPerConnection(size_t max_streams, |
502 size_t default_streams) { | 503 size_t default_streams) { |
503 max_streams_per_connection_.set(max_streams, default_streams); | 504 max_streams_per_connection_.set(max_streams, default_streams); |
504 } | 505 } |
505 | 506 |
506 uint32 QuicConfig::MaxStreamsPerConnection() const { | 507 uint32 QuicConfig::MaxStreamsPerConnection() const { |
507 return max_streams_per_connection_.GetUint32(); | 508 return max_streams_per_connection_.GetUint32(); |
508 } | 509 } |
509 | 510 |
| 511 bool QuicConfig::HasSetBytesForConnectionIdToSend() const { |
| 512 return bytes_for_connection_id_.HasSendValue(); |
| 513 } |
| 514 |
| 515 void QuicConfig::SetBytesForConnectionIdToSend(uint32 bytes) { |
| 516 bytes_for_connection_id_.SetSendValue(bytes); |
| 517 } |
| 518 |
| 519 bool QuicConfig::HasReceivedBytesForConnectionId() const { |
| 520 return bytes_for_connection_id_.HasReceivedValue(); |
| 521 } |
| 522 |
| 523 uint32 QuicConfig::ReceivedBytesForConnectionId() const { |
| 524 return bytes_for_connection_id_.GetReceivedValue(); |
| 525 } |
| 526 |
510 void QuicConfig::SetInitialCongestionWindowToSend(size_t initial_window) { | 527 void QuicConfig::SetInitialCongestionWindowToSend(size_t initial_window) { |
511 initial_congestion_window_.SetSendValue(initial_window); | 528 initial_congestion_window_.SetSendValue(initial_window); |
512 } | 529 } |
513 | 530 |
514 bool QuicConfig::HasReceivedInitialCongestionWindow() const { | 531 bool QuicConfig::HasReceivedInitialCongestionWindow() const { |
515 return initial_congestion_window_.HasReceivedValue(); | 532 return initial_congestion_window_.HasReceivedValue(); |
516 } | 533 } |
517 | 534 |
518 uint32 QuicConfig::ReceivedInitialCongestionWindow() const { | 535 uint32 QuicConfig::ReceivedInitialCongestionWindow() const { |
519 return initial_congestion_window_.GetReceivedValue(); | 536 return initial_congestion_window_.GetReceivedValue(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 SetInitialFlowControlWindowToSend(kDefaultFlowControlSendWindow); | 667 SetInitialFlowControlWindowToSend(kDefaultFlowControlSendWindow); |
651 SetInitialStreamFlowControlWindowToSend(kDefaultFlowControlSendWindow); | 668 SetInitialStreamFlowControlWindowToSend(kDefaultFlowControlSendWindow); |
652 SetInitialSessionFlowControlWindowToSend(kDefaultFlowControlSendWindow); | 669 SetInitialSessionFlowControlWindowToSend(kDefaultFlowControlSendWindow); |
653 } | 670 } |
654 | 671 |
655 void QuicConfig::ToHandshakeMessage(CryptoHandshakeMessage* out) const { | 672 void QuicConfig::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
656 congestion_feedback_.ToHandshakeMessage(out); | 673 congestion_feedback_.ToHandshakeMessage(out); |
657 idle_connection_state_lifetime_seconds_.ToHandshakeMessage(out); | 674 idle_connection_state_lifetime_seconds_.ToHandshakeMessage(out); |
658 keepalive_timeout_seconds_.ToHandshakeMessage(out); | 675 keepalive_timeout_seconds_.ToHandshakeMessage(out); |
659 max_streams_per_connection_.ToHandshakeMessage(out); | 676 max_streams_per_connection_.ToHandshakeMessage(out); |
| 677 bytes_for_connection_id_.ToHandshakeMessage(out); |
660 initial_congestion_window_.ToHandshakeMessage(out); | 678 initial_congestion_window_.ToHandshakeMessage(out); |
661 initial_round_trip_time_us_.ToHandshakeMessage(out); | 679 initial_round_trip_time_us_.ToHandshakeMessage(out); |
662 initial_flow_control_window_bytes_.ToHandshakeMessage(out); | 680 initial_flow_control_window_bytes_.ToHandshakeMessage(out); |
663 initial_stream_flow_control_window_bytes_.ToHandshakeMessage(out); | 681 initial_stream_flow_control_window_bytes_.ToHandshakeMessage(out); |
664 initial_session_flow_control_window_bytes_.ToHandshakeMessage(out); | 682 initial_session_flow_control_window_bytes_.ToHandshakeMessage(out); |
665 socket_receive_buffer_.ToHandshakeMessage(out); | 683 socket_receive_buffer_.ToHandshakeMessage(out); |
666 connection_options_.ToHandshakeMessage(out); | 684 connection_options_.ToHandshakeMessage(out); |
667 } | 685 } |
668 | 686 |
669 QuicErrorCode QuicConfig::ProcessPeerHello( | 687 QuicErrorCode QuicConfig::ProcessPeerHello( |
(...skipping 13 matching lines...) Expand all Loading... |
683 } | 701 } |
684 if (error == QUIC_NO_ERROR) { | 702 if (error == QUIC_NO_ERROR) { |
685 error = keepalive_timeout_seconds_.ProcessPeerHello( | 703 error = keepalive_timeout_seconds_.ProcessPeerHello( |
686 peer_hello, hello_type, error_details); | 704 peer_hello, hello_type, error_details); |
687 } | 705 } |
688 if (error == QUIC_NO_ERROR) { | 706 if (error == QUIC_NO_ERROR) { |
689 error = max_streams_per_connection_.ProcessPeerHello( | 707 error = max_streams_per_connection_.ProcessPeerHello( |
690 peer_hello, hello_type, error_details); | 708 peer_hello, hello_type, error_details); |
691 } | 709 } |
692 if (error == QUIC_NO_ERROR) { | 710 if (error == QUIC_NO_ERROR) { |
| 711 error = bytes_for_connection_id_.ProcessPeerHello( |
| 712 peer_hello, hello_type, error_details); |
| 713 } |
| 714 if (error == QUIC_NO_ERROR) { |
693 error = initial_congestion_window_.ProcessPeerHello( | 715 error = initial_congestion_window_.ProcessPeerHello( |
694 peer_hello, hello_type, error_details); | 716 peer_hello, hello_type, error_details); |
695 } | 717 } |
696 if (error == QUIC_NO_ERROR) { | 718 if (error == QUIC_NO_ERROR) { |
697 error = initial_round_trip_time_us_.ProcessPeerHello( | 719 error = initial_round_trip_time_us_.ProcessPeerHello( |
698 peer_hello, hello_type, error_details); | 720 peer_hello, hello_type, error_details); |
699 } | 721 } |
700 if (error == QUIC_NO_ERROR) { | 722 if (error == QUIC_NO_ERROR) { |
701 error = initial_flow_control_window_bytes_.ProcessPeerHello( | 723 error = initial_flow_control_window_bytes_.ProcessPeerHello( |
702 peer_hello, hello_type, error_details); | 724 peer_hello, hello_type, error_details); |
(...skipping 11 matching lines...) Expand all Loading... |
714 peer_hello, hello_type, error_details); | 736 peer_hello, hello_type, error_details); |
715 } | 737 } |
716 if (error == QUIC_NO_ERROR) { | 738 if (error == QUIC_NO_ERROR) { |
717 error = connection_options_.ProcessPeerHello( | 739 error = connection_options_.ProcessPeerHello( |
718 peer_hello, hello_type, error_details); | 740 peer_hello, hello_type, error_details); |
719 } | 741 } |
720 return error; | 742 return error; |
721 } | 743 } |
722 | 744 |
723 } // namespace net | 745 } // namespace net |
OLD | NEW |