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

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

Issue 2011933002: Add alternate server address to QuicConfig. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@122546126
Patch Set: Created 4 years, 7 months 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/quic_config.h ('k') | net/quic/quic_config_test.cc » ('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/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_bug_tracker.h" 12 #include "net/quic/quic_bug_tracker.h"
13 #include "net/quic/quic_socket_address_coder.h"
13 #include "net/quic/quic_utils.h" 14 #include "net/quic/quic_utils.h"
14 15
15 using std::min; 16 using std::min;
16 using std::string; 17 using std::string;
17 18
18 namespace net { 19 namespace net {
19 20
20 // Reads the value corresponding to |name_| from |msg| into |out|. If the 21 // Reads the value corresponding to |name_| from |msg| into |out|. If the
21 // |name_| is absent in |msg| and |presence| is set to OPTIONAL |out| is set 22 // |name_| is absent in |msg| and |presence| is set to OPTIONAL |out| is set
22 // to |default_value|. 23 // to |default_value|.
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 receive_values_.push_back(received_tags[i]); 329 receive_values_.push_back(received_tags[i]);
329 } 330 }
330 break; 331 break;
331 default: 332 default:
332 *error_details = "Bad " + QuicUtils::TagToString(tag_); 333 *error_details = "Bad " + QuicUtils::TagToString(tag_);
333 break; 334 break;
334 } 335 }
335 return error; 336 return error;
336 } 337 }
337 338
339 QuicFixedIPEndPoint::QuicFixedIPEndPoint(QuicTag tag,
340 QuicConfigPresence presence)
341 : QuicConfigValue(tag, presence),
342 has_send_value_(false),
343 has_receive_value_(false) {}
344
345 QuicFixedIPEndPoint::~QuicFixedIPEndPoint() {}
346
347 bool QuicFixedIPEndPoint::HasSendValue() const {
348 return has_send_value_;
349 }
350
351 const IPEndPoint& QuicFixedIPEndPoint::GetSendValue() const {
352 QUIC_BUG_IF(!has_send_value_) << "No send value to get for tag:"
353 << QuicUtils::TagToString(tag_);
354 return send_value_;
355 }
356
357 void QuicFixedIPEndPoint::SetSendValue(const IPEndPoint& value) {
358 has_send_value_ = true;
359 send_value_ = value;
360 }
361
362 bool QuicFixedIPEndPoint::HasReceivedValue() const {
363 return has_receive_value_;
364 }
365
366 const IPEndPoint& QuicFixedIPEndPoint::GetReceivedValue() const {
367 QUIC_BUG_IF(!has_receive_value_) << "No receive value to get for tag:"
368 << QuicUtils::TagToString(tag_);
369 return receive_value_;
370 }
371
372 void QuicFixedIPEndPoint::SetReceivedValue(const IPEndPoint& value) {
373 has_receive_value_ = true;
374 receive_value_ = value;
375 }
376
377 void QuicFixedIPEndPoint::ToHandshakeMessage(
378 CryptoHandshakeMessage* out) const {
379 if (has_send_value_) {
380 QuicSocketAddressCoder address_coder(send_value_);
381 out->SetStringPiece(tag_, address_coder.Encode());
382 }
383 }
384
385 QuicErrorCode QuicFixedIPEndPoint::ProcessPeerHello(
386 const CryptoHandshakeMessage& peer_hello,
387 HelloType hello_type,
388 string* error_details) {
389 base::StringPiece address;
390 if (!peer_hello.GetStringPiece(tag_, &address)) {
391 if (presence_ == PRESENCE_REQUIRED) {
392 *error_details = "Missing " + QuicUtils::TagToString(tag_);
393 return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND;
394 }
395 } else {
396 QuicSocketAddressCoder address_coder;
397 if (address_coder.Decode(address.data(), address.length())) {
398 SetReceivedValue(IPEndPoint(address_coder.ip(), address_coder.port()));
399 }
400 }
401 return QUIC_NO_ERROR;
402 }
403
338 QuicConfig::QuicConfig() 404 QuicConfig::QuicConfig()
339 : max_time_before_crypto_handshake_(QuicTime::Delta::Zero()), 405 : max_time_before_crypto_handshake_(QuicTime::Delta::Zero()),
340 max_idle_time_before_crypto_handshake_(QuicTime::Delta::Zero()), 406 max_idle_time_before_crypto_handshake_(QuicTime::Delta::Zero()),
341 max_undecryptable_packets_(0), 407 max_undecryptable_packets_(0),
342 connection_options_(kCOPT, PRESENCE_OPTIONAL), 408 connection_options_(kCOPT, PRESENCE_OPTIONAL),
343 idle_connection_state_lifetime_seconds_(kICSL, PRESENCE_REQUIRED), 409 idle_connection_state_lifetime_seconds_(kICSL, PRESENCE_REQUIRED),
344 silent_close_(kSCLS, PRESENCE_OPTIONAL), 410 silent_close_(kSCLS, PRESENCE_OPTIONAL),
345 max_streams_per_connection_(kMSPC, PRESENCE_REQUIRED), 411 max_streams_per_connection_(kMSPC, PRESENCE_REQUIRED),
346 bytes_for_connection_id_(kTCID, PRESENCE_OPTIONAL), 412 bytes_for_connection_id_(kTCID, PRESENCE_OPTIONAL),
347 initial_round_trip_time_us_(kIRTT, PRESENCE_OPTIONAL), 413 initial_round_trip_time_us_(kIRTT, PRESENCE_OPTIONAL),
348 initial_stream_flow_control_window_bytes_(kSFCW, PRESENCE_OPTIONAL), 414 initial_stream_flow_control_window_bytes_(kSFCW, PRESENCE_OPTIONAL),
349 initial_session_flow_control_window_bytes_(kCFCW, PRESENCE_OPTIONAL), 415 initial_session_flow_control_window_bytes_(kCFCW, PRESENCE_OPTIONAL),
350 socket_receive_buffer_(kSRBF, PRESENCE_OPTIONAL), 416 socket_receive_buffer_(kSRBF, PRESENCE_OPTIONAL),
351 multipath_enabled_(kMPTH, PRESENCE_OPTIONAL), 417 multipath_enabled_(kMPTH, PRESENCE_OPTIONAL),
352 connection_migration_disabled_(kNCMR, PRESENCE_OPTIONAL) { 418 connection_migration_disabled_(kNCMR, PRESENCE_OPTIONAL),
419 alternate_server_address_(kASAD, PRESENCE_OPTIONAL) {
353 SetDefaults(); 420 SetDefaults();
354 } 421 }
355 422
356 QuicConfig::QuicConfig(const QuicConfig& other) = default; 423 QuicConfig::QuicConfig(const QuicConfig& other) = default;
357 424
358 QuicConfig::~QuicConfig() {} 425 QuicConfig::~QuicConfig() {}
359 426
360 bool QuicConfig::SetInitialReceivedConnectionOptions( 427 bool QuicConfig::SetInitialReceivedConnectionOptions(
361 const QuicTagVector& tags) { 428 const QuicTagVector& tags) {
362 if (HasReceivedConnectionOptions()) { 429 if (HasReceivedConnectionOptions()) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 605 }
539 606
540 void QuicConfig::SetDisableConnectionMigration() { 607 void QuicConfig::SetDisableConnectionMigration() {
541 connection_migration_disabled_.SetSendValue(1); 608 connection_migration_disabled_.SetSendValue(1);
542 } 609 }
543 610
544 bool QuicConfig::DisableConnectionMigration() const { 611 bool QuicConfig::DisableConnectionMigration() const {
545 return connection_migration_disabled_.HasReceivedValue(); 612 return connection_migration_disabled_.HasReceivedValue();
546 } 613 }
547 614
615 void QuicConfig::SetAlternateServerAddressToSend(
616 const IPEndPoint& alternate_server_address) {
617 alternate_server_address_.SetSendValue(alternate_server_address);
618 }
619
620 bool QuicConfig::HasReceivedAlternateServerAddress() const {
621 return alternate_server_address_.HasReceivedValue();
622 }
623
624 const IPEndPoint& QuicConfig::ReceivedAlternateServerAddress() const {
625 return alternate_server_address_.GetReceivedValue();
626 }
627
548 bool QuicConfig::negotiated() const { 628 bool QuicConfig::negotiated() const {
549 // TODO(ianswett): Add the negotiated parameters once and iterate over all 629 // TODO(ianswett): Add the negotiated parameters once and iterate over all
550 // of them in negotiated, ToHandshakeMessage, ProcessClientHello, and 630 // of them in negotiated, ToHandshakeMessage, ProcessClientHello, and
551 // ProcessServerHello. 631 // ProcessServerHello.
552 return idle_connection_state_lifetime_seconds_.negotiated() && 632 return idle_connection_state_lifetime_seconds_.negotiated() &&
553 max_streams_per_connection_.negotiated(); 633 max_streams_per_connection_.negotiated();
554 } 634 }
555 635
556 void QuicConfig::SetDefaults() { 636 void QuicConfig::SetDefaults() {
557 idle_connection_state_lifetime_seconds_.set(kMaximumIdleTimeoutSecs, 637 idle_connection_state_lifetime_seconds_.set(kMaximumIdleTimeoutSecs,
(...skipping 15 matching lines...) Expand all
573 idle_connection_state_lifetime_seconds_.ToHandshakeMessage(out); 653 idle_connection_state_lifetime_seconds_.ToHandshakeMessage(out);
574 silent_close_.ToHandshakeMessage(out); 654 silent_close_.ToHandshakeMessage(out);
575 max_streams_per_connection_.ToHandshakeMessage(out); 655 max_streams_per_connection_.ToHandshakeMessage(out);
576 bytes_for_connection_id_.ToHandshakeMessage(out); 656 bytes_for_connection_id_.ToHandshakeMessage(out);
577 initial_round_trip_time_us_.ToHandshakeMessage(out); 657 initial_round_trip_time_us_.ToHandshakeMessage(out);
578 initial_stream_flow_control_window_bytes_.ToHandshakeMessage(out); 658 initial_stream_flow_control_window_bytes_.ToHandshakeMessage(out);
579 initial_session_flow_control_window_bytes_.ToHandshakeMessage(out); 659 initial_session_flow_control_window_bytes_.ToHandshakeMessage(out);
580 socket_receive_buffer_.ToHandshakeMessage(out); 660 socket_receive_buffer_.ToHandshakeMessage(out);
581 connection_migration_disabled_.ToHandshakeMessage(out); 661 connection_migration_disabled_.ToHandshakeMessage(out);
582 connection_options_.ToHandshakeMessage(out); 662 connection_options_.ToHandshakeMessage(out);
663 alternate_server_address_.ToHandshakeMessage(out);
583 } 664 }
584 665
585 QuicErrorCode QuicConfig::ProcessPeerHello( 666 QuicErrorCode QuicConfig::ProcessPeerHello(
586 const CryptoHandshakeMessage& peer_hello, 667 const CryptoHandshakeMessage& peer_hello,
587 HelloType hello_type, 668 HelloType hello_type,
588 string* error_details) { 669 string* error_details) {
589 DCHECK(error_details != nullptr); 670 DCHECK(error_details != nullptr);
590 671
591 QuicErrorCode error = QUIC_NO_ERROR; 672 QuicErrorCode error = QUIC_NO_ERROR;
592 if (error == QUIC_NO_ERROR) { 673 if (error == QUIC_NO_ERROR) {
(...skipping 29 matching lines...) Expand all
622 error_details); 703 error_details);
623 } 704 }
624 if (error == QUIC_NO_ERROR) { 705 if (error == QUIC_NO_ERROR) {
625 error = connection_migration_disabled_.ProcessPeerHello( 706 error = connection_migration_disabled_.ProcessPeerHello(
626 peer_hello, hello_type, error_details); 707 peer_hello, hello_type, error_details);
627 } 708 }
628 if (error == QUIC_NO_ERROR) { 709 if (error == QUIC_NO_ERROR) {
629 error = connection_options_.ProcessPeerHello(peer_hello, hello_type, 710 error = connection_options_.ProcessPeerHello(peer_hello, hello_type,
630 error_details); 711 error_details);
631 } 712 }
713 if (error == QUIC_NO_ERROR) {
714 error = alternate_server_address_.ProcessPeerHello(peer_hello, hello_type,
715 error_details);
716 }
632 return error; 717 return error;
633 } 718 }
634 719
635 } // namespace net 720 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_config.h ('k') | net/quic/quic_config_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698