6#ifndef KCENON_NETWORK_INTERNAL_EXPERIMENTAL_QUIC_CLIENT_H_
7#define KCENON_NETWORK_INTERNAL_EXPERIMENTAL_QUIC_CLIENT_H_
23#include <system_error>
149 :
public std::enable_shared_from_this<messaging_quic_client>
215 [[nodiscard]] auto
client_id() const -> const std::
string&;
265 [[nodiscard]] auto
is_running() const ->
bool override;
286 [[nodiscard]] auto
start(std::string_view host, uint16_t port) ->
VoidResult override;
302 [[nodiscard]] auto
is_connected() const ->
bool override;
319 [[nodiscard]] auto
send(std::vector<uint8_t>&& data) ->
VoidResult override;
348 std::vector<uint8_t>&& data,
374 [[nodiscard]] auto
alpn_protocol() const -> std::optional<std::
string> override;
483 auto
do_connect(std::string_view host,
unsigned short port) ->
void;
494 std::span<const uint8_t> data,
500 auto
on_error(std::error_code ec) ->
void;
505 auto
on_close(uint64_t error_code, const std::
string& reason) ->
void;
510 auto
get_socket() const -> std::shared_ptr<internal::quic_socket>;
529 const std::vector<uint8_t>& data,
570 std::unique_ptr<asio::executor_work_guard<asio::io_context::executor_type>>
572 std::shared_ptr<integration::thread_pool_interface>
577 std::shared_ptr<internal::quic_socket>
socket_;
Thread-safe callback registration and invocation manager.
A QUIC client that provides reliable, multiplexed communication.
std::shared_ptr< internal::quic_socket > socket_
The QUIC socket.
auto set_disconnected_callback(interfaces::i_quic_client::disconnected_callback_t callback) -> void override
Sets the callback for disconnection (interface version).
interfaces::i_quic_client::session_ticket_callback_t session_ticket_cb_
Session ticket callback.
std::function< void()> disconnected_callback_t
Callback type for disconnection.
auto stop() -> VoidResult override
Stops the QUIC client.
auto wait_for_stop() -> void override
Blocks until stop() is called.
auto send(std::vector< uint8_t > &&data) -> VoidResult override
Sends data on the default stream (interface version).
std::mutex socket_mutex_
Protects socket_ from data races.
auto do_stop_impl() -> VoidResult
QUIC-specific implementation of client stop.
auto on_connect() -> void
Callback invoked when connection is established.
std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > work_guard_
Keeps io_context running.
uint64_t default_stream_id_
Default stream for send_packet()
interfaces::i_quic_client::early_data_callback_t early_data_cb_
Early data production callback.
messaging_quic_client(std::string_view client_id)
Constructs a QUIC client with a given identifier.
auto is_running() const -> bool override
Checks if the client is currently running.
auto create_unidirectional_stream() -> Result< uint64_t > override
Creates a new unidirectional stream (interface version).
auto on_close(uint64_t error_code, const std::string &reason) -> void
Callback for connection close.
~messaging_quic_client() noexcept override
Destructor; automatically calls stop_client() if running.
auto alpn_protocol() const -> std::optional< std::string > override
Gets the negotiated ALPN protocol (interface version).
auto is_handshake_complete() const -> bool override
Checks if TLS handshake is complete (interface version).
auto invoke_stream_receive_callback(uint64_t stream_id, const std::vector< uint8_t > &data, bool fin) -> void
Invokes the stream receive callback.
auto set_early_data_accepted_callback(interfaces::i_quic_client::early_data_accepted_callback_t callback) -> void override
Sets the callback for early data acceptance notification (interface version).
auto start_client(std::string_view host, unsigned short port) -> VoidResult
Starts the client with default configuration.
auto close_stream(uint64_t stream_id) -> VoidResult override
Closes a stream (interface version).
std::unique_ptr< asio::io_context > io_context_
I/O context.
std::function< void(uint64_t, const std::vector< uint8_t > &, bool)> stream_receive_callback_t
Callback type for stream data (stream_id, data, fin)
std::shared_ptr< integration::thread_pool_interface > thread_pool_
Thread pool for async ops.
auto invoke_connected_callback() -> void
Invokes the connected callback.
auto send_on_stream(uint64_t stream_id, std::vector< uint8_t > &&data, bool fin=false) -> VoidResult override
Sends data on a specific stream (interface version).
auto do_start_impl(std::string_view host, unsigned short port) -> VoidResult
QUIC-specific implementation of client start.
std::atomic< bool > handshake_complete_
TLS handshake status.
auto invoke_receive_callback(const std::vector< uint8_t > &data) -> void
Invokes the receive callback.
auto set_session_ticket_callback(interfaces::i_quic_client::session_ticket_callback_t callback) -> void override
Sets the callback for session tickets (interface version).
auto set_receive_callback(interfaces::i_quic_client::receive_callback_t callback) -> void override
Sets the callback for received data on default stream (interface version).
auto set_stream_callback(interfaces::i_quic_client::stream_callback_t callback) -> void override
Sets the callback for stream data (interface version).
auto send_packet(std::vector< uint8_t > &&data) -> VoidResult
Send data on the default stream (stream 0).
std::function< void()> connected_callback_t
Callback type for connection established.
quic_client_config config_
Client configuration.
auto on_stream_data(uint64_t stream_id, std::span< const uint8_t > data, bool fin) -> void
Callback for receiving stream data.
auto stop_client() -> VoidResult
Stops the client and releases all resources.
interfaces::i_quic_client::early_data_accepted_callback_t early_data_accepted_cb_
Early data acceptance callback.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
std::function< void(const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data.
auto invoke_disconnected_callback() -> void
Invokes the disconnected callback.
auto on_error(std::error_code ec) -> void
Callback for handling errors.
std::future< void > io_context_future_
Future for io_context run.
auto do_connect(std::string_view host, unsigned short port) -> void
Internal connection implementation.
auto create_stream() -> Result< uint64_t > override
Creates a new bidirectional stream (interface version).
std::atomic< bool > is_connected_
auto invoke_error_callback(std::error_code ec) -> void
Invokes the error callback.
auto is_connected() const -> bool override
Checks if the client is connected (interface version).
auto set_connected_callback(interfaces::i_quic_client::connected_callback_t callback) -> void override
Sets the callback for connection established (interface version).
auto start(std::string_view host, uint16_t port) -> VoidResult override
Starts the QUIC client connecting to the specified server.
auto set_stream_receive_callback(stream_receive_callback_t callback) -> void
Sets the callback for stream data reception (all streams, legacy version).
auto is_early_data_accepted() const -> bool override
Checks if early data was accepted (interface version).
auto stats() const -> quic_connection_stats
Get connection statistics.
auto client_id() const -> const std::string &
Returns the client identifier.
auto get_socket() const -> std::shared_ptr< internal::quic_socket >
Get the internal socket with mutex protection.
auto set_alpn_protocols(const std::vector< std::string > &protocols) -> void override
Sets the ALPN protocols for negotiation (interface version).
std::atomic< bool > early_data_accepted_
Early data acceptance status.
auto set_error_callback(interfaces::i_quic_client::error_callback_t callback) -> void override
Sets the callback for errors (interface version).
utils::lifecycle_manager lifecycle_
auto set_early_data_callback(interfaces::i_quic_client::early_data_callback_t callback) -> void override
Sets the callback for early data production (interface version).
Interface for QUIC client components.
std::function< void(bool accepted)> early_data_accepted_callback_t
Callback type for early data acceptance notification.
std::function< std::vector< uint8_t >()> early_data_callback_t
Callback type for early data production.
std::function< void( std::vector< uint8_t > ticket_data, uint32_t lifetime_hint, uint32_t max_early_data)> session_ticket_callback_t
Callback type for session ticket received (for 0-RTT resumption)
std::function< void(uint64_t, const std::vector< uint8_t > &, bool)> stream_callback_t
Callback type for stream data (stream_id, data, is_fin)
Macros and utilities for marking experimental APIs.
#define NETWORK_REQUIRE_EXPERIMENTAL
Enforces opt-in for experimental APIs at compile time.
Component lifecycle management (start, stop, restart).
quic_role
Role of the QUIC endpoint (client or server)
quic_client_callback
Callback indices for messaging_quic_client.
Global context for shared network system resources.
Network-specific error and result type definitions.
Configuration options for QUIC client.
std::optional< std::string > ca_cert_file
Path to CA certificate file for server verification (PEM format)
uint64_t initial_max_streams_uni
Initial maximum unidirectional streams (default: 100)
bool verify_server
Whether to verify server certificate (default: true)
std::optional< std::vector< uint8_t > > session_ticket
Session ticket for 0-RTT resumption.
uint64_t initial_max_data
Initial maximum data that can be sent (default: 1 MB)
uint64_t max_idle_timeout_ms
Maximum idle timeout in milliseconds (default: 30 seconds)
uint32_t max_early_data_size
Maximum early data size in bytes (default: 16KB, 0 to disable)
uint64_t initial_max_stream_data
Initial maximum data per stream (default: 64 KB)
uint64_t initial_max_streams_bidi
Initial maximum bidirectional streams (default: 100)
std::optional< std::string > client_key_file
Path to client private key file for mutual TLS (PEM format)
bool enable_early_data
Enable 0-RTT early data (default: false)
std::optional< std::string > client_cert_file
Path to client certificate file for mutual TLS (PEM format)
std::vector< std::string > alpn_protocols
ALPN protocols to negotiate (e.g., {"h3", "hq-29"})
Statistics for a QUIC connection.
uint64_t packets_received
Total packets received.
uint64_t bytes_received
Total bytes received.
std::chrono::microseconds smoothed_rtt
Smoothed RTT.
std::chrono::microseconds min_rtt
Minimum RTT observed.
size_t cwnd
Congestion window size.
uint64_t bytes_sent
Total bytes sent.
uint64_t packets_sent
Total packets sent.
uint64_t packets_lost
Total packets lost.
Thread system integration interface for network_system.