In quic, include undecryptable packets information in error details when client closes connection with quic_handshake_timeout for debugging purpose. client only, not protected.

PiperOrigin-RevId: 317174812
Change-Id: If3b608b81585c188a571ff60c63af01e4e69d0a7
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index 38e117b..03f6922 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -2026,6 +2026,18 @@
   return true;
 }
 
+std::string QuicConnection::UndecryptablePacketsInfo() const {
+  std::string info = quiche::QuicheStrCat(
+      "num_undecryptable_packets: ", undecryptable_packets_.size(), " {");
+  for (const auto& packet : undecryptable_packets_) {
+    info = quiche::QuicheStrCat(
+        info, "[", EncryptionLevelToString(packet.encryption_level), ", ",
+        packet.packet->length(), ", ", packet.processed, "]");
+  }
+  info = quiche::QuicheStrCat(info, "}");
+  return info;
+}
+
 void QuicConnection::ProcessUdpPacket(const QuicSocketAddress& self_address,
                                       const QuicSocketAddress& peer_address,
                                       const QuicReceivedPacket& packet) {
@@ -4567,10 +4579,14 @@
   DCHECK(use_idle_network_detector_);
   const QuicTime::Delta duration =
       clock_->ApproximateNow() - stats_.connection_creation_time;
-  const std::string error_details = quiche::QuicheStrCat(
+  std::string error_details = quiche::QuicheStrCat(
       "Handshake timeout expired after ", duration.ToDebuggingValue(),
       ". Timeout:",
       idle_network_detector_.handshake_timeout().ToDebuggingValue());
+  if (perspective() == Perspective::IS_CLIENT && version().UsesTls()) {
+    error_details =
+        quiche::QuicheStrCat(error_details, UndecryptablePacketsInfo());
+  }
   QUIC_DVLOG(1) << ENDPOINT << error_details;
   CloseConnection(QUIC_HANDSHAKE_TIMEOUT, error_details,
                   ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
diff --git a/quic/core/quic_connection.h b/quic/core/quic_connection.h
index 8f4b113..48d16a2 100644
--- a/quic/core/quic_connection.h
+++ b/quic/core/quic_connection.h
@@ -1323,6 +1323,9 @@
   bool ShouldEnqueueUnDecryptablePacket(EncryptionLevel decryption_level,
                                         bool has_decryption_key) const;
 
+  // Returns string which contains undecryptable packets information.
+  std::string UndecryptablePacketsInfo() const;
+
   QuicFramer framer_;
 
   // Contents received in the current packet, especially used to identify