Allow QUIC server to replace connection IDs
This CL changes the QuicDispatcher to have it replace the connection ID provided by the client if its length differs from what the dispatcher was configured with. It also changes QuicConnection on the client side to accept connection ID changes coming from the server, and replace its own connection ID to match what the server expects on outgoing packets. This checks VariableLengthConnectionIdAllowedForVersion() so it only impacts v99.
gfe-relnote: v99-only change, not flag protected
PiperOrigin-RevId: 239328650
Change-Id: I21ee0c0ca74c7624823c38a72f323ae6491e21e6
diff --git a/quic/core/quic_utils_test.cc b/quic/core/quic_utils_test.cc
index 6ee6a2a..d0ce7e8 100644
--- a/quic/core/quic_utils_test.cc
+++ b/quic/core/quic_utils_test.cc
@@ -177,6 +177,28 @@
EXPECT_NE(connection_id, EmptyQuicConnectionId());
EXPECT_NE(connection_id, TestConnectionId());
EXPECT_NE(connection_id, TestConnectionId(1));
+ EXPECT_NE(connection_id, TestConnectionIdNineBytesLong(1));
+ EXPECT_EQ(QuicUtils::CreateRandomConnectionId().length(),
+ kQuicDefaultConnectionIdLength);
+}
+
+TEST_F(QuicUtilsTest, RandomConnectionIdVariableLength) {
+ MockRandom random(1337);
+ const uint8_t connection_id_length = 9;
+ QuicConnectionId connection_id =
+ QuicUtils::CreateRandomConnectionId(connection_id_length, &random);
+ EXPECT_EQ(connection_id.length(), connection_id_length);
+ char connection_id_bytes[connection_id_length];
+ random.RandBytes(connection_id_bytes, QUIC_ARRAYSIZE(connection_id_bytes));
+ EXPECT_EQ(connection_id,
+ QuicConnectionId(static_cast<char*>(connection_id_bytes),
+ QUIC_ARRAYSIZE(connection_id_bytes)));
+ EXPECT_NE(connection_id, EmptyQuicConnectionId());
+ EXPECT_NE(connection_id, TestConnectionId());
+ EXPECT_NE(connection_id, TestConnectionId(1));
+ EXPECT_NE(connection_id, TestConnectionIdNineBytesLong(1));
+ EXPECT_EQ(QuicUtils::CreateRandomConnectionId(connection_id_length).length(),
+ connection_id_length);
}
TEST_F(QuicUtilsTest, VariableLengthConnectionId) {