Change QuartcClientEndpoint to handle client-side version negotiation.

This allows Quartc to stop forcing the "no connection version negotiation" flags
to false, as QuartcEndpoint can now handle version negotiation properly in
either case.  (QuartcServerEndpoint already handles server-side version
negotiation through the QuartcDispatcher.)  In-connection version negotiation is
not fully reliable anyway, as some features of new QUIC versions cannot be
enabled or disabled in-place within a QuicConnection object (for example,
changes to how stream ids are allocated).

This only requires three changes:
 - QuartcEndpoint::Delegate extends QuartcSession::Delegate
 - QuartcClientEndpoint sits between the session and the final delegate
 - When QuartcClientEndpoint sees a QUIC_INVALID_VERSION error, it picks another
   version and tries again

This change is mostly cleanup to combine Endpoint and Session delegates and add
required overrides to existing delegates.

The only other minor change required is that QuartcMediaTransport must now
accept more than one call to OnSessionCreated().  All we have to do is remove
the DCHECK to allow this--nothing else assumes it will only happen once.

gfe-relnote: n/a (Quartc only)
PiperOrigin-RevId: 248378366
Change-Id: I442bd69e45f5d65e43d3e99118159f11dc595169
diff --git a/quic/quartc/quartc_session_test.cc b/quic/quartc/quartc_session_test.cc
index e150e03..87174dc 100644
--- a/quic/quartc/quartc_session_test.cc
+++ b/quic/quartc/quartc_session_test.cc
@@ -61,29 +61,25 @@
         QuicBandwidth::FromKBitsPerSecond(10 * 1000), kPropagationDelay);
 
     client_stream_delegate_ = QuicMakeUnique<FakeQuartcStreamDelegate>();
-    client_session_delegate_ = QuicMakeUnique<FakeQuartcSessionDelegate>(
+    client_session_delegate_ = QuicMakeUnique<FakeQuartcEndpointDelegate>(
         client_stream_delegate_.get(), simulator_.GetClock());
-    client_endpoint_delegate_ = QuicMakeUnique<FakeQuartcEndpointDelegate>(
-        client_session_delegate_.get());
 
     server_stream_delegate_ = QuicMakeUnique<FakeQuartcStreamDelegate>();
-    server_session_delegate_ = QuicMakeUnique<FakeQuartcSessionDelegate>(
+    server_session_delegate_ = QuicMakeUnique<FakeQuartcEndpointDelegate>(
         server_stream_delegate_.get(), simulator_.GetClock());
-    server_endpoint_delegate_ = QuicMakeUnique<FakeQuartcEndpointDelegate>(
-        server_session_delegate_.get());
 
     // No 0-rtt setup, because server config is empty.
     // CannotCreateDataStreamBeforeHandshake depends on 1-rtt setup.
     if (create_client_endpoint) {
       client_endpoint_ = QuicMakeUnique<QuartcClientEndpoint>(
           simulator_.GetAlarmFactory(), simulator_.GetClock(),
-          simulator_.GetRandomGenerator(), client_endpoint_delegate_.get(),
+          simulator_.GetRandomGenerator(), client_session_delegate_.get(),
           quic::QuartcSessionConfig(),
           /*serialized_server_config=*/"");
     }
     server_endpoint_ = QuicMakeUnique<QuartcServerEndpoint>(
         simulator_.GetAlarmFactory(), simulator_.GetClock(),
-        simulator_.GetRandomGenerator(), server_endpoint_delegate_.get(),
+        simulator_.GetRandomGenerator(), server_session_delegate_.get(),
         quic::QuartcSessionConfig());
   }
 
@@ -99,12 +95,12 @@
     client_endpoint_->Connect(client_transport_.get());
 
     CHECK(simulator_.RunUntil([this] {
-      return client_endpoint_delegate_->session() != nullptr &&
-             server_endpoint_delegate_->session() != nullptr;
+      return client_session_delegate_->session() != nullptr &&
+             server_session_delegate_->session() != nullptr;
     }));
 
-    client_peer_ = client_endpoint_delegate_->session();
-    server_peer_ = server_endpoint_delegate_->session();
+    client_peer_ = client_session_delegate_->session();
+    server_peer_ = server_session_delegate_->session();
   }
 
   // Runs all tasks scheduled in the next 200 ms.
@@ -214,11 +210,11 @@
     QuartcSession* const peer_sending =
         direction_from_server ? server_peer_ : client_peer_;
 
-    FakeQuartcSessionDelegate* const delegate_receiving =
+    FakeQuartcEndpointDelegate* const delegate_receiving =
         direction_from_server ? client_session_delegate_.get()
                               : server_session_delegate_.get();
 
-    FakeQuartcSessionDelegate* const delegate_sending =
+    FakeQuartcEndpointDelegate* const delegate_sending =
         direction_from_server ? server_session_delegate_.get()
                               : client_session_delegate_.get();
 
@@ -299,11 +295,9 @@
   std::unique_ptr<simulator::SymmetricLink> client_server_link_;
 
   std::unique_ptr<FakeQuartcStreamDelegate> client_stream_delegate_;
-  std::unique_ptr<FakeQuartcSessionDelegate> client_session_delegate_;
-  std::unique_ptr<FakeQuartcEndpointDelegate> client_endpoint_delegate_;
+  std::unique_ptr<FakeQuartcEndpointDelegate> client_session_delegate_;
   std::unique_ptr<FakeQuartcStreamDelegate> server_stream_delegate_;
-  std::unique_ptr<FakeQuartcSessionDelegate> server_session_delegate_;
-  std::unique_ptr<FakeQuartcEndpointDelegate> server_endpoint_delegate_;
+  std::unique_ptr<FakeQuartcEndpointDelegate> server_session_delegate_;
 
   std::unique_ptr<QuartcClientEndpoint> client_endpoint_;
   std::unique_ptr<QuartcServerEndpoint> server_endpoint_;
@@ -537,7 +531,7 @@
 
   client_endpoint_ = QuicMakeUnique<QuartcClientEndpoint>(
       simulator_.GetAlarmFactory(), simulator_.GetClock(),
-      simulator_.GetRandomGenerator(), client_endpoint_delegate_.get(),
+      simulator_.GetRandomGenerator(), client_session_delegate_.get(),
       QuartcSessionConfig(),
       // This is the key line here. It passes through the server config
       // from the server to the client.
@@ -549,8 +543,8 @@
   // client session should be created, but server won't be created yet.
   simulator_.RunFor(QuicTime::Delta::FromMilliseconds(1));
 
-  client_peer_ = client_endpoint_delegate_->session();
-  server_peer_ = server_endpoint_delegate_->session();
+  client_peer_ = client_session_delegate_->session();
+  server_peer_ = server_session_delegate_->session();
 
   ASSERT_NE(client_peer_, nullptr);
   ASSERT_EQ(server_peer_, nullptr);