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

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

Issue 2210693002: 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, 4 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/chromium/quic_stream_factory.h ('k') | net/quic/chromium/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/chromium/quic_stream_factory.h" 5 #include "net/quic/chromium/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 22 matching lines...) Expand all
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/chromium/bidirectional_stream_quic_impl.h" 35 #include "net/quic/chromium/bidirectional_stream_quic_impl.h"
36 #include "net/quic/chromium/crypto/channel_id_chromium.h" 36 #include "net/quic/chromium/crypto/channel_id_chromium.h"
37 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" 37 #include "net/quic/chromium/crypto/proof_verifier_chromium.h"
38 #include "net/quic/chromium/port_suggester.h" 38 #include "net/quic/chromium/port_suggester.h"
39 #include "net/quic/chromium/quic_chromium_alarm_factory.h" 39 #include "net/quic/chromium/quic_chromium_alarm_factory.h"
40 #include "net/quic/chromium/quic_chromium_connection_helper.h" 40 #include "net/quic/chromium/quic_chromium_connection_helper.h"
41 #include "net/quic/chromium/quic_chromium_packet_reader.h" 41 #include "net/quic/chromium/quic_chromium_packet_reader.h"
42 #include "net/quic/chromium/quic_chromium_packet_writer.h" 42 #include "net/quic/chromium/quic_chromium_packet_writer.h"
43 #include "net/quic/core/crypto/proof_verifier.h"
44 #include "net/quic/core/crypto/properties_based_quic_server_info.h" 43 #include "net/quic/core/crypto/properties_based_quic_server_info.h"
45 #include "net/quic/core/crypto/quic_random.h" 44 #include "net/quic/core/crypto/quic_random.h"
46 #include "net/quic/core/crypto/quic_server_info.h" 45 #include "net/quic/core/crypto/quic_server_info.h"
47 #include "net/quic/core/quic_client_promised_info.h" 46 #include "net/quic/core/quic_client_promised_info.h"
48 #include "net/quic/core/quic_clock.h" 47 #include "net/quic/core/quic_clock.h"
49 #include "net/quic/core/quic_connection.h" 48 #include "net/quic/core/quic_connection.h"
50 #include "net/quic/core/quic_crypto_client_stream_factory.h" 49 #include "net/quic/core/quic_crypto_client_stream_factory.h"
51 #include "net/quic/core/quic_flags.h" 50 #include "net/quic/core/quic_flags.h"
52 #include "net/socket/client_socket_factory.h" 51 #include "net/socket/client_socket_factory.h"
53 #include "net/socket/socket_performance_watcher.h" 52 #include "net/socket/socket_performance_watcher.h"
(...skipping 107 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_,
225 std::unique_ptr<ProofVerifierCallback>(verify_callback));
226 if (status == QUIC_PENDING) {
227 verify_callback_ = verify_callback;
228 callback_ = callback;
229 }
230 return status;
231 }
232
233 void OnComplete() {
234 if (!callback_.is_null())
235 callback_.Run(OK);
236 }
237
238 const QuicServerId& server_id() const { return server_id_; }
239
240 private:
241 QuicServerId server_id_;
242 ProofVerifierCallbackImpl* verify_callback_;
243 std::unique_ptr<ProofVerifyContext> verify_context_;
244 std::unique_ptr<ProofVerifyDetails> verify_details_;
245 std::string verify_error_details_;
246 const BoundNetLog net_log_;
247 CompletionCallback callback_;
248 base::WeakPtrFactory<CertVerifierJob> weak_factory_;
249
250 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob);
251 };
252
253 // 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
254 // for notifying any associated requests when complete. 171 // for notifying any associated requests when complete.
255 class QuicStreamFactory::Job { 172 class QuicStreamFactory::Job {
256 public: 173 public:
257 Job(QuicStreamFactory* factory, 174 Job(QuicStreamFactory* factory,
258 HostResolver* host_resolver, 175 HostResolver* host_resolver,
259 const QuicSessionKey& key, 176 const QuicSessionKey& key,
260 bool was_alternative_service_recently_broken, 177 bool was_alternative_service_recently_broken,
261 int cert_verify_flags, 178 int cert_verify_flags,
262 QuicServerInfo* server_info, 179 QuicServerInfo* server_info,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { 357 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() {
441 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. 358 // If we are waiting for WaitForDataReadyCallback, then cancel the callback.
442 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) 359 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE)
443 return; 360 return;
444 server_info_->CancelWaitForDataReadyCallback(); 361 server_info_->CancelWaitForDataReadyCallback();
445 OnIOComplete(OK); 362 OnIOComplete(OK);
446 } 363 }
447 364
448 int QuicStreamFactory::Job::DoResolveHost() { 365 int QuicStreamFactory::Job::DoResolveHost() {
449 // 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.
450 if (server_info_) 367 if (server_info_) {
451 server_info_->Start(); 368 server_info_->Start();
369 }
452 370
453 io_state_ = STATE_RESOLVE_HOST_COMPLETE; 371 io_state_ = STATE_RESOLVE_HOST_COMPLETE;
454 dns_resolution_start_time_ = base::TimeTicks::Now(); 372 dns_resolution_start_time_ = base::TimeTicks::Now();
455 return host_resolver_.Resolve( 373 return host_resolver_.Resolve(
456 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, 374 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY,
457 &address_list_, 375 &address_list_,
458 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), 376 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()),
459 net_log_); 377 net_log_);
460 } 378 }
461 379
462 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { 380 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) {
463 dns_resolution_end_time_ = base::TimeTicks::Now(); 381 dns_resolution_end_time_ = base::TimeTicks::Now();
464 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime", 382 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime",
465 dns_resolution_end_time_ - dns_resolution_start_time_); 383 dns_resolution_end_time_ - dns_resolution_start_time_);
466 if (rv != OK) 384 if (rv != OK)
467 return rv; 385 return rv;
468 386
469 DCHECK(!factory_->HasActiveSession(key_.server_id())); 387 DCHECK(!factory_->HasActiveSession(key_.server_id()));
470 388
471 // Inform the factory of this resolution, which will set up 389 // Inform the factory of this resolution, which will set up
472 // a session alias, if possible. 390 // a session alias, if possible.
473 if (factory_->OnResolution(key_, address_list_)) 391 if (factory_->OnResolution(key_, address_list_)) {
474 return OK; 392 return OK;
393 }
475 394
476 if (server_info_) 395 if (server_info_)
477 io_state_ = STATE_LOAD_SERVER_INFO; 396 io_state_ = STATE_LOAD_SERVER_INFO;
478 else 397 else
479 io_state_ = STATE_CONNECT; 398 io_state_ = STATE_CONNECT;
480 return OK; 399 return OK;
481 } 400 }
482 401
483 int QuicStreamFactory::Job::DoLoadServerInfo() { 402 int QuicStreamFactory::Job::DoLoadServerInfo() {
484 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
543 462
544 int rv = factory_->CreateSession( 463 int rv = factory_->CreateSession(
545 key_, cert_verify_flags_, std::move(server_info_), address_list_, 464 key_, cert_verify_flags_, std::move(server_info_), address_list_,
546 dns_resolution_end_time_, net_log_, &session_); 465 dns_resolution_end_time_, net_log_, &session_);
547 if (rv != OK) { 466 if (rv != OK) {
548 DCHECK(rv != ERR_IO_PENDING); 467 DCHECK(rv != ERR_IO_PENDING);
549 DCHECK(!session_); 468 DCHECK(!session_);
550 return rv; 469 return rv;
551 } 470 }
552 471
553 if (!session_->connection()->connected()) 472 if (!session_->connection()->connected()) {
554 return ERR_CONNECTION_CLOSED; 473 return ERR_CONNECTION_CLOSED;
474 }
555 475
556 session_->StartReading(); 476 session_->StartReading();
557 if (!session_->connection()->connected()) 477 if (!session_->connection()->connected()) {
558 return ERR_QUIC_PROTOCOL_ERROR; 478 return ERR_QUIC_PROTOCOL_ERROR;
479 }
559 bool require_confirmation = factory_->require_confirmation() || 480 bool require_confirmation = factory_->require_confirmation() ||
560 was_alternative_service_recently_broken_; 481 was_alternative_service_recently_broken_;
561 482
562 rv = session_->CryptoConnect( 483 rv = session_->CryptoConnect(
563 require_confirmation, 484 require_confirmation,
564 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 485 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
565 486
566 if (!session_->connection()->connected() && 487 if (!session_->connection()->connected() &&
567 session_->error() == QUIC_PROOF_INVALID) { 488 session_->error() == QUIC_PROOF_INVALID)
568 return ERR_QUIC_HANDSHAKE_FAILED; 489 return ERR_QUIC_HANDSHAKE_FAILED;
569 }
570 490
571 return rv; 491 return rv;
572 } 492 }
573 493
574 int QuicStreamFactory::Job::DoResumeConnect() { 494 int QuicStreamFactory::Job::DoResumeConnect() {
575 io_state_ = STATE_CONNECT_COMPLETE; 495 io_state_ = STATE_CONNECT_COMPLETE;
576 496
577 int rv = session_->ResumeCryptoConnect( 497 int rv = session_->ResumeCryptoConnect(
578 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 498 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
579 499
580 return rv; 500 return rv;
581 } 501 }
582 502
583 int QuicStreamFactory::Job::DoConnectComplete(int rv) { 503 int QuicStreamFactory::Job::DoConnectComplete(int rv) {
584 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { 504 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) {
585 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); 505 num_sent_client_hellos_ += session_->GetNumSentClientHellos();
586 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) 506 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) {
587 return ERR_QUIC_HANDSHAKE_FAILED; 507 return ERR_QUIC_HANDSHAKE_FAILED;
508 }
588 // The handshake was rejected statelessly, so create another connection 509 // The handshake was rejected statelessly, so create another connection
589 // to resume the handshake. 510 // to resume the handshake.
590 io_state_ = STATE_CONNECT; 511 io_state_ = STATE_CONNECT;
591 return OK; 512 return OK;
592 } 513 }
593 514
594 if (rv != OK) 515 if (rv != OK)
595 return rv; 516 return rv;
596 517
597 DCHECK(!factory_->HasActiveSession(key_.server_id())); 518 DCHECK(!factory_->HasActiveSession(key_.server_id()));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 int socket_receive_buffer_size, 627 int socket_receive_buffer_size,
707 bool delay_tcp_race, 628 bool delay_tcp_race,
708 int max_server_configs_stored_in_properties, 629 int max_server_configs_stored_in_properties,
709 bool close_sessions_on_ip_change, 630 bool close_sessions_on_ip_change,
710 bool disable_quic_on_timeout_with_open_streams, 631 bool disable_quic_on_timeout_with_open_streams,
711 int idle_connection_timeout_seconds, 632 int idle_connection_timeout_seconds,
712 bool migrate_sessions_on_network_change, 633 bool migrate_sessions_on_network_change,
713 bool migrate_sessions_early, 634 bool migrate_sessions_early,
714 bool allow_server_migration, 635 bool allow_server_migration,
715 bool force_hol_blocking, 636 bool force_hol_blocking,
716 bool race_cert_verification,
717 const QuicTagVector& connection_options, 637 const QuicTagVector& connection_options,
718 bool enable_token_binding) 638 bool enable_token_binding)
719 : require_confirmation_(true), 639 : require_confirmation_(true),
720 net_log_(net_log), 640 net_log_(net_log),
721 host_resolver_(host_resolver), 641 host_resolver_(host_resolver),
722 client_socket_factory_(client_socket_factory), 642 client_socket_factory_(client_socket_factory),
723 http_server_properties_(http_server_properties), 643 http_server_properties_(http_server_properties),
724 transport_security_state_(transport_security_state), 644 transport_security_state_(transport_security_state),
725 cert_transparency_verifier_(cert_transparency_verifier), 645 cert_transparency_verifier_(cert_transparency_verifier),
726 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), 646 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 yield_after_duration_(QuicTime::Delta::FromMilliseconds( 683 yield_after_duration_(QuicTime::Delta::FromMilliseconds(
764 kQuicYieldAfterDurationMilliseconds)), 684 kQuicYieldAfterDurationMilliseconds)),
765 close_sessions_on_ip_change_(close_sessions_on_ip_change), 685 close_sessions_on_ip_change_(close_sessions_on_ip_change),
766 migrate_sessions_on_network_change_( 686 migrate_sessions_on_network_change_(
767 migrate_sessions_on_network_change && 687 migrate_sessions_on_network_change &&
768 NetworkChangeNotifier::AreNetworkHandlesSupported()), 688 NetworkChangeNotifier::AreNetworkHandlesSupported()),
769 migrate_sessions_early_(migrate_sessions_early && 689 migrate_sessions_early_(migrate_sessions_early &&
770 migrate_sessions_on_network_change_), 690 migrate_sessions_on_network_change_),
771 allow_server_migration_(allow_server_migration), 691 allow_server_migration_(allow_server_migration),
772 force_hol_blocking_(force_hol_blocking), 692 force_hol_blocking_(force_hol_blocking),
773 race_cert_verification_(race_cert_verification),
774 port_seed_(random_generator_->RandUint64()), 693 port_seed_(random_generator_->RandUint64()),
775 check_persisted_supports_quic_(true), 694 check_persisted_supports_quic_(true),
776 has_initialized_data_(false), 695 has_initialized_data_(false),
777 num_push_streams_created_(0), 696 num_push_streams_created_(0),
778 status_(OPEN), 697 status_(OPEN),
779 task_runner_(nullptr), 698 task_runner_(nullptr),
780 ssl_config_service_(ssl_config_service), 699 ssl_config_service_(ssl_config_service),
781 weak_factory_(this) { 700 weak_factory_(this) {
782 if (ssl_config_service_.get()) 701 if (ssl_config_service_.get())
783 ssl_config_service_->AddObserver(this); 702 ssl_config_service_->AddObserver(this);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); 750 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED);
832 while (!all_sessions_.empty()) { 751 while (!all_sessions_.empty()) {
833 delete all_sessions_.begin()->first; 752 delete all_sessions_.begin()->first;
834 all_sessions_.erase(all_sessions_.begin()); 753 all_sessions_.erase(all_sessions_.begin());
835 } 754 }
836 while (!active_jobs_.empty()) { 755 while (!active_jobs_.empty()) {
837 const QuicServerId server_id = active_jobs_.begin()->first; 756 const QuicServerId server_id = active_jobs_.begin()->first;
838 STLDeleteElements(&(active_jobs_[server_id])); 757 STLDeleteElements(&(active_jobs_[server_id]));
839 active_jobs_.erase(server_id); 758 active_jobs_.erase(server_id);
840 } 759 }
841 while (!active_cert_verifier_jobs_.empty())
842 active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin());
843 if (ssl_config_service_.get()) 760 if (ssl_config_service_.get())
844 ssl_config_service_->RemoveObserver(this); 761 ssl_config_service_->RemoveObserver(this);
845 if (migrate_sessions_on_network_change_) { 762 if (migrate_sessions_on_network_change_) {
846 NetworkChangeNotifier::RemoveNetworkObserver(this); 763 NetworkChangeNotifier::RemoveNetworkObserver(this);
847 } else if (close_sessions_on_ip_change_) { 764 } else if (close_sessions_on_ip_change_) {
848 NetworkChangeNotifier::RemoveIPAddressObserver(this); 765 NetworkChangeNotifier::RemoveIPAddressObserver(this);
849 } 766 }
850 } 767 }
851 768
852 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { 769 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 881
965 QuicServerInfo* quic_server_info = nullptr; 882 QuicServerInfo* quic_server_info = nullptr;
966 if (quic_server_info_factory_.get()) { 883 if (quic_server_info_factory_.get()) {
967 bool load_from_disk_cache = !disable_disk_cache_; 884 bool load_from_disk_cache = !disable_disk_cache_;
968 MaybeInitialize(); 885 MaybeInitialize();
969 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) { 886 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) {
970 // If there is no entry for QUIC, consider that as a new server and 887 // If there is no entry for QUIC, consider that as a new server and
971 // don't wait for Cache thread to load the data for that server. 888 // don't wait for Cache thread to load the data for that server.
972 load_from_disk_cache = false; 889 load_from_disk_cache = false;
973 } 890 }
974 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) 891 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) {
975 quic_server_info = quic_server_info_factory_->GetForServer(server_id); 892 quic_server_info = quic_server_info_factory_->GetForServer(server_id);
893 }
976 } 894 }
977 895
978 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log));
979
980 QuicSessionKey key(destination, server_id); 896 QuicSessionKey key(destination, server_id);
981 std::unique_ptr<Job> job( 897 std::unique_ptr<Job> job(
982 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), 898 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id),
983 cert_verify_flags, quic_server_info, net_log)); 899 cert_verify_flags, quic_server_info, net_log));
984 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 900 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
985 base::Unretained(this), job.get())); 901 base::Unretained(this), job.get()));
986 if (rv == ERR_IO_PENDING) { 902 if (rv == ERR_IO_PENDING) {
987 active_requests_[request] = server_id; 903 active_requests_[request] = server_id;
988 job_requests_map_[server_id].insert(request); 904 job_requests_map_[server_id].insert(request);
989 active_jobs_[server_id].insert(job.release()); 905 active_jobs_[server_id].insert(job.release());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 active_jobs_[key.server_id()].insert(aux_job); 946 active_jobs_[key.server_id()].insert(aux_job);
1031 task_runner_->PostTask(FROM_HERE, 947 task_runner_->PostTask(FROM_HERE,
1032 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, 948 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob,
1033 aux_job->GetWeakPtr())); 949 aux_job->GetWeakPtr()));
1034 } 950 }
1035 951
1036 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, 952 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key,
1037 const AddressList& address_list) { 953 const AddressList& address_list) {
1038 const QuicServerId& server_id(key.server_id()); 954 const QuicServerId& server_id(key.server_id());
1039 DCHECK(!HasActiveSession(server_id)); 955 DCHECK(!HasActiveSession(server_id));
1040 if (disable_connection_pooling_) 956 if (disable_connection_pooling_) {
1041 return false; 957 return false;
958 }
1042 for (const IPEndPoint& address : address_list) { 959 for (const IPEndPoint& address : address_list) {
1043 if (!ContainsKey(ip_aliases_, address)) 960 if (!ContainsKey(ip_aliases_, address))
1044 continue; 961 continue;
1045 962
1046 const SessionSet& sessions = ip_aliases_[address]; 963 const SessionSet& sessions = ip_aliases_[address];
1047 for (QuicChromiumClientSession* session : sessions) { 964 for (QuicChromiumClientSession* session : sessions) {
1048 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) 965 if (!session->CanPool(server_id.host(), server_id.privacy_mode()))
1049 continue; 966 continue;
1050 active_sessions_[server_id] = session; 967 active_sessions_[server_id] = session;
1051 session_aliases_[session].insert(key); 968 session_aliases_[session].insert(key);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 for (Job* other_job : active_jobs_[server_id]) { 1018 for (Job* other_job : active_jobs_[server_id]) {
1102 if (other_job != job) 1019 if (other_job != job)
1103 other_job->Cancel(); 1020 other_job->Cancel();
1104 } 1021 }
1105 1022
1106 STLDeleteElements(&(active_jobs_[server_id])); 1023 STLDeleteElements(&(active_jobs_[server_id]));
1107 active_jobs_.erase(server_id); 1024 active_jobs_.erase(server_id);
1108 job_requests_map_.erase(server_id); 1025 job_requests_map_.erase(server_id);
1109 } 1026 }
1110 1027
1111 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) {
1112 active_cert_verifier_jobs_.erase(job->server_id());
1113 }
1114
1115 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( 1028 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession(
1116 QuicChromiumClientSession* session) { 1029 QuicChromiumClientSession* session) {
1117 return std::unique_ptr<QuicHttpStream>( 1030 return std::unique_ptr<QuicHttpStream>(
1118 new QuicHttpStream(session->GetWeakPtr())); 1031 new QuicHttpStream(session->GetWeakPtr()));
1119 } 1032 }
1120 1033
1121 QuicChromiumClientSession::QuicDisabledReason 1034 QuicChromiumClientSession::QuicDisabledReason
1122 QuicStreamFactory::QuicDisabledReason(uint16_t port) const { 1035 QuicStreamFactory::QuicDisabledReason(uint16_t port) const {
1123 if (max_number_of_lossy_connections_ > 0 && 1036 if (max_number_of_lossy_connections_ > 0 &&
1124 number_of_lossy_connections_.find(port) != 1037 number_of_lossy_connections_.find(port) !=
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 1133
1221 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { 1134 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) {
1222 const AliasSet& aliases = session_aliases_[session]; 1135 const AliasSet& aliases = session_aliases_[session];
1223 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); 1136 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end();
1224 ++it) { 1137 ++it) {
1225 const QuicServerId& server_id = it->server_id(); 1138 const QuicServerId& server_id = it->server_id();
1226 DCHECK(active_sessions_.count(server_id)); 1139 DCHECK(active_sessions_.count(server_id));
1227 DCHECK_EQ(session, active_sessions_[server_id]); 1140 DCHECK_EQ(session, active_sessions_[server_id]);
1228 // Track sessions which have recently gone away so that we can disable 1141 // Track sessions which have recently gone away so that we can disable
1229 // port suggestions. 1142 // port suggestions.
1230 if (session->goaway_received()) 1143 if (session->goaway_received()) {
1231 gone_away_aliases_.insert(*it); 1144 gone_away_aliases_.insert(*it);
1145 }
1232 1146
1233 active_sessions_.erase(server_id); 1147 active_sessions_.erase(server_id);
1234 ProcessGoingAwaySession(session, server_id, true); 1148 ProcessGoingAwaySession(session, server_id, true);
1235 } 1149 }
1236 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false); 1150 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false);
1237 if (!aliases.empty()) { 1151 if (!aliases.empty()) {
1238 const IPEndPoint peer_address = session->connection()->peer_address(); 1152 const IPEndPoint peer_address = session->connection()->peer_address();
1239 ip_aliases_[peer_address].erase(session); 1153 ip_aliases_[peer_address].erase(session);
1240 if (ip_aliases_[peer_address].empty()) 1154 if (ip_aliases_[peer_address].empty()) {
1241 ip_aliases_.erase(peer_address); 1155 ip_aliases_.erase(peer_address);
1156 }
1242 } 1157 }
1243 session_aliases_.erase(session); 1158 session_aliases_.erase(session);
1244 } 1159 }
1245 1160
1246 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { 1161 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) {
1247 DCHECK(session); 1162 DCHECK(session);
1248 uint16_t port = session->server_id().port(); 1163 uint16_t port = session->server_id().port();
1249 if (IsQuicDisabled(port)) 1164 if (IsQuicDisabled(port))
1250 return; 1165 return;
1251 1166
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 MaybeDisableQuic(session); 1251 MaybeDisableQuic(session);
1337 OnSessionGoingAway(session); 1252 OnSessionGoingAway(session);
1338 delete session; 1253 delete session;
1339 all_sessions_.erase(session); 1254 all_sessions_.erase(session);
1340 } 1255 }
1341 1256
1342 void QuicStreamFactory::OnSessionConnectTimeout( 1257 void QuicStreamFactory::OnSessionConnectTimeout(
1343 QuicChromiumClientSession* session) { 1258 QuicChromiumClientSession* session) {
1344 const AliasSet& aliases = session_aliases_[session]; 1259 const AliasSet& aliases = session_aliases_[session];
1345 1260
1346 if (aliases.empty()) 1261 if (aliases.empty()) {
1347 return; 1262 return;
1263 }
1348 1264
1349 for (const QuicSessionKey& key : aliases) { 1265 for (const QuicSessionKey& key : aliases) {
1350 const QuicServerId& server_id = key.server_id(); 1266 const QuicServerId& server_id = key.server_id();
1351 SessionMap::iterator session_it = active_sessions_.find(server_id); 1267 SessionMap::iterator session_it = active_sessions_.find(server_id);
1352 DCHECK(session_it != active_sessions_.end()); 1268 DCHECK(session_it != active_sessions_.end());
1353 DCHECK_EQ(session, session_it->second); 1269 DCHECK_EQ(session, session_it->second);
1354 active_sessions_.erase(session_it); 1270 active_sessions_.erase(session_it);
1355 } 1271 }
1356 1272
1357 const IPEndPoint peer_address = session->connection()->peer_address(); 1273 const IPEndPoint peer_address = session->connection()->peer_address();
1358 ip_aliases_[peer_address].erase(session); 1274 ip_aliases_[peer_address].erase(session);
1359 if (ip_aliases_[peer_address].empty()) 1275 if (ip_aliases_[peer_address].empty()) {
1360 ip_aliases_.erase(peer_address); 1276 ip_aliases_.erase(peer_address);
1277 }
1361 QuicSessionKey key = *aliases.begin(); 1278 QuicSessionKey key = *aliases.begin();
1362 session_aliases_.erase(session); 1279 session_aliases_.erase(session);
1363 Job* job = new Job(this, host_resolver_, session, key); 1280 Job* job = new Job(this, host_resolver_, session, key);
1364 active_jobs_[key.server_id()].insert(job); 1281 active_jobs_[key.server_id()].insert(job);
1365 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 1282 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
1366 base::Unretained(this), job)); 1283 base::Unretained(this), job));
1367 DCHECK_EQ(ERR_IO_PENDING, rv); 1284 DCHECK_EQ(ERR_IO_PENDING, rv);
1368 } 1285 }
1369 1286
1370 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { 1287 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, 1363 MaybeMigrateOrCloseSessions(network, /*force_close=*/false,
1447 scoped_event_log.net_log()); 1364 scoped_event_log.net_log());
1448 } 1365 }
1449 1366
1450 NetworkHandle QuicStreamFactory::FindAlternateNetwork( 1367 NetworkHandle QuicStreamFactory::FindAlternateNetwork(
1451 NetworkHandle old_network) { 1368 NetworkHandle old_network) {
1452 // Find a new network that sessions bound to |old_network| can be migrated to. 1369 // Find a new network that sessions bound to |old_network| can be migrated to.
1453 NetworkChangeNotifier::NetworkList network_list; 1370 NetworkChangeNotifier::NetworkList network_list;
1454 NetworkChangeNotifier::GetConnectedNetworks(&network_list); 1371 NetworkChangeNotifier::GetConnectedNetworks(&network_list);
1455 for (NetworkHandle new_network : network_list) { 1372 for (NetworkHandle new_network : network_list) {
1456 if (new_network != old_network) 1373 if (new_network != old_network) {
1457 return new_network; 1374 return new_network;
1375 }
1458 } 1376 }
1459 return NetworkChangeNotifier::kInvalidNetworkHandle; 1377 return NetworkChangeNotifier::kInvalidNetworkHandle;
1460 } 1378 }
1461 1379
1462 void QuicStreamFactory::MaybeMigrateOrCloseSessions( 1380 void QuicStreamFactory::MaybeMigrateOrCloseSessions(
1463 NetworkHandle network, 1381 NetworkHandle network,
1464 bool force_close, 1382 bool force_close,
1465 const BoundNetLog& bound_net_log) { 1383 const BoundNetLog& bound_net_log) {
1466 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); 1384 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network);
1467 NetworkHandle new_network = FindAlternateNetwork(network); 1385 NetworkHandle new_network = FindAlternateNetwork(network);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. 1573 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check.
1656 if (active_sessions_.empty()) 1574 if (active_sessions_.empty())
1657 return false; 1575 return false;
1658 return ContainsKey(active_sessions_, server_id); 1576 return ContainsKey(active_sessions_, server_id);
1659 } 1577 }
1660 1578
1661 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { 1579 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const {
1662 return ContainsKey(active_jobs_, server_id); 1580 return ContainsKey(active_jobs_, server_id);
1663 } 1581 }
1664 1582
1665 bool QuicStreamFactory::HasActiveCertVerifierJob(
1666 const QuicServerId& server_id) const {
1667 return ContainsKey(active_cert_verifier_jobs_, server_id);
1668 }
1669
1670 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, 1583 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket,
1671 IPEndPoint addr, 1584 IPEndPoint addr,
1672 NetworkHandle network) { 1585 NetworkHandle network) {
1673 if (enable_non_blocking_io_ && 1586 if (enable_non_blocking_io_ &&
1674 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { 1587 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) {
1675 #if defined(OS_WIN) 1588 #if defined(OS_WIN)
1676 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); 1589 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO();
1677 #endif 1590 #endif
1678 } 1591 }
1679 1592
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. 1661 DatagramSocket::DEFAULT_BIND; // Use OS to randomize.
1749 1662
1750 std::unique_ptr<DatagramClientSocket> socket( 1663 std::unique_ptr<DatagramClientSocket> socket(
1751 client_socket_factory_->CreateDatagramClientSocket( 1664 client_socket_factory_->CreateDatagramClientSocket(
1752 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), 1665 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester),
1753 net_log.net_log(), net_log.source())); 1666 net_log.net_log(), net_log.source()));
1754 1667
1755 // Passing in kInvalidNetworkHandle binds socket to default network. 1668 // Passing in kInvalidNetworkHandle binds socket to default network.
1756 int rv = ConfigureSocket(socket.get(), addr, 1669 int rv = ConfigureSocket(socket.get(), addr,
1757 NetworkChangeNotifier::kInvalidNetworkHandle); 1670 NetworkChangeNotifier::kInvalidNetworkHandle);
1758 if (rv != OK) 1671 if (rv != OK) {
1759 return rv; 1672 return rv;
1673 }
1760 1674
1761 if (enable_port_selection) 1675 if (enable_port_selection) {
1762 DCHECK_LE(1u, port_suggester->call_count()); 1676 DCHECK_LE(1u, port_suggester->call_count());
1763 else 1677 } else {
1764 DCHECK_EQ(0u, port_suggester->call_count()); 1678 DCHECK_EQ(0u, port_suggester->call_count());
1679 }
1765 1680
1766 if (!helper_.get()) { 1681 if (!helper_.get()) {
1767 helper_.reset( 1682 helper_.reset(
1768 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); 1683 new QuicChromiumConnectionHelper(clock_.get(), random_generator_));
1769 } 1684 }
1770 1685
1771 if (!alarm_factory_.get()) { 1686 if (!alarm_factory_.get()) {
1772 alarm_factory_.reset(new QuicChromiumAlarmFactory( 1687 alarm_factory_.reset(new QuicChromiumAlarmFactory(
1773 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); 1688 base::ThreadTaskRunnerHandle::Get().get(), clock_.get()));
1774 } 1689 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 alternative_service); 1783 alternative_service);
1869 } 1784 }
1870 1785
1871 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( 1786 bool QuicStreamFactory::CryptoConfigCacheIsEmpty(
1872 const QuicServerId& server_id) { 1787 const QuicServerId& server_id) {
1873 QuicCryptoClientConfig::CachedState* cached = 1788 QuicCryptoClientConfig::CachedState* cached =
1874 crypto_config_.LookupOrCreate(server_id); 1789 crypto_config_.LookupOrCreate(server_id);
1875 return cached->IsEmpty(); 1790 return cached->IsEmpty();
1876 } 1791 }
1877 1792
1878 QuicAsyncStatus QuicStreamFactory::StartCertVerifyJob(
1879 const QuicServerId& server_id,
1880 int cert_verify_flags,
1881 const BoundNetLog& net_log) {
1882 if (!race_cert_verification_)
1883 return QUIC_FAILURE;
1884 QuicCryptoClientConfig::CachedState* cached =
1885 crypto_config_.LookupOrCreate(server_id);
1886 if (!cached || cached->certs().empty() ||
1887 HasActiveCertVerifierJob(server_id)) {
1888 return QUIC_FAILURE;
1889 }
1890 std::unique_ptr<CertVerifierJob> cert_verifier_job(
1891 new CertVerifierJob(server_id, cert_verify_flags, net_log));
1892 QuicAsyncStatus status = cert_verifier_job->Run(
1893 &crypto_config_,
1894 base::Bind(&QuicStreamFactory::OnCertVerifyJobComplete,
1895 base::Unretained(this), cert_verifier_job.get()));
1896 if (status == QUIC_PENDING)
1897 active_cert_verifier_jobs_[server_id] = std::move(cert_verifier_job);
1898 return status;
1899 }
1900
1901 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( 1793 void QuicStreamFactory::InitializeCachedStateInCryptoConfig(
1902 const QuicServerId& server_id, 1794 const QuicServerId& server_id,
1903 const std::unique_ptr<QuicServerInfo>& server_info, 1795 const std::unique_ptr<QuicServerInfo>& server_info,
1904 QuicConnectionId* connection_id) { 1796 QuicConnectionId* connection_id) {
1905 QuicCryptoClientConfig::CachedState* cached = 1797 QuicCryptoClientConfig::CachedState* cached =
1906 crypto_config_.LookupOrCreate(server_id); 1798 crypto_config_.LookupOrCreate(server_id);
1907 if (cached->has_server_designated_connection_id()) 1799 if (cached->has_server_designated_connection_id())
1908 *connection_id = cached->GetNextServerDesignatedConnectionId(); 1800 *connection_id = cached->GetNextServerDesignatedConnectionId();
1909 1801
1910 if (!cached->IsEmpty()) 1802 if (!cached->IsEmpty())
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2012 // Since the session was active, there's no longer an 1904 // Since the session was active, there's no longer an
2013 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1905 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
2014 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1906 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
2015 // it as recently broken, which means that 0-RTT will be disabled but we'll 1907 // it as recently broken, which means that 0-RTT will be disabled but we'll
2016 // still race. 1908 // still race.
2017 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1909 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
2018 alternative_service); 1910 alternative_service);
2019 } 1911 }
2020 1912
2021 } // namespace net 1913 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_stream_factory.h ('k') | net/quic/chromium/quic_stream_factory_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698