summaryrefslogtreecommitdiff
path: root/chromium/net/tools/quic
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-18 14:34:04 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-10-04 11:15:27 +0000
commite6430e577f105ad8813c92e75c54660c4985026e (patch)
tree88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/net/tools/quic
parent53d399fe6415a96ea6986ec0d402a9c07da72453 (diff)
downloadqtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/net/tools/quic')
-rw-r--r--chromium/net/tools/quic/chlo_extractor_test.cc3
-rw-r--r--chromium/net/tools/quic/end_to_end_test.cc256
-rw-r--r--chromium/net/tools/quic/platform/impl/quic_socket_utils.cc2
-rw-r--r--chromium/net/tools/quic/quic_client_session_test.cc18
-rw-r--r--chromium/net/tools/quic/quic_client_test.cc4
-rw-r--r--chromium/net/tools/quic/quic_dispatcher.cc111
-rw-r--r--chromium/net/tools/quic/quic_dispatcher.h10
-rw-r--r--chromium/net/tools/quic/quic_dispatcher_test.cc286
-rw-r--r--chromium/net/tools/quic/quic_http_response_cache.h4
-rw-r--r--chromium/net/tools/quic/quic_server_test.cc5
-rw-r--r--chromium/net/tools/quic/quic_simple_dispatcher.cc3
-rw-r--r--chromium/net/tools/quic/quic_simple_dispatcher.h3
-rw-r--r--chromium/net/tools/quic/quic_simple_server_session_test.cc9
-rw-r--r--chromium/net/tools/quic/quic_simple_server_stream_test.cc2
-rw-r--r--chromium/net/tools/quic/quic_time_wait_list_manager_test.cc3
-rw-r--r--chromium/net/tools/quic/stateless_rejector_test.cc8
-rw-r--r--chromium/net/tools/quic/test_tools/quic_test_server.cc8
-rw-r--r--chromium/net/tools/quic/test_tools/server_thread.h1
18 files changed, 418 insertions, 318 deletions
diff --git a/chromium/net/tools/quic/chlo_extractor_test.cc b/chromium/net/tools/quic/chlo_extractor_test.cc
index 54f5a310064..90de56b6f5e 100644
--- a/chromium/net/tools/quic/chlo_extractor_test.cc
+++ b/chromium/net/tools/quic/chlo_extractor_test.cc
@@ -95,8 +95,7 @@ TEST_F(ChloExtractorTest, FindsValidChlo) {
EXPECT_TRUE(ChloExtractor::Extract(*packet_, versions, &delegate_))
<< QuicVersionToString(version);
EXPECT_EQ(version, delegate_.version());
- EXPECT_EQ(GetPeerInMemoryConnectionId(header_.public_header.connection_id),
- delegate_.connection_id());
+ EXPECT_EQ(header_.public_header.connection_id, delegate_.connection_id());
EXPECT_EQ(client_hello.DebugString(Perspective::IS_SERVER),
delegate_.chlo())
<< QuicVersionToString(version);
diff --git a/chromium/net/tools/quic/end_to_end_test.cc b/chromium/net/tools/quic/end_to_end_test.cc
index ca66c54988b..acaeea697fe 100644
--- a/chromium/net/tools/quic/end_to_end_test.cc
+++ b/chromium/net/tools/quic/end_to_end_test.cc
@@ -35,6 +35,7 @@
#include "net/quic/platform/api/quic_str_cat.h"
#include "net/quic/platform/api/quic_string_piece.h"
#include "net/quic/platform/api/quic_test.h"
+#include "net/quic/platform/api/quic_test_loopback.h"
#include "net/quic/platform/api/quic_text_utils.h"
#include "net/quic/test_tools/crypto_test_utils.h"
#include "net/quic/test_tools/quic_config_peer.h"
@@ -87,9 +88,7 @@ struct TestParams {
QuicTag congestion_control_tag,
bool disable_hpack_dynamic_table,
bool force_hol_blocking,
- bool use_cheap_stateless_reject,
- bool connection_id_big_endian_client,
- bool connection_id_big_endian_server)
+ bool use_cheap_stateless_reject)
: client_supported_versions(client_supported_versions),
server_supported_versions(server_supported_versions),
negotiated_version(negotiated_version),
@@ -99,9 +98,7 @@ struct TestParams {
congestion_control_tag(congestion_control_tag),
disable_hpack_dynamic_table(disable_hpack_dynamic_table),
force_hol_blocking(force_hol_blocking),
- use_cheap_stateless_reject(use_cheap_stateless_reject),
- connection_id_big_endian_client(connection_id_big_endian_client),
- connection_id_big_endian_server(connection_id_big_endian_server) {}
+ use_cheap_stateless_reject(use_cheap_stateless_reject) {}
friend std::ostream& operator<<(std::ostream& os, const TestParams& p) {
os << "{ server_supported_versions: "
@@ -117,11 +114,8 @@ struct TestParams {
<< QuicTagToString(p.congestion_control_tag);
os << " disable_hpack_dynamic_table: " << p.disable_hpack_dynamic_table;
os << " force_hol_blocking: " << p.force_hol_blocking;
- os << " use_cheap_stateless_reject: " << p.use_cheap_stateless_reject;
- os << " connection_id_big_endian_client: "
- << p.connection_id_big_endian_client;
- os << " connection_id_big_endian_server: "
- << p.connection_id_big_endian_server << " }";
+ os << " use_cheap_stateless_reject: " << p.use_cheap_stateless_reject
+ << " }";
return os;
}
@@ -134,8 +128,6 @@ struct TestParams {
bool disable_hpack_dynamic_table;
bool force_hol_blocking;
bool use_cheap_stateless_reject;
- bool connection_id_big_endian_client;
- bool connection_id_big_endian_server;
};
// Constructs various test permutations.
@@ -161,7 +153,7 @@ std::vector<TestParams> GetTestParams() {
// This must be kept in sync with the number of nested for-loops below as it
// is used to prune the number of tests that are run.
- const int kMaxEnabledOptions = 7;
+ const int kMaxEnabledOptions = 5;
int max_enabled_options = 0;
std::vector<TestParams> params;
for (bool server_uses_stateless_rejects_if_peer_supported : {true, false}) {
@@ -171,101 +163,84 @@ std::vector<TestParams> GetTestParams() {
for (bool disable_hpack_dynamic_table : {false}) {
for (bool force_hol_blocking : {true, false}) {
for (bool use_cheap_stateless_reject : {true, false}) {
- for (bool connection_id_big_endian_client : {true, false}) {
- for (bool connection_id_big_endian_server : {true, false}) {
- int enabled_options = 0;
- if (force_hol_blocking) {
- ++enabled_options;
- }
- if (congestion_control_tag != kQBIC) {
- ++enabled_options;
- }
- if (disable_hpack_dynamic_table) {
- ++enabled_options;
- }
- if (client_supports_stateless_rejects) {
- ++enabled_options;
- }
- if (server_uses_stateless_rejects_if_peer_supported) {
- ++enabled_options;
- }
- if (use_cheap_stateless_reject) {
- ++enabled_options;
- }
- if (connection_id_big_endian_server) {
- ++enabled_options;
- }
- if (connection_id_big_endian_client) {
- ++enabled_options;
- }
- CHECK_GE(kMaxEnabledOptions, enabled_options);
- if (enabled_options > max_enabled_options) {
- max_enabled_options = enabled_options;
- }
-
- // Run tests with no options, a single option, or all the
- // options enabled to avoid a combinatorial explosion.
- if (enabled_options > 1 &&
- enabled_options < kMaxEnabledOptions) {
+ int enabled_options = 0;
+ if (force_hol_blocking) {
+ ++enabled_options;
+ }
+ if (congestion_control_tag != kQBIC) {
+ ++enabled_options;
+ }
+ if (disable_hpack_dynamic_table) {
+ ++enabled_options;
+ }
+ if (client_supports_stateless_rejects) {
+ ++enabled_options;
+ }
+ if (server_uses_stateless_rejects_if_peer_supported) {
+ ++enabled_options;
+ }
+ if (use_cheap_stateless_reject) {
+ ++enabled_options;
+ }
+ CHECK_GE(kMaxEnabledOptions, enabled_options);
+ if (enabled_options > max_enabled_options) {
+ max_enabled_options = enabled_options;
+ }
+
+ // Run tests with no options, a single option, or all the
+ // options enabled to avoid a combinatorial explosion.
+ if (enabled_options > 1 && enabled_options < kMaxEnabledOptions) {
+ continue;
+ }
+
+ for (const QuicVersionVector& client_versions : version_buckets) {
+ CHECK(!client_versions.empty());
+ if (FilterSupportedVersions(client_versions).empty()) {
+ continue;
+ }
+ // Add an entry for server and client supporting all
+ // versions.
+ params.push_back(TestParams(
+ client_versions, all_supported_versions,
+ client_versions.front(), client_supports_stateless_rejects,
+ server_uses_stateless_rejects_if_peer_supported,
+ congestion_control_tag, disable_hpack_dynamic_table,
+ force_hol_blocking, use_cheap_stateless_reject));
+
+ // Run version negotiation tests tests with no options, or
+ // all the options enabled to avoid a combinatorial
+ // explosion.
+ if (enabled_options > 1 &&
+ enabled_options < kMaxEnabledOptions) {
+ continue;
+ }
+
+ // Test client supporting all versions and server supporting
+ // 1 version. Simulate an old server and exercise version
+ // downgrade in the client. Protocol negotiation should
+ // occur. Skip the i = 0 case because it is essentially the
+ // same as the default case.
+ for (size_t i = 1; i < client_versions.size(); ++i) {
+ QuicVersionVector server_supported_versions;
+ server_supported_versions.push_back(client_versions[i]);
+ if (FilterSupportedVersions(server_supported_versions)
+ .empty()) {
continue;
}
-
- for (const QuicVersionVector& client_versions :
- version_buckets) {
- CHECK(!client_versions.empty());
- if (FilterSupportedVersions(client_versions).empty()) {
- continue;
- }
- // Add an entry for server and client supporting all
- // versions.
- params.push_back(TestParams(
- client_versions, all_supported_versions,
- client_versions.front(),
- client_supports_stateless_rejects,
- server_uses_stateless_rejects_if_peer_supported,
- congestion_control_tag, disable_hpack_dynamic_table,
- force_hol_blocking, use_cheap_stateless_reject,
- connection_id_big_endian_client,
- connection_id_big_endian_server));
-
- // Run version negotiation tests tests with no options, or
- // all the options enabled to avoid a combinatorial
- // explosion.
- if (enabled_options > 1 &&
- enabled_options < kMaxEnabledOptions) {
- continue;
- }
-
- // Test client supporting all versions and server supporting
- // 1 version. Simulate an old server and exercise version
- // downgrade in the client. Protocol negotiation should
- // occur. Skip the i = 0 case because it is essentially the
- // same as the default case.
- for (size_t i = 1; i < client_versions.size(); ++i) {
- QuicVersionVector server_supported_versions;
- server_supported_versions.push_back(client_versions[i]);
- if (FilterSupportedVersions(server_supported_versions)
- .empty()) {
- continue;
- }
- params.push_back(TestParams(
- client_versions, server_supported_versions,
- server_supported_versions.front(),
- client_supports_stateless_rejects,
- server_uses_stateless_rejects_if_peer_supported,
- congestion_control_tag, disable_hpack_dynamic_table,
- force_hol_blocking, use_cheap_stateless_reject,
- connection_id_big_endian_client,
- connection_id_big_endian_server));
- } // End of version for loop.
- } // End of 2nd version for loop.
- } // End of connection_id_big_endian_server
- } // End of connection_id_big_endian_client
- } // End of use_cheap_stateless_reject for loop.
- } // End of force_hol_blocking loop.
- } // End of disable_hpack_dynamic_table for loop.
- } // End of congestion_control_tag for loop.
- } // End of client_supports_stateless_rejects for loop.
+ params.push_back(TestParams(
+ client_versions, server_supported_versions,
+ server_supported_versions.front(),
+ client_supports_stateless_rejects,
+ server_uses_stateless_rejects_if_peer_supported,
+ congestion_control_tag, disable_hpack_dynamic_table,
+ force_hol_blocking, use_cheap_stateless_reject));
+ } // End of version for loop.
+ } // End of 2nd version for loop.
+ } // End of use_cheap_stateless_reject for loop.
+ } // End of force_hol_blocking loop.
+ } // End of disable_hpack_dynamic_table for loop.
+ } // End of congestion_control_tag for loop.
+ } // End of client_supports_stateless_rejects for loop.
CHECK_EQ(kMaxEnabledOptions, max_enabled_options);
} // End of server_uses_stateless_rejects_if_peer_supported for loop.
return params;
@@ -299,7 +274,7 @@ class EndToEndTest : public QuicTestWithParam<TestParams> {
protected:
EndToEndTest()
: initialized_(false),
- server_address_(QuicSocketAddress(QuicIpAddress::Loopback4(), 0)),
+ server_address_(QuicSocketAddress(TestLoopback(), 0)),
server_hostname_("test.example.com"),
client_writer_(nullptr),
server_writer_(nullptr),
@@ -333,11 +308,6 @@ class EndToEndTest : public QuicTestWithParam<TestParams> {
AddToCache("/foo", 200, kFooResponseBody);
AddToCache("/bar", 200, kBarResponseBody);
-
- FLAGS_quic_restart_flag_quic_big_endian_connection_id_client =
- GetParam().connection_id_big_endian_client;
- FLAGS_quic_restart_flag_quic_big_endian_connection_id_server =
- GetParam().connection_id_big_endian_server;
}
~EndToEndTest() override {
@@ -414,16 +384,13 @@ class EndToEndTest : public QuicTestWithParam<TestParams> {
// TODO(nimia): Consider setting the congestion control algorithm for the
// client as well according to the test parameter.
copt.push_back(GetParam().congestion_control_tag);
- if (GetParam().congestion_control_tag == kQBIC &&
- FLAGS_quic_reloadable_flag_quic_fix_cubic_convex_mode) {
+ if (GetParam().congestion_control_tag == kQBIC) {
copt.push_back(kCCVX);
}
- if (GetParam().congestion_control_tag == kQBIC &&
- FLAGS_quic_reloadable_flag_quic_fix_cubic_bytes_quantization) {
+ if (GetParam().congestion_control_tag == kQBIC) {
copt.push_back(kCBQT);
}
- if (GetParam().congestion_control_tag == kQBIC &&
- FLAGS_quic_reloadable_flag_quic_enable_cubic_per_ack_updates) {
+ if (GetParam().congestion_control_tag == kQBIC) {
copt.push_back(kCPAU);
}
if (GetParam().congestion_control_tag == kTPCC &&
@@ -555,7 +522,9 @@ class EndToEndTest : public QuicTestWithParam<TestParams> {
void VerifyCleanConnection(bool had_packet_loss) {
QuicConnectionStats client_stats =
client_->client()->session()->connection()->GetStats();
- if (!had_packet_loss) {
+ // TODO(ianswett): Determine why this becomes even more flaky with BBR
+ // enabled. b/62141144
+ if (!had_packet_loss && !FLAGS_quic_reloadable_flag_quic_default_to_bbr) {
EXPECT_EQ(0u, client_stats.packets_lost);
}
EXPECT_EQ(0u, client_stats.packets_discarded);
@@ -1351,7 +1320,6 @@ TEST_P(EndToEndTest, SetIndependentMaxIncomingDynamicStreamsLimits) {
}
TEST_P(EndToEndTest, NegotiateCongestionControl) {
- FLAGS_quic_reloadable_flag_quic_allow_new_bbr = true;
ASSERT_TRUE(Initialize());
// For PCC, the underlying implementation may be a stub with a
@@ -1365,7 +1333,11 @@ TEST_P(EndToEndTest, NegotiateCongestionControl) {
CongestionControlType expected_congestion_control_type = kReno;
switch (GetParam().congestion_control_tag) {
case kRENO:
- expected_congestion_control_type = kReno;
+ if (!FLAGS_quic_reloadable_flag_quic_disable_packets_based_cc) {
+ expected_congestion_control_type = kReno;
+ } else {
+ expected_congestion_control_type = kRenoBytes;
+ }
break;
case kTBBR:
expected_congestion_control_type = kBBR;
@@ -1598,7 +1570,6 @@ class WrongAddressWriter : public QuicPacketWriterWrapper {
TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) {
ASSERT_TRUE(Initialize());
-
EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
EXPECT_EQ("200", client_->response_headers()->find(":status")->second);
@@ -1606,8 +1577,7 @@ TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) {
QuicIpAddress old_host = client_->client()->GetLatestClientAddress().host();
// Migrate socket to the new IP address.
- QuicIpAddress new_host;
- new_host.FromString("127.0.0.2");
+ QuicIpAddress new_host = TestLoopback(2);
EXPECT_NE(old_host, new_host);
ASSERT_TRUE(client_->client()->MigrateSocket(new_host));
@@ -2021,8 +1991,7 @@ TEST_P(EndToEndTest, ServerSendPublicReset) {
QuicConnectionId connection_id =
client_->client()->session()->connection()->connection_id();
QuicPublicResetPacket header;
- header.public_header.connection_id =
- GetPeerInMemoryConnectionId(connection_id);
+ header.public_header.connection_id = connection_id;
header.public_header.reset_flag = true;
header.public_header.version_flag = false;
QuicFramer framer(server_supported_versions_, QuicTime::Zero(),
@@ -2054,8 +2023,7 @@ TEST_P(EndToEndTest, ServerSendPublicResetWithDifferentConnectionId) {
QuicConnectionId incorrect_connection_id =
client_->client()->session()->connection()->connection_id() + 1;
QuicPublicResetPacket header;
- header.public_header.connection_id =
- GetPeerInMemoryConnectionId(incorrect_connection_id);
+ header.public_header.connection_id = incorrect_connection_id;
header.public_header.reset_flag = true;
header.public_header.version_flag = false;
QuicFramer framer(server_supported_versions_, QuicTime::Zero(),
@@ -2118,9 +2086,8 @@ TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) {
QuicConnectionId incorrect_connection_id =
client_->client()->session()->connection()->connection_id() + 1;
std::unique_ptr<QuicEncryptedPacket> packet(
- QuicFramer::BuildVersionNegotiationPacket(
- GetPeerInMemoryConnectionId(incorrect_connection_id),
- server_supported_versions_));
+ QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id,
+ server_supported_versions_));
testing::NiceMock<MockQuicConnectionDebugVisitor> visitor;
client_->client()->session()->connection()->set_debug_visitor(&visitor);
EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id))
@@ -2250,6 +2217,27 @@ TEST_P(EndToEndTest, BadEncryptedData) {
EXPECT_EQ("200", client_->response_headers()->find(":status")->second);
}
+TEST_P(EndToEndTest, CanceledStreamDoesNotBecomeZombie) {
+ ASSERT_TRUE(Initialize());
+ EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed());
+ // Lose the request.
+ SetPacketLossPercentage(100);
+ SpdyHeaderBlock headers;
+ headers[":method"] = "POST";
+ headers[":path"] = "/foo";
+ headers[":scheme"] = "https";
+ headers[":authority"] = server_hostname_;
+ client_->SendMessage(headers, "test_body", /*fin=*/false);
+ QuicSpdyClientStream* stream = client_->GetOrCreateStream();
+
+ // Cancel the stream.
+ stream->Reset(QUIC_STREAM_CANCELLED);
+ QuicSession* session = client_->client()->session();
+ // Verify canceled stream does not become zombie.
+ EXPECT_TRUE(QuicSessionPeer::zombie_streams(session).empty());
+ EXPECT_EQ(1u, QuicSessionPeer::closed_streams(session).size());
+}
+
// A test stream that gives |response_body_| as an error response body.
class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream {
public:
@@ -2341,7 +2329,7 @@ class ServerStreamThatDropsBodyFactory : public QuicTestServer::StreamFactory {
public:
ServerStreamThatDropsBodyFactory() {}
- ~ServerStreamThatDropsBodyFactory() override{};
+ ~ServerStreamThatDropsBodyFactory() override {}
QuicSimpleServerStream* CreateStream(
QuicStreamId id,
@@ -2384,7 +2372,7 @@ class ServerStreamThatSendsHugeResponseFactory
explicit ServerStreamThatSendsHugeResponseFactory(int64_t body_bytes)
: body_bytes_(body_bytes) {}
- ~ServerStreamThatSendsHugeResponseFactory() override{};
+ ~ServerStreamThatSendsHugeResponseFactory() override {}
QuicSimpleServerStream* CreateStream(
QuicStreamId id,
diff --git a/chromium/net/tools/quic/platform/impl/quic_socket_utils.cc b/chromium/net/tools/quic/platform/impl/quic_socket_utils.cc
index 621767c0667..e188da2e8e9 100644
--- a/chromium/net/tools/quic/platform/impl/quic_socket_utils.cc
+++ b/chromium/net/tools/quic/platform/impl/quic_socket_utils.cc
@@ -249,7 +249,7 @@ WriteResult QuicSocketUtils::WritePacket(
(kSpaceForIpv4 < kSpaceForIpv6) ? kSpaceForIpv6 : kSpaceForIpv4;
char cbuf[kSpaceForIp];
if (!self_address.IsInitialized()) {
- hdr.msg_control = 0;
+ hdr.msg_control = nullptr;
hdr.msg_controllen = 0;
} else {
hdr.msg_control = cbuf;
diff --git a/chromium/net/tools/quic/quic_client_session_test.cc b/chromium/net/tools/quic/quic_client_session_test.cc
index c970c77b8b1..b45312af054 100644
--- a/chromium/net/tools/quic/quic_client_session_test.cc
+++ b/chromium/net/tools/quic/quic_client_session_test.cc
@@ -153,6 +153,7 @@ TEST_P(QuicClientSessionTest, NoEncryptionAfterInitialEncryption) {
// Now create a second session using the same crypto config.
Initialize();
+ EXPECT_CALL(*connection_, OnCanWrite());
// Starting the handshake should move immediately to encryption
// established and will allow streams to be created.
session_->CryptoConnect();
@@ -168,7 +169,8 @@ TEST_P(QuicClientSessionTest, NoEncryptionAfterInitialEncryption) {
CryptoHandshakeMessage rej;
crypto_test_utils::FillInDummyReject(&rej, /* stateless */ false);
EXPECT_TRUE(session_->IsEncryptionEstablished());
- session_->GetMutableCryptoStream()->OnHandshakeMessage(rej);
+ crypto_test_utils::SendHandshakeMessageToStream(
+ session_->GetMutableCryptoStream(), rej, Perspective::IS_CLIENT);
EXPECT_FALSE(session_->IsEncryptionEstablished());
EXPECT_EQ(ENCRYPTION_NONE,
QuicPacketCreatorPeer::GetEncryptionLevel(
@@ -346,9 +348,8 @@ TEST_P(QuicClientSessionTest, InvalidPacketReceived) {
// Verify that a non-decryptable packet doesn't close the connection.
QuicConnectionId connection_id = session_->connection()->connection_id();
std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
- GetPeerInMemoryConnectionId(connection_id), false, false, 100, "data",
- PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, nullptr,
- Perspective::IS_SERVER));
+ connection_id, false, false, 100, "data", PACKET_8BYTE_CONNECTION_ID,
+ PACKET_6BYTE_PACKET_NUMBER, nullptr, Perspective::IS_SERVER));
std::unique_ptr<QuicReceivedPacket> received(
ConstructReceivedPacket(*packet, QuicTime::Zero()));
// Change the last byte of the encrypted data.
@@ -372,9 +373,8 @@ TEST_P(QuicClientSessionTest, InvalidFramedPacketReceived) {
QuicConnectionId connection_id = session_->connection()->connection_id();
QuicVersionVector versions = {GetParam()};
std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket(
- GetPeerInMemoryConnectionId(connection_id), false, false, 100, "data",
- PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, &versions,
- Perspective::IS_SERVER));
+ connection_id, false, false, 100, "data", PACKET_8BYTE_CONNECTION_ID,
+ PACKET_6BYTE_PACKET_NUMBER, &versions, Perspective::IS_SERVER));
std::unique_ptr<QuicReceivedPacket> received(
ConstructReceivedPacket(*packet, QuicTime::Zero()));
EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(1);
@@ -516,6 +516,8 @@ TEST_P(QuicClientSessionTest, IsClosedTrueAfterResetPromisedAlreadyOpen) {
CompleteCryptoHandshake();
session_->GetOrCreateStream(promised_stream_id_);
+ EXPECT_CALL(*connection_,
+ SendRstStream(promised_stream_id_, QUIC_REFUSED_STREAM, 0));
session_->ResetPromised(promised_stream_id_, QUIC_REFUSED_STREAM);
EXPECT_TRUE(session_->IsClosedStream(promised_stream_id_));
}
@@ -524,6 +526,8 @@ TEST_P(QuicClientSessionTest, IsClosedTrueAfterResetPromisedNonexistant) {
// Initialize crypto before the client session will create a stream.
CompleteCryptoHandshake();
+ EXPECT_CALL(*connection_,
+ SendRstStream(promised_stream_id_, QUIC_REFUSED_STREAM, 0));
session_->ResetPromised(promised_stream_id_, QUIC_REFUSED_STREAM);
EXPECT_TRUE(session_->IsClosedStream(promised_stream_id_));
}
diff --git a/chromium/net/tools/quic/quic_client_test.cc b/chromium/net/tools/quic/quic_client_test.cc
index 458a5b7a3b3..973826d0192 100644
--- a/chromium/net/tools/quic/quic_client_test.cc
+++ b/chromium/net/tools/quic/quic_client_test.cc
@@ -12,6 +12,7 @@
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "net/quic/platform/api/quic_test.h"
+#include "net/quic/platform/api/quic_test_loopback.h"
#include "net/quic/platform/api/quic_text_utils.h"
#include "net/quic/test_tools/crypto_test_utils.h"
#include "net/quic/test_tools/quic_test_utils.h"
@@ -49,8 +50,7 @@ size_t NumOpenSocketFDs() {
// Creates a new QuicClient and Initializes it. Caller is responsible for
// deletion.
QuicClient* CreateAndInitializeQuicClient(EpollServer* eps, uint16_t port) {
- QuicSocketAddress server_address(
- QuicSocketAddress(QuicIpAddress::Loopback4(), port));
+ QuicSocketAddress server_address(QuicSocketAddress(TestLoopback(), port));
QuicServerId server_id("hostname", server_address.port(),
PRIVACY_MODE_DISABLED);
QuicVersionVector versions = AllSupportedVersions();
diff --git a/chromium/net/tools/quic/quic_dispatcher.cc b/chromium/net/tools/quic/quic_dispatcher.cc
index fda85001fee..aa6ef57261a 100644
--- a/chromium/net/tools/quic/quic_dispatcher.cc
+++ b/chromium/net/tools/quic/quic_dispatcher.cc
@@ -7,6 +7,7 @@
#include <utility>
#include "base/macros.h"
+#include "net/quic/core/crypto/crypto_protocol.h"
#include "net/quic/core/crypto/quic_random.h"
#include "net/quic/core/quic_utils.h"
#include "net/quic/platform/api/quic_bug_tracker.h"
@@ -49,10 +50,14 @@ class DeleteSessionsAlarm : public QuicAlarm::Delegate {
// Collects packets serialized by a QuicPacketCreator in order
// to be handed off to the time wait list manager.
-class PacketCollector : public QuicPacketCreator::DelegateInterface {
+class PacketCollector : public QuicPacketCreator::DelegateInterface,
+ public QuicStreamFrameDataProducer {
public:
+ explicit PacketCollector(QuicBufferAllocator* allocator)
+ : send_buffer_(allocator) {}
~PacketCollector() override {}
+ // QuicPacketCreator::DelegateInterface methods:
void OnSerializedPacket(SerializedPacket* serialized_packet) override {
// Make a copy of the serialized packet to send later.
packets_.push_back(std::unique_ptr<QuicEncryptedPacket>(
@@ -67,12 +72,33 @@ class PacketCollector : public QuicPacketCreator::DelegateInterface {
const string& error_details,
ConnectionCloseSource source) override {}
+ // QuicStreamFrameDataProducer methods:
+ void SaveStreamData(QuicStreamId id,
+ QuicIOVector iov,
+ size_t iov_offset,
+ QuicStreamOffset offset,
+ QuicByteCount data_length) override {
+ DCHECK_EQ(kCryptoStreamId, id);
+ send_buffer_.SaveStreamData(iov, iov_offset, offset, data_length);
+ }
+
+ bool WriteStreamData(QuicStreamId id,
+ QuicStreamOffset offset,
+ QuicByteCount data_length,
+ QuicDataWriter* writer) override {
+ DCHECK_EQ(kCryptoStreamId, id);
+ return send_buffer_.WriteStreamData(offset, data_length, writer);
+ }
+
std::vector<std::unique_ptr<QuicEncryptedPacket>>* packets() {
return &packets_;
}
private:
std::vector<std::unique_ptr<QuicEncryptedPacket>> packets_;
+ // This is only needed until the packets are encrypted. Once packets are
+ // encrypted, the stream data is no longer required.
+ QuicStreamSendBuffer send_buffer_;
};
// Helper for statelessly closing connections by generating the
@@ -86,11 +112,23 @@ class StatelessConnectionTerminator {
QuicTimeWaitListManager* time_wait_list_manager)
: connection_id_(connection_id),
framer_(framer),
+ collector_(helper->GetBufferAllocator()),
creator_(connection_id,
framer,
helper->GetBufferAllocator(),
&collector_),
- time_wait_list_manager_(time_wait_list_manager) {}
+ time_wait_list_manager_(time_wait_list_manager) {
+ if (FLAGS_quic_reloadable_flag_quic_stream_owns_data) {
+ framer_->set_data_producer(&collector_);
+ }
+ }
+
+ ~StatelessConnectionTerminator() {
+ if (framer_->HasDataProducer()) {
+ // Clear framer's producer.
+ framer_->set_data_producer(nullptr);
+ }
+ }
// Generates a packet containing a CONNECTION_CLOSE frame specifying
// |error_code| and |error_details| and add the connection to time wait.
@@ -150,9 +188,27 @@ class StatelessConnectionTerminator {
QuicTimeWaitListManager* time_wait_list_manager_;
};
+// Class which extracts the ALPN from a CHLO packet.
+class ChloAlpnExtractor : public ChloExtractor::Delegate {
+ public:
+ void OnChlo(QuicVersion version,
+ QuicConnectionId connection_id,
+ const CryptoHandshakeMessage& chlo) override {
+ QuicStringPiece alpn_value;
+ if (chlo.GetStringPiece(kALPN, &alpn_value)) {
+ alpn_ = string(alpn_value);
+ }
+ }
+
+ string&& ConsumeAlpn() { return std::move(alpn_); }
+
+ private:
+ string alpn_;
+};
+
// Class which sits between the ChloExtractor and the StatelessRejector
// to give the QuicDispatcher a chance to apply policy checks to the CHLO.
-class ChloValidator : public ChloExtractor::Delegate {
+class ChloValidator : public ChloAlpnExtractor {
public:
ChloValidator(QuicCryptoServerStream::Helper* helper,
QuicSocketAddress self_address,
@@ -166,6 +222,8 @@ class ChloValidator : public ChloExtractor::Delegate {
void OnChlo(QuicVersion version,
QuicConnectionId connection_id,
const CryptoHandshakeMessage& chlo) override {
+ // Extract the ALPN
+ ChloAlpnExtractor::OnChlo(version, connection_id, chlo);
if (helper_->CanAcceptClientHello(chlo, self_address_, &error_details_)) {
can_accept_ = true;
rejector_->OnChlo(version, connection_id,
@@ -648,13 +706,14 @@ void QuicDispatcher::ProcessBufferedChlos(size_t max_connections_to_create) {
for (; new_sessions_allowed_per_event_loop_ > 0;
--new_sessions_allowed_per_event_loop_) {
QuicConnectionId connection_id;
- std::list<BufferedPacket> packets =
+ BufferedPacketList packet_list =
buffered_packets_.DeliverPacketsForNextConnection(&connection_id);
+ const std::list<BufferedPacket>& packets = packet_list.buffered_packets;
if (packets.empty()) {
return;
}
- QuicSession* session =
- CreateQuicSession(connection_id, packets.front().client_address);
+ QuicSession* session = CreateQuicSession(
+ connection_id, packets.front().client_address, packet_list.alpn);
QUIC_DLOG(INFO) << "Created new session for " << connection_id;
session_map_.insert(std::make_pair(connection_id, QuicWrapUnique(session)));
DeliverPacketsToSession(packets, session);
@@ -697,21 +756,15 @@ QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() {
void QuicDispatcher::BufferEarlyPacket(QuicConnectionId connection_id) {
bool is_new_connection = !buffered_packets_.HasBufferedPackets(connection_id);
- if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- is_new_connection &&
+ if (is_new_connection &&
!ShouldCreateOrBufferPacketForConnection(connection_id)) {
- QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_create_session_after_insertion,
- 1, 5);
return;
}
EnqueuePacketResult rs = buffered_packets_.EnqueuePacket(
connection_id, *current_packet_, current_server_address_,
- current_client_address_, /*is_chlo=*/false);
+ current_client_address_, /*is_chlo=*/false, /*alpn=*/"");
if (rs != EnqueuePacketResult::SUCCESS) {
OnBufferPacketFailure(rs, connection_id);
- } else if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- is_new_connection) {
- ShouldCreateOrBufferPacketForConnection(connection_id);
}
}
@@ -728,11 +781,8 @@ void QuicDispatcher::ProcessChlo() {
current_connection_id());
return;
}
- if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- !buffered_packets_.HasBufferedPackets(current_connection_id_) &&
+ if (!buffered_packets_.HasBufferedPackets(current_connection_id_) &&
!ShouldCreateOrBufferPacketForConnection(current_connection_id_)) {
- QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_create_session_after_insertion,
- 2, 5);
return;
}
if (FLAGS_quic_allow_chlo_buffering &&
@@ -740,33 +790,23 @@ void QuicDispatcher::ProcessChlo() {
new_sessions_allowed_per_event_loop_ <= 0) {
// Can't create new session any more. Wait till next event loop.
QUIC_BUG_IF(buffered_packets_.HasChloForConnection(current_connection_id_));
- bool is_new_connection =
- !buffered_packets_.HasBufferedPackets(current_connection_id_);
EnqueuePacketResult rs = buffered_packets_.EnqueuePacket(
current_connection_id_, *current_packet_, current_server_address_,
- current_client_address_, /*is_chlo=*/true);
+ current_client_address_, /*is_chlo=*/true, current_alpn_);
if (rs != EnqueuePacketResult::SUCCESS) {
OnBufferPacketFailure(rs, current_connection_id_);
- } else if (
- !FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- is_new_connection) {
- ShouldCreateOrBufferPacketForConnection(current_connection_id_);
}
return;
}
// Creates a new session and process all buffered packets for this connection.
- QuicSession* session =
- CreateQuicSession(current_connection_id_, current_client_address_);
+ QuicSession* session = CreateQuicSession(
+ current_connection_id_, current_client_address_, current_alpn_);
QUIC_DLOG(INFO) << "Created new session for " << current_connection_id_;
session_map_.insert(
std::make_pair(current_connection_id_, QuicWrapUnique(session)));
std::list<BufferedPacket> packets =
- buffered_packets_.DeliverPackets(current_connection_id_);
- // Check if CHLO is the first packet arrived on this connection.
- if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- packets.empty()) {
- ShouldCreateOrBufferPacketForConnection(current_connection_id_);
- }
+ buffered_packets_.DeliverPackets(current_connection_id_).buffered_packets;
+
// Process CHLO at first.
session->ProcessUdpPacket(current_server_address_, current_client_address_,
*current_packet_);
@@ -847,13 +887,15 @@ void QuicDispatcher::MaybeRejectStatelessly(QuicConnectionId connection_id,
!FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support ||
!ShouldAttemptCheapStatelessRejection()) {
// Not use cheap stateless reject.
+ ChloAlpnExtractor alpn_extractor;
if (FLAGS_quic_allow_chlo_buffering &&
!ChloExtractor::Extract(*current_packet_, GetSupportedVersions(),
- nullptr)) {
+ &alpn_extractor)) {
// Buffer non-CHLO packets.
ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id);
return;
}
+ current_alpn_ = alpn_extractor.ConsumeAlpn();
ProcessUnauthenticatedHeaderFate(kFateProcess, connection_id);
return;
}
@@ -869,6 +911,7 @@ void QuicDispatcher::MaybeRejectStatelessly(QuicConnectionId connection_id,
ProcessUnauthenticatedHeaderFate(kFateBuffer, connection_id);
return;
}
+ current_alpn_ = validator.ConsumeAlpn();
if (!validator.can_accept()) {
// This CHLO is prohibited by policy.
diff --git a/chromium/net/tools/quic/quic_dispatcher.h b/chromium/net/tools/quic/quic_dispatcher.h
index 877e602fac9..13bb50bbf95 100644
--- a/chromium/net/tools/quic/quic_dispatcher.h
+++ b/chromium/net/tools/quic/quic_dispatcher.h
@@ -9,7 +9,6 @@
#define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_
#include <memory>
-#include <unordered_map>
#include <vector>
#include "base/macros.h"
@@ -96,7 +95,7 @@ class QuicDispatcher : public QuicTimeWaitListManager::Visitor,
void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) override;
using SessionMap =
- std::unordered_map<QuicConnectionId, std::unique_ptr<QuicSession>>;
+ QuicUnorderedMap<QuicConnectionId, std::unique_ptr<QuicSession>>;
const SessionMap& session_map() const { return session_map_; }
@@ -162,7 +161,8 @@ class QuicDispatcher : public QuicTimeWaitListManager::Visitor,
protected:
virtual QuicSession* CreateQuicSession(
QuicConnectionId connection_id,
- const QuicSocketAddress& client_address) = 0;
+ const QuicSocketAddress& client_address,
+ QuicStringPiece alpn) = 0;
// Called when a connection is rejected statelessly.
virtual void OnConnectionRejectedStatelessly();
@@ -291,7 +291,7 @@ class QuicDispatcher : public QuicTimeWaitListManager::Visitor,
friend class test::QuicDispatcherPeer;
friend class StatelessRejectorProcessDoneCallback;
- typedef std::unordered_set<QuicConnectionId> QuicConnectionIdSet;
+ typedef QuicUnorderedSet<QuicConnectionId> QuicConnectionIdSet;
bool HandlePacketForTimeWait(const QuicPacketPublicHeader& header);
@@ -377,6 +377,8 @@ class QuicDispatcher : public QuicTimeWaitListManager::Visitor,
QuicSocketAddress current_client_address_;
QuicSocketAddress current_server_address_;
const QuicReceivedPacket* current_packet_;
+ // If |current_packet_| is a CHLO packet, the extracted alpn.
+ std::string current_alpn_;
QuicConnectionId current_connection_id_;
// Used to get the supported versions based on flag. Does not own.
diff --git a/chromium/net/tools/quic/quic_dispatcher_test.cc b/chromium/net/tools/quic/quic_dispatcher_test.cc
index 6e9b8ec7417..6491ebfc7c1 100644
--- a/chromium/net/tools/quic/quic_dispatcher_test.cc
+++ b/chromium/net/tools/quic/quic_dispatcher_test.cc
@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "net/quic/core/crypto/crypto_handshake.h"
+#include "net/quic/core/crypto/crypto_protocol.h"
#include "net/quic/core/crypto/quic_crypto_server_config.h"
#include "net/quic/core/crypto/quic_random.h"
#include "net/quic/core/quic_crypto_stream.h"
@@ -131,9 +132,10 @@ class TestDispatcher : public QuicDispatcher {
std::unique_ptr<QuicEpollAlarmFactory>(
new QuicEpollAlarmFactory(eps))) {}
- MOCK_METHOD2(CreateQuicSession,
+ MOCK_METHOD3(CreateQuicSession,
QuicServerSessionBase*(QuicConnectionId connection_id,
- const QuicSocketAddress& client_address));
+ const QuicSocketAddress& client_address,
+ QuicStringPiece alpn));
MOCK_METHOD1(ShouldCreateOrBufferPacketForConnection,
bool(QuicConnectionId connection_id));
@@ -255,9 +257,8 @@ class QuicDispatcherTest : public QuicTest {
QuicPacketNumber packet_number) {
QuicVersionVector versions(SupportedVersions(version));
std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
- GetPeerInMemoryConnectionId(connection_id), has_version_flag, false,
- packet_number, data, connection_id_length, packet_number_length,
- &versions));
+ connection_id, has_version_flag, false, packet_number, data,
+ connection_id_length, packet_number_length, &versions));
std::unique_ptr<QuicReceivedPacket> received_packet(
ConstructReceivedPacket(*packet, helper_.GetClock()->Now()));
@@ -317,6 +318,7 @@ class QuicDispatcherTest : public QuicTest {
string SerializeCHLO() {
CryptoHandshakeMessage client_hello;
client_hello.set_tag(kCHLO);
+ client_hello.SetStringPiece(kALPN, "hq");
return client_hello.GetSerialized(Perspective::IS_CLIENT)
.AsStringPiece()
.as_string();
@@ -343,7 +345,8 @@ TEST_F(QuicDispatcherTest, ProcessPackets) {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5);
- EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(1, client_address, QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, 1, client_address, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -352,11 +355,13 @@ TEST_F(QuicDispatcherTest, ProcessPackets) {
ProcessUdpPacket(_, _, _))
.WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor(
&QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1))));
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(1));
ProcessPacket(client_address, 1, true, SerializeCHLO());
EXPECT_EQ(client_address, dispatcher_->current_client_address());
EXPECT_EQ(server_address_, dispatcher_->current_server_address());
- EXPECT_CALL(*dispatcher_, CreateQuicSession(2, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(2, client_address, QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, 2, client_address, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -365,6 +370,7 @@ TEST_F(QuicDispatcherTest, ProcessPackets) {
ProcessUdpPacket(_, _, _))
.WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor(
&QuicDispatcherTest::ValidatePacket, base::Unretained(this), 2))));
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(2));
ProcessPacket(client_address, 2, true, SerializeCHLO());
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
@@ -379,7 +385,9 @@ TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5);
- EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0);
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(1, client_address, QuicStringPiece("hq")))
+ .Times(0);
QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
ProcessPacket(client_address, 1, true, version, SerializeCHLO(),
PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
@@ -388,7 +396,8 @@ TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) {
TEST_F(QuicDispatcherTest, Shutdown) {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
- EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(_, client_address, QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, 1, client_address, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -398,6 +407,7 @@ TEST_F(QuicDispatcherTest, Shutdown) {
.WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor(
&QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1))));
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(1));
ProcessPacket(client_address, 1, true, SerializeCHLO());
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
@@ -412,7 +422,8 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) {
// Create a new session.
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
QuicConnectionId connection_id = 1;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, connection_id, client_address,
&mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -422,6 +433,7 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) {
.WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor(
&QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1))));
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(1));
ProcessPacket(client_address, connection_id, true, SerializeCHLO());
// Close the connection by sending public reset packet.
@@ -464,7 +476,8 @@ TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) {
QuicConnectionId connection_id = 1;
// Dispatcher forwards all packets for this connection_id to the time wait
// list manager.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0);
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, QuicStringPiece("hq")))
+ .Times(0);
EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, connection_id))
.Times(1);
EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
@@ -479,7 +492,9 @@ TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5);
// dispatcher_ should drop this packet.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0);
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(1, client_address, QuicStringPiece("hq")))
+ .Times(0);
EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _)).Times(0);
EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
.Times(0);
@@ -491,7 +506,8 @@ TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
QuicConnectionId connection_id = 1;
server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5);
- EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(1, client_address, QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, 1, client_address, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -502,6 +518,8 @@ TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
&QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1))));
// A packet whose packet number is the largest that is allowed to start a
// connection.
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id));
ProcessPacket(client_address, connection_id, true, SerializeCHLO(),
PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
QuicDispatcher::kMaxReasonableInitialPacketNumber);
@@ -516,7 +534,8 @@ TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
QuicConnectionId connection_id = 1;
// Dispatcher forwards this packet for this connection_id to the time wait
// list manager.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0);
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, QuicStringPiece("hq")))
+ .Times(0);
EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, connection_id))
.Times(1);
EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
@@ -538,13 +557,15 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5);
QuicConnectionId connection_id = 1;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.Times(0);
ProcessPacket(client_address, connection_id, true,
static_cast<QuicVersion>(QuicVersionMin() - 1), SerializeCHLO(),
PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
++connection_id;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, connection_id, client_address,
&mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -554,11 +575,14 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
.WillOnce(testing::WithArgs<2>(
Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
base::Unretained(this), connection_id))));
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id));
ProcessPacket(client_address, connection_id, true, QuicVersionMin(),
SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
PACKET_6BYTE_PACKET_NUMBER, 1);
++connection_id;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, connection_id, client_address,
&mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -568,13 +592,16 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
.WillOnce(testing::WithArgs<2>(
Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
base::Unretained(this), connection_id))));
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id));
ProcessPacket(client_address, connection_id, true, QuicVersionMax(),
SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
PACKET_6BYTE_PACKET_NUMBER, 1);
// Turn off version 40.
SetQuicFlag(&FLAGS_quic_enable_version_40, false);
++connection_id;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.Times(0);
ProcessPacket(client_address, connection_id, true, QUIC_VERSION_40,
SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
@@ -583,7 +610,8 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
// Turn on version 40.
SetQuicFlag(&FLAGS_quic_enable_version_40, true);
++connection_id;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, connection_id, client_address,
&mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -593,6 +621,8 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
.WillOnce(testing::WithArgs<2>(
Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
base::Unretained(this), connection_id))));
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id));
ProcessPacket(client_address, connection_id, true, QUIC_VERSION_40,
SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
PACKET_6BYTE_PACKET_NUMBER, 1);
@@ -600,7 +630,8 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
// Turn off version 39.
FLAGS_quic_reloadable_flag_quic_enable_version_39 = false;
++connection_id;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.Times(0);
ProcessPacket(client_address, connection_id, true, QUIC_VERSION_39,
SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
@@ -609,7 +640,8 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
// Turn on version 39.
FLAGS_quic_reloadable_flag_quic_enable_version_39 = true;
++connection_id;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, connection_id, client_address,
&mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -619,6 +651,8 @@ TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
.WillOnce(testing::WithArgs<2>(
Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
base::Unretained(this), connection_id))));
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id));
ProcessPacket(client_address, connection_id, true, QUIC_VERSION_39,
SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
PACKET_6BYTE_PACKET_NUMBER, 1);
@@ -636,12 +670,17 @@ class MockQuicCryptoServerStream : public QuicCryptoServerStream {
compressed_certs_cache,
FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support,
session,
- helper) {}
+ helper),
+ handshake_confirmed_(false) {}
+
void set_handshake_confirmed_for_testing(bool handshake_confirmed) {
handshake_confirmed_ = handshake_confirmed;
}
+ bool handshake_confirmed() const override { return handshake_confirmed_; }
+
private:
+ bool handshake_confirmed_;
DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream);
};
@@ -659,7 +698,7 @@ struct StatelessRejectTestParams {
<< p.enable_stateless_rejects_via_flag << std::endl;
os << " client_supports_statelesss_rejects: "
<< p.client_supports_statelesss_rejects << std::endl;
- os << " crypto_handshake_successful: " << p.crypto_handshake_successful
+ os << " crypto_handshake_successful: " << p.crypto_handshake_successful
<< " }";
return os;
}
@@ -752,7 +791,8 @@ TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
QuicConnectionId connection_id = 1;
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("hq")))
.WillOnce(testing::Return(
CreateSessionBasedOnTestParams(connection_id, client_address)));
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
@@ -760,9 +800,15 @@ TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) {
.WillOnce(testing::WithArgs<2>(
Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
base::Unretained(this), connection_id))));
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id))
+ .Times(1);
+
// Process the first packet for the connection.
ProcessPacket(client_address, connection_id, true, SerializeCHLO());
if (ExpectStatelessReject()) {
+ EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
+ CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, _, _));
// If this is a stateless reject, the crypto stream will close the
// connection.
session1_->connection()->CloseConnection(
@@ -797,10 +843,12 @@ TEST_P(QuicDispatcherStatelessRejectTest, CheapRejects) {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
QuicConnectionId connection_id = 1;
if (GetParam().enable_stateless_rejects_via_flag) {
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(connection_id, client_address, _))
.Times(0);
} else {
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("h2")))
.WillOnce(testing::Return(
CreateSessionBasedOnTestParams(connection_id, client_address)));
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
@@ -817,9 +865,18 @@ TEST_P(QuicDispatcherStatelessRejectTest, CheapRejects) {
{"KEXS", "C255"},
{"COPT", "SREJ"},
{"NONC", "1234567890123456789012"},
+ {"ALPN", "h2"},
{"VER\0", "Q025"}},
kClientHelloMinimumSize);
+ if (GetParam().enable_stateless_rejects_via_flag) {
+ EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, connection_id))
+ .Times(1);
+ } else {
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id))
+ .Times(1);
+ }
ProcessPacket(client_address, connection_id, true,
client_hello.GetSerialized(Perspective::IS_CLIENT)
.AsStringPiece()
@@ -838,40 +895,45 @@ TEST_P(QuicDispatcherStatelessRejectTest, BufferNonChlo) {
const QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
const QuicConnectionId connection_id = 1;
+ EXPECT_CALL(*dispatcher_,
+ ShouldCreateOrBufferPacketForConnection(connection_id))
+ .Times(1);
ProcessPacket(client_address, connection_id, true, "NOT DATA FOR A CHLO");
// Process the first packet for the connection.
- CryptoHandshakeMessage client_hello =
- crypto_test_utils::CreateCHLO({{"AEAD", "AESG"},
- {"KEXS", "C255"},
- {"NONC", "1234567890123456789012"},
- {"VER\0", "Q025"}},
- kClientHelloMinimumSize);
-
- // If stateless rejects are enabled then a connection will be created now
- // and the buffered packet will be processed
- EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
- .WillOnce(testing::Return(
- CreateSessionBasedOnTestParams(connection_id, client_address)));
- EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
- ProcessUdpPacket(_, client_address, _))
- .WillOnce(testing::WithArg<2>(
- Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
- base::Unretained(this), connection_id))));
- // Expect both packets to be passed to ProcessUdpPacket(). And one of them
- // is already expected in CreateSessionBasedOnTestParams().
- EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
- ProcessUdpPacket(_, client_address, _))
- .WillOnce(testing::WithArg<2>(
- Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
- base::Unretained(this), connection_id))))
- .RetiresOnSaturation();
- ProcessPacket(client_address, connection_id, true,
- client_hello.GetSerialized(Perspective::IS_CLIENT)
- .AsStringPiece()
- .as_string());
- EXPECT_FALSE(
- time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
+ CryptoHandshakeMessage client_hello =
+ crypto_test_utils::CreateCHLO({{"AEAD", "AESG"},
+ {"KEXS", "C255"},
+ {"NONC", "1234567890123456789012"},
+ {"ALPN", "h3"},
+ {"VER\0", "Q025"}},
+ kClientHelloMinimumSize);
+
+ // If stateless rejects are enabled then a connection will be created now
+ // and the buffered packet will be processed
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address,
+ QuicStringPiece("h3")))
+ .WillOnce(testing::Return(
+ CreateSessionBasedOnTestParams(connection_id, client_address)));
+ EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
+ ProcessUdpPacket(_, client_address, _))
+ .WillOnce(testing::WithArg<2>(
+ Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
+ base::Unretained(this), connection_id))));
+ // Expect both packets to be passed to ProcessUdpPacket(). And one of them
+ // is already expected in CreateSessionBasedOnTestParams().
+ EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
+ ProcessUdpPacket(_, client_address, _))
+ .WillOnce(testing::WithArg<2>(
+ Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
+ base::Unretained(this), connection_id))))
+ .RetiresOnSaturation();
+ ProcessPacket(client_address, connection_id, true,
+ client_hello.GetSerialized(Perspective::IS_CLIENT)
+ .AsStringPiece()
+ .as_string());
+ EXPECT_FALSE(
+ time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
}
// Verify the stopgap test: Packets with truncated connection IDs should be
@@ -886,7 +948,8 @@ TEST_F(QuicDispatcherTestStrayPacketConnectionId,
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
QuicConnectionId connection_id = 1;
// Dispatcher drops this packet.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0);
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, QuicStringPiece("hq")))
+ .Times(0);
EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, connection_id))
.Times(0);
EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
@@ -926,7 +989,8 @@ class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
- EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(_, client_address, QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, 1, client_address, &helper_,
&alarm_factory_, &crypto_config_,
@@ -935,9 +999,11 @@ class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
ProcessUdpPacket(_, _, _))
.WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor(
&QuicDispatcherTest::ValidatePacket, base::Unretained(this), 1))));
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(1));
ProcessPacket(client_address, 1, true, SerializeCHLO());
- EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(_, client_address, QuicStringPiece("hq")))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, 2, client_address, &helper_,
&alarm_factory_, &crypto_config_,
@@ -946,6 +1012,7 @@ class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
ProcessUdpPacket(_, _, _))
.WillOnce(testing::WithArgs<2>(Invoke(CreateFunctor(
&QuicDispatcherTest::ValidatePacket, base::Unretained(this), 2))));
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(2));
ProcessPacket(client_address, 2, true, SerializeCHLO());
blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(dispatcher_.get());
@@ -1208,7 +1275,8 @@ TEST_P(BufferedPacketStoreTest, ProcessNonChloPacketsUptoLimitAndProcessChlo) {
data_connection_map_[conn_id].pop_back();
// When CHLO arrives, a new session should be created, and all packets
// buffered should be delivered to the session.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_address, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_address, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -1238,18 +1306,7 @@ TEST_P(BufferedPacketStoreTest,
for (size_t i = 1; i <= kNumConnections; ++i) {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), i);
QuicConnectionId conn_id = i;
- if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion) {
- EXPECT_CALL(*dispatcher_,
- ShouldCreateOrBufferPacketForConnection(conn_id));
- } else {
- if (i <= kNumConnections - 1) {
- // As they are on different connection, they should trigger
- // ShouldCreateOrBufferPacketForConnection(). The last packet should be
- // dropped.
- EXPECT_CALL(*dispatcher_,
- ShouldCreateOrBufferPacketForConnection(conn_id));
- }
- }
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id));
ProcessPacket(client_address, conn_id, true,
QuicStrCat("data packet on connection ", i),
PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
@@ -1268,26 +1325,16 @@ TEST_P(BufferedPacketStoreTest,
for (size_t i = 1; i <= kNumConnections; ++i) {
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), i);
QuicConnectionId conn_id = i;
- if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- conn_id == kNumConnections) {
- // The last CHLO should trigger ShouldCreateOrBufferPacketForConnection()
- // since it's the
- // first packet arrives on that connection.
+ if (conn_id == kNumConnections) {
EXPECT_CALL(*dispatcher_,
ShouldCreateOrBufferPacketForConnection(conn_id));
}
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_address, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_address, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
- if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- conn_id == kNumConnections) {
- // The last CHLO should trigger ShouldCreateOrBufferPacketForConnection()
- // since it's the first packet arrives on that connection.
- EXPECT_CALL(*dispatcher_,
- ShouldCreateOrBufferPacketForConnection(conn_id));
- }
// First |kNumConnections| - 1 connections should have buffered
// a packet in store. The rest should have been dropped.
size_t upper_limit =
@@ -1310,7 +1357,8 @@ TEST_P(BufferedPacketStoreTest, DeliverEmptyPackets) {
QuicConnectionId conn_id = 1;
QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_address, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_address, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -1331,7 +1379,8 @@ TEST_P(BufferedPacketStoreTest, ReceiveRetransmittedCHLO) {
// When CHLO arrives, a new session should be created, and all packets
// buffered should be delivered to the session.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_address))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_address, QuicStringPiece()))
.Times(1) // Only triggered by 1st CHLO.
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_address, &mock_helper_,
@@ -1388,19 +1437,10 @@ TEST_P(BufferedPacketStoreTest, ProcessCHLOsUptoLimitAndBufferTheRest) {
const size_t kNumCHLOs =
kMaxNumSessionsToCreate + kDefaultMaxConnectionsInStore + 1;
for (size_t conn_id = 1; conn_id <= kNumCHLOs; ++conn_id) {
- if (FLAGS_quic_reloadable_flag_quic_create_session_after_insertion) {
- EXPECT_CALL(*dispatcher_,
- ShouldCreateOrBufferPacketForConnection(conn_id));
- }
- if (!FLAGS_quic_reloadable_flag_quic_create_session_after_insertion &&
- conn_id < kNumCHLOs) {
- // Except the last connection, all connections for previous CHLOs should
- // be regarded as newly added.
- EXPECT_CALL(*dispatcher_,
- ShouldCreateOrBufferPacketForConnection(conn_id));
- }
+ EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id));
if (conn_id <= kMaxNumSessionsToCreate) {
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_addr_, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -1429,7 +1469,8 @@ TEST_P(BufferedPacketStoreTest, ProcessCHLOsUptoLimitAndBufferTheRest) {
for (size_t conn_id = kMaxNumSessionsToCreate + 1;
conn_id <= kMaxNumSessionsToCreate + kDefaultMaxConnectionsInStore;
++conn_id) {
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_addr_, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -1440,7 +1481,8 @@ TEST_P(BufferedPacketStoreTest, ProcessCHLOsUptoLimitAndBufferTheRest) {
Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
base::Unretained(this), conn_id))));
}
- EXPECT_CALL(*dispatcher_, CreateQuicSession(kNumCHLOs, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(kNumCHLOs, client_addr_, QuicStringPiece()))
.Times(0);
while (store->HasChlosBuffered()) {
@@ -1459,7 +1501,8 @@ TEST_P(BufferedPacketStoreTest, BufferDuplicatedCHLO) {
++conn_id) {
// Last CHLO will be buffered. Others will create connection right away.
if (conn_id <= kMaxNumSessionsToCreate) {
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_addr_, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -1480,7 +1523,8 @@ TEST_P(BufferedPacketStoreTest, BufferDuplicatedCHLO) {
size_t packets_buffered = 2;
// Reset counter and process buffered CHLO.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection, client_addr_))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection, client_addr_,
+ QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, last_connection, client_addr_,
&mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -1501,7 +1545,8 @@ TEST_P(BufferedPacketStoreTest, BufferNonChloPacketsUptoLimitWithChloBuffered) {
for (QuicConnectionId conn_id = 1; conn_id <= last_connection_id; ++conn_id) {
// Last CHLO will be buffered. Others will create connection right away.
if (conn_id <= kMaxNumSessionsToCreate) {
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_addr_, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -1524,7 +1569,8 @@ TEST_P(BufferedPacketStoreTest, BufferNonChloPacketsUptoLimitWithChloBuffered) {
}
// Reset counter and process buffered CHLO.
- EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection_id, client_addr_))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection_id, client_addr_,
+ QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, last_connection_id, client_addr_,
&mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -1558,7 +1604,8 @@ TEST_P(BufferedPacketStoreTest, ReceiveCHLOForBufferedConnection) {
conn_id <= kDefaultMaxConnectionsInStore + kMaxNumSessionsToCreate;
++conn_id) {
if (conn_id <= kMaxNumSessionsToCreate + 1) {
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_addr_, QuicStringPiece()))
.WillOnce(testing::Return(CreateSession(
dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
&mock_alarm_factory_, &crypto_config_,
@@ -1591,7 +1638,6 @@ class AsyncGetProofTest : public QuicDispatcherTest {
signed_config_(new QuicSignedServerConfig) {
FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support = true;
FLAGS_quic_reloadable_flag_quic_use_cheap_stateless_rejects = true;
- FLAGS_quic_reloadable_flag_quic_create_session_after_insertion = true;
}
void SetUp() override {
@@ -1602,6 +1648,7 @@ class AsyncGetProofTest : public QuicDispatcherTest {
chlo_ = crypto_test_utils::GenerateDefaultInchoateCHLO(clock_, version,
&crypto_config_);
chlo_.SetVector(net::kCOPT, net::QuicTagVector{net::kSREJ});
+ chlo_.SetStringPiece(kALPN, "HTTP/1");
// Pass an inchoate CHLO.
crypto_test_utils::GenerateFullCHLO(
chlo_, &crypto_config_, server_addr_, client_addr_, version, clock_,
@@ -1683,7 +1730,8 @@ TEST_F(AsyncGetProofTest, BasicAccept) {
EXPECT_CALL(check, Call(1));
EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_,
+ QuicStringPiece("HTTP/1")))
.WillOnce(testing::Return(GetSession(conn_id)));
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(
GetSession(conn_id)->connection()),
@@ -1733,7 +1781,8 @@ TEST_F(AsyncGetProofTest, BasicReject) {
ProcessPacket(_, client_addr_, conn_id));
EXPECT_CALL(check, Call(2));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_addr_, QuicStringPiece("hq")))
.Times(0);
EXPECT_CALL(*time_wait_list_manager_,
ProcessPacket(_, client_addr_, conn_id));
@@ -1768,7 +1817,8 @@ TEST_F(AsyncGetProofTest, MultipleAccept) {
EXPECT_CALL(check, Call(1));
EXPECT_CALL(*dispatcher_,
ShouldCreateOrBufferPacketForConnection(conn_id_2));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_2, client_addr_))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_2, client_addr_,
+ QuicStringPiece("HTTP/1")))
.WillOnce(testing::Return(GetSession(conn_id_2)));
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(
GetSession(conn_id_2)->connection()),
@@ -1790,7 +1840,8 @@ TEST_F(AsyncGetProofTest, MultipleAccept) {
ShouldCreateOrBufferPacketForConnection(conn_id_1));
EXPECT_CALL(check, Call(4));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_1, client_addr_))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_1, client_addr_,
+ QuicStringPiece("HTTP/1")))
.WillOnce(testing::Return(GetSession(conn_id_1)));
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(
GetSession(conn_id_1)->connection()),
@@ -1847,7 +1898,7 @@ TEST_F(AsyncGetProofTest, MultipleReject) {
InSequence s;
EXPECT_CALL(check, Call(1));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_2, client_addr_))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_2, client_addr_, _))
.Times(0);
EXPECT_CALL(*time_wait_list_manager_,
AddConnectionIdToTimeWait(conn_id_2, _, true, _));
@@ -1920,7 +1971,8 @@ TEST_F(AsyncGetProofTest, MultipleIdenticalReject) {
ShouldCreateOrBufferPacketForConnection(conn_id_1));
EXPECT_CALL(check, Call(2));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id_1, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id_1, client_addr_, QuicStringPiece()))
.Times(0);
EXPECT_CALL(*time_wait_list_manager_,
AddConnectionIdToTimeWait(conn_id_1, _, true, _));
@@ -1966,7 +2018,8 @@ TEST_F(AsyncGetProofTest, BufferTimeout) {
EXPECT_CALL(check, Call(2));
EXPECT_CALL(*time_wait_list_manager_,
ProcessPacket(_, client_addr_, conn_id));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_,
+ CreateQuicSession(conn_id, client_addr_, QuicStringPiece()))
.Times(0);
}
@@ -2018,7 +2071,8 @@ TEST_F(AsyncGetProofTest, TimeWaitTimeout) {
EXPECT_CALL(check, Call(2));
EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(conn_id));
- EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_))
+ EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, client_addr_,
+ QuicStringPiece("HTTP/1")))
.WillOnce(testing::Return(GetSession(conn_id)));
EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(
GetSession(conn_id)->connection()),
diff --git a/chromium/net/tools/quic/quic_http_response_cache.h b/chromium/net/tools/quic/quic_http_response_cache.h
index 5c8f6ea7798..fe9360489ec 100644
--- a/chromium/net/tools/quic/quic_http_response_cache.h
+++ b/chromium/net/tools/quic/quic_http_response_cache.h
@@ -9,12 +9,12 @@
#include <map>
#include <memory>
#include <string>
-#include <unordered_map>
#include <vector>
#include "base/files/file_path.h"
#include "base/macros.h"
#include "net/quic/core/spdy_utils.h"
+#include "net/quic/platform/api/quic_containers.h"
#include "net/quic/platform/api/quic_mutex.h"
#include "net/quic/platform/api/quic_string_piece.h"
#include "net/quic/platform/api/quic_url.h"
@@ -203,7 +203,7 @@ class QuicHttpResponseCache {
ServerPushInfo resource);
// Cached responses.
- std::unordered_map<std::string, std::unique_ptr<Response>> responses_
+ QuicUnorderedMap<std::string, std::unique_ptr<Response>> responses_
GUARDED_BY(response_mutex_);
// The default response for cache misses, if set.
diff --git a/chromium/net/tools/quic/quic_server_test.cc b/chromium/net/tools/quic/quic_server_test.cc
index 6c0037a3e85..5c923d9bd44 100644
--- a/chromium/net/tools/quic/quic_server_test.cc
+++ b/chromium/net/tools/quic/quic_server_test.cc
@@ -10,6 +10,7 @@
#include "net/quic/platform/api/quic_logging.h"
#include "net/quic/platform/api/quic_socket_address.h"
#include "net/quic/platform/api/quic_test.h"
+#include "net/quic/platform/api/quic_test_loopback.h"
#include "net/quic/test_tools/crypto_test_utils.h"
#include "net/quic/test_tools/mock_quic_dispatcher.h"
#include "net/tools/quic/quic_epoll_alarm_factory.h"
@@ -124,7 +125,9 @@ TEST_F(QuicServerEpollInTest, ProcessBufferedCHLOsOnEpollin) {
DoAll(testing::Assign(&more_chlos, false), testing::Return(false)));
// Send a packet to trigger epoll event.
- int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
+ int fd = socket(
+ AddressFamilyUnderTest() == IpAddressFamily::IP_V4 ? AF_INET : AF_INET6,
+ SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
ASSERT_LT(0, fd);
char buf[1024];
diff --git a/chromium/net/tools/quic/quic_simple_dispatcher.cc b/chromium/net/tools/quic/quic_simple_dispatcher.cc
index e173624489e..8b8e59c85e5 100644
--- a/chromium/net/tools/quic/quic_simple_dispatcher.cc
+++ b/chromium/net/tools/quic/quic_simple_dispatcher.cc
@@ -48,7 +48,8 @@ void QuicSimpleDispatcher::OnRstStreamReceived(
QuicServerSessionBase* QuicSimpleDispatcher::CreateQuicSession(
QuicConnectionId connection_id,
- const QuicSocketAddress& client_address) {
+ const QuicSocketAddress& client_address,
+ QuicStringPiece /*alpn*/) {
// The QuicServerSessionBase takes ownership of |connection| below.
QuicConnection* connection = new QuicConnection(
connection_id, client_address, helper(), alarm_factory(),
diff --git a/chromium/net/tools/quic/quic_simple_dispatcher.h b/chromium/net/tools/quic/quic_simple_dispatcher.h
index 41d24cfb33b..04e1252684b 100644
--- a/chromium/net/tools/quic/quic_simple_dispatcher.h
+++ b/chromium/net/tools/quic/quic_simple_dispatcher.h
@@ -31,7 +31,8 @@ class QuicSimpleDispatcher : public QuicDispatcher {
protected:
QuicServerSessionBase* CreateQuicSession(
QuicConnectionId connection_id,
- const QuicSocketAddress& client_address) override;
+ const QuicSocketAddress& client_address,
+ QuicStringPiece alpn) override;
QuicHttpResponseCache* response_cache() { return response_cache_; }
diff --git a/chromium/net/tools/quic/quic_simple_server_session_test.cc b/chromium/net/tools/quic/quic_simple_server_session_test.cc
index 85e80ad30b5..3349def6676 100644
--- a/chromium/net/tools/quic/quic_simple_server_session_test.cc
+++ b/chromium/net/tools/quic/quic_simple_server_session_test.cc
@@ -103,10 +103,17 @@ class MockQuicCryptoServerStream : public QuicCryptoServerStream {
void(const CachedNetworkParameters* cached_network_parameters));
void set_encryption_established(bool has_established) {
- encryption_established_ = has_established;
+ encryption_established_override_ = has_established;
+ }
+
+ bool encryption_established() const override {
+ return QuicCryptoServerStream::encryption_established() ||
+ encryption_established_override_;
}
private:
+ bool encryption_established_override_ = false;
+
DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream);
};
diff --git a/chromium/net/tools/quic/quic_simple_server_stream_test.cc b/chromium/net/tools/quic/quic_simple_server_stream_test.cc
index 93b06cf5280..c1add55c19a 100644
--- a/chromium/net/tools/quic/quic_simple_server_stream_test.cc
+++ b/chromium/net/tools/quic/quic_simple_server_stream_test.cc
@@ -43,7 +43,7 @@ class QuicSimpleServerStreamPeer : public QuicSimpleServerStream {
QuicHttpResponseCache* response_cache)
: QuicSimpleServerStream(stream_id, session, response_cache) {}
- ~QuicSimpleServerStreamPeer() override{};
+ ~QuicSimpleServerStreamPeer() override {}
using QuicSimpleServerStream::SendResponse;
using QuicSimpleServerStream::SendErrorResponse;
diff --git a/chromium/net/tools/quic/quic_time_wait_list_manager_test.cc b/chromium/net/tools/quic/quic_time_wait_list_manager_test.cc
index e81ffaed353..c9e7a8ea067 100644
--- a/chromium/net/tools/quic/quic_time_wait_list_manager_test.cc
+++ b/chromium/net/tools/quic/quic_time_wait_list_manager_test.cc
@@ -154,8 +154,7 @@ class ValidatePublicResetPacketPredicate
std::tr1::get<1>(packet_buffer));
framer.ProcessPacket(encrypted);
QuicPublicResetPacket packet = visitor.public_reset_packet();
- return connection_id_ == GetPeerInMemoryConnectionId(
- packet.public_header.connection_id) &&
+ return connection_id_ == packet.public_header.connection_id &&
packet.public_header.reset_flag &&
!packet.public_header.version_flag &&
net::test::TestPeerIPAddress() == packet.client_address.host() &&
diff --git a/chromium/net/tools/quic/stateless_rejector_test.cc b/chromium/net/tools/quic/stateless_rejector_test.cc
index 190121cb48a..20fe8bce86b 100644
--- a/chromium/net/tools/quic/stateless_rejector_test.cc
+++ b/chromium/net/tools/quic/stateless_rejector_test.cc
@@ -239,11 +239,9 @@ TEST_P(StatelessRejectorTest, RejectChlo) {
ASSERT_EQ(StatelessRejector::REJECTED, rejector_->state());
const CryptoHandshakeMessage& reply = rejector_->reply();
EXPECT_EQ(kSREJ, reply.tag());
- const uint32_t* reject_reasons;
- size_t num_reject_reasons;
- EXPECT_EQ(QUIC_NO_ERROR,
- reply.GetTaglist(kRREJ, &reject_reasons, &num_reject_reasons));
- EXPECT_EQ(1u, num_reject_reasons);
+ QuicTagVector reject_reasons;
+ EXPECT_EQ(QUIC_NO_ERROR, reply.GetTaglist(kRREJ, &reject_reasons));
+ EXPECT_EQ(1u, reject_reasons.size());
EXPECT_EQ(INVALID_EXPECTED_LEAF_CERTIFICATE,
static_cast<HandshakeFailureReason>(reject_reasons[0]));
}
diff --git a/chromium/net/tools/quic/test_tools/quic_test_server.cc b/chromium/net/tools/quic/test_tools/quic_test_server.cc
index a99706f96b3..a2a497377e6 100644
--- a/chromium/net/tools/quic/test_tools/quic_test_server.cc
+++ b/chromium/net/tools/quic/test_tools/quic_test_server.cc
@@ -95,13 +95,13 @@ class QuicTestDispatcher : public QuicSimpleDispatcher {
stream_factory_(nullptr),
crypto_stream_factory_(nullptr) {}
- QuicServerSessionBase* CreateQuicSession(
- QuicConnectionId id,
- const QuicSocketAddress& client) override {
+ QuicServerSessionBase* CreateQuicSession(QuicConnectionId id,
+ const QuicSocketAddress& client,
+ QuicStringPiece alpn) override {
QuicReaderMutexLock lock(&factory_lock_);
if (session_factory_ == nullptr && stream_factory_ == nullptr &&
crypto_stream_factory_ == nullptr) {
- return QuicSimpleDispatcher::CreateQuicSession(id, client);
+ return QuicSimpleDispatcher::CreateQuicSession(id, client, alpn);
}
QuicConnection* connection = new QuicConnection(
id, client, helper(), alarm_factory(), CreatePerConnectionWriter(),
diff --git a/chromium/net/tools/quic/test_tools/server_thread.h b/chromium/net/tools/quic/test_tools/server_thread.h
index 1c20ccddc89..287eb181a9a 100644
--- a/chromium/net/tools/quic/test_tools/server_thread.h
+++ b/chromium/net/tools/quic/test_tools/server_thread.h
@@ -8,6 +8,7 @@
#include <memory>
#include "base/macros.h"
+#include "base/synchronization/waitable_event.h"
#include "base/threading/simple_thread.h"
#include "net/quic/core/quic_config.h"
#include "net/quic/platform/api/quic_mutex.h"