12#include <system_error>
48 class dtls_socket :
public std::enable_shared_from_this<dtls_socket>
91 std::function<
void(std::error_code)> handler) -> void;
102 std::function<
void(
const std::vector<uint8_t>&,
103 const asio::ip::udp::endpoint&)> callback) -> void;
139 std::vector<uint8_t>&& data,
140 std::function<
void(std::error_code, std::size_t)> handler) -> void;
151 std::vector<uint8_t>&& data,
152 const asio::ip::udp::endpoint& endpoint,
153 std::function<
void(std::error_code, std::size_t)> handler) -> void;
194 const asio::ip::udp::endpoint& sender) -> void;
228 std::function<
void(const std::vector<uint8_t>&, const asio::ip::udp::endpoint&)>
230 std::function<
void(std::error_code)>
232 std::function<
void(std::error_code)>
A wrapper around ASIO UDP socket with OpenSSL DTLS encryption.
std::atomic< bool > handshake_in_progress_
handshake_type handshake_type_
std::array< uint8_t, 65536 > read_buffer_
std::mutex callback_mutex_
auto async_send(std::vector< uint8_t > &&data, std::function< void(std::error_code, std::size_t)> handler) -> void
Initiates an asynchronous encrypted send.
dtls_socket(const dtls_socket &)=delete
dtls_socket & operator=(dtls_socket &&)=delete
auto async_handshake(handshake_type type, std::function< void(std::error_code)> handler) -> void
Performs asynchronous DTLS handshake.
asio::ip::udp::endpoint peer_endpoint_
std::atomic< bool > handshake_complete_
auto make_ssl_error() const -> std::error_code
Creates an OpenSSL error code from the current error state.
handshake_type
Handshake type enumeration.
auto set_receive_callback(std::function< void(const std::vector< uint8_t > &, const asio::ip::udp::endpoint &)> callback) -> void
Sets a callback to receive decrypted inbound datagrams.
std::function< void(const std::vector< uint8_t > &, const asio::ip::udp::endpoint &)> receive_callback_
auto set_error_callback(std::function< void(std::error_code)> callback) -> void
Sets a callback to handle socket errors.
auto stop_receive() -> void
Stops the receive loop.
dtls_socket & operator=(const dtls_socket &)=delete
asio::ip::udp::socket socket_
auto set_peer_endpoint(const asio::ip::udp::endpoint &endpoint) -> void
Sets the peer endpoint for connected mode.
auto is_handshake_complete() const -> bool
Checks if the DTLS handshake is complete.
std::function< void(std::error_code)> handshake_callback_
asio::ip::udp::endpoint sender_endpoint_
auto flush_bio_output() -> void
Flushes pending DTLS output to the network.
auto start_receive() -> void
Begins the continuous asynchronous receive loop.
auto process_received_data(const std::vector< uint8_t > &data, const asio::ip::udp::endpoint &sender) -> void
Processes received encrypted data through DTLS.
std::mutex endpoint_mutex_
auto socket() -> asio::ip::udp::socket &
Provides direct access to the underlying UDP socket.
std::function< void(std::error_code)> error_callback_
dtls_socket(asio::ip::udp::socket socket, SSL_CTX *ssl_ctx)
Constructs a dtls_socket with an existing UDP socket.
auto peer_endpoint() const -> asio::ip::udp::endpoint
Returns the peer endpoint.
auto continue_handshake() -> void
Continues the handshake process.
auto do_receive() -> void
Internal function to handle the receive logic.
auto async_send_to(std::vector< uint8_t > &&data, const asio::ip::udp::endpoint &endpoint, std::function< void(std::error_code, std::size_t)> handler) -> void
Initiates an asynchronous encrypted send to a specific endpoint.
dtls_socket(dtls_socket &&)=delete
~dtls_socket()
Destructor. Cleans up OpenSSL resources.
std::atomic< bool > is_receiving_
struct ssl_ctx_st SSL_CTX
OpenSSL utilities and version definitions.