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

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

Issue 2267603002: 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: Fixup 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 21 matching lines...) Expand all
32 #include "net/dns/host_resolver.h" 32 #include "net/dns/host_resolver.h"
33 #include "net/http/bidirectional_stream_impl.h" 33 #include "net/http/bidirectional_stream_impl.h"
34 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" 34 #include "net/quic/chromium/bidirectional_stream_quic_impl.h"
35 #include "net/quic/chromium/crypto/channel_id_chromium.h" 35 #include "net/quic/chromium/crypto/channel_id_chromium.h"
36 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" 36 #include "net/quic/chromium/crypto/proof_verifier_chromium.h"
37 #include "net/quic/chromium/port_suggester.h" 37 #include "net/quic/chromium/port_suggester.h"
38 #include "net/quic/chromium/quic_chromium_alarm_factory.h" 38 #include "net/quic/chromium/quic_chromium_alarm_factory.h"
39 #include "net/quic/chromium/quic_chromium_connection_helper.h" 39 #include "net/quic/chromium/quic_chromium_connection_helper.h"
40 #include "net/quic/chromium/quic_chromium_packet_reader.h" 40 #include "net/quic/chromium/quic_chromium_packet_reader.h"
41 #include "net/quic/chromium/quic_chromium_packet_writer.h" 41 #include "net/quic/chromium/quic_chromium_packet_writer.h"
42 #include "net/quic/core/crypto/proof_verifier.h"
43 #include "net/quic/core/crypto/properties_based_quic_server_info.h" 42 #include "net/quic/core/crypto/properties_based_quic_server_info.h"
44 #include "net/quic/core/crypto/quic_random.h" 43 #include "net/quic/core/crypto/quic_random.h"
45 #include "net/quic/core/crypto/quic_server_info.h" 44 #include "net/quic/core/crypto/quic_server_info.h"
46 #include "net/quic/core/quic_client_promised_info.h" 45 #include "net/quic/core/quic_client_promised_info.h"
47 #include "net/quic/core/quic_clock.h" 46 #include "net/quic/core/quic_clock.h"
48 #include "net/quic/core/quic_connection.h" 47 #include "net/quic/core/quic_connection.h"
49 #include "net/quic/core/quic_crypto_client_stream_factory.h" 48 #include "net/quic/core/quic_crypto_client_stream_factory.h"
50 #include "net/quic/core/quic_flags.h" 49 #include "net/quic/core/quic_flags.h"
51 #include "net/socket/client_socket_factory.h" 50 #include "net/socket/client_socket_factory.h"
52 #include "net/socket/socket_performance_watcher.h" 51 #include "net/socket/socket_performance_watcher.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 DCHECK(url.is_valid()); 184 DCHECK(url.is_valid());
186 return origin_filter_.Run(url); 185 return origin_filter_.Run(url);
187 } 186 }
188 187
189 private: 188 private:
190 const base::Callback<bool(const GURL&)> origin_filter_; 189 const base::Callback<bool(const GURL&)> origin_filter_;
191 }; 190 };
192 191
193 } // namespace 192 } // namespace
194 193
195 // Responsible for verifying the certificates saved in
196 // QuicCryptoClientConfig, and for notifying any associated requests when
197 // complete. Results from cert verification are ignored.
198 class QuicStreamFactory::CertVerifierJob {
199 public:
200 // ProofVerifierCallbackImpl is passed as the callback method to
201 // VerifyCertChain. The ProofVerifier calls this class with the result of cert
202 // verification when verification is performed asynchronously.
203 class ProofVerifierCallbackImpl : public ProofVerifierCallback {
204 public:
205 explicit ProofVerifierCallbackImpl(CertVerifierJob* job) : job_(job) {}
206
207 ~ProofVerifierCallbackImpl() override {}
208
209 void Run(bool ok,
210 const std::string& error_details,
211 std::unique_ptr<ProofVerifyDetails>* details) override {
212 if (job_ == nullptr)
213 return;
214 job_->verify_callback_ = nullptr;
215 job_->OnComplete();
216 }
217
218 void Cancel() { job_ = nullptr; }
219
220 private:
221 CertVerifierJob* job_;
222 };
223
224 CertVerifierJob(const QuicServerId& server_id,
225 int cert_verify_flags,
226 const BoundNetLog& net_log)
227 : server_id_(server_id),
228 verify_callback_(nullptr),
229 verify_context_(base::WrapUnique(
230 new ProofVerifyContextChromium(cert_verify_flags, net_log))),
231 start_time_(base::TimeTicks::Now()),
232 net_log_(net_log),
233 weak_factory_(this) {}
234
235 ~CertVerifierJob() {
236 if (verify_callback_)
237 verify_callback_->Cancel();
238 }
239
240 // Starts verification of certs cached in the |crypto_config|.
241 QuicAsyncStatus Run(QuicCryptoClientConfig* crypto_config,
242 const CompletionCallback& callback) {
243 QuicCryptoClientConfig::CachedState* cached =
244 crypto_config->LookupOrCreate(server_id_);
245 ProofVerifierCallbackImpl* verify_callback =
246 new ProofVerifierCallbackImpl(this);
247 QuicAsyncStatus status = crypto_config->proof_verifier()->VerifyCertChain(
248 server_id_.host(), cached->certs(), verify_context_.get(),
249 &verify_error_details_, &verify_details_,
250 std::unique_ptr<ProofVerifierCallback>(verify_callback));
251 if (status == QUIC_PENDING) {
252 verify_callback_ = verify_callback;
253 callback_ = callback;
254 }
255 return status;
256 }
257
258 void OnComplete() {
259 UMA_HISTOGRAM_TIMES("Net.QuicSession.CertVerifierJob.CompleteTime",
260 base::TimeTicks::Now() - start_time_);
261 if (!callback_.is_null())
262 callback_.Run(OK);
263 }
264
265 const QuicServerId& server_id() const { return server_id_; }
266
267 private:
268 QuicServerId server_id_;
269 ProofVerifierCallbackImpl* verify_callback_;
270 std::unique_ptr<ProofVerifyContext> verify_context_;
271 std::unique_ptr<ProofVerifyDetails> verify_details_;
272 std::string verify_error_details_;
273 base::TimeTicks start_time_;
274 const BoundNetLog net_log_;
275 CompletionCallback callback_;
276 base::WeakPtrFactory<CertVerifierJob> weak_factory_;
277
278 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob);
279 };
280
281 // Responsible for creating a new QUIC session to the specified server, and 194 // Responsible for creating a new QUIC session to the specified server, and
282 // for notifying any associated requests when complete. 195 // for notifying any associated requests when complete.
283 class QuicStreamFactory::Job { 196 class QuicStreamFactory::Job {
284 public: 197 public:
285 Job(QuicStreamFactory* factory, 198 Job(QuicStreamFactory* factory,
286 HostResolver* host_resolver, 199 HostResolver* host_resolver,
287 const QuicSessionKey& key, 200 const QuicSessionKey& key,
288 bool was_alternative_service_recently_broken, 201 bool was_alternative_service_recently_broken,
289 int cert_verify_flags, 202 int cert_verify_flags,
290 QuicServerInfo* server_info, 203 QuicServerInfo* server_info,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { 381 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() {
469 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. 382 // If we are waiting for WaitForDataReadyCallback, then cancel the callback.
470 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) 383 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE)
471 return; 384 return;
472 server_info_->CancelWaitForDataReadyCallback(); 385 server_info_->CancelWaitForDataReadyCallback();
473 OnIOComplete(OK); 386 OnIOComplete(OK);
474 } 387 }
475 388
476 int QuicStreamFactory::Job::DoResolveHost() { 389 int QuicStreamFactory::Job::DoResolveHost() {
477 // Start loading the data now, and wait for it after we resolve the host. 390 // Start loading the data now, and wait for it after we resolve the host.
478 if (server_info_) 391 if (server_info_) {
479 server_info_->Start(); 392 server_info_->Start();
393 }
480 394
481 io_state_ = STATE_RESOLVE_HOST_COMPLETE; 395 io_state_ = STATE_RESOLVE_HOST_COMPLETE;
482 return host_resolver_->Resolve( 396 return host_resolver_->Resolve(
483 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, 397 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY,
484 &address_list_, 398 &address_list_,
485 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), 399 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()),
486 &request_, net_log_); 400 &request_, net_log_);
487 } 401 }
488 402
489 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { 403 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) {
490 if (rv != OK) 404 if (rv != OK)
491 return rv; 405 return rv;
492 406
493 DCHECK(!factory_->HasActiveSession(key_.server_id())); 407 DCHECK(!factory_->HasActiveSession(key_.server_id()));
494 408
495 // Inform the factory of this resolution, which will set up 409 // Inform the factory of this resolution, which will set up
496 // a session alias, if possible. 410 // a session alias, if possible.
497 if (factory_->OnResolution(key_, address_list_)) 411 if (factory_->OnResolution(key_, address_list_)) {
498 return OK; 412 return OK;
413 }
499 414
500 if (server_info_) 415 if (server_info_)
501 io_state_ = STATE_LOAD_SERVER_INFO; 416 io_state_ = STATE_LOAD_SERVER_INFO;
502 else 417 else
503 io_state_ = STATE_CONNECT; 418 io_state_ = STATE_CONNECT;
504 return OK; 419 return OK;
505 } 420 }
506 421
507 int QuicStreamFactory::Job::DoLoadServerInfo() { 422 int QuicStreamFactory::Job::DoLoadServerInfo() {
508 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; 423 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 482
568 int rv = factory_->CreateSession( 483 int rv = factory_->CreateSession(
569 key_, cert_verify_flags_, std::move(server_info_), address_list_, 484 key_, cert_verify_flags_, std::move(server_info_), address_list_,
570 dns_resolution_end_time_, net_log_, &session_); 485 dns_resolution_end_time_, net_log_, &session_);
571 if (rv != OK) { 486 if (rv != OK) {
572 DCHECK(rv != ERR_IO_PENDING); 487 DCHECK(rv != ERR_IO_PENDING);
573 DCHECK(!session_); 488 DCHECK(!session_);
574 return rv; 489 return rv;
575 } 490 }
576 491
577 if (!session_->connection()->connected()) 492 if (!session_->connection()->connected()) {
578 return ERR_CONNECTION_CLOSED; 493 return ERR_CONNECTION_CLOSED;
494 }
579 495
580 session_->StartReading(); 496 session_->StartReading();
581 if (!session_->connection()->connected()) 497 if (!session_->connection()->connected()) {
582 return ERR_QUIC_PROTOCOL_ERROR; 498 return ERR_QUIC_PROTOCOL_ERROR;
499 }
583 bool require_confirmation = factory_->require_confirmation() || 500 bool require_confirmation = factory_->require_confirmation() ||
584 was_alternative_service_recently_broken_; 501 was_alternative_service_recently_broken_;
585 502
586 rv = session_->CryptoConnect( 503 rv = session_->CryptoConnect(
587 require_confirmation, 504 require_confirmation,
588 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 505 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
589 506
590 if (!session_->connection()->connected() && 507 if (!session_->connection()->connected() &&
591 session_->error() == QUIC_PROOF_INVALID) { 508 session_->error() == QUIC_PROOF_INVALID)
592 return ERR_QUIC_HANDSHAKE_FAILED; 509 return ERR_QUIC_HANDSHAKE_FAILED;
593 }
594 510
595 return rv; 511 return rv;
596 } 512 }
597 513
598 int QuicStreamFactory::Job::DoResumeConnect() { 514 int QuicStreamFactory::Job::DoResumeConnect() {
599 io_state_ = STATE_CONNECT_COMPLETE; 515 io_state_ = STATE_CONNECT_COMPLETE;
600 516
601 int rv = session_->ResumeCryptoConnect( 517 int rv = session_->ResumeCryptoConnect(
602 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); 518 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()));
603 519
604 return rv; 520 return rv;
605 } 521 }
606 522
607 int QuicStreamFactory::Job::DoConnectComplete(int rv) { 523 int QuicStreamFactory::Job::DoConnectComplete(int rv) {
608 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { 524 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) {
609 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); 525 num_sent_client_hellos_ += session_->GetNumSentClientHellos();
610 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) 526 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) {
611 return ERR_QUIC_HANDSHAKE_FAILED; 527 return ERR_QUIC_HANDSHAKE_FAILED;
528 }
612 // The handshake was rejected statelessly, so create another connection 529 // The handshake was rejected statelessly, so create another connection
613 // to resume the handshake. 530 // to resume the handshake.
614 io_state_ = STATE_CONNECT; 531 io_state_ = STATE_CONNECT;
615 return OK; 532 return OK;
616 } 533 }
617 534
618 if (rv != OK) 535 if (rv != OK)
619 return rv; 536 return rv;
620 537
621 DCHECK(!factory_->HasActiveSession(key_.server_id())); 538 DCHECK(!factory_->HasActiveSession(key_.server_id()));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 int socket_receive_buffer_size, 647 int socket_receive_buffer_size,
731 bool delay_tcp_race, 648 bool delay_tcp_race,
732 int max_server_configs_stored_in_properties, 649 int max_server_configs_stored_in_properties,
733 bool close_sessions_on_ip_change, 650 bool close_sessions_on_ip_change,
734 bool disable_quic_on_timeout_with_open_streams, 651 bool disable_quic_on_timeout_with_open_streams,
735 int idle_connection_timeout_seconds, 652 int idle_connection_timeout_seconds,
736 bool migrate_sessions_on_network_change, 653 bool migrate_sessions_on_network_change,
737 bool migrate_sessions_early, 654 bool migrate_sessions_early,
738 bool allow_server_migration, 655 bool allow_server_migration,
739 bool force_hol_blocking, 656 bool force_hol_blocking,
740 bool race_cert_verification,
741 const QuicTagVector& connection_options, 657 const QuicTagVector& connection_options,
742 bool enable_token_binding) 658 bool enable_token_binding)
743 : require_confirmation_(true), 659 : require_confirmation_(true),
744 net_log_(net_log), 660 net_log_(net_log),
745 host_resolver_(host_resolver), 661 host_resolver_(host_resolver),
746 client_socket_factory_(client_socket_factory), 662 client_socket_factory_(client_socket_factory),
747 http_server_properties_(http_server_properties), 663 http_server_properties_(http_server_properties),
748 transport_security_state_(transport_security_state), 664 transport_security_state_(transport_security_state),
749 cert_transparency_verifier_(cert_transparency_verifier), 665 cert_transparency_verifier_(cert_transparency_verifier),
750 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), 666 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 yield_after_duration_(QuicTime::Delta::FromMilliseconds( 703 yield_after_duration_(QuicTime::Delta::FromMilliseconds(
788 kQuicYieldAfterDurationMilliseconds)), 704 kQuicYieldAfterDurationMilliseconds)),
789 close_sessions_on_ip_change_(close_sessions_on_ip_change), 705 close_sessions_on_ip_change_(close_sessions_on_ip_change),
790 migrate_sessions_on_network_change_( 706 migrate_sessions_on_network_change_(
791 migrate_sessions_on_network_change && 707 migrate_sessions_on_network_change &&
792 NetworkChangeNotifier::AreNetworkHandlesSupported()), 708 NetworkChangeNotifier::AreNetworkHandlesSupported()),
793 migrate_sessions_early_(migrate_sessions_early && 709 migrate_sessions_early_(migrate_sessions_early &&
794 migrate_sessions_on_network_change_), 710 migrate_sessions_on_network_change_),
795 allow_server_migration_(allow_server_migration), 711 allow_server_migration_(allow_server_migration),
796 force_hol_blocking_(force_hol_blocking), 712 force_hol_blocking_(force_hol_blocking),
797 race_cert_verification_(race_cert_verification),
798 port_seed_(random_generator_->RandUint64()), 713 port_seed_(random_generator_->RandUint64()),
799 check_persisted_supports_quic_(true), 714 check_persisted_supports_quic_(true),
800 has_initialized_data_(false), 715 has_initialized_data_(false),
801 num_push_streams_created_(0), 716 num_push_streams_created_(0),
802 status_(OPEN), 717 status_(OPEN),
803 task_runner_(nullptr), 718 task_runner_(nullptr),
804 ssl_config_service_(ssl_config_service), 719 ssl_config_service_(ssl_config_service),
805 weak_factory_(this) { 720 weak_factory_(this) {
806 if (ssl_config_service_.get()) 721 if (ssl_config_service_.get())
807 ssl_config_service_->AddObserver(this); 722 ssl_config_service_->AddObserver(this);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); 770 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED);
856 while (!all_sessions_.empty()) { 771 while (!all_sessions_.empty()) {
857 delete all_sessions_.begin()->first; 772 delete all_sessions_.begin()->first;
858 all_sessions_.erase(all_sessions_.begin()); 773 all_sessions_.erase(all_sessions_.begin());
859 } 774 }
860 while (!active_jobs_.empty()) { 775 while (!active_jobs_.empty()) {
861 const QuicServerId server_id = active_jobs_.begin()->first; 776 const QuicServerId server_id = active_jobs_.begin()->first;
862 base::STLDeleteElements(&(active_jobs_[server_id])); 777 base::STLDeleteElements(&(active_jobs_[server_id]));
863 active_jobs_.erase(server_id); 778 active_jobs_.erase(server_id);
864 } 779 }
865 while (!active_cert_verifier_jobs_.empty())
866 active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin());
867 if (ssl_config_service_.get()) 780 if (ssl_config_service_.get())
868 ssl_config_service_->RemoveObserver(this); 781 ssl_config_service_->RemoveObserver(this);
869 if (migrate_sessions_on_network_change_) { 782 if (migrate_sessions_on_network_change_) {
870 NetworkChangeNotifier::RemoveNetworkObserver(this); 783 NetworkChangeNotifier::RemoveNetworkObserver(this);
871 } else if (close_sessions_on_ip_change_) { 784 } else if (close_sessions_on_ip_change_) {
872 NetworkChangeNotifier::RemoveIPAddressObserver(this); 785 NetworkChangeNotifier::RemoveIPAddressObserver(this);
873 } 786 }
874 } 787 }
875 788
876 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { 789 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 901
989 QuicServerInfo* quic_server_info = nullptr; 902 QuicServerInfo* quic_server_info = nullptr;
990 if (quic_server_info_factory_.get()) { 903 if (quic_server_info_factory_.get()) {
991 bool load_from_disk_cache = !disable_disk_cache_; 904 bool load_from_disk_cache = !disable_disk_cache_;
992 MaybeInitialize(); 905 MaybeInitialize();
993 if (!base::ContainsKey(quic_supported_servers_at_startup_, destination)) { 906 if (!base::ContainsKey(quic_supported_servers_at_startup_, destination)) {
994 // If there is no entry for QUIC, consider that as a new server and 907 // If there is no entry for QUIC, consider that as a new server and
995 // don't wait for Cache thread to load the data for that server. 908 // don't wait for Cache thread to load the data for that server.
996 load_from_disk_cache = false; 909 load_from_disk_cache = false;
997 } 910 }
998 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) 911 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) {
999 quic_server_info = quic_server_info_factory_->GetForServer(server_id); 912 quic_server_info = quic_server_info_factory_->GetForServer(server_id);
913 }
1000 } 914 }
1001 915
1002 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log));
1003
1004 QuicSessionKey key(destination, server_id); 916 QuicSessionKey key(destination, server_id);
1005 std::unique_ptr<Job> job( 917 std::unique_ptr<Job> job(
1006 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), 918 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id),
1007 cert_verify_flags, quic_server_info, net_log)); 919 cert_verify_flags, quic_server_info, net_log));
1008 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 920 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
1009 base::Unretained(this), job.get())); 921 base::Unretained(this), job.get()));
1010 if (rv == ERR_IO_PENDING) { 922 if (rv == ERR_IO_PENDING) {
1011 active_requests_[request] = server_id; 923 active_requests_[request] = server_id;
1012 job_requests_map_[server_id].insert(request); 924 job_requests_map_[server_id].insert(request);
1013 active_jobs_[server_id].insert(job.release()); 925 active_jobs_[server_id].insert(job.release());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 active_jobs_[key.server_id()].insert(aux_job); 966 active_jobs_[key.server_id()].insert(aux_job);
1055 task_runner_->PostTask(FROM_HERE, 967 task_runner_->PostTask(FROM_HERE,
1056 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, 968 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob,
1057 aux_job->GetWeakPtr())); 969 aux_job->GetWeakPtr()));
1058 } 970 }
1059 971
1060 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, 972 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key,
1061 const AddressList& address_list) { 973 const AddressList& address_list) {
1062 const QuicServerId& server_id(key.server_id()); 974 const QuicServerId& server_id(key.server_id());
1063 DCHECK(!HasActiveSession(server_id)); 975 DCHECK(!HasActiveSession(server_id));
1064 if (disable_connection_pooling_) 976 if (disable_connection_pooling_) {
1065 return false; 977 return false;
978 }
1066 for (const IPEndPoint& address : address_list) { 979 for (const IPEndPoint& address : address_list) {
1067 if (!base::ContainsKey(ip_aliases_, address)) 980 if (!base::ContainsKey(ip_aliases_, address))
1068 continue; 981 continue;
1069 982
1070 const SessionSet& sessions = ip_aliases_[address]; 983 const SessionSet& sessions = ip_aliases_[address];
1071 for (QuicChromiumClientSession* session : sessions) { 984 for (QuicChromiumClientSession* session : sessions) {
1072 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) 985 if (!session->CanPool(server_id.host(), server_id.privacy_mode()))
1073 continue; 986 continue;
1074 active_sessions_[server_id] = session; 987 active_sessions_[server_id] = session;
1075 session_aliases_[session].insert(key); 988 session_aliases_[session].insert(key);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 for (Job* other_job : active_jobs_[server_id]) { 1038 for (Job* other_job : active_jobs_[server_id]) {
1126 if (other_job != job) 1039 if (other_job != job)
1127 other_job->Cancel(); 1040 other_job->Cancel();
1128 } 1041 }
1129 1042
1130 base::STLDeleteElements(&(active_jobs_[server_id])); 1043 base::STLDeleteElements(&(active_jobs_[server_id]));
1131 active_jobs_.erase(server_id); 1044 active_jobs_.erase(server_id);
1132 job_requests_map_.erase(server_id); 1045 job_requests_map_.erase(server_id);
1133 } 1046 }
1134 1047
1135 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) {
1136 active_cert_verifier_jobs_.erase(job->server_id());
1137 }
1138
1139 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( 1048 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession(
1140 QuicChromiumClientSession* session) { 1049 QuicChromiumClientSession* session) {
1141 return std::unique_ptr<QuicHttpStream>( 1050 return std::unique_ptr<QuicHttpStream>(
1142 new QuicHttpStream(session->GetWeakPtr())); 1051 new QuicHttpStream(session->GetWeakPtr()));
1143 } 1052 }
1144 1053
1145 QuicChromiumClientSession::QuicDisabledReason 1054 QuicChromiumClientSession::QuicDisabledReason
1146 QuicStreamFactory::QuicDisabledReason(uint16_t port) const { 1055 QuicStreamFactory::QuicDisabledReason(uint16_t port) const {
1147 if (max_number_of_lossy_connections_ > 0 && 1056 if (max_number_of_lossy_connections_ > 0 &&
1148 number_of_lossy_connections_.find(port) != 1057 number_of_lossy_connections_.find(port) !=
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 1153
1245 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { 1154 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) {
1246 const AliasSet& aliases = session_aliases_[session]; 1155 const AliasSet& aliases = session_aliases_[session];
1247 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); 1156 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end();
1248 ++it) { 1157 ++it) {
1249 const QuicServerId& server_id = it->server_id(); 1158 const QuicServerId& server_id = it->server_id();
1250 DCHECK(active_sessions_.count(server_id)); 1159 DCHECK(active_sessions_.count(server_id));
1251 DCHECK_EQ(session, active_sessions_[server_id]); 1160 DCHECK_EQ(session, active_sessions_[server_id]);
1252 // Track sessions which have recently gone away so that we can disable 1161 // Track sessions which have recently gone away so that we can disable
1253 // port suggestions. 1162 // port suggestions.
1254 if (session->goaway_received()) 1163 if (session->goaway_received()) {
1255 gone_away_aliases_.insert(*it); 1164 gone_away_aliases_.insert(*it);
1165 }
1256 1166
1257 active_sessions_.erase(server_id); 1167 active_sessions_.erase(server_id);
1258 ProcessGoingAwaySession(session, server_id, true); 1168 ProcessGoingAwaySession(session, server_id, true);
1259 } 1169 }
1260 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false); 1170 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false);
1261 if (!aliases.empty()) { 1171 if (!aliases.empty()) {
1262 const IPEndPoint peer_address = session->connection()->peer_address(); 1172 const IPEndPoint peer_address = session->connection()->peer_address();
1263 ip_aliases_[peer_address].erase(session); 1173 ip_aliases_[peer_address].erase(session);
1264 if (ip_aliases_[peer_address].empty()) 1174 if (ip_aliases_[peer_address].empty()) {
1265 ip_aliases_.erase(peer_address); 1175 ip_aliases_.erase(peer_address);
1176 }
1266 } 1177 }
1267 session_aliases_.erase(session); 1178 session_aliases_.erase(session);
1268 } 1179 }
1269 1180
1270 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { 1181 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) {
1271 DCHECK(session); 1182 DCHECK(session);
1272 uint16_t port = session->server_id().port(); 1183 uint16_t port = session->server_id().port();
1273 if (IsQuicDisabled(port)) 1184 if (IsQuicDisabled(port))
1274 return; 1185 return;
1275 1186
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 MaybeDisableQuic(session); 1271 MaybeDisableQuic(session);
1361 OnSessionGoingAway(session); 1272 OnSessionGoingAway(session);
1362 delete session; 1273 delete session;
1363 all_sessions_.erase(session); 1274 all_sessions_.erase(session);
1364 } 1275 }
1365 1276
1366 void QuicStreamFactory::OnSessionConnectTimeout( 1277 void QuicStreamFactory::OnSessionConnectTimeout(
1367 QuicChromiumClientSession* session) { 1278 QuicChromiumClientSession* session) {
1368 const AliasSet& aliases = session_aliases_[session]; 1279 const AliasSet& aliases = session_aliases_[session];
1369 1280
1370 if (aliases.empty()) 1281 if (aliases.empty()) {
1371 return; 1282 return;
1283 }
1372 1284
1373 for (const QuicSessionKey& key : aliases) { 1285 for (const QuicSessionKey& key : aliases) {
1374 const QuicServerId& server_id = key.server_id(); 1286 const QuicServerId& server_id = key.server_id();
1375 SessionMap::iterator session_it = active_sessions_.find(server_id); 1287 SessionMap::iterator session_it = active_sessions_.find(server_id);
1376 DCHECK(session_it != active_sessions_.end()); 1288 DCHECK(session_it != active_sessions_.end());
1377 DCHECK_EQ(session, session_it->second); 1289 DCHECK_EQ(session, session_it->second);
1378 active_sessions_.erase(session_it); 1290 active_sessions_.erase(session_it);
1379 } 1291 }
1380 1292
1381 const IPEndPoint peer_address = session->connection()->peer_address(); 1293 const IPEndPoint peer_address = session->connection()->peer_address();
1382 ip_aliases_[peer_address].erase(session); 1294 ip_aliases_[peer_address].erase(session);
1383 if (ip_aliases_[peer_address].empty()) 1295 if (ip_aliases_[peer_address].empty()) {
1384 ip_aliases_.erase(peer_address); 1296 ip_aliases_.erase(peer_address);
1297 }
1385 QuicSessionKey key = *aliases.begin(); 1298 QuicSessionKey key = *aliases.begin();
1386 session_aliases_.erase(session); 1299 session_aliases_.erase(session);
1387 Job* job = new Job(this, host_resolver_, session, key); 1300 Job* job = new Job(this, host_resolver_, session, key);
1388 active_jobs_[key.server_id()].insert(job); 1301 active_jobs_[key.server_id()].insert(job);
1389 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 1302 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
1390 base::Unretained(this), job)); 1303 base::Unretained(this), job));
1391 DCHECK_EQ(ERR_IO_PENDING, rv); 1304 DCHECK_EQ(ERR_IO_PENDING, rv);
1392 } 1305 }
1393 1306
1394 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { 1307 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, 1385 MaybeMigrateOrCloseSessions(network, /*force_close=*/false,
1473 scoped_event_log.net_log()); 1386 scoped_event_log.net_log());
1474 } 1387 }
1475 1388
1476 NetworkHandle QuicStreamFactory::FindAlternateNetwork( 1389 NetworkHandle QuicStreamFactory::FindAlternateNetwork(
1477 NetworkHandle old_network) { 1390 NetworkHandle old_network) {
1478 // Find a new network that sessions bound to |old_network| can be migrated to. 1391 // Find a new network that sessions bound to |old_network| can be migrated to.
1479 NetworkChangeNotifier::NetworkList network_list; 1392 NetworkChangeNotifier::NetworkList network_list;
1480 NetworkChangeNotifier::GetConnectedNetworks(&network_list); 1393 NetworkChangeNotifier::GetConnectedNetworks(&network_list);
1481 for (NetworkHandle new_network : network_list) { 1394 for (NetworkHandle new_network : network_list) {
1482 if (new_network != old_network) 1395 if (new_network != old_network) {
1483 return new_network; 1396 return new_network;
1397 }
1484 } 1398 }
1485 return NetworkChangeNotifier::kInvalidNetworkHandle; 1399 return NetworkChangeNotifier::kInvalidNetworkHandle;
1486 } 1400 }
1487 1401
1488 void QuicStreamFactory::MaybeMigrateOrCloseSessions( 1402 void QuicStreamFactory::MaybeMigrateOrCloseSessions(
1489 NetworkHandle network, 1403 NetworkHandle network,
1490 bool force_close, 1404 bool force_close,
1491 const BoundNetLog& bound_net_log) { 1405 const BoundNetLog& bound_net_log) {
1492 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); 1406 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network);
1493 NetworkHandle new_network = FindAlternateNetwork(network); 1407 NetworkHandle new_network = FindAlternateNetwork(network);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. 1599 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check.
1686 if (active_sessions_.empty()) 1600 if (active_sessions_.empty())
1687 return false; 1601 return false;
1688 return base::ContainsKey(active_sessions_, server_id); 1602 return base::ContainsKey(active_sessions_, server_id);
1689 } 1603 }
1690 1604
1691 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { 1605 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const {
1692 return base::ContainsKey(active_jobs_, server_id); 1606 return base::ContainsKey(active_jobs_, server_id);
1693 } 1607 }
1694 1608
1695 bool QuicStreamFactory::HasActiveCertVerifierJob(
1696 const QuicServerId& server_id) const {
1697 return base::ContainsKey(active_cert_verifier_jobs_, server_id);
1698 }
1699
1700 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, 1609 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket,
1701 IPEndPoint addr, 1610 IPEndPoint addr,
1702 NetworkHandle network) { 1611 NetworkHandle network) {
1703 if (enable_non_blocking_io_) 1612 if (enable_non_blocking_io_)
1704 socket->UseNonBlockingIO(); 1613 socket->UseNonBlockingIO();
1705 1614
1706 int rv; 1615 int rv;
1707 if (migrate_sessions_on_network_change_) { 1616 if (migrate_sessions_on_network_change_) {
1708 // If caller leaves network unspecified, use current default network. 1617 // If caller leaves network unspecified, use current default network.
1709 if (network == NetworkChangeNotifier::kInvalidNetworkHandle) { 1618 if (network == NetworkChangeNotifier::kInvalidNetworkHandle) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. 1683 DatagramSocket::DEFAULT_BIND; // Use OS to randomize.
1775 1684
1776 std::unique_ptr<DatagramClientSocket> socket( 1685 std::unique_ptr<DatagramClientSocket> socket(
1777 client_socket_factory_->CreateDatagramClientSocket( 1686 client_socket_factory_->CreateDatagramClientSocket(
1778 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), 1687 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester),
1779 net_log.net_log(), net_log.source())); 1688 net_log.net_log(), net_log.source()));
1780 1689
1781 // Passing in kInvalidNetworkHandle binds socket to default network. 1690 // Passing in kInvalidNetworkHandle binds socket to default network.
1782 int rv = ConfigureSocket(socket.get(), addr, 1691 int rv = ConfigureSocket(socket.get(), addr,
1783 NetworkChangeNotifier::kInvalidNetworkHandle); 1692 NetworkChangeNotifier::kInvalidNetworkHandle);
1784 if (rv != OK) 1693 if (rv != OK) {
1785 return rv; 1694 return rv;
1695 }
1786 1696
1787 if (enable_port_selection) 1697 if (enable_port_selection) {
1788 DCHECK_LE(1u, port_suggester->call_count()); 1698 DCHECK_LE(1u, port_suggester->call_count());
1789 else 1699 } else {
1790 DCHECK_EQ(0u, port_suggester->call_count()); 1700 DCHECK_EQ(0u, port_suggester->call_count());
1701 }
1791 1702
1792 if (!helper_.get()) { 1703 if (!helper_.get()) {
1793 helper_.reset( 1704 helper_.reset(
1794 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); 1705 new QuicChromiumConnectionHelper(clock_.get(), random_generator_));
1795 } 1706 }
1796 1707
1797 if (!alarm_factory_.get()) { 1708 if (!alarm_factory_.get()) {
1798 alarm_factory_.reset(new QuicChromiumAlarmFactory( 1709 alarm_factory_.reset(new QuicChromiumAlarmFactory(
1799 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); 1710 base::ThreadTaskRunnerHandle::Get().get(), clock_.get()));
1800 } 1711 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 alternative_service); 1805 alternative_service);
1895 } 1806 }
1896 1807
1897 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( 1808 bool QuicStreamFactory::CryptoConfigCacheIsEmpty(
1898 const QuicServerId& server_id) { 1809 const QuicServerId& server_id) {
1899 QuicCryptoClientConfig::CachedState* cached = 1810 QuicCryptoClientConfig::CachedState* cached =
1900 crypto_config_.LookupOrCreate(server_id); 1811 crypto_config_.LookupOrCreate(server_id);
1901 return cached->IsEmpty(); 1812 return cached->IsEmpty();
1902 } 1813 }
1903 1814
1904 QuicAsyncStatus QuicStreamFactory::StartCertVerifyJob(
1905 const QuicServerId& server_id,
1906 int cert_verify_flags,
1907 const BoundNetLog& net_log) {
1908 if (!race_cert_verification_)
1909 return QUIC_FAILURE;
1910 QuicCryptoClientConfig::CachedState* cached =
1911 crypto_config_.LookupOrCreate(server_id);
1912 if (!cached || cached->certs().empty() ||
1913 HasActiveCertVerifierJob(server_id)) {
1914 return QUIC_FAILURE;
1915 }
1916 std::unique_ptr<CertVerifierJob> cert_verifier_job(
1917 new CertVerifierJob(server_id, cert_verify_flags, net_log));
1918 QuicAsyncStatus status = cert_verifier_job->Run(
1919 &crypto_config_,
1920 base::Bind(&QuicStreamFactory::OnCertVerifyJobComplete,
1921 base::Unretained(this), cert_verifier_job.get()));
1922 if (status == QUIC_PENDING)
1923 active_cert_verifier_jobs_[server_id] = std::move(cert_verifier_job);
1924 return status;
1925 }
1926
1927 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( 1815 void QuicStreamFactory::InitializeCachedStateInCryptoConfig(
1928 const QuicServerId& server_id, 1816 const QuicServerId& server_id,
1929 const std::unique_ptr<QuicServerInfo>& server_info, 1817 const std::unique_ptr<QuicServerInfo>& server_info,
1930 QuicConnectionId* connection_id) { 1818 QuicConnectionId* connection_id) {
1931 QuicCryptoClientConfig::CachedState* cached = 1819 QuicCryptoClientConfig::CachedState* cached =
1932 crypto_config_.LookupOrCreate(server_id); 1820 crypto_config_.LookupOrCreate(server_id);
1933 if (cached->has_server_designated_connection_id()) 1821 if (cached->has_server_designated_connection_id())
1934 *connection_id = cached->GetNextServerDesignatedConnectionId(); 1822 *connection_id = cached->GetNextServerDesignatedConnectionId();
1935 1823
1936 if (!cached->IsEmpty()) 1824 if (!cached->IsEmpty())
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 // Since the session was active, there's no longer an 1926 // Since the session was active, there's no longer an
2039 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1927 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
2040 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1928 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
2041 // it as recently broken, which means that 0-RTT will be disabled but we'll 1929 // it as recently broken, which means that 0-RTT will be disabled but we'll
2042 // still race. 1930 // still race.
2043 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1931 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
2044 alternative_service); 1932 alternative_service);
2045 } 1933 }
2046 1934
2047 } // namespace net 1935 } // 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