9#include <botan/tls_session_manager_memory.h>
12#include <botan/internal/stl_util.h>
19 size_t max_sessions) :
21 if(max_sessions > 0) {
32 if(m_fifo.has_value()) {
33 while(m_sessions.size() >=
capacity()) {
35 m_sessions.erase(m_fifo->front());
45 if(m_fifo.has_value()) {
46 m_fifo->emplace_back(std::move(
id));
53 if(
auto id = handle.
id()) {
54 const auto session = m_sessions.find(
id.value());
55 if(session != m_sessions.end()) {
56 return session->second.session;
64 const size_t max_sessions_hint) {
69 std::vector<Session_with_Handle> found_sessions;
71 for(
const auto& [_, session_and_handle] : m_sessions) {
72 if(session_and_handle.session.server_info() == info) {
73 found_sessions.emplace_back(session_and_handle);
77 return found_sessions;
82 return remove_internal(handle);
85size_t Session_Manager_In_Memory::remove_internal(
const Session_Handle& handle) {
99 const auto before = m_sessions.size();
100 std::erase_if(m_sessions, [&](
const auto& item) {
101 const auto& [_unused1, session_and_handle] = item;
102 const auto& [_unused2, this_handle] = session_and_handle;
103 return this_handle.is_ticket() && this_handle.ticket().value() == ticket;
105 return before - m_sessions.size();
107 [&](
const Session_ID& id) ->
size_t {
return m_sessions.erase(
id); },
109 if(
auto id = handle.
id()) {
110 auto removed = remove_internal(
id.value());
116 if(
auto ticket = handle.
ticket()) {
117 return remove_internal(ticket.value());
129 const auto sessions = m_sessions.size();
131 if(m_fifo.has_value()) {
#define BOTAN_ASSERT_NOMSG(expr)
Helper class to embody a session handle in all protocol versions.
std::optional< Session_Ticket > ticket() const
decltype(auto) get() const
std::optional< Session_ID > id() const
void store(const Session &session, const Session_Handle &handle) override
Save a Session under a Session_Handle (TLS Client)
size_t remove_all() override
Session_Manager_In_Memory(const std::shared_ptr< RandomNumberGenerator > &rng, size_t max_sessions=1000)
std::vector< Session_with_Handle > find_some(const Server_Information &info, size_t max_sessions_hint) override
Internal retrieval function to find sessions to resume.
size_t remove(const Session_Handle &handle) override
std::optional< Session > retrieve_one(const Session_Handle &handle) override
Internal retrieval function for a single session.
recursive_mutex_type & mutex()
std::shared_ptr< RandomNumberGenerator > m_rng
Strong< std::vector< uint8_t >, struct Session_ID_ > Session_ID
holds a TLS 1.2 session ID for stateful resumption
Strong< std::vector< uint8_t >, struct Opaque_Session_Handle_ > Opaque_Session_Handle
holds an opaque session handle as used in TLS 1.3 that could be either a ticket for stateless resumpt...