Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: net/quic/core/quic_config.cc

Issue 2516033003: Landing Recent QUIC changes until Mon Nov 14 04:43:50 2016 +0000 (Closed)
Patch Set: Remove unused UpdatePacketGapSentHistogram() function. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_config.h ('k') | net/quic/core/quic_connection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/core/quic_config.h" 5 #include "net/quic/core/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/core/crypto/crypto_handshake_message.h" 10 #include "net/quic/core/crypto/crypto_handshake_message.h"
(...skipping 14 matching lines...) Expand all
25 QuicTag tag, 25 QuicTag tag,
26 QuicConfigPresence presence, 26 QuicConfigPresence presence,
27 uint32_t default_value, 27 uint32_t default_value,
28 uint32_t* out, 28 uint32_t* out,
29 string* error_details) { 29 string* error_details) {
30 DCHECK(error_details != nullptr); 30 DCHECK(error_details != nullptr);
31 QuicErrorCode error = msg.GetUint32(tag, out); 31 QuicErrorCode error = msg.GetUint32(tag, out);
32 switch (error) { 32 switch (error) {
33 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: 33 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND:
34 if (presence == PRESENCE_REQUIRED) { 34 if (presence == PRESENCE_REQUIRED) {
35 *error_details = "Missing " + QuicUtils::TagToString(tag); 35 *error_details = "Missing " + QuicTagToString(tag);
36 break; 36 break;
37 } 37 }
38 error = QUIC_NO_ERROR; 38 error = QUIC_NO_ERROR;
39 *out = default_value; 39 *out = default_value;
40 break; 40 break;
41 case QUIC_NO_ERROR: 41 case QUIC_NO_ERROR:
42 break; 42 break;
43 default: 43 default:
44 *error_details = "Bad " + QuicUtils::TagToString(tag); 44 *error_details = "Bad " + QuicTagToString(tag);
45 break; 45 break;
46 } 46 }
47 return error; 47 return error;
48 } 48 }
49 49
50 QuicConfigValue::QuicConfigValue(QuicTag tag, QuicConfigPresence presence) 50 QuicConfigValue::QuicConfigValue(QuicTag tag, QuicConfigPresence presence)
51 : tag_(tag), presence_(presence) {} 51 : tag_(tag), presence_(presence) {}
52 QuicConfigValue::~QuicConfigValue() {} 52 QuicConfigValue::~QuicConfigValue() {}
53 53
54 QuicNegotiableValue::QuicNegotiableValue(QuicTag tag, 54 QuicNegotiableValue::QuicNegotiableValue(QuicTag tag,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_t value; 100 uint32_t value;
101 QuicErrorCode error = ReadUint32(peer_hello, tag_, presence_, default_value_, 101 QuicErrorCode error = ReadUint32(peer_hello, tag_, presence_, default_value_,
102 &value, error_details); 102 &value, error_details);
103 if (error != QUIC_NO_ERROR) { 103 if (error != QUIC_NO_ERROR) {
104 return error; 104 return error;
105 } 105 }
106 if (hello_type == SERVER && value > max_value_) { 106 if (hello_type == SERVER && value > max_value_) {
107 *error_details = 107 *error_details = "Invalid value received for " + QuicTagToString(tag_);
108 "Invalid value received for " + QuicUtils::TagToString(tag_);
109 return QUIC_INVALID_NEGOTIATED_VALUE; 108 return QUIC_INVALID_NEGOTIATED_VALUE;
110 } 109 }
111 110
112 set_negotiated(true); 111 set_negotiated(true);
113 negotiated_value_ = min(value, max_value_); 112 negotiated_value_ = min(value, max_value_);
114 return QUIC_NO_ERROR; 113 return QUIC_NO_ERROR;
115 } 114 }
116 115
117 QuicNegotiableTag::QuicNegotiableTag(QuicTag tag, QuicConfigPresence presence)
118 : QuicNegotiableValue(tag, presence),
119 negotiated_tag_(0),
120 default_value_(0) {}
121
122 QuicNegotiableTag::~QuicNegotiableTag() {}
123
124 void QuicNegotiableTag::set(const QuicTagVector& possible,
125 QuicTag default_value) {
126 DCHECK(ContainsQuicTag(possible, default_value));
127 possible_values_ = possible;
128 default_value_ = default_value;
129 }
130
131 void QuicNegotiableTag::ToHandshakeMessage(CryptoHandshakeMessage* out) const {
132 if (negotiated()) {
133 // Because of the way we serialize and parse handshake messages we can
134 // serialize this as value and still parse it as a vector.
135 out->SetValue(tag_, negotiated_tag_);
136 } else {
137 out->SetVector(tag_, possible_values_);
138 }
139 }
140
141 QuicErrorCode QuicNegotiableTag::ReadVector(const CryptoHandshakeMessage& msg,
142 const QuicTag** out,
143 size_t* out_length,
144 string* error_details) const {
145 DCHECK(error_details != nullptr);
146 QuicErrorCode error = msg.GetTaglist(tag_, out, out_length);
147 switch (error) {
148 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND:
149 if (presence_ == PRESENCE_REQUIRED) {
150 *error_details = "Missing " + QuicUtils::TagToString(tag_);
151 break;
152 }
153 error = QUIC_NO_ERROR;
154 *out_length = 1;
155 *out = &default_value_;
156
157 case QUIC_NO_ERROR:
158 break;
159 default:
160 *error_details = "Bad " + QuicUtils::TagToString(tag_);
161 break;
162 }
163 return error;
164 }
165
166 QuicErrorCode QuicNegotiableTag::ProcessPeerHello(
167 const CryptoHandshakeMessage& peer_hello,
168 HelloType hello_type,
169 string* error_details) {
170 DCHECK(!negotiated());
171 DCHECK(error_details != nullptr);
172 const QuicTag* received_tags;
173 size_t received_tags_length;
174 QuicErrorCode error = ReadVector(peer_hello, &received_tags,
175 &received_tags_length, error_details);
176 if (error != QUIC_NO_ERROR) {
177 return error;
178 }
179
180 if (hello_type == SERVER) {
181 if (received_tags_length != 1 ||
182 !ContainsQuicTag(possible_values_, *received_tags)) {
183 *error_details = "Invalid " + QuicUtils::TagToString(tag_);
184 return QUIC_INVALID_NEGOTIATED_VALUE;
185 }
186 negotiated_tag_ = *received_tags;
187 } else {
188 QuicTag negotiated_tag;
189 if (!QuicUtils::FindMutualTag(
190 possible_values_, received_tags, received_tags_length,
191 QuicUtils::LOCAL_PRIORITY, &negotiated_tag, nullptr)) {
192 *error_details = "Unsupported " + QuicUtils::TagToString(tag_);
193 return QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP;
194 }
195 negotiated_tag_ = negotiated_tag;
196 }
197
198 set_negotiated(true);
199 return QUIC_NO_ERROR;
200 }
201
202 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) 116 QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence)
203 : QuicConfigValue(tag, presence), 117 : QuicConfigValue(tag, presence),
204 has_send_value_(false), 118 has_send_value_(false),
205 has_receive_value_(false) {} 119 has_receive_value_(false) {}
206 QuicFixedUint32::~QuicFixedUint32() {} 120 QuicFixedUint32::~QuicFixedUint32() {}
207 121
208 bool QuicFixedUint32::HasSendValue() const { 122 bool QuicFixedUint32::HasSendValue() const {
209 return has_send_value_; 123 return has_send_value_;
210 } 124 }
211 125
212 uint32_t QuicFixedUint32::GetSendValue() const { 126 uint32_t QuicFixedUint32::GetSendValue() const {
213 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:" 127 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:"
214 << QuicUtils::TagToString(tag_); 128 << QuicTagToString(tag_);
215 return send_value_; 129 return send_value_;
216 } 130 }
217 131
218 void QuicFixedUint32::SetSendValue(uint32_t value) { 132 void QuicFixedUint32::SetSendValue(uint32_t value) {
219 has_send_value_ = true; 133 has_send_value_ = true;
220 send_value_ = value; 134 send_value_ = value;
221 } 135 }
222 136
223 bool QuicFixedUint32::HasReceivedValue() const { 137 bool QuicFixedUint32::HasReceivedValue() const {
224 return has_receive_value_; 138 return has_receive_value_;
225 } 139 }
226 140
227 uint32_t QuicFixedUint32::GetReceivedValue() const { 141 uint32_t QuicFixedUint32::GetReceivedValue() const {
228 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:" 142 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:"
229 << QuicUtils::TagToString(tag_); 143 << QuicTagToString(tag_);
230 return receive_value_; 144 return receive_value_;
231 } 145 }
232 146
233 void QuicFixedUint32::SetReceivedValue(uint32_t value) { 147 void QuicFixedUint32::SetReceivedValue(uint32_t value) {
234 has_receive_value_ = true; 148 has_receive_value_ = true;
235 receive_value_ = value; 149 receive_value_ = value;
236 } 150 }
237 151
238 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const { 152 void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const {
239 if (has_send_value_) { 153 if (has_send_value_) {
240 out->SetValue(tag_, send_value_); 154 out->SetValue(tag_, send_value_);
241 } 155 }
242 } 156 }
243 157
244 QuicErrorCode QuicFixedUint32::ProcessPeerHello( 158 QuicErrorCode QuicFixedUint32::ProcessPeerHello(
245 const CryptoHandshakeMessage& peer_hello, 159 const CryptoHandshakeMessage& peer_hello,
246 HelloType hello_type, 160 HelloType hello_type,
247 string* error_details) { 161 string* error_details) {
248 DCHECK(error_details != nullptr); 162 DCHECK(error_details != nullptr);
249 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_); 163 QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_);
250 switch (error) { 164 switch (error) {
251 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: 165 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND:
252 if (presence_ == PRESENCE_OPTIONAL) { 166 if (presence_ == PRESENCE_OPTIONAL) {
253 return QUIC_NO_ERROR; 167 return QUIC_NO_ERROR;
254 } 168 }
255 *error_details = "Missing " + QuicUtils::TagToString(tag_); 169 *error_details = "Missing " + QuicTagToString(tag_);
256 break; 170 break;
257 case QUIC_NO_ERROR: 171 case QUIC_NO_ERROR:
258 has_receive_value_ = true; 172 has_receive_value_ = true;
259 break; 173 break;
260 default: 174 default:
261 *error_details = "Bad " + QuicUtils::TagToString(tag_); 175 *error_details = "Bad " + QuicTagToString(tag_);
262 break; 176 break;
263 } 177 }
264 return error; 178 return error;
265 } 179 }
266 180
267 QuicFixedTagVector::QuicFixedTagVector(QuicTag name, 181 QuicFixedTagVector::QuicFixedTagVector(QuicTag name,
268 QuicConfigPresence presence) 182 QuicConfigPresence presence)
269 : QuicConfigValue(name, presence), 183 : QuicConfigValue(name, presence),
270 has_send_values_(false), 184 has_send_values_(false),
271 has_receive_values_(false) {} 185 has_receive_values_(false) {}
272 186
273 QuicFixedTagVector::QuicFixedTagVector(const QuicFixedTagVector& other) = 187 QuicFixedTagVector::QuicFixedTagVector(const QuicFixedTagVector& other) =
274 default; 188 default;
275 189
276 QuicFixedTagVector::~QuicFixedTagVector() {} 190 QuicFixedTagVector::~QuicFixedTagVector() {}
277 191
278 bool QuicFixedTagVector::HasSendValues() const { 192 bool QuicFixedTagVector::HasSendValues() const {
279 return has_send_values_; 193 return has_send_values_;
280 } 194 }
281 195
282 QuicTagVector QuicFixedTagVector::GetSendValues() const { 196 QuicTagVector QuicFixedTagVector::GetSendValues() const {
283 QUIC_BUG_IF(!has_send_values_) << "No send values to get for tag:" 197 QUIC_BUG_IF(!has_send_values_) << "No send values to get for tag:"
284 << QuicUtils::TagToString(tag_); 198 << QuicTagToString(tag_);
285 return send_values_; 199 return send_values_;
286 } 200 }
287 201
288 void QuicFixedTagVector::SetSendValues(const QuicTagVector& values) { 202 void QuicFixedTagVector::SetSendValues(const QuicTagVector& values) {
289 has_send_values_ = true; 203 has_send_values_ = true;
290 send_values_ = values; 204 send_values_ = values;
291 } 205 }
292 206
293 bool QuicFixedTagVector::HasReceivedValues() const { 207 bool QuicFixedTagVector::HasReceivedValues() const {
294 return has_receive_values_; 208 return has_receive_values_;
295 } 209 }
296 210
297 QuicTagVector QuicFixedTagVector::GetReceivedValues() const { 211 QuicTagVector QuicFixedTagVector::GetReceivedValues() const {
298 QUIC_BUG_IF(!has_receive_values_) << "No receive value to get for tag:" 212 QUIC_BUG_IF(!has_receive_values_) << "No receive value to get for tag:"
299 << QuicUtils::TagToString(tag_); 213 << QuicTagToString(tag_);
300 return receive_values_; 214 return receive_values_;
301 } 215 }
302 216
303 void QuicFixedTagVector::SetReceivedValues(const QuicTagVector& values) { 217 void QuicFixedTagVector::SetReceivedValues(const QuicTagVector& values) {
304 has_receive_values_ = true; 218 has_receive_values_ = true;
305 receive_values_ = values; 219 receive_values_ = values;
306 } 220 }
307 221
308 void QuicFixedTagVector::ToHandshakeMessage(CryptoHandshakeMessage* out) const { 222 void QuicFixedTagVector::ToHandshakeMessage(CryptoHandshakeMessage* out) const {
309 if (has_send_values_) { 223 if (has_send_values_) {
310 out->SetVector(tag_, send_values_); 224 out->SetVector(tag_, send_values_);
311 } 225 }
312 } 226 }
313 227
314 QuicErrorCode QuicFixedTagVector::ProcessPeerHello( 228 QuicErrorCode QuicFixedTagVector::ProcessPeerHello(
315 const CryptoHandshakeMessage& peer_hello, 229 const CryptoHandshakeMessage& peer_hello,
316 HelloType hello_type, 230 HelloType hello_type,
317 string* error_details) { 231 string* error_details) {
318 DCHECK(error_details != nullptr); 232 DCHECK(error_details != nullptr);
319 const QuicTag* received_tags; 233 const QuicTag* received_tags;
320 size_t received_tags_length; 234 size_t received_tags_length;
321 QuicErrorCode error = 235 QuicErrorCode error =
322 peer_hello.GetTaglist(tag_, &received_tags, &received_tags_length); 236 peer_hello.GetTaglist(tag_, &received_tags, &received_tags_length);
323 switch (error) { 237 switch (error) {
324 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: 238 case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND:
325 if (presence_ == PRESENCE_OPTIONAL) { 239 if (presence_ == PRESENCE_OPTIONAL) {
326 return QUIC_NO_ERROR; 240 return QUIC_NO_ERROR;
327 } 241 }
328 *error_details = "Missing " + QuicUtils::TagToString(tag_); 242 *error_details = "Missing " + QuicTagToString(tag_);
329 break; 243 break;
330 case QUIC_NO_ERROR: 244 case QUIC_NO_ERROR:
331 DVLOG(1) << "Received Connection Option tags from receiver."; 245 DVLOG(1) << "Received Connection Option tags from receiver.";
332 has_receive_values_ = true; 246 has_receive_values_ = true;
333 for (size_t i = 0; i < received_tags_length; ++i) { 247 for (size_t i = 0; i < received_tags_length; ++i) {
334 receive_values_.push_back(received_tags[i]); 248 receive_values_.push_back(received_tags[i]);
335 } 249 }
336 break; 250 break;
337 default: 251 default:
338 *error_details = "Bad " + QuicUtils::TagToString(tag_); 252 *error_details = "Bad " + QuicTagToString(tag_);
339 break; 253 break;
340 } 254 }
341 return error; 255 return error;
342 } 256 }
343 257
344 QuicFixedIPEndPoint::QuicFixedIPEndPoint(QuicTag tag, 258 QuicFixedIPEndPoint::QuicFixedIPEndPoint(QuicTag tag,
345 QuicConfigPresence presence) 259 QuicConfigPresence presence)
346 : QuicConfigValue(tag, presence), 260 : QuicConfigValue(tag, presence),
347 has_send_value_(false), 261 has_send_value_(false),
348 has_receive_value_(false) {} 262 has_receive_value_(false) {}
349 263
350 QuicFixedIPEndPoint::~QuicFixedIPEndPoint() {} 264 QuicFixedIPEndPoint::~QuicFixedIPEndPoint() {}
351 265
352 bool QuicFixedIPEndPoint::HasSendValue() const { 266 bool QuicFixedIPEndPoint::HasSendValue() const {
353 return has_send_value_; 267 return has_send_value_;
354 } 268 }
355 269
356 const IPEndPoint& QuicFixedIPEndPoint::GetSendValue() const { 270 const IPEndPoint& QuicFixedIPEndPoint::GetSendValue() const {
357 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:" 271 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:"
358 << QuicUtils::TagToString(tag_); 272 << QuicTagToString(tag_);
359 return send_value_; 273 return send_value_;
360 } 274 }
361 275
362 void QuicFixedIPEndPoint::SetSendValue(const IPEndPoint& value) { 276 void QuicFixedIPEndPoint::SetSendValue(const IPEndPoint& value) {
363 has_send_value_ = true; 277 has_send_value_ = true;
364 send_value_ = value; 278 send_value_ = value;
365 } 279 }
366 280
367 bool QuicFixedIPEndPoint::HasReceivedValue() const { 281 bool QuicFixedIPEndPoint::HasReceivedValue() const {
368 return has_receive_value_; 282 return has_receive_value_;
369 } 283 }
370 284
371 const IPEndPoint& QuicFixedIPEndPoint::GetReceivedValue() const { 285 const IPEndPoint& QuicFixedIPEndPoint::GetReceivedValue() const {
372 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:" 286 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:"
373 << QuicUtils::TagToString(tag_); 287 << QuicTagToString(tag_);
374 return receive_value_; 288 return receive_value_;
375 } 289 }
376 290
377 void QuicFixedIPEndPoint::SetReceivedValue(const IPEndPoint& value) { 291 void QuicFixedIPEndPoint::SetReceivedValue(const IPEndPoint& value) {
378 has_receive_value_ = true; 292 has_receive_value_ = true;
379 receive_value_ = value; 293 receive_value_ = value;
380 } 294 }
381 295
382 void QuicFixedIPEndPoint::ToHandshakeMessage( 296 void QuicFixedIPEndPoint::ToHandshakeMessage(
383 CryptoHandshakeMessage* out) const { 297 CryptoHandshakeMessage* out) const {
384 if (has_send_value_) { 298 if (has_send_value_) {
385 QuicSocketAddressCoder address_coder(send_value_); 299 QuicSocketAddressCoder address_coder(send_value_);
386 out->SetStringPiece(tag_, address_coder.Encode()); 300 out->SetStringPiece(tag_, address_coder.Encode());
387 } 301 }
388 } 302 }
389 303
390 QuicErrorCode QuicFixedIPEndPoint::ProcessPeerHello( 304 QuicErrorCode QuicFixedIPEndPoint::ProcessPeerHello(
391 const CryptoHandshakeMessage& peer_hello, 305 const CryptoHandshakeMessage& peer_hello,
392 HelloType hello_type, 306 HelloType hello_type,
393 string* error_details) { 307 string* error_details) {
394 base::StringPiece address; 308 base::StringPiece address;
395 if (!peer_hello.GetStringPiece(tag_, &address)) { 309 if (!peer_hello.GetStringPiece(tag_, &address)) {
396 if (presence_ == PRESENCE_REQUIRED) { 310 if (presence_ == PRESENCE_REQUIRED) {
397 *error_details = "Missing " + QuicUtils::TagToString(tag_); 311 *error_details = "Missing " + QuicTagToString(tag_);
398 return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; 312 return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND;
399 } 313 }
400 } else { 314 } else {
401 QuicSocketAddressCoder address_coder; 315 QuicSocketAddressCoder address_coder;
402 if (address_coder.Decode(address.data(), address.length())) { 316 if (address_coder.Decode(address.data(), address.length())) {
403 SetReceivedValue(IPEndPoint(address_coder.ip(), address_coder.port())); 317 SetReceivedValue(IPEndPoint(address_coder.ip(), address_coder.port()));
404 } 318 }
405 } 319 }
406 return QUIC_NO_ERROR; 320 return QUIC_NO_ERROR;
407 } 321 }
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 error_details); 672 error_details);
759 } 673 }
760 if (error == QUIC_NO_ERROR) { 674 if (error == QUIC_NO_ERROR) {
761 error = force_hol_blocking_.ProcessPeerHello(peer_hello, hello_type, 675 error = force_hol_blocking_.ProcessPeerHello(peer_hello, hello_type,
762 error_details); 676 error_details);
763 } 677 }
764 return error; 678 return error;
765 } 679 }
766 680
767 } // namespace net 681 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_config.h ('k') | net/quic/core/quic_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698