| 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 <ostream> | 7 #include <ostream> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 max_disabled_reasons_(3), | 314 max_disabled_reasons_(3), |
| 315 threshold_timeouts_with_open_streams_(2), | 315 threshold_timeouts_with_open_streams_(2), |
| 316 threshold_public_resets_post_handshake_(2), | 316 threshold_public_resets_post_handshake_(2), |
| 317 receive_buffer_size_(0), | 317 receive_buffer_size_(0), |
| 318 delay_tcp_race_(true), | 318 delay_tcp_race_(true), |
| 319 close_sessions_on_ip_change_(false), | 319 close_sessions_on_ip_change_(false), |
| 320 disable_quic_on_timeout_with_open_streams_(false), | 320 disable_quic_on_timeout_with_open_streams_(false), |
| 321 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), | 321 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
| 322 migrate_sessions_on_network_change_(false), | 322 migrate_sessions_on_network_change_(false), |
| 323 migrate_sessions_early_(false), | 323 migrate_sessions_early_(false), |
| 324 force_hol_blocking_(false), | 324 force_hol_blocking_(false) { |
| 325 race_cert_verification_(false) { | |
| 326 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 325 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 327 } | 326 } |
| 328 | 327 |
| 329 ~QuicStreamFactoryTestBase() { | 328 ~QuicStreamFactoryTestBase() { |
| 330 // If |factory_| was initialized, then it took over ownership of |clock_|. | 329 // If |factory_| was initialized, then it took over ownership of |clock_|. |
| 331 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 330 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
| 332 if (!factory_) | 331 if (!factory_) { |
| 333 delete clock_; | 332 delete clock_; |
| 333 } |
| 334 } | 334 } |
| 335 | 335 |
| 336 void Initialize() { | 336 void Initialize() { |
| 337 DCHECK(!factory_); | 337 DCHECK(!factory_); |
| 338 factory_.reset(new QuicStreamFactory( | 338 factory_.reset(new QuicStreamFactory( |
| 339 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), | 339 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), |
| 340 &socket_factory_, &http_server_properties_, cert_verifier_.get(), | 340 &socket_factory_, &http_server_properties_, cert_verifier_.get(), |
| 341 &ct_policy_enforcer_, channel_id_service_.get(), | 341 &ct_policy_enforcer_, channel_id_service_.get(), |
| 342 &transport_security_state_, cert_transparency_verifier_.get(), | 342 &transport_security_state_, cert_transparency_verifier_.get(), |
| 343 /*SocketPerformanceWatcherFactory*/ nullptr, | 343 /*SocketPerformanceWatcherFactory*/ nullptr, |
| 344 &crypto_client_stream_factory_, &random_generator_, clock_, | 344 &crypto_client_stream_factory_, &random_generator_, clock_, |
| 345 kDefaultMaxPacketSize, string(), SupportedVersions(version_), | 345 kDefaultMaxPacketSize, string(), SupportedVersions(version_), |
| 346 enable_port_selection_, always_require_handshake_confirmation_, | 346 enable_port_selection_, always_require_handshake_confirmation_, |
| 347 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 347 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
| 348 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 348 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
| 349 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, | 349 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, |
| 350 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 350 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
| 351 threshold_public_resets_post_handshake_, receive_buffer_size_, | 351 threshold_public_resets_post_handshake_, receive_buffer_size_, |
| 352 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, | 352 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
| 353 close_sessions_on_ip_change_, | 353 close_sessions_on_ip_change_, |
| 354 disable_quic_on_timeout_with_open_streams_, | 354 disable_quic_on_timeout_with_open_streams_, |
| 355 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | 355 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, |
| 356 migrate_sessions_early_, force_hol_blocking_, race_cert_verification_, | 356 migrate_sessions_early_, force_hol_blocking_, QuicTagVector(), |
| 357 QuicTagVector(), /*enable_token_binding*/ false)); | 357 /*enable_token_binding*/ false)); |
| 358 factory_->set_require_confirmation(false); | 358 factory_->set_require_confirmation(false); |
| 359 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 359 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
| 360 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 360 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
| 361 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 361 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void InitializeConnectionMigrationTest( | 364 void InitializeConnectionMigrationTest( |
| 365 NetworkChangeNotifier::NetworkList connected_networks) { | 365 NetworkChangeNotifier::NetworkList connected_networks) { |
| 366 scoped_mock_network_change_notifier_.reset( | 366 scoped_mock_network_change_notifier_.reset( |
| 367 new ScopedMockNetworkChangeNotifier()); | 367 new ScopedMockNetworkChangeNotifier()); |
| 368 MockNetworkChangeNotifier* mock_ncn = | 368 MockNetworkChangeNotifier* mock_ncn = |
| 369 scoped_mock_network_change_notifier_->mock_network_change_notifier(); | 369 scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 370 mock_ncn->ForceNetworkHandlesSupported(); | 370 mock_ncn->ForceNetworkHandlesSupported(); |
| 371 mock_ncn->SetConnectedNetworksList(connected_networks); | 371 mock_ncn->SetConnectedNetworksList(connected_networks); |
| 372 migrate_sessions_on_network_change_ = true; | 372 migrate_sessions_on_network_change_ = true; |
| 373 migrate_sessions_early_ = true; | 373 migrate_sessions_early_ = true; |
| 374 Initialize(); | 374 Initialize(); |
| 375 } | 375 } |
| 376 | 376 |
| 377 bool HasActiveSession(const HostPortPair& host_port_pair) { | 377 bool HasActiveSession(const HostPortPair& host_port_pair) { |
| 378 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 378 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 379 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); | 379 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
| 380 } | 380 } |
| 381 | 381 |
| 382 bool HasActiveCertVerifierJob(const QuicServerId& server_id) { | |
| 383 return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), | |
| 384 server_id); | |
| 385 } | |
| 386 | |
| 387 QuicChromiumClientSession* GetActiveSession( | 382 QuicChromiumClientSession* GetActiveSession( |
| 388 const HostPortPair& host_port_pair) { | 383 const HostPortPair& host_port_pair) { |
| 389 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); | 384 QuicServerId server_id(host_port_pair, PRIVACY_MODE_DISABLED); |
| 390 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); | 385 return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
| 391 } | 386 } |
| 392 | 387 |
| 393 std::unique_ptr<QuicHttpStream> CreateFromSession( | 388 std::unique_ptr<QuicHttpStream> CreateFromSession( |
| 394 const HostPortPair& host_port_pair) { | 389 const HostPortPair& host_port_pair) { |
| 395 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); | 390 QuicChromiumClientSession* session = GetActiveSession(host_port_pair); |
| 396 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 391 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 int threshold_timeouts_with_open_streams_; | 540 int threshold_timeouts_with_open_streams_; |
| 546 int threshold_public_resets_post_handshake_; | 541 int threshold_public_resets_post_handshake_; |
| 547 int receive_buffer_size_; | 542 int receive_buffer_size_; |
| 548 bool delay_tcp_race_; | 543 bool delay_tcp_race_; |
| 549 bool close_sessions_on_ip_change_; | 544 bool close_sessions_on_ip_change_; |
| 550 bool disable_quic_on_timeout_with_open_streams_; | 545 bool disable_quic_on_timeout_with_open_streams_; |
| 551 int idle_connection_timeout_seconds_; | 546 int idle_connection_timeout_seconds_; |
| 552 bool migrate_sessions_on_network_change_; | 547 bool migrate_sessions_on_network_change_; |
| 553 bool migrate_sessions_early_; | 548 bool migrate_sessions_early_; |
| 554 bool force_hol_blocking_; | 549 bool force_hol_blocking_; |
| 555 bool race_cert_verification_; | |
| 556 }; | 550 }; |
| 557 | 551 |
| 558 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 552 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 559 public ::testing::TestWithParam<TestParams> { | 553 public ::testing::TestWithParam<TestParams> { |
| 560 protected: | 554 protected: |
| 561 QuicStreamFactoryTest() | 555 QuicStreamFactoryTest() |
| 562 : QuicStreamFactoryTestBase(GetParam().version, | 556 : QuicStreamFactoryTestBase(GetParam().version, |
| 563 GetParam().enable_connection_racing) {} | 557 GetParam().enable_connection_racing) {} |
| 564 }; | 558 }; |
| 565 | 559 |
| (...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4135 EXPECT_TRUE(cached2->GetServerConfig()); | 4129 EXPECT_TRUE(cached2->GetServerConfig()); |
| 4136 EXPECT_EQ(server_config2, cached2->server_config()); | 4130 EXPECT_EQ(server_config2, cached2->server_config()); |
| 4137 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | 4131 EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 4138 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | 4132 EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 4139 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | 4133 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 4140 EXPECT_EQ(signature2, cached2->signature()); | 4134 EXPECT_EQ(signature2, cached2->signature()); |
| 4141 ASSERT_EQ(1U, cached->certs().size()); | 4135 ASSERT_EQ(1U, cached->certs().size()); |
| 4142 EXPECT_EQ(test_cert2, cached2->certs()[0]); | 4136 EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 4143 } | 4137 } |
| 4144 | 4138 |
| 4145 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { | |
| 4146 Initialize(); | |
| 4147 | |
| 4148 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 4149 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); | |
| 4150 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 4151 | |
| 4152 // Save current state of |race_cert_verification|. | |
| 4153 bool race_cert_verification = | |
| 4154 QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); | |
| 4155 | |
| 4156 // Load server config. | |
| 4157 HostPortPair host_port_pair("test.example.com", kDefaultServerPort); | |
| 4158 QuicServerId quic_server_id(host_port_pair_, privacy_mode_); | |
| 4159 QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); | |
| 4160 | |
| 4161 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); | |
| 4162 | |
| 4163 // Start CertVerifyJob. | |
| 4164 QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( | |
| 4165 factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); | |
| 4166 EXPECT_NE(QUIC_FAILURE, status); | |
| 4167 | |
| 4168 if (status == QUIC_PENDING) { | |
| 4169 // Verify CertVerifierJob has started. | |
| 4170 EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); | |
| 4171 | |
| 4172 while (HasActiveCertVerifierJob(quic_server_id)) { | |
| 4173 base::RunLoop().RunUntilIdle(); | |
| 4174 } | |
| 4175 } | |
| 4176 // Verify CertVerifierJob has finished. | |
| 4177 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); | |
| 4178 | |
| 4179 // Start a QUIC request. | |
| 4180 QuicStreamRequest request(factory_.get()); | |
| 4181 EXPECT_EQ(ERR_IO_PENDING, | |
| 4182 request.Request(host_port_pair_, privacy_mode_, | |
| 4183 /*cert_verify_flags=*/0, url_, "GET", net_log_, | |
| 4184 callback_.callback())); | |
| 4185 | |
| 4186 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 4187 | |
| 4188 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | |
| 4189 EXPECT_TRUE(stream.get()); | |
| 4190 | |
| 4191 // Restore |race_cert_verification|. | |
| 4192 QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), | |
| 4193 race_cert_verification); | |
| 4194 | |
| 4195 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 4196 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 4197 | |
| 4198 // Verify there are no outstanding CertVerifierJobs after request has | |
| 4199 // finished. | |
| 4200 EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); | |
| 4201 } | |
| 4202 | |
| 4203 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { | 4139 TEST_P(QuicStreamFactoryTest, QuicDoingZeroRTT) { |
| 4204 Initialize(); | 4140 Initialize(); |
| 4205 | 4141 |
| 4206 factory_->set_require_confirmation(true); | 4142 factory_->set_require_confirmation(true); |
| 4207 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); | 4143 QuicServerId quic_server_id(host_port_pair_, PRIVACY_MODE_DISABLED); |
| 4208 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4144 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
| 4209 | 4145 |
| 4210 factory_->set_require_confirmation(false); | 4146 factory_->set_require_confirmation(false); |
| 4211 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); | 4147 EXPECT_FALSE(factory_->ZeroRTTEnabledFor(quic_server_id)); |
| 4212 | 4148 |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4768 EXPECT_NE(session1, session2); | 4704 EXPECT_NE(session1, session2); |
| 4769 | 4705 |
| 4770 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); | 4706 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); |
| 4771 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); | 4707 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); |
| 4772 | 4708 |
| 4773 EXPECT_TRUE(AllDataConsumed()); | 4709 EXPECT_TRUE(AllDataConsumed()); |
| 4774 } | 4710 } |
| 4775 | 4711 |
| 4776 } // namespace test | 4712 } // namespace test |
| 4777 } // namespace net | 4713 } // namespace net |
| OLD | NEW |