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 | 8 |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 enable_connection_racing_(enable_connection_racing), | 287 enable_connection_racing_(enable_connection_racing), |
288 enable_non_blocking_io_(true), | 288 enable_non_blocking_io_(true), |
289 disable_disk_cache_(false), | 289 disable_disk_cache_(false), |
290 prefer_aes_(false), | 290 prefer_aes_(false), |
291 max_number_of_lossy_connections_(0), | 291 max_number_of_lossy_connections_(0), |
292 packet_loss_threshold_(1.0f), | 292 packet_loss_threshold_(1.0f), |
293 max_disabled_reasons_(3), | 293 max_disabled_reasons_(3), |
294 threshold_timeouts_with_open_streams_(2), | 294 threshold_timeouts_with_open_streams_(2), |
295 threshold_public_resets_post_handshake_(2), | 295 threshold_public_resets_post_handshake_(2), |
296 receive_buffer_size_(0), | 296 receive_buffer_size_(0), |
| 297 delay_tcp_race_(true), |
297 close_sessions_on_ip_change_(false), | 298 close_sessions_on_ip_change_(false), |
298 disable_quic_on_timeout_with_open_streams_(false), | 299 disable_quic_on_timeout_with_open_streams_(false), |
299 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), | 300 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
300 migrate_sessions_on_network_change_(false), | 301 migrate_sessions_on_network_change_(false), |
301 migrate_sessions_early_(false) { | 302 migrate_sessions_early_(false) { |
302 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 303 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
303 } | 304 } |
304 | 305 |
305 ~QuicStreamFactoryTestBase() { | 306 ~QuicStreamFactoryTestBase() { |
306 // If |factory_| was initialized, then it took over ownership of |clock_|. | 307 // If |factory_| was initialized, then it took over ownership of |clock_|. |
(...skipping 11 matching lines...) Expand all Loading... |
318 &transport_security_state_, cert_transparency_verifier_.get(), | 319 &transport_security_state_, cert_transparency_verifier_.get(), |
319 /*SocketPerformanceWatcherFactory*/ nullptr, | 320 /*SocketPerformanceWatcherFactory*/ nullptr, |
320 &crypto_client_stream_factory_, &random_generator_, clock_, | 321 &crypto_client_stream_factory_, &random_generator_, clock_, |
321 kDefaultMaxPacketSize, std::string(), SupportedVersions(version_), | 322 kDefaultMaxPacketSize, std::string(), SupportedVersions(version_), |
322 enable_port_selection_, always_require_handshake_confirmation_, | 323 enable_port_selection_, always_require_handshake_confirmation_, |
323 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 324 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
324 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 325 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
325 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, | 326 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, |
326 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 327 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
327 threshold_public_resets_post_handshake_, receive_buffer_size_, | 328 threshold_public_resets_post_handshake_, receive_buffer_size_, |
328 /*max_server_configs_stored_in_properties*/ 0, | 329 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
329 close_sessions_on_ip_change_, | 330 close_sessions_on_ip_change_, |
330 disable_quic_on_timeout_with_open_streams_, | 331 disable_quic_on_timeout_with_open_streams_, |
331 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | 332 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, |
332 migrate_sessions_early_, QuicTagVector(), | 333 migrate_sessions_early_, QuicTagVector(), |
333 /*enable_token_binding*/ false)); | 334 /*enable_token_binding*/ false)); |
334 factory_->set_require_confirmation(false); | 335 factory_->set_require_confirmation(false); |
335 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 336 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
336 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 337 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
337 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 338 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
338 } | 339 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 bool enable_connection_racing_; | 508 bool enable_connection_racing_; |
508 bool enable_non_blocking_io_; | 509 bool enable_non_blocking_io_; |
509 bool disable_disk_cache_; | 510 bool disable_disk_cache_; |
510 bool prefer_aes_; | 511 bool prefer_aes_; |
511 int max_number_of_lossy_connections_; | 512 int max_number_of_lossy_connections_; |
512 double packet_loss_threshold_; | 513 double packet_loss_threshold_; |
513 int max_disabled_reasons_; | 514 int max_disabled_reasons_; |
514 int threshold_timeouts_with_open_streams_; | 515 int threshold_timeouts_with_open_streams_; |
515 int threshold_public_resets_post_handshake_; | 516 int threshold_public_resets_post_handshake_; |
516 int receive_buffer_size_; | 517 int receive_buffer_size_; |
| 518 bool delay_tcp_race_; |
517 bool close_sessions_on_ip_change_; | 519 bool close_sessions_on_ip_change_; |
518 bool disable_quic_on_timeout_with_open_streams_; | 520 bool disable_quic_on_timeout_with_open_streams_; |
519 int idle_connection_timeout_seconds_; | 521 int idle_connection_timeout_seconds_; |
520 bool migrate_sessions_on_network_change_; | 522 bool migrate_sessions_on_network_change_; |
521 bool migrate_sessions_early_; | 523 bool migrate_sessions_early_; |
522 }; | 524 }; |
523 | 525 |
524 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 526 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
525 public ::testing::TestWithParam<TestParams> { | 527 public ::testing::TestWithParam<TestParams> { |
526 protected: | 528 protected: |
(...skipping 3116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3643 EXPECT_TRUE(socket_data3.AllReadDataConsumed()); | 3645 EXPECT_TRUE(socket_data3.AllReadDataConsumed()); |
3644 EXPECT_TRUE(socket_data3.AllWriteDataConsumed()); | 3646 EXPECT_TRUE(socket_data3.AllWriteDataConsumed()); |
3645 EXPECT_TRUE(socket_data4.AllReadDataConsumed()); | 3647 EXPECT_TRUE(socket_data4.AllReadDataConsumed()); |
3646 EXPECT_TRUE(socket_data4.AllWriteDataConsumed()); | 3648 EXPECT_TRUE(socket_data4.AllWriteDataConsumed()); |
3647 } | 3649 } |
3648 | 3650 |
3649 TEST_P(QuicStreamFactoryTest, EnableDelayTcpRace) { | 3651 TEST_P(QuicStreamFactoryTest, EnableDelayTcpRace) { |
3650 Initialize(); | 3652 Initialize(); |
3651 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 3653 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
3652 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3654 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3655 bool delay_tcp_race = QuicStreamFactoryPeer::GetDelayTcpRace(factory_.get()); |
| 3656 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), false); |
3653 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 3657 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
3654 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); | 3658 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
3655 socket_factory_.AddSocketDataProvider(&socket_data); | 3659 socket_factory_.AddSocketDataProvider(&socket_data); |
3656 | 3660 |
3657 ServerNetworkStats stats1; | 3661 ServerNetworkStats stats1; |
3658 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 3662 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
3659 url::SchemeHostPort server("https", kDefaultServerHostName, | 3663 url::SchemeHostPort server("https", kDefaultServerHostName, |
3660 kDefaultServerPort); | 3664 kDefaultServerPort); |
3661 http_server_properties_.SetServerNetworkStats(server, stats1); | 3665 http_server_properties_.SetServerNetworkStats(server, stats1); |
3662 | 3666 |
3663 crypto_client_stream_factory_.set_handshake_mode( | 3667 crypto_client_stream_factory_.set_handshake_mode( |
3664 MockCryptoClientStream::ZERO_RTT); | 3668 MockCryptoClientStream::ZERO_RTT); |
3665 host_resolver_.set_synchronous_mode(true); | 3669 host_resolver_.set_synchronous_mode(true); |
3666 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), | 3670 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
3667 "192.168.0.1", ""); | 3671 "192.168.0.1", ""); |
3668 | 3672 |
3669 QuicStreamRequest request(factory_.get()); | 3673 QuicStreamRequest request(factory_.get()); |
3670 EXPECT_EQ(ERR_IO_PENDING, | 3674 EXPECT_EQ(ERR_IO_PENDING, |
3671 request.Request(host_port_pair_, privacy_mode_, | 3675 request.Request(host_port_pair_, privacy_mode_, |
3672 /*cert_verify_flags=*/0, url_, "POST", net_log_, | 3676 /*cert_verify_flags=*/0, url_, "POST", net_log_, |
3673 callback_.callback())); | 3677 callback_.callback())); |
3674 | 3678 |
| 3679 // If we don't delay TCP connection, then time delay should be 0. |
| 3680 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), false); |
| 3681 EXPECT_FALSE(factory_->delay_tcp_race()); |
| 3682 EXPECT_EQ(base::TimeDelta(), request.GetTimeDelayForWaitingJob()); |
| 3683 |
| 3684 // Enable |delay_tcp_race_| param and verify delay is one RTT and that |
| 3685 // server supports QUIC. |
| 3686 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), true); |
| 3687 EXPECT_TRUE(factory_->delay_tcp_race()); |
3675 EXPECT_EQ(base::TimeDelta::FromMicroseconds(15), | 3688 EXPECT_EQ(base::TimeDelta::FromMicroseconds(15), |
3676 request.GetTimeDelayForWaitingJob()); | 3689 request.GetTimeDelayForWaitingJob()); |
3677 | 3690 |
3678 // Confirm the handshake and verify that the stream is created. | 3691 // Confirm the handshake and verify that the stream is created. |
3679 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( | 3692 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
3680 QuicSession::HANDSHAKE_CONFIRMED); | 3693 QuicSession::HANDSHAKE_CONFIRMED); |
3681 | 3694 |
3682 EXPECT_EQ(OK, callback_.WaitForResult()); | 3695 EXPECT_EQ(OK, callback_.WaitForResult()); |
3683 | 3696 |
3684 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 3697 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
3685 EXPECT_TRUE(stream.get()); | 3698 EXPECT_TRUE(stream.get()); |
3686 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3699 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
3687 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3700 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3701 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), delay_tcp_race); |
3688 } | 3702 } |
3689 | 3703 |
3690 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { | 3704 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
3691 idle_connection_timeout_seconds_ = 500; | 3705 idle_connection_timeout_seconds_ = 500; |
3692 Initialize(); | 3706 Initialize(); |
3693 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 3707 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
3694 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 3708 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
3695 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); | 3709 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); |
3696 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); | 3710 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); |
3697 | 3711 |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4326 EXPECT_NE(session1, session2); | 4340 EXPECT_NE(session1, session2); |
4327 | 4341 |
4328 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); | 4342 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); |
4329 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); | 4343 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); |
4330 | 4344 |
4331 EXPECT_TRUE(AllDataConsumed()); | 4345 EXPECT_TRUE(AllDataConsumed()); |
4332 } | 4346 } |
4333 | 4347 |
4334 } // namespace test | 4348 } // namespace test |
4335 } // namespace net | 4349 } // namespace net |
OLD | NEW |