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_connection.h b/quic/core/quic_connection.h
index a2202ee..715a449 100644
--- a/quic/core/quic_connection.h
+++ b/quic/core/quic_connection.h
@@ -30,6 +30,7 @@
 #include "net/third_party/quiche/src/quic/core/quic_alarm.h"
 #include "net/third_party/quiche/src/quic/core/quic_alarm_factory.h"
 #include "net/third_party/quiche/src/quic/core/quic_blocked_writer_interface.h"
+#include "net/third_party/quiche/src/quic/core/quic_connection_id.h"
 #include "net/third_party/quiche/src/quic/core/quic_connection_stats.h"
 #include "net/third_party/quiche/src/quic/core/quic_framer.h"
 #include "net/third_party/quiche/src/quic/core/quic_one_block_arena.h"
@@ -864,6 +865,10 @@
     return sent_packet_manager_.handshake_confirmed();
   }
 
+  // Adds the connection ID to a set of connection IDs that are accepted as
+  // destination on incoming packets.
+  void AddIncomingConnectionId(QuicConnectionId connection_id);
+
  protected:
   // Calls cancel() on all the alarms owned by this connection.
   void CancelAllAlarms();
@@ -1111,6 +1116,9 @@
   // Returns the largest sent packet number that has been ACKed by peer.
   QuicPacketNumber GetLargestAckedPacket() const;
 
+  // Whether incoming_connection_ids_ contains connection_id.
+  bool HasIncomingConnectionId(QuicConnectionId connection_id);
+
   QuicFramer framer_;
 
   // Contents received in the current packet, especially used to identify
@@ -1136,7 +1144,7 @@
   const QuicClock* clock_;
   QuicRandom* random_generator_;
 
-  const QuicConnectionId connection_id_;
+  QuicConnectionId connection_id_;
   // Address on the last successfully processed packet received from the
   // direct peer.
   QuicSocketAddress self_address_;
@@ -1463,6 +1471,11 @@
   // saved and responded to.
   QuicDeque<QuicPathFrameBuffer> received_path_challenge_payloads_;
 
+  // Set of connection IDs that should be accepted as destination on
+  // received packets. This is conceptually a set but is implemented as a
+  // vector to improve performance since it is expected to be very small.
+  std::vector<QuicConnectionId> incoming_connection_ids_;
+
   // Latched value of quic_fix_termination_packets.
   const bool fix_termination_packets_;