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.cc b/quic/core/quic_utils.cc
index 6aaa67b..d03cc0e 100644
--- a/quic/core/quic_utils.cc
+++ b/quic/core/quic_utils.cc
@@ -8,6 +8,7 @@
#include <cstdint>
#include <string>
+#include "net/third_party/quiche/src/quic/core/quic_connection_id.h"
#include "net/third_party/quiche/src/quic/core/quic_constants.h"
#include "net/third_party/quiche/src/quic/core/quic_types.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_aligned.h"
@@ -456,15 +457,37 @@
// static
QuicConnectionId QuicUtils::CreateRandomConnectionId() {
- return CreateRandomConnectionId(QuicRandom::GetInstance());
+ return CreateRandomConnectionId(kQuicDefaultConnectionIdLength,
+ QuicRandom::GetInstance());
}
// static
QuicConnectionId QuicUtils::CreateRandomConnectionId(QuicRandom* random) {
- char connection_id_bytes[kQuicDefaultConnectionIdLength];
- random->RandBytes(connection_id_bytes, QUIC_ARRAYSIZE(connection_id_bytes));
+ return CreateRandomConnectionId(kQuicDefaultConnectionIdLength, random);
+}
+// static
+QuicConnectionId QuicUtils::CreateRandomConnectionId(
+ uint8_t connection_id_length) {
+ return CreateRandomConnectionId(connection_id_length,
+ QuicRandom::GetInstance());
+}
+
+// static
+QuicConnectionId QuicUtils::CreateRandomConnectionId(
+ uint8_t connection_id_length,
+ QuicRandom* random) {
+ if (connection_id_length == 0) {
+ return EmptyQuicConnectionId();
+ }
+ if (connection_id_length > kQuicMaxConnectionIdLength) {
+ QUIC_BUG << "Tried to CreateRandomConnectionId of invalid length "
+ << static_cast<int>(connection_id_length);
+ connection_id_length = kQuicMaxConnectionIdLength;
+ }
+ char connection_id_bytes[kQuicMaxConnectionIdLength];
+ random->RandBytes(connection_id_bytes, connection_id_length);
return QuicConnectionId(static_cast<char*>(connection_id_bytes),
- QUIC_ARRAYSIZE(connection_id_bytes));
+ connection_id_length);
}
// static