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 allow_server_migration_(false), |
324 force_hol_blocking_(false) { | 325 force_hol_blocking_(false) { |
325 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 326 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
326 } | 327 } |
327 | 328 |
328 ~QuicStreamFactoryTestBase() { | 329 ~QuicStreamFactoryTestBase() { |
329 // If |factory_| was initialized, then it took over ownership of |clock_|. | 330 // If |factory_| was initialized, then it took over ownership of |clock_|. |
330 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 331 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
331 if (!factory_) { | 332 if (!factory_) { |
332 delete clock_; | 333 delete clock_; |
333 } | 334 } |
(...skipping 12 matching lines...) Expand all Loading... |
346 enable_port_selection_, always_require_handshake_confirmation_, | 347 enable_port_selection_, always_require_handshake_confirmation_, |
347 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 348 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
348 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 349 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
349 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, | 350 prefer_aes_, max_number_of_lossy_connections_, packet_loss_threshold_, |
350 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 351 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
351 threshold_public_resets_post_handshake_, receive_buffer_size_, | 352 threshold_public_resets_post_handshake_, receive_buffer_size_, |
352 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, | 353 delay_tcp_race_, /*max_server_configs_stored_in_properties*/ 0, |
353 close_sessions_on_ip_change_, | 354 close_sessions_on_ip_change_, |
354 disable_quic_on_timeout_with_open_streams_, | 355 disable_quic_on_timeout_with_open_streams_, |
355 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, | 356 idle_connection_timeout_seconds_, migrate_sessions_on_network_change_, |
356 migrate_sessions_early_, force_hol_blocking_, QuicTagVector(), | 357 migrate_sessions_early_, allow_server_migration_, force_hol_blocking_, |
357 /*enable_token_binding*/ false)); | 358 QuicTagVector(), /*enable_token_binding*/ false)); |
358 factory_->set_require_confirmation(false); | 359 factory_->set_require_confirmation(false); |
359 EXPECT_FALSE(factory_->has_quic_server_info_factory()); | 360 EXPECT_FALSE(factory_->has_quic_server_info_factory()); |
360 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 361 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
361 EXPECT_TRUE(factory_->has_quic_server_info_factory()); | 362 EXPECT_TRUE(factory_->has_quic_server_info_factory()); |
362 } | 363 } |
363 | 364 |
364 void InitializeConnectionMigrationTest( | 365 void InitializeConnectionMigrationTest( |
365 NetworkChangeNotifier::NetworkList connected_networks) { | 366 NetworkChangeNotifier::NetworkList connected_networks) { |
366 scoped_mock_network_change_notifier_.reset( | 367 scoped_mock_network_change_notifier_.reset( |
367 new ScopedMockNetworkChangeNotifier()); | 368 new ScopedMockNetworkChangeNotifier()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 int max_disabled_reasons_; | 540 int max_disabled_reasons_; |
540 int threshold_timeouts_with_open_streams_; | 541 int threshold_timeouts_with_open_streams_; |
541 int threshold_public_resets_post_handshake_; | 542 int threshold_public_resets_post_handshake_; |
542 int receive_buffer_size_; | 543 int receive_buffer_size_; |
543 bool delay_tcp_race_; | 544 bool delay_tcp_race_; |
544 bool close_sessions_on_ip_change_; | 545 bool close_sessions_on_ip_change_; |
545 bool disable_quic_on_timeout_with_open_streams_; | 546 bool disable_quic_on_timeout_with_open_streams_; |
546 int idle_connection_timeout_seconds_; | 547 int idle_connection_timeout_seconds_; |
547 bool migrate_sessions_on_network_change_; | 548 bool migrate_sessions_on_network_change_; |
548 bool migrate_sessions_early_; | 549 bool migrate_sessions_early_; |
| 550 bool allow_server_migration_; |
549 bool force_hol_blocking_; | 551 bool force_hol_blocking_; |
550 }; | 552 }; |
551 | 553 |
552 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, | 554 class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
553 public ::testing::TestWithParam<TestParams> { | 555 public ::testing::TestWithParam<TestParams> { |
554 protected: | 556 protected: |
555 QuicStreamFactoryTest() | 557 QuicStreamFactoryTest() |
556 : QuicStreamFactoryTestBase(GetParam().version, | 558 : QuicStreamFactoryTestBase(GetParam().version, |
557 GetParam().enable_connection_racing) {} | 559 GetParam().enable_connection_racing) {} |
558 }; | 560 }; |
(...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2648 ERR_QUIC_PROTOCOL_ERROR, | 2650 ERR_QUIC_PROTOCOL_ERROR, |
2649 stream->SendRequest(request_headers, &response, callback_.callback())); | 2651 stream->SendRequest(request_headers, &response, callback_.callback())); |
2650 | 2652 |
2651 // Migration fails, and session is marked as going away. | 2653 // Migration fails, and session is marked as going away. |
2652 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | 2654 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
2653 | 2655 |
2654 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 2656 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
2655 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 2657 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
2656 } | 2658 } |
2657 | 2659 |
| 2660 TEST_P(QuicStreamFactoryTest, ServerMigration) { |
| 2661 allow_server_migration_ = true; |
| 2662 Initialize(); |
| 2663 |
| 2664 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2665 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2666 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2667 |
| 2668 std::unique_ptr<QuicEncryptedPacket> request_packet( |
| 2669 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true)); |
| 2670 MockWrite writes1[] = {MockWrite(SYNCHRONOUS, request_packet->data(), |
| 2671 request_packet->length(), 1)}; |
| 2672 MockRead reads1[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 2673 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, |
| 2674 arraysize(writes1)); |
| 2675 socket_factory_.AddSocketDataProvider(&socket_data1); |
| 2676 |
| 2677 // Create request and QuicHttpStream. |
| 2678 QuicStreamRequest request(factory_.get()); |
| 2679 EXPECT_EQ(ERR_IO_PENDING, |
| 2680 request.Request(host_port_pair_, privacy_mode_, |
| 2681 /*cert_verify_flags=*/0, url_, "GET", net_log_, |
| 2682 callback_.callback())); |
| 2683 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 2684 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 2685 EXPECT_TRUE(stream.get()); |
| 2686 |
| 2687 // Cause QUIC stream to be created. |
| 2688 HttpRequestInfo request_info; |
| 2689 request_info.method = "GET"; |
| 2690 request_info.url = GURL("https://www.example.org/"); |
| 2691 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 2692 net_log_, CompletionCallback())); |
| 2693 |
| 2694 // Ensure that session is alive and active. |
| 2695 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2696 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2697 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2698 |
| 2699 // Send GET request on stream. |
| 2700 HttpResponseInfo response; |
| 2701 HttpRequestHeaders request_headers; |
| 2702 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2703 callback_.callback())); |
| 2704 |
| 2705 IPEndPoint ip; |
| 2706 session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 2707 DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 2708 << ip.port(); |
| 2709 |
| 2710 // Set up second socket data provider that is used after |
| 2711 // migration. The request is rewritten to this new socket, and the |
| 2712 // response to the request is read on this new socket. |
| 2713 std::unique_ptr<QuicEncryptedPacket> ping( |
| 2714 client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 2715 std::unique_ptr<QuicEncryptedPacket> client_rst( |
| 2716 client_maker_.MakeAckAndRstPacket(3, false, kClientDataStreamId1, |
| 2717 QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 2718 MockWrite writes2[] = { |
| 2719 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0), |
| 2720 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 3)}; |
| 2721 std::unique_ptr<QuicEncryptedPacket> response_headers_packet( |
| 2722 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false)); |
| 2723 MockRead reads2[] = {MockRead(ASYNC, response_headers_packet->data(), |
| 2724 response_headers_packet->length(), 1), |
| 2725 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
| 2726 SequencedSocketData socket_data2(reads2, arraysize(reads2), writes2, |
| 2727 arraysize(writes2)); |
| 2728 socket_factory_.AddSocketDataProvider(&socket_data2); |
| 2729 |
| 2730 const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 2731 const uint16_t kTestPort = 123; |
| 2732 factory_->MigrateSessionToNewPeerAddress( |
| 2733 session, IPEndPoint(IPAddress(kTestIpAddress), kTestPort), net_log_); |
| 2734 |
| 2735 session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 2736 DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 2737 << ip.port(); |
| 2738 |
| 2739 // The session should be alive and active. |
| 2740 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2741 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2742 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2743 |
| 2744 // Run the message loop so that data queued in the new socket is read by the |
| 2745 // packet reader. |
| 2746 base::RunLoop().RunUntilIdle(); |
| 2747 |
| 2748 // Verify that response headers on the migrated socket were delivered to the |
| 2749 // stream. |
| 2750 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2751 EXPECT_EQ(200, response.headers->response_code()); |
| 2752 |
| 2753 stream.reset(); |
| 2754 |
| 2755 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 2756 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 2757 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2758 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2759 } |
| 2760 |
2658 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { | 2761 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { |
2659 Initialize(); | 2762 Initialize(); |
2660 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 2763 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
2661 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2764 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2662 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 2765 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
2663 | 2766 |
2664 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 2767 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
2665 std::unique_ptr<QuicEncryptedPacket> rst(ConstructClientRstPacket()); | 2768 std::unique_ptr<QuicEncryptedPacket> rst(ConstructClientRstPacket()); |
2666 vector<MockWrite> writes; | 2769 vector<MockWrite> writes; |
2667 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); | 2770 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
(...skipping 2036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4704 EXPECT_NE(session1, session2); | 4807 EXPECT_NE(session1, session2); |
4705 | 4808 |
4706 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); | 4809 EXPECT_EQ(QuicServerId(origin1_, privacy_mode_), session1->server_id()); |
4707 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); | 4810 EXPECT_EQ(QuicServerId(origin2_, privacy_mode_), session2->server_id()); |
4708 | 4811 |
4709 EXPECT_TRUE(AllDataConsumed()); | 4812 EXPECT_TRUE(AllDataConsumed()); |
4710 } | 4813 } |
4711 | 4814 |
4712 } // namespace test | 4815 } // namespace test |
4713 } // namespace net | 4816 } // namespace net |
OLD | NEW |