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 <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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 int threshold_timeouts_with_open_streams, | 626 int threshold_timeouts_with_open_streams, |
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 force_hol_blocking, | 635 bool force_hol_blocking, |
715 bool race_cert_verification, | |
716 const QuicTagVector& connection_options, | 636 const QuicTagVector& connection_options, |
717 bool enable_token_binding) | 637 bool enable_token_binding) |
718 : require_confirmation_(true), | 638 : require_confirmation_(true), |
719 net_log_(net_log), | 639 net_log_(net_log), |
720 host_resolver_(host_resolver), | 640 host_resolver_(host_resolver), |
721 client_socket_factory_(client_socket_factory), | 641 client_socket_factory_(client_socket_factory), |
722 http_server_properties_(http_server_properties), | 642 http_server_properties_(http_server_properties), |
723 transport_security_state_(transport_security_state), | 643 transport_security_state_(transport_security_state), |
724 cert_transparency_verifier_(cert_transparency_verifier), | 644 cert_transparency_verifier_(cert_transparency_verifier), |
725 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 645 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 yield_after_packets_(kQuicYieldAfterPacketsRead), | 680 yield_after_packets_(kQuicYieldAfterPacketsRead), |
761 yield_after_duration_(QuicTime::Delta::FromMilliseconds( | 681 yield_after_duration_(QuicTime::Delta::FromMilliseconds( |
762 kQuicYieldAfterDurationMilliseconds)), | 682 kQuicYieldAfterDurationMilliseconds)), |
763 close_sessions_on_ip_change_(close_sessions_on_ip_change), | 683 close_sessions_on_ip_change_(close_sessions_on_ip_change), |
764 migrate_sessions_on_network_change_( | 684 migrate_sessions_on_network_change_( |
765 migrate_sessions_on_network_change && | 685 migrate_sessions_on_network_change && |
766 NetworkChangeNotifier::AreNetworkHandlesSupported()), | 686 NetworkChangeNotifier::AreNetworkHandlesSupported()), |
767 migrate_sessions_early_(migrate_sessions_early && | 687 migrate_sessions_early_(migrate_sessions_early && |
768 migrate_sessions_on_network_change_), | 688 migrate_sessions_on_network_change_), |
769 force_hol_blocking_(force_hol_blocking), | 689 force_hol_blocking_(force_hol_blocking), |
770 race_cert_verification_(race_cert_verification), | |
771 port_seed_(random_generator_->RandUint64()), | 690 port_seed_(random_generator_->RandUint64()), |
772 check_persisted_supports_quic_(true), | 691 check_persisted_supports_quic_(true), |
773 has_initialized_data_(false), | 692 has_initialized_data_(false), |
774 num_push_streams_created_(0), | 693 num_push_streams_created_(0), |
775 status_(OPEN), | 694 status_(OPEN), |
776 task_runner_(nullptr), | 695 task_runner_(nullptr), |
777 ssl_config_service_(ssl_config_service), | 696 ssl_config_service_(ssl_config_service), |
778 weak_factory_(this) { | 697 weak_factory_(this) { |
779 if (ssl_config_service_.get()) | 698 if (ssl_config_service_.get()) |
780 ssl_config_service_->AddObserver(this); | 699 ssl_config_service_->AddObserver(this); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); | 747 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); |
829 while (!all_sessions_.empty()) { | 748 while (!all_sessions_.empty()) { |
830 delete all_sessions_.begin()->first; | 749 delete all_sessions_.begin()->first; |
831 all_sessions_.erase(all_sessions_.begin()); | 750 all_sessions_.erase(all_sessions_.begin()); |
832 } | 751 } |
833 while (!active_jobs_.empty()) { | 752 while (!active_jobs_.empty()) { |
834 const QuicServerId server_id = active_jobs_.begin()->first; | 753 const QuicServerId server_id = active_jobs_.begin()->first; |
835 STLDeleteElements(&(active_jobs_[server_id])); | 754 STLDeleteElements(&(active_jobs_[server_id])); |
836 active_jobs_.erase(server_id); | 755 active_jobs_.erase(server_id); |
837 } | 756 } |
838 while (!active_cert_verifier_jobs_.empty()) | |
839 active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin()); | |
840 if (ssl_config_service_.get()) | 757 if (ssl_config_service_.get()) |
841 ssl_config_service_->RemoveObserver(this); | 758 ssl_config_service_->RemoveObserver(this); |
842 if (migrate_sessions_on_network_change_) { | 759 if (migrate_sessions_on_network_change_) { |
843 NetworkChangeNotifier::RemoveNetworkObserver(this); | 760 NetworkChangeNotifier::RemoveNetworkObserver(this); |
844 } else if (close_sessions_on_ip_change_) { | 761 } else if (close_sessions_on_ip_change_) { |
845 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 762 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
846 } | 763 } |
847 } | 764 } |
848 | 765 |
849 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { | 766 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 | 878 |
962 QuicServerInfo* quic_server_info = nullptr; | 879 QuicServerInfo* quic_server_info = nullptr; |
963 if (quic_server_info_factory_.get()) { | 880 if (quic_server_info_factory_.get()) { |
964 bool load_from_disk_cache = !disable_disk_cache_; | 881 bool load_from_disk_cache = !disable_disk_cache_; |
965 MaybeInitialize(); | 882 MaybeInitialize(); |
966 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) { | 883 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) { |
967 // If there is no entry for QUIC, consider that as a new server and | 884 // If there is no entry for QUIC, consider that as a new server and |
968 // don't wait for Cache thread to load the data for that server. | 885 // don't wait for Cache thread to load the data for that server. |
969 load_from_disk_cache = false; | 886 load_from_disk_cache = false; |
970 } | 887 } |
971 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) | 888 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { |
972 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 889 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 890 } |
973 } | 891 } |
974 | 892 |
975 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); | |
976 | |
977 QuicSessionKey key(destination, server_id); | 893 QuicSessionKey key(destination, server_id); |
978 std::unique_ptr<Job> job( | 894 std::unique_ptr<Job> job( |
979 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), | 895 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), |
980 cert_verify_flags, quic_server_info, net_log)); | 896 cert_verify_flags, quic_server_info, net_log)); |
981 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 897 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
982 base::Unretained(this), job.get())); | 898 base::Unretained(this), job.get())); |
983 if (rv == ERR_IO_PENDING) { | 899 if (rv == ERR_IO_PENDING) { |
984 active_requests_[request] = server_id; | 900 active_requests_[request] = server_id; |
985 job_requests_map_[server_id].insert(request); | 901 job_requests_map_[server_id].insert(request); |
986 active_jobs_[server_id].insert(job.release()); | 902 active_jobs_[server_id].insert(job.release()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 active_jobs_[key.server_id()].insert(aux_job); | 943 active_jobs_[key.server_id()].insert(aux_job); |
1028 task_runner_->PostTask(FROM_HERE, | 944 task_runner_->PostTask(FROM_HERE, |
1029 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, | 945 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, |
1030 aux_job->GetWeakPtr())); | 946 aux_job->GetWeakPtr())); |
1031 } | 947 } |
1032 | 948 |
1033 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, | 949 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, |
1034 const AddressList& address_list) { | 950 const AddressList& address_list) { |
1035 const QuicServerId& server_id(key.server_id()); | 951 const QuicServerId& server_id(key.server_id()); |
1036 DCHECK(!HasActiveSession(server_id)); | 952 DCHECK(!HasActiveSession(server_id)); |
1037 if (disable_connection_pooling_) | 953 if (disable_connection_pooling_) { |
1038 return false; | 954 return false; |
| 955 } |
1039 for (const IPEndPoint& address : address_list) { | 956 for (const IPEndPoint& address : address_list) { |
1040 if (!ContainsKey(ip_aliases_, address)) | 957 if (!ContainsKey(ip_aliases_, address)) |
1041 continue; | 958 continue; |
1042 | 959 |
1043 const SessionSet& sessions = ip_aliases_[address]; | 960 const SessionSet& sessions = ip_aliases_[address]; |
1044 for (QuicChromiumClientSession* session : sessions) { | 961 for (QuicChromiumClientSession* session : sessions) { |
1045 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) | 962 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) |
1046 continue; | 963 continue; |
1047 active_sessions_[server_id] = session; | 964 active_sessions_[server_id] = session; |
1048 session_aliases_[session].insert(key); | 965 session_aliases_[session].insert(key); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 for (Job* other_job : active_jobs_[server_id]) { | 1015 for (Job* other_job : active_jobs_[server_id]) { |
1099 if (other_job != job) | 1016 if (other_job != job) |
1100 other_job->Cancel(); | 1017 other_job->Cancel(); |
1101 } | 1018 } |
1102 | 1019 |
1103 STLDeleteElements(&(active_jobs_[server_id])); | 1020 STLDeleteElements(&(active_jobs_[server_id])); |
1104 active_jobs_.erase(server_id); | 1021 active_jobs_.erase(server_id); |
1105 job_requests_map_.erase(server_id); | 1022 job_requests_map_.erase(server_id); |
1106 } | 1023 } |
1107 | 1024 |
1108 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) { | |
1109 active_cert_verifier_jobs_.erase(job->server_id()); | |
1110 } | |
1111 | |
1112 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( | 1025 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( |
1113 QuicChromiumClientSession* session) { | 1026 QuicChromiumClientSession* session) { |
1114 return std::unique_ptr<QuicHttpStream>( | 1027 return std::unique_ptr<QuicHttpStream>( |
1115 new QuicHttpStream(session->GetWeakPtr())); | 1028 new QuicHttpStream(session->GetWeakPtr())); |
1116 } | 1029 } |
1117 | 1030 |
1118 QuicChromiumClientSession::QuicDisabledReason | 1031 QuicChromiumClientSession::QuicDisabledReason |
1119 QuicStreamFactory::QuicDisabledReason(uint16_t port) const { | 1032 QuicStreamFactory::QuicDisabledReason(uint16_t port) const { |
1120 if (max_number_of_lossy_connections_ > 0 && | 1033 if (max_number_of_lossy_connections_ > 0 && |
1121 number_of_lossy_connections_.find(port) != | 1034 number_of_lossy_connections_.find(port) != |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 | 1130 |
1218 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { | 1131 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { |
1219 const AliasSet& aliases = session_aliases_[session]; | 1132 const AliasSet& aliases = session_aliases_[session]; |
1220 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 1133 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
1221 ++it) { | 1134 ++it) { |
1222 const QuicServerId& server_id = it->server_id(); | 1135 const QuicServerId& server_id = it->server_id(); |
1223 DCHECK(active_sessions_.count(server_id)); | 1136 DCHECK(active_sessions_.count(server_id)); |
1224 DCHECK_EQ(session, active_sessions_[server_id]); | 1137 DCHECK_EQ(session, active_sessions_[server_id]); |
1225 // Track sessions which have recently gone away so that we can disable | 1138 // Track sessions which have recently gone away so that we can disable |
1226 // port suggestions. | 1139 // port suggestions. |
1227 if (session->goaway_received()) | 1140 if (session->goaway_received()) { |
1228 gone_away_aliases_.insert(*it); | 1141 gone_away_aliases_.insert(*it); |
| 1142 } |
1229 | 1143 |
1230 active_sessions_.erase(server_id); | 1144 active_sessions_.erase(server_id); |
1231 ProcessGoingAwaySession(session, server_id, true); | 1145 ProcessGoingAwaySession(session, server_id, true); |
1232 } | 1146 } |
1233 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false); | 1147 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false); |
1234 if (!aliases.empty()) { | 1148 if (!aliases.empty()) { |
1235 const IPEndPoint peer_address = session->connection()->peer_address(); | 1149 const IPEndPoint peer_address = session->connection()->peer_address(); |
1236 ip_aliases_[peer_address].erase(session); | 1150 ip_aliases_[peer_address].erase(session); |
1237 if (ip_aliases_[peer_address].empty()) | 1151 if (ip_aliases_[peer_address].empty()) { |
1238 ip_aliases_.erase(peer_address); | 1152 ip_aliases_.erase(peer_address); |
| 1153 } |
1239 } | 1154 } |
1240 session_aliases_.erase(session); | 1155 session_aliases_.erase(session); |
1241 } | 1156 } |
1242 | 1157 |
1243 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { | 1158 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { |
1244 DCHECK(session); | 1159 DCHECK(session); |
1245 uint16_t port = session->server_id().port(); | 1160 uint16_t port = session->server_id().port(); |
1246 if (IsQuicDisabled(port)) | 1161 if (IsQuicDisabled(port)) |
1247 return; | 1162 return; |
1248 | 1163 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 MaybeDisableQuic(session); | 1248 MaybeDisableQuic(session); |
1334 OnSessionGoingAway(session); | 1249 OnSessionGoingAway(session); |
1335 delete session; | 1250 delete session; |
1336 all_sessions_.erase(session); | 1251 all_sessions_.erase(session); |
1337 } | 1252 } |
1338 | 1253 |
1339 void QuicStreamFactory::OnSessionConnectTimeout( | 1254 void QuicStreamFactory::OnSessionConnectTimeout( |
1340 QuicChromiumClientSession* session) { | 1255 QuicChromiumClientSession* session) { |
1341 const AliasSet& aliases = session_aliases_[session]; | 1256 const AliasSet& aliases = session_aliases_[session]; |
1342 | 1257 |
1343 if (aliases.empty()) | 1258 if (aliases.empty()) { |
1344 return; | 1259 return; |
| 1260 } |
1345 | 1261 |
1346 for (const QuicSessionKey& key : aliases) { | 1262 for (const QuicSessionKey& key : aliases) { |
1347 const QuicServerId& server_id = key.server_id(); | 1263 const QuicServerId& server_id = key.server_id(); |
1348 SessionMap::iterator session_it = active_sessions_.find(server_id); | 1264 SessionMap::iterator session_it = active_sessions_.find(server_id); |
1349 DCHECK(session_it != active_sessions_.end()); | 1265 DCHECK(session_it != active_sessions_.end()); |
1350 DCHECK_EQ(session, session_it->second); | 1266 DCHECK_EQ(session, session_it->second); |
1351 active_sessions_.erase(session_it); | 1267 active_sessions_.erase(session_it); |
1352 } | 1268 } |
1353 | 1269 |
1354 const IPEndPoint peer_address = session->connection()->peer_address(); | 1270 const IPEndPoint peer_address = session->connection()->peer_address(); |
1355 ip_aliases_[peer_address].erase(session); | 1271 ip_aliases_[peer_address].erase(session); |
1356 if (ip_aliases_[peer_address].empty()) | 1272 if (ip_aliases_[peer_address].empty()) { |
1357 ip_aliases_.erase(peer_address); | 1273 ip_aliases_.erase(peer_address); |
| 1274 } |
1358 QuicSessionKey key = *aliases.begin(); | 1275 QuicSessionKey key = *aliases.begin(); |
1359 session_aliases_.erase(session); | 1276 session_aliases_.erase(session); |
1360 Job* job = new Job(this, host_resolver_, session, key); | 1277 Job* job = new Job(this, host_resolver_, session, key); |
1361 active_jobs_[key.server_id()].insert(job); | 1278 active_jobs_[key.server_id()].insert(job); |
1362 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 1279 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
1363 base::Unretained(this), job)); | 1280 base::Unretained(this), job)); |
1364 DCHECK_EQ(ERR_IO_PENDING, rv); | 1281 DCHECK_EQ(ERR_IO_PENDING, rv); |
1365 } | 1282 } |
1366 | 1283 |
1367 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { | 1284 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, | 1360 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, |
1444 scoped_event_log.net_log()); | 1361 scoped_event_log.net_log()); |
1445 } | 1362 } |
1446 | 1363 |
1447 NetworkHandle QuicStreamFactory::FindAlternateNetwork( | 1364 NetworkHandle QuicStreamFactory::FindAlternateNetwork( |
1448 NetworkHandle old_network) { | 1365 NetworkHandle old_network) { |
1449 // Find a new network that sessions bound to |old_network| can be migrated to. | 1366 // Find a new network that sessions bound to |old_network| can be migrated to. |
1450 NetworkChangeNotifier::NetworkList network_list; | 1367 NetworkChangeNotifier::NetworkList network_list; |
1451 NetworkChangeNotifier::GetConnectedNetworks(&network_list); | 1368 NetworkChangeNotifier::GetConnectedNetworks(&network_list); |
1452 for (NetworkHandle new_network : network_list) { | 1369 for (NetworkHandle new_network : network_list) { |
1453 if (new_network != old_network) | 1370 if (new_network != old_network) { |
1454 return new_network; | 1371 return new_network; |
| 1372 } |
1455 } | 1373 } |
1456 return NetworkChangeNotifier::kInvalidNetworkHandle; | 1374 return NetworkChangeNotifier::kInvalidNetworkHandle; |
1457 } | 1375 } |
1458 | 1376 |
1459 void QuicStreamFactory::MaybeMigrateOrCloseSessions( | 1377 void QuicStreamFactory::MaybeMigrateOrCloseSessions( |
1460 NetworkHandle network, | 1378 NetworkHandle network, |
1461 bool force_close, | 1379 bool force_close, |
1462 const BoundNetLog& bound_net_log) { | 1380 const BoundNetLog& bound_net_log) { |
1463 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); | 1381 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); |
1464 NetworkHandle new_network = FindAlternateNetwork(network); | 1382 NetworkHandle new_network = FindAlternateNetwork(network); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. | 1550 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. |
1633 if (active_sessions_.empty()) | 1551 if (active_sessions_.empty()) |
1634 return false; | 1552 return false; |
1635 return ContainsKey(active_sessions_, server_id); | 1553 return ContainsKey(active_sessions_, server_id); |
1636 } | 1554 } |
1637 | 1555 |
1638 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { | 1556 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { |
1639 return ContainsKey(active_jobs_, server_id); | 1557 return ContainsKey(active_jobs_, server_id); |
1640 } | 1558 } |
1641 | 1559 |
1642 bool QuicStreamFactory::HasActiveCertVerifierJob( | |
1643 const QuicServerId& server_id) const { | |
1644 return ContainsKey(active_cert_verifier_jobs_, server_id); | |
1645 } | |
1646 | |
1647 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, | 1560 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, |
1648 IPEndPoint addr, | 1561 IPEndPoint addr, |
1649 NetworkHandle network) { | 1562 NetworkHandle network) { |
1650 if (enable_non_blocking_io_ && | 1563 if (enable_non_blocking_io_ && |
1651 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { | 1564 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { |
1652 #if defined(OS_WIN) | 1565 #if defined(OS_WIN) |
1653 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); | 1566 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); |
1654 #endif | 1567 #endif |
1655 } | 1568 } |
1656 | 1569 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. | 1638 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. |
1726 | 1639 |
1727 std::unique_ptr<DatagramClientSocket> socket( | 1640 std::unique_ptr<DatagramClientSocket> socket( |
1728 client_socket_factory_->CreateDatagramClientSocket( | 1641 client_socket_factory_->CreateDatagramClientSocket( |
1729 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), | 1642 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), |
1730 net_log.net_log(), net_log.source())); | 1643 net_log.net_log(), net_log.source())); |
1731 | 1644 |
1732 // Passing in kInvalidNetworkHandle binds socket to default network. | 1645 // Passing in kInvalidNetworkHandle binds socket to default network. |
1733 int rv = ConfigureSocket(socket.get(), addr, | 1646 int rv = ConfigureSocket(socket.get(), addr, |
1734 NetworkChangeNotifier::kInvalidNetworkHandle); | 1647 NetworkChangeNotifier::kInvalidNetworkHandle); |
1735 if (rv != OK) | 1648 if (rv != OK) { |
1736 return rv; | 1649 return rv; |
| 1650 } |
1737 | 1651 |
1738 if (enable_port_selection) | 1652 if (enable_port_selection) { |
1739 DCHECK_LE(1u, port_suggester->call_count()); | 1653 DCHECK_LE(1u, port_suggester->call_count()); |
1740 else | 1654 } else { |
1741 DCHECK_EQ(0u, port_suggester->call_count()); | 1655 DCHECK_EQ(0u, port_suggester->call_count()); |
| 1656 } |
1742 | 1657 |
1743 if (!helper_.get()) { | 1658 if (!helper_.get()) { |
1744 helper_.reset( | 1659 helper_.reset( |
1745 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); | 1660 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); |
1746 } | 1661 } |
1747 | 1662 |
1748 if (!alarm_factory_.get()) { | 1663 if (!alarm_factory_.get()) { |
1749 alarm_factory_.reset(new QuicChromiumAlarmFactory( | 1664 alarm_factory_.reset(new QuicChromiumAlarmFactory( |
1750 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); | 1665 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); |
1751 } | 1666 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1845 alternative_service); | 1760 alternative_service); |
1846 } | 1761 } |
1847 | 1762 |
1848 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( | 1763 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( |
1849 const QuicServerId& server_id) { | 1764 const QuicServerId& server_id) { |
1850 QuicCryptoClientConfig::CachedState* cached = | 1765 QuicCryptoClientConfig::CachedState* cached = |
1851 crypto_config_.LookupOrCreate(server_id); | 1766 crypto_config_.LookupOrCreate(server_id); |
1852 return cached->IsEmpty(); | 1767 return cached->IsEmpty(); |
1853 } | 1768 } |
1854 | 1769 |
1855 QuicAsyncStatus QuicStreamFactory::StartCertVerifyJob( | |
1856 const QuicServerId& server_id, | |
1857 int cert_verify_flags, | |
1858 const BoundNetLog& net_log) { | |
1859 if (!race_cert_verification_) | |
1860 return QUIC_FAILURE; | |
1861 QuicCryptoClientConfig::CachedState* cached = | |
1862 crypto_config_.LookupOrCreate(server_id); | |
1863 if (!cached || cached->certs().empty() || | |
1864 HasActiveCertVerifierJob(server_id)) { | |
1865 return QUIC_FAILURE; | |
1866 } | |
1867 std::unique_ptr<CertVerifierJob> cert_verifier_job( | |
1868 new CertVerifierJob(server_id, cert_verify_flags, net_log)); | |
1869 QuicAsyncStatus status = cert_verifier_job->Run( | |
1870 &crypto_config_, | |
1871 base::Bind(&QuicStreamFactory::OnCertVerifyJobComplete, | |
1872 base::Unretained(this), cert_verifier_job.get())); | |
1873 if (status == QUIC_PENDING) | |
1874 active_cert_verifier_jobs_[server_id] = std::move(cert_verifier_job); | |
1875 return status; | |
1876 } | |
1877 | |
1878 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( | 1770 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( |
1879 const QuicServerId& server_id, | 1771 const QuicServerId& server_id, |
1880 const std::unique_ptr<QuicServerInfo>& server_info, | 1772 const std::unique_ptr<QuicServerInfo>& server_info, |
1881 QuicConnectionId* connection_id) { | 1773 QuicConnectionId* connection_id) { |
1882 QuicCryptoClientConfig::CachedState* cached = | 1774 QuicCryptoClientConfig::CachedState* cached = |
1883 crypto_config_.LookupOrCreate(server_id); | 1775 crypto_config_.LookupOrCreate(server_id); |
1884 if (cached->has_server_designated_connection_id()) | 1776 if (cached->has_server_designated_connection_id()) |
1885 *connection_id = cached->GetNextServerDesignatedConnectionId(); | 1777 *connection_id = cached->GetNextServerDesignatedConnectionId(); |
1886 | 1778 |
1887 if (!cached->IsEmpty()) | 1779 if (!cached->IsEmpty()) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1989 // Since the session was active, there's no longer an | 1881 // Since the session was active, there's no longer an |
1990 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1882 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1991 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1883 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1992 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1884 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1993 // still race. | 1885 // still race. |
1994 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1886 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1995 alternative_service); | 1887 alternative_service); |
1996 } | 1888 } |
1997 | 1889 |
1998 } // namespace net | 1890 } // namespace net |
OLD | NEW |