diff options
Diffstat (limited to 'chromium/net/quic')
41 files changed, 2268 insertions, 1615 deletions
diff --git a/chromium/net/quic/bidirectional_stream_quic_impl.cc b/chromium/net/quic/bidirectional_stream_quic_impl.cc index 68d2f64279f..9725e10dc7a 100644 --- a/chromium/net/quic/bidirectional_stream_quic_impl.cc +++ b/chromium/net/quic/bidirectional_stream_quic_impl.cc @@ -95,17 +95,17 @@ void BidirectionalStreamQuicImpl::Start( if (rv != OK) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, - weak_factory_.GetWeakPtr(), - session_->IsCryptoHandshakeConfirmed() - ? rv - : ERR_QUIC_HANDSHAKE_FAILED)); + FROM_HERE, base::BindOnce(&BidirectionalStreamQuicImpl::NotifyError, + weak_factory_.GetWeakPtr(), + session_->IsCryptoHandshakeConfirmed() + ? rv + : ERR_QUIC_HANDSHAKE_FAILED)); return; } base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnStreamReady, - weak_factory_.GetWeakPtr(), rv)); + FROM_HERE, base::BindOnce(&BidirectionalStreamQuicImpl::OnStreamReady, + weak_factory_.GetWeakPtr(), rv)); } void BidirectionalStreamQuicImpl::SendRequestHeaders() { @@ -113,8 +113,8 @@ void BidirectionalStreamQuicImpl::SendRequestHeaders() { int rv = WriteHeaders(); if (rv < 0) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, - weak_factory_.GetWeakPtr(), rv)); + FROM_HERE, base::BindOnce(&BidirectionalStreamQuicImpl::NotifyError, + weak_factory_.GetWeakPtr(), rv)); } } @@ -174,8 +174,8 @@ void BidirectionalStreamQuicImpl::SendvData( if (!stream_->IsOpen()) { LOG(ERROR) << "Trying to send data after stream has been closed."; base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, - weak_factory_.GetWeakPtr(), ERR_UNEXPECTED)); + FROM_HERE, base::BindOnce(&BidirectionalStreamQuicImpl::NotifyError, + weak_factory_.GetWeakPtr(), ERR_UNEXPECTED)); return; } @@ -186,8 +186,8 @@ void BidirectionalStreamQuicImpl::SendvData( int rv = WriteHeaders(); if (rv < 0) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, - weak_factory_.GetWeakPtr(), rv)); + FROM_HERE, base::BindOnce(&BidirectionalStreamQuicImpl::NotifyError, + weak_factory_.GetWeakPtr(), rv)); return; } } @@ -199,8 +199,9 @@ void BidirectionalStreamQuicImpl::SendvData( if (rv != ERR_IO_PENDING) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, - weak_factory_.GetWeakPtr(), rv)); + FROM_HERE, + base::BindOnce(&BidirectionalStreamQuicImpl::OnSendDataComplete, + weak_factory_.GetWeakPtr(), rv)); } } @@ -261,8 +262,9 @@ void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { } base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::ReadInitialHeaders, - weak_factory_.GetWeakPtr())); + FROM_HERE, + base::BindOnce(&BidirectionalStreamQuicImpl::ReadInitialHeaders, + weak_factory_.GetWeakPtr())); NotifyStreamReady(); } @@ -291,8 +293,9 @@ void BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete(int rv) { negotiated_protocol_ = kProtoQUIC; connect_timing_ = session_->GetConnectTiming(); base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::ReadTrailingHeaders, - weak_factory_.GetWeakPtr())); + FROM_HERE, + base::BindOnce(&BidirectionalStreamQuicImpl::ReadTrailingHeaders, + weak_factory_.GetWeakPtr())); if (delegate_) delegate_->OnHeadersReceived(initial_headers_); } @@ -369,8 +372,9 @@ void BidirectionalStreamQuicImpl::NotifyErrorImpl(int error, weak_factory_.InvalidateWeakPtrs(); if (notify_delegate_later) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyFailure, - weak_factory_.GetWeakPtr(), delegate, error)); + FROM_HERE, + base::BindOnce(&BidirectionalStreamQuicImpl::NotifyFailure, + weak_factory_.GetWeakPtr(), delegate, error)); } else { NotifyFailure(delegate, error); // |this| might be destroyed at this point. @@ -392,8 +396,8 @@ void BidirectionalStreamQuicImpl::NotifyStreamReady() { int rv = WriteHeaders(); if (rv < 0) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::NotifyError, - weak_factory_.GetWeakPtr(), rv)); + FROM_HERE, base::BindOnce(&BidirectionalStreamQuicImpl::NotifyError, + weak_factory_.GetWeakPtr(), rv)); return; } } diff --git a/chromium/net/quic/bidirectional_stream_quic_impl_unittest.cc b/chromium/net/quic/bidirectional_stream_quic_impl_unittest.cc index 90079c9b320..b0a6ae8ff7f 100644 --- a/chromium/net/quic/bidirectional_stream_quic_impl_unittest.cc +++ b/chromium/net/quic/bidirectional_stream_quic_impl_unittest.cc @@ -11,7 +11,9 @@ #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/time/default_tick_clock.h" #include "base/time/time.h" +#include "base/timer/timer.h" #include "net/base/completion_once_callback.h" #include "net/base/ip_address.h" #include "net/base/load_timing_info.h" @@ -511,17 +513,22 @@ class BidirectionalStreamQuicImplTest PRIVACY_MODE_DISABLED, SocketTag()), /*require_confirmation=*/false, /*migrate_session_early_v2=*/false, /*migrate_session_on_network_change_v2=*/false, - /*go_away_on_path_degrading*/ false, /*default_network=*/NetworkChangeNotifier::kInvalidNetworkHandle, + quic::QuicTime::Delta::FromMilliseconds( + kDefaultRetransmittableOnWireTimeoutMillisecs), + /*migrate_idle_session=*/false, + base::TimeDelta::FromSeconds(kDefaultIdleSessionMigrationPeriodSeconds), base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), kMaxMigrationsToNonDefaultNetworkOnWriteError, kMaxMigrationsToNonDefaultNetworkOnPathDegrading, kQuicYieldAfterPacketsRead, quic::QuicTime::Delta::FromMilliseconds( kQuicYieldAfterDurationMilliseconds), + /*go_away_on_path_degrading*/ false, client_headers_include_h2_stream_dependency_, /*cert_verify_flags=*/0, quic::test::DefaultQuicConfig(), &crypto_config_, "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, + base::DefaultTickClock::GetInstance(), base::ThreadTaskRunnerHandle::Get().get(), /*socket_performance_watcher=*/nullptr, net_log().bound().net_log())); session_->Initialize(); @@ -547,7 +554,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, bool fin, quic::QuicStreamOffset offset, @@ -561,7 +568,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, bool fin, quic::QuicStreamOffset offset, @@ -573,7 +580,7 @@ class BidirectionalStreamQuicImplTest // Construct a data packet with multiple data frames std::unique_ptr<quic::QuicReceivedPacket> ConstructClientMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, bool fin, quic::QuicStreamOffset offset, @@ -588,7 +595,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin, RequestPriority request_priority, size_t* spdy_headers_frame_length) { @@ -598,7 +605,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructRequestHeadersPacketInner( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool fin, RequestPriority request_priority, @@ -610,7 +617,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructRequestHeadersPacketInner( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool fin, RequestPriority request_priority, @@ -631,7 +638,7 @@ class BidirectionalStreamQuicImplTest std::unique_ptr<quic::QuicReceivedPacket> ConstructRequestHeadersAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin, RequestPriority request_priority, quic::QuicStreamOffset* header_stream_offset, @@ -650,7 +657,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructResponseHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin, spdy::SpdyHeaderBlock response_headers, size_t* spdy_headers_frame_length, @@ -661,7 +668,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructResponseHeadersPacketInner( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool fin, spdy::SpdyHeaderBlock response_headers, @@ -673,7 +680,7 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructResponseTrailersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin, spdy::SpdyHeaderBlock trailers, size_t* spdy_headers_frame_length, @@ -684,41 +691,42 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientRstStreamPacket( - quic::QuicPacketNumber packet_number) { + uint64_t packet_number) { return ConstructRstStreamCancelledPacket(packet_number, !kIncludeVersion, 0, &client_maker_); } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerRstStreamPacket( - quic::QuicPacketNumber packet_number) { + uint64_t packet_number) { return ConstructRstStreamCancelledPacket(packet_number, !kIncludeVersion, 0, &server_maker_); } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientEarlyRstStreamPacket( - quic::QuicPacketNumber packet_number) { + uint64_t packet_number) { return ConstructRstStreamCancelledPacket(packet_number, kIncludeVersion, 0, &client_maker_); } std::unique_ptr<quic::QuicReceivedPacket> ConstructRstStreamCancelledPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool include_version, size_t bytes_written, QuicTestPacketMaker* maker) { std::unique_ptr<quic::QuicReceivedPacket> packet( maker->MakeRstPacket(packet_number, include_version, stream_id_, - quic::QUIC_STREAM_CANCELLED, bytes_written)); + quic::QUIC_STREAM_CANCELLED, bytes_written, + /*include_stop_sending_if_v99=*/true)); DVLOG(2) << "packet(" << packet_number << "): " << std::endl << quic::QuicTextUtils::HexDump(packet->AsStringPiece()); return packet; } std::unique_ptr<quic::QuicReceivedPacket> - ConstructClientAckAndRstStreamPacket(quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + ConstructClientAckAndRstStreamPacket(uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckAndRstPacket( packet_number, !kIncludeVersion, stream_id_, quic::QUIC_STREAM_CANCELLED, largest_received, smallest_received, @@ -726,11 +734,11 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool fin, quic::QuicStreamOffset offset, quic::QuicStringPiece data, @@ -746,11 +754,11 @@ class BidirectionalStreamQuicImplTest std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool fin, quic::QuicStreamOffset offset, const std::vector<std::string> data_writes) { @@ -764,27 +772,27 @@ class BidirectionalStreamQuicImplTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, !kIncludeCongestionFeedback); } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return server_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, !kIncludeCongestionFeedback); } std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset* offset) { return client_maker_.MakeInitialSettingsPacket(packet_number, offset); } @@ -852,7 +860,7 @@ class BidirectionalStreamQuicImplTest HostPortPair destination_; }; -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( Version, BidirectionalStreamQuicImplTest, ::testing::Combine( @@ -863,8 +871,7 @@ TEST_P(BidirectionalStreamQuicImplTest, GetRequest) { SetRequest("GET", "/", DEFAULT_PRIORITY); size_t spdy_request_headers_frame_length; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); AddWrite(ConstructRequestHeadersPacketInner( 1, GetNthClientInitiatedBidirectionalStreamId(0), kFin, DEFAULT_PRIORITY, &spdy_request_headers_frame_length, &header_stream_offset)); @@ -925,7 +932,7 @@ TEST_P(BidirectionalStreamQuicImplTest, GetRequest) { size_t spdy_trailers_frame_length; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody)); + base::NumberToString(strlen(kResponseBody)); // Server sends trailers. ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, trailers.Clone(), &spdy_trailers_frame_length, &offset)); @@ -967,8 +974,7 @@ TEST_P(BidirectionalStreamQuicImplTest, GetRequest) { TEST_P(BidirectionalStreamQuicImplTest, LoadTimingTwoRequests) { SetRequest("GET", "/", DEFAULT_PRIORITY); quic::QuicStreamOffset offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); AddWrite(ConstructRequestHeadersPacketInner( 1, GetNthClientInitiatedBidirectionalStreamId(0), kFin, DEFAULT_PRIORITY, nullptr, &offset)); @@ -1153,7 +1159,7 @@ TEST_P(BidirectionalStreamQuicImplTest, CoalesceDataBuffersNotHeadersFrame) { spdy::SpdyHeaderBlock trailers; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody)); + base::NumberToString(strlen(kResponseBody)); // Server sends trailers. ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, trailers.Clone(), &spdy_trailers_frame_length, &offset)); @@ -1271,7 +1277,7 @@ TEST_P(BidirectionalStreamQuicImplTest, spdy::SpdyHeaderBlock trailers; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody)); + base::NumberToString(strlen(kResponseBody)); // Server sends trailers. ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, trailers.Clone(), &spdy_trailers_frame_length, &offset)); @@ -1404,7 +1410,7 @@ TEST_P(BidirectionalStreamQuicImplTest, spdy::SpdyHeaderBlock trailers; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody)); + base::NumberToString(strlen(kResponseBody)); // Server sends trailers. ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, trailers.Clone(), &spdy_trailers_frame_length, &offset)); @@ -1576,7 +1582,7 @@ TEST_P(BidirectionalStreamQuicImplTest, PostRequest) { spdy::SpdyHeaderBlock trailers; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody)); + base::NumberToString(strlen(kResponseBody)); // Server sends trailers. ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, trailers.Clone(), &spdy_trailers_frame_length, &offset)); @@ -1670,7 +1676,7 @@ TEST_P(BidirectionalStreamQuicImplTest, EarlyDataOverrideRequest) { spdy::SpdyHeaderBlock trailers; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody)); + base::NumberToString(strlen(kResponseBody)); // Server sends trailers. ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, trailers.Clone(), &spdy_trailers_frame_length, &offset)); @@ -1801,8 +1807,7 @@ TEST_P(BidirectionalStreamQuicImplTest, ServerSendsRstAfterHeaders) { SetRequest("GET", "/", DEFAULT_PRIORITY); size_t spdy_request_headers_frame_length; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); AddWrite(ConstructRequestHeadersPacketInner( 1, GetNthClientInitiatedBidirectionalStreamId(0), kFin, DEFAULT_PRIORITY, &spdy_request_headers_frame_length, &header_stream_offset)); @@ -1848,8 +1853,7 @@ TEST_P(BidirectionalStreamQuicImplTest, ServerSendsRstAfterReadData) { SetRequest("GET", "/", DEFAULT_PRIORITY); size_t spdy_request_headers_frame_length; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); AddWrite(ConstructRequestHeadersPacketInner( 1, GetNthClientInitiatedBidirectionalStreamId(0), kFin, DEFAULT_PRIORITY, &spdy_request_headers_frame_length, &header_stream_offset)); @@ -2323,8 +2327,7 @@ TEST_P(BidirectionalStreamQuicImplTest, AsyncFinRead) { TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnTrailersReceived) { SetRequest("GET", "/", DEFAULT_PRIORITY); size_t spdy_request_headers_frame_length; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, &spdy_request_headers_frame_length)); AddWrite(ConstructClientAckPacket(2, 3, 1, 2)); // Ack the data packet @@ -2380,7 +2383,7 @@ TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnTrailersReceived) { spdy::SpdyHeaderBlock trailers; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody)); + base::NumberToString(strlen(kResponseBody)); // Server sends trailers. ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, trailers.Clone(), &spdy_trailers_frame_length, &offset)); diff --git a/chromium/net/quic/crypto/channel_id_chromium.cc b/chromium/net/quic/crypto/channel_id_chromium.cc index 31e1b5419a5..6629eba3811 100644 --- a/chromium/net/quic/crypto/channel_id_chromium.cc +++ b/chromium/net/quic/crypto/channel_id_chromium.cc @@ -7,6 +7,7 @@ #include <utility> #include <vector> +#include "base/bind.h" #include "base/strings/string_util.h" #include "crypto/ec_private_key.h" #include "crypto/ec_signature_creator.h" diff --git a/chromium/net/quic/crypto/proof_test_chromium.cc b/chromium/net/quic/crypto/proof_test_chromium.cc index 8ca3f49e1c0..f26640e6d8c 100644 --- a/chromium/net/quic/crypto/proof_test_chromium.cc +++ b/chromium/net/quic/crypto/proof_test_chromium.cc @@ -122,7 +122,7 @@ class ProofTest : public ::testing::TestWithParam<quic::QuicTransportVersion> { } // namespace -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( QuicTransportVersion, ProofTest, ::testing::ValuesIn(quic::AllSupportedTransportVersions())); diff --git a/chromium/net/quic/crypto/proof_verifier_chromium_test.cc b/chromium/net/quic/crypto/proof_verifier_chromium_test.cc index b3ce7ca2147..f740d5958ee 100644 --- a/chromium/net/quic/crypto/proof_verifier_chromium_test.cc +++ b/chromium/net/quic/crypto/proof_verifier_chromium_test.cc @@ -155,7 +155,7 @@ class ProofVerifierChromiumTest : public ::testing::Test { base::FilePath()); std::string signature; source.GetProof(quic::QuicSocketAddress(), kTestHostname, kTestConfig, - quic::QUIC_VERSION_35, kTestChloHash, + quic::QUIC_VERSION_39, kTestChloHash, std::make_unique<SignatureSaver>(&signature)); return signature; } @@ -211,7 +211,7 @@ TEST_F(ProofVerifierChromiumTest, FailsIfCertFails) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -231,7 +231,7 @@ TEST_F(ProofVerifierChromiumTest, ValidSCTList) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, ct::GetSCTListForTesting(), kTestEmptySCT, verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -251,7 +251,7 @@ TEST_F(ProofVerifierChromiumTest, InvalidSCTList) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, ct::GetSCTListWithInvalidSCT(), kTestEmptySCT, verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -269,7 +269,7 @@ TEST_F(ProofVerifierChromiumTest, FailsIfSignatureFails) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, kTestConfig, verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -299,7 +299,7 @@ TEST_F(ProofVerifierChromiumTest, PreservesEVIfAllowed) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -335,7 +335,7 @@ TEST_F(ProofVerifierChromiumTest, StripsEVIfNotAllowed) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -377,7 +377,7 @@ TEST_F(ProofVerifierChromiumTest, CTEVHistogramNonCompliant) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -423,7 +423,7 @@ TEST_F(ProofVerifierChromiumTest, CTEVHistogramCompliant) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -466,7 +466,7 @@ TEST_F(ProofVerifierChromiumTest, IsFatalErrorNotSetForNonFatalError) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -499,7 +499,7 @@ TEST_F(ProofVerifierChromiumTest, IsFatalErrorSetForFatalError) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -532,7 +532,7 @@ TEST_F(ProofVerifierChromiumTest, PKPEnforced) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kCTAndPKPHost, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kCTAndPKPHost, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -571,7 +571,7 @@ TEST_F(ProofVerifierChromiumTest, PKPBypassFlagSet) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kCTAndPKPHost, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kCTAndPKPHost, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -617,7 +617,7 @@ TEST_F(ProofVerifierChromiumTest, CTIsRequired) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -669,7 +669,7 @@ TEST_F(ProofVerifierChromiumTest, CTIsRequiredHistogramNonCompliant) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -720,7 +720,7 @@ TEST_F(ProofVerifierChromiumTest, CTIsRequiredHistogramCompliant) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -739,7 +739,7 @@ TEST_F(ProofVerifierChromiumTest, CTIsRequiredHistogramCompliant) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -777,7 +777,7 @@ TEST_F(ProofVerifierChromiumTest, CTIsNotRequiredHistogram) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -823,7 +823,7 @@ TEST_F(ProofVerifierChromiumTest, PKPAndCTBothTested) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kCTAndPKPHost, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kCTAndPKPHost, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_FAILURE, status); @@ -867,7 +867,7 @@ TEST_F(ProofVerifierChromiumTest, CTComplianceStatusHistogram) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -888,7 +888,7 @@ TEST_F(ProofVerifierChromiumTest, CTComplianceStatusHistogram) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); quic::QuicAsyncStatus status = proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); ASSERT_EQ(quic::QUIC_SUCCESS, status); @@ -932,7 +932,7 @@ TEST_F(ProofVerifierChromiumTest, CTRequirementsFlagNotMet) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); @@ -974,7 +974,7 @@ TEST_F(ProofVerifierChromiumTest, CTRequirementsFlagMet) { std::unique_ptr<DummyProofVerifierCallback> callback( new DummyProofVerifierCallback); proof_verifier.VerifyProof( - kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_35, + kTestHostname, kTestPort, kTestConfig, quic::QUIC_VERSION_39, kTestChloHash, certs_, kTestEmptySCT, GetTestSignature(), verify_context_.get(), &error_details_, &details_, std::move(callback)); diff --git a/chromium/net/quic/mock_crypto_client_stream.cc b/chromium/net/quic/mock_crypto_client_stream.cc index ce94f88f486..f589ff1f03b 100644 --- a/chromium/net/quic/mock_crypto_client_stream.cc +++ b/chromium/net/quic/mock_crypto_client_stream.cc @@ -20,7 +20,7 @@ using quic::ConnectionCloseBehavior; using quic::CryptoHandshakeMessage; using quic::CryptoMessageParser; using quic::ENCRYPTION_FORWARD_SECURE; -using quic::ENCRYPTION_INITIAL; +using quic::ENCRYPTION_ZERO_RTT; using quic::kAESG; using quic::kC255; using quic::kDefaultMaxStreamsPerConnection; @@ -108,20 +108,20 @@ bool MockCryptoClientStream::CryptoConnect() { } if (use_mock_crypter_) { session()->connection()->SetDecrypter( - ENCRYPTION_INITIAL, + ENCRYPTION_ZERO_RTT, QuicMakeUnique<MockDecrypter>(Perspective::IS_CLIENT)); session()->connection()->SetEncrypter( - ENCRYPTION_INITIAL, + ENCRYPTION_ZERO_RTT, QuicMakeUnique<MockEncrypter>(Perspective::IS_CLIENT)); } else { session()->connection()->SetDecrypter( - ENCRYPTION_INITIAL, + ENCRYPTION_ZERO_RTT, QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); session()->connection()->SetEncrypter( - ENCRYPTION_INITIAL, + ENCRYPTION_ZERO_RTT, QuicMakeUnique<NullEncrypter>(Perspective::IS_CLIENT)); } - session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); + session()->connection()->SetDefaultEncryptionLevel(ENCRYPTION_ZERO_RTT); session()->OnCryptoHandshakeEvent( QuicSession::ENCRYPTION_FIRST_ESTABLISHED); break; diff --git a/chromium/net/quic/mock_decrypter.cc b/chromium/net/quic/mock_decrypter.cc index 347efe360b6..86e5e26ac1b 100644 --- a/chromium/net/quic/mock_decrypter.cc +++ b/chromium/net/quic/mock_decrypter.cc @@ -39,8 +39,7 @@ bool MockDecrypter::SetDiversificationNonce(const DiversificationNonce& nonce) { return true; } -bool MockDecrypter::DecryptPacket(QuicTransportVersion version, - QuicPacketNumber /*packet_number*/, +bool MockDecrypter::DecryptPacket(uint64_t /*packet_number*/, QuicStringPiece associated_data, QuicStringPiece ciphertext, char* output, diff --git a/chromium/net/quic/mock_decrypter.h b/chromium/net/quic/mock_decrypter.h index adb818c76cd..57642da0b0f 100644 --- a/chromium/net/quic/mock_decrypter.h +++ b/chromium/net/quic/mock_decrypter.h @@ -33,8 +33,7 @@ class MockDecrypter : public quic::QuicDecrypter { bool SetPreliminaryKey(quic::QuicStringPiece key) override; bool SetDiversificationNonce( const quic::DiversificationNonce& nonce) override; - bool DecryptPacket(quic::QuicTransportVersion version, - quic::QuicPacketNumber packet_number, + bool DecryptPacket(uint64_t packet_number, quic::QuicStringPiece associated_data, quic::QuicStringPiece ciphertext, char* output, diff --git a/chromium/net/quic/mock_encrypter.cc b/chromium/net/quic/mock_encrypter.cc index d4f7e536bb7..97c9f9d298f 100644 --- a/chromium/net/quic/mock_encrypter.cc +++ b/chromium/net/quic/mock_encrypter.cc @@ -29,8 +29,7 @@ bool MockEncrypter::SetIV(QuicStringPiece iv) { return iv.empty(); } -bool MockEncrypter::EncryptPacket(QuicTransportVersion version, - QuicPacketNumber /*packet_number*/, +bool MockEncrypter::EncryptPacket(uint64_t /*packet_number*/, QuicStringPiece associated_data, QuicStringPiece plaintext, char* output, diff --git a/chromium/net/quic/mock_encrypter.h b/chromium/net/quic/mock_encrypter.h index 786babfcbad..7547327c5da 100644 --- a/chromium/net/quic/mock_encrypter.h +++ b/chromium/net/quic/mock_encrypter.h @@ -28,8 +28,7 @@ class MockEncrypter : public quic::QuicEncrypter { bool SetKey(quic::QuicStringPiece key) override; bool SetNoncePrefix(quic::QuicStringPiece nonce_prefix) override; bool SetIV(quic::QuicStringPiece iv) override; - bool EncryptPacket(quic::QuicTransportVersion version, - quic::QuicPacketNumber packet_number, + bool EncryptPacket(uint64_t packet_number, quic::QuicStringPiece associated_data, quic::QuicStringPiece plaintext, char* output, diff --git a/chromium/net/quic/quic_chromium_alarm_factory.cc b/chromium/net/quic/quic_chromium_alarm_factory.cc index 5475bfb8b19..9124fb0ee97 100644 --- a/chromium/net/quic/quic_chromium_alarm_factory.cc +++ b/chromium/net/quic/quic_chromium_alarm_factory.cc @@ -47,7 +47,7 @@ class QuicChromeAlarm : public quic::QuicAlarm { } task_runner_->PostDelayedTask( FROM_HERE, - base::Bind(&QuicChromeAlarm::OnAlarm, weak_factory_.GetWeakPtr()), + base::BindOnce(&QuicChromeAlarm::OnAlarm, weak_factory_.GetWeakPtr()), base::TimeDelta::FromMicroseconds(delay_us)); task_deadline_ = deadline(); } diff --git a/chromium/net/quic/quic_chromium_client_session.cc b/chromium/net/quic/quic_chromium_client_session.cc index 276e0491f1d..6889aad8446 100644 --- a/chromium/net/quic/quic_chromium_client_session.cc +++ b/chromium/net/quic/quic_chromium_client_session.cc @@ -6,6 +6,7 @@ #include <utility> +#include "base/bind.h" #include "base/callback_helpers.h" #include "base/location.h" #include "base/memory/ptr_util.h" @@ -17,6 +18,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/time/tick_clock.h" #include "base/trace_event/memory_usage_estimator.h" #include "base/values.h" #include "net/base/io_buffer.h" @@ -73,12 +75,6 @@ const int kDefaultRTTMilliSecs = 300; // The maximum size of uncompressed QUIC headers that will be allowed. const size_t kMaxUncompressedHeaderSize = 256 * 1024; -// The maximum time allowed to have no retransmittable packets on the wire -// (after sending the first retransmittable packet) if -// |migrate_session_early_v2_| is true. PING frames will be sent as needed to -// enforce this. -const size_t kDefaultRetransmittableOnWireTimeoutMillisecs = 100; - // Histograms for tracking down the crashes from http://crbug.com/354669 // Note: these values must be kept in sync with the corresponding values in: // tools/metrics/histograms/histograms.xml @@ -136,7 +132,7 @@ std::unique_ptr<base::Value> NetLogProbingResultCallback( bool is_success, NetLogCaptureMode capture_mode) { std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); - dict->SetString("network", base::Int64ToString(network)); + dict->SetString("network", base::NumberToString(network)); dict->SetString("peer address", peer_address->ToString()); dict->SetBoolean("is_success", is_success); return std::move(dict); @@ -585,8 +581,8 @@ void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure( // Avoid re-entrancy if the callback calls into the session. base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, - base::Bind(&QuicChromiumClientSession::StreamRequest::DoCallback, - weak_factory_.GetWeakPtr(), rv)); + base::BindOnce(&QuicChromiumClientSession::StreamRequest::DoCallback, + weak_factory_.GetWeakPtr(), rv)); } } @@ -681,13 +677,16 @@ QuicChromiumClientSession::QuicChromiumClientSession( bool require_confirmation, bool migrate_session_early_v2, bool migrate_sessions_on_network_change_v2, - bool go_away_on_path_degrading, NetworkChangeNotifier::NetworkHandle default_network, + quic::QuicTime::Delta retransmittable_on_wire_timeout, + bool migrate_idle_session, + base::TimeDelta idle_migration_period, base::TimeDelta max_time_on_non_default_network, int max_migrations_to_non_default_network_on_write_error, int max_migrations_to_non_default_network_on_path_degrading, int yield_after_packets, quic::QuicTime::Delta yield_after_duration, + bool go_away_on_path_degrading, bool headers_include_h2_stream_dependency, int cert_verify_flags, const quic::QuicConfig& config, @@ -697,6 +696,7 @@ QuicChromiumClientSession::QuicChromiumClientSession( base::TimeTicks dns_resolution_end_time, quic::QuicClientPushPromiseIndex* push_promise_index, ServerPushDelegate* push_delegate, + const base::TickClock* tick_clock, base::SequencedTaskRunner* task_runner, std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, NetLog* net_log) @@ -709,7 +709,8 @@ QuicChromiumClientSession::QuicChromiumClientSession( migrate_session_early_v2_(migrate_session_early_v2), migrate_session_on_network_change_v2_( migrate_sessions_on_network_change_v2), - go_away_on_path_degrading_(go_away_on_path_degrading), + migrate_idle_session_(migrate_idle_session), + idle_migration_period_(idle_migration_period), max_time_on_non_default_network_(max_time_on_non_default_network), max_migrations_to_non_default_network_on_write_error_( max_migrations_to_non_default_network_on_write_error), @@ -720,8 +721,11 @@ QuicChromiumClientSession::QuicChromiumClientSession( clock_(clock), yield_after_packets_(yield_after_packets), yield_after_duration_(yield_after_duration), + go_away_on_path_degrading_(go_away_on_path_degrading), most_recent_path_degrading_timestamp_(base::TimeTicks()), most_recent_network_disconnected_timestamp_(base::TimeTicks()), + tick_clock_(tick_clock), + most_recent_stream_close_time_(tick_clock_->NowTicks()), most_recent_write_error_(0), most_recent_write_error_timestamp_(base::TimeTicks()), stream_factory_(stream_factory), @@ -786,8 +790,7 @@ QuicChromiumClientSession::QuicChromiumClientSession( connect_timing_.dns_end = dns_resolution_end_time; if (migrate_session_early_v2_) { connection->set_retransmittable_on_wire_timeout( - quic::QuicTime::Delta::FromMilliseconds( - kDefaultRetransmittableOnWireTimeoutMillisecs)); + retransmittable_on_wire_timeout); } } @@ -911,24 +914,27 @@ void QuicChromiumClientSession::Initialize() { set_max_uncompressed_header_bytes(kMaxUncompressedHeaderSize); } -size_t QuicChromiumClientSession::WriteHeaders( +size_t QuicChromiumClientSession::WriteHeadersOnHeadersStream( quic::QuicStreamId id, spdy::SpdyHeaderBlock headers, bool fin, spdy::SpdyPriority priority, quic::QuicReferenceCountedPointer<quic::QuicAckListenerInterface> - ack_notifier_delegate) { + ack_listener) { spdy::SpdyStreamId parent_stream_id = 0; int weight = 0; bool exclusive = false; + if (headers_include_h2_stream_dependency_) { priority_dependency_state_.OnStreamCreation(id, priority, &parent_stream_id, &weight, &exclusive); } else { weight = spdy::Spdy3PriorityToHttp2Weight(priority); } - return WriteHeadersImpl(id, std::move(headers), fin, weight, parent_stream_id, - exclusive, std::move(ack_notifier_delegate)); + + return WriteHeadersOnHeadersStreamImpl(id, std::move(headers), fin, + parent_stream_id, weight, exclusive, + std::move(ack_listener)); } void QuicChromiumClientSession::UnregisterStreamPriority(quic::QuicStreamId id, @@ -1037,7 +1043,7 @@ int QuicChromiumClientSession::TryCreateStream(StreamRequest* request) { return OK; } - request->pending_start_time_ = base::TimeTicks::Now(); + request->pending_start_time_ = tick_clock_->NowTicks(); stream_requests_.push_back(request); UMA_HISTOGRAM_COUNTS_1000("Net.QuicSession.NumPendingStreamRequests", stream_requests_.size()); @@ -1224,7 +1230,7 @@ bool QuicChromiumClientSession::GetSSLInfo(SSLInfo* ssl_info) const { } int QuicChromiumClientSession::CryptoConnect(CompletionOnceCallback callback) { - connect_timing_.connect_start = base::TimeTicks::Now(); + connect_timing_.connect_start = tick_clock_->NowTicks(); RecordHandshakeState(STATE_STARTED); DCHECK(flow_controller()); @@ -1232,7 +1238,7 @@ int QuicChromiumClientSession::CryptoConnect(CompletionOnceCallback callback) { return ERR_QUIC_HANDSHAKE_FAILED; if (IsCryptoHandshakeConfirmed()) { - connect_timing_.connect_end = base::TimeTicks::Now(); + connect_timing_.connect_end = tick_clock_->NowTicks(); return OK; } @@ -1384,6 +1390,7 @@ QuicChromiumClientSession::CreateIncomingReliableStreamImpl( } void QuicChromiumClientSession::CloseStream(quic::QuicStreamId stream_id) { + most_recent_stream_close_time_ = tick_clock_->NowTicks(); quic::QuicStream* stream = GetOrCreateStream(stream_id); if (stream) { logger_->UpdateReceivedFrameCounts(stream_id, stream->num_frames_received(), @@ -1421,7 +1428,7 @@ void QuicChromiumClientSession::OnCanCreateNewOutgoingStream() { // TODO(ckrasic) - analyze data and then add logic to mark QUIC // broken if wait times are excessive. UMA_HISTOGRAM_TIMES("Net.QuicSession.PendingStreamsWaitTime", - base::TimeTicks::Now() - request->pending_start_time_); + tick_clock_->NowTicks() - request->pending_start_time_); stream_requests_.pop_front(); request->OnRequestCompleteSuccess( CreateOutgoingReliableStreamImpl(request->traffic_annotation()) @@ -1482,7 +1489,7 @@ void QuicChromiumClientSession::OnCryptoHandshakeEvent( // Update |connect_end| only when handshake is confirmed. This should also // take care of any failed 0-RTT request. - connect_timing_.connect_end = base::TimeTicks::Now(); + connect_timing_.connect_end = tick_clock_->NowTicks(); DCHECK_LE(connect_timing_.connect_start, connect_timing_.connect_end); UMA_HISTOGRAM_TIMES( "Net.QuicSession.HandshakeConfirmedTime", @@ -1492,7 +1499,7 @@ void QuicChromiumClientSession::OnCryptoHandshakeEvent( if (!connect_timing_.dns_end.is_null()) { UMA_HISTOGRAM_TIMES( "Net.QuicSession.HostResolution.HandshakeConfirmedTime", - base::TimeTicks::Now() - connect_timing_.dns_end); + tick_clock_->NowTicks() - connect_timing_.dns_end); } auto it = handles_.begin(); @@ -1569,6 +1576,12 @@ void QuicChromiumClientSession::OnConnectionClosed( UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedByPublicReset", is_from_google_server); } + + if (is_from_google_server) { + UMA_HISTOGRAM_COUNTS_100( + "Net.QuicSession.NumMigrationsExercisedBeforePublicReset", + sockets_.size() - 1); + } } if (IsCryptoHandshakeConfirmed()) { if (is_google_host) { @@ -1756,9 +1769,9 @@ int QuicChromiumClientSession::HandleWriteError( // Post a task to migrate the session onto a new network. task_runner_->PostTask( FROM_HERE, - base::Bind(&QuicChromiumClientSession::MigrateSessionOnWriteError, - weak_factory_.GetWeakPtr(), error_code, - connection()->writer())); + base::BindOnce(&QuicChromiumClientSession::MigrateSessionOnWriteError, + weak_factory_.GetWeakPtr(), error_code, + connection()->writer())); // Store packet in the session since the actual migration and packet rewrite // can happen via this posted task or via an async network notification. @@ -1779,7 +1792,7 @@ void QuicChromiumClientSession::MigrateSessionOnWriteError( if (writer != connection()->writer()) return; - most_recent_write_error_timestamp_ = base::TimeTicks::Now(); + most_recent_write_error_timestamp_ = tick_clock_->NowTicks(); most_recent_write_error_ = error_code; if (stream_factory_ == nullptr) { @@ -1793,8 +1806,24 @@ void QuicChromiumClientSession::MigrateSessionOnWriteError( current_connection_migration_cause_ = ON_WRITE_ERROR; - if (!IsSessionMigratable(/*close_session_if_not_migratable*/ false)) { - // Close the connection if migration failed. Do not cause a + if (migrate_idle_session_ && CheckIdleTimeExceedsIdleMigrationPeriod()) + return; + + if (!migrate_idle_session_ && GetNumActiveStreams() == 0 && + GetNumDrainingStreams() == 0) { + // connection close packet to be sent since socket may be borked. + connection()->CloseConnection(quic::QUIC_PACKET_WRITE_ERROR, + "Write error for non-migratable session", + quic::ConnectionCloseBehavior::SILENT_CLOSE); + return; + } + + // Do not migrate if connection migration is disabled. + if (config()->DisableConnectionMigration()) { + HistogramAndLogMigrationFailure( + net_log_, MIGRATION_STATUS_DISABLED_BY_CONFIG, connection_id(), + "Migration disabled by config"); + // Close the connection since migration was disabled. Do not cause a // connection close packet to be sent since socket may be borked. connection()->CloseConnection(quic::QUIC_PACKET_WRITE_ERROR, "Write error for non-migratable session", @@ -1869,8 +1898,8 @@ void QuicChromiumClientSession::OnNoNewNetwork() { // Post a task to maybe close the session if the alarm fires. task_runner_->PostDelayedTask( FROM_HERE, - base::Bind(&QuicChromiumClientSession::OnMigrationTimeout, - weak_factory_.GetWeakPtr(), sockets_.size()), + base::BindOnce(&QuicChromiumClientSession::OnMigrationTimeout, + weak_factory_.GetWeakPtr(), sockets_.size()), base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs)); } @@ -1938,9 +1967,11 @@ void QuicChromiumClientSession::OnProbeNetworkSucceeded( connection()->SetSelfAddress(self_address); // Close streams that are not migratable to the probed |network|. - // If session then becomes idle, close the connection. ResetNonMigratableStreams(); - if (GetNumActiveStreams() == 0 && GetNumDrainingStreams() == 0) { + + if (!migrate_idle_session_ && GetNumActiveStreams() == 0 && + GetNumDrainingStreams() == 0) { + // If idle sessions won't be migrated, close the connection. CloseSessionOnErrorLater( ERR_NETWORK_CHANGED, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, @@ -1948,6 +1979,9 @@ void QuicChromiumClientSession::OnProbeNetworkSucceeded( return; } + if (migrate_idle_session_ && CheckIdleTimeExceedsIdleMigrationPeriod()) + return; + // Migrate to the probed socket immediately: socket, writer and reader will // be acquired by connection and used as default on success. if (!MigrateToSocket(std::move(socket), std::move(reader), @@ -1963,17 +1997,18 @@ void QuicChromiumClientSession::OnProbeNetworkSucceeded( if (network == default_network_) { DVLOG(1) << "Client successfully migrated to default network."; CancelMigrateBackToDefaultNetworkTimer(); - } else { - DVLOG(1) << "Client successfully got off default network after " - << "successful probing network: " << network << "."; - current_migrations_to_non_default_network_on_path_degrading_++; - if (!migrate_back_to_default_timer_.IsRunning()) { - current_connection_migration_cause_ = ON_MIGRATE_BACK_TO_DEFAULT_NETWORK; - // Session gets off the |default_network|, stay on |network| for now but - // try to migrate back to default network after 1 second. - StartMigrateBackToDefaultNetworkTimer( - base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs)); - } + return; + } + + DVLOG(1) << "Client successfully got off default network after " + << "successful probing network: " << network << "."; + current_migrations_to_non_default_network_on_path_degrading_++; + if (!migrate_back_to_default_timer_.IsRunning()) { + current_connection_migration_cause_ = ON_MIGRATE_BACK_TO_DEFAULT_NETWORK; + // Session gets off the |default_network|, stay on |network| for now but + // try to migrate back to default network after 1 second. + StartMigrateBackToDefaultNetworkTimer( + base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs)); } } @@ -2130,8 +2165,31 @@ void QuicChromiumClientSession::MigrateNetworkImmediately( // - otherwise, it's brought to default network, cancel the running timer to // migrate back. - if (!IsSessionMigratable(/*close_session_if_not_migratable=*/true)) + if (!migrate_idle_session_ && GetNumActiveStreams() == 0 && + GetNumDrainingStreams() == 0) { + HistogramAndLogMigrationFailure(net_log_, + MIGRATION_STATUS_NO_MIGRATABLE_STREAMS, + connection_id(), "No active streams"); + CloseSessionOnErrorLater( + ERR_NETWORK_CHANGED, + quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, + quic::ConnectionCloseBehavior::SILENT_CLOSE); return; + } + + if (migrate_idle_session_ && CheckIdleTimeExceedsIdleMigrationPeriod()) + return; + + // Do not migrate if connection migration is disabled. + if (config()->DisableConnectionMigration()) { + HistogramAndLogMigrationFailure( + net_log_, MIGRATION_STATUS_DISABLED_BY_CONFIG, connection_id(), + "Migration disabled by config"); + CloseSessionOnErrorLater(ERR_NETWORK_CHANGED, + quic::QUIC_CONNECTION_MIGRATION_DISABLED_BY_CONFIG, + quic::ConnectionCloseBehavior::SILENT_CLOSE); + return; + } if (network == GetDefaultSocket()->GetBoundNetwork()) { HistogramAndLogMigrationFailure(net_log_, MIGRATION_STATUS_ALREADY_MIGRATED, @@ -2149,15 +2207,16 @@ void QuicChromiumClientSession::MigrateNetworkImmediately( if (result == MigrationResult::FAILURE) return; - if (network != default_network_) { - // TODO(zhongyi): reconsider this, maybe we just want to hear back - // We are forced to migrate to |network|, probably |default_network_| is - // not working, start to migrate back to default network after 1 secs. - StartMigrateBackToDefaultNetworkTimer( - base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs)); - } else { + if (network == default_network_) { CancelMigrateBackToDefaultNetworkTimer(); + return; } + + // TODO(zhongyi): reconsider this, maybe we just want to hear back + // We are forced to migrate to |network|, probably |default_network_| is + // not working, start to migrate back to default network after 1 secs. + StartMigrateBackToDefaultNetworkTimer( + base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs)); } void QuicChromiumClientSession::OnWriteError(int error_code) { @@ -2209,7 +2268,7 @@ void QuicChromiumClientSession::OnPathDegrading() { net_log_.AddEvent( NetLogEventType::QUIC_CONNECTION_MIGRATION_ON_PATH_DEGRADING); if (most_recent_path_degrading_timestamp_ == base::TimeTicks()) - most_recent_path_degrading_timestamp_ = base::TimeTicks::Now(); + most_recent_path_degrading_timestamp_ = tick_clock_->NowTicks(); if (!stream_factory_) return; @@ -2256,7 +2315,7 @@ void QuicChromiumClientSession::OnPathDegrading() { migration_net_log.BeginEvent( NetLogEventType::QUIC_CONNECTION_MIGRATION_TRIGGERED, NetLogQuicConnectionMigrationTriggerCallback("PathDegrading")); - // Probe alternative network, session will migrate to the probed + // Probe the alternative network, session will migrate to the probed // network and decide whether it wants to migrate back to the default // network on success. StartProbeNetwork(alternate_network, peer_address(), migration_net_log); @@ -2264,8 +2323,8 @@ void QuicChromiumClientSession::OnPathDegrading() { NetLogEventType::QUIC_CONNECTION_MIGRATION_TRIGGERED); } -bool QuicChromiumClientSession::HasOpenDynamicStreams() const { - return quic::QuicSession::HasOpenDynamicStreams() || +bool QuicChromiumClientSession::ShouldKeepConnectionAlive() const { + return quic::QuicSpdySession::ShouldKeepConnectionAlive() || GetNumDrainingOutgoingStreams() > 0; } @@ -2402,7 +2461,8 @@ ProbingResult QuicChromiumClientSession::StartProbeNetwork( CHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); - if (GetNumActiveStreams() == 0 && GetNumDrainingStreams() == 0) { + if (!migrate_idle_session_ && GetNumActiveStreams() == 0 && + GetNumDrainingStreams() == 0) { HistogramAndLogMigrationFailure(migration_net_log, MIGRATION_STATUS_NO_MIGRATABLE_STREAMS, connection_id(), "No active streams"); @@ -2413,6 +2473,9 @@ ProbingResult QuicChromiumClientSession::StartProbeNetwork( return ProbingResult::DISABLED_WITH_IDLE_SESSION; } + if (migrate_idle_session_ && CheckIdleTimeExceedsIdleMigrationPeriod()) + return ProbingResult::DISABLED_WITH_IDLE_SESSION; + // Abort probing if connection migration is disabled by config. if (config()->DisableConnectionMigration()) { DVLOG(1) << "Client disables probing network with connection migration " @@ -2420,7 +2483,6 @@ ProbingResult QuicChromiumClientSession::StartProbeNetwork( HistogramAndLogMigrationFailure( migration_net_log, MIGRATION_STATUS_DISABLED_BY_CONFIG, connection_id(), "Migration disabled by config"); - // TODO(zhongyi): do we want to close the session? return ProbingResult::DISABLED_BY_CONFIG; } @@ -2500,10 +2562,8 @@ void QuicChromiumClientSession::TryMigrateBackToDefaultNetwork( ProbingResult result = StartProbeNetwork(default_network_, peer_address(), net_log_); - if (result == ProbingResult::DISABLED_WITH_IDLE_SESSION) { - // |this| session has been closed due to idle session. + if (result == ProbingResult::DISABLED_WITH_IDLE_SESSION) return; - } if (result != ProbingResult::PENDING) { // Session is not allowed to migrate, mark session as going away, cancel @@ -2538,35 +2598,26 @@ void QuicChromiumClientSession::MaybeRetryMigrateBackToDefaultNetwork() { TryMigrateBackToDefaultNetwork(retry_migrate_back_timeout); } -bool QuicChromiumClientSession::IsSessionMigratable( - bool close_session_if_not_migratable) { - // Close idle sessions. - if (GetNumActiveStreams() == 0 && GetNumDrainingStreams() == 0) { - HistogramAndLogMigrationFailure(net_log_, - MIGRATION_STATUS_NO_MIGRATABLE_STREAMS, - connection_id(), "No active streams"); - if (close_session_if_not_migratable) { - CloseSessionOnErrorLater( - ERR_NETWORK_CHANGED, - quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, - quic::ConnectionCloseBehavior::SILENT_CLOSE); - } +bool QuicChromiumClientSession::CheckIdleTimeExceedsIdleMigrationPeriod() { + if (!migrate_idle_session_) + return false; + + if (GetNumActiveStreams() != 0 || GetNumDrainingStreams() != 0) { return false; } - // Do not migrate sessions where connection migration is disabled. - if (config()->DisableConnectionMigration()) { - HistogramAndLogMigrationFailure( - net_log_, MIGRATION_STATUS_DISABLED_BY_CONFIG, connection_id(), - "Migration disabled by config"); - if (close_session_if_not_migratable) { - CloseSessionOnErrorLater( - ERR_NETWORK_CHANGED, - quic::QUIC_CONNECTION_MIGRATION_DISABLED_BY_CONFIG, - quic::ConnectionCloseBehavior::SILENT_CLOSE); - } + // There are no active/drainning streams, check the last stream's finish time. + if (tick_clock_->NowTicks() - most_recent_stream_close_time_ < + idle_migration_period_) { + // Still within the idle migration period. return false; } + + HistogramAndLogMigrationFailure( + net_log_, MIGRATION_STATUS_IDLE_MIGRATION_TIMEOUT, connection_id(), + "Ilde migration period exceeded"); + CloseSessionOnErrorLater(ERR_NETWORK_CHANGED, quic::QUIC_NETWORK_IDLE_TIMEOUT, + quic::ConnectionCloseBehavior::SILENT_CLOSE); return true; } @@ -2591,7 +2642,7 @@ void QuicChromiumClientSession::ResetNonMigratableStreams() { void QuicChromiumClientSession::LogMetricsOnNetworkDisconnected() { if (most_recent_path_degrading_timestamp_ != base::TimeTicks()) { - most_recent_network_disconnected_timestamp_ = base::TimeTicks::Now(); + most_recent_network_disconnected_timestamp_ = tick_clock_->NowTicks(); base::TimeDelta degrading_duration = most_recent_network_disconnected_timestamp_ - most_recent_path_degrading_timestamp_; @@ -2620,7 +2671,7 @@ void QuicChromiumClientSession::LogMetricsOnNetworkMadeDefault() { if (most_recent_network_disconnected_timestamp_ != base::TimeTicks()) { // NetworkDiscconected happens before NetworkMadeDefault, the platform // is dropping WiFi. - base::TimeTicks now = base::TimeTicks::Now(); + base::TimeTicks now = tick_clock_->NowTicks(); base::TimeDelta disconnection_duration = now - most_recent_network_disconnected_timestamp_; base::TimeDelta degrading_duration = @@ -2697,7 +2748,7 @@ std::unique_ptr<base::Value> QuicChromiumClientSession::GetInfoAsValue( std::unique_ptr<base::ListValue> stream_list(new base::ListValue()); for (DynamicStreamMap::const_iterator it = dynamic_streams().begin(); it != dynamic_streams().end(); ++it) { - stream_list->AppendString(base::UintToString(it->second->id())); + stream_list->AppendString(base::NumberToString(it->second->id())); } dict->Set("active_streams", std::move(stream_list)); @@ -2792,8 +2843,8 @@ void QuicChromiumClientSession::NotifyFactoryOfSessionClosedLater() { DCHECK(!connection()->connected()); task_runner_->PostTask( FROM_HERE, - base::Bind(&QuicChromiumClientSession::NotifyFactoryOfSessionClosed, - weak_factory_.GetWeakPtr())); + base::BindOnce(&QuicChromiumClientSession::NotifyFactoryOfSessionClosed, + weak_factory_.GetWeakPtr())); } void QuicChromiumClientSession::NotifyFactoryOfSessionClosed() { @@ -2819,11 +2870,11 @@ MigrationResult QuicChromiumClientSession::Migrate( return MigrationResult::FAILURE; if (network != NetworkChangeNotifier::kInvalidNetworkHandle) { - // This is a migration attempt from connection migration. Close - // streams that are not migratable to |network|. If session then becomes - // idle, close the connection if |close_session_on_error| is true. + // This is a migration attempt from connection migration. ResetNonMigratableStreams(); - if (GetNumActiveStreams() == 0 && GetNumDrainingStreams() == 0) { + if (!migrate_idle_session_ && GetNumActiveStreams() == 0 && + GetNumDrainingStreams() == 0) { + // If idle sessions can not be migrated, close the session if needed. if (close_session_on_error) { CloseSessionOnErrorLater( ERR_NETWORK_CHANGED, @@ -2920,8 +2971,8 @@ bool QuicChromiumClientSession::MigrateToSocket( // socket. This avoids reentrancy issues if there is a write error // on the write to the new socket. task_runner_->PostTask( - FROM_HERE, base::Bind(&QuicChromiumClientSession::WriteToNewSocket, - weak_factory_.GetWeakPtr())); + FROM_HERE, base::BindOnce(&QuicChromiumClientSession::WriteToNewSocket, + weak_factory_.GetWeakPtr())); return true; } diff --git a/chromium/net/quic/quic_chromium_client_session.h b/chromium/net/quic/quic_chromium_client_session.h index 7ddacd84559..120c85bfd97 100644 --- a/chromium/net/quic/quic_chromium_client_session.h +++ b/chromium/net/quic/quic_chromium_client_session.h @@ -21,6 +21,7 @@ #include "base/containers/mru_cache.h" #include "base/macros.h" #include "base/time/time.h" +#include "base/timer/timer.h" #include "net/base/completion_once_callback.h" #include "net/base/load_timing_info.h" #include "net/base/net_error_details.h" @@ -106,6 +107,7 @@ enum QuicConnectionMigrationStatus { MIGRATION_STATUS_TIMEOUT, MIGRATION_STATUS_ON_WRITE_ERROR_DISABLED, MIGRATION_STATUS_PATH_DEGRADING_BEFORE_HANDSHAKE_CONFIRMED, + MIGRATION_STATUS_IDLE_MIGRATION_TIMEOUT, MIGRATION_STATUS_MAX }; @@ -373,13 +375,16 @@ class NET_EXPORT_PRIVATE QuicChromiumClientSession bool require_confirmation, bool migrate_sesion_early_v2, bool migrate_session_on_network_change_v2, - bool go_away_on_path_degrading, NetworkChangeNotifier::NetworkHandle default_network, + quic::QuicTime::Delta retransmittable_on_wire_timeout, + bool migrate_idle_session, + base::TimeDelta idle_migration_period, base::TimeDelta max_time_on_non_default_network, int max_migrations_to_non_default_network_on_write_error, int max_migrations_to_non_default_network_on_path_degrading, int yield_after_packets, quic::QuicTime::Delta yield_after_duration, + bool go_away_on_path_degrading, bool headers_include_h2_stream_dependency, int cert_verify_flags, const quic::QuicConfig& config, @@ -389,6 +394,7 @@ class NET_EXPORT_PRIVATE QuicChromiumClientSession base::TimeTicks dns_resolution_end_time, quic::QuicClientPushPromiseIndex* push_promise_index, ServerPushDelegate* push_delegate, + const base::TickClock* tick_clock, base::SequencedTaskRunner* task_runner, std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, NetLog* net_log); @@ -449,7 +455,7 @@ class NET_EXPORT_PRIVATE QuicChromiumClientSession const quic::QuicSocketAddress& peer_address) override; // quic::QuicSpdySession methods: - size_t WriteHeaders( + size_t WriteHeadersOnHeadersStream( quic::QuicStreamId id, spdy::SpdyHeaderBlock headers, bool fin, @@ -496,7 +502,7 @@ class NET_EXPORT_PRIVATE QuicChromiumClientSession const quic::QuicSocketAddress& self_address, const quic::QuicSocketAddress& peer_address) override; void OnPathDegrading() override; - bool HasOpenDynamicStreams() const override; + bool ShouldKeepConnectionAlive() const override; // QuicChromiumPacketReader::Visitor methods: void OnReadError(int result, const DatagramClientSocket* socket) override; @@ -709,9 +715,12 @@ class NET_EXPORT_PRIVATE QuicChromiumClientSession void TryMigrateBackToDefaultNetwork(base::TimeDelta timeout); void MaybeRetryMigrateBackToDefaultNetwork(); - // Returns true if session is migratable. If not, a task is posted to - // close the session later if |close_session_if_not_migratable| is true. - bool IsSessionMigratable(bool close_session_if_not_migratable); + // If migrate idle session is enabled, returns true and post a task to close + // the connection if session's idle time exceeds the |idle_migration_period_|. + // If migrate idle session is not enabled, returns true and posts a task to + // close the connection if session doesn't have outstanding streams. + bool CheckIdleTimeExceedsIdleMigrationPeriod(); + // Close non-migratable streams in both directions by sending reset stream to // peer when connection migration attempts to migrate to the alternate // network. @@ -744,7 +753,9 @@ class NET_EXPORT_PRIVATE QuicChromiumClientSession bool require_confirmation_; bool migrate_session_early_v2_; bool migrate_session_on_network_change_v2_; - bool go_away_on_path_degrading_; + bool migrate_idle_session_; + // Session can be migrated if its idle time is within this period. + base::TimeDelta idle_migration_period_; base::TimeDelta max_time_on_non_default_network_; // Maximum allowed number of migrations to non-default network triggered by // packet write error per default network. @@ -757,9 +768,12 @@ class NET_EXPORT_PRIVATE QuicChromiumClientSession quic::QuicClock* clock_; // Unowned. int yield_after_packets_; quic::QuicTime::Delta yield_after_duration_; + bool go_away_on_path_degrading_; base::TimeTicks most_recent_path_degrading_timestamp_; base::TimeTicks most_recent_network_disconnected_timestamp_; + const base::TickClock* tick_clock_; + base::TimeTicks most_recent_stream_close_time_; int most_recent_write_error_; base::TimeTicks most_recent_write_error_timestamp_; diff --git a/chromium/net/quic/quic_chromium_client_session_test.cc b/chromium/net/quic/quic_chromium_client_session_test.cc index fcb13dc8c1c..9380fc78531 100644 --- a/chromium/net/quic/quic_chromium_client_session_test.cc +++ b/chromium/net/quic/quic_chromium_client_session_test.cc @@ -5,12 +5,14 @@ #include "net/quic/quic_chromium_client_session.h" #include "base/base64.h" +#include "base/bind.h" #include "base/files/file_path.h" #include "base/memory/ptr_util.h" #include "base/run_loop.h" #include "base/stl_util.h" #include "base/test/metrics/histogram_tester.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/time/default_tick_clock.h" #include "build/build_config.h" #include "net/base/test_completion_callback.h" #include "net/cert/cert_verify_result.h" @@ -160,18 +162,23 @@ class QuicChromiumClientSessionTest base::WrapUnique(static_cast<QuicServerInfo*>(nullptr)), session_key_, /*require_confirmation=*/false, migrate_session_early_v2_, /*migrate_session_on_network_change_v2=*/false, - /*go_away_on_path_degrading*/ false, /*defaulet_network=*/NetworkChangeNotifier::kInvalidNetworkHandle, + quic::QuicTime::Delta::FromMilliseconds( + kDefaultRetransmittableOnWireTimeoutMillisecs), + /*migrate_idle_session=*/false, + base::TimeDelta::FromSeconds(kDefaultIdleSessionMigrationPeriodSeconds), base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), kMaxMigrationsToNonDefaultNetworkOnWriteError, kMaxMigrationsToNonDefaultNetworkOnPathDegrading, kQuicYieldAfterPacketsRead, quic::QuicTime::Delta::FromMilliseconds( kQuicYieldAfterDurationMilliseconds), - /*cert_verify_flags=*/0, client_headers_include_h2_stream_dependency_, + /*cert_verify_flags=*/0, /*go_away_on_path_degrading*/ false, + client_headers_include_h2_stream_dependency_, quic::test::DefaultQuicConfig(), &crypto_config_, "CONNECTION_UNKNOWN", base::TimeTicks::Now(), base::TimeTicks::Now(), &push_promise_index_, - &test_push_delegate_, base::ThreadTaskRunnerHandle::Get().get(), + &test_push_delegate_, base::DefaultTickClock::GetInstance(), + base::ThreadTaskRunnerHandle::Get().get(), /*socket_performance_watcher=*/nullptr, &net_log_)); scoped_refptr<X509Certificate> cert( @@ -251,7 +258,7 @@ class QuicChromiumClientSessionTest bool migrate_session_early_v2_; }; -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( VersionIncludeStreamDependencySequence, QuicChromiumClientSessionTest, ::testing::Combine( @@ -524,7 +531,8 @@ TEST_P(QuicChromiumClientSessionTest, AsyncStreamRequest) { quic_data.AddWrite( SYNCHRONOUS, client_maker_.MakeRstPacket( 3, true, GetNthClientInitiatedBidirectionalStreamId(0), - quic::QUIC_RST_ACKNOWLEDGEMENT)); + quic::QUIC_STREAM_CANCELLED, 0, + /*include_stop_sending_if_v99=*/false)); // After the STREAM_ID_BLOCKED is sent, receive a MAX_STREAM_ID to increase // the limit. quic_data.AddRead( @@ -564,6 +572,15 @@ TEST_P(QuicChromiumClientSessionTest, AsyncStreamRequest) { GetNthClientInitiatedBidirectionalStreamId(0), quic::QUIC_STREAM_CANCELLED, 0); session_->OnRstStream(rst); + if (version_ == quic::QUIC_VERSION_99) { + // For version99, to close the stream completely, we also must receive a + // STOP_SENDING frame: + quic::QuicStopSendingFrame stop_sending( + quic::kInvalidControlFrameId, + GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED); + session_->OnStopSendingFrame(stop_sending); + } // Pump the message loop to read the max stream id packet. base::RunLoop().RunUntilIdle(); @@ -652,10 +669,13 @@ TEST_P(QuicChromiumClientSessionTest, CancelPendingStreamRequest) { SYNCHRONOUS, client_maker_.MakeStreamIdBlockedPacket( 2, true, GetNthClientInitiatedBidirectionalStreamId(49))); + // This node receives the RST_STREAM+STOP_SENDING, it responds + // with only a RST_STREAM. quic_data.AddWrite( SYNCHRONOUS, client_maker_.MakeRstPacket( 3, true, GetNthClientInitiatedBidirectionalStreamId(0), - quic::QUIC_RST_ACKNOWLEDGEMENT)); + quic::QUIC_STREAM_CANCELLED, 0, + /*include_stop_sending_if_v99=*/false)); } else { quic_data.AddWrite( SYNCHRONOUS, client_maker_.MakeRstPacket( @@ -694,6 +714,15 @@ TEST_P(QuicChromiumClientSessionTest, CancelPendingStreamRequest) { GetNthClientInitiatedBidirectionalStreamId(0), quic::QUIC_STREAM_CANCELLED, 0); session_->OnRstStream(rst); + if (version_ == quic::QUIC_VERSION_99) { + // For version99, we require a STOP_SENDING as well as a RESET_STREAM to + // fully close the stream. + quic::QuicStopSendingFrame stop_sending( + quic::kInvalidControlFrameId, + GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED); + session_->OnStopSendingFrame(stop_sending); + } EXPECT_EQ(kMaxOpenStreams - 1, session_->GetNumOpenOutgoingStreams()); quic_data.Resume(); @@ -732,7 +761,7 @@ TEST_P(QuicChromiumClientSessionTest, ConnectionCloseBeforeStreamRequest) { TEST_P(QuicChromiumClientSessionTest, ConnectionCloseBeforeHandshakeConfirmed) { // Force the connection close packet to use long headers with connection ID. - server_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); + server_maker_.SetEncryptionLevel(quic::ENCRYPTION_NONE); MockQuicData quic_data; quic_data.AddRead(ASYNC, ERR_IO_PENDING); @@ -1569,6 +1598,10 @@ TEST_P(QuicChromiumClientSessionTest, MigrateToSocketReadError) { } TEST_P(QuicChromiumClientSessionTest, DetectPathDegradingDuringHandshake) { + if (version_ >= quic::QUIC_VERSION_47) { + // TODO(nharper): reenable once MakeDummyCHLOPacket() fixed + return; + } migrate_session_early_v2_ = true; MockQuicData quic_data; diff --git a/chromium/net/quic/quic_chromium_client_stream.cc b/chromium/net/quic/quic_chromium_client_stream.cc index d9f79bc3f4b..3fc5eca5c0a 100644 --- a/chromium/net/quic/quic_chromium_client_stream.cc +++ b/chromium/net/quic/quic_chromium_client_stream.cc @@ -6,6 +6,7 @@ #include <utility> +#include "base/bind.h" #include "base/bind_helpers.h" #include "base/callback_helpers.h" #include "base/location.h" @@ -125,8 +126,8 @@ void QuicChromiumClientStream::Handle::OnError(int error) { // the call stack of the owner of the handle. base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, - base::Bind(&QuicChromiumClientStream::Handle::InvokeCallbacksOnClose, - weak_factory_.GetWeakPtr(), error)); + base::BindOnce(&QuicChromiumClientStream::Handle::InvokeCallbacksOnClose, + weak_factory_.GetWeakPtr(), error)); } void QuicChromiumClientStream::Handle::InvokeCallbacksOnClose(int error) { @@ -555,7 +556,7 @@ bool QuicChromiumClientStream::WriteStreamData(quic::QuicStringPiece data, // Must not be called when data is buffered. DCHECK(!HasBufferedData()); // Writes the data, or buffers it. - WriteOrBufferBody(data, fin, nullptr); + WriteOrBufferBody(data, fin); return !HasBufferedData(); // Was all data written? } @@ -569,7 +570,7 @@ bool QuicChromiumClientStream::WritevStreamData( for (size_t i = 0; i < buffers.size(); ++i) { bool is_fin = fin && (i == buffers.size() - 1); quic::QuicStringPiece string_data(buffers[i]->data(), lengths[i]); - WriteOrBufferBody(string_data, is_fin, nullptr); + WriteOrBufferBody(string_data, is_fin); } return !HasBufferedData(); // Was all data written? } @@ -619,7 +620,7 @@ void QuicChromiumClientStream::NotifyHandleOfInitialHeadersAvailableLater() { DCHECK(handle_); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, - base::Bind( + base::BindOnce( &QuicChromiumClientStream::NotifyHandleOfInitialHeadersAvailable, weak_factory_.GetWeakPtr())); } @@ -636,7 +637,7 @@ void QuicChromiumClientStream::NotifyHandleOfTrailingHeadersAvailableLater() { DCHECK(handle_); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, - base::Bind( + base::BindOnce( &QuicChromiumClientStream::NotifyHandleOfTrailingHeadersAvailable, weak_factory_.GetWeakPtr())); } @@ -688,8 +689,8 @@ void QuicChromiumClientStream::NotifyHandleOfDataAvailableLater() { DCHECK(handle_); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, - base::Bind(&QuicChromiumClientStream::NotifyHandleOfDataAvailable, - weak_factory_.GetWeakPtr())); + base::BindOnce(&QuicChromiumClientStream::NotifyHandleOfDataAvailable, + weak_factory_.GetWeakPtr())); } void QuicChromiumClientStream::NotifyHandleOfDataAvailable() { diff --git a/chromium/net/quic/quic_chromium_client_stream_test.cc b/chromium/net/quic/quic_chromium_client_stream_test.cc index 9f6d3fd5e6b..0009749cbf0 100644 --- a/chromium/net/quic/quic_chromium_client_stream_test.cc +++ b/chromium/net/quic/quic_chromium_client_stream_test.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/bind.h" #include "base/memory/ptr_util.h" #include "base/run_loop.h" #include "base/stl_util.h" @@ -93,17 +94,17 @@ class MockQuicClientSessionBase : public quic::QuicSpdyClientSessionBase { MOCK_CONST_METHOD0(IsCryptoHandshakeConfirmed, bool()); // Methods taking non-copyable types like spdy::SpdyHeaderBlock by value // cannot be mocked directly. - size_t WriteHeaders( + size_t WriteHeadersOnHeadersStream( quic::QuicStreamId id, spdy::SpdyHeaderBlock headers, bool fin, spdy::SpdyPriority priority, quic::QuicReferenceCountedPointer<quic::QuicAckListenerInterface> ack_listener) override { - return WriteHeadersMock(id, headers, fin, priority, - std::move(ack_listener)); + return WriteHeadersOnHeadersStreamMock(id, headers, fin, priority, + std::move(ack_listener)); } - MOCK_METHOD5(WriteHeadersMock, + MOCK_METHOD5(WriteHeadersOnHeadersStreamMock, size_t(quic::QuicStreamId id, const spdy::SpdyHeaderBlock& headers, bool fin, @@ -242,13 +243,13 @@ class QuicChromiumClientStreamTest } quic::QuicStreamId GetNthClientInitiatedBidirectionalStreamId(int n) { - return quic::test::QuicSpdySessionPeer:: - GetNthClientInitiatedBidirectionalStreamId(session_, n); + return quic::test::GetNthClientInitiatedBidirectionalStreamId( + session_.connection()->transport_version(), n); } quic::QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(int n) { - return quic::test::QuicSpdySessionPeer:: - GetNthServerInitiatedUnidirectionalStreamId(session_, n); + return quic::test::GetNthServerInitiatedUnidirectionalStreamId( + session_.connection()->transport_version(), n); } void ResetStreamCallback(QuicChromiumClientStream* stream, int /*rv*/) { @@ -277,7 +278,7 @@ class QuicChromiumClientStreamTest quic::QuicClientPushPromiseIndex push_promise_index_; }; -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( Version, QuicChromiumClientStreamTest, ::testing::ValuesIn(quic::AllSupportedTransportVersions())); @@ -372,13 +373,36 @@ TEST_P(QuicChromiumClientStreamTest, HandleAfterStreamReset) { quic::kInvalidControlFrameId, quic::test::GetNthClientInitiatedBidirectionalStreamId(GetParam(), 0), quic::QUIC_STREAM_CANCELLED, 0); - EXPECT_CALL( - session_, - SendRstStream( - quic::test::GetNthClientInitiatedBidirectionalStreamId(GetParam(), 0), - quic::QUIC_RST_ACKNOWLEDGEMENT, 0)); - stream_->OnStreamReset(rst); + if (GetParam() != quic::QUIC_VERSION_99) { + EXPECT_CALL( + session_, + SendRstStream(quic::test::GetNthClientInitiatedBidirectionalStreamId( + GetParam(), 0), + quic::QUIC_RST_ACKNOWLEDGEMENT, 0)); + } else { + // Intercept & check that the call to the QuicConnection's OnStreamReast + // has correct stream ID and error code -- for V99/IETF Quic, it should + // have the STREAM_CANCELLED error code, not RST_ACK... Capture + // OnStreamReset (rather than SendRstStream) because the V99 path bypasses + // SendRstStream, calling SendRstStreamInner directly. Mocking + // SendRstStreamInner is problematic since the test relies on it to perform + // the closing operations and getting the stream in the correct state. + EXPECT_CALL( + *(static_cast<quic::test::MockQuicConnection*>(session_.connection())), + OnStreamReset(stream_->id(), quic::QUIC_STREAM_CANCELLED)); + } + stream_->OnStreamReset(rst); + if (GetParam() == quic::QUIC_VERSION_99) { + // Make a STOP_SENDING frame and pass it to QUIC. For V99/IETF QUIC, + // we need both a REST_STREAM and a STOP_SENDING to effect a closed + // stream. + quic::QuicStopSendingFrame stop_sending_frame( + quic::kInvalidControlFrameId, + quic::test::GetNthClientInitiatedBidirectionalStreamId(GetParam(), 0), + quic::QUIC_STREAM_CANCELLED); + session_.OnStopSendingFrame(stop_sending_frame); + } EXPECT_FALSE(handle_->IsOpen()); EXPECT_EQ(quic::QUIC_STREAM_CANCELLED, handle_->stream_error()); } @@ -549,7 +573,7 @@ TEST_P(QuicChromiumClientStreamTest, OnTrailers) { spdy::SpdyHeaderBlock trailers; trailers["bar"] = "foo"; - trailers[quic::kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); + trailers[quic::kFinalOffsetHeaderKey] = base::NumberToString(strlen(data)); auto t = ProcessTrailers(trailers); @@ -606,7 +630,7 @@ TEST_P(QuicChromiumClientStreamTest, MarkTrailersConsumedWhenNotifyDelegate) { spdy::SpdyHeaderBlock trailers; trailers["bar"] = "foo"; - trailers[quic::kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); + trailers[quic::kFinalOffsetHeaderKey] = base::NumberToString(strlen(data)); quic::QuicHeaderList t = ProcessTrailers(trailers); EXPECT_FALSE(stream_->IsDoneReading()); @@ -661,7 +685,7 @@ TEST_P(QuicChromiumClientStreamTest, ReadAfterTrailersReceivedButNotDelivered) { // Deliver trailers. Delegate notification is posted asynchronously. spdy::SpdyHeaderBlock trailers; trailers["bar"] = "foo"; - trailers[quic::kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); + trailers[quic::kFinalOffsetHeaderKey] = base::NumberToString(strlen(data)); quic::QuicHeaderList t = ProcessTrailers(trailers); diff --git a/chromium/net/quic/quic_chromium_packet_reader.cc b/chromium/net/quic/quic_chromium_packet_reader.cc index 95478db607d..0f4c8cd668f 100644 --- a/chromium/net/quic/quic_chromium_packet_reader.cc +++ b/chromium/net/quic/quic_chromium_packet_reader.cc @@ -4,6 +4,7 @@ #include "net/quic/quic_chromium_packet_reader.h" +#include "base/bind.h" #include "base/location.h" #include "base/metrics/histogram_macros.h" #include "base/single_thread_task_runner.h" @@ -62,8 +63,8 @@ void QuicChromiumPacketReader::StartReading() { // Schedule the work through the message loop to 1) prevent infinite // recursion and 2) avoid blocking the thread for too long. base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&QuicChromiumPacketReader::OnReadComplete, - weak_factory_.GetWeakPtr(), rv)); + FROM_HERE, base::BindOnce(&QuicChromiumPacketReader::OnReadComplete, + weak_factory_.GetWeakPtr(), rv)); } else { if (!ProcessReadResult(rv)) { return; diff --git a/chromium/net/quic/quic_chromium_packet_writer.cc b/chromium/net/quic/quic_chromium_packet_writer.cc index 526c48e9313..fbdc48d538e 100644 --- a/chromium/net/quic/quic_chromium_packet_writer.cc +++ b/chromium/net/quic/quic_chromium_packet_writer.cc @@ -7,6 +7,7 @@ #include <string> #include <utility> +#include "base/bind.h" #include "base/location.h" #include "base/logging.h" #include "base/metrics/histogram_macros.h" @@ -189,12 +190,6 @@ void QuicChromiumPacketWriter::RetryPacketAfterNoBuffers() { OnWriteComplete(result.error_code); } -bool QuicChromiumPacketWriter::IsWriteBlockedDataBuffered() const { - // Chrome sockets' Write() methods buffer the data until the Write is - // permitted. - return true; -} - bool QuicChromiumPacketWriter::IsWriteBlocked() const { return (force_write_blocked_ || write_in_progress_); } diff --git a/chromium/net/quic/quic_chromium_packet_writer.h b/chromium/net/quic/quic_chromium_packet_writer.h index 731f3cf1ff8..a1558ef37a2 100644 --- a/chromium/net/quic/quic_chromium_packet_writer.h +++ b/chromium/net/quic/quic_chromium_packet_writer.h @@ -88,7 +88,6 @@ class NET_EXPORT_PRIVATE QuicChromiumPacketWriter const quic::QuicIpAddress& self_address, const quic::QuicSocketAddress& peer_address, quic::PerPacketOptions* options) override; - bool IsWriteBlockedDataBuffered() const override; bool IsWriteBlocked() const override; void SetWritable() override; quic::QuicByteCount GetMaxPacketSize( diff --git a/chromium/net/quic/quic_connection_logger.cc b/chromium/net/quic/quic_connection_logger.cc index c10dd4f986a..38d7578c25d 100644 --- a/chromium/net/quic/quic_connection_logger.cc +++ b/chromium/net/quic/quic_connection_logger.cc @@ -58,7 +58,7 @@ std::unique_ptr<base::Value> NetLogQuicPacketSentCallback( std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); dict->SetInteger("transmission_type", transmission_type); dict->SetKey("packet_number", - NetLogNumberValue(serialized_packet.packet_number)); + NetLogNumberValue(serialized_packet.packet_number.ToUint64())); dict->SetInteger("size", serialized_packet.encrypted_length); dict->SetKey("sent_time_us", NetLogNumberValue(sent_time.ToDebuggingValue())); return std::move(dict); @@ -69,8 +69,10 @@ std::unique_ptr<base::Value> NetLogQuicPacketRetransmittedCallback( quic::QuicPacketNumber new_packet_number, NetLogCaptureMode /* capture_mode */) { std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); - dict->SetKey("old_packet_number", NetLogNumberValue(old_packet_number)); - dict->SetKey("new_packet_number", NetLogNumberValue(new_packet_number)); + dict->SetKey("old_packet_number", + NetLogNumberValue(old_packet_number.ToUint64())); + dict->SetKey("new_packet_number", + NetLogNumberValue(new_packet_number.ToUint64())); return std::move(dict); } @@ -81,7 +83,7 @@ std::unique_ptr<base::Value> NetLogQuicPacketLostCallback( NetLogCaptureMode /*capture_mode*/) { auto dict = std::make_unique<base::DictionaryValue>(); dict->SetInteger("transmission_type", transmission_type); - dict->SetKey("packet_number", NetLogNumberValue(packet_number)); + dict->SetKey("packet_number", NetLogNumberValue(packet_number.ToUint64())); dict->SetKey("detection_time_us", NetLogNumberValue(detection_time.ToDebuggingValue())); return dict; @@ -91,7 +93,7 @@ std::unique_ptr<base::Value> NetLogQuicDuplicatePacketCallback( quic::QuicPacketNumber packet_number, NetLogCaptureMode /* capture_mode */) { std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); - dict->SetKey("packet_number", NetLogNumberValue(packet_number)); + dict->SetKey("packet_number", NetLogNumberValue(packet_number.ToUint64())); return std::move(dict); } @@ -103,7 +105,8 @@ std::unique_ptr<base::Value> NetLogQuicPacketHeaderCallback( header->destination_connection_id.ToString()); dict->SetInteger("reset_flag", header->reset_flag); dict->SetInteger("version_flag", header->version_flag); - dict->SetKey("packet_number", NetLogNumberValue(header->packet_number)); + dict->SetKey("packet_number", + NetLogNumberValue(header->packet_number.ToUint64())); return std::move(dict); } @@ -122,7 +125,8 @@ std::unique_ptr<base::Value> NetLogQuicAckFrameCallback( const quic::QuicAckFrame* frame, NetLogCaptureMode /* capture_mode */) { auto dict = std::make_unique<base::DictionaryValue>(); - dict->SetKey("largest_observed", NetLogNumberValue(frame->largest_acked)); + dict->SetKey("largest_observed", + NetLogNumberValue(frame->largest_acked.ToUint64())); dict->SetKey("delta_time_largest_observed_us", NetLogNumberValue(frame->ack_delay_time.ToMicroseconds())); @@ -133,7 +137,7 @@ std::unique_ptr<base::Value> NetLogQuicAckFrameCallback( for (quic::QuicPacketNumber packet = frame->packets.Min(); packet < frame->largest_acked; ++packet) { if (!frame->packets.Contains(packet)) { - missing->GetList().push_back(NetLogNumberValue(packet)); + missing->GetList().push_back(NetLogNumberValue(packet.ToUint64())); } } } @@ -143,7 +147,7 @@ std::unique_ptr<base::Value> NetLogQuicAckFrameCallback( const quic::PacketTimeVector& received_times = frame->received_packet_times; for (auto it = received_times.begin(); it != received_times.end(); ++it) { auto info = std::make_unique<base::DictionaryValue>(); - info->SetKey("packet_number", NetLogNumberValue(it->first)); + info->SetKey("packet_number", NetLogNumberValue(it->first.ToUint64())); info->SetKey("received", NetLogNumberValue(it->second.ToDebuggingValue())); received->Append(std::move(info)); } @@ -202,7 +206,8 @@ std::unique_ptr<base::Value> NetLogQuicStopWaitingFrameCallback( NetLogCaptureMode /* capture_mode */) { auto dict = std::make_unique<base::DictionaryValue>(); auto sent_info = std::make_unique<base::DictionaryValue>(); - sent_info->SetKey("least_unacked", NetLogNumberValue(frame->least_unacked)); + sent_info->SetKey("least_unacked", + NetLogNumberValue(frame->least_unacked.ToUint64())); dict->Set("sent_info", std::move(sent_info)); return std::move(dict); } @@ -239,10 +244,12 @@ std::unique_ptr<base::Value> NetLogQuicCryptoHandshakeMessageCallback( std::unique_ptr<base::Value> NetLogQuicOnConnectionClosedCallback( quic::QuicErrorCode error, + string error_details, quic::ConnectionCloseSource source, NetLogCaptureMode /* capture_mode */) { std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); dict->SetInteger("quic_error", error); + dict->SetString("details", error_details); dict->SetBoolean("from_peer", source == quic::ConnectionCloseSource::FROM_PEER ? true : false); @@ -295,11 +302,9 @@ QuicConnectionLogger::QuicConnectionLogger( const NetLogWithSource& net_log) : net_log_(net_log), session_(session), - last_received_packet_number_(0), last_received_packet_size_(0), no_packet_received_after_ping_(false), previous_received_packet_size_(0), - largest_received_packet_number_(0), num_out_of_order_received_packets_(0), num_out_of_order_large_received_packets_(0), num_packets_received_(0), @@ -460,7 +465,7 @@ void QuicConnectionLogger::OnFrameAddedToPacket(const quic::QuicFrame& frame) { case quic::STOP_WAITING_FRAME: net_log_.AddEvent(NetLogEventType::QUIC_SESSION_STOP_WAITING_FRAME_SENT, base::Bind(&NetLogQuicStopWaitingFrameCallback, - frame.stop_waiting_frame)); + &frame.stop_waiting_frame)); break; case quic::PING_FRAME: UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ConnectionFlowControlBlocked", @@ -508,7 +513,7 @@ void QuicConnectionLogger::OnPacketSent( quic::QuicTime sent_time) { if (!net_log_is_capturing_) return; - if (original_packet_number == 0) { + if (!original_packet_number.IsInitialized()) { net_log_.AddEvent( NetLogEventType::QUIC_SESSION_PACKET_SENT, base::Bind(&NetLogQuicPacketSentCallback, serialized_packet, @@ -595,10 +600,18 @@ void QuicConnectionLogger::OnProtocolVersionMismatch( void QuicConnectionLogger::OnPacketHeader( const quic::QuicPacketHeader& header) { + if (!first_received_packet_number_.IsInitialized()) { + first_received_packet_number_ = header.packet_number; + } else if (header.packet_number < first_received_packet_number_) { + // Ignore packets with packet numbers less than + // first_received_packet_number_. + return; + } ++num_packets_received_; - if (largest_received_packet_number_ < header.packet_number) { - quic::QuicPacketNumber delta = - header.packet_number - largest_received_packet_number_; + if (!largest_received_packet_number_.IsInitialized()) { + largest_received_packet_number_ = header.packet_number; + } else if (largest_received_packet_number_ < header.packet_number) { + uint64_t delta = header.packet_number - largest_received_packet_number_; if (delta > 1) { // There is a gap between the largest packet previously received and // the current packet. This indicates either loss, or out-of-order @@ -609,10 +622,13 @@ void QuicConnectionLogger::OnPacketHeader( } largest_received_packet_number_ = header.packet_number; } - if (header.packet_number < received_packets_.size()) { - received_packets_[static_cast<size_t>(header.packet_number)] = true; + if (header.packet_number - first_received_packet_number_ < + received_packets_.size()) { + received_packets_[header.packet_number - first_received_packet_number_] = + true; } - if (header.packet_number < last_received_packet_number_) { + if (last_received_packet_number_.IsInitialized() && + header.packet_number < last_received_packet_number_) { ++num_out_of_order_received_packets_; if (previous_received_packet_size_ < last_received_packet_size_) ++num_out_of_order_large_received_packets_; @@ -621,10 +637,12 @@ void QuicConnectionLogger::OnPacketHeader( static_cast<base::HistogramBase::Sample>(last_received_packet_number_ - header.packet_number)); } else if (no_packet_received_after_ping_) { - UMA_HISTOGRAM_COUNTS_1M( - "Net.QuicSession.PacketGapReceivedNearPing", - static_cast<base::HistogramBase::Sample>(header.packet_number - - last_received_packet_number_)); + if (last_received_packet_number_.IsInitialized()) { + UMA_HISTOGRAM_COUNTS_1M( + "Net.QuicSession.PacketGapReceivedNearPing", + static_cast<base::HistogramBase::Sample>( + header.packet_number - last_received_packet_number_)); + } no_packet_received_after_ping_ = false; } last_received_packet_number_ = header.packet_number; @@ -640,11 +658,18 @@ void QuicConnectionLogger::OnStreamFrame(const quic::QuicStreamFrame& frame) { base::Bind(&NetLogQuicStreamFrameCallback, frame)); } -void QuicConnectionLogger::OnAckFrame(const quic::QuicAckFrame& frame) { +void QuicConnectionLogger::OnIncomingAck( + const quic::QuicAckFrame& frame, + quic::QuicTime ack_receive_time, + quic::QuicPacketNumber largest_observed, + bool rtt_updated, + quic::QuicPacketNumber least_unacked_sent_packet) { const size_t kApproximateLargestSoloAckBytes = 100; - if (last_received_packet_number_ < received_acks_.size() && + if (last_received_packet_number_ - first_received_packet_number_ < + received_acks_.size() && last_received_packet_size_ < kApproximateLargestSoloAckBytes) { - received_acks_[static_cast<size_t>(last_received_packet_number_)] = true; + received_acks_[last_received_packet_number_ - + first_received_packet_number_] = true; } if (!net_log_is_capturing_) @@ -774,9 +799,9 @@ void QuicConnectionLogger::OnConnectionClosed( quic::ConnectionCloseSource source) { if (!net_log_is_capturing_) return; - net_log_.AddEvent( - NetLogEventType::QUIC_SESSION_CLOSED, - base::Bind(&NetLogQuicOnConnectionClosedCallback, error, source)); + net_log_.AddEvent(NetLogEventType::QUIC_SESSION_CLOSED, + base::Bind(&NetLogQuicOnConnectionClosedCallback, error, + error_details, source)); } void QuicConnectionLogger::OnSuccessfulVersionNegotiation( @@ -823,10 +848,12 @@ base::HistogramBase* QuicConnectionLogger::Get6PacketHistogram( } float QuicConnectionLogger::ReceivedPacketLossRate() const { - if (largest_received_packet_number_ <= num_packets_received_) + if (!largest_received_packet_number_.IsInitialized()) return 0.0f; - float num_received = largest_received_packet_number_ - num_packets_received_; - return num_received / largest_received_packet_number_; + float num_packets = + largest_received_packet_number_ - first_received_packet_number_ + 1; + float num_missing = num_packets - num_packets_received_; + return num_missing / num_packets; } void QuicConnectionLogger::OnRttChanged(quic::QuicTime::Delta rtt) const { @@ -849,7 +876,8 @@ void QuicConnectionLogger::RecordAggregatePacketLossRate() const { // histogram. (e.g., if we only got 5 packets, but lost 1, we'd otherwise // record a 20% loss in this histogram!). We may still get some strange data // (1 loss in 22 is still high :-/). - if (largest_received_packet_number_ <= 21) + if (!largest_received_packet_number_.IsInitialized() || + largest_received_packet_number_ - first_received_packet_number_ < 22) return; string prefix("Net.QuicSession.PacketLossRate_"); diff --git a/chromium/net/quic/quic_connection_logger.h b/chromium/net/quic/quic_connection_logger.h index e3200988409..4eada914fa8 100644 --- a/chromium/net/quic/quic_connection_logger.h +++ b/chromium/net/quic/quic_connection_logger.h @@ -50,6 +50,11 @@ class NET_EXPORT_PRIVATE QuicConnectionLogger quic::QuicPacketNumber original_packet_number, quic::TransmissionType transmission_type, quic::QuicTime sent_time) override; + void OnIncomingAck(const quic::QuicAckFrame& frame, + quic::QuicTime ack_receive_time, + quic::QuicPacketNumber largest_observed, + bool rtt_updated, + quic::QuicPacketNumber least_unacked_sent_packet) override; void OnPacketLoss(quic::QuicPacketNumber lost_packet_number, quic::TransmissionType transmission_type, quic::QuicTime detection_time) override; @@ -64,7 +69,6 @@ class NET_EXPORT_PRIVATE QuicConnectionLogger void OnProtocolVersionMismatch(quic::ParsedQuicVersion version) override; void OnPacketHeader(const quic::QuicPacketHeader& header) override; void OnStreamFrame(const quic::QuicStreamFrame& frame) override; - void OnAckFrame(const quic::QuicAckFrame& frame) override; void OnStopWaitingFrame(const quic::QuicStopWaitingFrame& frame) override; void OnRstStreamFrame(const quic::QuicRstStreamFrame& frame) override; void OnConnectionCloseFrame( @@ -118,6 +122,11 @@ class NET_EXPORT_PRIVATE QuicConnectionLogger bool no_packet_received_after_ping_; // The size of the previously received packet. size_t previous_received_packet_size_; + // The first received packet number. Used as the left edge of + // received_packets_ and received_acks_. In the case where packets are + // received out of order, packets with numbers smaller than + // first_received_packet_number_ will not be logged. + quic::QuicPacketNumber first_received_packet_number_; // The largest packet number received. In the case where a packet is // received late (out of order), this value will not be updated. quic::QuicPacketNumber largest_received_packet_number_; @@ -152,13 +161,13 @@ class NET_EXPORT_PRIVATE QuicConnectionLogger // Count of the number of BLOCKED frames sent. int num_blocked_frames_sent_; // Vector of inital packets status' indexed by packet numbers, where - // false means never received. Zero is not a valid packet number, so - // that offset is never used, and we'll track 150 packets. - std::bitset<151> received_packets_; + // false means never received. We track 150 packets starting from + // first_received_packet_number_. + std::bitset<150> received_packets_; // Vector to indicate which of the initial 150 received packets turned out to // contain solo ACK frames. An element is true iff an ACK frame was in the // corresponding packet, and there was very little else. - std::bitset<151> received_acks_; + std::bitset<150> received_acks_; // The available type of connection (WiFi, 3G, etc.) when connection was first // used. const char* const connection_description_; diff --git a/chromium/net/quic/quic_connectivity_probing_manager.cc b/chromium/net/quic/quic_connectivity_probing_manager.cc index 223ad97a823..78e8461cbb3 100644 --- a/chromium/net/quic/quic_connectivity_probing_manager.cc +++ b/chromium/net/quic/quic_connectivity_probing_manager.cc @@ -4,6 +4,7 @@ #include "net/quic/quic_connectivity_probing_manager.h" +#include "base/bind.h" #include "base/metrics/histogram_macros.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" @@ -46,7 +47,7 @@ std::unique_ptr<base::Value> NetLogProbingDestinationCallback( const quic::QuicSocketAddress* peer_address, NetLogCaptureMode capture_mode) { std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); - dict->SetString("network", base::Int64ToString(network)); + dict->SetString("network", base::NumberToString(network)); dict->SetString("peer address", peer_address->ToString()); return std::move(dict); } @@ -79,8 +80,8 @@ int QuicConnectivityProbingManager::HandleWriteError( // undergoing probing, which will delete the packet writer. task_runner_->PostTask( FROM_HERE, - base::Bind(&QuicConnectivityProbingManager::NotifyDelegateProbeFailed, - weak_factory_.GetWeakPtr())); + base::BindOnce(&QuicConnectivityProbingManager::NotifyDelegateProbeFailed, + weak_factory_.GetWeakPtr())); return error_code; } diff --git a/chromium/net/quic/quic_connectivity_probing_manager.h b/chromium/net/quic/quic_connectivity_probing_manager.h index 9931a372f80..8a4795e0f47 100644 --- a/chromium/net/quic/quic_connectivity_probing_manager.h +++ b/chromium/net/quic/quic_connectivity_probing_manager.h @@ -6,6 +6,7 @@ #define NET_QUIC_QUIC_CONNECTIVITY_PROBING_MANAGER_H_ #include "base/time/time.h" +#include "base/timer/timer.h" #include "net/base/net_export.h" #include "net/log/net_log_with_source.h" #include "net/quic/quic_chromium_packet_reader.h" diff --git a/chromium/net/quic/quic_end_to_end_unittest.cc b/chromium/net/quic/quic_end_to_end_unittest.cc index 8478688e717..30adf6d6dd7 100644 --- a/chromium/net/quic/quic_end_to_end_unittest.cc +++ b/chromium/net/quic/quic_end_to_end_unittest.cc @@ -75,7 +75,7 @@ class TestTransactionFactory : public HttpTransactionFactory { HttpCache* GetCache() override { return nullptr; } - HttpNetworkSession* GetSession() override { return session_.get(); }; + HttpNetworkSession* GetSession() override { return session_.get(); } private: std::unique_ptr<HttpNetworkSession> session_; @@ -107,8 +107,7 @@ class QuicEndToEndTest : public ::testing::TestWithParam<TestParams>, cert_transparency_verifier_(new MultiLogCTVerifier()), ssl_config_service_(new SSLConfigServiceDefaults), proxy_resolution_service_(ProxyResolutionService::CreateDirect()), - auth_handler_factory_( - HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), + auth_handler_factory_(HttpAuthHandlerFactory::CreateDefault()), strike_register_no_startup_period_(false) { request_.method = "GET"; request_.url = GURL("https://test.example.com/"); @@ -157,8 +156,9 @@ class QuicEndToEndTest : public ::testing::TestWithParam<TestParams>, // Use a mapped host resolver so that request for test.example.com (port 80) // reach the server running on localhost. - std::string map_rule = "MAP test.example.com test.example.com:" + - base::IntToString(server_->server_address().port()); + std::string map_rule = + "MAP test.example.com test.example.com:" + + base::NumberToString(server_->server_address().port()); EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule)); // To simplify the test, and avoid the race with the HTTP request, we force @@ -261,9 +261,9 @@ class QuicEndToEndTest : public ::testing::TestWithParam<TestParams>, bool strike_register_no_startup_period_; }; -INSTANTIATE_TEST_CASE_P(Tests, - QuicEndToEndTest, - ::testing::ValuesIn(GetTestParams())); +INSTANTIATE_TEST_SUITE_P(Tests, + QuicEndToEndTest, + ::testing::ValuesIn(GetTestParams())); TEST_P(QuicEndToEndTest, LargeGetWithNoPacketLoss) { std::string response(10 * 1024, 'x'); diff --git a/chromium/net/quic/quic_flags_list.h b/chromium/net/quic/quic_flags_list.h index 052ab3910ec..ac1a62a1e34 100644 --- a/chromium/net/quic/quic_flags_list.h +++ b/chromium/net/quic/quic_flags_list.h @@ -6,6 +6,7 @@ // inside a macro to generate values. The following line silences a // presubmit warning that would otherwise be triggered by this: // no-include-guard-because-multiply-included +// NOLINT(build/header_guard) // This file contains the list of QUIC protocol flags. @@ -149,23 +150,6 @@ QUIC_FLAG(bool, // expire when the bandwidth increases more than 25% in QUIC BBR STARTUP. QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_bbr_slower_startup4, false) -// If true, try to aggregate acked stream frames. -QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_aggregate_acked_stream_frames_2, - true) - -// If true, disable QUIC version 35. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_disable_version_35, true) - -// If true, increase size of random bytes in IETF stateless reset packet. -QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_more_random_bytes_in_stateless_reset, - false) - -// If true, use new, lower-overhead implementation of LRU cache for compressed -// certificates. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_new_lru_cache, true) - // When true and the BBR9 connection option is present, BBR only considers // bandwidth samples app-limited if they're not filling the pipe. QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_bbr_flexible_app_limited, false) @@ -176,15 +160,6 @@ QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_stop_reading_when_level_triggered, false) -// If true, mark packets for loss retransmission even they do not contain -// retransmittable frames. -QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_fix_mark_for_loss_retransmission, - true) - -// If true, enable version 45. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_enable_version_45, false) - // If true, QuicSession::HasPendingCryptoData checks whether the crypto stream's // send buffer is empty. This flag fixes a bug where the retransmission alarm // mode is wrong for the first CHLO packet. @@ -203,30 +178,14 @@ QUIC_FLAG( // ACK frame are sent and processed. QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_send_timestamps, false) -// When true, QUIC server push uses a unidirectional stream. -QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_unidirectional_server_push_stream, - true) - -// This flag fixes a bug where dispatcher's last_packet_is_ietf_quic may be -// wrong when getting proof asynchronously. -QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_fix_last_packet_is_ietf_quic, - true) - // If true, dispatcher passes in a single version when creating a server // connection, such that version negotiation is not supported in connection. QUIC_FLAG(bool, FLAGS_quic_restart_flag_quic_no_server_conn_ver_negotiation2, false) -// If true, enable QUIC version 46 which adds CRYPTO frames. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_enable_version_46, false) - -// When true, cache that encryption has been established to save CPU. -QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_optimize_encryption_established, - true) +// If true, enable QUIC version 46. +QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_enable_version_46, true) // When in STARTUP and recovery, do not add bytes_acked to QUIC BBR's CWND in // CalculateCongestionWindow() @@ -235,10 +194,6 @@ QUIC_FLAG( FLAGS_quic_reloadable_flag_quic_bbr_no_bytes_acked_in_startup_recovery, false) -// If true, make GeneralLossAlgorithm::DetectLosses faster by never rescanning -// the same packet in QuicUnackedPacketMap. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_faster_detect_loss, false) - // If true, use common code for checking whether a new stream ID may be // allocated. QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_use_common_stream_check, false) @@ -258,7 +213,7 @@ QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_fix_spurious_ack_alarm, false) // If true, QuicSpdyStream::WritevBody() will convert iovs into QuicMemSliceSpan // and call WriteMemSlices instead. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_call_write_mem_slices, false) +QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_call_write_mem_slices, true) // If true, enables the BBS4 and BBS5 connection options, which reduce BBR's // pacing rate in STARTUP as more losses occur as a fraction of CWND. @@ -266,72 +221,82 @@ QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_bbr_startup_rate_reduction, false) -// If true, only send version negotiation packets when they are at least -// 1200 bytes. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_limit_version_negotiation, true) - -// If true, disables key share caching for QUIC key exchange -QUIC_FLAG(bool, FLAGS_quic_restart_flag_quic_no_ephemeral_key_source, true) - -// If true, QuicDispatcher will not assume all blocked writers share the same -// opinion about whether their packet writers are blocked. -QUIC_FLAG(bool, - FLAGS_quic_restart_flag_quic_check_blocked_writer_for_blockage, - false) - -// If true, for QUIC V44, if a server connection is post handshake and has no -// termination packets, add it to time wait list with -// action=SEND_STATELESS_RESET. -QUIC_FLAG( - bool, - FLAGS_quic_reloadable_flag_quic_send_reset_for_post_handshake_connections_without_termination_packets, - true) - // If true, disconnected quic connection will not be added to dispatcher's write // blocked list. QUIC_FLAG( bool, FLAGS_quic_reloadable_flag_quic_connection_do_not_add_to_write_blocked_list_if_disconnected, - false) + true) -// Changes internal in-memory representation of QUIC connection IDs to network -// byte order. +// If true, QuicPacketCreator::SetTransmissionType will set the transmission +// type of the next successfully added frame. QUIC_FLAG(bool, - FLAGS_quic_restart_flag_quic_connection_ids_network_byte_order, + FLAGS_quic_reloadable_flag_quic_set_transmission_type_for_next_frame, true) -// Allows use of new QUIC connection ID constructor designed for -// variable-length connection IDs when acting as client. +// If true, log leaf cert subject name into warning log. QUIC_FLAG(bool, - FLAGS_quic_restart_flag_quic_variable_length_connection_ids_client, + FLAGS_quic_reloadable_flag_quic_log_cert_name_for_empty_sct, true) -// Allows use of new QUIC connection ID constructor designed for -// variable-length connection IDs when acting as server -QUIC_FLAG(bool, - FLAGS_quic_restart_flag_quic_variable_length_connection_ids_server, - true) -// If true, QuicPacketCreator::SetTransmissionType will set the transmission -// type of the next successfully added frame. +// If true, QuicCryptoServerConfig will correctly rotate configs based on +// primary time. +QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_fix_config_rotation, true) + +// If true, use numeric_limits<uint64_t>::max() to represent uninitialized +// packet number. +QUIC_FLAG(bool, FLAGS_quic_restart_flag_quic_uint64max_uninitialized_pn, true) + +// If true, enable QUIC version 47 which adds CRYPTO frames. +QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_enable_version_47, false) + +// If true, disable QUIC version 39. +QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_disable_version_39, false) + +// If true, simplifies the implementation of +// QuicFramer::BuildConnectivityProbingPacket(). +QUIC_FLAG( + bool, + FLAGS_quic_reloadable_flag_quic_simplify_build_connectivity_probing_packet, + true) + +// If true, use one loss algorithm per encryption level. +QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_use_uber_loss_algorithm, false) + +// When true, QuicFramer will use AppendIetfConnectionIdsNew instead of +// AppendIetfConnectionId. QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_set_transmission_type_for_next_frame, + FLAGS_quic_reloadable_flag_quic_use_new_append_connection_id, false) -// If true, always send connection close/reset for IETF connections. -QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_always_reset_ietf_connections, - true) -// When true, allows the AKD2 and AKD4 connection options to continue activating -// ack decimation with reordering. +// If true, QuicStreamSequencerBuffer will switch to a new +// QuicIntervalSet::AddOptimizedForAppend method in OnStreamData(). +QUIC_FLAG( + bool, + FLAGS_quic_reloadable_flag_quic_faster_interval_add_in_sequence_buffer, + false) + +// If true, GFE time wait list will send termination packets based on current +// packet's encryption level. +QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_fix_termination_packets, false) + +// If true, stop using AckBundling mode to send ACK, also deprecate ack_queued +// from QuicConnection. QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_keep_ack_decimation_reordering, + FLAGS_quic_reloadable_flag_quic_deprecate_ack_bundling_mode, false) -// If true, close QUIC connection if peer acks packet number 0 because our -// implementation never sends packet number 0. -QUIC_FLAG(bool, FLAGS_quic_reloadable_flag_quic_disallow_peer_ack_0, true) +// If true, enforce that QUIC CHLOs fit in one packet. +QUIC_FLAG(bool, FLAGS_quic_enforce_single_packet_chlo, true) -// If true, log leaf cert subject name into warning log. +// If both this flag and gfe2_reloadable_flag_quic_deprecate_ack_bundling_mode +// are true, QuicReceivedPacketManager decides when to send ACKs. QUIC_FLAG(bool, - FLAGS_quic_reloadable_flag_quic_log_cert_name_for_empty_sct, - true) + FLAGS_quic_reloadable_flag_quic_rpm_decides_when_to_send_acks, + false) + +// If true, instead of send encryption none termination packets, send stateless +// reset in reponse to short headers. +QUIC_FLAG(bool, + FLAGS_quic_reloadable_flag_quic_always_reset_short_header_packets, + false) diff --git a/chromium/net/quic/quic_http_stream.cc b/chromium/net/quic/quic_http_stream.cc index 08f91f4ce43..9702ee6d177 100644 --- a/chromium/net/quic/quic_http_stream.cc +++ b/chromium/net/quic/quic_http_stream.cc @@ -7,10 +7,12 @@ #include <utility> #include "base/auto_reset.h" +#include "base/bind.h" #include "base/callback_helpers.h" #include "base/metrics/histogram_macros.h" #include "base/strings/string_split.h" #include "base/threading/thread_task_runner_handle.h" +#include "net/base/ip_endpoint.h" #include "net/base/load_flags.h" #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" @@ -80,18 +82,16 @@ HttpResponseInfo::ConnectionInfo QuicHttpStream::ConnectionInfoFromQuicVersion( switch (quic_version) { case quic::QUIC_VERSION_UNSUPPORTED: return HttpResponseInfo::CONNECTION_INFO_QUIC_UNKNOWN_VERSION; - case quic::QUIC_VERSION_35: - return HttpResponseInfo::CONNECTION_INFO_QUIC_35; case quic::QUIC_VERSION_39: return HttpResponseInfo::CONNECTION_INFO_QUIC_39; case quic::QUIC_VERSION_43: return HttpResponseInfo::CONNECTION_INFO_QUIC_43; case quic::QUIC_VERSION_44: return HttpResponseInfo::CONNECTION_INFO_QUIC_44; - case quic::QUIC_VERSION_45: - return HttpResponseInfo::CONNECTION_INFO_QUIC_45; case quic::QUIC_VERSION_46: return HttpResponseInfo::CONNECTION_INFO_QUIC_46; + case quic::QUIC_VERSION_47: + return HttpResponseInfo::CONNECTION_INFO_QUIC_47; case quic::QUIC_VERSION_99: return HttpResponseInfo::CONNECTION_INFO_QUIC_99; } @@ -679,7 +679,7 @@ int QuicHttpStream::ProcessResponseHeaders( if (rv != OK) return rv; - response_info_->socket_address = HostPortPair::FromIPEndPoint(address); + response_info_->remote_endpoint = address; response_info_->connection_info = ConnectionInfoFromQuicVersion(quic_session()->GetQuicVersion()); response_info_->vary_data.Init(*request_info_, diff --git a/chromium/net/quic/quic_http_stream_test.cc b/chromium/net/quic/quic_http_stream_test.cc index c9455d8ddca..3384fee4a33 100644 --- a/chromium/net/quic/quic_http_stream_test.cc +++ b/chromium/net/quic/quic_http_stream_test.cc @@ -9,11 +9,13 @@ #include <memory> #include <utility> +#include "base/bind.h" #include "base/memory/ptr_util.h" #include "base/run_loop.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/time/default_tick_clock.h" #include "base/time/time.h" #include "net/base/chunked_upload_data_stream.h" #include "net/base/elements_upload_data_stream.h" @@ -51,6 +53,7 @@ #include "net/third_party/quic/core/crypto/quic_encrypter.h" #include "net/third_party/quic/core/http/spdy_utils.h" #include "net/third_party/quic/core/quic_connection.h" +#include "net/third_party/quic/core/quic_utils.h" #include "net/third_party/quic/core/quic_write_blocked_list.h" #include "net/third_party/quic/core/tls_client_handshaker.h" #include "net/third_party/quic/platform/api/quic_string_piece.h" @@ -121,8 +124,8 @@ class ReadErrorUploadDataStream : public UploadDataStream { int ReadInternal(IOBuffer* buf, int buf_len) override { if (async_ == FailureMode::ASYNC) { base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, - weak_factory_.GetWeakPtr())); + FROM_HERE, base::BindOnce(&ReadErrorUploadDataStream::CompleteRead, + weak_factory_.GetWeakPtr())); return ERR_IO_PENDING; } return ERR_FAILED; @@ -321,17 +324,22 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< PRIVACY_MODE_DISABLED, SocketTag()), /*require_confirmation=*/false, /*migrate_session_early_v2=*/false, /*migrate_session_on_network_change_v2=*/false, - /*go_away_on_path_degrading*/ false, /*default_network=*/NetworkChangeNotifier::kInvalidNetworkHandle, + quic::QuicTime::Delta::FromMilliseconds( + kDefaultRetransmittableOnWireTimeoutMillisecs), + /*migrate_idle_session=*/false, + base::TimeDelta::FromSeconds(kDefaultIdleSessionMigrationPeriodSeconds), base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), kMaxMigrationsToNonDefaultNetworkOnWriteError, kMaxMigrationsToNonDefaultNetworkOnPathDegrading, kQuicYieldAfterPacketsRead, quic::QuicTime::Delta::FromMilliseconds( kQuicYieldAfterDurationMilliseconds), + /*go_away_on_path_degrading*/ false, client_headers_include_h2_stream_dependency_, /*cert_verify_flags=*/0, quic::test::DefaultQuicConfig(), &crypto_config_, "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, + base::DefaultTickClock::GetInstance(), base::ThreadTaskRunnerHandle::Get().get(), /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); session_->Initialize(); @@ -367,7 +375,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> InnerConstructDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -379,7 +387,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, bool fin, quic::QuicStreamOffset offset, @@ -391,7 +399,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< std::unique_ptr<quic::QuicReceivedPacket> ConstructClientMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, bool fin, quic::QuicStreamOffset offset, @@ -401,7 +409,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, bool fin, quic::QuicStreamOffset offset, @@ -412,7 +420,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> InnerConstructRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -425,7 +433,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> InnerConstructRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -443,7 +451,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< std::unique_ptr<quic::QuicReceivedPacket> ConstructRequestHeadersAndDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -461,7 +469,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructRequestAndRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -481,7 +489,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin, RequestPriority request_priority, size_t* spdy_headers_frame_length) { @@ -491,7 +499,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> InnerConstructResponseHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool fin, size_t* spdy_headers_frame_length) { @@ -502,7 +510,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructResponseHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin, size_t* spdy_headers_frame_length) { return InnerConstructResponseHeadersPacket(packet_number, stream_id_, fin, @@ -510,7 +518,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> - ConstructResponseHeadersPacketWithOffset(quic::QuicPacketNumber packet_number, + ConstructResponseHeadersPacketWithOffset(uint64_t packet_number, bool fin, size_t* spdy_headers_frame_length, quic::QuicStreamOffset* offset) { @@ -520,7 +528,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructResponseTrailersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin, spdy::SpdyHeaderBlock trailers, size_t* spdy_headers_frame_length, @@ -531,21 +539,19 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientRstStreamPacket( - quic::QuicPacketNumber packet_number) { + uint64_t packet_number) { return client_maker_.MakeRstPacket(packet_number, true, stream_id_, quic::QUIC_RST_ACKNOWLEDGEMENT); } std::unique_ptr<quic::QuicReceivedPacket> - ConstructClientRstStreamCancelledPacket( - quic::QuicPacketNumber packet_number) { + ConstructClientRstStreamCancelledPacket(uint64_t packet_number) { return client_maker_.MakeRstPacket(packet_number, !kIncludeVersion, stream_id_, quic::QUIC_STREAM_CANCELLED); } std::unique_ptr<quic::QuicReceivedPacket> - ConstructClientRstStreamVaryMismatchPacket( - quic::QuicPacketNumber packet_number) { + ConstructClientRstStreamVaryMismatchPacket(uint64_t packet_number) { return client_maker_.MakeRstPacket(packet_number, !kIncludeVersion, promise_id_, quic::QUIC_PROMISE_VARY_MISMATCH); @@ -553,7 +559,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< std::unique_ptr<quic::QuicReceivedPacket> ConstructClientRstStreamVaryMismatchAndRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -571,10 +577,10 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndRstStreamPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckAndRstPacket( packet_number, !kIncludeVersion, stream_id_, quic::QUIC_STREAM_CANCELLED, largest_received, smallest_received, @@ -582,7 +588,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientRstStreamErrorPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool include_version) { return client_maker_.MakeRstPacket(packet_number, include_version, stream_id_, @@ -590,32 +596,32 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< } std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndRstStreamPacket( - quic::QuicPacketNumber packet_number) { + uint64_t packet_number) { return ConstructAckAndRstStreamPacket(packet_number, 2, 1, 2); } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, !kIncludeCongestionFeedback); } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return server_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, !kIncludeCongestionFeedback); } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientPriorityPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, quic::QuicStreamId id, quic::QuicStreamId parent_stream_id, @@ -720,7 +726,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam< quic::QuicStreamOffset response_offset_; }; -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( VersionIncludeStreamDependencySequence, QuicHttpStreamTest, ::testing::Combine( @@ -950,7 +956,7 @@ TEST_P(QuicHttpStreamTest, GetRequestWithTrailers) { size_t spdy_trailers_frame_length; trailers["foo"] = "bar"; trailers[quic::kFinalOffsetHeaderKey] = - base::IntToString(strlen(kResponseBody) + header.length()); + base::NumberToString(strlen(kResponseBody) + header.length()); ProcessPacket(ConstructResponseTrailersPacket( 4, kFin, std::move(trailers), &spdy_trailers_frame_length, &offset)); @@ -1168,8 +1174,7 @@ TEST_P(QuicHttpStreamTest, LogGranularQuicErrorIfHandshakeNotConfirmed) { SetRequest("GET", "/", DEFAULT_PRIORITY); size_t spdy_request_headers_frame_length; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); AddWrite(InnerConstructRequestHeadersPacket( 1, GetNthClientInitiatedBidirectionalStreamId(0), kIncludeVersion, kFin, DEFAULT_PRIORITY, &spdy_request_headers_frame_length, @@ -2305,7 +2310,7 @@ TEST_P(QuicHttpStreamTest, ServerPushVaryCheckFail) { quic::QuicStreamOffset header_stream_offset = 0; AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); - quic::QuicPacketNumber client_packet_number = 2; + uint64_t client_packet_number = 2; if (client_headers_include_h2_stream_dependency_ && version_ >= quic::QUIC_VERSION_43) { AddWrite(ConstructClientPriorityPacket( @@ -2313,9 +2318,10 @@ TEST_P(QuicHttpStreamTest, ServerPushVaryCheckFail) { DEFAULT_PRIORITY, &header_stream_offset)); } AddWrite(ConstructClientRstStreamVaryMismatchAndRequestHeadersPacket( - client_packet_number++, stream_id_ + quic::test::NextStreamId(version_), - !kIncludeVersion, kFin, DEFAULT_PRIORITY, promise_id_, - &spdy_request_header_frame_length, &header_stream_offset)); + client_packet_number++, + stream_id_ + quic::QuicUtils::StreamIdDelta(version_), !kIncludeVersion, + kFin, DEFAULT_PRIORITY, promise_id_, &spdy_request_header_frame_length, + &header_stream_offset)); AddWrite(ConstructClientAckPacket(client_packet_number++, 3, 1, 2)); AddWrite(ConstructClientRstStreamCancelledPacket(client_packet_number++)); @@ -2375,7 +2381,7 @@ TEST_P(QuicHttpStreamTest, ServerPushVaryCheckFail) { EXPECT_EQ( QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) ->id(), - stream_id_ + quic::test::NextStreamId(version_)); + stream_id_ + quic::QuicUtils::StreamIdDelta(version_)); // After rendezvous failure, the push stream has been cancelled. EXPECT_EQ(session_->GetPromisedByUrl(promise_url_), nullptr); @@ -2389,7 +2395,7 @@ TEST_P(QuicHttpStreamTest, ServerPushVaryCheckFail) { SetResponse("404 Not Found", string()); size_t spdy_response_header_frame_length; ProcessPacket(InnerConstructResponseHeadersPacket( - 3, stream_id_ + quic::test::NextStreamId(version_), kFin, + 3, stream_id_ + quic::QuicUtils::StreamIdDelta(version_), kFin, &spdy_response_header_frame_length)); base::RunLoop().RunUntilIdle(); diff --git a/chromium/net/quic/quic_http_utils.cc b/chromium/net/quic/quic_http_utils.cc index 13deeff2d90..2b3dda387a3 100644 --- a/chromium/net/quic/quic_http_utils.cc +++ b/chromium/net/quic/quic_http_utils.cc @@ -20,7 +20,7 @@ void RecordAltSvcFormat(AltSvcFormat format) { UMA_HISTOGRAM_ENUMERATION("Net.QuicAltSvcFormat", format, ALTSVC_FORMAT_MAX); } -}; // namespace +} // namespace spdy::SpdyPriority ConvertRequestPriorityToQuicPriority( const RequestPriority priority) { diff --git a/chromium/net/quic/quic_http_utils_test.cc b/chromium/net/quic/quic_http_utils_test.cc index e9f274616b7..137e1c18944 100644 --- a/chromium/net/quic/quic_http_utils_test.cc +++ b/chromium/net/quic/quic_http_utils_test.cc @@ -39,7 +39,7 @@ TEST(QuicHttpUtilsTest, ConvertQuicPriorityToRequestPriority) { TEST(QuicHttpUtilsTest, FilterSupportedAltSvcVersions) { quic::QuicTransportVersionVector supported_versions = { - quic::QUIC_VERSION_35, quic::QUIC_VERSION_39, quic::QUIC_VERSION_44}; + quic::QUIC_VERSION_46, quic::QUIC_VERSION_39, quic::QUIC_VERSION_44}; std::vector<uint32_t> alt_svc_versions_google = {quic::QUIC_VERSION_44, quic::QUIC_VERSION_43}; diff --git a/chromium/net/quic/quic_network_transaction_unittest.cc b/chromium/net/quic/quic_network_transaction_unittest.cc index dccd471f01e..7d4adc5786b 100644 --- a/chromium/net/quic/quic_network_transaction_unittest.cc +++ b/chromium/net/quic/quic_network_transaction_unittest.cc @@ -8,6 +8,7 @@ #include <utility> #include <vector> +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/macros.h" #include "base/run_loop.h" @@ -18,6 +19,7 @@ #include "base/test/metrics/histogram_tester.h" #include "net/base/chunked_upload_data_stream.h" #include "net/base/completion_once_callback.h" +#include "net/base/ip_endpoint.h" #include "net/base/mock_network_change_notifier.h" #include "net/base/test_completion_callback.h" #include "net/base/test_proxy_delegate.h" @@ -145,7 +147,7 @@ std::string GenerateQuicVersionsListForAltSvcHeader( for (const quic::QuicTransportVersion& version : versions) { if (!result.empty()) result.append(","); - result.append(base::IntToString(version)); + result.append(base::NumberToString(version)); } return result; } @@ -277,8 +279,7 @@ class QuicNetworkTransactionTest cert_transparency_verifier_(new MultiLogCTVerifier()), ssl_config_service_(new SSLConfigServiceDefaults), proxy_resolution_service_(ProxyResolutionService::CreateDirect()), - auth_handler_factory_( - HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), + auth_handler_factory_(HttpAuthHandlerFactory::CreateDefault()), ssl_data_(ASYNC, OK) { request_.method = "GET"; std::string url("https://"); @@ -312,38 +313,38 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientConnectionClosePacket(quic::QuicPacketNumber num) { + ConstructClientConnectionClosePacket(uint64_t num) { return client_maker_.MakeConnectionClosePacket( num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructServerConnectionClosePacket(quic::QuicPacketNumber num) { + ConstructServerConnectionClosePacket(uint64_t num) { return server_maker_.MakeConnectionClosePacket( num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); } std::unique_ptr<quic::QuicEncryptedPacket> ConstructServerGoAwayPacket( - quic::QuicPacketNumber num, + uint64_t num, quic::QuicErrorCode error_code, std::string reason_phrase) { return server_maker_.MakeGoAwayPacket(num, error_code, reason_phrase); } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, true); } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicTime::Delta ack_delay_time) { return client_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, true, @@ -351,43 +352,43 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckAndRstPacket( - quic::QuicPacketNumber num, + uint64_t num, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckAndRstPacket( num, false, stream_id, error_code, largest_received, smallest_received, least_unacked, true); } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( - quic::QuicPacketNumber num, + uint64_t num, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, size_t bytes_written) { return client_maker_.MakeRstPacket(num, false, stream_id, error_code, - bytes_written); + bytes_written, + /*include_stop_sending_if_v99=*/true); } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientAckAndConnectionClosePacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + ConstructClientAckAndConnectionClosePacket(uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, true); } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckAndConnectionClosePacket( - quic::QuicPacketNumber num, + uint64_t num, quic::QuicTime::Delta delta_time_largest_observed, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicErrorCode quic_error, const std::string& quic_error_details) { return client_maker_.MakeAckAndConnectionClosePacket( @@ -396,7 +397,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructServerRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code) { @@ -405,22 +406,22 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset* offset) { return client_maker_.MakeInitialSettingsPacket(packet_number, offset); } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return server_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, false); } std::unique_ptr<quic::QuicReceivedPacket> ConstructClientPriorityPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, quic::QuicStreamId id, quic::QuicStreamId parent_stream_id, @@ -433,11 +434,11 @@ class QuicNetworkTransactionTest std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckAndPriorityFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, const std::vector<QuicTestPacketMaker::Http2StreamDependency>& priority_frames, quic::QuicStreamOffset* offset) { @@ -476,7 +477,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructServerDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -487,7 +488,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -499,7 +500,7 @@ class QuicNetworkTransactionTest std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -511,12 +512,12 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckAndDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool include_version, quic::QuicStreamId stream_id, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool fin, quic::QuicStreamOffset offset, quic::QuicStringPiece data) { @@ -527,12 +528,12 @@ class QuicNetworkTransactionTest std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool include_version, quic::QuicStreamId stream_id, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool fin, quic::QuicStreamOffset offset, const std::vector<std::string> data_writes) { @@ -542,7 +543,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientForceHolDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -553,7 +554,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientRequestHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructClientRequestHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -564,7 +565,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientRequestHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructClientRequestHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -576,7 +577,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientRequestHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructClientRequestHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -589,7 +590,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientRequestHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructClientRequestHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -606,7 +607,7 @@ class QuicNetworkTransactionTest std::unique_ptr<quic::QuicReceivedPacket> ConstructClientRequestHeadersAndDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -625,7 +626,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientMultipleDataFramesPacket(quic::QuicPacketNumber packet_number, + ConstructClientMultipleDataFramesPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -636,7 +637,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructServerPushPromisePacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, quic::QuicStreamId promised_stream_id, bool should_include_version, @@ -649,7 +650,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructServerResponseHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructServerResponseHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -660,7 +661,7 @@ class QuicNetworkTransactionTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructServerResponseHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructServerResponseHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -729,7 +730,7 @@ class QuicNetworkTransactionTest void CheckResponsePort(HttpNetworkTransaction* trans, uint16_t port) { const HttpResponseInfo* response = trans->GetResponseInfo(); ASSERT_TRUE(response != nullptr); - EXPECT_EQ(port, response->socket_address.port()); + EXPECT_EQ(port, response->remote_endpoint.port()); } void CheckWasHttpResponse(HttpNetworkTransaction* trans) { @@ -998,7 +999,7 @@ class QuicNetworkTransactionTest } }; -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( VersionIncludeStreamDependencySequence, QuicNetworkTransactionTest, ::testing::Combine( @@ -1243,7 +1244,7 @@ TEST_P(QuicNetworkTransactionTest, LargeResponseHeaders) { spdy::SpdySerializedFrame spdy_frame = response_framer.SerializeFrame(headers_frame); - quic::QuicPacketNumber packet_number = 1; + uint64_t packet_number = 1; size_t chunk_size = 1200; for (size_t offset = 0; offset < spdy_frame.size(); offset += chunk_size) { size_t len = std::min(chunk_size, spdy_frame.size() - offset); @@ -1302,7 +1303,7 @@ TEST_P(QuicNetworkTransactionTest, TooLargeResponseHeaders) { spdy::SpdySerializedFrame spdy_frame = response_framer.SerializeFrame(headers_frame); - quic::QuicPacketNumber packet_number = 1; + uint64_t packet_number = 1; size_t chunk_size = 1200; for (size_t offset = 0; offset < spdy_frame.size(); offset += chunk_size) { size_t len = std::min(chunk_size, spdy_frame.size() - offset); @@ -2216,13 +2217,6 @@ TEST_P(QuicNetworkTransactionTest, GoAwayWithConnectionMigrationOnPortsOnly) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -2230,7 +2224,7 @@ TEST_P(QuicNetworkTransactionTest, GoAwayWithConnectionMigrationOnPortsOnly) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( @@ -2251,11 +2245,14 @@ TEST_P(QuicNetworkTransactionTest, GoAwayWithConnectionMigrationOnPortsOnly) { // alternate network as well, QUIC is marked as broken and the brokenness will // not expire when default network changes. TEST_P(QuicNetworkTransactionTest, QuicFailsOnBothNetworksWhileTCPSucceeds) { + if (version_ >= quic::QUIC_VERSION_47) { + // TODO(nharper): reenable once MakeDummyCHLOPacket() fixed + return; + } SetUpTestForRetryConnectionOnAlternateNetwork(); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); // The request will initially go out over QUIC. MockQuicData quic_data; @@ -2308,13 +2305,6 @@ TEST_P(QuicNetworkTransactionTest, QuicFailsOnBothNetworksWhileTCPSucceeds) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -2332,7 +2322,7 @@ TEST_P(QuicNetworkTransactionTest, QuicFailsOnBothNetworksWhileTCPSucceeds) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -2375,11 +2365,14 @@ TEST_P(QuicNetworkTransactionTest, QuicFailsOnBothNetworksWhileTCPSucceeds) { // alternate network, QUIC is marked as broken. The brokenness will expire when // the default network changes. TEST_P(QuicNetworkTransactionTest, RetryOnAlternateNetworkWhileTCPSucceeds) { + if (version_ >= quic::QUIC_VERSION_47) { + // TODO(nharper): reenable once MakeDummyCHLOPacket() fixed + return; + } SetUpTestForRetryConnectionOnAlternateNetwork(); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); // The request will initially go out over QUIC. MockQuicData quic_data; @@ -2439,13 +2432,6 @@ TEST_P(QuicNetworkTransactionTest, RetryOnAlternateNetworkWhileTCPSucceeds) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -2463,7 +2449,7 @@ TEST_P(QuicNetworkTransactionTest, RetryOnAlternateNetworkWhileTCPSucceeds) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -2513,11 +2499,14 @@ TEST_P(QuicNetworkTransactionTest, RetryOnAlternateNetworkWhileTCPSucceeds) { // before handshake is confirmed. If TCP doesn't succeed but QUIC on the // alternative network succeeds, QUIC is not marked as broken. TEST_P(QuicNetworkTransactionTest, RetryOnAlternateNetworkWhileTCPHanging) { + if (version_ >= quic::QUIC_VERSION_47) { + // TODO(nharper): reenable once MakeDummyCHLOPacket() fixed + return; + } SetUpTestForRetryConnectionOnAlternateNetwork(); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); // The request will initially go out over QUIC. MockQuicData quic_data; @@ -2583,13 +2572,6 @@ TEST_P(QuicNetworkTransactionTest, RetryOnAlternateNetworkWhileTCPHanging) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -2607,7 +2589,7 @@ TEST_P(QuicNetworkTransactionTest, RetryOnAlternateNetworkWhileTCPHanging) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -2656,8 +2638,7 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmed) { ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -2724,13 +2705,6 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmed) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -2744,7 +2718,7 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmed) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -2774,8 +2748,7 @@ TEST_P(QuicNetworkTransactionTest, TooManyRtosAfterHandshakeConfirmed) { ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -2850,13 +2823,6 @@ TEST_P(QuicNetworkTransactionTest, TooManyRtosAfterHandshakeConfirmed) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -2870,7 +2836,7 @@ TEST_P(QuicNetworkTransactionTest, TooManyRtosAfterHandshakeConfirmed) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -2900,8 +2866,7 @@ TEST_P(QuicNetworkTransactionTest, ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -2981,13 +2946,6 @@ TEST_P(QuicNetworkTransactionTest, host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -3002,7 +2960,7 @@ TEST_P(QuicNetworkTransactionTest, auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans->Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3029,8 +2987,7 @@ TEST_P(QuicNetworkTransactionTest, ProtocolErrorAfterHandshakeConfirmed) { // The request will initially go out over QUIC. MockQuicData quic_data; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite( SYNCHRONOUS, ConstructClientRequestHeadersPacket( @@ -3060,13 +3017,6 @@ TEST_P(QuicNetworkTransactionTest, ProtocolErrorAfterHandshakeConfirmed) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); @@ -3074,7 +3024,7 @@ TEST_P(QuicNetworkTransactionTest, ProtocolErrorAfterHandshakeConfirmed) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3109,8 +3059,7 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken) { ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -3191,13 +3140,6 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -3211,7 +3153,7 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3251,8 +3193,7 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken2) { ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -3333,13 +3274,6 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken2) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -3353,7 +3287,7 @@ TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken2) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3397,8 +3331,7 @@ TEST_P(QuicNetworkTransactionTest, ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -3487,13 +3420,6 @@ TEST_P(QuicNetworkTransactionTest, host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -3507,7 +3433,7 @@ TEST_P(QuicNetworkTransactionTest, HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3550,8 +3476,7 @@ TEST_P(QuicNetworkTransactionTest, ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -3640,13 +3565,6 @@ TEST_P(QuicNetworkTransactionTest, host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -3660,7 +3578,7 @@ TEST_P(QuicNetworkTransactionTest, HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3701,8 +3619,7 @@ TEST_P(QuicNetworkTransactionTest, ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -3782,13 +3699,6 @@ TEST_P(QuicNetworkTransactionTest, host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // Use a TestTaskRunner to avoid waiting in real time for timeouts. @@ -3803,7 +3713,7 @@ TEST_P(QuicNetworkTransactionTest, auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans->Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3833,8 +3743,7 @@ TEST_P(QuicNetworkTransactionTest, // The request will initially go out over QUIC. MockQuicData quic_data; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite( SYNCHRONOUS, ConstructClientRequestHeadersPacket( @@ -3878,13 +3787,6 @@ TEST_P(QuicNetworkTransactionTest, host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); @@ -3892,7 +3794,7 @@ TEST_P(QuicNetworkTransactionTest, HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -3932,8 +3834,7 @@ TEST_P(QuicNetworkTransactionTest, ResetAfterHandshakeConfirmedThenBroken) { ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); std::string request_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeRequestHeadersPacketAndSaveData( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -3977,13 +3878,6 @@ TEST_P(QuicNetworkTransactionTest, ResetAfterHandshakeConfirmedThenBroken) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); @@ -3991,7 +3885,7 @@ TEST_P(QuicNetworkTransactionTest, ResetAfterHandshakeConfirmedThenBroken) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); // Pump the message loop to get the request started. @@ -4954,8 +4848,7 @@ TEST_P(QuicNetworkTransactionTest, HungAlternativeService) { TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { MockQuicData mock_quic_data; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); mock_quic_data.AddWrite( SYNCHRONOUS, ConstructClientRequestHeadersPacket( @@ -4991,8 +4884,7 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { MockQuicData mock_quic_data; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); mock_quic_data.AddWrite( SYNCHRONOUS, ConstructClientRequestHeadersPacket( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -5017,13 +4909,6 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); AddHangingNonAlternateProtocolSocketData(); CreateSession(); @@ -5055,13 +4940,6 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); request_.url = GURL("http://mail.example.org/"); CreateSession(); @@ -5104,13 +4982,6 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -5118,7 +4989,7 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( @@ -5133,8 +5004,7 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithTooEarlyResponse) { MockQuicData mock_quic_data; quic::QuicStreamOffset client_header_stream_offset = 0; quic::QuicStreamOffset server_header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); mock_quic_data.AddWrite( SYNCHRONOUS, ConstructClientRequestHeadersPacket( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -5193,11 +5063,6 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithTooEarlyResponse) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, net_log_.bound()); AddHangingNonAlternateProtocolSocketData(); CreateSession(); @@ -5232,8 +5097,7 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithMultipleTooEarlyResponse) { MockQuicData mock_quic_data; quic::QuicStreamOffset client_header_stream_offset = 0; quic::QuicStreamOffset server_header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); mock_quic_data.AddWrite( SYNCHRONOUS, ConstructClientRequestHeadersPacket( 1, GetNthClientInitiatedBidirectionalStreamId(0), true, @@ -5290,11 +5154,6 @@ TEST_P(QuicNetworkTransactionTest, ZeroRTTWithMultipleTooEarlyResponse) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, net_log_.bound()); AddHangingNonAlternateProtocolSocketData(); CreateSession(); @@ -5360,13 +5219,6 @@ TEST_P(QuicNetworkTransactionTest, host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -5374,7 +5226,7 @@ TEST_P(QuicNetworkTransactionTest, HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( @@ -5427,13 +5279,6 @@ TEST_P(QuicNetworkTransactionTest, host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -5441,7 +5286,7 @@ TEST_P(QuicNetworkTransactionTest, HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( @@ -5489,13 +5334,6 @@ TEST_P(QuicNetworkTransactionTest, RstSteamErrorHandling) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -5503,7 +5341,7 @@ TEST_P(QuicNetworkTransactionTest, RstSteamErrorHandling) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( @@ -5554,13 +5392,6 @@ TEST_P(QuicNetworkTransactionTest, RstSteamBeforeHeaders) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); session_->quic_stream_factory()->set_require_confirmation(true); @@ -5568,7 +5399,7 @@ TEST_P(QuicNetworkTransactionTest, RstSteamBeforeHeaders) { HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); TestCompletionCallback callback; - rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( @@ -5672,8 +5503,7 @@ TEST_P(QuicNetworkTransactionTest, DelayTCPOnStartWithQuicSupportOnSameIP) { MockQuicData mock_quic_data; quic::QuicStreamOffset header_stream_offset = 0; - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); - client_maker_.SetLongHeaderType(quic::ZERO_RTT_PROTECTED); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); mock_quic_data.AddWrite( SYNCHRONOUS, ConstructClientRequestHeadersPacket( @@ -5907,6 +5737,10 @@ TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolOnConnectFailure) { } TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { + if (version_ >= quic::QUIC_VERSION_47) { + // TODO(nharper): reenable once MakeDummyCHLOPacket() fixed + return; + } MockQuicData mock_quic_data; mock_quic_data.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); mock_quic_data.AddRead(ASYNC, ConstructServerConnectionClosePacket(1)); @@ -5929,13 +5763,6 @@ TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); // TODO(rch): Check if we need a 0RTT version of ConnectionCloseDuringConnect @@ -6010,13 +5837,6 @@ TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnectProxy) { // synchronously. host_resolver_.set_synchronous_mode(true); host_resolver_.rules()->AddIPLiteralRule("myproxy.org", "192.168.0.1", ""); - HostResolver::RequestInfo info(HostPortPair("myproxy.org", 443)); - AddressList address; - std::unique_ptr<HostResolver::Request> request; - int rv = host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, - CompletionOnceCallback(), &request, - net_log_.bound()); - EXPECT_THAT(rv, IsOk()); CreateSession(); crypto_client_stream_factory_.set_handshake_mode( @@ -6378,7 +6198,7 @@ TEST_P(QuicNetworkTransactionTest, QuicServerPush) { MockQuicData mock_quic_data; quic::QuicStreamOffset header_stream_offset = 0; - quic::QuicPacketNumber client_packet_number = 1; + uint64_t client_packet_number = 1; mock_quic_data.AddWrite( SYNCHRONOUS, ConstructInitialSettingsPacket(client_packet_number++, &header_stream_offset)); @@ -6469,7 +6289,7 @@ TEST_P(QuicNetworkTransactionTest, CancelServerPushAfterConnectionClose) { MockQuicData mock_quic_data; quic::QuicStreamOffset header_stream_offset = 0; - quic::QuicPacketNumber client_packet_number = 1; + uint64_t client_packet_number = 1; // Initial SETTINGS frame. mock_quic_data.AddWrite( SYNCHRONOUS, ConstructInitialSettingsPacket(client_packet_number++, @@ -6631,7 +6451,7 @@ class QuicURLRequestContext : public URLRequestContext { storage_.set_ssl_config_service( std::make_unique<SSLConfigServiceDefaults>()); storage_.set_http_auth_handler_factory( - HttpAuthHandlerFactory::CreateDefault(host_resolver())); + HttpAuthHandlerFactory::CreateDefault()); storage_.set_http_server_properties( std::make_unique<HttpServerPropertiesImpl>()); storage_.set_job_factory(std::make_unique<URLRequestJobFactoryImpl>()); @@ -6724,7 +6544,7 @@ TEST_P(QuicNetworkTransactionTest, RawHeaderSizeSuccessfullPushHeadersFirst) { MockQuicData mock_quic_data; quic::QuicStreamOffset header_stream_offset = 0; - quic::QuicPacketNumber client_packet_number = 1; + uint64_t client_packet_number = 1; mock_quic_data.AddWrite( SYNCHRONOUS, ConstructInitialSettingsPacket(client_packet_number++, &header_stream_offset)); @@ -6907,8 +6727,7 @@ class QuicNetworkTransactionWithDestinationTest cert_transparency_verifier_(new MultiLogCTVerifier()), ssl_config_service_(new SSLConfigServiceDefaults), proxy_resolution_service_(ProxyResolutionService::CreateDirect()), - auth_handler_factory_( - HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), + auth_handler_factory_(HttpAuthHandlerFactory::CreateDefault()), random_generator_(0), ssl_data_(ASYNC, OK) {} @@ -6982,7 +6801,7 @@ class QuicNetworkTransactionWithDestinationTest expiration, supported_versions_); } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientRequestHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructClientRequestHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, quic::QuicStreamOffset* offset, @@ -6992,7 +6811,7 @@ class QuicNetworkTransactionWithDestinationTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientRequestHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructClientRequestHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, quic::QuicStreamId parent_stream_id, @@ -7008,7 +6827,7 @@ class QuicNetworkTransactionWithDestinationTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientRequestHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructClientRequestHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, QuicTestPacketMaker* maker) { @@ -7017,7 +6836,7 @@ class QuicNetworkTransactionWithDestinationTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructServerResponseHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructServerResponseHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, quic::QuicStreamOffset* offset, QuicTestPacketMaker* maker) { @@ -7027,7 +6846,7 @@ class QuicNetworkTransactionWithDestinationTest } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructServerResponseHeadersPacket(quic::QuicPacketNumber packet_number, + ConstructServerResponseHeadersPacket(uint64_t packet_number, quic::QuicStreamId stream_id, QuicTestPacketMaker* maker) { return ConstructServerResponseHeadersPacket(packet_number, stream_id, @@ -7035,7 +6854,7 @@ class QuicNetworkTransactionWithDestinationTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructServerDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, QuicTestPacketMaker* maker) { quic::QuicString header = ""; @@ -7050,17 +6869,17 @@ class QuicNetworkTransactionWithDestinationTest } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, QuicTestPacketMaker* maker) { return maker->MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, true); } std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset* offset, QuicTestPacketMaker* maker) { return maker->MakeInitialSettingsPacket(packet_number, offset); @@ -7121,7 +6940,7 @@ class QuicNetworkTransactionWithDestinationTest EXPECT_TRUE(response->was_alpn_negotiated); EXPECT_EQ(QuicHttpStream::ConnectionInfoFromQuicVersion(version_), response->connection_info); - EXPECT_EQ(443, response->socket_address.port()); + EXPECT_EQ(443, response->remote_endpoint.port()); } quic::QuicStreamId GetNthClientInitiatedBidirectionalStreamId(int n) { @@ -7155,9 +6974,9 @@ class QuicNetworkTransactionWithDestinationTest SSLSocketDataProvider ssl_data_; }; -INSTANTIATE_TEST_CASE_P(VersionIncludeStreamDependencySequence, - QuicNetworkTransactionWithDestinationTest, - ::testing::ValuesIn(GetPoolingTestParams())); +INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, + QuicNetworkTransactionWithDestinationTest, + ::testing::ValuesIn(GetPoolingTestParams())); // A single QUIC request fails because the certificate does not match the origin // hostname, regardless of whether it matches the alternative service hostname. @@ -7405,7 +7224,7 @@ TEST_P(QuicNetworkTransactionTest, QuicServerPushMatchesRequestWithBody) { MockQuicData mock_quic_data; quic::QuicStreamOffset header_stream_offset = 0; - quic::QuicPacketNumber client_packet_number = 1; + uint64_t client_packet_number = 1; mock_quic_data.AddWrite( SYNCHRONOUS, ConstructInitialSettingsPacket(client_packet_number++, &header_stream_offset)); @@ -8404,6 +8223,72 @@ TEST_P(QuicNetworkTransactionTest, QuicProxyRequestPriority) { EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed()); } +// Makes sure the CONNECT request packet for a QUIC proxy contains the correct +// HTTP/2 stream dependency and weights given the request priority. +TEST_P(QuicNetworkTransactionTest, QuicProxyMultipleRequestsError) { + session_params_.enable_quic = true; + session_params_.enable_quic_proxies_for_https_urls = true; + proxy_resolution_service_ = ProxyResolutionService::CreateFixedFromPacResult( + "QUIC proxy.example.org:70", TRAFFIC_ANNOTATION_FOR_TESTS); + + const RequestPriority kRequestPriority = MEDIUM; + const RequestPriority kRequestPriority2 = LOWEST; + + MockQuicData mock_quic_data; + quic::QuicStreamOffset header_stream_offset = 0; + mock_quic_data.AddWrite( + ASYNC, ConstructInitialSettingsPacket(1, &header_stream_offset)); + mock_quic_data.AddWrite(SYNCHRONOUS, ERR_FAILED); + // This should never be reached. + mock_quic_data.AddRead(ASYNC, ERR_CONNECTION_FAILED); + mock_quic_data.AddSocketDataToFactory(&socket_factory_); + + // Second connection attempt just fails - result doesn't really matter. + MockQuicData mock_quic_data2; + mock_quic_data2.AddConnect(SYNCHRONOUS, ERR_FAILED); + mock_quic_data2.AddSocketDataToFactory(&socket_factory_); + + int original_max_sockets_per_group = + ClientSocketPoolManager::max_sockets_per_group( + HttpNetworkSession::SocketPoolType::NORMAL_SOCKET_POOL); + ClientSocketPoolManager::set_max_sockets_per_group( + HttpNetworkSession::SocketPoolType::NORMAL_SOCKET_POOL, 1); + int original_max_sockets_per_pool = + ClientSocketPoolManager::max_sockets_per_pool( + HttpNetworkSession::SocketPoolType::NORMAL_SOCKET_POOL); + ClientSocketPoolManager::set_max_sockets_per_pool( + HttpNetworkSession::SocketPoolType::NORMAL_SOCKET_POOL, 1); + CreateSession(); + + request_.url = GURL("https://mail.example.org/"); + HttpNetworkTransaction trans(kRequestPriority, session_.get()); + TestCompletionCallback callback; + int rv = trans.Start(&request_, callback.callback(), net_log_.bound()); + EXPECT_EQ(ERR_IO_PENDING, rv); + + HttpRequestInfo request2; + request2.url = GURL("https://mail.example.org/some/other/path/"); + request2.traffic_annotation = + net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); + + HttpNetworkTransaction trans2(kRequestPriority2, session_.get()); + TestCompletionCallback callback2; + int rv2 = trans2.Start(&request2, callback2.callback(), net_log_.bound()); + EXPECT_EQ(ERR_IO_PENDING, rv2); + + EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); + EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed()); + + EXPECT_EQ(ERR_FAILED, callback2.WaitForResult()); + + ClientSocketPoolManager::set_max_sockets_per_pool( + HttpNetworkSession::SocketPoolType::NORMAL_SOCKET_POOL, + original_max_sockets_per_pool); + ClientSocketPoolManager::set_max_sockets_per_group( + HttpNetworkSession::SocketPoolType::NORMAL_SOCKET_POOL, + original_max_sockets_per_group); +} + // Test the request-challenge-retry sequence for basic auth, over a QUIC // connection when setting up a QUIC proxy tunnel. TEST_P(QuicNetworkTransactionTest, QuicProxyAuth) { @@ -8480,7 +8365,8 @@ TEST_P(QuicNetworkTransactionTest, QuicProxyAuth) { SYNCHRONOUS, client_maker->MakeRstPacket( 4, false, GetNthClientInitiatedBidirectionalStreamId(0), - quic::QUIC_STREAM_CANCELLED, client_data_offset)); + quic::QUIC_STREAM_CANCELLED, client_data_offset, + /*include_stop_sending_if_v99=*/true)); headers = client_maker->ConnectRequestHeaders("mail.example.org:443"); headers["proxy-authorization"] = "Basic Zm9vOmJheg=="; diff --git a/chromium/net/quic/quic_proxy_client_socket.cc b/chromium/net/quic/quic_proxy_client_socket.cc index 2d04bdf4411..4354816ad39 100644 --- a/chromium/net/quic/quic_proxy_client_socket.cc +++ b/chromium/net/quic/quic_proxy_client_socket.cc @@ -13,7 +13,6 @@ #include "base/values.h" #include "net/http/http_auth_controller.h" #include "net/http/http_response_headers.h" -#include "net/http/proxy_connect_redirect_http_stream.h" #include "net/log/net_log_source.h" #include "net/log/net_log_source_type.h" #include "net/quic/quic_http_utils.h" @@ -37,7 +36,6 @@ QuicProxyClientSocket::QuicProxyClientSocket( endpoint_(endpoint), auth_(auth_controller), user_agent_(user_agent), - redirect_has_load_timing_info_(false), net_log_(net_log), weak_factory_(this) { DCHECK(stream_->IsOpen()); @@ -60,12 +58,6 @@ const HttpResponseInfo* QuicProxyClientSocket::GetConnectResponseInfo() const { return response_.headers.get() ? &response_ : nullptr; } -std::unique_ptr<HttpStream> -QuicProxyClientSocket::CreateConnectResponseStream() { - return std::make_unique<ProxyConnectRedirectHttpStream>( - redirect_has_load_timing_info_ ? &redirect_load_timing_info_ : nullptr); -} - const scoped_refptr<HttpAuthController>& QuicProxyClientSocket::GetAuthController() const { return auth_; @@ -76,7 +68,7 @@ int QuicProxyClientSocket::RestartWithAuth(CompletionOnceCallback callback) { // stream may not be reused and a new QuicProxyClientSocket must be // created (possibly on top of the same QUIC Session). next_state_ = STATE_DISCONNECTED; - return OK; + return ERR_UNABLE_TO_REUSE_CONNECTION_FOR_PROXY_AUTH; } bool QuicProxyClientSocket::IsUsingSpdy() const { @@ -87,9 +79,13 @@ NextProto QuicProxyClientSocket::GetProxyNegotiatedProtocol() const { return kProtoQUIC; } -void QuicProxyClientSocket::SetStreamPriority(RequestPriority priority) { - stream_->SetPriority(ConvertRequestPriorityToQuicPriority(priority)); -} +// Ignore priority changes, just use priority of initial request. Since multiple +// requests are pooled on the QuicProxyClientSocket, reprioritization doesn't +// really work. +// +// TODO(mmenke): Use a single priority value for all QuicProxyClientSockets, +// regardless of what priority they're created with. +void QuicProxyClientSocket::SetStreamPriority(RequestPriority priority) {} // Sends a HEADERS frame to the proxy with a CONNECT request // for the specified endpoint. Waits for the server to send back @@ -412,8 +408,6 @@ int QuicProxyClientSocket::DoReadReplyComplete(int result) { // If we can't, fail the tunnel connection. if (!SanitizeProxyRedirect(&response_)) return ERR_TUNNEL_CONNECTION_FAILED; - redirect_has_load_timing_info_ = - GetLoadTimingInfo(&redirect_load_timing_info_); next_state_ = STATE_DISCONNECTED; return ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT; diff --git a/chromium/net/quic/quic_proxy_client_socket.h b/chromium/net/quic/quic_proxy_client_socket.h index b9688eced33..d72aed881e7 100644 --- a/chromium/net/quic/quic_proxy_client_socket.h +++ b/chromium/net/quic/quic_proxy_client_socket.h @@ -42,7 +42,6 @@ class NET_EXPORT_PRIVATE QuicProxyClientSocket : public ProxyClientSocket { // ProxyClientSocket methods: const HttpResponseInfo* GetConnectResponseInfo() const override; - std::unique_ptr<HttpStream> CreateConnectResponseStream() override; const scoped_refptr<HttpAuthController>& GetAuthController() const override; int RestartWithAuth(CompletionOnceCallback callback) override; bool IsUsingSpdy() const override; @@ -140,10 +139,6 @@ class NET_EXPORT_PRIVATE QuicProxyClientSocket : public ProxyClientSocket { std::string user_agent_; - // Used only for redirects. - bool redirect_has_load_timing_info_; - LoadTimingInfo redirect_load_timing_info_; - // Session connect timing info. LoadTimingInfo::ConnectTiming connect_timing_; diff --git a/chromium/net/quic/quic_proxy_client_socket_unittest.cc b/chromium/net/quic/quic_proxy_client_socket_unittest.cc index a385cc1df87..32105e50a43 100644 --- a/chromium/net/quic/quic_proxy_client_socket_unittest.cc +++ b/chromium/net/quic/quic_proxy_client_socket_unittest.cc @@ -5,11 +5,16 @@ #include "net/quic/quic_proxy_client_socket.h" #include <memory> +#include <tuple> #include <utility> +#include <vector> +#include "base/bind.h" #include "base/memory/ptr_util.h" #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" +#include "base/threading/thread_task_runner_handle.h" +#include "base/time/default_tick_clock.h" #include "net/dns/mock_host_resolver.h" #include "net/http/http_auth_cache.h" #include "net/http/http_auth_handler_factory.h" @@ -31,6 +36,7 @@ #include "net/quic/test_task_runner.h" #include "net/socket/socket_test_util.h" #include "net/test/cert_test_util.h" +#include "net/test/gtest_util.h" #include "net/test/test_data_directory.h" #include "net/test/test_with_scoped_task_environment.h" #include "net/third_party/quic/core/crypto/null_encrypter.h" @@ -94,6 +100,12 @@ class QuicProxyClientSocketTest quic::QuicConnectionIdLength connection_id_length, quic::QuicPacketNumberLength packet_number_length, quic::QuicStreamOffset offset) { + quic::QuicVariableLengthIntegerLength retry_token_length_length = + quic::VARIABLE_LENGTH_INTEGER_LENGTH_0; + quic::QuicVariableLengthIntegerLength length_length = + quic::QuicVersionHasLongHeaderLengths(version) && include_version + ? quic::VARIABLE_LENGTH_INTEGER_LENGTH_2 + : quic::VARIABLE_LENGTH_INTEGER_LENGTH_0; size_t min_data_length = 1; size_t min_packet_length = quic::NullEncrypter(quic::Perspective::IS_CLIENT) @@ -101,7 +113,8 @@ class QuicProxyClientSocketTest quic::QuicPacketCreator::StreamFramePacketOverhead( version, quic::PACKET_8BYTE_CONNECTION_ID, quic::PACKET_0BYTE_CONNECTION_ID, include_version, - include_diversification_nonce, packet_number_length, offset); + include_diversification_nonce, packet_number_length, + retry_token_length_length, length_length, offset); DCHECK(packet_length >= min_packet_length); return min_data_length + packet_length - min_packet_length; @@ -134,8 +147,7 @@ class QuicProxyClientSocketTest proxy_host_port_(kProxyHost, kProxyPort), endpoint_host_port_(kOriginHost, kOriginPort), host_resolver_(new MockCachingHostResolver()), - http_auth_handler_factory_( - HttpAuthHandlerFactory::CreateDefault(host_resolver_.get())) { + http_auth_handler_factory_(HttpAuthHandlerFactory::CreateDefault()) { IPAddress ip(192, 0, 2, 33); peer_addr_ = IPEndPoint(ip, 443); clock_.AdvanceTime(quic::QuicTime::Delta::FromMilliseconds(20)); @@ -209,17 +221,22 @@ class QuicProxyClientSocketTest SocketTag()), /*require_confirmation=*/false, /*migrate_session_early_v2=*/false, /*migrate_session_on_network_change_v2=*/false, - /*go_away_on_path_degrading*/ false, /*default_network=*/NetworkChangeNotifier::kInvalidNetworkHandle, + quic::QuicTime::Delta::FromMilliseconds( + kDefaultRetransmittableOnWireTimeoutMillisecs), + /*migrate_idle_session=*/true, + base::TimeDelta::FromSeconds(kDefaultIdleSessionMigrationPeriodSeconds), base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), kMaxMigrationsToNonDefaultNetworkOnWriteError, kMaxMigrationsToNonDefaultNetworkOnPathDegrading, kQuicYieldAfterPacketsRead, quic::QuicTime::Delta::FromMilliseconds( kQuicYieldAfterDurationMilliseconds), + /*go_away_on_path_degrading*/ false, client_headers_include_h2_stream_dependency_, /*cert_verify_flags=*/0, quic::test::DefaultQuicConfig(), &crypto_config_, "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, + base::DefaultTickClock::GetInstance(), base::ThreadTaskRunnerHandle::Get().get(), /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); @@ -243,10 +260,10 @@ class QuicProxyClientSocketTest sock_.reset(new QuicProxyClientSocket( std::move(stream_handle), std::move(session_handle_), user_agent_, endpoint_host_port_, net_log_.bound(), - new HttpAuthController(HttpAuth::AUTH_PROXY, - GURL("https://" + proxy_host_port_.ToString()), - &http_auth_cache_, - http_auth_handler_factory_.get()))); + new HttpAuthController( + HttpAuth::AUTH_PROXY, + GURL("https://" + proxy_host_port_.ToString()), &http_auth_cache_, + http_auth_handler_factory_.get(), host_resolver_.get()))); session_->StartReading(); } @@ -260,46 +277,62 @@ class QuicProxyClientSocketTest // Helper functions for constructing packets sent by the client std::unique_ptr<quic::QuicReceivedPacket> ConstructSettingsPacket( - quic::QuicPacketNumber packet_number) { + uint64_t packet_number) { return client_maker_.MakeInitialSettingsPacket(packet_number, &header_stream_offset_); } std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicRstStreamErrorCode error_code, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckAndRstPacket( packet_number, !kIncludeVersion, client_data_stream_id1_, error_code, largest_received, smallest_received, least_unacked, kSendFeedback); } + std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndRstOnlyPacket( + uint64_t packet_number, + quic::QuicRstStreamErrorCode error_code, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, + size_t bytes_written) { + return client_maker_.MakeAckAndRstPacket( + packet_number, !kIncludeVersion, client_data_stream_id1_, error_code, + largest_received, smallest_received, least_unacked, kSendFeedback, + bytes_written, + /*include_stop_sending=*/false); + } + std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicRstStreamErrorCode error_code, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, size_t bytes_written) { return client_maker_.MakeAckAndRstPacket( packet_number, !kIncludeVersion, client_data_stream_id1_, error_code, largest_received, smallest_received, least_unacked, kSendFeedback, - bytes_written); + bytes_written, + /*include_stop_sending_if_v99=*/true); } std::unique_ptr<quic::QuicReceivedPacket> ConstructRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicRstStreamErrorCode error_code, size_t bytes_written) { return client_maker_.MakeRstPacket(packet_number, !kIncludeVersion, client_data_stream_id1_, error_code, - bytes_written); + bytes_written, + /*include_stop_sending_if_v99=*/true); } std::unique_ptr<quic::QuicReceivedPacket> ConstructConnectRequestPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, RequestPriority request_priority = LOWEST) { spdy::SpdyHeaderBlock block; PopulateConnectRequestIR(&block); @@ -310,7 +343,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructConnectAuthRequestPacket( - quic::QuicPacketNumber packet_number) { + uint64_t packet_number) { spdy::SpdyHeaderBlock block; PopulateConnectRequestIR(&block); block["proxy-authorization"] = "Basic Zm9vOmJhcg=="; @@ -321,7 +354,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset offset, quic::QuicStringPiece data) { return client_maker_.MakeDataPacket(packet_number, client_data_stream_id1_, @@ -329,7 +362,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset offset, const std::vector<std::string> data_writes) { return client_maker_.MakeMultipleDataFramesPacket( @@ -338,10 +371,10 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndDataPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicStreamOffset offset, quic::QuicStringPiece data) { return client_maker_.MakeAckAndDataPacket( @@ -352,10 +385,10 @@ class QuicProxyClientSocketTest std::unique_ptr<quic::QuicReceivedPacket> ConstructAckAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicStreamOffset offset, const std::vector<std::string> data_writes) { return client_maker_.MakeAckAndMultipleDataFramesPacket( @@ -365,10 +398,10 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { return client_maker_.MakeAckPacket(packet_number, largest_received, smallest_received, least_unacked, kSendFeedback); @@ -377,16 +410,17 @@ class QuicProxyClientSocketTest // Helper functions for constructing packets sent by the server std::unique_ptr<quic::QuicReceivedPacket> ConstructServerRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicRstStreamErrorCode error_code, size_t bytes_written) { return server_maker_.MakeRstPacket(packet_number, !kIncludeVersion, client_data_stream_id1_, error_code, - bytes_written); + bytes_written, + /*include_stop_sending_if_v99=*/true); } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset offset, quic::QuicStringPiece data) { return server_maker_.MakeDataPacket(packet_number, client_data_stream_id1_, @@ -394,7 +428,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerDataFinPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset offset, quic::QuicStringPiece data) { return server_maker_.MakeDataPacket(packet_number, client_data_stream_id1_, @@ -402,7 +436,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> ConstructServerConnectReplyPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool fin) { spdy::SpdyHeaderBlock block; block[":status"] = "200"; @@ -413,8 +447,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> - ConstructServerConnectAuthReplyPacket(quic::QuicPacketNumber packet_number, - bool fin) { + ConstructServerConnectAuthReplyPacket(uint64_t packet_number, bool fin) { spdy::SpdyHeaderBlock block; block[":status"] = "407"; block["proxy-authenticate"] = "Basic realm=\"MyRealm1\""; @@ -424,9 +457,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> - ConstructServerConnectRedirectReplyPacket( - quic::QuicPacketNumber packet_number, - bool fin) { + ConstructServerConnectRedirectReplyPacket(uint64_t packet_number, bool fin) { spdy::SpdyHeaderBlock block; block[":status"] = "302"; block["location"] = kRedirectUrl; @@ -437,8 +468,7 @@ class QuicProxyClientSocketTest } std::unique_ptr<quic::QuicReceivedPacket> - ConstructServerConnectErrorReplyPacket(quic::QuicPacketNumber packet_number, - bool fin) { + ConstructServerConnectErrorReplyPacket(uint64_t packet_number, bool fin) { spdy::SpdyHeaderBlock block; block[":status"] = "500"; @@ -805,8 +835,10 @@ TEST_P(QuicProxyClientSocketTest, GetTotalReceivedBytes) { TEST_P(QuicProxyClientSocketTest, SetStreamPriority) { mock_quic_data_.AddWrite(SYNCHRONOUS, ConstructSettingsPacket(1)); + // Despite setting the priority to HIGHEST, the requets initial priority of + // LOWEST is used. mock_quic_data_.AddWrite(SYNCHRONOUS, - ConstructConnectRequestPacket(2, HIGHEST)); + ConstructConnectRequestPacket(2, LOWEST)); mock_quic_data_.AddRead(ASYNC, ConstructServerConnectReplyPacket(1, !kFin)); mock_quic_data_.AddRead(SYNCHRONOUS, ERR_IO_PENDING); mock_quic_data_.AddWrite( @@ -1622,10 +1654,9 @@ TEST_P(QuicProxyClientSocketTest, RstWithReadAndWritePending) { mock_quic_data_.AddWrite( ASYNC, ConstructAckAndMultipleDataFramesPacket( 3, 1, 1, 1, 0, {header, quic::QuicString(kMsg2, kLen2)})); - mock_quic_data_.AddWrite( - SYNCHRONOUS, - ConstructAckAndRstPacket(4, quic::QUIC_RST_ACKNOWLEDGEMENT, 2, 2, 1, - header.length() + kLen2)); + mock_quic_data_.AddWrite(SYNCHRONOUS, ConstructAckAndRstOnlyPacket( + 4, quic::QUIC_STREAM_CANCELLED, 2, + 2, 1, header.length() + kLen2)); } Initialize(); @@ -1757,10 +1788,9 @@ TEST_P(QuicProxyClientSocketTest, RstWithReadAndWritePendingDelete) { mock_quic_data_.AddWrite( ASYNC, ConstructAckAndMultipleDataFramesPacket( 3, 1, 1, 1, 0, {header, quic::QuicString(kMsg1, kLen1)})); - mock_quic_data_.AddWrite( - SYNCHRONOUS, - ConstructAckAndRstPacket(4, quic::QUIC_RST_ACKNOWLEDGEMENT, 2, 2, 1, - header.length() + kLen1)); + mock_quic_data_.AddWrite(SYNCHRONOUS, ConstructAckAndRstOnlyPacket( + 4, quic::QUIC_STREAM_CANCELLED, 2, + 2, 1, header.length() + kLen1)); } Initialize(); @@ -1790,7 +1820,7 @@ TEST_P(QuicProxyClientSocketTest, RstWithReadAndWritePendingDelete) { EXPECT_FALSE(write_callback_.have_result()); } -INSTANTIATE_TEST_CASE_P( +INSTANTIATE_TEST_SUITE_P( VersionIncludeStreamDependencySequence, QuicProxyClientSocketTest, ::testing::Combine( diff --git a/chromium/net/quic/quic_stream_factory.cc b/chromium/net/quic/quic_stream_factory.cc index 21a089d23f0..ba11def3e11 100644 --- a/chromium/net/quic/quic_stream_factory.cc +++ b/chromium/net/quic/quic_stream_factory.cc @@ -9,6 +9,7 @@ #include <tuple> #include <utility> +#include "base/bind.h" #include "base/callback_helpers.h" #include "base/location.h" #include "base/metrics/field_trial.h" @@ -19,6 +20,7 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/time/default_tick_clock.h" #include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/process_memory_dump.h" @@ -150,14 +152,6 @@ void LogPlatformNotificationInHistogram( notification, NETWORK_NOTIFICATION_MAX); } -void LogStaleHostRacing(bool used) { - UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.StaleHostRacing", used); -} - -void LogStaleAndFreshHostMatched(bool matched) { - UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.StaleAndFreshHostMatched", matched); -} - void LogConnectionIpPooling(bool pooled) { UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ConnectionIpPooled", pooled); } @@ -203,7 +197,8 @@ bssl::UniquePtr<SSL_CTX> QuicStreamFactoryCreateSslCtx() { class ServerIdOriginFilter : public quic::QuicCryptoClientConfig::ServerIdFilter { public: - ServerIdOriginFilter(const base::Callback<bool(const GURL&)> origin_filter) + explicit ServerIdOriginFilter( + const base::RepeatingCallback<bool(const GURL&)> origin_filter) : origin_filter_(origin_filter) {} bool Matches(const quic::QuicServerId& server_id) const override { @@ -342,7 +337,6 @@ class QuicStreamFactory::Job { int DoConnect(); int DoConnectComplete(int rv); int DoConfirmConnection(int rv); - int DoWaitForHostResolution(); int DoValidateHost(); void OnResolveHostComplete(int rv); @@ -377,10 +371,12 @@ class QuicStreamFactory::Job { return; priority_ = priority; - if (io_state_ == STATE_RESOLVE_HOST_COMPLETE && - !host_resolution_finished_) { - DCHECK(request_); - request_->ChangeRequestPriority(priority); + if (resolve_host_request_ && !host_resolution_finished_) { + if (fresh_resolve_host_request_) { + fresh_resolve_host_request_->ChangeRequestPriority(priority); + } else { + resolve_host_request_->ChangeRequestPriority(priority); + } } } @@ -390,8 +386,6 @@ class QuicStreamFactory::Job { RequestPriority priority() const { return priority_; } - bool IsHostResolutionComplete() const { return host_resolution_finished_; } - private: enum IoState { STATE_NONE, @@ -399,7 +393,6 @@ class QuicStreamFactory::Job { STATE_RESOLVE_HOST_COMPLETE, STATE_CONNECT, STATE_CONNECT_COMPLETE, - STATE_WAIT_FOR_HOST_RESOLUTION, STATE_HOST_VALIDATION, STATE_CONFIRM_CONNECTION, }; @@ -410,13 +403,14 @@ class QuicStreamFactory::Job { QuicChromiumClientSession* session = session_; session_ = nullptr; session->CloseSessionOnErrorLater( - ERR_ABORTED, quic::QUIC_CONNECTION_CANCELLED, + ERR_ABORTED, quic::QUIC_STALE_CONNECTION_CANCELLED, quic::ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); } } bool DoesPeerAddressMatchWithFreshAddressList() { - std::vector<net::IPEndPoint> endpoints = address_list_.endpoints(); + std::vector<net::IPEndPoint> endpoints = + fresh_resolve_host_request_->GetAddressResults().value().endpoints(); IPEndPoint stale_address = session_->peer_address().impl().socket_address(); if (std::find(endpoints.begin(), endpoints.end(), stale_address) != @@ -426,11 +420,36 @@ class QuicStreamFactory::Job { return false; } + void LogStaleHostRacing(bool used) { + if (used) { + net_log_.AddEvent( + NetLogEventType:: + QUIC_STREAM_FACTORY_JOB_STALE_HOST_TRIED_ON_CONNECTION); + } else { + net_log_.AddEvent( + NetLogEventType:: + QUIC_STREAM_FACTORY_JOB_STALE_HOST_NOT_USED_ON_CONNECTION); + } + UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.StaleHostRacing", used); + } + + void LogStaleAndFreshHostMatched(bool matched) { + if (matched) { + net_log_.AddEvent( + NetLogEventType:: + QUIC_STREAM_FACTORY_JOB_STALE_HOST_RESOLUTION_MATCHED); + } else { + net_log_.AddEvent( + NetLogEventType:: + QUIC_STREAM_FACTORY_JOB_STALE_HOST_RESOLUTION_NO_MATCH); + } + UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.StaleAndFreshHostMatched", matched); + } + IoState io_state_; QuicStreamFactory* factory_; quic::QuicTransportVersion quic_version_; HostResolver* host_resolver_; - std::unique_ptr<HostResolver::Request> request_; const QuicSessionAliasKey key_; RequestPriority priority_; const int cert_verify_flags_; @@ -439,7 +458,6 @@ class QuicStreamFactory::Job { const bool race_stale_dns_on_connection_; const NetLogWithSource net_log_; int num_sent_client_hellos_; - bool dns_race_ongoing_; bool host_resolution_finished_; bool connection_retried_; QuicChromiumClientSession* session_; @@ -448,8 +466,10 @@ class QuicStreamFactory::Job { NetworkChangeNotifier::NetworkHandle network_; CompletionOnceCallback host_resolution_callback_; CompletionOnceCallback callback_; - AddressList address_list_; - AddressList stale_address_list_; + std::unique_ptr<HostResolver::ResolveHostRequest> resolve_host_request_; + // Only set during DNS race. After completion, cleared or replaces + // |resolve_host_request_|. + std::unique_ptr<HostResolver::ResolveHostRequest> fresh_resolve_host_request_; base::TimeTicks dns_resolution_start_time_; base::TimeTicks dns_resolution_end_time_; std::set<QuicStreamRequest*> stream_requests_; @@ -484,7 +504,6 @@ QuicStreamFactory::Job::Job(QuicStreamFactory* factory, NetLogWithSource::Make(net_log.net_log(), NetLogSourceType::QUIC_STREAM_FACTORY_JOB)), num_sent_client_hellos_(0), - dns_race_ongoing_(false), host_resolution_finished_(false), connection_retried_(false), session_(nullptr), @@ -537,9 +556,6 @@ int QuicStreamFactory::Job::DoLoop(int rv) { case STATE_CONNECT_COMPLETE: rv = DoConnectComplete(rv); break; - case STATE_WAIT_FOR_HOST_RESOLUTION: - rv = DoWaitForHostResolution(); - break; case STATE_HOST_VALIDATION: rv = DoValidateHost(); break; @@ -555,16 +571,17 @@ int QuicStreamFactory::Job::DoLoop(int rv) { } void QuicStreamFactory::Job::OnResolveHostComplete(int rv) { - host_resolution_finished_ = true; - if (!race_stale_dns_on_connection_) - DCHECK_EQ(STATE_RESOLVE_HOST_COMPLETE, io_state_); + DCHECK(!host_resolution_finished_); - if (dns_race_ongoing_) { + if (fresh_resolve_host_request_) { + DCHECK(race_stale_dns_on_connection_); if (rv != OK) { CloseStaleHostConnection(); - dns_race_ongoing_ = false; + resolve_host_request_ = std::move(fresh_resolve_host_request_); io_state_ = STATE_RESOLVE_HOST_COMPLETE; - } else if (factory_->HasMatchingIpSession(key_, address_list_)) { + } else if (factory_->HasMatchingIpSession( + key_, + fresh_resolve_host_request_->GetAddressResults().value())) { // Session with resolved IP has already existed, so close racing // connection, run callback, and return. LogConnectionIpPooling(true); @@ -577,21 +594,28 @@ void QuicStreamFactory::Job::OnResolveHostComplete(int rv) { // hasn't finished yet. if (DoesPeerAddressMatchWithFreshAddressList()) { LogStaleAndFreshHostMatched(true); - dns_race_ongoing_ = false; + fresh_resolve_host_request_ = nullptr; return; } LogStaleAndFreshHostMatched(false); - net_log_.AddEvent( - NetLogEventType:: - QUIC_STREAM_FACTORY_JOB_STALE_HOST_RESOLUTION_NO_MATCH); CloseStaleHostConnection(); - dns_race_ongoing_ = false; + resolve_host_request_ = std::move(fresh_resolve_host_request_); io_state_ = STATE_RESOLVE_HOST_COMPLETE; - } + } // Else stale connection has already finished successfully. + } else { + // If not in DNS race, we should have been waiting for this callback in + // STATE_RESOLVE_HOST_COMPLETE. + DCHECK_EQ(STATE_RESOLVE_HOST_COMPLETE, io_state_); } rv = DoLoop(rv); + // Expect to be marked by either DoResolveHostComplete() or DoValidateHost(). + DCHECK(host_resolution_finished_); + + // DNS race should be completed either above or by DoValidateHost(). + DCHECK(!fresh_resolve_host_request_); + for (auto* request : stream_requests_) { request->OnHostResolutionComplete(rv); } @@ -629,30 +653,48 @@ int QuicStreamFactory::Job::DoResolveHost() { io_state_ = STATE_RESOLVE_HOST_COMPLETE; - int rv = host_resolver_->Resolve( - HostResolver::RequestInfo(key_.destination()), priority_, &address_list_, - base::Bind(&QuicStreamFactory::Job::OnResolveHostComplete, GetWeakPtr()), - &request_, net_log_); - - if (rv != ERR_IO_PENDING || !race_stale_dns_on_connection_) { + HostResolver::ResolveHostParameters parameters; + parameters.initial_priority = priority_; + if (race_stale_dns_on_connection_) { + parameters.cache_usage = + HostResolver::ResolveHostParameters::CacheUsage::STALE_ALLOWED; + } + resolve_host_request_ = + host_resolver_->CreateRequest(key_.destination(), net_log_, parameters); + // Unretained is safe because |this| owns the request, ensuring cancellation + // on destruction. + int rv = resolve_host_request_->Start(base::BindOnce( + &QuicStreamFactory::Job::OnResolveHostComplete, base::Unretained(this))); + + if (rv == ERR_IO_PENDING || !resolve_host_request_->GetStaleInfo() || + !resolve_host_request_->GetStaleInfo().value().is_stale()) { + // Not a stale result. if (race_stale_dns_on_connection_) LogStaleHostRacing(false); return rv; } - HostCache::EntryStaleness stale_info; - if (host_resolver_->ResolveStaleFromCache( - HostResolver::RequestInfo(key_.destination()), &stale_address_list_, - &stale_info, net_log_) == OK) { - io_state_ = STATE_CONNECT; - LogStaleHostRacing(true); - dns_race_ongoing_ = true; - return OK; + // If request resulted in a stale cache entry, start request for fresh results + DCHECK(race_stale_dns_on_connection_); + + parameters.cache_usage = + HostResolver::ResolveHostParameters::CacheUsage::DISALLOWED; + fresh_resolve_host_request_ = + host_resolver_->CreateRequest(key_.destination(), net_log_, parameters); + // Unretained is safe because |this| owns the request, ensuring cancellation + // on destruction. + int fresh_rv = fresh_resolve_host_request_->Start(base::BindOnce( + &QuicStreamFactory::Job::OnResolveHostComplete, base::Unretained(this))); + if (fresh_rv != ERR_IO_PENDING) { + // Fresh request returned immediate results. + LogStaleHostRacing(false); + resolve_host_request_ = std::move(fresh_resolve_host_request_); + return rv; } - LogStaleHostRacing(false); - net_log_.AddEvent( - NetLogEventType::QUIC_STREAM_FACTORY_JOB_STALE_HOST_RESOLUTION_FAILED); - return ERR_IO_PENDING; + + io_state_ = STATE_CONNECT; + LogStaleHostRacing(true); + return OK; } int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { @@ -661,12 +703,13 @@ int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { if (rv != OK) return rv; - DCHECK(!dns_race_ongoing_); + DCHECK(!fresh_resolve_host_request_); DCHECK(!factory_->HasActiveSession(key_.session_key())); // Inform the factory of this resolution, which will set up // a session alias, if possible. - if (factory_->HasMatchingIpSession(key_, address_list_)) { + if (factory_->HasMatchingIpSession( + key_, resolve_host_request_->GetAddressResults().value())) { LogConnectionIpPooling(true); return OK; } @@ -685,7 +728,7 @@ int QuicStreamFactory::Job::DoConnect() { DCHECK_NE(quic_version_, quic::QUIC_VERSION_UNSUPPORTED); int rv = factory_->CreateSession( key_, quic_version_, cert_verify_flags_, require_confirmation, - dns_race_ongoing_ ? stale_address_list_ : address_list_, + resolve_host_request_->GetAddressResults().value(), dns_resolution_start_time_, dns_resolution_end_time_, net_log_, &session_, &network_); DVLOG(1) << "Created session on network: " << network_; @@ -715,36 +758,23 @@ int QuicStreamFactory::Job::DoConnect() { } int QuicStreamFactory::Job::DoConnectComplete(int rv) { - if (!dns_race_ongoing_) { + if (!fresh_resolve_host_request_) { io_state_ = STATE_CONFIRM_CONNECTION; return rv; } if (rv == OK) { - io_state_ = STATE_WAIT_FOR_HOST_RESOLUTION; - return OK; + io_state_ = STATE_HOST_VALIDATION; + return ERR_IO_PENDING; } // Connection from stale host resolution failed, has been closed and will - // be deleted soon. Update Job status accordingly. - dns_race_ongoing_ = false; + // be deleted soon. Update Job status accordingly to wait for fresh host + // resolution. + resolve_host_request_ = std::move(fresh_resolve_host_request_); session_ = nullptr; - - if (address_list_.empty()) { - io_state_ = STATE_RESOLVE_HOST_COMPLETE; - return ERR_IO_PENDING; - } - // TODO(renjietang): Check if IP matches. If so, we don't need to try - // connecting with the bad IP again. - io_state_ = STATE_CONNECT; - return OK; -} - -int QuicStreamFactory::Job::DoWaitForHostResolution() { - io_state_ = STATE_HOST_VALIDATION; - if (address_list_.empty()) - return ERR_IO_PENDING; - return OK; + io_state_ = STATE_RESOLVE_HOST_COMPLETE; + return ERR_IO_PENDING; } // This state is reached iff both host resolution and connection from stale dns @@ -752,16 +782,16 @@ int QuicStreamFactory::Job::DoWaitForHostResolution() { int QuicStreamFactory::Job::DoValidateHost() { if (DoesPeerAddressMatchWithFreshAddressList()) { LogStaleAndFreshHostMatched(true); + fresh_resolve_host_request_ = nullptr; + host_resolution_finished_ = true; io_state_ = STATE_CONFIRM_CONNECTION; return OK; } LogStaleAndFreshHostMatched(false); - net_log_.AddEvent( - NetLogEventType::QUIC_STREAM_FACTORY_JOB_STALE_HOST_RESOLUTION_NO_MATCH); - dns_race_ongoing_ = false; + resolve_host_request_ = std::move(fresh_resolve_host_request_); CloseStaleHostConnection(); - io_state_ = STATE_CONNECT; + io_state_ = STATE_RESOLVE_HOST_COMPLETE; return OK; } @@ -788,7 +818,8 @@ int QuicStreamFactory::Job::DoConfirmConnection(int rv) { !session_->IsCryptoHandshakeConfirmed() && network_ == factory_->default_network()) { if (session_->error() == quic::QUIC_NETWORK_IDLE_TIMEOUT || - session_->error() == quic::QUIC_HANDSHAKE_TIMEOUT) { + session_->error() == quic::QUIC_HANDSHAKE_TIMEOUT || + session_->error() == quic::QUIC_PACKET_WRITE_ERROR) { // Retry the connection on an alternate network if crypto handshake failed // with network idle time out or handshake time out. DCHECK(network_ != NetworkChangeNotifier::kInvalidNetworkHandle); @@ -988,17 +1019,20 @@ QuicStreamFactory::QuicStreamFactory( bool mark_quic_broken_when_network_blackholes, int idle_connection_timeout_seconds, int reduced_ping_timeout_seconds, + int retransmittable_on_wire_timeout_milliseconds, int max_time_before_crypto_handshake_seconds, int max_idle_time_before_crypto_handshake_seconds, bool migrate_sessions_on_network_change_v2, bool migrate_sessions_early_v2, bool retry_on_alternate_network_before_handshake, - bool race_stale_dns_on_connection, - bool go_away_on_path_degrading, + bool migrate_idle_sessions, + base::TimeDelta idle_session_migration_period, base::TimeDelta max_time_on_non_default_network, int max_migrations_to_non_default_network_on_write_error, int max_migrations_to_non_default_network_on_path_degrading, bool allow_server_migration, + bool race_stale_dns_on_connection, + bool go_away_on_path_degrading, bool race_cert_verification, bool estimate_initial_rtt, bool headers_include_h2_stream_dependency, @@ -1037,6 +1071,8 @@ QuicStreamFactory::QuicStreamFactory( ping_timeout_(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs)), reduced_ping_timeout_( quic::QuicTime::Delta::FromSeconds(reduced_ping_timeout_seconds)), + retransmittable_on_wire_timeout_(quic::QuicTime::Delta::FromMilliseconds( + retransmittable_on_wire_timeout_milliseconds)), yield_after_packets_(kQuicYieldAfterPacketsRead), yield_after_duration_(quic::QuicTime::Delta::FromMilliseconds( kQuicYieldAfterDurationMilliseconds)), @@ -1050,27 +1086,29 @@ QuicStreamFactory::QuicStreamFactory( retry_on_alternate_network_before_handshake_( retry_on_alternate_network_before_handshake && migrate_sessions_on_network_change_v2_), - race_stale_dns_on_connection_(race_stale_dns_on_connection), - go_away_on_path_degrading_(go_away_on_path_degrading), default_network_(NetworkChangeNotifier::kInvalidNetworkHandle), + migrate_idle_sessions_(migrate_idle_sessions && + migrate_sessions_on_network_change_v2_), + idle_session_migration_period_(idle_session_migration_period), max_time_on_non_default_network_(max_time_on_non_default_network), max_migrations_to_non_default_network_on_write_error_( max_migrations_to_non_default_network_on_write_error), max_migrations_to_non_default_network_on_path_degrading_( max_migrations_to_non_default_network_on_path_degrading), allow_server_migration_(allow_server_migration), + race_stale_dns_on_connection_(race_stale_dns_on_connection), + go_away_on_path_degrading_(go_away_on_path_degrading), race_cert_verification_(race_cert_verification), estimate_initial_rtt(estimate_initial_rtt), headers_include_h2_stream_dependency_( headers_include_h2_stream_dependency), need_to_check_persisted_supports_quic_(true), num_push_streams_created_(0), + tick_clock_(nullptr), task_runner_(nullptr), ssl_config_service_(ssl_config_service), enable_socket_recv_optimization_(enable_socket_recv_optimization), weak_factory_(this) { - if (ssl_config_service_) - ssl_config_service_->AddObserver(this); DCHECK(transport_security_state_); DCHECK(http_server_properties_); crypto_config_.set_user_agent_id(user_agent_id); @@ -1113,8 +1151,6 @@ QuicStreamFactory::~QuicStreamFactory() { active_jobs_.clear(); while (!active_cert_verifier_jobs_.empty()) active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin()); - if (ssl_config_service_) - ssl_config_service_->RemoveObserver(this); if (close_sessions_on_ip_change_ || goaway_sessions_on_ip_change_) { NetworkChangeNotifier::RemoveIPAddressObserver(this); } @@ -1290,6 +1326,9 @@ int QuicStreamFactory::Create(const QuicSessionKey& session_key, if (!task_runner_) task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); + if (!tick_clock_) + tick_clock_ = base::DefaultTickClock::GetInstance(); + ignore_result( StartCertVerifyJob(session_key.server_id(), cert_verify_flags, net_log)); @@ -1611,10 +1650,6 @@ std::unique_ptr<DatagramClientSocket> QuicStreamFactory::CreateSocket( return socket; } -void QuicStreamFactory::OnSSLConfigChanged() { - CloseAllSessions(ERR_CERT_DATABASE_CHANGED, quic::QUIC_CONNECTION_CANCELLED); -} - void QuicStreamFactory::OnCertDBChanged() { // We should flush the sessions if we removed trust from a // cert, because a previously trusted server may have become @@ -1781,8 +1816,7 @@ int QuicStreamFactory::CreateSession( config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize); config.SetBytesForConnectionIdToSend(0); ConfigureInitialRttEstimate(server_id, &config); - if (quic_version > quic::QUIC_VERSION_35 && - quic_version < quic::QUIC_VERSION_44 && + if (quic_version < quic::QUIC_VERSION_44 && !config.HasClientSentConnectionOption(quic::kNSTP, quic::Perspective::IS_CLIENT)) { // Enable the no stop waiting frames connection option by default. @@ -1810,16 +1844,17 @@ int QuicStreamFactory::CreateSession( clock_, transport_security_state_, ssl_config_service_, std::move(server_info), key.session_key(), require_confirmation, migrate_sessions_early_v2_, migrate_sessions_on_network_change_v2_, - go_away_on_path_degrading_, default_network_, + default_network_, retransmittable_on_wire_timeout_, + migrate_idle_sessions_, idle_session_migration_period_, max_time_on_non_default_network_, max_migrations_to_non_default_network_on_write_error_, max_migrations_to_non_default_network_on_path_degrading_, - yield_after_packets_, yield_after_duration_, + yield_after_packets_, yield_after_duration_, go_away_on_path_degrading_, headers_include_h2_stream_dependency_, cert_verify_flags, config, &crypto_config_, network_connection_.connection_description(), dns_resolution_start_time, dns_resolution_end_time, &push_promise_index_, - push_delegate_, task_runner_, std::move(socket_performance_watcher), - net_log.net_log()); + push_delegate_, tick_clock_, task_runner_, + std::move(socket_performance_watcher), net_log.net_log()); all_sessions_[*session] = key; // owning pointer writer->set_delegate(*session); diff --git a/chromium/net/quic/quic_stream_factory.h b/chromium/net/quic/quic_stream_factory.h index 6dcb932e8e9..0a64637a262 100644 --- a/chromium/net/quic/quic_stream_factory.h +++ b/chromium/net/quic/quic_stream_factory.h @@ -18,6 +18,7 @@ #include "base/logging.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" +#include "base/time/tick_clock.h" #include "base/time/time.h" #include "net/base/address_list.h" #include "net/base/completion_once_callback.h" @@ -79,6 +80,15 @@ class QuicStreamFactoryPeer; // When a connection is idle for 30 seconds it will be closed. const int kIdleConnectionTimeoutSeconds = 30; +// Sessions can migrate if they have been idle for less than this period. +const int kDefaultIdleSessionMigrationPeriodSeconds = 30; + +// The maximum time allowed to have no retransmittable packets on the wire +// (after sending the first retransmittable packet) if +// |migrate_session_early_v2_| is true. PING frames will be sent as needed to +// enforce this. +const int64_t kDefaultRetransmittableOnWireTimeoutMillisecs = 100; + // The default maximum time QUIC session could be on non-default network before // migrate back to default network. const int64_t kMaxTimeOnNonDefaultNetworkSecs = 128; @@ -191,7 +201,6 @@ class NET_EXPORT_PRIVATE QuicStreamRequest { class NET_EXPORT_PRIVATE QuicStreamFactory : public NetworkChangeNotifier::IPAddressObserver, public NetworkChangeNotifier::NetworkObserver, - public SSLConfigService::Observer, public CertDatabase::Observer { public: // This class encompasses |destination| and |server_id|. @@ -247,17 +256,20 @@ class NET_EXPORT_PRIVATE QuicStreamFactory bool mark_quic_broken_when_network_blackholes, int idle_connection_timeout_seconds, int reduced_ping_timeout_seconds, + int retransmittable_on_wire_timeout_milliseconds_, int max_time_before_crypto_handshake_seconds, int max_idle_time_before_crypto_handshake_seconds, bool migrate_sessions_on_network_change_v2, bool migrate_sessions_early_v2, bool retry_on_alternate_network_before_handshake, - bool race_stale_dns_on_connection, - bool go_away_on_path_degrading, + bool migrate_idle_sessions, + base::TimeDelta idle_session_migration_period, base::TimeDelta max_time_on_non_default_network, int max_migrations_to_non_default_network_on_write_error, int max_migrations_to_non_default_network_on_path_degrading, bool allow_server_migration, + bool race_stale_dns_on_connection, + bool go_away_on_path_degrading, bool race_cert_verification, bool estimate_initial_rtt, bool headers_include_h2_stream_dependency, @@ -350,11 +362,6 @@ class NET_EXPORT_PRIVATE QuicStreamFactory void OnNetworkMadeDefault( NetworkChangeNotifier::NetworkHandle network) override; - // SSLConfigService::Observer methods: - - // We perform the same flushing as described above when SSL settings change. - void OnSSLConfigChanged() override; - // CertDatabase::Observer methods: // We close all sessions when certificate database is changed. @@ -528,6 +535,9 @@ class NET_EXPORT_PRIVATE QuicStreamFactory quic::QuicTime::Delta ping_timeout_; quic::QuicTime::Delta reduced_ping_timeout_; + // Timeout for how long the wire can have no retransmittable packets. + quic::QuicTime::Delta retransmittable_on_wire_timeout_; + // If more than |yield_after_packets_| packets have been read or more than // |yield_after_duration_| time has passed, then // QuicChromiumPacketReader::StartReading() yields by doing a PostTask(). @@ -552,19 +562,18 @@ class NET_EXPORT_PRIVATE QuicStreamFactory // connection fails on the default network before handshake is confirmed. const bool retry_on_alternate_network_before_handshake_; - // Set if stale DNS result may be speculatively used to connect and then - // compared with the original DNS result. - const bool race_stale_dns_on_connection_; - - // Set if client should mark the session as GOAWAY when the connection - // experiences poor connectivity - const bool go_away_on_path_degrading_; - // If |migrate_sessions_early_v2_| is true, tracks the current default // network, and is updated OnNetworkMadeDefault. // Otherwise, always set to NetworkChangeNotifier::kInvalidNetwork. NetworkChangeNotifier::NetworkHandle default_network_; + // Set if idle sessions can be migrated within + // |idle_session_migration_period_| when connection migration is triggered. + const bool migrate_idle_sessions_; + + // Sessions can migrate if they have been idle for less than this period. + const base::TimeDelta idle_session_migration_period_; + // Maximum time sessions could use on non-default network before try to // migrate back to default network. const base::TimeDelta max_time_on_non_default_network_; @@ -579,6 +588,14 @@ class NET_EXPORT_PRIVATE QuicStreamFactory // server address. const bool allow_server_migration_; + // Set if stale DNS result may be speculatively used to connect and then + // compared with the original DNS result. + const bool race_stale_dns_on_connection_; + + // Set if client should mark the session as GOAWAY when the connection + // experiences poor connectivity + const bool go_away_on_path_degrading_; + // Set if cert verification is to be raced with host resolution. bool race_cert_verification_; @@ -601,6 +618,8 @@ class NET_EXPORT_PRIVATE QuicStreamFactory quic::QuicClientPushPromiseIndex push_promise_index_; + const base::TickClock* tick_clock_; + base::SequencedTaskRunner* task_runner_; SSLConfigService* const ssl_config_service_; diff --git a/chromium/net/quic/quic_stream_factory_fuzzer.cc b/chromium/net/quic/quic_stream_factory_fuzzer.cc index 5be455ff95d..05ddcfab442 100644 --- a/chromium/net/quic/quic_stream_factory_fuzzer.cc +++ b/chromium/net/quic/quic_stream_factory_fuzzer.cc @@ -12,7 +12,7 @@ #include "net/cert/do_nothing_ct_verifier.h" #include "net/cert/mock_cert_verifier.h" #include "net/cert/x509_certificate.h" -#include "net/dns/fuzzed_host_resolver.h" +#include "net/dns/fuzzed_context_host_resolver.h" #include "net/http/http_server_properties_impl.h" #include "net/http/transport_security_state.h" #include "net/quic/mock_crypto_client_stream_factory.h" @@ -83,8 +83,8 @@ static struct Env* env = new Env(); extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { base::FuzzedDataProvider data_provider(data, size); - FuzzedHostResolver host_resolver(HostResolver::Options(), nullptr, - &data_provider); + FuzzedContextHostResolver host_resolver(HostResolver::Options(), nullptr, + &data_provider); FuzzedSocketFactory socket_factory(&data_provider); // Initialize this on each loop since some options mutate this. @@ -106,6 +106,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { bool migrate_sessions_early_v2 = false; bool migrate_sessions_on_network_change_v2 = false; bool retry_on_alternate_network_before_handshake = false; + bool migrate_idle_sessions = false; bool go_away_on_path_degrading = false; if (!close_sessions_on_ip_change) { @@ -116,6 +117,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { migrate_sessions_early_v2 = data_provider.ConsumeBool(); retry_on_alternate_network_before_handshake = data_provider.ConsumeBool(); + migrate_idle_sessions = data_provider.ConsumeBool(); } } } @@ -135,16 +137,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { goaway_sessions_on_ip_change, mark_quic_broken_when_network_blackholes, kIdleConnectionTimeoutSeconds, quic::kPingTimeoutSecs, + kDefaultRetransmittableOnWireTimeoutMillisecs, quic::kMaxTimeForCryptoHandshakeSecs, quic::kInitialIdleTimeoutSecs, migrate_sessions_on_network_change_v2, migrate_sessions_early_v2, - retry_on_alternate_network_before_handshake, - race_stale_dns_on_connection, go_away_on_path_degrading, + retry_on_alternate_network_before_handshake, migrate_idle_sessions, + base::TimeDelta::FromSeconds( + kDefaultIdleSessionMigrationPeriodSeconds), base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), kMaxMigrationsToNonDefaultNetworkOnWriteError, kMaxMigrationsToNonDefaultNetworkOnPathDegrading, - allow_server_migration, race_cert_verification, estimate_initial_rtt, - headers_include_h2_stream_dependency, env->connection_options, - env->client_connection_options, enable_socket_recv_optimization); + allow_server_migration, race_stale_dns_on_connection, + go_away_on_path_degrading, race_cert_verification, + estimate_initial_rtt, headers_include_h2_stream_dependency, + env->connection_options, env->client_connection_options, + enable_socket_recv_optimization); QuicStreamRequest request(factory.get()); TestCompletionCallback callback; diff --git a/chromium/net/quic/quic_stream_factory_peer.cc b/chromium/net/quic/quic_stream_factory_peer.cc index 5d44d9d965a..40a7ade6563 100644 --- a/chromium/net/quic/quic_stream_factory_peer.cc +++ b/chromium/net/quic/quic_stream_factory_peer.cc @@ -101,6 +101,11 @@ void QuicStreamFactoryPeer::SetTaskRunner( factory->task_runner_ = task_runner; } +void QuicStreamFactoryPeer::SetTickClock(QuicStreamFactory* factory, + const base::TickClock* tick_clock) { + factory->tick_clock_ = tick_clock; +} + quic::QuicTime::Delta QuicStreamFactoryPeer::GetPingTimeout( QuicStreamFactory* factory) { return factory->ping_timeout_; diff --git a/chromium/net/quic/quic_stream_factory_peer.h b/chromium/net/quic/quic_stream_factory_peer.h index 89e625d549e..8f9fc21451c 100644 --- a/chromium/net/quic/quic_stream_factory_peer.h +++ b/chromium/net/quic/quic_stream_factory_peer.h @@ -10,6 +10,7 @@ #include "base/macros.h" #include "base/sequenced_task_runner.h" +#include "base/time/tick_clock.h" #include "net/base/host_port_pair.h" #include "net/base/privacy_mode.h" #include "net/third_party/quic/core/quic_packets.h" @@ -63,6 +64,9 @@ class QuicStreamFactoryPeer { static bool IsLiveSession(QuicStreamFactory* factory, QuicChromiumClientSession* session); + static void SetTickClock(QuicStreamFactory* factory, + const base::TickClock* tick_clock); + static void SetTaskRunner(QuicStreamFactory* factory, base::SequencedTaskRunner* task_runner); diff --git a/chromium/net/quic/quic_stream_factory_test.cc b/chromium/net/quic/quic_stream_factory_test.cc index 1a3719d1797..3fe6aeecd4e 100644 --- a/chromium/net/quic/quic_stream_factory_test.cc +++ b/chromium/net/quic/quic_stream_factory_test.cc @@ -13,6 +13,7 @@ #include "base/macros.h" #include "base/run_loop.h" #include "base/strings/string_util.h" +#include "base/test/simple_test_tick_clock.h" #include "base/test/test_mock_time_task_runner.h" #include "build/build_config.h" #include "net/base/mock_network_change_notifier.h" @@ -225,15 +226,13 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { random_generator_(0), runner_(new TestTaskRunner(&clock_)), version_(version), - client_headers_include_h2_stream_dependency_( - client_headers_include_h2_stream_dependency), client_maker_( version_, quic::QuicUtils::CreateRandomConnectionId(&random_generator_), &clock_, kDefaultServerHostName, quic::Perspective::IS_CLIENT, - client_headers_include_h2_stream_dependency_), + client_headers_include_h2_stream_dependency), server_maker_( version_, quic::QuicUtils::CreateRandomConnectionId(&random_generator_), @@ -255,23 +254,9 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { &QuicStreamFactoryTestBase::OnFailedOnDefaultNetwork, base::Unretained(this))), failed_on_default_network_(false), - store_server_configs_in_properties_(false), - close_sessions_on_ip_change_(false), - goaway_sessions_on_ip_change_(false), - idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), - reduced_ping_timeout_seconds_(quic::kPingTimeoutSecs), - max_time_before_crypto_handshake_seconds_( - quic::kMaxTimeForCryptoHandshakeSecs), - max_idle_time_before_crypto_handshake_seconds_( - quic::kInitialIdleTimeoutSecs), - migrate_sessions_on_network_change_v2_(false), - migrate_sessions_early_v2_(false), - retry_on_alternate_network_before_handshake_(false), - race_stale_dns_on_connection_(false), - go_away_on_path_degrading_(false), - allow_server_migration_(false), - race_cert_verification_(false), - estimate_initial_rtt_(false) { + store_server_configs_in_properties_(false) { + test_params_.quic_headers_include_h2_stream_dependency = + client_headers_include_h2_stream_dependency; clock_.AdvanceTime(quic::QuicTime::Delta::FromSeconds(1)); } @@ -284,23 +269,34 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { cert_transparency_verifier_.get(), /*SocketPerformanceWatcherFactory*/ nullptr, &crypto_client_stream_factory_, &random_generator_, &clock_, - quic::kDefaultMaxPacketSize, string(), - store_server_configs_in_properties_, close_sessions_on_ip_change_, - goaway_sessions_on_ip_change_, - /*mark_quic_broken_when_network_blackholes*/ false, - idle_connection_timeout_seconds_, reduced_ping_timeout_seconds_, - max_time_before_crypto_handshake_seconds_, - max_idle_time_before_crypto_handshake_seconds_, - migrate_sessions_on_network_change_v2_, migrate_sessions_early_v2_, - retry_on_alternate_network_before_handshake_, - race_stale_dns_on_connection_, go_away_on_path_degrading_, - base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), - kMaxMigrationsToNonDefaultNetworkOnWriteError, - kMaxMigrationsToNonDefaultNetworkOnPathDegrading, - allow_server_migration_, race_cert_verification_, estimate_initial_rtt_, - client_headers_include_h2_stream_dependency_, connection_options_, - client_connection_options_, - /*enable_socket_recv_optimization*/ false)); + test_params_.quic_max_packet_length, test_params_.quic_user_agent_id, + store_server_configs_in_properties_, + test_params_.quic_close_sessions_on_ip_change, + test_params_.quic_goaway_sessions_on_ip_change, + test_params_.mark_quic_broken_when_network_blackholes, + test_params_.quic_idle_connection_timeout_seconds, + test_params_.quic_reduced_ping_timeout_seconds, + test_params_.quic_retransmittable_on_wire_timeout_milliseconds, + test_params_.quic_max_time_before_crypto_handshake_seconds, + test_params_.quic_max_idle_time_before_crypto_handshake_seconds, + test_params_.quic_migrate_sessions_on_network_change_v2, + test_params_.quic_migrate_sessions_early_v2, + test_params_.quic_retry_on_alternate_network_before_handshake, + test_params_.quic_migrate_idle_sessions, + test_params_.quic_idle_session_migration_period, + test_params_.quic_max_time_on_non_default_network, + test_params_.quic_max_migrations_to_non_default_network_on_write_error, + test_params_ + .quic_max_migrations_to_non_default_network_on_path_degrading, + test_params_.quic_allow_server_migration, + test_params_.quic_race_stale_dns_on_connection, + test_params_.quic_go_away_on_path_degrading, + test_params_.quic_race_cert_verification, + test_params_.quic_estimate_initial_rtt, + test_params_.quic_headers_include_h2_stream_dependency, + test_params_.quic_connection_options, + test_params_.quic_client_connection_options, + test_params_.quic_enable_socket_recv_optimization)); } void InitializeConnectionMigrationV2Test( @@ -311,9 +307,8 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { scoped_mock_network_change_notifier_->mock_network_change_notifier(); mock_ncn->ForceNetworkHandlesSupported(); mock_ncn->SetConnectedNetworksList(connected_networks); - migrate_sessions_on_network_change_v2_ = true; - migrate_sessions_early_v2_ = true; - retry_on_alternate_network_before_handshake_ = true; + test_params_.quic_migrate_sessions_on_network_change_v2 = true; + test_params_.quic_migrate_sessions_early_v2 = true; socket_factory_.reset(new TestConnectionMigrationSocketFactory); Initialize(); } @@ -422,13 +417,13 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { } std::unique_ptr<quic::QuicEncryptedPacket> - ConstructClientConnectionClosePacket(quic::QuicPacketNumber num) { + ConstructClientConnectionClosePacket(uint64_t num) { return client_maker_.MakeConnectionClosePacket( num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); } std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicRstStreamErrorCode error_code) { quic::QuicStreamId stream_id = GetNthClientInitiatedBidirectionalStreamId(0); @@ -454,7 +449,7 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { } std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin) { @@ -469,7 +464,7 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { } std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, quic::QuicStreamId parent_stream_id, bool should_include_version, @@ -486,7 +481,7 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { } std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -497,7 +492,7 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { } std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin) { @@ -513,7 +508,7 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { } std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset* offset) { return client_maker_.MakeInitialSettingsPacket(packet_number, offset); } @@ -521,7 +516,7 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { // Helper method for server migration tests. void VerifyServerMigration(const quic::QuicConfig& config, IPEndPoint expected_address) { - allow_server_migration_ = true; + test_params_.quic_allow_server_migration = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -594,7 +589,7 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { // Verifies that the QUIC stream factory is initialized correctly. void VerifyInitialization() { store_server_configs_in_properties_ = true; - idle_connection_timeout_seconds_ = 500; + test_params_.quic_idle_connection_timeout_seconds = 500; Initialize(); factory_->set_require_confirmation(false); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -810,7 +805,8 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } // Helper methods for tests of connection migration on write error. - void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); + void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode, + bool migrate_idle_sessions); // Migratable stream triggers write error. void TestMigrationOnWriteErrorMixedStreams(IoMode write_error_mode); // Non-migratable stream triggers write error. @@ -837,6 +833,11 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { void TestNoAlternateNetworkBeforeHandshake(quic::QuicErrorCode error); void TestNewConnectionOnAlternateNetworkBeforeHandshake( quic::QuicErrorCode error); + void TestOnNetworkMadeDefaultNonMigratableStream(bool migrate_idle_sessions); + void TestMigrateSessionEarlyNonMigratableStream(bool migrate_idle_sessions); + void TestOnNetworkDisconnectedNoOpenStreams(bool migrate_idle_sessions); + void TestOnNetworkMadeDefaultNoOpenStreams(bool migrate_idle_sessions); + void TestOnNetworkDisconnectedNonMigratableStream(bool migrate_idle_sessions); QuicFlagSaver flags_; // Save/restore all QUIC flag values. std::unique_ptr<MockHostResolverBase> host_resolver_; @@ -847,7 +848,6 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { quic::MockClock clock_; scoped_refptr<TestTaskRunner> runner_; const quic::QuicTransportVersion version_; - const bool client_headers_include_h2_stream_dependency_; QuicTestPacketMaker client_maker_; QuicTestPacketMaker server_maker_; HttpServerPropertiesImpl http_server_properties_; @@ -872,23 +872,8 @@ class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { NetErrorDetails net_error_details_; // Variables to configure QuicStreamFactory. + HttpNetworkSession::Params test_params_; bool store_server_configs_in_properties_; - bool close_sessions_on_ip_change_; - bool goaway_sessions_on_ip_change_; - int idle_connection_timeout_seconds_; - int reduced_ping_timeout_seconds_; - int max_time_before_crypto_handshake_seconds_; - int max_idle_time_before_crypto_handshake_seconds_; - bool migrate_sessions_on_network_change_v2_; - bool migrate_sessions_early_v2_; - bool retry_on_alternate_network_before_handshake_; - bool race_stale_dns_on_connection_; - bool go_away_on_path_degrading_; - bool allow_server_migration_; - bool race_cert_verification_; - bool estimate_initial_rtt_; - quic::QuicTagVector connection_options_; - quic::QuicTagVector client_connection_options_; }; class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, @@ -900,9 +885,9 @@ class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, GetParam().client_headers_include_h2_stream_dependency) {} }; -INSTANTIATE_TEST_CASE_P(VersionIncludeStreamDependencySequence, - QuicStreamFactoryTest, - ::testing::ValuesIn(GetTestParams())); +INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, + QuicStreamFactoryTest, + ::testing::ValuesIn(GetTestParams())); TEST_P(QuicStreamFactoryTest, Create) { Initialize(); @@ -1124,7 +1109,7 @@ TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { stats.srtt = base::TimeDelta::FromMilliseconds(10); http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), stats); - estimate_initial_rtt_ = true; + test_params_.quic_estimate_initial_rtt = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -1157,7 +1142,7 @@ TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { ScopedMockNetworkChangeNotifier notifier; notifier.mock_network_change_notifier()->SetConnectionType( NetworkChangeNotifier::CONNECTION_2G); - estimate_initial_rtt_ = true; + test_params_.quic_estimate_initial_rtt = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -1190,7 +1175,7 @@ TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { ScopedMockNetworkChangeNotifier notifier; notifier.mock_network_change_notifier()->SetConnectionType( NetworkChangeNotifier::CONNECTION_3G); - estimate_initial_rtt_ = true; + test_params_.quic_estimate_initial_rtt = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -2027,7 +2012,7 @@ TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { } TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { - close_sessions_on_ip_change_ = true; + test_params_.quic_close_sessions_on_ip_change = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); @@ -2111,7 +2096,7 @@ TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { // as going away on IP address change instead of being closed. New requests will // go to a new connection. TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { - goaway_sessions_on_ip_change_ = true; + test_params_.quic_goaway_sessions_on_ip_change = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); @@ -2633,7 +2618,7 @@ TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { // available): // - default network disconnected is delivered: session attempts connection // migration but found not alternate network. Session waits for a new network -// comes up in the next kWaitTimeForNewNetworkSecs seonds. +// comes up in the next kWaitTimeForNewNetworkSecs seconds. // - no new network is connected, migration times out. Session is closed. TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); @@ -2704,9 +2689,24 @@ TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { // This test verifies that connectivity probes will be sent even if there is // a non-migratable stream. However, when connection migrates to the +// successfully probed path, any non-migratable streams will be reset. +TEST_P(QuicStreamFactoryTest, + OnNetworkMadeDefaultNonMigratableStream_MigrateIdleSessions) { + TestOnNetworkMadeDefaultNonMigratableStream(true); +} + +// This test verifies that connectivity probes will be sent even if there is +// a non-migratable stream. However, when connection migrates to the // successfully probed path, any non-migratable stream will be reset. And if // the connection becomes idle then, close the connection. -TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { +TEST_P(QuicStreamFactoryTest, + OnNetworkMadeDefaultNonMigratableStream_DoNotMigrateIdleSessions) { + TestOnNetworkMadeDefaultNonMigratableStream(false); +} + +void QuicStreamFactoryTestBase::TestOnNetworkMadeDefaultNonMigratableStream( + bool migrate_idle_sessions) { + test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -2715,13 +2715,16 @@ TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { MockQuicData socket_data; socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); - socket_data.AddWrite( - SYNCHRONOUS, - client_maker_.MakeRstAckAndConnectionClosePacket( - 3, false, GetNthClientInitiatedBidirectionalStreamId(0), - quic::QUIC_STREAM_CANCELLED, - quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, - quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); + if (!migrate_idle_sessions) { + socket_data.AddWrite( + SYNCHRONOUS, + client_maker_.MakeRstAckAndConnectionClosePacket( + 3, false, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED, + quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, + quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, + "net error")); + } socket_data.AddSocketDataToFactory(socket_factory_.get()); @@ -2734,6 +2737,18 @@ TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { // Connectivity probe to receive from the server. quic_data1.AddRead(ASYNC, server_maker_.MakeConnectivityProbingPacket(1, false)); + if (migrate_idle_sessions) { + quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + // A RESET will be sent to the peer to cancel the non-migratable stream. + quic_data1.AddWrite( + SYNCHRONOUS, + client_maker_.MakeRstPacket( + 3, false, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED)); + // Ping packet to send after migration is completed. + quic_data1.AddWrite(SYNCHRONOUS, + client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); + } quic_data1.AddSocketDataToFactory(socket_factory_.get()); // Create request and QuicHttpStream. @@ -2772,13 +2787,14 @@ TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { EXPECT_EQ(1u, session->GetNumActiveStreams()); // Resume data to read a connectivity probing response, which will cause - // non-migtable streams to be closed. As session becomes idle, connection will - // be closed. + // non-migtable streams to be closed. quic_data1.Resume(); EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); - EXPECT_FALSE(HasActiveSession(host_port_pair_)); + EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); EXPECT_EQ(0u, session->GetNumActiveStreams()); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(quic_data1.AllReadDataConsumed()); EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); EXPECT_TRUE(socket_data.AllReadDataConsumed()); @@ -2844,20 +2860,53 @@ TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { EXPECT_TRUE(socket_data.AllWriteDataConsumed()); } -TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { +TEST_P(QuicStreamFactoryTest, + OnNetworkDisconnectedNonMigratableStream_DoNotMigrateIdleSessions) { + TestOnNetworkDisconnectedNonMigratableStream(false); +} + +TEST_P(QuicStreamFactoryTest, + OnNetworkDisconnectedNonMigratableStream_MigrateIdleSessions) { + TestOnNetworkDisconnectedNonMigratableStream(true); +} + +void QuicStreamFactoryTestBase::TestOnNetworkDisconnectedNonMigratableStream( + bool migrate_idle_sessions) { + test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); + MockQuicData failed_socket_data; MockQuicData socket_data; - socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); - socket_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeRstPacket( - 2, true, GetNthClientInitiatedBidirectionalStreamId(0), - quic::QUIC_STREAM_CANCELLED)); - socket_data.AddSocketDataToFactory(socket_factory_.get()); + if (migrate_idle_sessions) { + quic::QuicStreamOffset header_stream_offset = 0; + failed_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + failed_socket_data.AddWrite( + SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); + // A RESET will be sent to the peer to cancel the non-migratable stream. + failed_socket_data.AddWrite( + SYNCHRONOUS, client_maker_.MakeRstPacket( + 2, true, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED)); + failed_socket_data.AddSocketDataToFactory(socket_factory_.get()); + + // Set up second socket data provider that is used after migration. + socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + // Ping packet to send after migration. + socket_data.AddWrite( + SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); + socket_data.AddSocketDataToFactory(socket_factory_.get()); + } else { + socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); + socket_data.AddWrite( + SYNCHRONOUS, client_maker_.MakeRstPacket( + 2, true, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED)); + socket_data.AddSocketDataToFactory(socket_factory_.get()); + } // Create request and QuicHttpStream. QuicStreamRequest request(factory_.get()); @@ -2886,13 +2935,23 @@ TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { // Trigger connection migration. Since there is a non-migratable stream, // this should cause a RST_STREAM frame to be emitted with - // quic::QUIC_STREAM_CANCELLED error code, and the session will be closed. + // quic::QUIC_STREAM_CANCELLED error code. + // If migate idle session, the connection will then be migrated to the + // alternate network. Otherwise, the connection will be closed. scoped_mock_network_change_notifier_->mock_network_change_notifier() ->NotifyNetworkDisconnected(kDefaultNetworkForTests); - EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); - EXPECT_FALSE(HasActiveSession(host_port_pair_)); + EXPECT_EQ(migrate_idle_sessions, + QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); + EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); + + if (migrate_idle_sessions) { + EXPECT_EQ(0u, session->GetNumActiveStreams()); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(failed_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(failed_socket_data.AllWriteDataConsumed()); + } EXPECT_TRUE(socket_data.AllReadDataConsumed()); EXPECT_TRUE(socket_data.AllWriteDataConsumed()); } @@ -2955,7 +3014,19 @@ TEST_P(QuicStreamFactoryTest, EXPECT_TRUE(socket_data.AllWriteDataConsumed()); } -TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { +TEST_P(QuicStreamFactoryTest, + OnNetworkMadeDefaultNoOpenStreams_DoNotMigrateIdleSessions) { + TestOnNetworkMadeDefaultNoOpenStreams(false); +} + +TEST_P(QuicStreamFactoryTest, + OnNetworkMadeDefaultNoOpenStreams_MigrateIdleSessions) { + TestOnNetworkMadeDefaultNoOpenStreams(true); +} + +void QuicStreamFactoryTestBase::TestOnNetworkMadeDefaultNoOpenStreams( + bool migrate_idle_sessions) { + test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -2964,13 +3035,32 @@ TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { MockQuicData socket_data; socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); - socket_data.AddWrite( - SYNCHRONOUS, - client_maker_.MakeConnectionClosePacket( - 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, - "net error")); + if (!migrate_idle_sessions) { + socket_data.AddWrite( + SYNCHRONOUS, + client_maker_.MakeConnectionClosePacket( + 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, + "net error")); + } socket_data.AddSocketDataToFactory(socket_factory_.get()); + MockQuicData quic_data1; + if (migrate_idle_sessions) { + // Set up the second socket data provider that is used for probing. + // Connectivity probe to be sent on the new path. + quic_data1.AddWrite(SYNCHRONOUS, + client_maker_.MakeConnectivityProbingPacket(2, true)); + quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause + // Connectivity probe to receive from the server. + quic_data1.AddRead(ASYNC, + server_maker_.MakeConnectivityProbingPacket(1, false)); + quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + // Ping packet to send after migration is completed. + quic_data1.AddWrite(SYNCHRONOUS, + client_maker_.MakeAckAndPingPacket(3, false, 1, 1, 1)); + quic_data1.AddSocketDataToFactory(socket_factory_.get()); + } + // Create request and QuicHttpStream. QuicStreamRequest request(factory_.get()); EXPECT_EQ(ERR_IO_PENDING, @@ -2987,28 +3077,57 @@ TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); EXPECT_TRUE(HasActiveSession(host_port_pair_)); + EXPECT_EQ(0u, session->GetNumActiveStreams()); + EXPECT_EQ(0u, session->GetNumDrainingStreams()); // Trigger connection migration. scoped_mock_network_change_notifier_->mock_network_change_notifier() ->NotifyNetworkMadeDefault(kNewNetworkForTests); + EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); - EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); - EXPECT_FALSE(HasActiveSession(host_port_pair_)); - + if (migrate_idle_sessions) { + quic_data1.Resume(); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(quic_data1.AllReadDataConsumed()); + EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); + } EXPECT_TRUE(socket_data.AllReadDataConsumed()); EXPECT_TRUE(socket_data.AllWriteDataConsumed()); } -TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { +TEST_P(QuicStreamFactoryTest, + OnNetworkDisconnectedNoOpenStreams_DoNotMigateIdleSessions) { + TestOnNetworkDisconnectedNoOpenStreams(false); +} + +TEST_P(QuicStreamFactoryTest, + OnNetworkDisconnectedNoOpenStreams_MigateIdleSessions) { + TestOnNetworkDisconnectedNoOpenStreams(true); +} + +void QuicStreamFactoryTestBase::TestOnNetworkDisconnectedNoOpenStreams( + bool migrate_idle_sessions) { + test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); - MockQuicData socket_data; - socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); - socket_data.AddSocketDataToFactory(socket_factory_.get()); + MockQuicData default_socket_data; + default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); + default_socket_data.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData alternate_socket_data; + if (migrate_idle_sessions) { + // Set up second socket data provider that is used after migration. + alternate_socket_data.AddRead(SYNCHRONOUS, + ERR_IO_PENDING); // Hanging read. + // Ping packet to send after migration. + alternate_socket_data.AddWrite( + SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); + alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); + } // Create request and QuicHttpStream. QuicStreamRequest request(factory_.get()); @@ -3022,9 +3141,7 @@ TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { std::unique_ptr<HttpStream> stream = CreateStream(&request); EXPECT_TRUE(stream.get()); - // Ensure that session is alive and active. - QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); - EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); + // Ensure that session is active. EXPECT_TRUE(HasActiveSession(host_port_pair_)); // Trigger connection migration. Since there are no active streams, @@ -3032,11 +3149,14 @@ TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { scoped_mock_network_change_notifier_->mock_network_change_notifier() ->NotifyNetworkDisconnected(kDefaultNetworkForTests); - EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); - EXPECT_FALSE(HasActiveSession(host_port_pair_)); + EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); - EXPECT_TRUE(socket_data.AllReadDataConsumed()); - EXPECT_TRUE(socket_data.AllWriteDataConsumed()); + EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); + if (migrate_idle_sessions) { + EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); + } } // This test verifies session migrates to the alternate network immediately when @@ -3647,7 +3767,7 @@ void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( // This test verifies that the session marks itself GOAWAY on path degrading // and it does not receive any new request TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { - go_away_on_path_degrading_ = true; + test_params_.quic_go_away_on_path_degrading = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); @@ -4410,7 +4530,19 @@ TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { // This test verifies that session with non-migratable stream will probe the // alternate network on path degrading, and close the non-migratable streams // when probe is successful. -TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { +TEST_P(QuicStreamFactoryTest, + MigrateSessionEarlyNonMigratableStream_DoNotMigrateIdleSessions) { + TestMigrateSessionEarlyNonMigratableStream(false); +} + +TEST_P(QuicStreamFactoryTest, + MigrateSessionEarlyNonMigratableStream_MigrateIdleSessions) { + TestMigrateSessionEarlyNonMigratableStream(true); +} + +void QuicStreamFactoryTestBase::TestMigrateSessionEarlyNonMigratableStream( + bool migrate_idle_sessions) { + test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -4419,13 +4551,16 @@ TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { MockQuicData socket_data; socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); - socket_data.AddWrite( - SYNCHRONOUS, - client_maker_.MakeRstAckAndConnectionClosePacket( - 3, false, GetNthClientInitiatedBidirectionalStreamId(0), - quic::QUIC_STREAM_CANCELLED, - quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, - quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); + if (!migrate_idle_sessions) { + socket_data.AddWrite( + SYNCHRONOUS, + client_maker_.MakeRstAckAndConnectionClosePacket( + 3, false, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED, + quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, + quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, + "net error")); + } socket_data.AddSocketDataToFactory(socket_factory_.get()); // Set up the second socket data provider that is used for probing. @@ -4437,6 +4572,18 @@ TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { // Connectivity probe to receive from the server. quic_data1.AddRead(ASYNC, server_maker_.MakeConnectivityProbingPacket(1, false)); + if (migrate_idle_sessions) { + quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + // A RESET will be sent to the peer to cancel the non-migratable stream. + quic_data1.AddWrite( + SYNCHRONOUS, + client_maker_.MakeRstPacket( + 3, false, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED)); + // Ping packet to send after migration is completed. + quic_data1.AddWrite(SYNCHRONOUS, + client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); + } quic_data1.AddSocketDataToFactory(socket_factory_.get()); // Create request and QuicHttpStream. @@ -4465,22 +4612,23 @@ TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { EXPECT_TRUE(HasActiveSession(host_port_pair_)); // Trigger connection migration. Since there is a non-migratable stream, - // this should cause session to be continue without migrating. + // this should cause session to migrate. session->OnPathDegrading(); // Run the message loop so that data queued in the new socket is read by the // packet reader. base::RunLoop().RunUntilIdle(); - EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); EXPECT_TRUE(HasActiveSession(host_port_pair_)); EXPECT_EQ(1u, session->GetNumActiveStreams()); // Resume the data to read the connectivity probing response to declare probe // as successful. Non-migratable streams will be closed. quic_data1.Resume(); - EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); - EXPECT_FALSE(HasActiveSession(host_port_pair_)); + if (migrate_idle_sessions) + base::RunLoop().RunUntilIdle(); + + EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); EXPECT_EQ(0u, session->GetNumActiveStreams()); EXPECT_TRUE(quic_data1.AllReadDataConsumed()); @@ -4601,7 +4749,8 @@ TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { socket_data1.AddWrite( SYNCHRONOUS, client_maker_.MakeRstPacket( 5, false, GetNthClientInitiatedBidirectionalStreamId(1), - quic::QUIC_STREAM_CANCELLED, 0)); + quic::QUIC_STREAM_CANCELLED, 0, + /*include_stop_sending_if_v99=*/true)); socket_data1.AddSocketDataToFactory(socket_factory_.get()); @@ -4814,7 +4963,8 @@ TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { quic_data3.AddWrite( SYNCHRONOUS, client_maker_.MakeRstPacket( 5, false, GetNthClientInitiatedBidirectionalStreamId(0), - quic::QUIC_STREAM_CANCELLED, 0)); + quic::QUIC_STREAM_CANCELLED, 0, + /*include_stop_sending_if_v99=*/true)); quic_data3.AddSocketDataToFactory(socket_factory_.get()); // Fast forward to fire the migrate back timer and verify the session @@ -4997,6 +5147,7 @@ void QuicStreamFactoryTestBase:: quic::QuicErrorCode quic_error) { DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); + test_params_.quic_retry_on_alternate_network_before_handshake = true; InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); @@ -5148,6 +5299,7 @@ void QuicStreamFactoryTestBase:: // is triggered before handshake is confirmed and connection migration is turned // on. TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { + DCHECK(!test_params_.quic_retry_on_alternate_network_before_handshake); InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); @@ -5212,6 +5364,102 @@ TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); } +// Test that if the original connection is closed with QUIC_PACKET_WRITE_ERROR +// before handshake is confirmed and new connection before handshake is turned +// on, a new connection will be retried on the alternate network. +TEST_P(QuicStreamFactoryTest, + RetryConnectionOnWriteErrorBeforeHandshakeConfirmed) { + test_params_.quic_retry_on_alternate_network_before_handshake = true; + InitializeConnectionMigrationV2Test( + {kDefaultNetworkForTests, kNewNetworkForTests}); + + // Use unmocked crypto stream to do crypto connect. + crypto_client_stream_factory_.set_handshake_mode( + MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); + + // Socket data for connection on the default network. + MockQuicData socket_data; + socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. + socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + socket_data.AddSocketDataToFactory(socket_factory_.get()); + + // Socket data for connection on the alternate network. + MockQuicData socket_data2; + quic::QuicStreamOffset header_stream_offset = 0; + socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); + socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. + // Change the encryption level after handshake is confirmed. + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); + socket_data2.AddWrite( + ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); + socket_data2.AddWrite( + ASYNC, ConstructGetRequestPacket( + 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, + &header_stream_offset)); + socket_data2.AddRead( + ASYNC, + ConstructOkResponsePacket( + 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); + socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + socket_data2.AddWrite( + SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( + 4, false, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); + socket_data2.AddSocketDataToFactory(socket_factory_.get()); + + // Create request, should fail after the write of the CHLO fails. + QuicStreamRequest request(factory_.get()); + EXPECT_EQ(ERR_IO_PENDING, + request.Request( + host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, + SocketTag(), + /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, + failed_on_default_network_callback_, callback_.callback())); + // Ensure that the session is alive but not active. + EXPECT_FALSE(HasActiveSession(host_port_pair_)); + EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); + base::RunLoop().RunUntilIdle(); + QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); + EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); + + // Confirm the handshake on the alternate network. + crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( + quic::QuicSession::HANDSHAKE_CONFIRMED); + EXPECT_THAT(callback_.WaitForResult(), IsOk()); + EXPECT_TRUE(HasActiveSession(host_port_pair_)); + + // Resume the data now so that data can be sent and read. + socket_data2.Resume(); + + // Create the stream. + std::unique_ptr<HttpStream> stream = CreateStream(&request); + EXPECT_TRUE(stream.get()); + HttpRequestInfo request_info; + request_info.method = "GET"; + request_info.url = GURL("https://www.example.org/"); + request_info.traffic_annotation = + MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); + EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, + net_log_, CompletionOnceCallback())); + // Send the request. + HttpResponseInfo response; + HttpRequestHeaders request_headers; + EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, + callback_.callback())); + // Run the message loop to finish asynchronous mock write. + base::RunLoop().RunUntilIdle(); + // Read the response. + EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); + EXPECT_EQ(200, response.headers->response_code()); + + stream.reset(); + EXPECT_TRUE(socket_data.AllReadDataConsumed()); + EXPECT_TRUE(socket_data.AllWriteDataConsumed()); + EXPECT_TRUE(socket_data2.AllReadDataConsumed()); + EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); +} + void QuicStreamFactoryTestBase::TestMigrationOnWriteError( IoMode write_error_mode) { InitializeConnectionMigrationV2Test( @@ -5459,7 +5707,8 @@ void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( socket_data1.AddWrite( SYNCHRONOUS, client_maker_.MakeRstPacket( 4, false, GetNthClientInitiatedBidirectionalStreamId(1), - quic::QUIC_STREAM_CANCELLED, 0)); + quic::QUIC_STREAM_CANCELLED, 0, + /*include_stop_sending_if_v99=*/true)); socket_data1.AddSocketDataToFactory(socket_factory_.get()); @@ -5585,7 +5834,8 @@ void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( SYNCHRONOUS, client_maker_.MakeRstPacket(packet_number++, true, GetNthClientInitiatedBidirectionalStreamId(1), - quic::QUIC_STREAM_CANCELLED, 0)); + quic::QUIC_STREAM_CANCELLED, 0, + /*include_stop_sending_if_v99=*/true)); socket_data1.AddRead( ASYNC, ConstructOkResponsePacket( @@ -5726,7 +5976,8 @@ void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( SYNCHRONOUS, client_maker_.MakeRstPacket(packet_number++, true, GetNthClientInitiatedBidirectionalStreamId(1), - quic::QUIC_STREAM_CANCELLED, 0)); + quic::QUIC_STREAM_CANCELLED, 0, + /*include_stop_sending_if_v99=*/true)); socket_data1.AddWrite( SYNCHRONOUS, ConstructGetRequestPacket(packet_number++, @@ -5830,20 +6081,52 @@ void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); } +// This test verifies that when a connection encounters a packet write error, it +// will cancel non-migratable streams, and migrate to the alternate network. void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( - IoMode write_error_mode) { - DVLOG(1) << "Mode: " + IoMode write_error_mode, + bool migrate_idle_sessions) { + DVLOG(1) << "Write error mode: " << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); + DVLOG(1) << "Migrate idle sessions: " << migrate_idle_sessions; + test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; InitializeConnectionMigrationV2Test( {kDefaultNetworkForTests, kNewNetworkForTests}); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); + MockQuicData failed_socket_data; MockQuicData socket_data; - socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); - socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); - socket_data.AddSocketDataToFactory(socket_factory_.get()); + if (migrate_idle_sessions) { + quic::QuicStreamOffset header_stream_offset = 0; + // The socket data provider for the original socket before migration. + failed_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + failed_socket_data.AddWrite( + SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); + failed_socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); + failed_socket_data.AddSocketDataToFactory(socket_factory_.get()); + + // Set up second socket data provider that is used after migration. + socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + // Although the write error occurs when writing a packet for the + // non-migratable stream and the stream will be cancelled during migration, + // the packet will still be retransimitted at the connection level. + socket_data.AddWrite( + SYNCHRONOUS, ConstructGetRequestPacket( + 2, GetNthClientInitiatedBidirectionalStreamId(0), true, + true, &header_stream_offset)); + // A RESET will be sent to the peer to cancel the non-migratable stream. + socket_data.AddWrite( + SYNCHRONOUS, client_maker_.MakeRstPacket( + 3, true, GetNthClientInitiatedBidirectionalStreamId(0), + quic::QUIC_STREAM_CANCELLED)); + socket_data.AddSocketDataToFactory(socket_factory_.get()); + } else { + socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); + socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); + socket_data.AddSocketDataToFactory(socket_factory_.get()); + } // Create request and QuicHttpStream. QuicStreamRequest request(factory_.get()); @@ -5882,22 +6165,41 @@ void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( // Run message loop to execute migration attempt. base::RunLoop().RunUntilIdle(); - // Migration fails, and session is closed and deleted. - EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); - EXPECT_FALSE(HasActiveSession(host_port_pair_)); + // Migration closes the non-migratable stream and: + // if migrate idle session is enabled, it migrates to the alternate network + // successfully; otherwise the connection is closed. + EXPECT_EQ(migrate_idle_sessions, + QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); + EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); + if (migrate_idle_sessions) { + EXPECT_TRUE(failed_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(failed_socket_data.AllWriteDataConsumed()); + } EXPECT_TRUE(socket_data.AllReadDataConsumed()); EXPECT_TRUE(socket_data.AllWriteDataConsumed()); } +TEST_P( + QuicStreamFactoryTest, + MigrateSessionOnWriteErrorNonMigratableStreamSync_DoNotMigrateIdleSessions) { + TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS, false); +} + +TEST_P( + QuicStreamFactoryTest, + MigrateSessionOnWriteErrorNonMigratableStreamAsync_DoNotMigrateIdleSessions) { + TestMigrationOnWriteErrorNonMigratableStream(ASYNC, false); +} + TEST_P(QuicStreamFactoryTest, - MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { - TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS); + MigrateSessionOnWriteErrorNonMigratableStreamSync_MigrateIdleSessions) { + TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS, true); } TEST_P(QuicStreamFactoryTest, - MigrateSessionOnWriteErrorNonMigratableStreamAsync) { - TestMigrationOnWriteErrorNonMigratableStream(ASYNC); + MigrateSessionOnWriteErrorNonMigratableStreamAsync_MigrateIdleSessions) { + TestMigrationOnWriteErrorNonMigratableStream(ASYNC, true); } void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( @@ -7174,8 +7476,242 @@ void QuicStreamFactoryTestBase:: EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); } +// This test verifies after session migrates off the default network, it keeps +// retrying migrate back to the default network until successfully gets on the +// default network or the idle migration period threshold is exceeded. +// The default threshold is 30s. +TEST_P(QuicStreamFactoryTest, DefaultIdleMigrationPeriod) { + test_params_.quic_migrate_idle_sessions = true; + InitializeConnectionMigrationV2Test( + {kDefaultNetworkForTests, kNewNetworkForTests}); + ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); + crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); + + // Using a testing task runner and a test tick tock. + auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); + QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); + QuicStreamFactoryPeer::SetTickClock(factory_.get(), + task_runner->GetMockTickClock()); + + MockQuicData default_socket_data; + default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); + default_socket_data.AddSocketDataToFactory(socket_factory_.get()); + + // Set up second socket data provider that is used after migration. + MockQuicData alternate_socket_data; + alternate_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + // Ping packet to send after migration. + alternate_socket_data.AddWrite( + SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); + alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); + + // Set up probing socket for migrating back to the default network. + MockQuicData quic_data; // retry count: 0. + quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data1; // retry count: 1 + quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data1.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data1.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data2; // retry count: 2 + quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data2.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data2.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data3; // retry count: 3 + quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data3.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data3.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data4; // retry count: 4 + quic_data4.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data4.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data4.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data5; // retry count: 5 + quic_data5.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data5.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data5.AddSocketDataToFactory(socket_factory_.get()); + + // Create request and QuicHttpStream. + QuicStreamRequest request(factory_.get()); + EXPECT_EQ(ERR_IO_PENDING, + request.Request( + host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, + SocketTag(), + /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, + failed_on_default_network_callback_, callback_.callback())); + EXPECT_THAT(callback_.WaitForResult(), IsOk()); + std::unique_ptr<HttpStream> stream = CreateStream(&request); + EXPECT_TRUE(stream.get()); + + // Ensure that session is active. + EXPECT_TRUE(HasActiveSession(host_port_pair_)); + + // Trigger connection migration. Since there are no active streams, + // the session will be closed. + scoped_mock_network_change_notifier_->mock_network_change_notifier() + ->NotifyNetworkDisconnected(kDefaultNetworkForTests); + + // The nearest task will complete migration. + EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(base::TimeDelta()); + + // The migrate back timer will fire. Due to default network + // being disconnected, no attempt will be exercised to migrate back. + EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), + task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); + EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); + + // Deliver the signal that the old default network now backs up. + scoped_mock_network_change_notifier_->mock_network_change_notifier() + ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); + + // A task is posted to migrate back to the default network immediately. + EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(base::TimeDelta()); + + // Retry migrate back in 1, 2, 4, 8, 16s. + // Session will be closed due to idle migration timeout. + for (int i = 0; i < 5; i++) { + EXPECT_TRUE(HasActiveSession(host_port_pair_)); + // A task is posted to migrate back to the default network in 2^i seconds. + EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta::FromSeconds(UINT64_C(1) << i), + task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); + } + + EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); + EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); +} + +TEST_P(QuicStreamFactoryTest, CustomIdleMigrationPeriod) { + // The customized threshold is 15s. + test_params_.quic_migrate_idle_sessions = true; + test_params_.quic_idle_session_migration_period = + base::TimeDelta::FromSeconds(15); + InitializeConnectionMigrationV2Test( + {kDefaultNetworkForTests, kNewNetworkForTests}); + ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); + crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); + + // Using a testing task runner and a test tick tock. + auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); + QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); + QuicStreamFactoryPeer::SetTickClock(factory_.get(), + task_runner->GetMockTickClock()); + + MockQuicData default_socket_data; + default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); + default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); + default_socket_data.AddSocketDataToFactory(socket_factory_.get()); + + // Set up second socket data provider that is used after migration. + MockQuicData alternate_socket_data; + alternate_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + // Ping packet to send after migration. + alternate_socket_data.AddWrite( + SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); + alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); + + // Set up probing socket for migrating back to the default network. + MockQuicData quic_data; // retry count: 0. + quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data1; // retry count: 1 + quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data1.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data1.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data2; // retry count: 2 + quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data2.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data2.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data3; // retry count: 3 + quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data3.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data3.AddSocketDataToFactory(socket_factory_.get()); + + MockQuicData quic_data4; // retry count: 4 + quic_data4.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. + quic_data4.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); + quic_data4.AddSocketDataToFactory(socket_factory_.get()); + + // Create request and QuicHttpStream. + QuicStreamRequest request(factory_.get()); + EXPECT_EQ(ERR_IO_PENDING, + request.Request( + host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, + SocketTag(), + /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, + failed_on_default_network_callback_, callback_.callback())); + EXPECT_THAT(callback_.WaitForResult(), IsOk()); + std::unique_ptr<HttpStream> stream = CreateStream(&request); + EXPECT_TRUE(stream.get()); + + // Ensure that session is active. + EXPECT_TRUE(HasActiveSession(host_port_pair_)); + + // Trigger connection migration. Since there are no active streams, + // the session will be closed. + scoped_mock_network_change_notifier_->mock_network_change_notifier() + ->NotifyNetworkDisconnected(kDefaultNetworkForTests); + + // The nearest task will complete migration. + EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(base::TimeDelta()); + + // The migrate back timer will fire. Due to default network + // being disconnected, no attempt will be exercised to migrate back. + EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), + task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); + EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); + + // Deliver the signal that the old default network now backs up. + scoped_mock_network_change_notifier_->mock_network_change_notifier() + ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); + + // A task is posted to migrate back to the default network immediately. + EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(base::TimeDelta()); + + // Retry migrate back in 1, 2, 4, 8s. + // Session will be closed due to idle migration timeout. + for (int i = 0; i < 4; i++) { + EXPECT_TRUE(HasActiveSession(host_port_pair_)); + // A task is posted to migrate back to the default network in 2^i seconds. + EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); + EXPECT_EQ(base::TimeDelta::FromSeconds(UINT64_C(1) << i), + task_runner->NextPendingTaskDelay()); + task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); + } + + EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); + EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); + EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); +} + TEST_P(QuicStreamFactoryTest, ServerMigration) { - allow_server_migration_ = true; + test_params_.quic_allow_server_migration = true; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -7316,7 +7852,7 @@ TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { } TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { - allow_server_migration_ = true; + test_params_.quic_allow_server_migration = true; Initialize(); // Add a resolver rule to make initial connection to an IPv4 address. @@ -7387,70 +7923,6 @@ TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); } -TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { - Initialize(); - ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); - crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); - crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); - - MockQuicData socket_data; - socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); - socket_data.AddWrite( - SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); - socket_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( - 3, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); - socket_data.AddSocketDataToFactory(socket_factory_.get()); - - MockQuicData socket_data2; - socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - socket_data2.AddWrite(SYNCHRONOUS, - ConstructInitialSettingsPacket(1, nullptr)); - socket_data2.AddSocketDataToFactory(socket_factory_.get()); - - QuicStreamRequest request(factory_.get()); - EXPECT_EQ(ERR_IO_PENDING, - request.Request( - host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, - SocketTag(), - /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, - failed_on_default_network_callback_, callback_.callback())); - - EXPECT_THAT(callback_.WaitForResult(), IsOk()); - std::unique_ptr<HttpStream> stream = CreateStream(&request); - HttpRequestInfo request_info; - request_info.traffic_annotation = - MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); - EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, - net_log_, CompletionOnceCallback())); - - ssl_config_service_->NotifySSLConfigChange(); - EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, - stream->ReadResponseHeaders(callback_.callback())); - EXPECT_FALSE(factory_->require_confirmation()); - - // Now attempting to request a stream to the same origin should create - // a new session. - - QuicStreamRequest request2(factory_.get()); - EXPECT_EQ(ERR_IO_PENDING, - request2.Request( - host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, - SocketTag(), - /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, - failed_on_default_network_callback_, callback_.callback())); - - EXPECT_THAT(callback_.WaitForResult(), IsOk()); - stream = CreateStream(&request2); - stream.reset(); // Will reset stream 3. - - EXPECT_TRUE(socket_data.AllReadDataConsumed()); - EXPECT_TRUE(socket_data.AllWriteDataConsumed()); - EXPECT_TRUE(socket_data2.AllReadDataConsumed()); - EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); -} - TEST_P(QuicStreamFactoryTest, OnCertDBChanged) { Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -7630,7 +8102,7 @@ TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) { } TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { - reduced_ping_timeout_seconds_ = 10; + test_params_.quic_reduced_ping_timeout_seconds = 10; Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); @@ -7804,7 +8276,7 @@ TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); MockQuicData socket_data; - socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(0)); + socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); socket_data.AddRead(ASYNC, OK); socket_data.AddSocketDataToFactory(socket_factory_.get()); @@ -7853,7 +8325,7 @@ TEST_P(QuicStreamFactoryTest, YieldAfterDuration) { factory_.get(), quic::QuicTime::Delta::FromMilliseconds(-1)); MockQuicData socket_data; - socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(0)); + socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); socket_data.AddRead(ASYNC, OK); socket_data.AddSocketDataToFactory(socket_factory_.get()); @@ -8110,9 +8582,9 @@ class QuicStreamFactoryWithDestinationTest sequenced_socket_data_vector_; }; -INSTANTIATE_TEST_CASE_P(VersionIncludeStreamDependencySequence, - QuicStreamFactoryWithDestinationTest, - ::testing::ValuesIn(GetPoolingTestParams())); +INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, + QuicStreamFactoryWithDestinationTest, + ::testing::ValuesIn(GetPoolingTestParams())); // A single QUIC request fails because the certificate does not match the origin // hostname, regardless of whether it matches the alternative service hostname. @@ -8447,18 +8919,19 @@ TEST_P(QuicStreamFactoryTest, ClearCachedStatesInCryptoConfig) { // Passes connection options and client connection options to QuicStreamFactory, // then checks that its internal quic::QuicConfig is correct. TEST_P(QuicStreamFactoryTest, ConfigConnectionOptions) { - connection_options_.push_back(quic::kTIME); - connection_options_.push_back(quic::kTBBR); - connection_options_.push_back(quic::kREJ); + test_params_.quic_connection_options.push_back(quic::kTIME); + test_params_.quic_connection_options.push_back(quic::kTBBR); + test_params_.quic_connection_options.push_back(quic::kREJ); - client_connection_options_.push_back(quic::kTBBR); - client_connection_options_.push_back(quic::k1RTT); + test_params_.quic_client_connection_options.push_back(quic::kTBBR); + test_params_.quic_client_connection_options.push_back(quic::k1RTT); Initialize(); const quic::QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); - EXPECT_EQ(connection_options_, config->SendConnectionOptions()); + EXPECT_EQ(test_params_.quic_connection_options, + config->SendConnectionOptions()); EXPECT_TRUE(config->HasClientRequestedIndependentOption( quic::kTBBR, quic::Perspective::IS_CLIENT)); EXPECT_TRUE(config->HasClientRequestedIndependentOption( @@ -8531,13 +9004,12 @@ TEST_P(QuicStreamFactoryTest, HostResolverRequestReprioritizedOnSetPriority) { EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); } -// Passes |max_time_before_crypto_handshake_seconds| and -// |max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, then +// Passes |quic_max_time_before_crypto_handshake_seconds| and +// |quic_max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, // checks that its internal quic::QuicConfig is correct. TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { - max_time_before_crypto_handshake_seconds_ = 11; - max_idle_time_before_crypto_handshake_seconds_ = 13; - + test_params_.quic_max_time_before_crypto_handshake_seconds = 11; + test_params_.quic_max_idle_time_before_crypto_handshake_seconds = 13; Initialize(); const quic::QuicConfig* config = @@ -8792,7 +9264,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { // the final connection is established through the resolved DNS. No racing // connection. TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -8841,7 +9313,6 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { // host resolver, connection should be successful and through resolved DNS. No // racing connection. TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { - race_stale_dns_on_connection_ = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -8890,7 +9361,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { // With dns race experiment on, DNS resolve returns async, stale dns used, // connects synchrounously, and then the resolved DNS matches. TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -8949,7 +9420,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { // async, and then the result matches. TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9017,7 +9488,7 @@ TEST_P(QuicStreamFactoryTest, // return, then connection finishes and matches with the result. TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9081,7 +9552,7 @@ TEST_P(QuicStreamFactoryTest, // sync, but dns no match TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9108,8 +9579,9 @@ TEST_P(QuicStreamFactoryTest, quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); quic_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( - 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); + SYNCHRONOUS, + client_maker_.MakeConnectionClosePacket( + 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); quic_data.AddSocketDataToFactory(socket_factory_.get()); // Socket for the new connection. @@ -9152,7 +9624,7 @@ TEST_P(QuicStreamFactoryTest, // With dns race experiment on, dns resolve async, stale used and connects // async, finishes before dns, but no match TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9181,8 +9653,9 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); quic_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( - 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); + SYNCHRONOUS, + client_maker_.MakeConnectionClosePacket( + 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); quic_data.AddSocketDataToFactory(socket_factory_.get()); MockQuicData quic_data2; @@ -9225,7 +9698,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { // With dns race experiment on, dns resolve async, stale used and connects // async, dns finishes first, but no match TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9252,10 +9725,11 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { MockQuicData quic_data; quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( - 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); + SYNCHRONOUS, + client_maker_.MakeConnectionClosePacket( + 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); quic_data.AddSocketDataToFactory(socket_factory_.get()); MockQuicData quic_data2; @@ -9295,7 +9769,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { // With dns race experiment on, dns resolve returns error sync, same behavior // as experiment is not on TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9320,7 +9794,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { // With dns race experiment on, no cache available, dns resolve returns error // async TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9349,7 +9823,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { // With dns race experiment on, dns resolve async, staled used and connects // sync, dns returns error and no connection is established. TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9375,8 +9849,9 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); quic_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( - 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); + SYNCHRONOUS, + client_maker_.MakeConnectionClosePacket( + 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); quic_data.AddSocketDataToFactory(socket_factory_.get()); QuicStreamRequest request(factory_.get()); @@ -9402,7 +9877,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { // With dns race experiment on, dns resolve async, stale used and connection // return error, then dns matches TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9450,7 +9925,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { // With dns race experiment on, dns resolve async, stale used and connection // returns error, dns no match, new connection is established TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9514,7 +9989,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { // With dns race experiment on, dns resolve async, stale used and connection // returns error, dns no match, new connection error TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9566,7 +10041,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { // With dns race experiment on, dns resolve async and stale connect async, dns // resolve returns error and then preconnect finishes TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9593,10 +10068,11 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { // Socket data for stale connection which is supposed to disconnect. MockQuicData quic_data; quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( - 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); + SYNCHRONOUS, + client_maker_.MakeConnectionClosePacket( + 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); quic_data.AddSocketDataToFactory(socket_factory_.get()); QuicStreamRequest request(factory_.get()); @@ -9619,7 +10095,7 @@ TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { // resolve returns error and then preconnect fails. TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); @@ -9645,10 +10121,11 @@ TEST_P(QuicStreamFactoryTest, MockQuicData quic_data; quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); - client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); + client_maker_.SetEncryptionLevel(quic::ENCRYPTION_ZERO_RTT); quic_data.AddWrite( - SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( - 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); + SYNCHRONOUS, + client_maker_.MakeConnectionClosePacket( + 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); quic_data.AddSocketDataToFactory(socket_factory_.get()); QuicStreamRequest request(factory_.get()); @@ -9671,7 +10148,7 @@ TEST_P(QuicStreamFactoryTest, // With dns race experiment on, test that host resolution callback behaves // normal as experiment is not on TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { - race_stale_dns_on_connection_ = true; + test_params_.quic_race_stale_dns_on_connection = true; host_resolver_ = std::make_unique<MockCachingHostResolver>(); Initialize(); ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); diff --git a/chromium/net/quic/quic_test_packet_maker.cc b/chromium/net/quic/quic_test_packet_maker.cc index 09c2c44f853..52ae592b1d4 100644 --- a/chromium/net/quic/quic_test_packet_maker.cc +++ b/chromium/net/quic/quic_test_packet_maker.cc @@ -13,14 +13,15 @@ #include "net/third_party/quic/core/quic_utils.h" #include "net/third_party/quic/test_tools/mock_random.h" #include "net/third_party/quic/test_tools/quic_test_utils.h" +#include "net/third_party/quic/test_tools/simple_data_producer.h" namespace net { namespace test { namespace { -quic::QuicAckFrame MakeAckFrame(quic::QuicPacketNumber largest_observed) { +quic::QuicAckFrame MakeAckFrame(uint64_t largest_observed) { quic::QuicAckFrame ack; - ack.largest_acked = largest_observed; + ack.largest_acked = quic::QuicPacketNumber(largest_observed); return ack; } @@ -41,7 +42,7 @@ QuicTestPacketMaker::QuicTestPacketMaker( spdy_response_framer_(spdy::SpdyFramer::ENABLE_COMPRESSION), perspective_(perspective), encryption_level_(quic::ENCRYPTION_FORWARD_SECURE), - long_header_type_(quic::HANDSHAKE), + long_header_type_(quic::INVALID_PACKET_TYPE), client_headers_include_h2_stream_dependency_( client_headers_include_h2_stream_dependency && version >= quic::QUIC_VERSION_43) { @@ -56,18 +57,25 @@ void QuicTestPacketMaker::set_hostname(const std::string& host) { } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeConnectivityProbingPacket(quic::QuicPacketNumber num, +QuicTestPacketMaker::MakeConnectivityProbingPacket(uint64_t num, bool include_version) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicFramer framer(quic::test::SupportedVersions(quic::ParsedQuicVersion( quic::PROTOCOL_QUIC_CRYPTO, version_)), @@ -77,20 +85,20 @@ QuicTestPacketMaker::MakeConnectivityProbingPacket(quic::QuicPacketNumber num, char buffer[quic::kDefaultMaxPacketSize]; size_t length; if (version_ != quic::QUIC_VERSION_99) { - length = framer.BuildConnectivityProbingPacket(header, buffer, - max_plaintext_size); + length = framer.BuildConnectivityProbingPacket( + header, buffer, max_plaintext_size, encryption_level_); } else if (perspective_ == quic::Perspective::IS_CLIENT) { quic::test::MockRandom rand(0); quic::QuicPathFrameBuffer payload; length = framer.BuildPaddedPathChallengePacket( - header, buffer, max_plaintext_size, &payload, &rand); + header, buffer, max_plaintext_size, &payload, &rand, encryption_level_); } else { quic::test::MockRandom rand(0); quic::QuicPathFrameBuffer payload; rand.RandBytes(payload.data(), payload.size()); quic::QuicDeque<quic::QuicPathFrameBuffer> payloads{payload}; length = framer.BuildPathResponsePacket(header, buffer, max_plaintext_size, - payloads, true); + payloads, true, encryption_level_); } size_t encrypted_size = framer.EncryptInPlace( quic::ENCRYPTION_NONE, header.packet_number, @@ -103,27 +111,33 @@ QuicTestPacketMaker::MakeConnectivityProbingPacket(quic::QuicPacketNumber num, } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakePingPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicPingFrame ping; return MakePacket(header, quic::QuicFrame(ping)); } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeDummyCHLOPacket(quic::QuicPacketNumber packet_num) { - encryption_level_ = quic::ENCRYPTION_NONE; - SetLongHeaderType(quic::INITIAL); +QuicTestPacketMaker::MakeDummyCHLOPacket(uint64_t packet_num) { + SetEncryptionLevel(quic::ENCRYPTION_NONE); InitializeHeader(packet_num, /*include_version=*/true); quic::CryptoHandshakeMessage message = @@ -131,86 +145,108 @@ QuicTestPacketMaker::MakeDummyCHLOPacket(quic::QuicPacketNumber packet_num) { const quic::QuicData& data = message.GetSerialized(); quic::QuicFrames frames; - quic::QuicStreamFrame frame( - quic::QuicUtils::GetCryptoStreamId(version_), /*fin=*/false, /*offset=*/0, - quic::QuicStringPiece(data.data(), data.length())); - frames.push_back(quic::QuicFrame(frame)); + quic::QuicCryptoFrame crypto_frame; + quic::test::SimpleDataProducer producer; + quic::QuicStreamFrameDataProducer* producer_p = nullptr; + if (version_ < quic::QUIC_VERSION_47) { + quic::QuicStreamFrame frame(quic::QuicUtils::GetCryptoStreamId(version_), + /*fin=*/false, /*offset=*/0, + data.AsStringPiece()); + frames.push_back(quic::QuicFrame(frame)); + } else { + crypto_frame = + quic::QuicCryptoFrame(quic::ENCRYPTION_NONE, 0, data.length()); + producer.SaveCryptoData(quic::ENCRYPTION_NONE, 0, data.AsStringPiece()); + frames.push_back(quic::QuicFrame(&crypto_frame)); + producer_p = &producer; + } DVLOG(1) << "Adding frame: " << frames.back(); quic::QuicPaddingFrame padding; frames.push_back(quic::QuicFrame(padding)); DVLOG(1) << "Adding frame: " << frames.back(); - return MakeMultipleFramesPacket(header_, frames); + std::unique_ptr<quic::QuicReceivedPacket> packet = + MakeMultipleFramesPacket(header_, frames, producer_p); + return packet; } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeAckAndPingPacket( - quic::QuicPacketNumber num, - bool include_version, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked) { +QuicTestPacketMaker::MakeAckAndPingPacket(uint64_t num, + bool include_version, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = quic::QuicTime::Delta::Zero(); - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { - ack.packets.AddRange(1, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(1), + quic::QuicPacketNumber(largest_received + 1)); } quic::QuicFrames frames; frames.push_back(quic::QuicFrame(&ack)); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - frames.push_back(quic::QuicFrame(quic::QuicPingFrame())); DVLOG(1) << "Adding frame: " << frames.back(); - return MakeMultipleFramesPacket(header, frames); + return MakeMultipleFramesPacket(header, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code) { - return MakeRstPacket(num, include_version, stream_id, error_code, 0); + return MakeRstPacket(num, include_version, stream_id, error_code, 0, + /*include_stop_sending_if_v99=*/true); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, - size_t bytes_written) { + size_t bytes_written, + bool include_stop_sending_if_v99) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicFrames frames; @@ -221,27 +257,34 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRstPacket( // The STOP_SENDING frame must be outside of the if (version==99) so that it // stays in scope until the packet is built. quic::QuicStopSendingFrame stop(1, stream_id, error_code); - if (version_ == quic::QUIC_VERSION_99) { + if (include_stop_sending_if_v99 && version_ == quic::QUIC_VERSION_99) { frames.push_back(quic::QuicFrame(&stop)); DVLOG(1) << "Adding frame: " << frames.back(); } - return MakeMultipleFramesPacket(header, frames); + return MakeMultipleFramesPacket(header, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeStreamIdBlockedPacket(quic::QuicPacketNumber num, +QuicTestPacketMaker::MakeStreamIdBlockedPacket(uint64_t num, bool include_version, quic::QuicStreamId stream_id) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicStreamIdBlockedFrame frame(1, stream_id); DVLOG(1) << "Adding frame: " << quic::QuicFrame(frame); @@ -249,19 +292,26 @@ QuicTestPacketMaker::MakeStreamIdBlockedPacket(quic::QuicPacketNumber num, } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeMaxStreamIdPacket(quic::QuicPacketNumber num, +QuicTestPacketMaker::MakeMaxStreamIdPacket(uint64_t num, bool include_version, quic::QuicStreamId stream_id) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicMaxStreamIdFrame frame(1, stream_id); DVLOG(1) << "Adding frame: " << quic::QuicFrame(frame); @@ -270,7 +320,7 @@ QuicTestPacketMaker::MakeMaxStreamIdPacket(quic::QuicPacketNumber num, std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRstAndRequestHeadersPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId rst_stream_id, quic::QuicRstStreamErrorCode rst_error_code, @@ -312,66 +362,69 @@ QuicTestPacketMaker::MakeRstAndRequestHeadersPacket( DVLOG(1) << "Adding frame: " << frames.back(); InitializeHeader(num, include_version); - return MakeMultipleFramesPacket(header_, frames); + return MakeMultipleFramesPacket(header_, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckAndRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback) { return MakeAckAndRstPacket(num, include_version, stream_id, error_code, largest_received, smallest_received, least_unacked, - send_feedback, 0); + send_feedback, 0, + /*include_stop_sending_if_v99=*/true); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckAndRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback, - size_t bytes_written) { + size_t bytes_written, + bool include_stop_sending_if_v99) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = quic::QuicTime::Delta::Zero(); - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { - ack.packets.AddRange(1, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(1), + quic::QuicPacketNumber(largest_received + 1)); } quic::QuicFrames frames; frames.push_back(quic::QuicFrame(&ack)); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - quic::QuicRstStreamFrame rst(1, stream_id, error_code, bytes_written); frames.push_back(quic::QuicFrame(&rst)); DVLOG(1) << "Adding frame: " << frames.back(); @@ -379,36 +432,43 @@ QuicTestPacketMaker::MakeAckAndRstPacket( // The STOP_SENDING frame must be outside of the if (version==99) so that it // stays in scope until the packet is built. quic::QuicStopSendingFrame stop(1, stream_id, error_code); - if (version_ == quic::QUIC_VERSION_99) { + if (version_ == quic::QUIC_VERSION_99 && include_stop_sending_if_v99) { frames.push_back(quic::QuicFrame(&stop)); DVLOG(1) << "Adding frame: " << frames.back(); } - return MakeMultipleFramesPacket(header, frames); + return MakeMultipleFramesPacket(header, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRstAckAndConnectionClosePacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, quic::QuicTime::Delta ack_delay_time, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicErrorCode quic_error, const std::string& quic_error_details) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicFrames frames; quic::QuicRstStreamFrame rst(1, stream_id, error_code, 0); @@ -426,23 +486,17 @@ QuicTestPacketMaker::MakeRstAckAndConnectionClosePacket( quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = ack_delay_time; - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { - ack.packets.AddRange(1, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(1), + quic::QuicPacketNumber(largest_received + 1)); } frames.push_back(quic::QuicFrame(&ack)); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - quic::QuicConnectionCloseFrame close; close.error_code = quic_error; close.error_details = quic_error_details; @@ -450,50 +504,51 @@ QuicTestPacketMaker::MakeRstAckAndConnectionClosePacket( frames.push_back(quic::QuicFrame(&close)); DVLOG(1) << "Adding frame: " << frames.back(); - return MakeMultipleFramesPacket(header, frames); + return MakeMultipleFramesPacket(header, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckAndConnectionClosePacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicTime::Delta ack_delay_time, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicErrorCode quic_error, const std::string& quic_error_details) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = ack_delay_time; - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { - ack.packets.AddRange(1, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(1), + quic::QuicPacketNumber(largest_received + 1)); } quic::QuicFrames frames; frames.push_back(quic::QuicFrame(&ack)); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - quic::QuicConnectionCloseFrame close; close.error_code = quic_error; close.error_details = quic_error_details; @@ -501,25 +556,32 @@ QuicTestPacketMaker::MakeAckAndConnectionClosePacket( frames.push_back(quic::QuicFrame(&close)); DVLOG(1) << "Adding frame: " << frames.back(); - return MakeMultipleFramesPacket(header, frames); + return MakeMultipleFramesPacket(header, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeConnectionClosePacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicErrorCode quic_error, const std::string& quic_error_details) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(include_version); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicConnectionCloseFrame close; close.error_code = quic_error; @@ -528,19 +590,26 @@ QuicTestPacketMaker::MakeConnectionClosePacket( } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeGoAwayPacket( - quic::QuicPacketNumber num, + uint64_t num, quic::QuicErrorCode error_code, std::string reason_phrase) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(false); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = num; + header.packet_number = quic::QuicPacketNumber(num); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicGoAwayFrame goaway; goaway.error_code = error_code; @@ -550,10 +619,10 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeGoAwayPacket( } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback) { return MakeAckPacket(packet_number, 1, largest_received, smallest_received, least_unacked, send_feedback, @@ -561,11 +630,11 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber first_received, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t first_received, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback) { return MakeAckPacket(packet_number, first_received, largest_received, smallest_received, least_unacked, send_feedback, @@ -573,10 +642,10 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback, quic::QuicTime::Delta ack_delay_time) { return MakeAckPacket(packet_number, 1, largest_received, smallest_received, @@ -584,33 +653,41 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber first_received, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t first_received, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback, quic::QuicTime::Delta ack_delay_time) { quic::QuicPacketHeader header; header.destination_connection_id = connection_id_; - header.destination_connection_id_length = GetDestinationConnectionIdLength(); + header.destination_connection_id_included = HasDestinationConnectionId(); header.source_connection_id = connection_id_; - header.source_connection_id_length = GetSourceConnectionIdLength(); + header.source_connection_id_included = HasSourceConnectionId(); header.reset_flag = false; header.version_flag = ShouldIncludeVersion(false); header.long_packet_type = long_header_type_; header.packet_number_length = GetPacketNumberLength(); - header.packet_number = packet_number; + header.packet_number = quic::QuicPacketNumber(packet_number); + + if (quic::QuicVersionHasLongHeaderLengths(version_) && header.version_flag) { + if (long_header_type_ == quic::INITIAL) { + header.retry_token_length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = ack_delay_time; - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { DCHECK_GE(largest_received, first_received); - ack.packets.AddRange(first_received, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(first_received), + quic::QuicPacketNumber(largest_received + 1)); } quic::QuicFramer framer(quic::test::SupportedVersions(quic::ParsedQuicVersion( quic::PROTOCOL_QUIC_CRYPTO, version_)), @@ -620,13 +697,6 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( frames.push_back(ack_frame); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - std::unique_ptr<quic::QuicPacket> packet( quic::test::BuildUnsizedDataPacket(&framer, header, frames)); char buffer[quic::kMaxPacketSize]; @@ -641,7 +711,7 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckPacket( // Returns a newly created packet to send kData on stream 1. std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -655,7 +725,7 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeDataPacket( std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -671,57 +741,50 @@ QuicTestPacketMaker::MakeMultipleDataFramesPacket( data_frames.push_back(quic_frame); offset += data_writes[i].length(); } - return MakeMultipleFramesPacket(header_, data_frames); + return MakeMultipleFramesPacket(header_, data_frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeAckAndDataPacket( - quic::QuicPacketNumber packet_number, - bool include_version, - quic::QuicStreamId stream_id, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, - bool fin, - quic::QuicStreamOffset offset, - quic::QuicStringPiece data) { +QuicTestPacketMaker::MakeAckAndDataPacket(uint64_t packet_number, + bool include_version, + quic::QuicStreamId stream_id, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, + bool fin, + quic::QuicStreamOffset offset, + quic::QuicStringPiece data) { InitializeHeader(packet_number, include_version); quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = quic::QuicTime::Delta::Zero(); - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { - ack.packets.AddRange(1, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(1), + quic::QuicPacketNumber(largest_received + 1)); } quic::QuicFrames frames; frames.push_back(quic::QuicFrame(&ack)); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - frames.push_back( quic::QuicFrame(quic::QuicStreamFrame(stream_id, fin, offset, data))); DVLOG(1) << "Adding frame: " << frames.back(); - return MakeMultipleFramesPacket(header_, frames); + return MakeMultipleFramesPacket(header_, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool include_version, quic::QuicStreamId stream_id, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool fin, quic::QuicStreamOffset offset, const std::vector<std::string>& data_writes) { @@ -729,24 +792,18 @@ QuicTestPacketMaker::MakeAckAndMultipleDataFramesPacket( quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = quic::QuicTime::Delta::Zero(); - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { - ack.packets.AddRange(1, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(1), + quic::QuicPacketNumber(largest_received + 1)); } quic::QuicFrames frames; frames.push_back(quic::QuicFrame(&ack)); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - for (size_t i = 0; i < data_writes.size(); ++i) { bool is_fin = fin && (i == data_writes.size() - 1); quic::QuicFrame quic_frame(quic::QuicStreamFrame( @@ -755,12 +812,12 @@ QuicTestPacketMaker::MakeAckAndMultipleDataFramesPacket( frames.push_back(quic_frame); offset += data_writes[i].length(); } - return MakeMultipleFramesPacket(header_, frames); + return MakeMultipleFramesPacket(header_, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRequestHeadersAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -802,12 +859,12 @@ QuicTestPacketMaker::MakeRequestHeadersAndMultipleDataFramesPacket( frames.push_back(quic_frame); offset += data_writes[i].length(); } - return MakeMultipleFramesPacket(header_, frames); + return MakeMultipleFramesPacket(header_, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -824,7 +881,7 @@ QuicTestPacketMaker::MakeRequestHeadersPacket( // Will also update the value after packet creation. std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -842,7 +899,7 @@ QuicTestPacketMaker::MakeRequestHeadersPacket( std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRequestHeadersPacketAndSaveData( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -877,7 +934,7 @@ QuicTestPacketMaker::MakeRequestHeadersPacketAndSaveData( std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRequestHeadersAndRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -919,7 +976,7 @@ QuicTestPacketMaker::MakeRequestHeadersAndRstPacket( } InitializeHeader(packet_number, should_include_version); - return MakeMultipleFramesPacket(header_, frames); + return MakeMultipleFramesPacket(header_, frames, nullptr); } spdy::SpdySerializedFrame QuicTestPacketMaker::MakeSpdyHeadersFrame( @@ -948,7 +1005,7 @@ spdy::SpdySerializedFrame QuicTestPacketMaker::MakeSpdyHeadersFrame( // |spdy_headers_frame_length|. std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeRequestHeadersPacketWithOffsetTracking( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -965,7 +1022,7 @@ QuicTestPacketMaker::MakeRequestHeadersPacketWithOffsetTracking( // Will also update the value after packet creation. std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakePushPromisePacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, quic::QuicStreamId promised_stream_id, bool should_include_version, @@ -997,13 +1054,12 @@ QuicTestPacketMaker::MakePushPromisePacket( } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeForceHolDataPacket( - quic::QuicPacketNumber packet_number, - quic::QuicStreamId stream_id, - bool should_include_version, - bool fin, - quic::QuicStreamOffset* offset, - quic::QuicStringPiece data) { +QuicTestPacketMaker::MakeForceHolDataPacket(uint64_t packet_number, + quic::QuicStreamId stream_id, + bool should_include_version, + bool fin, + quic::QuicStreamOffset* offset, + quic::QuicStringPiece data) { spdy::SpdyDataIR spdy_data(stream_id, data); spdy_data.set_fin(fin); spdy::SpdySerializedFrame spdy_frame( @@ -1020,7 +1076,7 @@ QuicTestPacketMaker::MakeForceHolDataPacket( // Will also update the value after packet creation. std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeResponseHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -1052,7 +1108,7 @@ QuicTestPacketMaker::MakeResponseHeadersPacket( std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeResponseHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -1067,7 +1123,7 @@ QuicTestPacketMaker::MakeResponseHeadersPacket( // |spdy_headers_frame_length|. std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeResponseHeadersPacketWithOffsetTracking( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -1121,16 +1177,20 @@ std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakePacket( const quic::QuicFrame& frame) { quic::QuicFrames frames; frames.push_back(frame); - return MakeMultipleFramesPacket(header, frames); + return MakeMultipleFramesPacket(header, frames, nullptr); } std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeMultipleFramesPacket( const quic::QuicPacketHeader& header, - const quic::QuicFrames& frames) { + const quic::QuicFrames& frames, + quic::QuicStreamFrameDataProducer* data_producer) { quic::QuicFramer framer(quic::test::SupportedVersions(quic::ParsedQuicVersion( quic::PROTOCOL_QUIC_CRYPTO, version_)), clock_->Now(), perspective_); + if (data_producer != nullptr) { + framer.set_data_producer(data_producer); + } size_t max_plaintext_size = framer.GetMaxPlaintextSize(quic::kDefaultMaxPacketSize); std::unique_ptr<quic::QuicPacket> packet(quic::test::BuildUnsizedDataPacket( @@ -1145,23 +1205,30 @@ QuicTestPacketMaker::MakeMultipleFramesPacket( return encrypted.Clone(); } -void QuicTestPacketMaker::InitializeHeader(quic::QuicPacketNumber packet_number, +void QuicTestPacketMaker::InitializeHeader(uint64_t packet_number, bool should_include_version) { header_.destination_connection_id = connection_id_; - header_.destination_connection_id_length = GetDestinationConnectionIdLength(); + header_.destination_connection_id_included = HasDestinationConnectionId(); header_.source_connection_id = connection_id_; - header_.source_connection_id_length = GetSourceConnectionIdLength(); + header_.source_connection_id_included = HasSourceConnectionId(); header_.reset_flag = false; header_.version_flag = ShouldIncludeVersion(should_include_version); header_.long_packet_type = long_header_type_; header_.packet_number_length = GetPacketNumberLength(); - header_.packet_number = packet_number; + header_.packet_number = quic::QuicPacketNumber(packet_number); + if (quic::QuicVersionHasLongHeaderLengths(version_) && + should_include_version) { + if (long_header_type_ == quic::INITIAL) { + header_.retry_token_length_length = + quic::VARIABLE_LENGTH_INTEGER_LENGTH_1; + } + header_.length_length = quic::VARIABLE_LENGTH_INTEGER_LENGTH_2; + } } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakeInitialSettingsPacket( - quic::QuicPacketNumber packet_number, - quic::QuicStreamOffset* offset) { +QuicTestPacketMaker::MakeInitialSettingsPacket(uint64_t packet_number, + quic::QuicStreamOffset* offset) { std::string unused_data; return MakeInitialSettingsPacketAndSaveData(packet_number, offset, &unused_data); @@ -1169,7 +1236,7 @@ QuicTestPacketMaker::MakeInitialSettingsPacket( std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeInitialSettingsPacketAndSaveData( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset* offset, std::string* stream_data) { spdy::SpdySettingsIR settings_frame; @@ -1193,7 +1260,7 @@ QuicTestPacketMaker::MakeInitialSettingsPacketAndSaveData( } std::unique_ptr<quic::QuicReceivedPacket> -QuicTestPacketMaker::MakePriorityPacket(quic::QuicPacketNumber packet_number, +QuicTestPacketMaker::MakePriorityPacket(uint64_t packet_number, bool should_include_version, quic::QuicStreamId id, quic::QuicStreamId parent_stream_id, @@ -1223,33 +1290,27 @@ QuicTestPacketMaker::MakePriorityPacket(quic::QuicPacketNumber packet_number, std::unique_ptr<quic::QuicReceivedPacket> QuicTestPacketMaker::MakeAckAndMultiplePriorityFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, const std::vector<Http2StreamDependency>& priority_frames, quic::QuicStreamOffset* offset) { quic::QuicAckFrame ack(MakeAckFrame(largest_received)); ack.ack_delay_time = quic::QuicTime::Delta::Zero(); - for (quic::QuicPacketNumber i = smallest_received; i <= largest_received; - ++i) { - ack.received_packet_times.push_back(std::make_pair(i, clock_->Now())); + for (uint64_t i = smallest_received; i <= largest_received; ++i) { + ack.received_packet_times.push_back( + std::make_pair(quic::QuicPacketNumber(i), clock_->Now())); } if (largest_received > 0) { - ack.packets.AddRange(1, largest_received + 1); + ack.packets.AddRange(quic::QuicPacketNumber(1), + quic::QuicPacketNumber(largest_received + 1)); } quic::QuicFrames frames; frames.push_back(quic::QuicFrame(&ack)); DVLOG(1) << "Adding frame: " << frames.back(); - quic::QuicStopWaitingFrame stop_waiting; - if (version_ == quic::QUIC_VERSION_35) { - stop_waiting.least_unacked = least_unacked; - frames.push_back(quic::QuicFrame(&stop_waiting)); - DVLOG(1) << "Adding frame: " << frames.back(); - } - const bool exclusive = client_headers_include_h2_stream_dependency_; quic::QuicStreamOffset header_offset = 0; if (offset == nullptr) { @@ -1276,15 +1337,25 @@ QuicTestPacketMaker::MakeAckAndMultiplePriorityFramesPacket( } InitializeHeader(packet_number, should_include_version); - return MakeMultipleFramesPacket(header_, frames); + return MakeMultipleFramesPacket(header_, frames, nullptr); } void QuicTestPacketMaker::SetEncryptionLevel(quic::EncryptionLevel level) { encryption_level_ = level; -} - -void QuicTestPacketMaker::SetLongHeaderType(quic::QuicLongHeaderType type) { - long_header_type_ = type; + switch (level) { + case quic::ENCRYPTION_NONE: + long_header_type_ = quic::INITIAL; + break; + case quic::ENCRYPTION_ZERO_RTT: + long_header_type_ = quic::ZERO_RTT_PROTECTED; + break; + case quic::ENCRYPTION_FORWARD_SECURE: + long_header_type_ = quic::INVALID_PACKET_TYPE; + break; + default: + QUIC_BUG << quic::QuicUtils::EncryptionLevelToString(level); + long_header_type_ = quic::INVALID_PACKET_TYPE; + } } bool QuicTestPacketMaker::ShouldIncludeVersion(bool include_version) const { @@ -1304,23 +1375,23 @@ quic::QuicPacketNumberLength QuicTestPacketMaker::GetPacketNumberLength() return quic::PACKET_1BYTE_PACKET_NUMBER; } -quic::QuicConnectionIdLength -QuicTestPacketMaker::GetDestinationConnectionIdLength() const { +quic::QuicConnectionIdIncluded QuicTestPacketMaker::HasDestinationConnectionId() + const { if (perspective_ == quic::Perspective::IS_SERVER && version_ > quic::QUIC_VERSION_43) { - return quic::PACKET_0BYTE_CONNECTION_ID; + return quic::CONNECTION_ID_ABSENT; } - return quic::PACKET_8BYTE_CONNECTION_ID; + return quic::CONNECTION_ID_PRESENT; } -quic::QuicConnectionIdLength QuicTestPacketMaker::GetSourceConnectionIdLength() +quic::QuicConnectionIdIncluded QuicTestPacketMaker::HasSourceConnectionId() const { if (perspective_ == quic::Perspective::IS_SERVER && version_ > quic::QUIC_VERSION_43 && encryption_level_ < quic::ENCRYPTION_FORWARD_SECURE) { - return quic::PACKET_8BYTE_CONNECTION_ID; + return quic::CONNECTION_ID_PRESENT; } - return quic::PACKET_0BYTE_CONNECTION_ID; + return quic::CONNECTION_ID_ABSENT; } } // namespace test diff --git a/chromium/net/quic/quic_test_packet_maker.h b/chromium/net/quic/quic_test_packet_maker.h index 33b8d36526d..fe7bb3940f3 100644 --- a/chromium/net/quic/quic_test_packet_maker.h +++ b/chromium/net/quic/quic_test_packet_maker.h @@ -16,6 +16,7 @@ #include "base/macros.h" #include "net/base/request_priority.h" #include "net/third_party/quic/core/quic_packets.h" +#include "net/third_party/quic/core/quic_stream_frame_data_producer.h" #include "net/third_party/quic/platform/api/quic_string_piece.h" #include "net/third_party/quic/test_tools/mock_clock.h" #include "net/third_party/quic/test_tools/mock_random.h" @@ -49,45 +50,46 @@ class QuicTestPacketMaker { void set_hostname(const std::string& host); std::unique_ptr<quic::QuicReceivedPacket> MakeConnectivityProbingPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version); std::unique_ptr<quic::QuicReceivedPacket> MakePingPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version); std::unique_ptr<quic::QuicReceivedPacket> MakeDummyCHLOPacket( - quic::QuicPacketNumber packet_num); + uint64_t packet_num); std::unique_ptr<quic::QuicReceivedPacket> MakeAckAndPingPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked); + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked); std::unique_ptr<quic::QuicReceivedPacket> MakeStreamIdBlockedPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id); std::unique_ptr<quic::QuicReceivedPacket> MakeMaxStreamIdPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id); std::unique_ptr<quic::QuicReceivedPacket> MakeRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code); std::unique_ptr<quic::QuicReceivedPacket> MakeRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, - size_t bytes_written); + size_t bytes_written, + bool include_stop_sending_if_v99); std::unique_ptr<quic::QuicReceivedPacket> MakeRstAndRequestHeadersPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId rst_stream_id, quic::QuicRstStreamErrorCode rst_error_code, @@ -100,126 +102,127 @@ class QuicTestPacketMaker { quic::QuicStreamOffset* offset); std::unique_ptr<quic::QuicReceivedPacket> MakeAckAndRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback); std::unique_ptr<quic::QuicReceivedPacket> MakeAckAndRstPacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback, - size_t bytes_written); + size_t bytes_written, + bool include_stop_sending_if_v99); std::unique_ptr<quic::QuicReceivedPacket> MakeRstAckAndConnectionClosePacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicStreamId stream_id, quic::QuicRstStreamErrorCode error_code, quic::QuicTime::Delta delta_time_largest_observed, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicErrorCode quic_error, const std::string& quic_error_details); std::unique_ptr<quic::QuicReceivedPacket> MakeAckAndConnectionClosePacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicTime::Delta delta_time_largest_observed, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, quic::QuicErrorCode quic_error, const std::string& quic_error_details); std::unique_ptr<quic::QuicReceivedPacket> MakeConnectionClosePacket( - quic::QuicPacketNumber num, + uint64_t num, bool include_version, quic::QuicErrorCode quic_error, const std::string& quic_error_details); std::unique_ptr<quic::QuicReceivedPacket> MakeGoAwayPacket( - quic::QuicPacketNumber num, + uint64_t num, quic::QuicErrorCode error_code, std::string reason_phrase); std::unique_ptr<quic::QuicReceivedPacket> MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback); std::unique_ptr<quic::QuicReceivedPacket> MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber first_received, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t first_received, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback); std::unique_ptr<quic::QuicReceivedPacket> MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback, quic::QuicTime::Delta ack_delay_time); std::unique_ptr<quic::QuicReceivedPacket> MakeAckPacket( - quic::QuicPacketNumber packet_number, - quic::QuicPacketNumber first_received, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t packet_number, + uint64_t first_received, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool send_feedback, quic::QuicTime::Delta ack_delay_time); std::unique_ptr<quic::QuicReceivedPacket> MakeDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, quic::QuicStreamOffset offset, quic::QuicStringPiece data); std::unique_ptr<quic::QuicReceivedPacket> MakeForceHolDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, quic::QuicStreamOffset* offset, quic::QuicStringPiece data); std::unique_ptr<quic::QuicReceivedPacket> MakeMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, quic::QuicStreamOffset offset, const std::vector<std::string>& data_writes); std::unique_ptr<quic::QuicReceivedPacket> MakeAckAndDataPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool include_version, quic::QuicStreamId stream_id, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool fin, quic::QuicStreamOffset offset, quic::QuicStringPiece data); std::unique_ptr<quic::QuicReceivedPacket> MakeAckAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool include_version, quic::QuicStreamId stream_id, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, bool fin, quic::QuicStreamOffset offset, const std::vector<std::string>& data); std::unique_ptr<quic::QuicReceivedPacket> MakeRequestHeadersAndMultipleDataFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -233,7 +236,7 @@ class QuicTestPacketMaker { // If |spdy_headers_frame_length| is non-null, it will be set to the size of // the SPDY headers frame created for this packet. std::unique_ptr<quic::QuicReceivedPacket> MakeRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -243,7 +246,7 @@ class QuicTestPacketMaker { size_t* spdy_headers_frame_length); std::unique_ptr<quic::QuicReceivedPacket> MakeRequestHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -255,7 +258,7 @@ class QuicTestPacketMaker { // Saves the serialized QUIC stream data in |stream_data|. std::unique_ptr<quic::QuicReceivedPacket> MakeRequestHeadersPacketAndSaveData( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -267,7 +270,7 @@ class QuicTestPacketMaker { std::string* stream_data); std::unique_ptr<quic::QuicReceivedPacket> MakeRequestHeadersAndRstPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -283,7 +286,7 @@ class QuicTestPacketMaker { // |spdy_headers_frame_length|. std::unique_ptr<quic::QuicReceivedPacket> MakeRequestHeadersPacketWithOffsetTracking( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -295,7 +298,7 @@ class QuicTestPacketMaker { // If |spdy_headers_frame_length| is non-null, it will be set to the size of // the SPDY headers frame created for this packet. std::unique_ptr<quic::QuicReceivedPacket> MakePushPromisePacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, quic::QuicStreamId promised_stream_id, bool should_include_version, @@ -307,7 +310,7 @@ class QuicTestPacketMaker { // If |spdy_headers_frame_length| is non-null, it will be set to the size of // the SPDY headers frame created for this packet. std::unique_ptr<quic::QuicReceivedPacket> MakeResponseHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -316,7 +319,7 @@ class QuicTestPacketMaker { quic::QuicStreamOffset* offset); std::unique_ptr<quic::QuicReceivedPacket> MakeResponseHeadersPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamId stream_id, bool should_include_version, bool fin, @@ -326,29 +329,28 @@ class QuicTestPacketMaker { // Convenience method for calling MakeResponseHeadersPacket with nullptr for // |spdy_headers_frame_length|. std::unique_ptr<quic::QuicReceivedPacket> - MakeResponseHeadersPacketWithOffsetTracking( - quic::QuicPacketNumber packet_number, - quic::QuicStreamId stream_id, - bool should_include_version, - bool fin, - spdy::SpdyHeaderBlock headers, - quic::QuicStreamOffset* offset); + MakeResponseHeadersPacketWithOffsetTracking(uint64_t packet_number, + quic::QuicStreamId stream_id, + bool should_include_version, + bool fin, + spdy::SpdyHeaderBlock headers, + quic::QuicStreamOffset* offset); // Creates a packet containing the initial SETTINGS frame, and saves the // headers stream offset into |offset|. std::unique_ptr<quic::QuicReceivedPacket> MakeInitialSettingsPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, quic::QuicStreamOffset* offset); // Same as above, but also saves the serialized QUIC stream data in // |stream_data|. std::unique_ptr<quic::QuicReceivedPacket> - MakeInitialSettingsPacketAndSaveData(quic::QuicPacketNumber packet_number, + MakeInitialSettingsPacketAndSaveData(uint64_t packet_number, quic::QuicStreamOffset* offset, std::string* stream_data); std::unique_ptr<quic::QuicReceivedPacket> MakePriorityPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, quic::QuicStreamId id, quic::QuicStreamId parent_stream_id, @@ -357,18 +359,16 @@ class QuicTestPacketMaker { std::unique_ptr<quic::QuicReceivedPacket> MakeAckAndMultiplePriorityFramesPacket( - quic::QuicPacketNumber packet_number, + uint64_t packet_number, bool should_include_version, - quic::QuicPacketNumber largest_received, - quic::QuicPacketNumber smallest_received, - quic::QuicPacketNumber least_unacked, + uint64_t largest_received, + uint64_t smallest_received, + uint64_t least_unacked, const std::vector<Http2StreamDependency>& priority_frames, quic::QuicStreamOffset* offset); void SetEncryptionLevel(quic::EncryptionLevel level); - void SetLongHeaderType(quic::QuicLongHeaderType type); - spdy::SpdyHeaderBlock GetRequestHeaders(const std::string& method, const std::string& scheme, const std::string& path); @@ -389,10 +389,10 @@ class QuicTestPacketMaker { const quic::QuicFrame& frame); std::unique_ptr<quic::QuicReceivedPacket> MakeMultipleFramesPacket( const quic::QuicPacketHeader& header, - const quic::QuicFrames& frames); + const quic::QuicFrames& frames, + quic::QuicStreamFrameDataProducer* data_producer); - void InitializeHeader(quic::QuicPacketNumber packet_number, - bool should_include_version); + void InitializeHeader(uint64_t packet_number, bool should_include_version); spdy::SpdySerializedFrame MakeSpdyHeadersFrame( quic::QuicStreamId stream_id, @@ -405,9 +405,8 @@ class QuicTestPacketMaker { quic::QuicPacketNumberLength GetPacketNumberLength() const; - quic::QuicConnectionIdLength GetDestinationConnectionIdLength() const; - - quic::QuicConnectionIdLength GetSourceConnectionIdLength() const; + quic::QuicConnectionIdIncluded HasDestinationConnectionId() const; + quic::QuicConnectionIdIncluded HasSourceConnectionId() const; quic::QuicTransportVersion version_; quic::QuicConnectionId connection_id_; |