OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // TODO: This should be tested and optimized, and even better, suggest a window | 64 // TODO: This should be tested and optimized, and even better, suggest a window |
65 // that corresponds to historical bandwidth and min-RTT. | 65 // that corresponds to historical bandwidth and min-RTT. |
66 // Larger initial congestion windows can, if we don't overshoot, reduce latency | 66 // Larger initial congestion windows can, if we don't overshoot, reduce latency |
67 // by avoiding the RTT needed for slow start to double (and re-double) from a | 67 // by avoiding the RTT needed for slow start to double (and re-double) from a |
68 // default of 10. | 68 // default of 10. |
69 // We match SPDY's use of 32 when secure (since we'd compete with SPDY). | 69 // We match SPDY's use of 32 when secure (since we'd compete with SPDY). |
70 const int32 kServerSecureInitialCongestionWindow = 32; | 70 const int32 kServerSecureInitialCongestionWindow = 32; |
71 // Be conservative, and just use double a typical TCP ICWND for HTTP. | 71 // Be conservative, and just use double a typical TCP ICWND for HTTP. |
72 const int32 kServerInecureInitialCongestionWindow = 20; | 72 const int32 kServerInecureInitialCongestionWindow = 20; |
73 | 73 |
| 74 const char kDummyHostname[] = "quic.global.props"; |
| 75 const uint16 kDummyPort = 0; |
| 76 |
74 void HistogramCreateSessionFailure(enum CreateSessionFailure error) { | 77 void HistogramCreateSessionFailure(enum CreateSessionFailure error) { |
75 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.CreationError", error, | 78 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.CreationError", error, |
76 CREATION_ERROR_MAX); | 79 CREATION_ERROR_MAX); |
77 } | 80 } |
78 | 81 |
79 bool IsEcdsaSupported() { | 82 bool IsEcdsaSupported() { |
80 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
81 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 84 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
82 return false; | 85 return false; |
83 #endif | 86 #endif |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 clock_(clock), | 506 clock_(clock), |
504 max_packet_length_(max_packet_length), | 507 max_packet_length_(max_packet_length), |
505 config_(InitializeQuicConfig(enable_time_based_loss_detection, | 508 config_(InitializeQuicConfig(enable_time_based_loss_detection, |
506 connection_options)), | 509 connection_options)), |
507 supported_versions_(supported_versions), | 510 supported_versions_(supported_versions), |
508 enable_port_selection_(enable_port_selection), | 511 enable_port_selection_(enable_port_selection), |
509 always_require_handshake_confirmation_( | 512 always_require_handshake_confirmation_( |
510 always_require_handshake_confirmation), | 513 always_require_handshake_confirmation), |
511 disable_connection_pooling_(disable_connection_pooling), | 514 disable_connection_pooling_(disable_connection_pooling), |
512 port_seed_(random_generator_->RandUint64()), | 515 port_seed_(random_generator_->RandUint64()), |
| 516 check_persisted_supports_quic_(true), |
513 weak_factory_(this) { | 517 weak_factory_(this) { |
514 DCHECK(transport_security_state_); | 518 DCHECK(transport_security_state_); |
515 crypto_config_.SetDefaults(); | 519 crypto_config_.SetDefaults(); |
516 crypto_config_.set_user_agent_id(user_agent_id); | 520 crypto_config_.set_user_agent_id(user_agent_id); |
517 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 521 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
518 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 522 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
519 crypto_config_.SetProofVerifier( | 523 crypto_config_.SetProofVerifier( |
520 new ProofVerifierChromium(cert_verifier, transport_security_state)); | 524 new ProofVerifierChromium(cert_verifier, transport_security_state)); |
521 crypto_config_.SetChannelIDSource( | 525 crypto_config_.SetChannelIDSource( |
522 new ChannelIDSourceChromium(channel_id_service)); | 526 new ChannelIDSourceChromium(channel_id_service)); |
523 base::CPU cpu; | 527 base::CPU cpu; |
524 if (cpu.has_aesni() && cpu.has_avx()) | 528 if (cpu.has_aesni() && cpu.has_avx()) |
525 crypto_config_.PreferAesGcm(); | 529 crypto_config_.PreferAesGcm(); |
526 if (!IsEcdsaSupported()) | 530 if (!IsEcdsaSupported()) |
527 crypto_config_.DisableEcdsa(); | 531 crypto_config_.DisableEcdsa(); |
528 } | 532 } |
529 | 533 |
530 QuicStreamFactory::~QuicStreamFactory() { | 534 QuicStreamFactory::~QuicStreamFactory() { |
531 CloseAllSessions(ERR_ABORTED); | 535 CloseAllSessions(ERR_ABORTED); |
532 while (!all_sessions_.empty()) { | 536 while (!all_sessions_.empty()) { |
533 delete all_sessions_.begin()->first; | 537 delete all_sessions_.begin()->first; |
534 all_sessions_.erase(all_sessions_.begin()); | 538 all_sessions_.erase(all_sessions_.begin()); |
535 } | 539 } |
536 STLDeleteValues(&active_jobs_); | 540 STLDeleteValues(&active_jobs_); |
537 } | 541 } |
538 | 542 |
| 543 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { |
| 544 require_confirmation_ = require_confirmation; |
| 545 if (http_server_properties_ && (!(local_address_ == IPEndPoint()))) { |
| 546 // TODO(rtenneti): Delete host_port_pair and persist data in globals. |
| 547 HostPortPair host_port_pair(kDummyHostname, kDummyPort); |
| 548 http_server_properties_->SetSupportsQuic( |
| 549 host_port_pair, !require_confirmation, |
| 550 local_address_.ToStringWithoutPort()); |
| 551 } |
| 552 } |
| 553 |
539 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, | 554 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, |
540 bool is_https, | 555 bool is_https, |
541 PrivacyMode privacy_mode, | 556 PrivacyMode privacy_mode, |
542 base::StringPiece method, | 557 base::StringPiece method, |
543 const BoundNetLog& net_log, | 558 const BoundNetLog& net_log, |
544 QuicStreamRequest* request) { | 559 QuicStreamRequest* request) { |
545 QuicServerId server_id(host_port_pair, is_https, privacy_mode); | 560 QuicServerId server_id(host_port_pair, is_https, privacy_mode); |
546 if (HasActiveSession(server_id)) { | 561 if (HasActiveSession(server_id)) { |
547 request->set_stream(CreateIfSessionExists(server_id, net_log)); | 562 request->set_stream(CreateIfSessionExists(server_id, net_log)); |
548 return OK; | 563 return OK; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 session_aliases_[session].insert(server_id); | 624 session_aliases_[session].insert(server_id); |
610 return true; | 625 return true; |
611 } | 626 } |
612 } | 627 } |
613 return false; | 628 return false; |
614 } | 629 } |
615 | 630 |
616 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { | 631 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { |
617 if (rv == OK) { | 632 if (rv == OK) { |
618 if (!always_require_handshake_confirmation_) | 633 if (!always_require_handshake_confirmation_) |
619 require_confirmation_ = false; | 634 set_require_confirmation(false); |
620 | 635 |
621 // Create all the streams, but do not notify them yet. | 636 // Create all the streams, but do not notify them yet. |
622 for (RequestSet::iterator it = job_requests_map_[job].begin(); | 637 for (RequestSet::iterator it = job_requests_map_[job].begin(); |
623 it != job_requests_map_[job].end() ; ++it) { | 638 it != job_requests_map_[job].end() ; ++it) { |
624 DCHECK(HasActiveSession(job->server_id())); | 639 DCHECK(HasActiveSession(job->server_id())); |
625 (*it)->set_stream(CreateIfSessionExists(job->server_id(), | 640 (*it)->set_stream(CreateIfSessionExists(job->server_id(), |
626 (*it)->net_log())); | 641 (*it)->net_log())); |
627 } | 642 } |
628 } | 643 } |
629 while (!job_requests_map_[job].empty()) { | 644 while (!job_requests_map_[job].empty()) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 } | 780 } |
766 return list; | 781 return list; |
767 } | 782 } |
768 | 783 |
769 void QuicStreamFactory::ClearCachedStatesInCryptoConfig() { | 784 void QuicStreamFactory::ClearCachedStatesInCryptoConfig() { |
770 crypto_config_.ClearCachedStates(); | 785 crypto_config_.ClearCachedStates(); |
771 } | 786 } |
772 | 787 |
773 void QuicStreamFactory::OnIPAddressChanged() { | 788 void QuicStreamFactory::OnIPAddressChanged() { |
774 CloseAllSessions(ERR_NETWORK_CHANGED); | 789 CloseAllSessions(ERR_NETWORK_CHANGED); |
775 require_confirmation_ = true; | 790 set_require_confirmation(true); |
776 } | 791 } |
777 | 792 |
778 void QuicStreamFactory::OnCertAdded(const X509Certificate* cert) { | 793 void QuicStreamFactory::OnCertAdded(const X509Certificate* cert) { |
779 CloseAllSessions(ERR_CERT_DATABASE_CHANGED); | 794 CloseAllSessions(ERR_CERT_DATABASE_CHANGED); |
780 } | 795 } |
781 | 796 |
782 void QuicStreamFactory::OnCACertChanged(const X509Certificate* cert) { | 797 void QuicStreamFactory::OnCACertChanged(const X509Certificate* cert) { |
783 // We should flush the sessions if we removed trust from a | 798 // We should flush the sessions if we removed trust from a |
784 // cert, because a previously trusted server may have become | 799 // cert, because a previously trusted server may have become |
785 // untrusted. | 800 // untrusted. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 } | 865 } |
851 // Set a buffer large enough to contain the initial CWND's worth of packet | 866 // Set a buffer large enough to contain the initial CWND's worth of packet |
852 // to work around the problem with CHLO packets being sent out with the | 867 // to work around the problem with CHLO packets being sent out with the |
853 // wrong encryption level, when the send buffer is full. | 868 // wrong encryption level, when the send buffer is full. |
854 rv = socket->SetSendBufferSize(kMaxPacketSize * 20); | 869 rv = socket->SetSendBufferSize(kMaxPacketSize * 20); |
855 if (rv != OK) { | 870 if (rv != OK) { |
856 HistogramCreateSessionFailure(CREATION_ERROR_SETTING_SEND_BUFFER); | 871 HistogramCreateSessionFailure(CREATION_ERROR_SETTING_SEND_BUFFER); |
857 return rv; | 872 return rv; |
858 } | 873 } |
859 | 874 |
| 875 socket->GetLocalAddress(&local_address_); |
| 876 if (check_persisted_supports_quic_ && http_server_properties_) { |
| 877 check_persisted_supports_quic_ = false; |
| 878 // TODO(rtenneti): Delete host_port_pair and persist data in globals. |
| 879 HostPortPair host_port_pair(kDummyHostname, kDummyPort); |
| 880 SupportsQuic supports_quic(true, local_address_.ToStringWithoutPort()); |
| 881 if (http_server_properties_->GetSupportsQuic( |
| 882 host_port_pair).Equals(supports_quic)) { |
| 883 require_confirmation_ = false; |
| 884 } |
| 885 } |
| 886 |
860 DefaultPacketWriterFactory packet_writer_factory(socket.get()); | 887 DefaultPacketWriterFactory packet_writer_factory(socket.get()); |
861 | 888 |
862 if (!helper_.get()) { | 889 if (!helper_.get()) { |
863 helper_.reset(new QuicConnectionHelper( | 890 helper_.reset(new QuicConnectionHelper( |
864 base::MessageLoop::current()->message_loop_proxy().get(), | 891 base::MessageLoop::current()->message_loop_proxy().get(), |
865 clock_.get(), random_generator_)); | 892 clock_.get(), random_generator_)); |
866 } | 893 } |
867 | 894 |
868 QuicConnection* connection = new QuicConnection(connection_id, | 895 QuicConnection* connection = new QuicConnection(connection_id, |
869 addr, | 896 addr, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 http_server_properties_->ClearAlternateProtocol(server); | 1030 http_server_properties_->ClearAlternateProtocol(server); |
1004 http_server_properties_->SetAlternateProtocol( | 1031 http_server_properties_->SetAlternateProtocol( |
1005 server, alternate.port, alternate.protocol, 1); | 1032 server, alternate.port, alternate.protocol, 1); |
1006 DCHECK_EQ(QUIC, | 1033 DCHECK_EQ(QUIC, |
1007 http_server_properties_->GetAlternateProtocol(server).protocol); | 1034 http_server_properties_->GetAlternateProtocol(server).protocol); |
1008 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1035 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
1009 server)); | 1036 server)); |
1010 } | 1037 } |
1011 | 1038 |
1012 } // namespace net | 1039 } // namespace net |
OLD | NEW |