Introduce MASQUE, part 2: client code

This CL introduces the client code for MASQUE as defined by <https://tools.ietf.org/html/draft-schinazi-masque>. Most of the work here is plumbing in order to override the right methods of the QUIC codebase. The meat of the MASQUE protocol work is in the parent cl/278956073.

gfe-relnote: n/a, adds unused code
PiperOrigin-RevId: 285443244
Change-Id: I76c66a4d89b8b70aada4f15f03ac5ec139ada22f
diff --git a/quic/masque/masque_client_session.cc b/quic/masque/masque_client_session.cc
new file mode 100644
index 0000000..2d7c790
--- /dev/null
+++ b/quic/masque/masque_client_session.cc
@@ -0,0 +1,95 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/third_party/quiche/src/quic/masque/masque_client_session.h"
+
+namespace quic {
+
+MasqueClientSession::MasqueClientSession(
+    const QuicConfig& config,
+    const ParsedQuicVersionVector& supported_versions,
+    QuicConnection* connection,
+    const QuicServerId& server_id,
+    QuicCryptoClientConfig* crypto_config,
+    QuicClientPushPromiseIndex* push_promise_index,
+    Owner* owner)
+    : QuicSpdyClientSession(config,
+                            supported_versions,
+                            connection,
+                            server_id,
+                            crypto_config,
+                            push_promise_index),
+      owner_(owner),
+      compression_engine_(this) {}
+
+void MasqueClientSession::OnMessageReceived(quiche::QuicheStringPiece message) {
+  QUIC_DVLOG(1) << "Received DATAGRAM frame of length " << message.length();
+
+  QuicConnectionId client_connection_id, server_connection_id;
+  QuicSocketAddress server_address;
+  std::string packet;
+  bool version_present;
+  if (!compression_engine_.DecompressDatagram(
+          message, &client_connection_id, &server_connection_id,
+          &server_address, &packet, &version_present)) {
+    return;
+  }
+
+  auto connection_id_registration =
+      client_connection_id_registrations_.find(client_connection_id);
+  if (connection_id_registration == client_connection_id_registrations_.end()) {
+    QUIC_DLOG(ERROR) << "MasqueClientSession failed to dispatch "
+                     << client_connection_id;
+    return;
+  }
+  EncapsulatedClientSession* encapsulated_client_session =
+      connection_id_registration->second;
+  encapsulated_client_session->ProcessPacket(packet, server_address);
+
+  QUIC_DVLOG(1) << "Sent " << packet.length() << " bytes to connection for "
+                << client_connection_id;
+}
+
+void MasqueClientSession::OnMessageAcked(QuicMessageId message_id,
+                                         QuicTime /*receive_timestamp*/) {
+  QUIC_DVLOG(1) << "Received ack for DATAGRAM frame " << message_id;
+}
+
+void MasqueClientSession::OnMessageLost(QuicMessageId message_id) {
+  QUIC_DVLOG(1) << "We believe DATAGRAM frame " << message_id << " was lost";
+}
+
+void MasqueClientSession::SendPacket(QuicConnectionId client_connection_id,
+                                     QuicConnectionId server_connection_id,
+                                     quiche::QuicheStringPiece packet,
+                                     const QuicSocketAddress& server_address) {
+  compression_engine_.CompressAndSendPacket(
+      packet, client_connection_id, server_connection_id, server_address);
+}
+
+void MasqueClientSession::RegisterConnectionId(
+    QuicConnectionId client_connection_id,
+    EncapsulatedClientSession* encapsulated_client_session) {
+  QUIC_DLOG(INFO) << "Registering " << client_connection_id
+                  << " to encapsulated client";
+  DCHECK(client_connection_id_registrations_.find(client_connection_id) ==
+             client_connection_id_registrations_.end() ||
+         client_connection_id_registrations_[client_connection_id] ==
+             encapsulated_client_session);
+  client_connection_id_registrations_[client_connection_id] =
+      encapsulated_client_session;
+}
+
+void MasqueClientSession::UnregisterConnectionId(
+    QuicConnectionId client_connection_id) {
+  QUIC_DLOG(INFO) << "Unregistering " << client_connection_id;
+  if (client_connection_id_registrations_.find(client_connection_id) !=
+      client_connection_id_registrations_.end()) {
+    client_connection_id_registrations_.erase(client_connection_id);
+    owner_->UnregisterClientConnectionId(client_connection_id);
+    compression_engine_.UnregisterClientConnectionId(client_connection_id);
+  }
+}
+
+}  // namespace quic