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/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 max_number_of_lossy_connections_(0), | 315 max_number_of_lossy_connections_(0), |
316 packet_loss_threshold_(1.0f), | 316 packet_loss_threshold_(1.0f), |
317 max_disabled_reasons_(3), | 317 max_disabled_reasons_(3), |
318 threshold_timeouts_with_open_streams_(2), | 318 threshold_timeouts_with_open_streams_(2), |
319 threshold_public_resets_post_handshake_(2), | 319 threshold_public_resets_post_handshake_(2), |
320 receive_buffer_size_(0), | 320 receive_buffer_size_(0), |
321 delay_tcp_race_(true), | 321 delay_tcp_race_(true), |
322 close_sessions_on_ip_change_(false), | 322 close_sessions_on_ip_change_(false), |
323 disable_quic_on_timeout_with_open_streams_(false), | 323 disable_quic_on_timeout_with_open_streams_(false), |
324 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), | 324 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
| 325 reduced_ping_timeout_seconds_(kPingTimeoutSecs), |
325 packet_reader_yield_after_duration_milliseconds_( | 326 packet_reader_yield_after_duration_milliseconds_( |
326 kQuicYieldAfterDurationMilliseconds), | 327 kQuicYieldAfterDurationMilliseconds), |
327 migrate_sessions_on_network_change_(false), | 328 migrate_sessions_on_network_change_(false), |
328 migrate_sessions_early_(false), | 329 migrate_sessions_early_(false), |
329 allow_server_migration_(false), | 330 allow_server_migration_(false), |
330 force_hol_blocking_(false), | 331 force_hol_blocking_(false), |
331 race_cert_verification_(false) { | 332 race_cert_verification_(false) { |
332 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 333 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
333 } | 334 } |
334 | 335 |
(...skipping 16 matching lines...) Expand all Loading... |
351 kDefaultMaxPacketSize, string(), SupportedVersions(version_), | 352 kDefaultMaxPacketSize, string(), SupportedVersions(version_), |
352 enable_port_selection_, always_require_handshake_confirmation_, | 353 enable_port_selection_, always_require_handshake_confirmation_, |
353 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 354 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
354 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 355 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
355 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, | 356 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, |
356 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 357 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
357 threshold_public_resets_post_handshake_, receive_buffer_size_, | 358 threshold_public_resets_post_handshake_, receive_buffer_size_, |
358 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, | 359 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
359 close_sessions_on_ip_change_, | 360 close_sessions_on_ip_change_, |
360 disable_quic_on_timeout_with_open_streams_, | 361 disable_quic_on_timeout_with_open_streams_, |
361 idle_connection_timeout_seconds_, | 362 idle_connection_timeout_seconds_, reduced_ping_timeout_seconds_, |
362 packet_reader_yield_after_duration_milliseconds_, | 363 packet_reader_yield_after_duration_milliseconds_, |
363 migrate_sessions_on_network_change_, migrate_sessions_early_, | 364 migrate_sessions_on_network_change_, migrate_sessions_early_, |
364 allow_server_migration_, force_hol_blocking_, race_cert_verification_, | 365 allow_server_migration_, force_hol_blocking_, race_cert_verification_, |
365 QuicTagVector(), | 366 QuicTagVector(), |
366 /*enable_token_binding*/ false)); | 367 /*enable_token_binding*/ false)); |
367 factory_->set_require_confirmation(false); | 368 factory_->set_require_confirmation(false); |
368 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 369 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
369 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 370 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
370 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 371 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
371 } | 372 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 int max_number_of_lossy_connections_; | 611 int max_number_of_lossy_connections_; |
611 double packet_loss_threshold_; | 612 double packet_loss_threshold_; |
612 int max_disabled_reasons_; | 613 int max_disabled_reasons_; |
613 int threshold_timeouts_with_open_streams_; | 614 int threshold_timeouts_with_open_streams_; |
614 int threshold_public_resets_post_handshake_; | 615 int threshold_public_resets_post_handshake_; |
615 int receive_buffer_size_; | 616 int receive_buffer_size_; |
616 bool delay_tcp_race_; | 617 bool delay_tcp_race_; |
617 bool close_sessions_on_ip_change_; | 618 bool close_sessions_on_ip_change_; |
618 bool disable_quic_on_timeout_with_open_streams_; | 619 bool disable_quic_on_timeout_with_open_streams_; |
619 int idle_connection_timeout_seconds_; | 620 int idle_connection_timeout_seconds_; |
| 621 int reduced_ping_timeout_seconds_; |
620 int packet_reader_yield_after_duration_milliseconds_; | 622 int packet_reader_yield_after_duration_milliseconds_; |
621 bool migrate_sessions_on_network_change_; | 623 bool migrate_sessions_on_network_change_; |
622 bool migrate_sessions_early_; | 624 bool migrate_sessions_early_; |
623 bool allow_server_migration_; | 625 bool allow_server_migration_; |
624 bool force_hol_blocking_; | 626 bool force_hol_blocking_; |
625 bool race_cert_verification_; | 627 bool race_cert_verification_; |
626 }; | 628 }; |
627 | 629 |
628 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 630 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
629 public ::testing::TestWithParam<TestParams> { | 631 public ::testing::TestWithParam<TestParams> { |
(...skipping 2969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 0, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(factory_.get())); | 3601 0, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(factory_.get())); |
3600 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), | 3602 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), |
3601 host_port_pair_.port())); | 3603 host_port_pair_.port())); |
3602 | 3604 |
3603 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3605 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
3604 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3606 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
3605 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 3607 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
3606 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 3608 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
3607 } | 3609 } |
3608 | 3610 |
| 3611 TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { |
| 3612 reduced_ping_timeout_seconds_ = 10; |
| 3613 disable_disk_cache_ = true; |
| 3614 threshold_timeouts_with_open_streams_ = 2; |
| 3615 Initialize(); |
| 3616 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3617 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3618 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3619 |
| 3620 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3621 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), |
| 3622 host_port_pair_.port())); |
| 3623 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections( |
| 3624 factory_.get(), host_port_pair_.port())); |
| 3625 |
| 3626 MockQuicData socket_data; |
| 3627 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3628 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 3629 |
| 3630 MockQuicData socket_data2; |
| 3631 socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3632 socket_data2.AddSocketDataToFactory(&socket_factory_); |
| 3633 |
| 3634 HostPortPair server2(kServer2HostName, kDefaultServerPort); |
| 3635 |
| 3636 crypto_client_stream_factory_.set_handshake_mode( |
| 3637 MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 3638 host_resolver_.set_synchronous_mode(true); |
| 3639 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 3640 "192.168.0.1", ""); |
| 3641 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
| 3642 |
| 3643 // Quic should use default PING timeout when no previous connection times out |
| 3644 // with open stream. |
| 3645 EXPECT_EQ(QuicTime::Delta::FromSeconds(kPingTimeoutSecs), |
| 3646 QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 3647 QuicStreamRequest request(factory_.get()); |
| 3648 EXPECT_EQ(OK, request.Request(host_port_pair_, privacy_mode_, |
| 3649 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 3650 callback_.callback())); |
| 3651 |
| 3652 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3653 EXPECT_EQ(QuicTime::Delta::FromSeconds(kPingTimeoutSecs), |
| 3654 session->connection()->ping_timeout()); |
| 3655 |
| 3656 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 3657 EXPECT_TRUE(stream.get()); |
| 3658 HttpRequestInfo request_info; |
| 3659 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 3660 net_log_, CompletionCallback())); |
| 3661 |
| 3662 DVLOG(1) |
| 3663 << "Created 1st session and initialized a stream. Now trigger timeout"; |
| 3664 session->connection()->CloseConnection(QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 3665 ConnectionCloseBehavior::SILENT_CLOSE); |
| 3666 // Need to spin the loop now to ensure that |
| 3667 // QuicStreamFactory::OnSessionClosed() runs. |
| 3668 base::RunLoop run_loop; |
| 3669 run_loop.RunUntilIdle(); |
| 3670 |
| 3671 EXPECT_EQ( |
| 3672 1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(factory_.get())); |
| 3673 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), |
| 3674 host_port_pair_.port())); |
| 3675 |
| 3676 // The first connection times out with open stream, QUIC should reduce initial |
| 3677 // PING time for subsequent connections. |
| 3678 EXPECT_EQ(QuicTime::Delta::FromSeconds(10), |
| 3679 QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 3680 |
| 3681 // Test two-in-a-row timeouts with open streams. |
| 3682 DVLOG(1) << "Create 2nd session and timeout with open stream"; |
| 3683 TestCompletionCallback callback2; |
| 3684 QuicStreamRequest request2(factory_.get()); |
| 3685 EXPECT_EQ(OK, request2.Request(server2, privacy_mode_, |
| 3686 /*cert_verify_flags=*/0, url2_, "GET", |
| 3687 net_log_, callback2.callback())); |
| 3688 QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 3689 EXPECT_EQ(QuicTime::Delta::FromSeconds(10), |
| 3690 session2->connection()->ping_timeout()); |
| 3691 |
| 3692 std::unique_ptr<QuicHttpStream> stream2 = request2.CreateStream(); |
| 3693 EXPECT_TRUE(stream2.get()); |
| 3694 EXPECT_EQ(OK, stream2->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 3695 net_log_, CompletionCallback())); |
| 3696 session2->connection()->CloseConnection( |
| 3697 QUIC_NETWORK_IDLE_TIMEOUT, "test", ConnectionCloseBehavior::SILENT_CLOSE); |
| 3698 // Need to spin the loop now to ensure that |
| 3699 // QuicStreamFactory::OnSessionClosed() runs. |
| 3700 base::RunLoop run_loop2; |
| 3701 run_loop2.RunUntilIdle(); |
| 3702 EXPECT_EQ( |
| 3703 2, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(factory_.get())); |
| 3704 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), |
| 3705 host_port_pair_.port())); |
| 3706 EXPECT_EQ(QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS, |
| 3707 factory_->QuicDisabledReason(host_port_pair_.port())); |
| 3708 |
| 3709 // Verify that QUIC is un-disabled after a TCP job fails. |
| 3710 factory_->OnTcpJobCompleted(/*succeeded=*/false); |
| 3711 EXPECT_EQ( |
| 3712 0, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(factory_.get())); |
| 3713 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), |
| 3714 host_port_pair_.port())); |
| 3715 |
| 3716 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3717 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3718 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 3719 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 3720 } |
| 3721 |
3609 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfThree) { | 3722 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfThree) { |
3610 disable_disk_cache_ = true; | 3723 disable_disk_cache_ = true; |
3611 threshold_public_resets_post_handshake_ = 2; | 3724 threshold_public_resets_post_handshake_ = 2; |
3612 Initialize(); | 3725 Initialize(); |
3613 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 3726 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
3614 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3727 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
3615 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3728 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
3616 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3729 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
3617 | 3730 |
3618 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), | 3731 EXPECT_FALSE(QuicStreamFactoryPeer::IsQuicDisabled(factory_.get(), |
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5085 // Clear all cached states. | 5198 // Clear all cached states. |
5086 factory_->ClearCachedStatesInCryptoConfig( | 5199 factory_->ClearCachedStatesInCryptoConfig( |
5087 base::Callback<bool(const GURL&)>()); | 5200 base::Callback<bool(const GURL&)>()); |
5088 EXPECT_TRUE(test_cases[0].state->certs().empty()); | 5201 EXPECT_TRUE(test_cases[0].state->certs().empty()); |
5089 EXPECT_TRUE(test_cases[1].state->certs().empty()); | 5202 EXPECT_TRUE(test_cases[1].state->certs().empty()); |
5090 EXPECT_TRUE(test_cases[2].state->certs().empty()); | 5203 EXPECT_TRUE(test_cases[2].state->certs().empty()); |
5091 } | 5204 } |
5092 | 5205 |
5093 } // namespace test | 5206 } // namespace test |
5094 } // namespace net | 5207 } // namespace net |
OLD | NEW |