Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 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 | #include "quiche/quic/test_tools/simple_session_cache.h" |
Bence Béky | 8247a39 | 2022-04-12 10:24:20 -0400 | [diff] [blame] | 6 | |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 7 | #include <memory> |
Bence Béky | 8247a39 | 2022-04-12 10:24:20 -0400 | [diff] [blame] | 8 | |
Bence Béky | bac0405 | 2022-04-07 15:44:29 -0400 | [diff] [blame] | 9 | #include "quiche/quic/core/crypto/quic_crypto_client_config.h" |
| 10 | |
| 11 | namespace quic { |
| 12 | namespace test { |
| 13 | |
| 14 | void SimpleSessionCache::Insert(const QuicServerId& server_id, |
| 15 | bssl::UniquePtr<SSL_SESSION> session, |
| 16 | const TransportParameters& params, |
| 17 | const ApplicationState* application_state) { |
| 18 | auto it = cache_entries_.find(server_id); |
| 19 | if (it == cache_entries_.end()) { |
| 20 | it = cache_entries_.insert(std::make_pair(server_id, Entry())).first; |
| 21 | } |
| 22 | if (session != nullptr) { |
| 23 | it->second.session = std::move(session); |
| 24 | } |
| 25 | if (application_state != nullptr) { |
| 26 | it->second.application_state = |
| 27 | std::make_unique<ApplicationState>(*application_state); |
| 28 | } |
| 29 | it->second.params = std::make_unique<TransportParameters>(params); |
| 30 | } |
| 31 | |
| 32 | std::unique_ptr<QuicResumptionState> SimpleSessionCache::Lookup( |
| 33 | const QuicServerId& server_id, QuicWallTime /*now*/, |
| 34 | const SSL_CTX* /*ctx*/) { |
| 35 | auto it = cache_entries_.find(server_id); |
| 36 | if (it == cache_entries_.end()) { |
| 37 | return nullptr; |
| 38 | } |
| 39 | |
| 40 | if (!it->second.session) { |
| 41 | cache_entries_.erase(it); |
| 42 | return nullptr; |
| 43 | } |
| 44 | |
| 45 | auto state = std::make_unique<QuicResumptionState>(); |
| 46 | state->tls_session = std::move(it->second.session); |
| 47 | if (it->second.application_state != nullptr) { |
| 48 | state->application_state = |
| 49 | std::make_unique<ApplicationState>(*it->second.application_state); |
| 50 | } |
| 51 | state->transport_params = |
| 52 | std::make_unique<TransportParameters>(*it->second.params); |
| 53 | state->token = it->second.token; |
| 54 | return state; |
| 55 | } |
| 56 | |
| 57 | void SimpleSessionCache::ClearEarlyData(const QuicServerId& /*server_id*/) { |
| 58 | // The simple session cache only stores 1 SSL ticket per entry, so no need to |
| 59 | // do anything here. |
| 60 | } |
| 61 | |
| 62 | void SimpleSessionCache::OnNewTokenReceived(const QuicServerId& server_id, |
| 63 | absl::string_view token) { |
| 64 | auto it = cache_entries_.find(server_id); |
| 65 | if (it == cache_entries_.end()) { |
| 66 | return; |
| 67 | } |
| 68 | it->second.token = std::string(token); |
| 69 | } |
| 70 | |
| 71 | void SimpleSessionCache::RemoveExpiredEntries(QuicWallTime /*now*/) { |
| 72 | // The simple session cache does not support removing expired entries. |
| 73 | } |
| 74 | |
| 75 | void SimpleSessionCache::Clear() { cache_entries_.clear(); } |
| 76 | |
| 77 | } // namespace test |
| 78 | } // namespace quic |