xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/test_tools/simple_session_cache.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_TEST_TOOLS_SIMPLE_SESSION_CACHE_H_
6 #define QUICHE_QUIC_TEST_TOOLS_SIMPLE_SESSION_CACHE_H_
7 
8 #include <memory>
9 
10 #include "quiche/quic/core/crypto/quic_crypto_client_config.h"
11 #include "quiche/quic/core/crypto/transport_parameters.h"
12 
13 namespace quic {
14 namespace test {
15 
16 // SimpleSessionCache provides a simple implementation of SessionCache that
17 // stores only one QuicResumptionState per QuicServerId. No limit is placed on
18 // the total number of entries in the cache. When Lookup is called, if a cache
19 // entry exists for the provided QuicServerId, the entry will be removed from
20 // the cached when it is returned.
21 // TODO(fayang): Remove SimpleSessionCache by using QuicClientSessionCache.
22 class SimpleSessionCache : public SessionCache {
23  public:
24   SimpleSessionCache() = default;
25   ~SimpleSessionCache() override = default;
26 
27   void Insert(const QuicServerId& server_id,
28               bssl::UniquePtr<SSL_SESSION> session,
29               const TransportParameters& params,
30               const ApplicationState* application_state) override;
31   std::unique_ptr<QuicResumptionState> Lookup(const QuicServerId& server_id,
32                                               QuicWallTime now,
33                                               const SSL_CTX* ctx) override;
34   void ClearEarlyData(const QuicServerId& server_id) override;
35   void OnNewTokenReceived(const QuicServerId& server_id,
36                           absl::string_view token) override;
37   void RemoveExpiredEntries(QuicWallTime now) override;
38   void Clear() override;
39 
40  private:
41   struct Entry {
42     bssl::UniquePtr<SSL_SESSION> session;
43     std::unique_ptr<TransportParameters> params;
44     std::unique_ptr<ApplicationState> application_state;
45     std::string token;
46   };
47   std::map<QuicServerId, Entry> cache_entries_;
48 };
49 
50 }  // namespace test
51 }  // namespace quic
52 
53 #endif  // QUICHE_QUIC_TEST_TOOLS_SIMPLE_SESSION_CACHE_H_
54