Add ShouldUpdateExpectedConnectionIdLength to QuicFramer

ShouldUpdateExpectedConnectionIdLength allows clients of QuicDispatcher like Quartc to have the QuicFramer owned by the QuicDispatcher dynamically change its expected connection ID length based on received long header packets. This will allow quartc to migrate to 0-length connection IDs.

gfe-relnote: refactor-only, no behavior change, not flag protected
PiperOrigin-RevId: 237882443
Change-Id: If7a49b092e1ff29fec740a18bbb7c5b78d749d62
diff --git a/quic/core/quic_framer.cc b/quic/core/quic_framer.cc
index 22d0ecf..32d50c5 100644
--- a/quic/core/quic_framer.cc
+++ b/quic/core/quic_framer.cc
@@ -473,7 +473,8 @@
       data_producer_(nullptr),
       infer_packet_header_type_from_version_(perspective ==
                                              Perspective::IS_CLIENT),
-      expected_connection_id_length_(expected_connection_id_length) {
+      expected_connection_id_length_(expected_connection_id_length),
+      should_update_expected_connection_id_length_(false) {
   DCHECK(!supported_versions.empty());
   version_ = supported_versions_[0];
   decrypter_ = QuicMakeUnique<NullDecrypter>(perspective);
@@ -2565,12 +2566,20 @@
     if (dcil != 0) {
       dcil += kConnectionIdLengthAdjustment;
     }
+    if (should_update_expected_connection_id_length_ &&
+        expected_connection_id_length_ != dcil) {
+      QUIC_DVLOG(1) << ENDPOINT << "Updating expected_connection_id_length: "
+                    << static_cast<int>(expected_connection_id_length_)
+                    << " -> " << static_cast<int>(dcil);
+      expected_connection_id_length_ = dcil;
+    }
     uint8_t scil = connection_id_lengths_byte & kSourceConnectionIdLengthMask;
     if (scil != 0) {
       scil += kConnectionIdLengthAdjustment;
     }
-    if (dcil != destination_connection_id_length ||
-        scil != source_connection_id_length) {
+    if ((dcil != destination_connection_id_length ||
+         scil != source_connection_id_length) &&
+        !should_update_expected_connection_id_length_) {
       QUIC_DVLOG(1) << "dcil: " << static_cast<uint32_t>(dcil)
                     << ", scil: " << static_cast<uint32_t>(scil);
       set_detailed_error("Invalid ConnectionId length.");