Modify QuicResumptionState and SessionCache to support multiple TLS sessions. gfe-relnote: unused code. not protected. Merge instructions: This CL introduces API changes that are not trivial to fix in Chromium. The best way to merge is to remove "quic/quic_client_session_cache.cc", "quic/quic_client_session_cache.h", "quic/quic_client_session_cache_unittests.cc" from BUILD.gn. The implementation isn't used yet. So it's safe to do so. PiperOrigin-RevId: 305534943 Change-Id: I7b427d2ca2e6fe0d53c74bea548910eb629b5488
diff --git a/quic/core/crypto/quic_crypto_client_config.h b/quic/core/crypto/quic_crypto_client_config.h index e4f7061..99ed31a 100644 --- a/quic/core/crypto/quic_crypto_client_config.h +++ b/quic/core/crypto/quic_crypto_client_config.h
@@ -42,13 +42,13 @@ // client didn't receive a 0-RTT capable session ticket from the server, // |transport_params| will be null. Otherwise, it will contain the transport // parameters received from the server on the original connection. - std::unique_ptr<TransportParameters> transport_params; + TransportParameters* transport_params; // If |transport_params| is null, then |application_state| is ignored and // should be empty. |application_state| contains serialized state that the // client received from the server at the application layer that the client // needs to remember when performing a 0-RTT handshake. - std::vector<uint8_t> application_state; + std::vector<uint8_t>* application_state; }; // SessionCache is an interface for managing storing and retrieving @@ -57,15 +57,18 @@ public: virtual ~SessionCache() {} - // Inserts |state| into the cache, keyed by |server_id|. Insert is called - // after a session ticket is received. If the session ticket is valid for - // 0-RTT, there may be a delay between its receipt and the call to Insert - // while waiting for application state for |state|. - // - // Insert may be called multiple times per connection. SessionCache - // implementations should support storing multiple entries per server ID. + // Inserts |session|, |params|, and |application_states| into the cache, keyed + // by |server_id|. Insert is first called after all three values are present. + // The ownership of |session| is transferred to the cache, while other two are + // copied. Multiple sessions might need to be inserted for a connection. + // SessionCache implementations should support storing + // multiple entries per server ID. + // TODO(renjietang): Once params and application_states are wired up, change + // the argument type to const&. virtual void Insert(const QuicServerId& server_id, - std::unique_ptr<QuicResumptionState> state) = 0; + bssl::UniquePtr<SSL_SESSION> session, + TransportParameters* params, + std::vector<uint8_t>* application_states) = 0; // Lookup is called once at the beginning of each TLS handshake to potentially // provide the saved state both for the TLS handshake and for sending 0-RTT
diff --git a/quic/core/tls_client_handshaker.cc b/quic/core/tls_client_handshaker.cc index 5148e71..b0a7d36 100644 --- a/quic/core/tls_client_handshaker.cc +++ b/quic/core/tls_client_handshaker.cc
@@ -486,9 +486,7 @@ QUIC_DVLOG(1) << "No session cache, not inserting a session"; return; } - auto cache_state = std::make_unique<QuicResumptionState>(); - cache_state->tls_session = std::move(session); - session_cache_->Insert(server_id_, std::move(cache_state)); + session_cache_->Insert(server_id_, std::move(session), nullptr, nullptr); } void TlsClientHandshaker::WriteMessage(EncryptionLevel level,
diff --git a/quic/test_tools/simple_session_cache.cc b/quic/test_tools/simple_session_cache.cc index 7787fbe..32f8436 100644 --- a/quic/test_tools/simple_session_cache.cc +++ b/quic/test_tools/simple_session_cache.cc
@@ -3,12 +3,18 @@ // found in the LICENSE file. #include "net/third_party/quiche/src/quic/test_tools/simple_session_cache.h" +#include <memory> +#include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_client_config.h" namespace quic { namespace test { void SimpleSessionCache::Insert(const QuicServerId& server_id, - std::unique_ptr<QuicResumptionState> state) { + bssl::UniquePtr<SSL_SESSION> session, + TransportParameters* /*params*/, + std::vector<uint8_t>* /*application_states*/) { + auto state = std::make_unique<QuicResumptionState>(); + state->tls_session = std::move(session); cache_entries_.insert(std::make_pair(server_id, std::move(state))); }
diff --git a/quic/test_tools/simple_session_cache.h b/quic/test_tools/simple_session_cache.h index 40a6946..62dbd6f 100644 --- a/quic/test_tools/simple_session_cache.h +++ b/quic/test_tools/simple_session_cache.h
@@ -21,7 +21,9 @@ ~SimpleSessionCache() override = default; void Insert(const QuicServerId& server_id, - std::unique_ptr<QuicResumptionState> state) override; + bssl::UniquePtr<SSL_SESSION> session, + TransportParameters* params, + std::vector<uint8_t>* application_states) override; std::unique_ptr<QuicResumptionState> Lookup(const QuicServerId& server_id, const SSL_CTX* ctx) override;