32#include <asio/ssl.hpp>
34#include "kcenon/network/internal/tcp/secure_tcp_socket.h"
64 :
public std::enable_shared_from_this<secure_session>
74 asio::ssl::context& ssl_context,
113 auto send_packet(std::vector<uint8_t>&& data) -> void;
120 std::function<
void(
const std::vector<uint8_t>&)> callback) -> void;
127 std::function<
void(
const std::string&)> callback) -> void;
134 std::function<
void(std::error_code)> callback) -> void;
140 [[nodiscard]]
auto server_id() const -> const std::
string& {
153 auto on_receive(
const std::vector<uint8_t>& data) -> void;
161 auto on_error(std::error_code ec) -> void;
174 std::shared_ptr<internal::secure_tcp_socket>
Manages a single connected secure (TLS/SSL) client session on the server side, providing asynchronous...
auto stop_session() -> void
Stops the session by closing the socket and marking the session as inactive.
std::function< void(const std::vector< uint8_t > &)> receive_callback_
Callbacks for session events.
auto process_next_message() -> void
Processes pending messages from the queue.
auto is_stopped() const noexcept -> bool
Checks if the session has been stopped.
std::mutex callback_mutex_
Mutex protecting callback access.
std::mutex queue_mutex_
Mutex protecting access to pending_messages_ queue.
std::shared_ptr< internal::secure_tcp_socket > socket_
~secure_session() noexcept
Destructor; calls stop_session() if not already stopped.
std::atomic< bool > is_stopped_
std::function< void(const std::string &)> disconnection_callback_
std::deque< std::vector< uint8_t > > pending_messages_
Queue of pending received messages awaiting processing.
std::function< void(std::error_code)> error_callback_
auto set_error_callback(std::function< void(std::error_code)> callback) -> void
Sets the callback for errors.
auto set_disconnection_callback(std::function< void(const std::string &)> callback) -> void
Sets the callback for disconnection.
auto set_receive_callback(std::function< void(const std::vector< uint8_t > &)> callback) -> void
Sets the callback for received data.
auto start_session() -> void
Starts the session: performs SSL handshake, sets up read/error callbacks, and begins reading data.
auto on_error(std::error_code ec) -> void
Callback for handling socket errors from secure_tcp_socket.
secure_session(asio::ip::tcp::socket socket, asio::ssl::context &ssl_context, std::string_view server_id)
Constructs a secure session with a given socket, SSL context, and server_id.
auto send_packet(std::vector< uint8_t > &&data) -> void
Sends data to the connected client with encryption.
auto server_id() const -> const std::string &
Gets the server identifier.
static constexpr size_t max_pending_messages_
Maximum number of pending messages before applying backpressure.
auto on_receive(const std::vector< uint8_t > &data) -> void
Callback for when encrypted data arrives from the client.