26#include <asio/ssl.hpp>
35#if KCENON_WITH_COMMON_SYSTEM
36 #include <kcenon/common/interfaces/monitoring_interface.h>
88 class secure_messaging_server
89 :
public std::enable_shared_from_this<secure_messaging_server>
98 const std::vector<uint8_t>&)>;
110 const std::string& cert_file,
111 const std::string& key_file);
156 [[nodiscard]] auto
is_running() const noexcept ->
bool;
162 [[nodiscard]] auto
server_id() const -> const std::
string&;
192#if KCENON_WITH_COMMON_SYSTEM
197 auto set_monitor(kcenon::common::interfaces::IMonitor* monitor) -> void;
203 auto get_monitor() const ->
kcenon::common::interfaces::IMonitor*;
283 auto
on_accept(std::error_code ec, asio::ip::
tcp::socket socket)
321 std::unique_ptr<asio::io_context>
323 std::unique_ptr<asio::executor_work_guard<asio::io_context::executor_type>>
325 std::unique_ptr<asio::ip::
tcp::acceptor>
328 std::shared_ptr<
integration::thread_pool_interface>
333 std::unique_ptr<asio::ssl::context>
351#if KCENON_WITH_COMMON_SYSTEM
355 kcenon::common::interfaces::IMonitor* monitor_ =
nullptr;
360 std::atomic<uint64_t> messages_received_{0};
361 std::atomic<uint64_t> messages_sent_{0};
362 std::atomic<uint64_t> connection_errors_{0};
Thread-safe callback registration and invocation manager.
A secure server class that manages incoming TLS/SSL encrypted TCP connections, creating secure_sessio...
std::unique_ptr< asio::ip::tcp::acceptor > acceptor_
std::function< void(const std::string &)> disconnection_callback_t
Callback type for disconnection.
auto on_accept(std::error_code ec, asio::ip::tcp::socket socket) -> void
Handler called when an asynchronous accept finishes.
auto set_connection_callback(connection_callback_t callback) -> void
Sets the callback for new client connections.
auto set_error_callback(error_callback_t callback) -> void
Sets the callback for session errors.
auto server_id() const -> const std::string &
Returns the server identifier.
auto cleanup_dead_sessions() -> void
Removes stopped sessions from the sessions vector.
auto do_stop_impl() -> VoidResult
Secure TCP-specific implementation of server stop.
auto get_connection_callback() const -> connection_callback_t
Gets a copy of the connection callback.
utils::lifecycle_manager lifecycle_
std::future< void > io_context_future_
auto get_disconnection_callback() const -> disconnection_callback_t
Gets a copy of the disconnection callback.
secure_messaging_server(std::string_view server_id, const std::string &cert_file, const std::string &key_file)
Constructs a secure_messaging_server with SSL/TLS support.
auto start_cleanup_timer() -> void
Starts a periodic timer that triggers session cleanup.
std::vector< std::shared_ptr< kcenon::network::session::secure_session > > sessions_
Holds all active secure sessions.
auto invoke_connection_callback(std::shared_ptr< session::secure_session > session) -> void
Invokes the connection callback with the given session.
std::unique_ptr< asio::io_context > io_context_
std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > work_guard_
~secure_messaging_server() noexcept
Destructor. If the server is still running, stop_server() is invoked.
auto start_server(unsigned short port) -> VoidResult
Starts the server on the specified port.
auto get_error_callback() const -> error_callback_t
Gets a copy of the error callback.
std::unique_ptr< asio::steady_timer > cleanup_timer_
Timer for periodic cleanup of stopped sessions.
auto stop_server() -> VoidResult
Stops the server and closes all connections.
std::unique_ptr< asio::ssl::context > ssl_context_
std::function< void(std::shared_ptr< session::secure_session >, std::error_code)> error_callback_t
Callback type for errors.
std::shared_ptr< integration::thread_pool_interface > thread_pool_
auto get_receive_callback() const -> receive_callback_t
Gets a copy of the receive callback.
auto do_accept() -> void
Initiates an asynchronous accept operation (async_accept).
std::function< void(std::shared_ptr< session::secure_session >)> connection_callback_t
Callback type for new connection.
std::function< void(std::shared_ptr< session::secure_session >, const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data.
auto do_start_impl(unsigned short port) -> VoidResult
Secure TCP-specific implementation of server start.
auto is_running() const noexcept -> bool
Check if the server is currently running.
auto set_disconnection_callback(disconnection_callback_t callback) -> void
Sets the callback for client disconnections.
auto wait_for_stop() -> void
Blocks until stop_server() is called.
auto set_receive_callback(receive_callback_t callback) -> void
Sets the callback for received messages.
std::mutex sessions_mutex_
Mutex protecting access to sessions_ vector.
Feature flags for network_system.
Component lifecycle management (start, stop, restart).
Result< std::monostate > VoidResult
tcp_server_callback
Callback indices for messaging_server and secure_messaging_server.
Network-specific error and result type definitions.
Thread system integration interface for network_system.