10#ifndef NETWORK_USE_EXPERIMENTAL
11#define NETWORK_USE_EXPERIMENTAL
23 : client_id_(client_id)
24 , client_(std::make_shared<core::messaging_quic_client>(client_id))
43 alpn_protocols_ = protocols;
46 client_->set_alpn_protocols(protocols);
52 ca_cert_path_ = std::string(path);
57 client_cert_path_ = std::string(cert_path);
58 client_key_path_ = std::string(key_path);
63 verify_server_ = verify;
68 max_idle_timeout_ms_ = timeout_ms;
84 client_->wait_for_stop();
98 "Client not initialized",
99 "quic_client_adapter::start"
105 config.ca_cert_file = ca_cert_path_;
106 config.client_cert_file = client_cert_path_;
107 config.client_key_file = client_key_path_;
108 config.verify_server = verify_server_;
109 config.alpn_protocols = alpn_protocols_;
110 config.max_idle_timeout_ms = max_idle_timeout_ms_;
112 return client_->start_client(host, port,
config);
121 "Client not initialized",
122 "quic_client_adapter::stop"
126 return client_->stop_client();
135 "Client not initialized",
136 "quic_client_adapter::send"
140 if (!client_->is_connected())
144 "Client is not connected",
145 "quic_client_adapter::send"
149 return client_->send(std::move(data));
159 std::lock_guard<std::mutex> lock(callbacks_mutex_);
160 observer_ = std::move(observer);
165 std::lock_guard<std::mutex> lock(callbacks_mutex_);
166 receive_callback_ = std::move(callback);
171 std::lock_guard<std::mutex> lock(callbacks_mutex_);
172 connected_callback_ = std::move(callback);
177 std::lock_guard<std::mutex> lock(callbacks_mutex_);
178 disconnected_callback_ = std::move(callback);
183 std::lock_guard<std::mutex> lock(callbacks_mutex_);
184 error_callback_ = std::move(callback);
199 client_->set_receive_callback([
this](
const std::vector<uint8_t>& data) {
200 std::shared_ptr<interfaces::connection_observer> observer_copy;
203 std::lock_guard<std::mutex> lock(callbacks_mutex_);
204 observer_copy = observer_;
205 callback_copy = receive_callback_;
210 observer_copy->on_receive(data);
219 client_->set_connected_callback([
this]() {
220 std::shared_ptr<interfaces::connection_observer> observer_copy;
223 std::lock_guard<std::mutex> lock(callbacks_mutex_);
224 observer_copy = observer_;
225 callback_copy = connected_callback_;
230 observer_copy->on_connected();
239 client_->set_disconnected_callback([
this]() {
240 std::shared_ptr<interfaces::connection_observer> observer_copy;
243 std::lock_guard<std::mutex> lock(callbacks_mutex_);
244 observer_copy = observer_;
245 callback_copy = disconnected_callback_;
250 observer_copy->on_disconnected();
259 client_->set_error_callback([
this](std::error_code ec) {
260 std::shared_ptr<interfaces::connection_observer> observer_copy;
263 std::lock_guard<std::mutex> lock(callbacks_mutex_);
264 observer_copy = observer_;
265 callback_copy = error_callback_;
270 observer_copy->on_error(ec);
std::function< void(const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data.
std::function< void()> connected_callback_t
Callback type for connection established.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
std::function< void()> disconnected_callback_t
Callback type for disconnection.
auto is_connected() const -> bool override
Checks if the client is connected to the server.
auto set_max_idle_timeout(uint64_t timeout_ms) -> void
Sets max idle timeout in milliseconds.
auto set_connected_callback(connected_callback_t callback) -> void override
Sets the callback for connection established.
auto send(std::vector< uint8_t > &&data) -> VoidResult override
Sends data to the connected server.
auto set_verify_server(bool verify) -> void
Sets whether to verify server certificate.
quic_client_adapter(std::string_view client_id)
Constructs an adapter with a unique client ID.
auto wait_for_stop() -> void override
Blocks until the component has stopped.
auto stop() -> VoidResult override
Stops the client and closes the connection.
auto set_client_cert(std::string_view cert_path, std::string_view key_path) -> void
Sets client certificate path for mutual TLS.
auto set_receive_callback(receive_callback_t callback) -> void override
Sets the callback for received data.
auto is_running() const -> bool override
Checks if the component is currently running.
auto setup_internal_callbacks() -> void
Sets up internal callbacks to bridge QUIC callbacks to i_protocol_client callbacks.
auto set_observer(std::shared_ptr< interfaces::connection_observer > observer) -> void override
Sets the connection observer for unified event handling.
auto set_alpn_protocols(const std::vector< std::string > &protocols) -> void
Sets the ALPN protocols for negotiation.
auto set_disconnected_callback(disconnected_callback_t callback) -> void override
Sets the callback for disconnection.
std::shared_ptr< core::messaging_quic_client > client_
~quic_client_adapter() override
Destructor ensures proper cleanup.
auto set_ca_cert_path(std::string_view path) -> void
Sets CA certificate path for server verification.
auto set_error_callback(error_callback_t callback) -> void override
Sets the callback for errors.
auto start(std::string_view host, uint16_t port) -> VoidResult override
Starts the client and connects to the specified server.
constexpr int invalid_argument
constexpr int internal_error
VoidResult error_void(int code, const std::string &message, const std::string &source="network_system", const std::string &details="")
Network-specific error and result type definitions.
Configuration options for QUIC client.