29#ifdef BUILD_TLS_SUPPORT
30#include <openssl/ssl.h>
36#ifdef BUILD_TLS_SUPPORT
82template <policy::TlsPolicy TlsPolicy = policy::no_tls>
84 :
public std::enable_shared_from_this<unified_udp_messaging_client<TlsPolicy>>
93 std::function<void(
const std::vector<uint8_t>&,
const asio::ip::udp::endpoint&)>;
157 [[nodiscard]] auto
client_id() const -> const std::
string&;
178 [[nodiscard]] auto
start(std::string_view host, uint16_t port) ->
VoidResult override;
180 [[nodiscard]] auto
send(std::vector<uint8_t>&& data,
230#ifdef BUILD_TLS_SUPPORT
232 std::conditional_t<is_secure, internal::dtls_socket, internal::udp_socket>;
244#ifdef BUILD_TLS_SUPPORT
257 const asio::ip::udp::endpoint& endpoint) -> void;
295#ifdef BUILD_TLS_SUPPORT
297 [[no_unique_address]] TlsPolicy tls_config_;
310#ifdef BUILD_TLS_SUPPORT
320#include "unified_udp_messaging_client.inl"
Thread-safe callback registration and invocation manager.
Unified UDP client template parameterized by TLS policy.
auto set_receive_callback(interfaces::i_udp_client::receive_callback_t callback) -> void override
Sets the callback for received datagrams.
static constexpr bool is_secure
Indicates whether TLS (DTLS) is enabled for this client.
std::function< void(const std::vector< uint8_t > &, const asio::ip::udp::endpoint &)> receive_callback_t
Callback type for received datagrams with sender endpoint.
auto invoke_disconnected_callback() -> void
auto set_connected(bool connected) -> void
auto send_packet(std::vector< uint8_t > &&data) -> VoidResult
Sends a datagram to the configured target endpoint.
auto wait_for_stop() -> void override
Blocks until stop_client() is called.
auto is_running() const -> bool override
Checks if the client is currently running.
auto invoke_error_callback(std::error_code ec) -> void
auto set_error_callback(error_callback_t callback) -> void override
Sets the callback for errors.
unified_udp_messaging_client(std::string_view client_id)
Constructs a plain UDP client with a given identifier.
auto set_connected_callback(connected_callback_t callback) -> void
Sets the callback for connection established (DTLS handshake complete).
std::function< void()> disconnected_callback_t
Callback type for disconnection.
auto start_client(std::string_view host, uint16_t port) -> VoidResult
Starts the client by resolving target host and port.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
auto stop_client() -> VoidResult
Stops the client and releases all resources.
auto set_target(std::string_view host, uint16_t port) -> VoidResult override
Changes the target endpoint for future sends.
auto set_disconnected_callback(disconnected_callback_t callback) -> void
Sets the callback for disconnection.
unified_udp_messaging_client(std::string_view client_id, const TlsPolicy &tls_config)
Constructs a secure UDP client (DTLS) with TLS configuration.
std::atomic< bool > is_connected_
utils::lifecycle_manager lifecycle_
auto do_start_impl(std::string_view host, uint16_t port) -> VoidResult
auto send(std::vector< uint8_t > &&data, interfaces::i_udp_client::send_callback_t handler=nullptr) -> VoidResult override
Sends a datagram to the configured target endpoint.
auto do_stop_impl() -> VoidResult
~unified_udp_messaging_client() noexcept override
Destructor; automatically calls stop_client() if still running.
std::mutex endpoint_mutex_
std::function< void()> connected_callback_t
Callback type for connection established (DTLS handshake complete)
std::shared_ptr< integration::thread_pool_interface > thread_pool_
auto get_receive_callback() const -> receive_callback_t
std::shared_ptr< socket_type > socket_
auto client_id() const -> const std::string &
Returns the client identifier.
std::future< void > io_context_future_
auto get_error_callback() const -> error_callback_t
auto invoke_connected_callback() -> void
auto invoke_receive_callback(const std::vector< uint8_t > &data, const asio::ip::udp::endpoint &endpoint) -> void
auto stop() -> VoidResult override
Stops the UDP client.
auto start(std::string_view host, uint16_t port) -> VoidResult override
Starts the UDP client targeting the specified endpoint.
asio::ip::udp::endpoint target_endpoint_
auto is_connected() const noexcept -> bool
Checks if the client is connected (DTLS handshake complete).
std::unique_ptr< asio::io_context > io_context_
Interface for UDP client components.
std::function< void(std::error_code, std::size_t)> send_callback_t
Callback type for send completion.
A lightweight wrapper around asio::ip::udp::socket, enabling asynchronous datagram operations.
struct ssl_ctx_st SSL_CTX
Component lifecycle management (start, stop, restart).
constexpr bool is_tls_enabled_v
Helper variable template to check if TLS is enabled at compile time.
Result< std::monostate > VoidResult
unified_udp_client_callback
Callback indices for unified_udp_messaging_client.
Network-specific error and result type definitions.
Thread system integration interface for network_system.
Policy-based TLS configuration (no_tls, require_tls, optional_tls).