| 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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "net/quic/crypto/quic_server_info.h" | 24 #include "net/quic/crypto/quic_server_info.h" |
| 25 #include "net/quic/port_suggester.h" | 25 #include "net/quic/port_suggester.h" |
| 26 #include "net/quic/quic_client_session.h" | 26 #include "net/quic/quic_client_session.h" |
| 27 #include "net/quic/quic_clock.h" | 27 #include "net/quic/quic_clock.h" |
| 28 #include "net/quic/quic_connection.h" | 28 #include "net/quic/quic_connection.h" |
| 29 #include "net/quic/quic_connection_helper.h" | 29 #include "net/quic/quic_connection_helper.h" |
| 30 #include "net/quic/quic_crypto_client_stream_factory.h" | 30 #include "net/quic/quic_crypto_client_stream_factory.h" |
| 31 #include "net/quic/quic_default_packet_writer.h" | 31 #include "net/quic/quic_default_packet_writer.h" |
| 32 #include "net/quic/quic_http_stream.h" | 32 #include "net/quic/quic_http_stream.h" |
| 33 #include "net/quic/quic_protocol.h" | 33 #include "net/quic/quic_protocol.h" |
| 34 #include "net/quic/quic_session_key.h" |
| 34 #include "net/socket/client_socket_factory.h" | 35 #include "net/socket/client_socket_factory.h" |
| 35 | 36 |
| 36 using std::string; | 37 using std::string; |
| 37 using std::vector; | 38 using std::vector; |
| 38 | 39 |
| 39 namespace net { | 40 namespace net { |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 const uint64 kBrokenAlternateProtocolDelaySecs = 300; | 44 const uint64 kBrokenAlternateProtocolDelaySecs = 300; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 active_requests_[request] = job; | 393 active_requests_[request] = job; |
| 393 job_requests_map_[job].insert(request); | 394 job_requests_map_[job].insert(request); |
| 394 return ERR_IO_PENDING; | 395 return ERR_IO_PENDING; |
| 395 } | 396 } |
| 396 | 397 |
| 397 QuicServerInfo* quic_server_info = NULL; | 398 QuicServerInfo* quic_server_info = NULL; |
| 398 if (quic_server_info_factory_) { | 399 if (quic_server_info_factory_) { |
| 399 QuicCryptoClientConfig* crypto_config = | 400 QuicCryptoClientConfig* crypto_config = |
| 400 GetOrCreateCryptoConfig(session_key); | 401 GetOrCreateCryptoConfig(session_key); |
| 401 QuicCryptoClientConfig::CachedState* cached = | 402 QuicCryptoClientConfig::CachedState* cached = |
| 402 crypto_config->LookupOrCreate(session_key.host_port_pair().host()); | 403 crypto_config->LookupOrCreate(session_key); |
| 403 DCHECK(cached); | 404 DCHECK(cached); |
| 404 if (cached->IsEmpty()) { | 405 if (cached->IsEmpty()) { |
| 405 quic_server_info = | 406 quic_server_info = quic_server_info_factory_->GetForServer(session_key); |
| 406 quic_server_info_factory_->GetForHost(host_port_pair.host()); | |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, | 409 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, |
| 410 is_https, method, cert_verifier, | 410 is_https, method, cert_verifier, |
| 411 quic_server_info, net_log)); | 411 quic_server_info, net_log)); |
| 412 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 412 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 413 base::Unretained(this), job.get())); | 413 base::Unretained(this), job.get())); |
| 414 | 414 |
| 415 if (rv == ERR_IO_PENDING) { | 415 if (rv == ERR_IO_PENDING) { |
| 416 active_requests_[request] = job.get(); | 416 active_requests_[request] = job.get(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 431 for (size_t i = 0; i < address_list.size(); ++i) { | 431 for (size_t i = 0; i < address_list.size(); ++i) { |
| 432 const IPEndPoint& address = address_list[i]; | 432 const IPEndPoint& address = address_list[i]; |
| 433 const IpAliasKey ip_alias_key(address, session_key.is_https()); | 433 const IpAliasKey ip_alias_key(address, session_key.is_https()); |
| 434 if (!ContainsKey(ip_aliases_, ip_alias_key)) | 434 if (!ContainsKey(ip_aliases_, ip_alias_key)) |
| 435 continue; | 435 continue; |
| 436 | 436 |
| 437 const SessionSet& sessions = ip_aliases_[ip_alias_key]; | 437 const SessionSet& sessions = ip_aliases_[ip_alias_key]; |
| 438 for (SessionSet::const_iterator i = sessions.begin(); | 438 for (SessionSet::const_iterator i = sessions.begin(); |
| 439 i != sessions.end(); ++i) { | 439 i != sessions.end(); ++i) { |
| 440 QuicClientSession* session = *i; | 440 QuicClientSession* session = *i; |
| 441 if (!session->CanPool(session_key.host_port_pair().host())) | 441 if (!session->CanPool(session_key.host())) |
| 442 continue; | 442 continue; |
| 443 active_sessions_[session_key] = session; | 443 active_sessions_[session_key] = session; |
| 444 session_aliases_[session].insert(session_key); | 444 session_aliases_[session].insert(session_key); |
| 445 return true; | 445 return true; |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 return false; | 448 return false; |
| 449 } | 449 } |
| 450 | 450 |
| 451 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { | 451 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 const HttpServerProperties::NetworkStats* stats = | 708 const HttpServerProperties::NetworkStats* stats = |
| 709 http_server_properties_->GetServerNetworkStats(host_port_pair); | 709 http_server_properties_->GetServerNetworkStats(host_port_pair); |
| 710 if (stats != NULL) { | 710 if (stats != NULL) { |
| 711 config.set_initial_round_trip_time_us(stats->rtt.InMicroseconds(), | 711 config.set_initial_round_trip_time_us(stats->rtt.InMicroseconds(), |
| 712 stats->rtt.InMicroseconds()); | 712 stats->rtt.InMicroseconds()); |
| 713 } | 713 } |
| 714 } | 714 } |
| 715 | 715 |
| 716 *session = new QuicClientSession( | 716 *session = new QuicClientSession( |
| 717 connection, socket.Pass(), writer.Pass(), this, server_info.Pass(), | 717 connection, socket.Pass(), writer.Pass(), this, server_info.Pass(), |
| 718 quic_crypto_client_stream_factory_, host_port_pair.host(), | 718 quic_crypto_client_stream_factory_, session_key, config, crypto_config, |
| 719 config, crypto_config, net_log.net_log()); | 719 net_log.net_log()); |
| 720 all_sessions_.insert(*session); // owning pointer | 720 all_sessions_.insert(*session); // owning pointer |
| 721 if (is_https) { | 721 if (is_https) { |
| 722 crypto_config->SetProofVerifier( | 722 crypto_config->SetProofVerifier( |
| 723 new ProofVerifierChromium(cert_verifier, net_log)); | 723 new ProofVerifierChromium(cert_verifier, net_log)); |
| 724 } | 724 } |
| 725 return OK; | 725 return OK; |
| 726 } | 726 } |
| 727 | 727 |
| 728 bool QuicStreamFactory::HasActiveJob(const QuicSessionKey& key) const { | 728 bool QuicStreamFactory::HasActiveJob(const QuicSessionKey& key) const { |
| 729 return ContainsKey(active_jobs_, key); | 729 return ContainsKey(active_jobs_, key); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 755 crypto_config->SetDefaults(); | 755 crypto_config->SetDefaults(); |
| 756 all_crypto_configs_[session_key] = crypto_config; | 756 all_crypto_configs_[session_key] = crypto_config; |
| 757 PopulateFromCanonicalConfig(session_key, crypto_config); | 757 PopulateFromCanonicalConfig(session_key, crypto_config); |
| 758 } | 758 } |
| 759 return crypto_config; | 759 return crypto_config; |
| 760 } | 760 } |
| 761 | 761 |
| 762 void QuicStreamFactory::PopulateFromCanonicalConfig( | 762 void QuicStreamFactory::PopulateFromCanonicalConfig( |
| 763 const QuicSessionKey& session_key, | 763 const QuicSessionKey& session_key, |
| 764 QuicCryptoClientConfig* crypto_config) { | 764 QuicCryptoClientConfig* crypto_config) { |
| 765 const string server_hostname = session_key.host_port_pair().host(); | 765 const string server_hostname = session_key.host(); |
| 766 const uint16 server_port = session_key.host_port_pair().port(); | |
| 767 unsigned i = 0; | 766 unsigned i = 0; |
| 768 for (; i < canoncial_suffixes_.size(); ++i) { | 767 for (; i < canoncial_suffixes_.size(); ++i) { |
| 769 if (EndsWith(server_hostname, canoncial_suffixes_[i], false)) { | 768 if (EndsWith(server_hostname, canoncial_suffixes_[i], false)) { |
| 770 break; | 769 break; |
| 771 } | 770 } |
| 772 } | 771 } |
| 773 if (i == canoncial_suffixes_.size()) | 772 if (i == canoncial_suffixes_.size()) |
| 774 return; | 773 return; |
| 775 | 774 |
| 776 HostPortPair suffix_host_port_pair(canoncial_suffixes_[i], server_port); | 775 HostPortPair suffix_host_port_pair(canoncial_suffixes_[i], |
| 776 session_key.port()); |
| 777 QuicSessionKey suffix_session_key(suffix_host_port_pair, | 777 QuicSessionKey suffix_session_key(suffix_host_port_pair, |
| 778 session_key.is_https()); | 778 session_key.is_https()); |
| 779 if (!ContainsKey(canonical_hostname_to_origin_map_, suffix_session_key)) { | 779 if (!ContainsKey(canonical_hostname_to_origin_map_, suffix_session_key)) { |
| 780 // This is the first host we've seen which matches the suffix, so make it | 780 // This is the first host we've seen which matches the suffix, so make it |
| 781 // canonical. | 781 // canonical. |
| 782 canonical_hostname_to_origin_map_[suffix_session_key] = session_key; | 782 canonical_hostname_to_origin_map_[suffix_session_key] = session_key; |
| 783 return; | 783 return; |
| 784 } | 784 } |
| 785 | 785 |
| 786 const QuicSessionKey& canonical_session_key = | 786 const QuicSessionKey& canonical_session_key = |
| 787 canonical_hostname_to_origin_map_[suffix_session_key]; | 787 canonical_hostname_to_origin_map_[suffix_session_key]; |
| 788 QuicCryptoClientConfig* canonical_crypto_config = | 788 QuicCryptoClientConfig* canonical_crypto_config = |
| 789 all_crypto_configs_[canonical_session_key]; | 789 all_crypto_configs_[canonical_session_key]; |
| 790 DCHECK(canonical_crypto_config); | 790 DCHECK(canonical_crypto_config); |
| 791 const HostPortPair& canonical_host_port_pair = | |
| 792 canonical_session_key.host_port_pair(); | |
| 793 | 791 |
| 794 // Copy the CachedState for the canonical server from canonical_crypto_config | 792 // Copy the CachedState for the canonical server from canonical_crypto_config |
| 795 // as the initial CachedState for the server_hostname in crypto_config. | 793 // as the initial CachedState for the server_hostname in crypto_config. |
| 796 crypto_config->InitializeFrom(server_hostname, | 794 crypto_config->InitializeFrom(session_key, canonical_session_key, |
| 797 canonical_host_port_pair.host(), | |
| 798 canonical_crypto_config); | 795 canonical_crypto_config); |
| 799 // Update canonical version to point at the "most recent" crypto_config. | 796 // Update canonical version to point at the "most recent" crypto_config. |
| 800 canonical_hostname_to_origin_map_[suffix_session_key] = | 797 canonical_hostname_to_origin_map_[suffix_session_key] = |
| 801 canonical_session_key; | 798 canonical_session_key; |
| 802 } | 799 } |
| 803 | 800 |
| 804 void QuicStreamFactory::ExpireBrokenAlternateProtocolMappings() { | 801 void QuicStreamFactory::ExpireBrokenAlternateProtocolMappings() { |
| 805 base::TimeTicks now = base::TimeTicks::Now(); | 802 base::TimeTicks now = base::TimeTicks::Now(); |
| 806 while (!broken_alternate_protocol_list_.empty()) { | 803 while (!broken_alternate_protocol_list_.empty()) { |
| 807 BrokenAlternateProtocolEntry entry = | 804 BrokenAlternateProtocolEntry entry = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 824 base::TimeTicks when = broken_alternate_protocol_list_.front().when; | 821 base::TimeTicks when = broken_alternate_protocol_list_.front().when; |
| 825 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 822 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 826 base::MessageLoop::current()->PostDelayedTask( | 823 base::MessageLoop::current()->PostDelayedTask( |
| 827 FROM_HERE, | 824 FROM_HERE, |
| 828 base::Bind(&QuicStreamFactory::ExpireBrokenAlternateProtocolMappings, | 825 base::Bind(&QuicStreamFactory::ExpireBrokenAlternateProtocolMappings, |
| 829 weak_factory_.GetWeakPtr()), | 826 weak_factory_.GetWeakPtr()), |
| 830 delay); | 827 delay); |
| 831 } | 828 } |
| 832 | 829 |
| 833 } // namespace net | 830 } // namespace net |
| OLD | NEW |