Pass SNI extracted from CHLO to QuicDispatcher:: CreateQuicSession(). The new argument is not used.

SNI is needed in Envoy to retrieve HCM filter config and create the filter.

No behavior change other than extracting SNI from CHLO in gQUIC while it is extracting ALPN. TlsChloExtractor is already extracting that field.

PiperOrigin-RevId: 366527349
Change-Id: Idfe3f7b62109efc2102aa52285c4c7789308de42
diff --git a/quic/core/quic_buffered_packet_store.cc b/quic/core/quic_buffered_packet_store.cc
index 8f05277..e4d4c97 100644
--- a/quic/core/quic_buffered_packet_store.cc
+++ b/quic/core/quic_buffered_packet_store.cc
@@ -87,6 +87,7 @@
     QuicSocketAddress peer_address,
     bool is_chlo,
     const std::vector<std::string>& alpns,
+    const absl::string_view sni,
     const ParsedQuicVersion& version) {
   QUIC_BUG_IF(quic_bug_12410_1, !GetQuicFlag(FLAGS_quic_allow_chlo_buffering))
       << "Shouldn't buffer packets if disabled via flag.";
@@ -142,6 +143,7 @@
     // first later.
     queue.buffered_packets.push_front(std::move(new_entry));
     queue.alpns = alpns;
+    queue.sni = std::string(sni);
     connections_with_chlo_[connection_id] = false;  // Dummy value.
     // Set the version of buffered packets of this connection on CHLO.
     queue.version = version;
@@ -259,8 +261,10 @@
     const QuicConnectionId& connection_id,
     const ParsedQuicVersion& version,
     const QuicReceivedPacket& packet,
-    std::vector<std::string>* out_alpns) {
+    std::vector<std::string>* out_alpns,
+    std::string* out_sni) {
   QUICHE_DCHECK_NE(out_alpns, nullptr);
+  QUICHE_DCHECK_NE(out_sni, nullptr);
   QUICHE_DCHECK_EQ(version.handshake_protocol, PROTOCOL_TLS1_3);
   auto it = undecryptable_packets_.find(connection_id);
   if (it == undecryptable_packets_.end()) {
@@ -273,6 +277,7 @@
     return false;
   }
   *out_alpns = it->second.tls_chlo_extractor.alpns();
+  *out_sni = it->second.tls_chlo_extractor.server_name();
   return true;
 }
 
diff --git a/quic/core/quic_buffered_packet_store.h b/quic/core/quic_buffered_packet_store.h
index c8f6375..29be2c8 100644
--- a/quic/core/quic_buffered_packet_store.h
+++ b/quic/core/quic_buffered_packet_store.h
@@ -69,6 +69,7 @@
     QuicTime creation_time;
     // The ALPNs from the CHLO, if found.
     std::vector<std::string> alpns;
+    std::string sni;
     // Indicating whether this is an IETF QUIC connection.
     bool ietf_quic;
     // If buffered_packets contains the CHLO, it is the version of the CHLO.
@@ -110,6 +111,7 @@
                                     QuicSocketAddress peer_address,
                                     bool is_chlo,
                                     const std::vector<std::string>& alpns,
+                                    const absl::string_view sni,
                                     const ParsedQuicVersion& version);
 
   // Returns true if there are any packets buffered for |connection_id|.
@@ -119,11 +121,12 @@
   // only be called when HasBufferedPackets(connection_id) is true.
   // Returns whether we've now parsed a full multi-packet TLS CHLO.
   // When this returns true, |out_alpns| is populated with the list of ALPNs
-  // extracted from the CHLO.
+  // extracted from the CHLO. |out_sni| is populated with the SNI tag in CHLO.
   bool IngestPacketForTlsChloExtraction(const QuicConnectionId& connection_id,
                                         const ParsedQuicVersion& version,
                                         const QuicReceivedPacket& packet,
-                                        std::vector<std::string>* out_alpns);
+                                        std::vector<std::string>* out_alpns,
+                                        std::string* out_sni);
 
   // Returns the list of buffered packets for |connection_id| and removes them
   // from the store. Returns an empty list if no early arrived packets for this
diff --git a/quic/core/quic_buffered_packet_store_test.cc b/quic/core/quic_buffered_packet_store_test.cc
index 1d9cce7..c5d11f2 100644
--- a/quic/core/quic_buffered_packet_store_test.cc
+++ b/quic/core/quic_buffered_packet_store_test.cc
@@ -70,7 +70,7 @@
 TEST_F(QuicBufferedPacketStoreTest, SimpleEnqueueAndDeliverPacket) {
   QuicConnectionId connection_id = TestConnectionId(1);
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   EXPECT_TRUE(store_.HasBufferedPackets(connection_id));
   auto packets = store_.DeliverPackets(connection_id);
   const std::list<BufferedPacket>& queue = packets.buffered_packets;
@@ -93,9 +93,9 @@
   QuicSocketAddress addr_with_new_port(QuicIpAddress::Any4(), 256);
   QuicConnectionId connection_id = TestConnectionId(1);
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       addr_with_new_port, false, {}, invalid_version_);
+                       addr_with_new_port, false, {}, "", invalid_version_);
   std::list<BufferedPacket> queue =
       store_.DeliverPackets(connection_id).buffered_packets;
   ASSERT_EQ(2u, queue.size());
@@ -110,9 +110,9 @@
   for (uint64_t conn_id = 1; conn_id <= num_connections; ++conn_id) {
     QuicConnectionId connection_id = TestConnectionId(conn_id);
     store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                         peer_address_, false, {}, invalid_version_);
+                         peer_address_, false, {}, "", invalid_version_);
     store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                         peer_address_, false, {}, invalid_version_);
+                         peer_address_, false, {}, "", invalid_version_);
   }
 
   // Deliver packets in reversed order.
@@ -134,12 +134,12 @@
   // keep.
   EXPECT_EQ(QuicBufferedPacketStore::SUCCESS,
             store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                                 peer_address_, true, {}, valid_version_));
+                                 peer_address_, true, {}, "", valid_version_));
   for (size_t i = 1; i <= num_packets; ++i) {
     // Only first |kDefaultMaxUndecryptablePackets packets| will be buffered.
     EnqueuePacketResult result =
         store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                             peer_address_, false, {}, invalid_version_);
+                             peer_address_, false, {}, "", invalid_version_);
     if (i <= kDefaultMaxUndecryptablePackets) {
       EXPECT_EQ(EnqueuePacketResult::SUCCESS, result);
     } else {
@@ -161,7 +161,7 @@
     QuicConnectionId connection_id = TestConnectionId(conn_id);
     EnqueuePacketResult result =
         store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                             peer_address_, false, {}, invalid_version_);
+                             peer_address_, false, {}, "", invalid_version_);
     if (conn_id <= kMaxConnectionsWithoutCHLO) {
       EXPECT_EQ(EnqueuePacketResult::SUCCESS, result);
     } else {
@@ -190,7 +190,7 @@
   for (uint64_t conn_id = 1; conn_id <= num_chlos; ++conn_id) {
     EXPECT_EQ(EnqueuePacketResult::SUCCESS,
               store_.EnqueuePacket(TestConnectionId(conn_id), false, packet_,
-                                   self_address_, peer_address_, true, {},
+                                   self_address_, peer_address_, true, {}, "",
                                    valid_version_));
   }
 
@@ -201,7 +201,7 @@
     QuicConnectionId connection_id = TestConnectionId(conn_id);
     EnqueuePacketResult result =
         store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                             peer_address_, true, {}, valid_version_);
+                             peer_address_, true, {}, "", valid_version_);
     if (conn_id <= kDefaultMaxConnectionsInStore) {
       EXPECT_EQ(EnqueuePacketResult::SUCCESS, result);
     } else {
@@ -214,9 +214,10 @@
   // Buffer data packets on different connections upto limit.
   for (uint64_t conn_id = 1; conn_id <= kMaxConnectionsWithoutCHLO; ++conn_id) {
     QuicConnectionId connection_id = TestConnectionId(conn_id);
-    EXPECT_EQ(EnqueuePacketResult::SUCCESS,
-              store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                                   peer_address_, false, {}, invalid_version_));
+    EXPECT_EQ(
+        EnqueuePacketResult::SUCCESS,
+        store_.EnqueuePacket(connection_id, false, packet_, self_address_,
+                             peer_address_, false, {}, "", invalid_version_));
   }
 
   // Buffer CHLOs on other connections till store is full.
@@ -225,7 +226,7 @@
     QuicConnectionId connection_id = TestConnectionId(i);
     EnqueuePacketResult rs =
         store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                             peer_address_, true, {}, valid_version_);
+                             peer_address_, true, {}, "", valid_version_);
     if (i <= kDefaultMaxConnectionsInStore) {
       EXPECT_EQ(EnqueuePacketResult::SUCCESS, rs);
       EXPECT_TRUE(store_.HasChloForConnection(connection_id));
@@ -242,7 +243,7 @@
   EXPECT_EQ(EnqueuePacketResult::SUCCESS,
             store_.EnqueuePacket(
                 /*connection_id=*/TestConnectionId(1), false, packet_,
-                self_address_, peer_address_, true, {}, valid_version_));
+                self_address_, peer_address_, true, {}, "", valid_version_));
   EXPECT_TRUE(store_.HasChloForConnection(
       /*connection_id=*/TestConnectionId(1)));
 
@@ -270,14 +271,15 @@
 TEST_F(QuicBufferedPacketStoreTest, PacketQueueExpiredBeforeDelivery) {
   QuicConnectionId connection_id = TestConnectionId(1);
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   EXPECT_EQ(EnqueuePacketResult::SUCCESS,
             store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                                 peer_address_, true, {}, valid_version_));
+                                 peer_address_, true, {}, "", valid_version_));
   QuicConnectionId connection_id2 = TestConnectionId(2);
-  EXPECT_EQ(EnqueuePacketResult::SUCCESS,
-            store_.EnqueuePacket(connection_id2, false, packet_, self_address_,
-                                 peer_address_, false, {}, invalid_version_));
+  EXPECT_EQ(
+      EnqueuePacketResult::SUCCESS,
+      store_.EnqueuePacket(connection_id2, false, packet_, self_address_,
+                           peer_address_, false, {}, "", invalid_version_));
 
   // CHLO on connection 3 arrives 1ms later.
   clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
@@ -286,7 +288,7 @@
   // connections.
   QuicSocketAddress another_client_address(QuicIpAddress::Any4(), 255);
   store_.EnqueuePacket(connection_id3, false, packet_, self_address_,
-                       another_client_address, true, {}, valid_version_);
+                       another_client_address, true, {}, "", valid_version_);
 
   // Advance clock to the time when connection 1 and 2 expires.
   clock_.AdvanceTime(
@@ -318,9 +320,9 @@
   // for them to expire.
   QuicConnectionId connection_id4 = TestConnectionId(4);
   store_.EnqueuePacket(connection_id4, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   store_.EnqueuePacket(connection_id4, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   clock_.AdvanceTime(
       QuicBufferedPacketStorePeer::expiration_alarm(&store_)->deadline() -
       clock_.ApproximateNow());
@@ -335,9 +337,9 @@
 
   // Enqueue some packets
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   EXPECT_TRUE(store_.HasBufferedPackets(connection_id));
   EXPECT_FALSE(store_.HasChlosBuffered());
 
@@ -361,11 +363,11 @@
 
   // Enqueue some packets, which include a CHLO
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, true, {}, valid_version_);
+                       peer_address_, true, {}, "", valid_version_);
   store_.EnqueuePacket(connection_id, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   EXPECT_TRUE(store_.HasBufferedPackets(connection_id));
   EXPECT_TRUE(store_.HasChlosBuffered());
 
@@ -390,11 +392,12 @@
 
   // Enqueue some packets for two connection IDs
   store_.EnqueuePacket(connection_id_1, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   store_.EnqueuePacket(connection_id_1, false, packet_, self_address_,
-                       peer_address_, false, {}, invalid_version_);
+                       peer_address_, false, {}, "", invalid_version_);
   store_.EnqueuePacket(connection_id_2, false, packet_, self_address_,
-                       peer_address_, true, {"h3"}, valid_version_);
+                       peer_address_, true, {"h3"}, TestHostname(),
+                       valid_version_);
   EXPECT_TRUE(store_.HasBufferedPackets(connection_id_1));
   EXPECT_TRUE(store_.HasBufferedPackets(connection_id_2));
   EXPECT_TRUE(store_.HasChlosBuffered());
@@ -413,6 +416,7 @@
   EXPECT_EQ(1u, packets.buffered_packets.size());
   ASSERT_EQ(1u, packets.alpns.size());
   EXPECT_EQ("h3", packets.alpns[0]);
+  EXPECT_EQ(TestHostname(), packets.sni);
   // Since connection_id_2's chlo arrives, verify version is set.
   EXPECT_EQ(valid_version_, packets.version);
   EXPECT_TRUE(store_.HasChlosBuffered());
diff --git a/quic/core/quic_dispatcher.cc b/quic/core/quic_dispatcher.cc
index 171246d..0ed002a 100644
--- a/quic/core/quic_dispatcher.cc
+++ b/quic/core/quic_dispatcher.cc
@@ -191,8 +191,8 @@
   QuicTimeWaitListManager* time_wait_list_manager_;
 };
 
-// Class which extracts the ALPN from a QUIC_CRYPTO CHLO packet.
-class ChloAlpnExtractor : public ChloExtractor::Delegate {
+// Class which extracts the ALPN and SNI from a QUIC_CRYPTO CHLO packet.
+class ChloAlpnSniExtractor : public ChloExtractor::Delegate {
  public:
   void OnChlo(QuicTransportVersion version,
               QuicConnectionId /*server_connection_id*/,
@@ -201,6 +201,10 @@
     if (chlo.GetStringPiece(kALPN, &alpn_value)) {
       alpn_ = std::string(alpn_value);
     }
+    absl::string_view sni;
+    if (chlo.GetStringPiece(quic::kSNI, &sni)) {
+      sni_ = std::string(sni);
+    }
     if (version == LegacyVersionForEncapsulation().transport_version) {
       absl::string_view qlve_value;
       if (chlo.GetStringPiece(kQLVE, &qlve_value)) {
@@ -211,18 +215,21 @@
 
   std::string&& ConsumeAlpn() { return std::move(alpn_); }
 
+  std::string&& ConsumeSni() { return std::move(sni_); }
+
   std::string&& ConsumeLegacyVersionEncapsulationInnerPacket() {
     return std::move(legacy_version_encapsulation_inner_packet_);
   }
 
  private:
   std::string alpn_;
+  std::string sni_;
   std::string legacy_version_encapsulation_inner_packet_;
 };
 
 bool MaybeHandleLegacyVersionEncapsulation(
     QuicDispatcher* dispatcher,
-    ChloAlpnExtractor* alpn_extractor,
+    ChloAlpnSniExtractor* alpn_extractor,
     const ReceivedPacketInfo& packet_info) {
   std::string legacy_version_encapsulation_inner_packet =
       alpn_extractor->ConsumeLegacyVersionEncapsulationInnerPacket();
@@ -515,7 +522,7 @@
           packet_info.version == LegacyVersionForEncapsulation()) {
         // This packet is using the Legacy Version Encapsulation version but the
         // corresponding session isn't, attempt extraction of inner packet.
-        ChloAlpnExtractor alpn_extractor;
+        ChloAlpnSniExtractor alpn_extractor;
         if (ChloExtractor::Extract(packet_info.packet, packet_info.version,
                                    config_->create_session_tag_indicators(),
                                    &alpn_extractor,
@@ -541,7 +548,7 @@
           packet_info.version == LegacyVersionForEncapsulation()) {
         // This packet is using the Legacy Version Encapsulation version but the
         // corresponding session isn't, attempt extraction of inner packet.
-        ChloAlpnExtractor alpn_extractor;
+        ChloAlpnSniExtractor alpn_extractor;
         if (ChloExtractor::Extract(packet_info.packet, packet_info.version,
                                    config_->create_session_tag_indicators(),
                                    &alpn_extractor,
@@ -676,11 +683,12 @@
       packet_info->destination_connection_id;
   // Packet's connection ID is unknown.  Apply the validity checks.
   QuicPacketFate fate = ValidityChecks(*packet_info);
-  ChloAlpnExtractor alpn_extractor;
+  ChloAlpnSniExtractor alpn_extractor;
   switch (fate) {
     case kFateProcess: {
       if (packet_info->version.handshake_protocol == PROTOCOL_TLS1_3) {
         bool has_full_tls_chlo = false;
+        std::string sni;
         std::vector<std::string> alpns;
         if (buffered_packets_.HasBufferedPackets(
                 packet_info->destination_connection_id)) {
@@ -689,7 +697,7 @@
           has_full_tls_chlo =
               buffered_packets_.IngestPacketForTlsChloExtraction(
                   packet_info->destination_connection_id, packet_info->version,
-                  packet_info->packet, &alpns);
+                  packet_info->packet, &alpns, &sni);
         } else {
           // If we do not have a BufferedPacketList for this connection ID,
           // create a single-use one to check whether this packet contains a
@@ -701,10 +709,11 @@
             // This packet contains a full single-packet CHLO.
             has_full_tls_chlo = true;
             alpns = tls_chlo_extractor.alpns();
+            sni = tls_chlo_extractor.server_name();
           }
         }
         if (has_full_tls_chlo) {
-          ProcessChlo(alpns, packet_info);
+          ProcessChlo(alpns, sni, packet_info);
         } else {
           // This packet does not contain a full CHLO. It could be a 0-RTT
           // packet that arrived before the CHLO (due to loss or reordering),
@@ -741,7 +750,8 @@
         break;
       }
 
-      ProcessChlo({alpn_extractor.ConsumeAlpn()}, packet_info);
+      ProcessChlo({alpn_extractor.ConsumeAlpn()}, alpn_extractor.ConsumeSni(),
+                  packet_info);
     } break;
     case kFateTimeWait:
       // Add this connection_id to the time-wait state, to safely reject
@@ -1230,9 +1240,10 @@
     server_connection_id = MaybeReplaceServerConnectionId(server_connection_id,
                                                           packet_list.version);
     std::string alpn = SelectAlpn(packet_list.alpns);
-    std::unique_ptr<QuicSession> session = CreateQuicSession(
-        server_connection_id, packets.front().self_address,
-        packets.front().peer_address, alpn, packet_list.version);
+    std::unique_ptr<QuicSession> session =
+        CreateQuicSession(server_connection_id, packets.front().self_address,
+                          packets.front().peer_address, alpn,
+                          packet_list.version, packet_list.sni);
     if (original_connection_id != server_connection_id) {
       session->connection()->SetOriginalDestinationConnectionId(
           original_connection_id);
@@ -1304,13 +1315,14 @@
       packet_info.destination_connection_id,
       packet_info.form != GOOGLE_QUIC_PACKET, packet_info.packet,
       packet_info.self_address, packet_info.peer_address, /*is_chlo=*/false,
-      /*alpns=*/{}, packet_info.version);
+      /*alpns=*/{}, /*sni=*/absl::string_view(), packet_info.version);
   if (rs != EnqueuePacketResult::SUCCESS) {
     OnBufferPacketFailure(rs, packet_info.destination_connection_id);
   }
 }
 
 void QuicDispatcher::ProcessChlo(const std::vector<std::string>& alpns,
+                                 absl::string_view sni,
                                  ReceivedPacketInfo* packet_info) {
   if (!buffered_packets_.HasBufferedPackets(
           packet_info->destination_connection_id) &&
@@ -1326,7 +1338,7 @@
         packet_info->destination_connection_id,
         packet_info->form != GOOGLE_QUIC_PACKET, packet_info->packet,
         packet_info->self_address, packet_info->peer_address,
-        /*is_chlo=*/true, alpns, packet_info->version);
+        /*is_chlo=*/true, alpns, sni, packet_info->version);
     if (rs != EnqueuePacketResult::SUCCESS) {
       OnBufferPacketFailure(rs, packet_info->destination_connection_id);
     }
@@ -1341,7 +1353,7 @@
   std::string alpn = SelectAlpn(alpns);
   std::unique_ptr<QuicSession> session = CreateQuicSession(
       packet_info->destination_connection_id, packet_info->self_address,
-      packet_info->peer_address, alpn, packet_info->version);
+      packet_info->peer_address, alpn, packet_info->version, sni);
   if (QUIC_PREDICT_FALSE(session == nullptr)) {
     QUIC_BUG(quic_bug_10287_8)
         << "CreateQuicSession returned nullptr for "
diff --git a/quic/core/quic_dispatcher.h b/quic/core/quic_dispatcher.h
index b8a02fb..8174954 100644
--- a/quic/core/quic_dispatcher.h
+++ b/quic/core/quic_dispatcher.h
@@ -180,7 +180,8 @@
       const QuicSocketAddress& self_address,
       const QuicSocketAddress& peer_address,
       absl::string_view alpn,
-      const ParsedQuicVersion& version) = 0;
+      const ParsedQuicVersion& version,
+      absl::string_view sni) = 0;
 
   // Tries to validate and dispatch packet based on available information.
   // Returns true if packet is dropped or successfully dispatched (e.g.,
@@ -242,6 +243,7 @@
   // Called when |packet_info| is a CHLO packet. Creates a new connection and
   // delivers any buffered packets for that connection id.
   void ProcessChlo(const std::vector<std::string>& alpns,
+                   absl::string_view sni,
                    ReceivedPacketInfo* packet_info);
 
   // Return true if dispatcher wants to destroy session outside of
diff --git a/quic/core/quic_dispatcher_test.cc b/quic/core/quic_dispatcher_test.cc
index da4241b..3df8a76 100644
--- a/quic/core/quic_dispatcher_test.cc
+++ b/quic/core/quic_dispatcher_test.cc
@@ -139,7 +139,8 @@
                const QuicSocketAddress& self_address,
                const QuicSocketAddress& peer_address,
                absl::string_view alpn,
-               const quic::ParsedQuicVersion& version),
+               const quic::ParsedQuicVersion& version,
+               absl::string_view sni),
               (override));
 
   MOCK_METHOD(bool,
@@ -466,7 +467,7 @@
     QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
     EXPECT_CALL(*dispatcher_,
                 CreateQuicSession(connection_id, _, client_address,
-                                  Eq(ExpectedAlpnForVersion(version)), _))
+                                  Eq(ExpectedAlpnForVersion(version)), _, _))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, connection_id, client_address,
             &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -487,7 +488,7 @@
     QuicConnectionId connection_id = TestConnectionId(++connection_id_);
     QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
     EXPECT_CALL(*dispatcher_,
-                CreateQuicSession(connection_id, _, client_address, _, _))
+                CreateQuicSession(connection_id, _, client_address, _, _, _))
         .Times(0);
     ProcessFirstFlight(version, client_address, connection_id);
   }
@@ -535,7 +536,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(1), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(1), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -586,7 +587,7 @@
   // Processing the second packet should create the new session.
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(server_connection_id, _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, TestHostname()))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, server_connection_id, client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -653,7 +654,7 @@
   // Processing the packet should create a new session.
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(server_connection_id, _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, server_connection_id, client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -678,7 +679,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(1), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, TestHostname()))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(1), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -695,7 +696,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(2), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, TestHostname()))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(2), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -725,7 +726,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(1), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(1), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -752,7 +753,7 @@
   CreateTimeWaitListManager();
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(TestConnectionId(1), _, _, _, _, _, _, _))
@@ -767,7 +768,7 @@
   CreateTimeWaitListManager();
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_,
               SendVersionNegotiationPacket(connection_id, _, _, _, _, _, _, _))
       .Times(1);
@@ -780,7 +781,7 @@
   CreateTimeWaitListManager();
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_,
               SendVersionNegotiationPacket(
                   TestConnectionId(1), TestConnectionId(2), _, _, _, _, _, _))
@@ -793,7 +794,7 @@
   CreateTimeWaitListManager();
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_,
               SendVersionNegotiationPacket(_, _, _, _, _, _, _, _))
       .Times(0);
@@ -817,7 +818,7 @@
   CreateTimeWaitListManager();
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_,
               SendVersionNegotiationPacket(_, _, _, _, _, _, _, _))
       .Times(1);
@@ -836,7 +837,7 @@
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
   EXPECT_CALL(*dispatcher_,
-              CreateQuicSession(_, _, client_address, Eq(ExpectedAlpn()), _))
+              CreateQuicSession(_, _, client_address, Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(1), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -865,7 +866,7 @@
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
   QuicConnectionId connection_id = TestConnectionId(1);
   EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, _, client_address,
-                                              Eq(ExpectedAlpn()), _))
+                                              Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, connection_id, client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -905,7 +906,7 @@
   QuicConnectionId connection_id = TestConnectionId(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(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_,
               ProcessPacket(_, _, connection_id, _, _, _))
       .Times(0);
@@ -926,7 +927,7 @@
   QuicReceivedPacket packet(short_packet, 21, QuicTime::Zero());
   char valid_size_packet[23] = {0x70, 0xa7, 0x02, 0x6c};
   QuicReceivedPacket packet2(valid_size_packet, 23, QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _, _))
       .Times(0);
   EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _))
@@ -955,7 +956,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(fixed_connection_id, _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, fixed_connection_id, client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -992,7 +993,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(fixed_connection_id, _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, fixed_connection_id, client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -1023,7 +1024,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(1), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(1), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -1040,7 +1041,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(fixed_connection_id, _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, fixed_connection_id, client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -1071,8 +1072,8 @@
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 0);
 
   // dispatcher_ should drop this packet.
-  EXPECT_CALL(*dispatcher_,
-              CreateQuicSession(TestConnectionId(1), _, client_address, _, _))
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(TestConnectionId(1), _,
+                                              client_address, _, _, _))
       .Times(0);
   EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _, _))
       .Times(0);
@@ -1092,7 +1093,7 @@
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
   // dispatcher_ should drop this packet.
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _, _))
       .Times(0);
   EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _))
@@ -1108,7 +1109,7 @@
 
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_,
               SendVersionNegotiationPacket(
                   server_connection_id, client_connection_id,
@@ -1163,7 +1164,7 @@
       0xC0, 0xFF, 0x00, 0x00, 28, /*destination connection ID length*/ 0x08};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1180,7 +1181,7 @@
       0xC0, 0xFF, 0x00, 0x00, 27, /*destination connection ID length*/ 0x08};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1197,7 +1198,7 @@
       0xC0, 0xFF, 0x00, 0x00, 25, /*destination connection ID length*/ 0x08};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1214,7 +1215,7 @@
       0xC0, 'T', '0', '5', '0', /*destination connection ID length*/ 0x08};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1231,7 +1232,7 @@
       0xC0, 'Q', '0', '4', '9', /*destination connection ID length*/ 0x08};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1248,7 +1249,7 @@
       0xC0, 'Q', '0', '4', '8', /*connection ID length byte*/ 0x50};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1265,7 +1266,7 @@
       0xC0, 'Q', '0', '4', '7', /*connection ID length byte*/ 0x50};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1282,7 +1283,7 @@
       0xC0, 'Q', '0', '4', '5', /*connection ID length byte*/ 0x50};
   QuicReceivedPacket received_packet(packet, ABSL_ARRAYSIZE(packet),
                                      QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1299,7 +1300,7 @@
       0xFF, 'Q', '0', '4', '4', /*connection ID length byte*/ 0x50};
   QuicReceivedPacket received_packet44(
       packet44, kMinPacketSizeForVersionNegotiation, QuicTime::Zero());
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(
       *time_wait_list_manager_,
       SendVersionNegotiationPacket(_, _, /*ietf_quic=*/true,
@@ -1333,7 +1334,7 @@
                   server_connection_id, client_connection_id,
                   /*ietf_quic=*/true, /*use_length_prefix=*/true, _, _, _, _))
       .Times(1);
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
 
   dispatcher_->ProcessPacket(server_address_, client_address, *received_packet);
 }
@@ -1382,7 +1383,7 @@
   QuicEncryptedPacket encrypted(packet, sizeof(packet), false);
   std::unique_ptr<QuicReceivedPacket> received_packet(
       ConstructReceivedPacket(encrypted, mock_helper_.GetClock()->Now()));
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
 
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
   dispatcher_->ProcessPacket(server_address_, client_address, *received_packet);
@@ -1433,7 +1434,7 @@
                                 sizeof(packet), false);
   std::unique_ptr<QuicReceivedPacket> received_packet(
       ConstructReceivedPacket(encrypted, mock_helper_.GetClock()->Now()));
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
 
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
   dispatcher_->ProcessPacket(server_address_, client_address, *received_packet);
@@ -1484,7 +1485,7 @@
                                 sizeof(packet), false);
   std::unique_ptr<QuicReceivedPacket> received_packet(
       ConstructReceivedPacket(encrypted, mock_helper_.GetClock()->Now()));
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
 
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
   dispatcher_->ProcessPacket(server_address_, client_address, *received_packet);
@@ -1506,7 +1507,7 @@
   CreateTimeWaitListManager();
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_, SendPacket(_, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _))
       .Times(0);
@@ -1568,7 +1569,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(1), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(1), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -1586,7 +1587,7 @@
   // No more new connections afterwards.
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(2), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .Times(0u);
   ProcessFirstFlight(client_address, TestConnectionId(2));
 
@@ -1607,7 +1608,7 @@
   // No more new connections afterwards.
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(2), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .Times(0u);
   ProcessFirstFlight(client_address, TestConnectionId(2));
 
@@ -1616,7 +1617,7 @@
 
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(1), _, client_address,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, TestConnectionId(1), client_address,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -1657,7 +1658,7 @@
 
   QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
   QuicConnectionId connection_id = TestConnectionId(1);
-  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _)).Times(0);
+  EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, _, _, _, _)).Times(0);
   EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _, _))
       .Times(0);
   EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _))
@@ -1698,8 +1699,8 @@
 
     QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
 
-    EXPECT_CALL(*dispatcher_,
-                CreateQuicSession(_, _, client_address, Eq(ExpectedAlpn()), _))
+    EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, client_address,
+                                                Eq(ExpectedAlpn()), _, _))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, TestConnectionId(1), client_address,
             &helper_, &alarm_factory_, &crypto_config_,
@@ -1714,8 +1715,8 @@
                     ReceivedPacketInfoConnectionIdEquals(TestConnectionId(1))));
     ProcessFirstFlight(client_address, TestConnectionId(1));
 
-    EXPECT_CALL(*dispatcher_,
-                CreateQuicSession(_, _, client_address, Eq(ExpectedAlpn()), _))
+    EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, client_address,
+                                                Eq(ExpectedAlpn()), _, _))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, TestConnectionId(2), client_address,
             &helper_, &alarm_factory_, &crypto_config_,
@@ -1985,8 +1986,8 @@
   }
   void AddConnection1() {
     QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
-    EXPECT_CALL(*dispatcher_,
-                CreateQuicSession(_, _, client_address, Eq(ExpectedAlpn()), _))
+    EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, client_address,
+                                                Eq(ExpectedAlpn()), _, _))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, TestConnectionId(1), client_address,
             &helper_, &alarm_factory_, &crypto_config_,
@@ -2004,8 +2005,8 @@
 
   void AddConnection2() {
     QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 2);
-    EXPECT_CALL(*dispatcher_,
-                CreateQuicSession(_, _, client_address, Eq(ExpectedAlpn()), _))
+    EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _, client_address,
+                                                Eq(ExpectedAlpn()), _, _))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, TestConnectionId(2), client_address,
             &helper_, &alarm_factory_, &crypto_config_,
@@ -2225,8 +2226,9 @@
 
   // 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_addr_,
-                                              Eq(ExpectedAlpn()), _))
+  EXPECT_CALL(*dispatcher_,
+              CreateQuicSession(conn_id, _, client_addr_, Eq(ExpectedAlpn()), _,
+                                TestHostname()))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
           &mock_alarm_factory_, &crypto_config_,
@@ -2261,7 +2263,7 @@
   // 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_addr_,
-                                              Eq(ExpectedAlpn()), _))
+                                              Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
           &mock_alarm_factory_, &crypto_config_,
@@ -2313,7 +2315,7 @@
                       ReceivedPacketInfoConnectionIdEquals(conn_id)));
     }
     EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, _, client_address,
-                                                Eq(ExpectedAlpn()), _))
+                                                Eq(ExpectedAlpn()), _, _))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, conn_id, client_address, &mock_helper_,
             &mock_alarm_factory_, &crypto_config_,
@@ -2341,7 +2343,7 @@
   EXPECT_CALL(*dispatcher_, ShouldCreateOrBufferPacketForConnection(
                                 ReceivedPacketInfoConnectionIdEquals(conn_id)));
   EXPECT_CALL(*dispatcher_, CreateQuicSession(conn_id, _, client_addr_,
-                                              Eq(ExpectedAlpn()), _))
+                                              Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
           &mock_alarm_factory_, &crypto_config_,
@@ -2361,7 +2363,7 @@
   // 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_addr_,
-                                              Eq(ExpectedAlpn()), _))
+                                              Eq(ExpectedAlpn()), _, _))
       .Times(1)  // Only triggered by 1st CHLO.
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, conn_id, client_addr_, &mock_helper_,
@@ -2430,7 +2432,7 @@
     if (conn_id <= kMaxNumSessionsToCreate) {
       EXPECT_CALL(*dispatcher_,
                   CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
-                                    Eq(ExpectedAlpn()), _))
+                                    Eq(ExpectedAlpn()), _, TestHostname()))
           .WillOnce(Return(ByMove(CreateSession(
               dispatcher_.get(), config_, TestConnectionId(conn_id),
               client_addr_, &mock_helper_, &mock_alarm_factory_,
@@ -2465,7 +2467,7 @@
        ++conn_id) {
     EXPECT_CALL(*dispatcher_,
                 CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
-                                  Eq(ExpectedAlpn()), _))
+                                  Eq(ExpectedAlpn()), _, TestHostname()))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, TestConnectionId(conn_id), client_addr_,
             &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -2481,7 +2483,7 @@
   }
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(TestConnectionId(kNumCHLOs), _, client_addr_,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .Times(0);
 
   while (store->HasChlosBuffered()) {
@@ -2501,7 +2503,7 @@
     if (conn_id <= kMaxNumSessionsToCreate) {
       EXPECT_CALL(*dispatcher_,
                   CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
-                                    Eq(ExpectedAlpn()), _))
+                                    Eq(ExpectedAlpn()), _, _))
           .WillOnce(Return(ByMove(CreateSession(
               dispatcher_.get(), config_, TestConnectionId(conn_id),
               client_addr_, &mock_helper_, &mock_alarm_factory_,
@@ -2528,7 +2530,7 @@
 
   // Reset counter and process buffered CHLO.
   EXPECT_CALL(*dispatcher_, CreateQuicSession(last_connection, _, client_addr_,
-                                              Eq(ExpectedAlpn()), _))
+                                              Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, last_connection, client_addr_,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -2554,7 +2556,7 @@
     if (conn_id <= kMaxNumSessionsToCreate) {
       EXPECT_CALL(*dispatcher_,
                   CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
-                                    Eq(ExpectedAlpn()), _))
+                                    Eq(ExpectedAlpn()), _, _))
           .WillOnce(Return(ByMove(CreateSession(
               dispatcher_.get(), config_, TestConnectionId(conn_id),
               client_addr_, &mock_helper_, &mock_alarm_factory_,
@@ -2583,7 +2585,7 @@
   // Reset counter and process buffered CHLO.
   EXPECT_CALL(*dispatcher_,
               CreateQuicSession(last_connection_id, _, client_addr_,
-                                Eq(ExpectedAlpn()), _))
+                                Eq(ExpectedAlpn()), _, _))
       .WillOnce(Return(ByMove(CreateSession(
           dispatcher_.get(), config_, last_connection_id, client_addr_,
           &mock_helper_, &mock_alarm_factory_, &crypto_config_,
@@ -2619,7 +2621,7 @@
     if (conn_id <= kMaxNumSessionsToCreate + 1) {
       EXPECT_CALL(*dispatcher_,
                   CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
-                                    Eq(ExpectedAlpn()), _))
+                                    Eq(ExpectedAlpn()), _, _))
           .WillOnce(Return(ByMove(CreateSession(
               dispatcher_.get(), config_, TestConnectionId(conn_id),
               client_addr_, &mock_helper_, &mock_alarm_factory_,
@@ -2661,7 +2663,7 @@
       EXPECT_CALL(
           *dispatcher_,
           CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
-                            Eq(ExpectedAlpnForVersion(version)), version))
+                            Eq(ExpectedAlpnForVersion(version)), version, _))
           .WillOnce(Return(ByMove(CreateSession(
               dispatcher_.get(), config_, TestConnectionId(conn_id),
               client_addr_, &mock_helper_, &mock_alarm_factory_,
@@ -2685,9 +2687,10 @@
        conn_id <= last_connection_id; ++conn_id) {
     ParsedQuicVersion version =
         supported_versions[(conn_id - 1) % supported_versions.size()];
-    EXPECT_CALL(*dispatcher_,
-                CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
-                                  Eq(ExpectedAlpnForVersion(version)), version))
+    EXPECT_CALL(
+        *dispatcher_,
+        CreateQuicSession(TestConnectionId(conn_id), _, client_addr_,
+                          Eq(ExpectedAlpnForVersion(version)), version, _))
         .WillOnce(Return(ByMove(CreateSession(
             dispatcher_.get(), config_, TestConnectionId(conn_id), client_addr_,
             &mock_helper_, &mock_alarm_factory_, &crypto_config_,
diff --git a/quic/masque/masque_dispatcher.cc b/quic/masque/masque_dispatcher.cc
index 2273e9b..5729d54 100644
--- a/quic/masque/masque_dispatcher.cc
+++ b/quic/masque/masque_dispatcher.cc
@@ -35,7 +35,8 @@
     const QuicSocketAddress& self_address,
     const QuicSocketAddress& peer_address,
     absl::string_view /*alpn*/,
-    const ParsedQuicVersion& version) {
+    const ParsedQuicVersion& version,
+    absl::string_view /*sni*/) {
   // The MasqueServerSession takes ownership of |connection| below.
   QuicConnection* connection =
       new QuicConnection(connection_id, self_address, peer_address, helper(),
diff --git a/quic/masque/masque_dispatcher.h b/quic/masque/masque_dispatcher.h
index ce371b5..368219e 100644
--- a/quic/masque/masque_dispatcher.h
+++ b/quic/masque/masque_dispatcher.h
@@ -42,7 +42,8 @@
       const QuicSocketAddress& self_address,
       const QuicSocketAddress& peer_address,
       absl::string_view alpn,
-      const ParsedQuicVersion& version) override;
+      const ParsedQuicVersion& version,
+      absl::string_view sni) override;
 
   bool OnFailedToDispatchPacket(const ReceivedPacketInfo& packet_info) override;
 
diff --git a/quic/qbone/qbone_client_test.cc b/quic/qbone/qbone_client_test.cc
index 75a3a1e..91bb82d 100644
--- a/quic/qbone/qbone_client_test.cc
+++ b/quic/qbone/qbone_client_test.cc
@@ -127,7 +127,8 @@
       const QuicSocketAddress& self_address,
       const QuicSocketAddress& peer_address,
       absl::string_view alpn,
-      const quic::ParsedQuicVersion& version) override {
+      const quic::ParsedQuicVersion& version,
+      absl::string_view sni) override {
     QUICHE_CHECK_EQ(alpn, "qbone");
     QuicConnection* connection = new QuicConnection(
         id, self_address, peer_address, helper(), alarm_factory(), writer(),
diff --git a/quic/test_tools/quic_test_server.cc b/quic/test_tools/quic_test_server.cc
index 5f4738b..f6e2c34 100644
--- a/quic/test_tools/quic_test_server.cc
+++ b/quic/test_tools/quic_test_server.cc
@@ -98,12 +98,13 @@
       const QuicSocketAddress& self_address,
       const QuicSocketAddress& peer_address,
       absl::string_view alpn,
-      const ParsedQuicVersion& version) override {
+      const ParsedQuicVersion& version,
+      absl::string_view sni) override {
     QuicReaderMutexLock lock(&factory_lock_);
     if (session_factory_ == nullptr && stream_factory_ == nullptr &&
         crypto_stream_factory_ == nullptr) {
       return QuicSimpleDispatcher::CreateQuicSession(
-          id, self_address, peer_address, alpn, version);
+          id, self_address, peer_address, alpn, version, sni);
     }
     QuicConnection* connection = new QuicConnection(
         id, self_address, peer_address, helper(), alarm_factory(), writer(),
diff --git a/quic/tools/quic_simple_dispatcher.cc b/quic/tools/quic_simple_dispatcher.cc
index 736c061..aa9a9c1 100644
--- a/quic/tools/quic_simple_dispatcher.cc
+++ b/quic/tools/quic_simple_dispatcher.cc
@@ -53,7 +53,8 @@
     const QuicSocketAddress& self_address,
     const QuicSocketAddress& peer_address,
     absl::string_view /*alpn*/,
-    const ParsedQuicVersion& version) {
+    const ParsedQuicVersion& version,
+    absl::string_view /*sni*/) {
   // The QuicServerSessionBase takes ownership of |connection| below.
   QuicConnection* connection =
       new QuicConnection(connection_id, self_address, peer_address, helper(),
diff --git a/quic/tools/quic_simple_dispatcher.h b/quic/tools/quic_simple_dispatcher.h
index a629d3c..c790f21 100644
--- a/quic/tools/quic_simple_dispatcher.h
+++ b/quic/tools/quic_simple_dispatcher.h
@@ -36,7 +36,8 @@
       const QuicSocketAddress& self_address,
       const QuicSocketAddress& peer_address,
       absl::string_view alpn,
-      const ParsedQuicVersion& version) override;
+      const ParsedQuicVersion& version,
+      absl::string_view sni) override;
 
   QuicSimpleServerBackend* server_backend() {
     return quic_simple_server_backend_;
diff --git a/quic/tools/quic_transport_simple_server_dispatcher.cc b/quic/tools/quic_transport_simple_server_dispatcher.cc
index 7029cf7..25730ed 100644
--- a/quic/tools/quic_transport_simple_server_dispatcher.cc
+++ b/quic/tools/quic_transport_simple_server_dispatcher.cc
@@ -39,7 +39,8 @@
     const QuicSocketAddress& self_address,
     const QuicSocketAddress& peer_address,
     absl::string_view /*alpn*/,
-    const ParsedQuicVersion& version) {
+    const ParsedQuicVersion& version,
+    absl::string_view /*sni*/) {
   auto connection = std::make_unique<QuicConnection>(
       server_connection_id, self_address, peer_address, helper(),
       alarm_factory(), writer(),
diff --git a/quic/tools/quic_transport_simple_server_dispatcher.h b/quic/tools/quic_transport_simple_server_dispatcher.h
index 500b02d..bb38596 100644
--- a/quic/tools/quic_transport_simple_server_dispatcher.h
+++ b/quic/tools/quic_transport_simple_server_dispatcher.h
@@ -32,7 +32,8 @@
       const QuicSocketAddress& self_address,
       const QuicSocketAddress& peer_address,
       absl::string_view alpn,
-      const ParsedQuicVersion& version) override;
+      const ParsedQuicVersion& version,
+      absl::string_view sni) override;
 
   std::vector<url::Origin> accepted_origins_;
 };