Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
i_quic_client.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
8
9#include <cstdint>
10#include <functional>
11#include <optional>
12#include <string>
13#include <string_view>
14#include <system_error>
15#include <vector>
16
18
20{
21
42 {
43 public:
45 using receive_callback_t = std::function<void(const std::vector<uint8_t>&)>;
46
48 using stream_callback_t = std::function<void(uint64_t, const std::vector<uint8_t>&, bool)>;
49
51 using connected_callback_t = std::function<void()>;
52
54 using disconnected_callback_t = std::function<void()>;
55
57 using error_callback_t = std::function<void(std::error_code)>;
58
60 using session_ticket_callback_t = std::function<void(
61 std::vector<uint8_t> ticket_data,
62 uint32_t lifetime_hint,
63 uint32_t max_early_data)>;
64
66 using early_data_callback_t = std::function<std::vector<uint8_t>()>;
67
69 using early_data_accepted_callback_t = std::function<void(bool accepted)>;
70
85 [[nodiscard]] virtual auto start(std::string_view host, uint16_t port) -> VoidResult = 0;
86
98 [[nodiscard]] virtual auto stop() -> VoidResult = 0;
99
104 [[nodiscard]] virtual auto is_connected() const -> bool = 0;
105
110 [[nodiscard]] virtual auto is_handshake_complete() const -> bool = 0;
111
112 // =====================================================================
113 // Default Stream Operations
114 // =====================================================================
115
121 [[nodiscard]] virtual auto send(std::vector<uint8_t>&& data) -> VoidResult = 0;
122
123 // =====================================================================
124 // Multi-Stream Operations (QUIC Specific)
125 // =====================================================================
126
131 [[nodiscard]] virtual auto create_stream() -> Result<uint64_t> = 0;
132
137 [[nodiscard]] virtual auto create_unidirectional_stream() -> Result<uint64_t> = 0;
138
146 [[nodiscard]] virtual auto send_on_stream(
147 uint64_t stream_id,
148 std::vector<uint8_t>&& data,
149 bool fin = false) -> VoidResult = 0;
150
156 [[nodiscard]] virtual auto close_stream(uint64_t stream_id) -> VoidResult = 0;
157
158 // =====================================================================
159 // ALPN Configuration
160 // =====================================================================
161
166 virtual auto set_alpn_protocols(const std::vector<std::string>& protocols) -> void = 0;
167
172 [[nodiscard]] virtual auto alpn_protocol() const -> std::optional<std::string> = 0;
173
174 // =====================================================================
175 // 0-RTT Support
176 // =====================================================================
177
182 [[nodiscard]] virtual auto is_early_data_accepted() const -> bool = 0;
183
184 // =====================================================================
185 // Callbacks
186 // =====================================================================
187
192 virtual auto set_receive_callback(receive_callback_t callback) -> void = 0;
193
198 virtual auto set_stream_callback(stream_callback_t callback) -> void = 0;
199
204 virtual auto set_connected_callback(connected_callback_t callback) -> void = 0;
205
210 virtual auto set_disconnected_callback(disconnected_callback_t callback) -> void = 0;
211
216 virtual auto set_error_callback(error_callback_t callback) -> void = 0;
217
222 virtual auto set_session_ticket_callback(session_ticket_callback_t callback) -> void = 0;
223
228 virtual auto set_early_data_callback(early_data_callback_t callback) -> void = 0;
229
235 };
236
237} // namespace kcenon::network::interfaces
Base interface for all network components.
Interface for QUIC client components.
std::function< void(bool accepted)> early_data_accepted_callback_t
Callback type for early data acceptance notification.
virtual auto set_error_callback(error_callback_t callback) -> void=0
Sets the callback for errors.
virtual auto alpn_protocol() const -> std::optional< std::string >=0
Gets the negotiated ALPN protocol.
virtual auto create_stream() -> Result< uint64_t >=0
Creates a new bidirectional stream.
virtual auto set_session_ticket_callback(session_ticket_callback_t callback) -> void=0
Sets the callback for session tickets (for 0-RTT).
virtual auto send_on_stream(uint64_t stream_id, std::vector< uint8_t > &&data, bool fin=false) -> VoidResult=0
Sends data on a specific stream.
std::function< void()> connected_callback_t
Callback type for connection established.
virtual auto is_connected() const -> bool=0
Checks if the client is connected.
virtual auto set_early_data_callback(early_data_callback_t callback) -> void=0
Sets the callback for early data production.
std::function< std::vector< uint8_t >()> early_data_callback_t
Callback type for early data production.
virtual auto is_handshake_complete() const -> bool=0
Checks if TLS handshake is complete.
std::function< void()> disconnected_callback_t
Callback type for disconnection.
std::function< void(const std::vector< uint8_t > &)> receive_callback_t
Callback type for received data on default stream.
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)
virtual auto set_alpn_protocols(const std::vector< std::string > &protocols) -> void=0
Sets the ALPN protocols for negotiation.
virtual auto set_disconnected_callback(disconnected_callback_t callback) -> void=0
Sets the callback for disconnection.
std::function< void(uint64_t, const std::vector< uint8_t > &, bool)> stream_callback_t
Callback type for stream data (stream_id, data, is_fin)
virtual auto send(std::vector< uint8_t > &&data) -> VoidResult=0
Sends data on the default stream (stream 0).
virtual auto close_stream(uint64_t stream_id) -> VoidResult=0
Closes a stream.
virtual auto start(std::string_view host, uint16_t port) -> VoidResult=0
Starts the QUIC client connecting to the specified server.
virtual auto is_early_data_accepted() const -> bool=0
Checks if early data was accepted by the server.
virtual auto set_receive_callback(receive_callback_t callback) -> void=0
Sets the callback for received data on default stream.
virtual auto stop() -> VoidResult=0
Stops the QUIC client.
virtual auto set_connected_callback(connected_callback_t callback) -> void=0
Sets the callback for connection established.
virtual auto set_stream_callback(stream_callback_t callback) -> void=0
Sets the callback for stream data.
std::function< void(std::error_code)> error_callback_t
Callback type for errors.
virtual auto set_early_data_accepted_callback(early_data_accepted_callback_t callback) -> void=0
Sets the callback for early data acceptance notification.
virtual auto create_unidirectional_stream() -> Result< uint64_t >=0
Creates a new unidirectional stream.
Base interface for all network components.
Network-specific error and result type definitions.