| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 QuicPacketWriter* DefaultPacketWriterFactory::Create( | 117 QuicPacketWriter* DefaultPacketWriterFactory::Create( |
| 118 QuicConnection* connection) const { | 118 QuicConnection* connection) const { |
| 119 scoped_ptr<QuicDefaultPacketWriter> writer( | 119 scoped_ptr<QuicDefaultPacketWriter> writer( |
| 120 new QuicDefaultPacketWriter(socket_)); | 120 new QuicDefaultPacketWriter(socket_)); |
| 121 writer->SetConnection(connection); | 121 writer->SetConnection(connection); |
| 122 return writer.release(); | 122 return writer.release(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace | 125 } // namespace |
| 126 | 126 |
| 127 QuicStreamFactory::IpAliasKey::IpAliasKey() {} | |
| 128 | |
| 129 QuicStreamFactory::IpAliasKey::IpAliasKey(IPEndPoint ip_endpoint, | |
| 130 bool is_https) | |
| 131 : ip_endpoint(ip_endpoint), | |
| 132 is_https(is_https) {} | |
| 133 | |
| 134 QuicStreamFactory::IpAliasKey::~IpAliasKey() {} | |
| 135 | |
| 136 bool QuicStreamFactory::IpAliasKey::operator<( | |
| 137 const QuicStreamFactory::IpAliasKey& other) const { | |
| 138 if (!(ip_endpoint == other.ip_endpoint)) { | |
| 139 return ip_endpoint < other.ip_endpoint; | |
| 140 } | |
| 141 return is_https < other.is_https; | |
| 142 } | |
| 143 | |
| 144 bool QuicStreamFactory::IpAliasKey::operator==( | |
| 145 const QuicStreamFactory::IpAliasKey& other) const { | |
| 146 return is_https == other.is_https && | |
| 147 ip_endpoint == other.ip_endpoint; | |
| 148 }; | |
| 149 | |
| 150 // Responsible for creating a new QUIC session to the specified server, and | 127 // Responsible for creating a new QUIC session to the specified server, and |
| 151 // for notifying any associated requests when complete. | 128 // for notifying any associated requests when complete. |
| 152 class QuicStreamFactory::Job { | 129 class QuicStreamFactory::Job { |
| 153 public: | 130 public: |
| 154 Job(QuicStreamFactory* factory, | 131 Job(QuicStreamFactory* factory, |
| 155 HostResolver* host_resolver, | 132 HostResolver* host_resolver, |
| 156 const HostPortPair& host_port_pair, | 133 const HostPortPair& host_port_pair, |
| 157 bool server_and_origin_have_same_host, | 134 bool server_and_origin_have_same_host, |
| 158 bool is_https, | |
| 159 bool was_alternative_service_recently_broken, | 135 bool was_alternative_service_recently_broken, |
| 160 PrivacyMode privacy_mode, | 136 PrivacyMode privacy_mode, |
| 161 int cert_verify_flags, | 137 int cert_verify_flags, |
| 162 bool is_post, | 138 bool is_post, |
| 163 QuicServerInfo* server_info, | 139 QuicServerInfo* server_info, |
| 164 const BoundNetLog& net_log); | 140 const BoundNetLog& net_log); |
| 165 | 141 |
| 166 // Creates a new job to handle the resumption of for connecting an | 142 // Creates a new job to handle the resumption of for connecting an |
| 167 // existing session. | 143 // existing session. |
| 168 Job(QuicStreamFactory* factory, | 144 Job(QuicStreamFactory* factory, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 base::TimeTicks dns_resolution_start_time_; | 201 base::TimeTicks dns_resolution_start_time_; |
| 226 base::TimeTicks dns_resolution_end_time_; | 202 base::TimeTicks dns_resolution_end_time_; |
| 227 base::WeakPtrFactory<Job> weak_factory_; | 203 base::WeakPtrFactory<Job> weak_factory_; |
| 228 DISALLOW_COPY_AND_ASSIGN(Job); | 204 DISALLOW_COPY_AND_ASSIGN(Job); |
| 229 }; | 205 }; |
| 230 | 206 |
| 231 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 207 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
| 232 HostResolver* host_resolver, | 208 HostResolver* host_resolver, |
| 233 const HostPortPair& host_port_pair, | 209 const HostPortPair& host_port_pair, |
| 234 bool server_and_origin_have_same_host, | 210 bool server_and_origin_have_same_host, |
| 235 bool is_https, | |
| 236 bool was_alternative_service_recently_broken, | 211 bool was_alternative_service_recently_broken, |
| 237 PrivacyMode privacy_mode, | 212 PrivacyMode privacy_mode, |
| 238 int cert_verify_flags, | 213 int cert_verify_flags, |
| 239 bool is_post, | 214 bool is_post, |
| 240 QuicServerInfo* server_info, | 215 QuicServerInfo* server_info, |
| 241 const BoundNetLog& net_log) | 216 const BoundNetLog& net_log) |
| 242 : io_state_(STATE_RESOLVE_HOST), | 217 : io_state_(STATE_RESOLVE_HOST), |
| 243 factory_(factory), | 218 factory_(factory), |
| 244 host_resolver_(host_resolver), | 219 host_resolver_(host_resolver), |
| 245 server_id_(host_port_pair, is_https, privacy_mode), | 220 server_id_(host_port_pair, /*is_https=*/true, privacy_mode), |
| 246 cert_verify_flags_(cert_verify_flags), | 221 cert_verify_flags_(cert_verify_flags), |
| 247 server_and_origin_have_same_host_(server_and_origin_have_same_host), | 222 server_and_origin_have_same_host_(server_and_origin_have_same_host), |
| 248 is_post_(is_post), | 223 is_post_(is_post), |
| 249 was_alternative_service_recently_broken_( | 224 was_alternative_service_recently_broken_( |
| 250 was_alternative_service_recently_broken), | 225 was_alternative_service_recently_broken), |
| 251 server_info_(server_info), | 226 server_info_(server_info), |
| 252 started_another_job_(false), | 227 started_another_job_(false), |
| 253 net_log_(net_log), | 228 net_log_(net_log), |
| 254 session_(nullptr), | 229 session_(nullptr), |
| 255 weak_factory_(this) { | 230 weak_factory_(this) {} |
| 256 } | |
| 257 | 231 |
| 258 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 232 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
| 259 HostResolver* host_resolver, | 233 HostResolver* host_resolver, |
| 260 QuicChromiumClientSession* session, | 234 QuicChromiumClientSession* session, |
| 261 QuicServerId server_id) | 235 QuicServerId server_id) |
| 262 : io_state_(STATE_RESUME_CONNECT), | 236 : io_state_(STATE_RESUME_CONNECT), |
| 263 factory_(factory), | 237 factory_(factory), |
| 264 host_resolver_(host_resolver), // unused | 238 host_resolver_(host_resolver), // unused |
| 265 server_id_(server_id), | 239 server_id_(server_id), |
| 266 cert_verify_flags_(0), // unused | 240 cert_verify_flags_(0), // unused |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 483 |
| 510 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) | 484 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) |
| 511 : factory_(factory) {} | 485 : factory_(factory) {} |
| 512 | 486 |
| 513 QuicStreamRequest::~QuicStreamRequest() { | 487 QuicStreamRequest::~QuicStreamRequest() { |
| 514 if (factory_ && !callback_.is_null()) | 488 if (factory_ && !callback_.is_null()) |
| 515 factory_->CancelRequest(this); | 489 factory_->CancelRequest(this); |
| 516 } | 490 } |
| 517 | 491 |
| 518 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, | 492 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, |
| 519 bool is_https, | |
| 520 PrivacyMode privacy_mode, | 493 PrivacyMode privacy_mode, |
| 521 int cert_verify_flags, | 494 int cert_verify_flags, |
| 522 base::StringPiece origin_host, | 495 base::StringPiece origin_host, |
| 523 base::StringPiece method, | 496 base::StringPiece method, |
| 524 const BoundNetLog& net_log, | 497 const BoundNetLog& net_log, |
| 525 const CompletionCallback& callback) { | 498 const CompletionCallback& callback) { |
| 526 DCHECK(!stream_); | 499 DCHECK(!stream_); |
| 527 DCHECK(callback_.is_null()); | 500 DCHECK(callback_.is_null()); |
| 528 DCHECK(factory_); | 501 DCHECK(factory_); |
| 529 origin_host_ = origin_host.as_string(); | 502 origin_host_ = origin_host.as_string(); |
| 530 privacy_mode_ = privacy_mode; | 503 privacy_mode_ = privacy_mode; |
| 531 int rv = | 504 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, |
| 532 factory_->Create(host_port_pair, is_https, privacy_mode, | 505 origin_host, method, net_log, this); |
| 533 cert_verify_flags, origin_host, method, net_log, this); | |
| 534 if (rv == ERR_IO_PENDING) { | 506 if (rv == ERR_IO_PENDING) { |
| 535 host_port_pair_ = host_port_pair; | 507 host_port_pair_ = host_port_pair; |
| 536 is_https_ = is_https; | |
| 537 net_log_ = net_log; | 508 net_log_ = net_log; |
| 538 callback_ = callback; | 509 callback_ = callback; |
| 539 } else { | 510 } else { |
| 540 factory_ = nullptr; | 511 factory_ = nullptr; |
| 541 } | 512 } |
| 542 if (rv == OK) | 513 if (rv == OK) |
| 543 DCHECK(stream_); | 514 DCHECK(stream_); |
| 544 return rv; | 515 return rv; |
| 545 } | 516 } |
| 546 | 517 |
| 547 void QuicStreamRequest::set_stream(scoped_ptr<QuicHttpStream> stream) { | 518 void QuicStreamRequest::set_stream(scoped_ptr<QuicHttpStream> stream) { |
| 548 DCHECK(stream); | 519 DCHECK(stream); |
| 549 stream_ = stream.Pass(); | 520 stream_ = stream.Pass(); |
| 550 } | 521 } |
| 551 | 522 |
| 552 void QuicStreamRequest::OnRequestComplete(int rv) { | 523 void QuicStreamRequest::OnRequestComplete(int rv) { |
| 553 factory_ = nullptr; | 524 factory_ = nullptr; |
| 554 callback_.Run(rv); | 525 callback_.Run(rv); |
| 555 } | 526 } |
| 556 | 527 |
| 557 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { | 528 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { |
| 558 if (!factory_) | 529 if (!factory_) |
| 559 return base::TimeDelta(); | 530 return base::TimeDelta(); |
| 560 return factory_->GetTimeDelayForWaitingJob( | 531 return factory_->GetTimeDelayForWaitingJob( |
| 561 QuicServerId(host_port_pair_, is_https_, privacy_mode_)); | 532 QuicServerId(host_port_pair_, /*is_https=*/true, privacy_mode_)); |
| 562 } | 533 } |
| 563 | 534 |
| 564 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { | 535 scoped_ptr<QuicHttpStream> QuicStreamRequest::ReleaseStream() { |
| 565 DCHECK(stream_); | 536 DCHECK(stream_); |
| 566 return stream_.Pass(); | 537 return stream_.Pass(); |
| 567 } | 538 } |
| 568 | 539 |
| 569 QuicStreamFactory::QuicStreamFactory( | 540 QuicStreamFactory::QuicStreamFactory( |
| 570 HostResolver* host_resolver, | 541 HostResolver* host_resolver, |
| 571 ClientSocketFactory* client_socket_factory, | 542 ClientSocketFactory* client_socket_factory, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 srtt = kDefaultRTT; | 682 srtt = kDefaultRTT; |
| 712 return base::TimeDelta::FromMicroseconds(srtt); | 683 return base::TimeDelta::FromMicroseconds(srtt); |
| 713 } | 684 } |
| 714 | 685 |
| 715 void QuicStreamFactory::set_quic_server_info_factory( | 686 void QuicStreamFactory::set_quic_server_info_factory( |
| 716 QuicServerInfoFactory* quic_server_info_factory) { | 687 QuicServerInfoFactory* quic_server_info_factory) { |
| 717 quic_server_info_factory_.reset(quic_server_info_factory); | 688 quic_server_info_factory_.reset(quic_server_info_factory); |
| 718 } | 689 } |
| 719 | 690 |
| 720 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, | 691 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, |
| 721 bool is_https, | |
| 722 PrivacyMode privacy_mode, | 692 PrivacyMode privacy_mode, |
| 723 int cert_verify_flags, | 693 int cert_verify_flags, |
| 724 base::StringPiece origin_host, | 694 base::StringPiece origin_host, |
| 725 base::StringPiece method, | 695 base::StringPiece method, |
| 726 const BoundNetLog& net_log, | 696 const BoundNetLog& net_log, |
| 727 QuicStreamRequest* request) { | 697 QuicStreamRequest* request) { |
| 728 QuicServerId server_id(host_port_pair, is_https, privacy_mode); | 698 QuicServerId server_id(host_port_pair, /*is_https=*/true, privacy_mode); |
| 729 SessionMap::iterator it = active_sessions_.find(server_id); | 699 SessionMap::iterator it = active_sessions_.find(server_id); |
| 730 if (it != active_sessions_.end()) { | 700 if (it != active_sessions_.end()) { |
| 731 QuicChromiumClientSession* session = it->second; | 701 QuicChromiumClientSession* session = it->second; |
| 732 if (!session->CanPool(origin_host.as_string(), privacy_mode)) | 702 if (!session->CanPool(origin_host.as_string(), privacy_mode)) |
| 733 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 703 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
| 734 request->set_stream(CreateFromSession(session)); | 704 request->set_stream(CreateFromSession(session)); |
| 735 return OK; | 705 return OK; |
| 736 } | 706 } |
| 737 | 707 |
| 738 if (HasActiveJob(server_id)) { | 708 if (HasActiveJob(server_id)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 755 // If there is no entry for QUIC, consider that as a new server and | 725 // If there is no entry for QUIC, consider that as a new server and |
| 756 // don't wait for Cache thread to load the data for that server. | 726 // don't wait for Cache thread to load the data for that server. |
| 757 load_from_disk_cache = false; | 727 load_from_disk_cache = false; |
| 758 } | 728 } |
| 759 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { | 729 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { |
| 760 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 730 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 761 } | 731 } |
| 762 } | 732 } |
| 763 | 733 |
| 764 bool server_and_origin_have_same_host = host_port_pair.host() == origin_host; | 734 bool server_and_origin_have_same_host = host_port_pair.host() == origin_host; |
| 765 scoped_ptr<Job> job(new Job(this, host_resolver_, host_port_pair, | 735 scoped_ptr<Job> job(new Job( |
| 766 server_and_origin_have_same_host, is_https, | 736 this, host_resolver_, host_port_pair, server_and_origin_have_same_host, |
| 767 WasQuicRecentlyBroken(server_id), privacy_mode, | 737 WasQuicRecentlyBroken(server_id), privacy_mode, cert_verify_flags, |
| 768 cert_verify_flags, method == "POST" /* is_post */, | 738 method == "POST" /* is_post */, quic_server_info, net_log)); |
| 769 quic_server_info, net_log)); | |
| 770 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 739 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 771 base::Unretained(this), job.get())); | 740 base::Unretained(this), job.get())); |
| 772 if (rv == ERR_IO_PENDING) { | 741 if (rv == ERR_IO_PENDING) { |
| 773 active_requests_[request] = server_id; | 742 active_requests_[request] = server_id; |
| 774 job_requests_map_[server_id].insert(request); | 743 job_requests_map_[server_id].insert(request); |
| 775 active_jobs_[server_id].insert(job.release()); | 744 active_jobs_[server_id].insert(job.release()); |
| 776 return rv; | 745 return rv; |
| 777 } | 746 } |
| 778 if (rv == OK) { | 747 if (rv == OK) { |
| 779 it = active_sessions_.find(server_id); | 748 it = active_sessions_.find(server_id); |
| 780 DCHECK(it != active_sessions_.end()); | 749 DCHECK(it != active_sessions_.end()); |
| 781 QuicChromiumClientSession* session = it->second; | 750 QuicChromiumClientSession* session = it->second; |
| 782 if (!session->CanPool(origin_host.as_string(), privacy_mode)) | 751 if (!session->CanPool(origin_host.as_string(), privacy_mode)) |
| 783 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 752 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
| 784 request->set_stream(CreateFromSession(session)); | 753 request->set_stream(CreateFromSession(session)); |
| 785 } | 754 } |
| 786 return rv; | 755 return rv; |
| 787 } | 756 } |
| 788 | 757 |
| 789 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, | 758 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, |
| 790 int cert_verify_flags, | 759 int cert_verify_flags, |
| 791 bool server_and_origin_have_same_host, | 760 bool server_and_origin_have_same_host, |
| 792 bool is_post, | 761 bool is_post, |
| 793 const BoundNetLog& net_log) { | 762 const BoundNetLog& net_log) { |
| 794 Job* aux_job = | 763 Job* aux_job = new Job( |
| 795 new Job(this, host_resolver_, server_id.host_port_pair(), | 764 this, host_resolver_, server_id.host_port_pair(), |
| 796 server_and_origin_have_same_host, server_id.is_https(), | 765 server_and_origin_have_same_host, WasQuicRecentlyBroken(server_id), |
| 797 WasQuicRecentlyBroken(server_id), server_id.privacy_mode(), | 766 server_id.privacy_mode(), cert_verify_flags, is_post, nullptr, net_log); |
| 798 cert_verify_flags, is_post, nullptr, net_log); | |
| 799 active_jobs_[server_id].insert(aux_job); | 767 active_jobs_[server_id].insert(aux_job); |
| 800 task_runner_->PostTask(FROM_HERE, | 768 task_runner_->PostTask(FROM_HERE, |
| 801 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, | 769 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, |
| 802 aux_job->GetWeakPtr())); | 770 aux_job->GetWeakPtr())); |
| 803 } | 771 } |
| 804 | 772 |
| 805 bool QuicStreamFactory::OnResolution( | 773 bool QuicStreamFactory::OnResolution( |
| 806 const QuicServerId& server_id, | 774 const QuicServerId& server_id, |
| 807 const AddressList& address_list) { | 775 const AddressList& address_list) { |
| 808 DCHECK(!HasActiveSession(server_id)); | 776 DCHECK(!HasActiveSession(server_id)); |
| 809 if (disable_connection_pooling_) { | 777 if (disable_connection_pooling_) { |
| 810 return false; | 778 return false; |
| 811 } | 779 } |
| 812 for (const IPEndPoint& address : address_list) { | 780 for (const IPEndPoint& address : address_list) { |
| 813 const IpAliasKey ip_alias_key(address, server_id.is_https()); | 781 if (!ContainsKey(ip_aliases_, address)) |
| 814 if (!ContainsKey(ip_aliases_, ip_alias_key)) | |
| 815 continue; | 782 continue; |
| 816 | 783 |
| 817 const SessionSet& sessions = ip_aliases_[ip_alias_key]; | 784 const SessionSet& sessions = ip_aliases_[address]; |
| 818 for (QuicChromiumClientSession* session : sessions) { | 785 for (QuicChromiumClientSession* session : sessions) { |
| 819 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) | 786 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) |
| 820 continue; | 787 continue; |
| 821 active_sessions_[server_id] = session; | 788 active_sessions_[server_id] = session; |
| 822 session_aliases_[session].insert(server_id); | 789 session_aliases_[session].insert(server_id); |
| 823 return true; | 790 return true; |
| 824 } | 791 } |
| 825 } | 792 } |
| 826 return false; | 793 return false; |
| 827 } | 794 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 // port suggestions. | 953 // port suggestions. |
| 987 if (session->goaway_received()) { | 954 if (session->goaway_received()) { |
| 988 gone_away_aliases_.insert(*it); | 955 gone_away_aliases_.insert(*it); |
| 989 } | 956 } |
| 990 | 957 |
| 991 active_sessions_.erase(*it); | 958 active_sessions_.erase(*it); |
| 992 ProcessGoingAwaySession(session, *it, true); | 959 ProcessGoingAwaySession(session, *it, true); |
| 993 } | 960 } |
| 994 ProcessGoingAwaySession(session, all_sessions_[session], false); | 961 ProcessGoingAwaySession(session, all_sessions_[session], false); |
| 995 if (!aliases.empty()) { | 962 if (!aliases.empty()) { |
| 996 const IpAliasKey ip_alias_key(session->connection()->peer_address(), | 963 const IPEndPoint peer_address = session->connection()->peer_address(); |
| 997 aliases.begin()->is_https()); | 964 ip_aliases_[peer_address].erase(session); |
| 998 ip_aliases_[ip_alias_key].erase(session); | 965 if (ip_aliases_[peer_address].empty()) { |
| 999 if (ip_aliases_[ip_alias_key].empty()) { | 966 ip_aliases_.erase(peer_address); |
| 1000 ip_aliases_.erase(ip_alias_key); | |
| 1001 } | 967 } |
| 1002 } | 968 } |
| 1003 session_aliases_.erase(session); | 969 session_aliases_.erase(session); |
| 1004 } | 970 } |
| 1005 | 971 |
| 1006 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { | 972 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { |
| 1007 DCHECK(session); | 973 DCHECK(session); |
| 1008 uint16 port = session->server_id().port(); | 974 uint16 port = session->server_id().port(); |
| 1009 if (IsQuicDisabled(port)) | 975 if (IsQuicDisabled(port)) |
| 1010 return; | 976 return; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 ++it) { | 1042 ++it) { |
| 1077 DCHECK(active_sessions_.count(*it)); | 1043 DCHECK(active_sessions_.count(*it)); |
| 1078 DCHECK_EQ(session, active_sessions_[*it]); | 1044 DCHECK_EQ(session, active_sessions_[*it]); |
| 1079 active_sessions_.erase(*it); | 1045 active_sessions_.erase(*it); |
| 1080 } | 1046 } |
| 1081 | 1047 |
| 1082 if (aliases.empty()) { | 1048 if (aliases.empty()) { |
| 1083 return; | 1049 return; |
| 1084 } | 1050 } |
| 1085 | 1051 |
| 1086 const IpAliasKey ip_alias_key(session->connection()->peer_address(), | 1052 const IPEndPoint peer_address = session->connection()->peer_address(); |
| 1087 aliases.begin()->is_https()); | 1053 ip_aliases_[peer_address].erase(session); |
| 1088 ip_aliases_[ip_alias_key].erase(session); | 1054 if (ip_aliases_[peer_address].empty()) { |
| 1089 if (ip_aliases_[ip_alias_key].empty()) { | 1055 ip_aliases_.erase(peer_address); |
| 1090 ip_aliases_.erase(ip_alias_key); | |
| 1091 } | 1056 } |
| 1092 QuicServerId server_id = *aliases.begin(); | 1057 QuicServerId server_id = *aliases.begin(); |
| 1093 session_aliases_.erase(session); | 1058 session_aliases_.erase(session); |
| 1094 Job* job = new Job(this, host_resolver_, session, server_id); | 1059 Job* job = new Job(this, host_resolver_, session, server_id); |
| 1095 active_jobs_[server_id].insert(job); | 1060 active_jobs_[server_id].insert(job); |
| 1096 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 1061 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 1097 base::Unretained(this), job)); | 1062 base::Unretained(this), job)); |
| 1098 DCHECK_EQ(ERR_IO_PENDING, rv); | 1063 DCHECK_EQ(ERR_IO_PENDING, rv); |
| 1099 } | 1064 } |
| 1100 | 1065 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 DefaultPacketWriterFactory packet_writer_factory(socket.get()); | 1225 DefaultPacketWriterFactory packet_writer_factory(socket.get()); |
| 1261 | 1226 |
| 1262 if (!helper_.get()) { | 1227 if (!helper_.get()) { |
| 1263 helper_.reset( | 1228 helper_.reset( |
| 1264 new QuicConnectionHelper(base::ThreadTaskRunnerHandle::Get().get(), | 1229 new QuicConnectionHelper(base::ThreadTaskRunnerHandle::Get().get(), |
| 1265 clock_.get(), random_generator_)); | 1230 clock_.get(), random_generator_)); |
| 1266 } | 1231 } |
| 1267 | 1232 |
| 1268 QuicConnection* connection = new QuicConnection( | 1233 QuicConnection* connection = new QuicConnection( |
| 1269 connection_id, addr, helper_.get(), packet_writer_factory, | 1234 connection_id, addr, helper_.get(), packet_writer_factory, |
| 1270 true /* owns_writer */, Perspective::IS_CLIENT, server_id.is_https(), | 1235 true /* owns_writer */, Perspective::IS_CLIENT, /*is_https=*/true, |
| 1271 supported_versions_); | 1236 supported_versions_); |
| 1272 connection->SetMaxPacketLength(max_packet_length_); | 1237 connection->SetMaxPacketLength(max_packet_length_); |
| 1273 | 1238 |
| 1274 InitializeCachedStateInCryptoConfig(server_id, server_info); | 1239 InitializeCachedStateInCryptoConfig(server_id, server_info); |
| 1275 | 1240 |
| 1276 QuicConfig config = config_; | 1241 QuicConfig config = config_; |
| 1277 config.SetSocketReceiveBufferToSend(socket_receive_buffer_size_); | 1242 config.SetSocketReceiveBufferToSend(socket_receive_buffer_size_); |
| 1278 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); | 1243 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); |
| 1279 config.SetInitialSessionFlowControlWindowToSend( | 1244 config.SetInitialSessionFlowControlWindowToSend( |
| 1280 kQuicSessionMaxRecvWindowSize); | 1245 kQuicSessionMaxRecvWindowSize); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 } | 1288 } |
| 1324 return OK; | 1289 return OK; |
| 1325 } | 1290 } |
| 1326 | 1291 |
| 1327 void QuicStreamFactory::ActivateSession(const QuicServerId& server_id, | 1292 void QuicStreamFactory::ActivateSession(const QuicServerId& server_id, |
| 1328 QuicChromiumClientSession* session) { | 1293 QuicChromiumClientSession* session) { |
| 1329 DCHECK(!HasActiveSession(server_id)); | 1294 DCHECK(!HasActiveSession(server_id)); |
| 1330 UMA_HISTOGRAM_COUNTS("Net.QuicActiveSessions", active_sessions_.size()); | 1295 UMA_HISTOGRAM_COUNTS("Net.QuicActiveSessions", active_sessions_.size()); |
| 1331 active_sessions_[server_id] = session; | 1296 active_sessions_[server_id] = session; |
| 1332 session_aliases_[session].insert(server_id); | 1297 session_aliases_[session].insert(server_id); |
| 1333 const IpAliasKey ip_alias_key(session->connection()->peer_address(), | 1298 const IPEndPoint peer_address = session->connection()->peer_address(); |
| 1334 server_id.is_https()); | 1299 DCHECK(!ContainsKey(ip_aliases_[peer_address], session)); |
| 1335 DCHECK(!ContainsKey(ip_aliases_[ip_alias_key], session)); | 1300 ip_aliases_[peer_address].insert(session); |
| 1336 ip_aliases_[ip_alias_key].insert(session); | |
| 1337 } | 1301 } |
| 1338 | 1302 |
| 1339 int64 QuicStreamFactory::GetServerNetworkStatsSmoothedRttInMicroseconds( | 1303 int64 QuicStreamFactory::GetServerNetworkStatsSmoothedRttInMicroseconds( |
| 1340 const QuicServerId& server_id) const { | 1304 const QuicServerId& server_id) const { |
| 1341 const ServerNetworkStats* stats = | 1305 const ServerNetworkStats* stats = |
| 1342 http_server_properties_->GetServerNetworkStats( | 1306 http_server_properties_->GetServerNetworkStats( |
| 1343 server_id.host_port_pair()); | 1307 server_id.host_port_pair()); |
| 1344 if (stats == nullptr) | 1308 if (stats == nullptr) |
| 1345 return 0; | 1309 return 0; |
| 1346 return stats->srtt.InMicroseconds(); | 1310 return stats->srtt.InMicroseconds(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1376 | 1340 |
| 1377 // TODO(rtenneti): Delete the following histogram after collecting stats. | 1341 // TODO(rtenneti): Delete the following histogram after collecting stats. |
| 1378 // If the AlternativeServiceMap contained an entry for this host, check if | 1342 // If the AlternativeServiceMap contained an entry for this host, check if |
| 1379 // the disk cache contained an entry for it. | 1343 // the disk cache contained an entry for it. |
| 1380 if (ContainsKey(quic_supported_servers_at_startup_, | 1344 if (ContainsKey(quic_supported_servers_at_startup_, |
| 1381 server_id.host_port_pair())) { | 1345 server_id.host_port_pair())) { |
| 1382 UMA_HISTOGRAM_BOOLEAN("Net.QuicServerInfo.ExpectConfigMissingFromDiskCache", | 1346 UMA_HISTOGRAM_BOOLEAN("Net.QuicServerInfo.ExpectConfigMissingFromDiskCache", |
| 1383 server_info->state().server_config.empty()); | 1347 server_info->state().server_config.empty()); |
| 1384 } | 1348 } |
| 1385 | 1349 |
| 1386 if (!cached->Initialize(server_info->state().server_config, | 1350 cached->Initialize(server_info->state().server_config, |
| 1387 server_info->state().source_address_token, | 1351 server_info->state().source_address_token, |
| 1388 server_info->state().certs, | 1352 server_info->state().certs, |
| 1389 server_info->state().server_config_sig, | 1353 server_info->state().server_config_sig, clock_->WallNow()); |
| 1390 clock_->WallNow())) | |
| 1391 return; | |
| 1392 | |
| 1393 if (!server_id.is_https()) { | |
| 1394 // Don't check the certificates for insecure QUIC. | |
| 1395 cached->SetProofValid(); | |
| 1396 } | |
| 1397 } | 1354 } |
| 1398 | 1355 |
| 1399 void QuicStreamFactory::MaybeInitialize() { | 1356 void QuicStreamFactory::MaybeInitialize() { |
| 1400 // We don't initialize data from HttpServerProperties in the constructor | 1357 // We don't initialize data from HttpServerProperties in the constructor |
| 1401 // because HttpServerProperties has not yet initialized. We're guaranteed | 1358 // because HttpServerProperties has not yet initialized. We're guaranteed |
| 1402 // HttpServerProperties has been initialized by the first time a request is | 1359 // HttpServerProperties has been initialized by the first time a request is |
| 1403 // made. | 1360 // made. |
| 1404 if (has_initialized_data_) | 1361 if (has_initialized_data_) |
| 1405 return; | 1362 return; |
| 1406 | 1363 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 // Since the session was active, there's no longer an | 1426 // Since the session was active, there's no longer an |
| 1470 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1427 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
| 1471 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1428 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
| 1472 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1429 // it as recently broken, which means that 0-RTT will be disabled but we'll |
| 1473 // still race. | 1430 // still race. |
| 1474 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1431 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 1475 alternative_service); | 1432 alternative_service); |
| 1476 } | 1433 } |
| 1477 | 1434 |
| 1478 } // namespace net | 1435 } // namespace net |
| OLD | NEW |