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

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

Issue 2131813002: Revert of QUIC - Race Cert Verification with host resolution if certs are (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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_stream_factory.h ('k') | net/quic/quic_stream_factory_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) 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 <openssl/aead.h> 7 #include <openssl/aead.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <tuple> 10 #include <tuple>
(...skipping 16 matching lines...) Expand all
27 #include "crypto/openssl_util.h" 27 #include "crypto/openssl_util.h"
28 #include "net/base/ip_address.h" 28 #include "net/base/ip_address.h"
29 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
30 #include "net/cert/cert_verifier.h" 30 #include "net/cert/cert_verifier.h"
31 #include "net/cert/ct_verifier.h" 31 #include "net/cert/ct_verifier.h"
32 #include "net/dns/host_resolver.h" 32 #include "net/dns/host_resolver.h"
33 #include "net/dns/single_request_host_resolver.h" 33 #include "net/dns/single_request_host_resolver.h"
34 #include "net/http/bidirectional_stream_impl.h" 34 #include "net/http/bidirectional_stream_impl.h"
35 #include "net/quic/bidirectional_stream_quic_impl.h" 35 #include "net/quic/bidirectional_stream_quic_impl.h"
36 #include "net/quic/crypto/channel_id_chromium.h" 36 #include "net/quic/crypto/channel_id_chromium.h"
37 #include "net/quic/crypto/proof_verifier.h"
38 #include "net/quic/crypto/proof_verifier_chromium.h" 37 #include "net/quic/crypto/proof_verifier_chromium.h"
39 #include "net/quic/crypto/properties_based_quic_server_info.h" 38 #include "net/quic/crypto/properties_based_quic_server_info.h"
40 #include "net/quic/crypto/quic_random.h" 39 #include "net/quic/crypto/quic_random.h"
41 #include "net/quic/crypto/quic_server_info.h" 40 #include "net/quic/crypto/quic_server_info.h"
42 #include "net/quic/port_suggester.h" 41 #include "net/quic/port_suggester.h"
43 #include "net/quic/quic_chromium_alarm_factory.h" 42 #include "net/quic/quic_chromium_alarm_factory.h"
44 #include "net/quic/quic_chromium_connection_helper.h" 43 #include "net/quic/quic_chromium_connection_helper.h"
45 #include "net/quic/quic_chromium_packet_reader.h" 44 #include "net/quic/quic_chromium_packet_reader.h"
46 #include "net/quic/quic_chromium_packet_writer.h" 45 #include "net/quic/quic_chromium_packet_writer.h"
47 #include "net/quic/quic_client_promised_info.h" 46 #include "net/quic/quic_client_promised_info.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 QuicConfig config; 160 QuicConfig config;
162 config.SetIdleConnectionStateLifetime( 161 config.SetIdleConnectionStateLifetime(
163 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds), 162 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds),
164 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds)); 163 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds));
165 config.SetConnectionOptionsToSend(connection_options); 164 config.SetConnectionOptionsToSend(connection_options);
166 return config; 165 return config;
167 } 166 }
168 167
169 } // namespace 168 } // namespace
170 169
171 // Responsible for verifying the certificates saved in
172 // QuicCryptoClientConfig, and for notifying any associated requests when
173 // complete. Results from cert verification are ignored.
174 class QuicStreamFactory::CertVerifierJob {
175 public:
176 // ProofVerifierCallbackImpl is passed as the callback method to
177 // VerifyCertChain. The ProofVerifier calls this class with the result of cert
178 // verification when verification is performed asynchronously.
179 class ProofVerifierCallbackImpl : public ProofVerifierCallback {
180 public:
181 explicit ProofVerifierCallbackImpl(CertVerifierJob* job) : job_(job) {}
182
183 ~ProofVerifierCallbackImpl() override {}
184
185 void Run(bool ok,
186 const std::string& error_details,
187 std::unique_ptr<ProofVerifyDetails>* details) override {
188 if (job_ == nullptr)
189 return;
190 job_->verify_callback_ = nullptr;
191 job_->OnComplete();
192 }
193
194 void Cancel() { job_ = nullptr; }
195
196 private:
197 CertVerifierJob* job_;
198 };
199
200 CertVerifierJob(const QuicServerId& server_id,
201 int cert_verify_flags,
202 const BoundNetLog& net_log)
203 : server_id_(server_id),
204 verify_callback_(nullptr),
205 verify_context_(base::WrapUnique(
206 new ProofVerifyContextChromium(cert_verify_flags, net_log))),
207 net_log_(net_log),
208 weak_factory_(this) {}
209
210 ~CertVerifierJob() {
211 if (verify_callback_)
212 verify_callback_->Cancel();
213 }
214
215 // Starts verification of certs cached in the |crypto_config|.
216 QuicAsyncStatus Run(QuicCryptoClientConfig* crypto_config,
217 const CompletionCallback& callback) {
218 QuicCryptoClientConfig::CachedState* cached =
219 crypto_config->LookupOrCreate(server_id_);
220 ProofVerifierCallbackImpl* verify_callback =
221 new ProofVerifierCallbackImpl(this);
222 QuicAsyncStatus status = crypto_config->proof_verifier()->VerifyCertChain(
223 server_id_.host(), cached->certs(), verify_context_.get(),
224 &verify_error_details_, &verify_details_, verify_callback);
225 if (status == QUIC_PENDING) {
226 verify_callback_ = verify_callback;
227 callback_ = callback;
228 } else {
229 delete verify_callback;
230 }
231 return status;
232 }
233
234 void OnComplete() {
235 if (!callback_.is_null())
236 callback_.Run(OK);
237 }
238
239 const QuicServerId& server_id() const { return server_id_; }
240
241 private:
242 QuicServerId server_id_;
243 ProofVerifierCallbackImpl* verify_callback_;
244 std::unique_ptr<ProofVerifyContext> verify_context_;
245 std::unique_ptr<ProofVerifyDetails> verify_details_;
246 std::string verify_error_details_;
247 const BoundNetLog net_log_;
248 CompletionCallback callback_;
249 base::WeakPtrFactory<CertVerifierJob> weak_factory_;
250
251 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob);
252 };
253
254 // Responsible for creating a new QUIC session to the specified server, and 170 // Responsible for creating a new QUIC session to the specified server, and
255 // for notifying any associated requests when complete. 171 // for notifying any associated requests when complete.
256 class QuicStreamFactory::Job { 172 class QuicStreamFactory::Job {
257 public: 173 public:
258 Job(QuicStreamFactory* factory, 174 Job(QuicStreamFactory* factory,
259 HostResolver* host_resolver, 175 HostResolver* host_resolver,
260 const QuicSessionKey& key, 176 const QuicSessionKey& key,
261 bool was_alternative_service_recently_broken, 177 bool was_alternative_service_recently_broken,
262 int cert_verify_flags, 178 int cert_verify_flags,
263 QuicServerInfo* server_info, 179 QuicServerInfo* server_info,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { 357 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() {
442 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. 358 // If we are waiting for WaitForDataReadyCallback, then cancel the callback.
443 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) 359 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE)
444 return; 360 return;
445 server_info_->CancelWaitForDataReadyCallback(); 361 server_info_->CancelWaitForDataReadyCallback();
446 OnIOComplete(OK); 362 OnIOComplete(OK);
447 } 363 }
448 364
449 int QuicStreamFactory::Job::DoResolveHost() { 365 int QuicStreamFactory::Job::DoResolveHost() {
450 // Start loading the data now, and wait for it after we resolve the host. 366 // Start loading the data now, and wait for it after we resolve the host.
451 if (server_info_) 367 if (server_info_) {
452 server_info_->Start(); 368 server_info_->Start();
369 }
453 370
454 io_state_ = STATE_RESOLVE_HOST_COMPLETE; 371 io_state_ = STATE_RESOLVE_HOST_COMPLETE;
455 dns_resolution_start_time_ = base::TimeTicks::Now(); 372 dns_resolution_start_time_ = base::TimeTicks::Now();
456 return host_resolver_.Resolve( 373 return host_resolver_.Resolve(
457 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, 374 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY,
458 &address_list_, 375 &address_list_,
459 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), 376 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()),
460 net_log_); 377 net_log_);
461 } 378 }
462 379
463 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { 380 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) {
464 dns_resolution_end_time_ = base::TimeTicks::Now(); 381 dns_resolution_end_time_ = base::TimeTicks::Now();
465 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime", 382 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime",
466 dns_resolution_end_time_ - dns_resolution_start_time_); 383 dns_resolution_end_time_ - dns_resolution_start_time_);
467 if (rv != OK) 384 if (rv != OK)
468 return rv; 385 return rv;
469 386
470 DCHECK(!factory_->HasActiveSession(key_.server_id())); 387 DCHECK(!factory_->HasActiveSession(key_.server_id()));
471 388
472 // Inform the factory of this resolution, which will set up 389 // Inform the factory of this resolution, which will set up
473 // a session alias, if possible. 390 // a session alias, if possible.
474 if (factory_->OnResolution(key_, address_list_)) 391 if (factory_->OnResolution(key_, address_list_)) {
475 return OK; 392 return OK;
393 }
476 394
477 if (server_info_) 395 if (server_info_)
478 io_state_ = STATE_LOAD_SERVER_INFO; 396 io_state_ = STATE_LOAD_SERVER_INFO;
479 else 397 else
480 io_state_ = STATE_CONNECT; 398 io_state_ = STATE_CONNECT;
481 return OK; 399 return OK;
482 } 400 }
483 401
484 int QuicStreamFactory::Job::DoLoadServerInfo() { 402 int QuicStreamFactory::Job::DoLoadServerInfo() {
485 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; 403 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 462
545 int rv = factory_->CreateSession( 463 int rv = factory_->CreateSession(
546 key_, cert_verify_flags_, std::move(server_info_), address_list_, 464 key_, cert_verify_flags_, std::move(server_info_), address_list_,
547 dns_resolution_end_time_, net_log_, &session_); 465 dns_resolution_end_time_, net_log_, &session_);
548 if (rv != OK) { 466 if (rv != OK) {
549 DCHECK(rv != ERR_IO_PENDING); 467 DCHECK(rv != ERR_IO_PENDING);
550 DCHECK(!session_); 468 DCHECK(!session_);
551 return rv; 469 return rv;
552 } 470 }
553 471
554 if (!session_->connection()->connected()) 472 if (!session_->connection()->connected()) {
555 return ERR_CONNECTION_CLOSED; 473 return ERR_CONNECTION_CLOSED;
474 }
556 475
557 session_->StartReading(); 476 session_->StartReading();
558 if (!session_->connection()->connected()) 477 if (!session_->connection()->connected()) {
559 return ERR_QUIC_PROTOCOL_ERROR; 478 return ERR_QUIC_PROTOCOL_ERROR;
479 }
560 bool require_confirmation = factory_->require_confirmation() || 480 bool require_confirmation = factory_->require_confirmation() ||
561 was_alternative_service_recently_broken_; 481 was_alternative_service_recently_broken_;
562 482
563 rv = session_->CryptoConnect( 483 rv = session_->CryptoConnect(
564 require_confirmation, 484 require_confirmation,
565 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 485 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
566 486
567 if (!session_->connection()->connected() && 487 if (!session_->connection()->connected() &&
568 session_->error() == QUIC_PROOF_INVALID) { 488 session_->error() == QUIC_PROOF_INVALID)
569 return ERR_QUIC_HANDSHAKE_FAILED; 489 return ERR_QUIC_HANDSHAKE_FAILED;
570 }
571 490
572 return rv; 491 return rv;
573 } 492 }
574 493
575 int QuicStreamFactory::Job::DoResumeConnect() { 494 int QuicStreamFactory::Job::DoResumeConnect() {
576 io_state_ = STATE_CONNECT_COMPLETE; 495 io_state_ = STATE_CONNECT_COMPLETE;
577 496
578 int rv = session_->ResumeCryptoConnect( 497 int rv = session_->ResumeCryptoConnect(
579 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 498 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
580 499
581 return rv; 500 return rv;
582 } 501 }
583 502
584 int QuicStreamFactory::Job::DoConnectComplete(int rv) { 503 int QuicStreamFactory::Job::DoConnectComplete(int rv) {
585 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { 504 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) {
586 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); 505 num_sent_client_hellos_ += session_->GetNumSentClientHellos();
587 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) 506 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) {
588 return ERR_QUIC_HANDSHAKE_FAILED; 507 return ERR_QUIC_HANDSHAKE_FAILED;
508 }
589 // The handshake was rejected statelessly, so create another connection 509 // The handshake was rejected statelessly, so create another connection
590 // to resume the handshake. 510 // to resume the handshake.
591 io_state_ = STATE_CONNECT; 511 io_state_ = STATE_CONNECT;
592 return OK; 512 return OK;
593 } 513 }
594 514
595 if (rv != OK) 515 if (rv != OK)
596 return rv; 516 return rv;
597 517
598 DCHECK(!factory_->HasActiveSession(key_.server_id())); 518 DCHECK(!factory_->HasActiveSession(key_.server_id()));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 int threshold_public_resets_post_handshake, 625 int threshold_public_resets_post_handshake,
706 int threshold_timeouts_with_open_streams, 626 int threshold_timeouts_with_open_streams,
707 int socket_receive_buffer_size, 627 int socket_receive_buffer_size,
708 bool delay_tcp_race, 628 bool delay_tcp_race,
709 int max_server_configs_stored_in_properties, 629 int max_server_configs_stored_in_properties,
710 bool close_sessions_on_ip_change, 630 bool close_sessions_on_ip_change,
711 bool disable_quic_on_timeout_with_open_streams, 631 bool disable_quic_on_timeout_with_open_streams,
712 int idle_connection_timeout_seconds, 632 int idle_connection_timeout_seconds,
713 bool migrate_sessions_on_network_change, 633 bool migrate_sessions_on_network_change,
714 bool migrate_sessions_early, 634 bool migrate_sessions_early,
715 bool race_cert_verification,
716 const QuicTagVector& connection_options, 635 const QuicTagVector& connection_options,
717 bool enable_token_binding) 636 bool enable_token_binding)
718 : require_confirmation_(true), 637 : require_confirmation_(true),
719 net_log_(net_log), 638 net_log_(net_log),
720 host_resolver_(host_resolver), 639 host_resolver_(host_resolver),
721 client_socket_factory_(client_socket_factory), 640 client_socket_factory_(client_socket_factory),
722 http_server_properties_(http_server_properties), 641 http_server_properties_(http_server_properties),
723 transport_security_state_(transport_security_state), 642 transport_security_state_(transport_security_state),
724 cert_transparency_verifier_(cert_transparency_verifier), 643 cert_transparency_verifier_(cert_transparency_verifier),
725 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), 644 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 delay_tcp_race_(delay_tcp_race), 678 delay_tcp_race_(delay_tcp_race),
760 yield_after_packets_(kQuicYieldAfterPacketsRead), 679 yield_after_packets_(kQuicYieldAfterPacketsRead),
761 yield_after_duration_(QuicTime::Delta::FromMilliseconds( 680 yield_after_duration_(QuicTime::Delta::FromMilliseconds(
762 kQuicYieldAfterDurationMilliseconds)), 681 kQuicYieldAfterDurationMilliseconds)),
763 close_sessions_on_ip_change_(close_sessions_on_ip_change), 682 close_sessions_on_ip_change_(close_sessions_on_ip_change),
764 migrate_sessions_on_network_change_( 683 migrate_sessions_on_network_change_(
765 migrate_sessions_on_network_change && 684 migrate_sessions_on_network_change &&
766 NetworkChangeNotifier::AreNetworkHandlesSupported()), 685 NetworkChangeNotifier::AreNetworkHandlesSupported()),
767 migrate_sessions_early_(migrate_sessions_early && 686 migrate_sessions_early_(migrate_sessions_early &&
768 migrate_sessions_on_network_change_), 687 migrate_sessions_on_network_change_),
769 race_cert_verification_(race_cert_verification),
770 port_seed_(random_generator_->RandUint64()), 688 port_seed_(random_generator_->RandUint64()),
771 check_persisted_supports_quic_(true), 689 check_persisted_supports_quic_(true),
772 has_initialized_data_(false), 690 has_initialized_data_(false),
773 num_push_streams_created_(0), 691 num_push_streams_created_(0),
774 status_(OPEN), 692 status_(OPEN),
775 task_runner_(nullptr), 693 task_runner_(nullptr),
776 ssl_config_service_(ssl_config_service), 694 ssl_config_service_(ssl_config_service),
777 weak_factory_(this) { 695 weak_factory_(this) {
778 if (ssl_config_service_.get()) 696 if (ssl_config_service_.get())
779 ssl_config_service_->AddObserver(this); 697 ssl_config_service_->AddObserver(this);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); 745 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED);
828 while (!all_sessions_.empty()) { 746 while (!all_sessions_.empty()) {
829 delete all_sessions_.begin()->first; 747 delete all_sessions_.begin()->first;
830 all_sessions_.erase(all_sessions_.begin()); 748 all_sessions_.erase(all_sessions_.begin());
831 } 749 }
832 while (!active_jobs_.empty()) { 750 while (!active_jobs_.empty()) {
833 const QuicServerId server_id = active_jobs_.begin()->first; 751 const QuicServerId server_id = active_jobs_.begin()->first;
834 STLDeleteElements(&(active_jobs_[server_id])); 752 STLDeleteElements(&(active_jobs_[server_id]));
835 active_jobs_.erase(server_id); 753 active_jobs_.erase(server_id);
836 } 754 }
837 while (!active_cert_verifier_jobs_.empty())
838 active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin());
839 if (ssl_config_service_.get()) 755 if (ssl_config_service_.get())
840 ssl_config_service_->RemoveObserver(this); 756 ssl_config_service_->RemoveObserver(this);
841 if (migrate_sessions_on_network_change_) { 757 if (migrate_sessions_on_network_change_) {
842 NetworkChangeNotifier::RemoveNetworkObserver(this); 758 NetworkChangeNotifier::RemoveNetworkObserver(this);
843 } else if (close_sessions_on_ip_change_) { 759 } else if (close_sessions_on_ip_change_) {
844 NetworkChangeNotifier::RemoveIPAddressObserver(this); 760 NetworkChangeNotifier::RemoveIPAddressObserver(this);
845 } 761 }
846 } 762 }
847 763
848 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { 764 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 876
961 QuicServerInfo* quic_server_info = nullptr; 877 QuicServerInfo* quic_server_info = nullptr;
962 if (quic_server_info_factory_.get()) { 878 if (quic_server_info_factory_.get()) {
963 bool load_from_disk_cache = !disable_disk_cache_; 879 bool load_from_disk_cache = !disable_disk_cache_;
964 MaybeInitialize(); 880 MaybeInitialize();
965 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) { 881 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) {
966 // If there is no entry for QUIC, consider that as a new server and 882 // If there is no entry for QUIC, consider that as a new server and
967 // don't wait for Cache thread to load the data for that server. 883 // don't wait for Cache thread to load the data for that server.
968 load_from_disk_cache = false; 884 load_from_disk_cache = false;
969 } 885 }
970 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) 886 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) {
971 quic_server_info = quic_server_info_factory_->GetForServer(server_id); 887 quic_server_info = quic_server_info_factory_->GetForServer(server_id);
888 }
972 } 889 }
973 890
974 StartCertVerifyJob(server_id, cert_verify_flags, net_log);
975
976 QuicSessionKey key(destination, server_id); 891 QuicSessionKey key(destination, server_id);
977 std::unique_ptr<Job> job( 892 std::unique_ptr<Job> job(
978 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), 893 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id),
979 cert_verify_flags, quic_server_info, net_log)); 894 cert_verify_flags, quic_server_info, net_log));
980 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 895 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
981 base::Unretained(this), job.get())); 896 base::Unretained(this), job.get()));
982 if (rv == ERR_IO_PENDING) { 897 if (rv == ERR_IO_PENDING) {
983 active_requests_[request] = server_id; 898 active_requests_[request] = server_id;
984 job_requests_map_[server_id].insert(request); 899 job_requests_map_[server_id].insert(request);
985 active_jobs_[server_id].insert(job.release()); 900 active_jobs_[server_id].insert(job.release());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 active_jobs_[key.server_id()].insert(aux_job); 941 active_jobs_[key.server_id()].insert(aux_job);
1027 task_runner_->PostTask(FROM_HERE, 942 task_runner_->PostTask(FROM_HERE,
1028 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, 943 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob,
1029 aux_job->GetWeakPtr())); 944 aux_job->GetWeakPtr()));
1030 } 945 }
1031 946
1032 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, 947 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key,
1033 const AddressList& address_list) { 948 const AddressList& address_list) {
1034 const QuicServerId& server_id(key.server_id()); 949 const QuicServerId& server_id(key.server_id());
1035 DCHECK(!HasActiveSession(server_id)); 950 DCHECK(!HasActiveSession(server_id));
1036 if (disable_connection_pooling_) 951 if (disable_connection_pooling_) {
1037 return false; 952 return false;
953 }
1038 for (const IPEndPoint& address : address_list) { 954 for (const IPEndPoint& address : address_list) {
1039 if (!ContainsKey(ip_aliases_, address)) 955 if (!ContainsKey(ip_aliases_, address))
1040 continue; 956 continue;
1041 957
1042 const SessionSet& sessions = ip_aliases_[address]; 958 const SessionSet& sessions = ip_aliases_[address];
1043 for (QuicChromiumClientSession* session : sessions) { 959 for (QuicChromiumClientSession* session : sessions) {
1044 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) 960 if (!session->CanPool(server_id.host(), server_id.privacy_mode()))
1045 continue; 961 continue;
1046 active_sessions_[server_id] = session; 962 active_sessions_[server_id] = session;
1047 session_aliases_[session].insert(key); 963 session_aliases_[session].insert(key);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 for (Job* other_job : active_jobs_[server_id]) { 1013 for (Job* other_job : active_jobs_[server_id]) {
1098 if (other_job != job) 1014 if (other_job != job)
1099 other_job->Cancel(); 1015 other_job->Cancel();
1100 } 1016 }
1101 1017
1102 STLDeleteElements(&(active_jobs_[server_id])); 1018 STLDeleteElements(&(active_jobs_[server_id]));
1103 active_jobs_.erase(server_id); 1019 active_jobs_.erase(server_id);
1104 job_requests_map_.erase(server_id); 1020 job_requests_map_.erase(server_id);
1105 } 1021 }
1106 1022
1107 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) {
1108 active_cert_verifier_jobs_.erase(job->server_id());
1109 }
1110
1111 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( 1023 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession(
1112 QuicChromiumClientSession* session) { 1024 QuicChromiumClientSession* session) {
1113 return std::unique_ptr<QuicHttpStream>( 1025 return std::unique_ptr<QuicHttpStream>(
1114 new QuicHttpStream(session->GetWeakPtr())); 1026 new QuicHttpStream(session->GetWeakPtr()));
1115 } 1027 }
1116 1028
1117 QuicChromiumClientSession::QuicDisabledReason 1029 QuicChromiumClientSession::QuicDisabledReason
1118 QuicStreamFactory::QuicDisabledReason(uint16_t port) const { 1030 QuicStreamFactory::QuicDisabledReason(uint16_t port) const {
1119 if (max_number_of_lossy_connections_ > 0 && 1031 if (max_number_of_lossy_connections_ > 0 &&
1120 number_of_lossy_connections_.find(port) != 1032 number_of_lossy_connections_.find(port) !=
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 1128
1217 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { 1129 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) {
1218 const AliasSet& aliases = session_aliases_[session]; 1130 const AliasSet& aliases = session_aliases_[session];
1219 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); 1131 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end();
1220 ++it) { 1132 ++it) {
1221 const QuicServerId& server_id = it->server_id(); 1133 const QuicServerId& server_id = it->server_id();
1222 DCHECK(active_sessions_.count(server_id)); 1134 DCHECK(active_sessions_.count(server_id));
1223 DCHECK_EQ(session, active_sessions_[server_id]); 1135 DCHECK_EQ(session, active_sessions_[server_id]);
1224 // Track sessions which have recently gone away so that we can disable 1136 // Track sessions which have recently gone away so that we can disable
1225 // port suggestions. 1137 // port suggestions.
1226 if (session->goaway_received()) 1138 if (session->goaway_received()) {
1227 gone_away_aliases_.insert(*it); 1139 gone_away_aliases_.insert(*it);
1140 }
1228 1141
1229 active_sessions_.erase(server_id); 1142 active_sessions_.erase(server_id);
1230 ProcessGoingAwaySession(session, server_id, true); 1143 ProcessGoingAwaySession(session, server_id, true);
1231 } 1144 }
1232 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false); 1145 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false);
1233 if (!aliases.empty()) { 1146 if (!aliases.empty()) {
1234 const IPEndPoint peer_address = session->connection()->peer_address(); 1147 const IPEndPoint peer_address = session->connection()->peer_address();
1235 ip_aliases_[peer_address].erase(session); 1148 ip_aliases_[peer_address].erase(session);
1236 if (ip_aliases_[peer_address].empty()) 1149 if (ip_aliases_[peer_address].empty()) {
1237 ip_aliases_.erase(peer_address); 1150 ip_aliases_.erase(peer_address);
1151 }
1238 } 1152 }
1239 session_aliases_.erase(session); 1153 session_aliases_.erase(session);
1240 } 1154 }
1241 1155
1242 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { 1156 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) {
1243 DCHECK(session); 1157 DCHECK(session);
1244 uint16_t port = session->server_id().port(); 1158 uint16_t port = session->server_id().port();
1245 if (IsQuicDisabled(port)) 1159 if (IsQuicDisabled(port))
1246 return; 1160 return;
1247 1161
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 MaybeDisableQuic(session); 1246 MaybeDisableQuic(session);
1333 OnSessionGoingAway(session); 1247 OnSessionGoingAway(session);
1334 delete session; 1248 delete session;
1335 all_sessions_.erase(session); 1249 all_sessions_.erase(session);
1336 } 1250 }
1337 1251
1338 void QuicStreamFactory::OnSessionConnectTimeout( 1252 void QuicStreamFactory::OnSessionConnectTimeout(
1339 QuicChromiumClientSession* session) { 1253 QuicChromiumClientSession* session) {
1340 const AliasSet& aliases = session_aliases_[session]; 1254 const AliasSet& aliases = session_aliases_[session];
1341 1255
1342 if (aliases.empty()) 1256 if (aliases.empty()) {
1343 return; 1257 return;
1258 }
1344 1259
1345 for (const QuicSessionKey& key : aliases) { 1260 for (const QuicSessionKey& key : aliases) {
1346 const QuicServerId& server_id = key.server_id(); 1261 const QuicServerId& server_id = key.server_id();
1347 SessionMap::iterator session_it = active_sessions_.find(server_id); 1262 SessionMap::iterator session_it = active_sessions_.find(server_id);
1348 DCHECK(session_it != active_sessions_.end()); 1263 DCHECK(session_it != active_sessions_.end());
1349 DCHECK_EQ(session, session_it->second); 1264 DCHECK_EQ(session, session_it->second);
1350 active_sessions_.erase(session_it); 1265 active_sessions_.erase(session_it);
1351 } 1266 }
1352 1267
1353 const IPEndPoint peer_address = session->connection()->peer_address(); 1268 const IPEndPoint peer_address = session->connection()->peer_address();
1354 ip_aliases_[peer_address].erase(session); 1269 ip_aliases_[peer_address].erase(session);
1355 if (ip_aliases_[peer_address].empty()) 1270 if (ip_aliases_[peer_address].empty()) {
1356 ip_aliases_.erase(peer_address); 1271 ip_aliases_.erase(peer_address);
1272 }
1357 QuicSessionKey key = *aliases.begin(); 1273 QuicSessionKey key = *aliases.begin();
1358 session_aliases_.erase(session); 1274 session_aliases_.erase(session);
1359 Job* job = new Job(this, host_resolver_, session, key); 1275 Job* job = new Job(this, host_resolver_, session, key);
1360 active_jobs_[key.server_id()].insert(job); 1276 active_jobs_[key.server_id()].insert(job);
1361 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 1277 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
1362 base::Unretained(this), job)); 1278 base::Unretained(this), job));
1363 DCHECK_EQ(ERR_IO_PENDING, rv); 1279 DCHECK_EQ(ERR_IO_PENDING, rv);
1364 } 1280 }
1365 1281
1366 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { 1282 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, 1358 MaybeMigrateOrCloseSessions(network, /*force_close=*/false,
1443 scoped_event_log.net_log()); 1359 scoped_event_log.net_log());
1444 } 1360 }
1445 1361
1446 NetworkHandle QuicStreamFactory::FindAlternateNetwork( 1362 NetworkHandle QuicStreamFactory::FindAlternateNetwork(
1447 NetworkHandle old_network) { 1363 NetworkHandle old_network) {
1448 // Find a new network that sessions bound to |old_network| can be migrated to. 1364 // Find a new network that sessions bound to |old_network| can be migrated to.
1449 NetworkChangeNotifier::NetworkList network_list; 1365 NetworkChangeNotifier::NetworkList network_list;
1450 NetworkChangeNotifier::GetConnectedNetworks(&network_list); 1366 NetworkChangeNotifier::GetConnectedNetworks(&network_list);
1451 for (NetworkHandle new_network : network_list) { 1367 for (NetworkHandle new_network : network_list) {
1452 if (new_network != old_network) 1368 if (new_network != old_network) {
1453 return new_network; 1369 return new_network;
1370 }
1454 } 1371 }
1455 return NetworkChangeNotifier::kInvalidNetworkHandle; 1372 return NetworkChangeNotifier::kInvalidNetworkHandle;
1456 } 1373 }
1457 1374
1458 void QuicStreamFactory::MaybeMigrateOrCloseSessions( 1375 void QuicStreamFactory::MaybeMigrateOrCloseSessions(
1459 NetworkHandle network, 1376 NetworkHandle network,
1460 bool force_close, 1377 bool force_close,
1461 const BoundNetLog& bound_net_log) { 1378 const BoundNetLog& bound_net_log) {
1462 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); 1379 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network);
1463 NetworkHandle new_network = FindAlternateNetwork(network); 1380 NetworkHandle new_network = FindAlternateNetwork(network);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. 1541 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check.
1625 if (active_sessions_.empty()) 1542 if (active_sessions_.empty())
1626 return false; 1543 return false;
1627 return ContainsKey(active_sessions_, server_id); 1544 return ContainsKey(active_sessions_, server_id);
1628 } 1545 }
1629 1546
1630 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { 1547 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const {
1631 return ContainsKey(active_jobs_, server_id); 1548 return ContainsKey(active_jobs_, server_id);
1632 } 1549 }
1633 1550
1634 bool QuicStreamFactory::HasActiveCertVerifierJob(
1635 const QuicServerId& server_id) const {
1636 return ContainsKey(active_cert_verifier_jobs_, server_id);
1637 }
1638
1639 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, 1551 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket,
1640 IPEndPoint addr, 1552 IPEndPoint addr,
1641 NetworkHandle network) { 1553 NetworkHandle network) {
1642 if (enable_non_blocking_io_ && 1554 if (enable_non_blocking_io_ &&
1643 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { 1555 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) {
1644 #if defined(OS_WIN) 1556 #if defined(OS_WIN)
1645 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); 1557 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO();
1646 #endif 1558 #endif
1647 } 1559 }
1648 1560
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. 1629 DatagramSocket::DEFAULT_BIND; // Use OS to randomize.
1718 1630
1719 std::unique_ptr<DatagramClientSocket> socket( 1631 std::unique_ptr<DatagramClientSocket> socket(
1720 client_socket_factory_->CreateDatagramClientSocket( 1632 client_socket_factory_->CreateDatagramClientSocket(
1721 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), 1633 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester),
1722 net_log.net_log(), net_log.source())); 1634 net_log.net_log(), net_log.source()));
1723 1635
1724 // Passing in kInvalidNetworkHandle binds socket to default network. 1636 // Passing in kInvalidNetworkHandle binds socket to default network.
1725 int rv = ConfigureSocket(socket.get(), addr, 1637 int rv = ConfigureSocket(socket.get(), addr,
1726 NetworkChangeNotifier::kInvalidNetworkHandle); 1638 NetworkChangeNotifier::kInvalidNetworkHandle);
1727 if (rv != OK) 1639 if (rv != OK) {
1728 return rv; 1640 return rv;
1641 }
1729 1642
1730 if (enable_port_selection) 1643 if (enable_port_selection) {
1731 DCHECK_LE(1u, port_suggester->call_count()); 1644 DCHECK_LE(1u, port_suggester->call_count());
1732 else 1645 } else {
1733 DCHECK_EQ(0u, port_suggester->call_count()); 1646 DCHECK_EQ(0u, port_suggester->call_count());
1647 }
1734 1648
1735 if (!helper_.get()) { 1649 if (!helper_.get()) {
1736 helper_.reset( 1650 helper_.reset(
1737 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); 1651 new QuicChromiumConnectionHelper(clock_.get(), random_generator_));
1738 } 1652 }
1739 1653
1740 if (!alarm_factory_.get()) { 1654 if (!alarm_factory_.get()) {
1741 alarm_factory_.reset(new QuicChromiumAlarmFactory( 1655 alarm_factory_.reset(new QuicChromiumAlarmFactory(
1742 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); 1656 base::ThreadTaskRunnerHandle::Get().get(), clock_.get()));
1743 } 1657 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 alternative_service); 1748 alternative_service);
1835 } 1749 }
1836 1750
1837 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( 1751 bool QuicStreamFactory::CryptoConfigCacheIsEmpty(
1838 const QuicServerId& server_id) { 1752 const QuicServerId& server_id) {
1839 QuicCryptoClientConfig::CachedState* cached = 1753 QuicCryptoClientConfig::CachedState* cached =
1840 crypto_config_.LookupOrCreate(server_id); 1754 crypto_config_.LookupOrCreate(server_id);
1841 return cached->IsEmpty(); 1755 return cached->IsEmpty();
1842 } 1756 }
1843 1757
1844 void QuicStreamFactory::StartCertVerifyJob(const QuicServerId& server_id,
1845 int cert_verify_flags,
1846 const BoundNetLog& net_log) {
1847 if (!race_cert_verification_)
1848 return;
1849 QuicCryptoClientConfig::CachedState* cached =
1850 crypto_config_.LookupOrCreate(server_id);
1851 if (!cached || cached->certs().empty() ||
1852 HasActiveCertVerifierJob(server_id)) {
1853 return;
1854 }
1855 std::unique_ptr<CertVerifierJob> cert_verifier_job(
1856 new CertVerifierJob(server_id, cert_verify_flags, net_log));
1857 QuicAsyncStatus status = cert_verifier_job->Run(
1858 &crypto_config_,
1859 base::Bind(&QuicStreamFactory::OnCertVerifyJobComplete,
1860 base::Unretained(this), cert_verifier_job.get()));
1861 if (status == QUIC_PENDING)
1862 active_cert_verifier_jobs_[server_id] = std::move(cert_verifier_job);
1863 }
1864
1865 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( 1758 void QuicStreamFactory::InitializeCachedStateInCryptoConfig(
1866 const QuicServerId& server_id, 1759 const QuicServerId& server_id,
1867 const std::unique_ptr<QuicServerInfo>& server_info, 1760 const std::unique_ptr<QuicServerInfo>& server_info,
1868 QuicConnectionId* connection_id) { 1761 QuicConnectionId* connection_id) {
1869 QuicCryptoClientConfig::CachedState* cached = 1762 QuicCryptoClientConfig::CachedState* cached =
1870 crypto_config_.LookupOrCreate(server_id); 1763 crypto_config_.LookupOrCreate(server_id);
1871 if (cached->has_server_designated_connection_id()) 1764 if (cached->has_server_designated_connection_id())
1872 *connection_id = cached->GetNextServerDesignatedConnectionId(); 1765 *connection_id = cached->GetNextServerDesignatedConnectionId();
1873 1766
1874 if (!cached->IsEmpty()) 1767 if (!cached->IsEmpty())
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 // Since the session was active, there's no longer an 1869 // Since the session was active, there's no longer an
1977 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1870 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1978 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1871 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1979 // it as recently broken, which means that 0-RTT will be disabled but we'll 1872 // it as recently broken, which means that 0-RTT will be disabled but we'll
1980 // still race. 1873 // still race.
1981 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1874 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1982 alternative_service); 1875 alternative_service);
1983 } 1876 }
1984 1877
1985 } // namespace net 1878 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_stream_factory.h ('k') | net/quic/quic_stream_factory_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698