CTaps 0.3.0
A C implementation of the Transport Services API (RFC 9621 - 9623)
Loading...
Searching...
No Matches
ctaps.h
Go to the documentation of this file.
1//
2// CTaps - C implementation Transport Services as described in RFC 9621 - 9623
3//
4
5#ifndef CTAPS_H
6#define CTAPS_H
7
8#include <netinet/in.h>
9#include <netinet/tcp.h>
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <sys/socket.h>
14
15// Symbol visibility control - only export public API functions
16#if defined(__GNUC__)
17#define CT_EXTERN __attribute__((visibility("default")))
18#else
19#define CT_EXTERN
20#endif
21
22#define CT_CONNECTION_DEFAULT_PRIORITY 100
23
24/**
25 * @ingroup connection
26 * @struct ct_connection_t
27 * @brief Opaque handle representing a connection.
28 *
29 * Received via callback when a preconnection has been initiated or
30 * a listener has received a new connection.
31 */
32typedef struct ct_connection_s ct_connection_t;
33
34/**
35 * @ingroup listener
36 * @struct ct_listener_t
37 * @brief Opaque handle representing a listener.
38 *
39 * Received via callback after ct_preconnection_listen()
40 */
41typedef struct ct_listener_s ct_listener_t;
42
43/**
44 * @ingroup listener
45 * @brief Check if a listener is closed.
46 * @param[in] listener Listener to check
47 * @return true if the listener is closed or NULL is passed, false otherwise
48 */
50
51/**
52 * @ingroup listener
53 * @brief Get the callback context associated with a listener.
54 * @param[in] listener Listener to get context from
55 * @return Pointer to callback context, or NULL if no context is set
56 */
58
59/**
60 * @ingroup listener
61 * @brief Close a listener and stop accepting new connections.
62 * @param[in] listener Listener to close
63 */
65
66/**
67 * @ingroup listener
68 * @brief Free resources in a listener.
69 * @param[in] listener Listener to free
70 */
72
73/**
74 * @ingroup library
75 * @brief Initialize the CTaps library
76 *
77 * This function must be called before any other CTaps functions. It initializes
78 * the event loop and sets default logging level
79 *
80 * @return 0 on success, negative error code on failure
81 *
82 * @note Must be called before ct_start_event_loop()
83 * @note This function initializes global state and is not thread-safe
84 *
85 * @see ct_start_event_loop() for starting the event loop after initialization
86 * @see ct_close() for cleanup and shutdown
87 */
89
90/**
91 * @ingroup library
92 * @brief Start the CTaps event loop (blocking operation).
93 *
94 * @return 0 on success, negative error code on failure
95 *
96 * @note Must be called after ct_initialize()
97 * @note All CTaps callbacks are invoked from within this event loop's thread context
98 * @note Returns when there are no more active and referenced handles
99 *
100 * @see ct_initialize() for library initialization
101 */
103
104/**
105 * @ingroup library
106 * @brief Close and cleanup the CTaps library.
107 *
108 * @return 0 on success, negative error code on failure
109 *
110 * @see ct_initialize() for re-initializing the library
111 */
113
114// =============================================================================
115// Logging Configuration
116// =============================================================================
117
118/**
119 * @ingroup logging
120 * @brief Log level enumeration for filtering log output.
121 *
122 * Log levels range from TRACE (most verbose) to ERROR (critical errors only).
123 * Setting a log level filters out all messages below that level.
124 */
125typedef enum {
126 CT_LOG_TRACE = 0, ///< Trace-level debugging (most verbose)
127 CT_LOG_DEBUG = 1, ///< Debug-level information
128 CT_LOG_INFO = 2, ///< Informational messages (default)
129 CT_LOG_WARN = 3, ///< Warning messages
130 CT_LOG_ERROR = 4, ///< Error messages
132
133/**
134 * @ingroup logging
135 * @brief Set the minimum logging level for CTaps.
136 *
137 * Only log messages at or above this level will be output. By default,
138 * CTaps logs at CT_LOG_INFO level and above.
139 *
140 * @param[in] level Minimum log level (CT_LOG_TRACE through CT_LOG_ERROR)
141 *
142 * @note This can be called before ct_initialize() or at any time during execution
143 * @note Lower numeric values are more verbose (TRACE=0, ERROR=4)
144 *
145 * @see ct_log_level_enum_t for available log levels
146 */
148
149/**
150 * @ingroup logging
151 * @brief Add a file output destination for CTaps logs.
152 *
153 * Logs will be written to the specified file in addition to stderr.
154 * Multiple files can be added, each with their own minimum log level.
155 *
156 * @param[in] file_path Path to the log file (will be created/appended)
157 * @param[in] min_level Minimum log level to write to this file
158 *
159 * @return 0 on success, negative error code on failure
160 *
161 * @note The file will be opened in append mode
162 * @note File handle remains open for the lifetime of the library
163 * @note This should be called after ct_initialize()
164 */
165CT_EXTERN int ct_add_log_file(const char* file_path, ct_log_level_enum_t min_level);
166
167// =============================================================================
168// Selection Properties - Transport property preferences for protocol selection
169// =============================================================================
170//
171
172/**
173 * @ingroup selection_properties
174 * @brief Preference levels for transport selection properties.
175 *
176 * These values express how strongly a particular transport property is desired,
177 * ranging from PROHIBIT (must not have) to REQUIRE (must have).
178 *
179 * If a candidate cannot fulfill a PROHIBIT or REQUIRE it is pruned completely.
180 *
181 * If a candidate cannot fulfill an AVOID or PREFER it is placed later in
182 * the order of possible candidates to race.
183 *
184 * @note A missing PREFER is placed later than any missing avoids. even if
185 * a candidate cannot fulfill 10 AVOIDs, it will be placed before a candidate
186 * which is missing only a single PREFER
187 */
188typedef enum {
189 PROHIBIT = -2, ///< Protocol MUST NOT have this property (eliminates candidates)
190 AVOID, ///< Prefer protocols without this property if possible
191 NO_PREFERENCE, ///< No preference - property does not affect selection
192 PREFER, ///< Prefer protocols with this property if available
193 REQUIRE, ///< Protocol MUST have this property (eliminates candidates)
195
196
197/**
198 * @ingroup selection_properties
199 * @brief Direction of communication for a connection.
200 */
201typedef enum {
202 CT_DIRECTION_BIDIRECTIONAL, ///< Two-way communication (send and receive)
203 CT_DIRECTION_UNIDIRECTIONAL_SEND, ///< One-way, send only
204 CT_DIRECTION_UNIDIRECTIONAL_RECV ///< One-way, receive only
206
207/**
208 * @ingroup selection_properties
209 * @brief Multipath transport modes.
210 */
211typedef enum {
212 CT_MULTIPATH_DISABLED, ///< Do not use multipath
213 CT_MULTIPATH_ACTIVE, ///< Actively use multiple paths simultaneously
214 CT_MULTIPATH_PASSIVE ///< Will accept multipath used by peer
216
217// Since it is a struct, wrap with {0}
218#define EMPTY_PREFERENCE_SET_DEFAULT {0}
219#define RUNTIME_DEPENDENT_DEFAULT 0
220
221// clang-format off
222#define get_selection_property_list(f) \
223f(RELIABILITY, "reliability", ct_selection_preference_enum_t, reliability, REQUIRE, TYPE_PREFERENCE) \
224f(PRESERVE_MSG_BOUNDARIES, "preserveMsgBoundaries", ct_selection_preference_enum_t, preserve_msg_boundaries, NO_PREFERENCE, TYPE_PREFERENCE ) \
225f(PER_MSG_RELIABILITY, "perMsgReliability", ct_selection_preference_enum_t, per_msg_reliability, NO_PREFERENCE, TYPE_PREFERENCE) \
226f(PRESERVE_ORDER, "preserveOrder", ct_selection_preference_enum_t, preserve_order, REQUIRE, TYPE_PREFERENCE) \
227f(ZERO_RTT_MSG, "zeroRttMsg", ct_selection_preference_enum_t, zero_rtt_msg, NO_PREFERENCE, TYPE_PREFERENCE) \
228f(MULTISTREAMING, "multistreaming", ct_selection_preference_enum_t, multistreaming, PREFER, TYPE_PREFERENCE) \
229f(FULL_CHECKSUM_SEND, "fullChecksumSend", ct_selection_preference_enum_t, full_checksum_send, REQUIRE, TYPE_PREFERENCE) \
230f(FULL_CHECKSUM_RECV, "fullChecksumRecv", ct_selection_preference_enum_t, full_checksum_recv, REQUIRE, TYPE_PREFERENCE) \
231f(CONGESTION_CONTROL, "congestionControl", ct_selection_preference_enum_t, congestion_control, REQUIRE, TYPE_PREFERENCE) \
232f(KEEP_ALIVE, "keepAlive", ct_selection_preference_enum_t, keep_alive, NO_PREFERENCE, TYPE_PREFERENCE) \
233f(USE_TEMPORARY_LOCAL_ADDRESS, "useTemporaryLocalAddress", ct_selection_preference_enum_t, use_temporary_local_address, RUNTIME_DEPENDENT_DEFAULT, TYPE_PREFERENCE) \
234f(MULTIPATH, "multipath", ct_multipath_enum_t, multipath, RUNTIME_DEPENDENT_DEFAULT, TYPE_ENUM) \
235f(ADVERTISES_ALT_ADDRESS, "advertisesAltAddr", ct_selection_preference_enum_t, advertises_alt_address, PROHIBIT, TYPE_PREFERENCE) \
236f(DIRECTION, "direction", ct_direction_of_communication_enum_t, direction, CT_DIRECTION_BIDIRECTIONAL, TYPE_ENUM) \
237f(SOFT_ERROR_NOTIFY, "softErrorNotify", ct_selection_preference_enum_t, soft_error_notify, NO_PREFERENCE, TYPE_PREFERENCE) \
238f(ACTIVE_READ_BEFORE_SEND, "activeReadBeforeSend", ct_selection_preference_enum_t, active_read_before_send, NO_PREFERENCE, TYPE_PREFERENCE)
239
240#define get_preference_set_selection_property_list(f) \
241 f(INTERFACE, "interface", ct_preference_set_t, interface, EMPTY_PREFERENCE_SET_DEFAULT, \
242 TYPE_PREFERENCE_SET) \
243 f(PVD, "pvd", ct_preference_set_t, pvd, EMPTY_PREFERENCE_SET_DEFAULT, TYPE_PREFERENCE_SET)
244
245#define output_enum(enum_name, string_name, property_type, token_name, default_value, type) \
246 enum_name,
247
248// clang-format on
249
250// =============================================================================
251// Connection Properties
252// =============================================================================
253
254/**
255 * @ingroup connection_properties
256 * @brief 0 Means no timeout in ms
257 */
258#define CT_CONN_TIMEOUT_DISABLED 0 ///< Matches picoquic's definition of no timeout
259/**
260 * @ingroup connection_properties
261 * @brief Special value: No rate limit
262 */
263#define CT_CONN_RATE_UNLIMITED UINT64_MAX ///< Special value: no rate limit
264/**
265 * @ingroup connection_properties
266 * @brief Special value: Full checksum
267 */
268#define CT_CONN_CHECKSUM_FULL_COVERAGE UINT32_MAX ///< Special value: checksum entire message
269/**
270 * @ingroup connection_properties
271 * @brief Special value: No max message length
272 */
273#define CT_CONN_MSG_MAX_LEN_NOT_APPLICABLE 0 ///< Special value: no maximum length
274
275/**
276 * @ingroup connection_properties
277 * @brief Connection lifecycle states.
278 */
279typedef enum {
280 CT_CONN_STATE_INVALID = -1, ///< Invalid state (used for error handling)
281 CT_CONN_STATE_ESTABLISHING, ///< Connection is being established
282 CT_CONN_STATE_ESTABLISHED, ///< Connection is ready for data transfer
283 CT_CONN_STATE_CLOSING, ///< Connection is closing gracefully
284 CT_CONN_STATE_CLOSED ///< Connection is fully closed
286
287/**
288 * @ingroup connection_properties
289 * @brief Connection scheduling algorithms for multipath.
290 */
291typedef enum {
292 CT_CONN_SCHEDULER_WEIGHTED_FAIR_QUEUEING = 0, ///< Weighted fair queueing across paths
294
295/**
296 * @ingroup connection_properties
297 * @brief QoS capacity profiles for traffic classification.
298 */
299typedef enum {
300 CT_CAPACITY_PROFILE_BEST_EFFORT = 0, ///< Default best-effort traffic
301 CT_CAPACITY_PROFILE_SCAVENGER, ///< Background/bulk traffic
302 CT_CAPACITY_PROFILE_LOW_LATENCY_INTERACTIVE, ///< Interactive low-latency (e.g., gaming, VoIP)
303 CT_CAPACITY_PROFILE_LOW_LATENCY_NON_INTERACTIVE, ///< Non-interactive low-latency (e.g., streaming)
304 CT_CAPACITY_PROFILE_CONSTANT_RATE_STREAMING, ///< Constant bitrate streaming
305 CT_CAPACITY_PROFILE_CAPACITY_SEEKING ///< Throughput-seeking traffic
307
308/**
309 * @ingroup connection_properties
310 * @brief Policies for multipath traffic distribution.
311 */
312typedef enum {
313 CT_MULTIPATH_POLICY_HANDOVER = 0, ///< Use paths sequentially (failover only)
314 CT_MULTIPATH_POLICY_INTERACTIVE, ///< Optimize for low latency
315 CT_MULTIPATH_POLICY_AGGREGATE ///< Use all paths for maximum throughput
317
318// clang-format off
319#define get_writable_connection_property_list(f) \
320f(RECV_CHECKSUM_LEN, "recvChecksumLen", uint32_t, recv_checksum_len, CT_CONN_CHECKSUM_FULL_COVERAGE, TYPE_UINT32) \
321f(CONN_PRIORITY, "connPriority", uint8_t, conn_priority, CT_CONNECTION_DEFAULT_PRIORITY, TYPE_UINT8) \
322f(CONN_TIMEOUT, "connTimeout", uint32_t, conn_timeout_ms, CT_CONN_TIMEOUT_DISABLED, TYPE_UINT32) \
323f(KEEP_ALIVE_TIMEOUT, "keepAliveTimeout", uint32_t, keep_alive_timeout, CT_CONN_TIMEOUT_DISABLED, TYPE_UINT32) \
324f(CONN_SCHEDULER, "connScheduler", ct_connection_scheduler_enum_t, conn_scheduler, CT_CONN_SCHEDULER_WEIGHTED_FAIR_QUEUEING, TYPE_ENUM) \
325f(CONN_CAPACITY_PROFILE, "connCapacityProfile", ct_capacity_profile_enum_t, conn_capacity_profile, CT_CAPACITY_PROFILE_BEST_EFFORT, TYPE_ENUM) \
326f(MULTIPATH_POLICY, "multipathPolicy", ct_multipath_policy_enum_t, multipath_policy, CT_MULTIPATH_POLICY_HANDOVER, TYPE_ENUM) \
327f(MIN_SEND_RATE, "minSendRate", uint64_t, min_send_rate, CT_CONN_RATE_UNLIMITED, TYPE_UINT64) \
328f(MIN_RECV_RATE, "minRecvRate", uint64_t, min_recv_rate, CT_CONN_RATE_UNLIMITED, TYPE_UINT64) \
329f(MAX_SEND_RATE, "maxSendRate", uint64_t, max_send_rate, CT_CONN_RATE_UNLIMITED, TYPE_UINT64) \
330f(MAX_RECV_RATE, "maxRecvRate", uint64_t, max_recv_rate, CT_CONN_RATE_UNLIMITED, TYPE_UINT64) \
331f(GROUP_CONN_LIMIT, "groupConnLimit", uint64_t, group_conn_limit, CT_CONN_RATE_UNLIMITED, TYPE_UINT64) \
332f(ISOLATE_SESSION, "isolateSession", bool, isolate_session, false, TYPE_BOOL)
333
334#define get_read_only_connection_properties(f) \
335f(SINGULAR_TRANSMISSION_MSG_MAX_LEN, "singularTransmissionMsgMaxLen", uint64_t, singular_transmission_msg_max_len, 0, TYPE_UINT64) \
336f(SEND_MESSAGE_MAX_LEN, "sendMsgMaxLen", uint64_t, send_message_max_len, 0, TYPE_UINT64) \
337f(RECV_MESSAGE_MAX_LEN, "recvMessageMaxLen", uint64_t, recv_message_max_len, 0, TYPE_UINT64)
338
339#define get_tcp_connection_properties(f) \
340f(USER_TIMEOUT_VALUE_MS, "userTimeoutValueMs", uint32_t, user_timeout_value_ms, TCP_USER_TIMEOUT, TYPE_UINT32) \
341f(USER_TIMEOUT_ENABLED, "userTimeoutEnabled", bool, user_timeout_enabled, false, TYPE_BOOL) \
342f(USER_TIMEOUT_CHANGEABLE, "userTimeoutChangeable", bool, user_timeout_changeable, true, TYPE_BOOL)
343
344// =============================================================================
345// Transport Properties - Combination of selection and connection properties
346// =============================================================================
347
348/**
349 * @ingroup transport_properties
350 * @struct ct_transport_properties_t
351 * @brief Opaque handle representing transport properties used for
352 * selecting and configuring protocols.
353 *
354 * Allocate a new instance using ct_transport_properties_new().
355 * Use setter functions to configure properties, then pass to
356 * ct_preconnection_new() or similar.
357 */
358typedef struct ct_transport_properties_s ct_transport_properties_t;
359
360#define output_transport_property_getter_declaration(enum_name, string_name, property_type, \
361 token_name, default_value, type_enum) \
362 CT_EXTERN property_type ct_transport_properties_get_##token_name( \
363 const ct_transport_properties_t* transport_props);
364
365#define output_transport_property_preference_getter_declaration( \
366 enum_name, string_name, property_type, token_name, default_value, type) \
367 CT_EXTERN ct_selection_preference_enum_t ct_transport_properties_get_##token_name##_preference( \
368 const ct_transport_properties_t* transport_props, const char* value);
369
370#define output_transport_property_setter_declaration(enum_name, string_name, property_type, \
371 token_name, default_value, type_enum) \
372 CT_EXTERN void ct_transport_properties_set_##token_name( \
373 ct_transport_properties_t* transport_props, property_type val);
374
375#define output_transport_property_preference_set_adder(enum_name, string_name, property_type, \
376 token_name, default_value, type) \
377 CT_EXTERN int ct_transport_properties_add_##token_name##_preference( \
378 ct_transport_properties_t* transport_props, const char* value, \
379 ct_selection_preference_enum_t preference);
380
381/** @addtogroup selection_properties
382 * @{
383 */
386
391/** @} */
392
393
394
395/** @addtogroup connection_properties
396 * @{
397 */
401
405
408/** @} */
409
410// clang-format on
411
412// =============================================================================
413// Message properties
414// =============================================================================
415
416/**
417 * @ingroup message_properties
418 * @struct ct_message_properties_t
419 * @brief Collection of message properties for per-message transmission control.
420 *
421 * ## Message Properties Ownership Model
422 *
423 * ### Lifecycle
424 * - Create with ct_message_properties_new()
425 * - Embed in a message context with ct_message_context_new()
426 * - This takes a deep copy internally
427 * - Free your copy with ct_message_properties_free() when done
428 * - CTaps-owned copies are freed automatically
429 */
430typedef struct ct_message_properties_s ct_message_properties_t;
431
432/**
433 * @ingroup message_properties
434 * @brief Special value: Full checksum coverage for individual message.
435 */
436#define CT_MESSAGE_CHECKSUM_FULL_COVERAGE UINT32_MAX
437
438// clang-format off
439#define get_message_property_list(f) \
440f(MSG_LIFETIME, "msgLifetime", uint64_t, lifetime, 0, TYPE_UINT64) \
441f(MSG_PRIORITY, "msgPriority", uint32_t, priority, 100, TYPE_UINT32) \
442f(MSG_ORDERED, "msgOrdered", bool, ordered, true, TYPE_BOOL) \
443f(MSG_SAFELY_REPLAYABLE, "msgSafelyReplayable", bool, safely_replayable, false, TYPE_BOOL) \
444f(FINAL, "final", bool, final, false, TYPE_BOOL) \
445f(MSG_CHECKSUM_LEN, "msgChecksumLen", uint32_t, checksum_len, CT_MESSAGE_CHECKSUM_FULL_COVERAGE, TYPE_UINT32) \
446f(MSG_RELIABLE, "msgReliable", bool, reliable, true, TYPE_BOOL) \
447f(MSG_CAPACITY_PROFILE, "msgCapacityProfile", ct_capacity_profile_enum_t, capacity_profile, CT_CAPACITY_PROFILE_BEST_EFFORT, TYPE_ENUM) \
448f(NO_FRAGMENTATION, "noFragmentation", bool, no_fragmentation, false, TYPE_BOOL) \
449f(NO_SEGMENTATION, "noSegmentation", bool, no_segmentation, false, TYPE_BOOL)
450
451#define output_message_property_getter_declaration(enum_name, string_name, property_type, \
452 token_name, default_value, type_enum) \
453 CT_EXTERN property_type ct_message_properties_get_##token_name( \
454 const ct_message_properties_t* msg_props);
455
456#define output_message_property_setter_declaration(enum_name, string_name, property_type, \
457 token_name, default_value, type_enum) \
458 CT_EXTERN void ct_message_properties_set_##token_name(ct_message_properties_t* msg_props, \
459 property_type val);
460
463
464// clang-format on
465
466/**
467 * @ingroup message_properties
468 * @brief Create a new message properties object with default values.
469 *
470 * Allocates and initializes a new message properties object on the heap.
471 * The returned object must be freed with ct_message_properties_free().
472 *
473 * @return Pointer to newly allocated message properties, or NULL on allocation failure.
474 */
476
477/**
478 * @ingroup message_properties
479 * @brief Free resources in message properties.
480 * @param[in] message_properties structure to free
481 */
483
484// =============================================================================
485// Security Parameters
486// =============================================================================
487
488/**
489 * @ingroup security_parameters
490 * @struct ct_security_parameters_t
491 * @brief Opaque handle representing a security parameters used to configure security settings for connections and listeners.
492 *
493 * ## Security Parameters Ownership Model
494 *
495 * ### Passing to Preconnections and Connections
496 * When you pass security parameters to ct_preconnection_new() or similar functions:
497 * - **You retain ownership** of your original security_parameters
498 * - CTaps makes a **deep copy** internally
499 * - **You can free your security_parameters** after the function returns
500 * - Multiple preconnections can share the same source security_parameters safely
501 *
502 * ### Lifecycle
503 * - Create with ct_security_parameters_new()
504 * - Pass to preconnection/connection functions
505 * - This makes a deep copy internally
506 * - Free your copy with ct_security_parameters_free() when done
507 * - CTaps-owned copies are freed automatically
508 */
509typedef struct ct_security_parameters_s ct_security_parameters_t;
510
511/**
512 * @ingroup security_parameters
513 * @brief Set the path to the ticket store for QUIC session resumption.
514 *
515 * Optional parameter, but needed if you want client session resumption.
516 *
517 * Frees any existing ticket store path
518 *
519 * Takes a deep copy of the provided string.
520 *
521 * @param[in] sec Pointer to security parameters object to configure
522 * @param[in] ticket_store_path Filesystem path to the ticket store (e.g., "quic_tickets.dat")
523 * @return 0 on success, negative error code on failure
524 */
526 const char* ticket_store_path);
527
528/**
529 * @ingroup security_parameters
530 * @brief Set the server name identification (SNI) for TLS connections.
531 *
532 * Frees any existing server name identification value.
533 *
534 * @param[in] sec Pointer to security parameters object to configure
535 * @param[in] sni Server name for TLS SNI extension (e.g., "example.com")
536 * @return 0 on success, negative error code on failure
537 */
539 const char* sni);
540
541/**
542 * @ingroup security_parameters
543 * @brief Add a server certificate and private key for TLS connections.
544 * @param[in] sec Pointer to security parameters object to configure
545 * @param[in] cert_file Filesystem path to the certificate file (PEM format)
546 * @param[in] key_file Filesystem path to the private key file (PEM format), or NULL if not applicable
547 * @return 0 on success, negative error code on failure
548 */
550 const char* cert_file,
551 const char* key_file);
552
553/**
554 * @ingroup security_parameters
555 * @brief Add a client certificate and private key for TLS connections.
556 * @param[in] sec Pointer to security parameters object to configure
557 * @param[in] cert_file Filesystem path to the certificate file (PEM format)
558 * @param[in] key_file Filesystem path to the private key file (PEM format), or NULL if not applicable
559 * @return 0 on success, negative error code on failure
560 */
562 const char* cert_file,
563 const char* key_file);
564/**
565 * @ingroup security_parameters
566 * @brief Add an ALPN protocol identifier to the list of supported ALPNs for TLS connections.
567 * @param[in] sec Pointer to security parameters object to configure
568 * @param[in] alpn ALPN protocol identifier string (e.g., "h3-29")
569 * @return 0 on success, negative error code on failure
570 */
572/**
573 * @ingroup security_parameters
574 * @brief Free and clear all configured ALPN protocol identifiers from the security parameters.
575 * @param[in] sec Pointer to security parameters object to configure
576 * @return 0 on success, negative error code on failure
577 */
579
580/**
581 * @ingroup security_parameters
582 * @brief Set the session ticket encryption key for QUIC session resumption.
583 *
584 * This is an optional parameter, but needed if you want server session resumption.
585 *
586 * Frees any existing session ticket encryption key.
587 *
588 * Takes a deep copy of the provided key data.
589 *
590 * @param[in] sec Pointer to security parameters object to configure
591 * @param[in] key Binary key data for encrypting session tickets
592 * @param[in] key_len Length of the key data in bytes
593 * @return 0 on success, negative error code on failure
594 */
595CT_EXTERN int
597 const uint8_t* key,
598 size_t key_len);
599
600/**
601 * @ingroup security_parameters
602 * @brief Allocate a new security parameters object on the heap.
603 * @return Pointer to newly allocated security parameters, or NULL on failure
604 */
606
607/**
608 * @ingroup security_parameters
609 * @brief Free resources in security parameters including the structure itself.
610 * @param[in] security_parameters structure to free
611 */
613
614
615/** @addtogroup security_parameters
616 * @{
617 */
618CT_EXTERN const char*
620CT_EXTERN const char*
622
623CT_EXTERN size_t
625CT_EXTERN const char*
627 size_t index);
628CT_EXTERN const char*
630 size_t index);
631
632CT_EXTERN size_t
634CT_EXTERN const char*
636 size_t index);
637CT_EXTERN const char*
639 size_t index);
640
641/**
642 * @ingroup security_parameters
643 * @brief Get the configured ALPN protocol identifiers.
644 * @param[in] sec Security parameters to query
645 * @param[out] num_alpns Set to the number of ALPN strings in the returned array
646 * @return Pointer to array of ALPN strings, or NULL if none are set
647 */
649 size_t* num_alpns);
650/**
651 * @ingroup security_parameters
652 * @brief Get the session ticket encryption key.
653 * @param[in] sec Security parameters to query
654 * @param[out] key_len Set to the length of the returned key in bytes
655 * @return Pointer to key data, or NULL if no key is set
656 */
657CT_EXTERN const uint8_t*
659 size_t* key_len);
660/** @} */
661
662/**
663 * @ingroup transport_properties
664 * @brief Create a new transport properties object with default values.
665 * @note The returned object must be freed with ct_transport_properties_free().
666 *
667 * @return Pointer to newly allocated transport properties, or NULL on allocation failure.
668 */
670
671/**
672 * @ingroup transport_properties
673 * @brief Free a transport properties object.
674 *
675 * @param[in] props Pointer to transport properties to free. Does nothing if NULL.
676 */
678
679// =============================================================================
680// Endpoints - Opaque types for local and remote endpoints
681// =============================================================================
682
683/**
684 * @ingroup local_endpoints
685 * @struct ct_local_endpoint_t
686 * @brief Opaque handle representing a local endpoint (generic or resolved to specific ip address and port).
687 *
688 * Use ct_local_endpoint_new() to create and ct_local_endpoint_with_*() to configure.
689 */
690typedef struct ct_local_endpoint_s ct_local_endpoint_t;
691
692/**
693 * @ingroup remote_endpoints
694 * @struct ct_remote_endpoint_t
695 * @brief Opaque handle representing a remote endpoint (generic or resolved to specific ip address and port).
696 *
697 * Use ct_remote_endpoint_new() to create and ct_remote_endpoint_with_*() to configure.
698 */
699typedef struct ct_remote_endpoint_s ct_remote_endpoint_t;
700
701/**
702 * @ingroup local_endpoints
703 * @brief Create a new heap-allocated local endpoint.
704 *
705 * The caller owns the returned endpoint and must free it with ct_local_endpoint_free()
706 * when done.
707 *
708 * @return Pointer to newly allocated endpoint, or NULL on error
709 */
711
712/**
713 * @ingroup local_endpoints
714 * @brief Set the network interface for a local endpoint.
715 * @param[in,out] local_endpoint Endpoint to modify
716 * @param[in] interface_name Interface name (e.g., "eth0", "wlan0")
717 * @return 0 on success, negative error code on failure
718 */
720 const char* interface_name);
721
722/**
723 * @ingroup local_endpoints
724 * @brief Set the port number for a local endpoint.
725 * @param[in,out] local_endpoint Endpoint to modify
726 * @param[in] port Port number
727 */
728CT_EXTERN void ct_local_endpoint_with_port(ct_local_endpoint_t* local_endpoint, uint16_t port);
729
730/**
731 * @ingroup local_endpoints
732 * @brief Set the service name for a local endpoint.
733 *
734 * Takes a deep copy of the provided string.
735 *
736 * @param[in,out] local_endpoint Endpoint to modify
737 * @param[in] service Service name (e.g., "http", "https")
738 * @return 0 on success, negative error code on failure
739 */
740CT_EXTERN int ct_local_endpoint_with_service(ct_local_endpoint_t* local_endpoint, const char* service);
741
742/**
743 * @ingroup local_endpoints
744 * @brief Set the IPv4 address for a local endpoint.
745 * @param[in,out] local_endpoint Endpoint to modify
746 * @param[in] ipv4_addr IPv4 address in network byte order
747 * @return 0 on success, negative error code on failure
748 */
749CT_EXTERN int ct_local_endpoint_with_ipv4(ct_local_endpoint_t* local_endpoint, in_addr_t ipv4_addr);
750
751/**
752 * @ingroup local_endpoints
753 * @brief Set the IPv6 address for a local endpoint.
754 * @param[in,out] local_endpoint Endpoint to modify
755 * @param[in] ipv6_addr IPv6 address in network byte order
756 * @return 0 on success, negative error code on failure
757 */
759 struct in6_addr ipv6_addr);
760
761/**
762 * @ingroup local_endpoints
763 * @brief Initialize a local endpoint from a sockaddr structure.
764 *
765 * CTaps does not take ownership of the passed addr pointer,
766 * so it can be safely freed after return.
767 *
768 * @param[out] local_endpoint Endpoint to initialize
769 * @param[in] addr Socket address structure
770 * @return 0 on success, negative error code on failure
771 */
773 const struct sockaddr_storage* addr);
774/**
775 * @ingroup local_endpoints
776 * @brief Free all resources in a local endpoint including the structure itself.
777 * @param[in] local_endpoint Endpoint to free
778 */
780
781/**
782 * @ingroup local_endpoints
783 * @brief Create a heap-allocated copy of a local endpoint.
784 * @param[in] local_endpoint Source endpoint
785 * @return Pointer to newly allocated copy, or NULL on error
786 */
788
789/**
790 * @ingroup local_endpoints
791 * @brief Get the service for a local endpoint
792 * @param[in] local_endpoint endpoint to get service for
793 *
794 * @return char* pointer to service name, NULL if endpoint is null, or if service is not set
795 */
797
798/**
799 * @ingroup local_endpoints
800 * @brief Get the resolved port for a local endpoint after binding.
801 *
802 * @return Port number assigned to the local endpoint in host order
803 */
805
806
807/**
808 * @ingroup remote_endpoints
809 * @brief Create a new heap-allocated remote endpoint.
810 *
811 * The caller owns the returned endpoint and must free it with ct_remote_endpoint_free()
812 * when done.
813 *
814 * @return Pointer to newly allocated endpoint, or NULL on error
815 */
817
818/**
819 * @ingroup remote_endpoints
820 * @brief Set the hostname for a remote endpoint.
821 * @param[in,out] remote_endpoint Endpoint to modify
822 * @param[in] hostname Hostname or IP address string
823 * @return 0 on success, negative error code on failure
824 */
826 const char* hostname);
827
828/**
829 * @ingroup remote_endpoints
830 * @brief Set the port number for a remote endpoint.
831 * @param[in,out] remote_endpoint Endpoint to modify
832 * @param[in] port Port number
833 */
834CT_EXTERN void ct_remote_endpoint_with_port(ct_remote_endpoint_t* remote_endpoint, uint16_t port);
835
836/**
837 * @ingroup remote_endpoints
838 * @brief Set the service name for a remote endpoint.
839 * @param[in,out] remote_endpoint Endpoint to modify
840 * @param[in] service Service name (e.g., "http", "https")
841 * @return 0 on success, negative error code on failure
842 */
844 const char* service);
845
846/**
847 * @ingroup remote_endpoints
848 * @brief Free all resources in a remote endpoint including the structure itself.
849 * @param[in] remote_endpoint Endpoint to free
850 */
852
853/**
854 * @ingroup remote_endpoints
855 * @brief Initialize a remote endpoint from a sockaddr structure.
856 * @param[out] remote_endpoint Endpoint to initialize
857 * @param[in] addr Socket address structure
858 * @return 0 on success, negative error code on failure
859 */
861 const struct sockaddr_storage* addr);
862
863/**
864 * @ingroup remote_endpoints
865 * @brief Create a heap-allocated copy of a remote endpoint.
866 * @param[in] remote_endpoint Source endpoint
867 * @return Pointer to newly allocated copy, or NULL on error
868 */
870
871/**
872 * @ingroup remote_endpoints
873 * @brief Set the IPv4 address for a remote endpoint.
874 * @param[in,out] remote_endpoint Endpoint to modify
875 * @param[in] ipv4_addr IPv4 address in network byte order
876 * @return 0 on success, negative error code on failure
877 */
879 in_addr_t ipv4_addr);
880
881/**
882 * @ingroup remote_endpoints
883 * @brief Set the IPv6 address for a remote endpoint.
884 * @param[in,out] remote_endpoint Endpoint to modify
885 * @param[in] ipv6_addr IPv6 address structure
886 * @return 0 on success, negative error code on failure
887 */
889 struct in6_addr ipv6_addr);
890
891/**
892 * @ingroup remote_endpoints
893 * @brief Get the service for a remote endpoint
894 * @param[in] remote_endpoint endpoint to get service for
895 *
896 * @return char* pointer to service name, NULL if endpoint is null, or if service is not set
897 */
899
900// =============================================================================
901// Messages - Message and message context structures
902// =============================================================================
903
904/**
905 * @ingroup message
906 * @struct ct_message_t
907 * @brief Opaque handle representing a single message to be sent or received.
908 *
909 * Use ct_message_new()/ct_message_new_with_content() to create, and ct_message_free() to free.
910 *
911 * ## Message Ownership Model
912 *
913 * ### Sending Messages
914 * When you send a message using ct_send_message() or ct_send_message_full():
915 * - **You retain ownership** of your original message
916 * - CTaps makes a **deep copy** internally for transmission
917 * - **You can free your message immediately** after the send function returns
918 * - CTaps manages the lifecycle of its internal copy
919 *
920 * ### Receiving Messages
921 *
922 * When you receive a message in a receive callback:
923 * - The message is only valid during the callback execution,
924 * you must take a deep copy if you need to use it after the callback returns
925 *
926 * ### Example
927 * @code{.c}
928 * ct_message_t* msg = ct_message_new_with_content("Hello", 5);
929 * ct_send_message(connection, msg);
930 * ct_message_free(msg); // Safe to free immediately after send
931 * @endcode
932 */
933typedef struct ct_message_s ct_message_t;
934
935/**
936 * @ingroup message
937 * @brief Free all resources in a message including the structure.
938 * @param[in] message Message to free
939 */
941
942/**
943 * @ingroup message
944 *
945 * @note The caller maintains ownership even after passing to send functions,
946 * CTaps makes deep copies internally.
947 *
948 * @brief Allocate a new message on the heap.
949 * @return Pointer to newly allocated message, or NULL on failure
950 */
952
953/**
954 * @ingroup message
955 * @brief Allocate a new message with content.
956 * @param[in] content Data buffer for the message
957 * @param[in] length Length of data in bytes
958 * @return Pointer to newly allocated message with content, or NULL on failure
959 */
960CT_EXTERN ct_message_t* ct_message_new_with_content(const char* content, size_t length);
961
962/**
963 * @ingroup message
964 * @brief Get the length of a message.
965 * @param[in] message Message to query
966 * @return Length of message in bytes, or 0 if message is NULL
967 */
969
970
971/**
972 * @ingroup message
973 * @brief Create a deep copy of a message, including its content.
974 * @param[in] message Message to copy
975 * @return Pointer to newly allocated copy of the message, or NULL on failure
976 */
978
979/**
980 * @ingroup message
981 * @brief Get the content buffer of a message.
982 * @param[in] message Message to query
983 * @return Pointer to message content, or NULL if message is NULL
984 */
986
987/**
988 * @ingroup message
989 * @brief Set the content of a message, replacing any existing content.
990 * @param[in,out] message Message to modify
991 * @param[in] content New data buffer for the message
992 * @param[in] length Length of new data in bytes
993 */
994CT_EXTERN void ct_message_set_content(ct_message_t* message, const void* content, size_t length);
995
996/**
997 * @ingroup message
998 * @struct ct_message_context_t
999 * @brief Opaque handle representing message metadata to pass to sending protocol.
1000 *
1001 * ## Message Context Ownership Model
1002 *
1003 * ### Passing to Sending Functions
1004 * When you pass a message context to ct_send_message_full() or similar functions:
1005 * - **You retain ownership** of your original message_context
1006 * - CTaps makes a **deep copy** internally if it needs to store the context
1007 * - **You can free your message_context** after the function returns
1008 *
1009 * ### Receiving in Callbacks
1010 * When a message context is passed to your receive callback:
1011 * - The message context is only valid during the callback execution,
1012 * you must take a deep copy if you need to use it after the callback returns
1013 *
1014 *
1015 * @code{.c}
1016 * ct_message_t* msg = ct_message_new_with_content("Hello", 5);
1017 * ct_message_context_t* msg_ctx = ct_message_context_new();
1018 * ct_send_message_full(connection, msg, msg_ctx);
1019 * ct_message_free(msg);
1020 * ct_message_context_free(msg_ctx); // Safe to free immediately after send
1021 * @endcode
1022 *
1023 */
1024typedef struct ct_message_context_s ct_message_context_t;
1025
1026/**
1027 * @ingroup message_context
1028 * @brief Initialize a message context with default values.
1029 * @return Heap allocated empty message context
1030 */
1032
1033/**
1034 * @ingroup message_context
1035 * @brief Free resources in a message context.
1036 * @param[in] message_context Context to free
1037 */
1039
1040/**
1041 * @ingroup message_context
1042 * @brief Get message properties from a message context.
1043 *
1044 * Returns a pointer to the message properties contained in the message context.
1045 * The returned pointer is owned by the message context and should not be freed.
1046 *
1047 * @param[in] message_context Context to get properties from
1048 * @return Pointer to message properties, or NULL if message_context is NULL
1049 */
1052
1053/**
1054 * @ingroup message_context
1055 * @brief Get the remote endpoint from a message context.
1056 *
1057 * @param[in] message_context Context to get remote endpoint from
1058 * @return Pointer to remote endpoint, or NULL if message_context is NULL or remote endpoint not set
1059 */
1062
1063/**
1064 * @ingroup message_context
1065 * @brief Get the local endpoint from a message context.
1066 *
1067 * @param[in] message_context Context to get local endpoint from
1068 * @return Pointer to local endpoint, or NULL if message_context is NULL or local endpoint not set
1069 */
1072
1073/**
1074 * @ingroup message_context
1075 * @brief Get the receive context from a message context.
1076 *
1077 * The receive context is a user-provided pointer that can be set in the ct_receive_callbacks_t structure.
1078 * It is intended to allow users to associate custom data with a specific receive callback invocation.
1079 *
1080 * @see ct_receive_callbacks_t::per_receive_context
1081 *
1082 * @param[in] message_context Context to get receive context from
1083 * @return User-provided receive context pointer, or NULL if message_context is NULL or no receive context set
1084 */
1086
1087
1088#define output_message_context_getter_declaration(enum_name, string_name, property_type, \
1089 token_name, default_value, type_enum) \
1090 CT_EXTERN property_type ct_message_context_get_##token_name( \
1091 const ct_message_context_t* msg_ctx);
1092
1093#define output_message_context_setter_declaration(enum_name, string_name, property_type, \
1094 token_name, default_value, type_enum) \
1095 CT_EXTERN void ct_message_context_set_##token_name(ct_message_context_t* msg_ctx, \
1096 property_type val);
1097
1100
1101// =============================================================================
1102// Callbacks - Connection and Listener callback structures
1103// =============================================================================
1104
1105/**
1106 * @ingroup connection
1107 * @brief Callback functions for receiving messages on a connection.
1108 *
1109 * Set these callbacks via ct_receive_message() to handle incoming data.
1110 */
1111typedef struct ct_receive_callbacks_s {
1112 /** @brief Called when a complete message is received.
1113 * @param[in] connection The connection that received the message
1114 * @param[in] received_message Pointer to received message. Only valid during callback execution - copy if needed after return.
1115 * @param[in] ctx Message context with properties and endpoints
1116 */
1117 void (*receive_callback)(ct_connection_t* connection, ct_message_t* received_message,
1119
1120 /** @brief Called when a receive error occurs.
1121 * @param[in] connection The connection that experienced the error
1122 * @param[in] ctx Message context
1123 * @param[in] reason Error description string
1124 */
1125 void (*receive_error)(ct_connection_t* connection, ct_message_context_t* ctx,
1126 const char* reason);
1127
1128 /**
1129 * @brief Per-receive user context accessible when this specific callback is invoked.
1130 * Can be fetched within ct_message_context_get_receive_context(ctx)
1131 *
1132 * @code{.c}
1133 *
1134 * void check_specific_callback_was_invoked(ct_connection_t* connection,
1135 * ct_message_t* received_message,
1136 * ct_message_context_t* message_context) {
1137 * my_custom_struct* recv_ctx = ct_message_context_get_receive_context(message_context);
1138 * recv_ctx->was_invoked = true;
1139 * }
1140 * @endcode
1141 */
1144
1145/**
1146 * @ingroup connection
1147 * @brief Callback functions for connection lifecycle events.
1148 *
1149 * Set these callbacks via ct_preconnection_initiate() or ct_preconnection_listen().
1150 * All callbacks are invoked from the event loop thread.
1151 */
1152typedef struct ct_connection_callbacks_s {
1153 /** @brief Called when a connection error occurs after establishment. */
1154 void (*connection_error)(ct_connection_t* connection);
1155
1156 /** @brief Called when connection establishment fails. */
1157 void (*establishment_error)(ct_connection_t* connection);
1158
1159 /** @brief Called when a connection expires (e.g., timeout). */
1160 void (*expired)(ct_connection_t* connection);
1161
1162 /** @brief Called when the connection's network path changes, local or remote. */
1163 void (*path_change)(ct_connection_t* connection);
1164
1165 /** @brief Called when connection is established and ready for data transfer. */
1166 void (*ready)(ct_connection_t* connection);
1167
1168 /** @brief Called when connection is closed and can be safely freed. */
1169 void (*closed)(ct_connection_t* connection);
1170
1171 /** @brief Called when a message send operation fails. */
1172 void (*send_error)(ct_connection_t* connection, ct_message_context_t* message_context,
1173 int reason_code);
1174
1175 /** @brief Called when a message is passed to the transport protocol. */
1176 void (*sent)(ct_connection_t* connection, ct_message_context_t* message_context);
1177
1178 /** @brief Called when a non-fatal error occurs (e.g., congestion). */
1179 void (*soft_error)(ct_connection_t* connection);
1180
1181 /**
1182 * Per connection context accessible whenever a given connection is
1183 * passed to a callback.
1184 *
1185 * Can be fetched with ct_connection_get_callback_context(connection)
1186 *
1187 * @code{.c}
1188 * void count_number_of_received_messages(ct_connection_t* connection,
1189 * ct_message_t* received_message,
1190 * ct_message_context_t* message_context) {
1191 * my_custom_struct* recv_ctx = ct_connection_get_callback_context(connection);
1192 * recv_ctx->num_received_messages++;
1193 * }
1194 * @endcode
1195 */
1196 void* per_connection_context; ///< User-provided context for the connection lifetime
1198
1199/**
1200 * @ingroup listener
1201 * @brief Callback functions for listener events.
1202 *
1203 * Set these callbacks via ct_preconnection_listen().
1204 */
1205typedef struct ct_listener_callbacks_s {
1206
1207 /***
1208 * @brief Called when the listener starts listening and is ready to accept connections.
1209 *
1210 * Listener creation is currently synchronous, so this callback is invoked immediately
1211 * within ct_preconnection_listen()
1212 */
1213 void (*listener_ready)(ct_listener_t* listener);
1214
1215 /** @brief Called when a new connection is received. */
1216 void (*connection_received)(ct_listener_t* listener, ct_connection_t* new_conn);
1217
1218 /**
1219 * @brief Called when connection establishment fails for an incoming connection.
1220 * @param[in] listener The listener which failed, or NULL if a listener could not be created
1221 * @param[in] reason Error code
1222 */
1223 void (*establishment_error)(ct_listener_t* listener, int error_code);
1224
1225 /** @brief Called when the listener has been closed and will accept no more connections. */
1226 void (*listener_closed)(ct_listener_t* listener);
1227
1228
1229 /**
1230 * Per listener context accessible whenever a given listener is
1231 * passed to a callback.
1232 *
1233 * Can be fetched with ct_listener_get_callback_context(listener)
1234 *
1235 * @code{.c}
1236 *
1237 * void count_num_received_connections(ct_listener_t* listener,
1238 * ct_connection_t* new_connection) {
1239 * my_custom_struct* recv_ctx = ct_listener_get_callback_context(listener);
1240 * recv_ctx->num_received_messages++;
1241 * }
1242 * @endcode
1243 */
1246
1247// =============================================================================
1248// Message Framer - Optional message framing/parsing layer
1249// =============================================================================
1250
1251/**
1252 * @ingroup framer
1253 * @brief Callback invoked by framer when message encoding is complete.
1254 *
1255 * @param[in] connection The connection
1256 * @param[in] encoded_message The encoded message ready for transmission
1257 * @param[in] context Message context
1258 * @return 0 on success, negative error code on failure
1259 */
1261 ct_message_t* encoded_message,
1262 ct_message_context_t* context);
1263
1264/**
1265 * @ingroup framer
1266 * @brief Callback invoked by framer when message decoding is complete.
1267 *
1268 * @param[in] connection The connection
1269 * @param[in] decoded_message The decoded message
1270 * @param[in] context Message context
1271 */
1273 ct_message_t* decoded_message,
1274 ct_message_context_t* context);
1275
1276/**
1277 * @ingroup framer
1278 * @struct ct_framer_impl_t
1279 * @brief Opaque handle representing a framer layer, wrapping or unwrapping sent/received
1280 * messages.
1281 *
1282 * Currently only one framer is supported per Connection.
1283 */
1284typedef struct ct_framer_impl_s {
1285 /**
1286 * @brief Encode an outbound message before transmission.
1287 *
1288 * Implementation should call the provided callback when encoding is complete.
1289 *
1290 * @param[in] connection The connection
1291 * @param[in] message The message to encode
1292 * @param[in] context Message context
1293 * @param[in] callback Callback to invoke when encoding is complete
1294 * @return 0 on success, negative error code on failure
1295 */
1296 int (*encode_message)(ct_connection_t* connection, ct_message_t* message,
1298
1299 /**
1300 * @brief Decode inbound data into application messages.
1301 *
1302 * @param[in] connection The connection
1303 * @param[in] message received from transport layer
1304 * @param[in] context Message context containing endpoint info
1305 * @param[in] callback Callback to invoke when decoding is complete
1306 */
1307 void (*decode_data)(ct_connection_t* connection, ct_message_t* message,
1310
1311
1312/**
1313 * @ingroup preconnection
1314 * @struct ct_preconnection_t
1315 * @brief Opaque handle representing a preconnection.
1316 *
1317 * Created before initiating a connection or listener, this object holds all configuration
1318 * (endpoints, properties, security) needed to initiate a connection or start a listener.
1319 *
1320 * Created via ct_preconnection_new().
1321 */
1322typedef struct ct_preconnection_s ct_preconnection_t;
1323
1324/**
1325 * @ingroup preconnection
1326 * @brief Create a new preconnection with transport properties and endpoints.
1327 *
1328 * Allocates and initializes a new preconnection object on the heap.
1329 * The returned object must be freed with ct_preconnection_free().
1330 *
1331 * Takes deep copies of all passed endpoints and transport/security parameters.
1332 * The caller can therefore safely free or reuse the original parameters after this function returns.
1333 *
1334 * @param[in] local_endpoints Array of local endpoints to bind to, or NULL
1335 * @param[in] num_local_endpoints Number of local endpoints (0 if local_endpoints is NULL)
1336 * @param[in] remote_endpoints Array of remote endpoints to connect to, or NULL
1337 * @param[in] num_remote_endpoints Number of remote endpoints (0 if remote_endpoints is NULL)
1338 * @param[in] transport_properties Transport property preferences, or NULL for defaults
1339 * @param[in] security_parameters Security configuration (TLS/QUIC), or NULL
1340 * @return Pointer to newly allocated preconnection, or NULL on allocation failure
1341 */
1343ct_preconnection_new(const ct_local_endpoint_t* const* local_endpoints, size_t num_local_endpoints,
1344 const ct_remote_endpoint_t* const* remote_endpoints, size_t num_remote_endpoints,
1345 const ct_transport_properties_t* transport_properties,
1346 const ct_security_parameters_t* security_parameters);
1347
1348/**
1349 * @ingroup preconnection
1350 * @brief Free a preconnection object.
1351 *
1352 * Releases all resources associated with the preconnection object,
1353 *
1354 * @param[in] preconnection Pointer to preconnection to free. Does nothing if NULL.
1355 */
1357
1358/**
1359 * @ingroup preconnection
1360 * @brief Set a message framer for the preconnection.
1361 *
1362 * CTaps does not take ownership of the passed framer pointer, so it can be
1363 * safely freed after return.
1364 *
1365 * @param[in,out] preconnection Preconnection to modify
1366 * @param[in] framer_impl Framer implementation to use, or NULL for no framing
1367 *
1368 * @return 0 on success, negative error code on failure
1369 */
1371 const ct_framer_impl_t* framer_impl);
1372
1373/**
1374 * @ingroup preconnection
1375 * @brief Initiate a connection
1376 *
1377 * Initiates a connection using the configured Preconnection. The connection is allocated
1378 * internally and provided to the user via the ready() callback.
1379 *
1380 * CTaps does not take ownership of the passed preconnection pointer, so it can be
1381 * safely freed after return.
1382 *
1383 * CTaps does not take ownership of the passed connection_callbacks pointer,
1384 * so it can be safely freed after return.
1385 *
1386 * @param[in] preconnection Pointer to the Preconnection object containing the connection
1387 * configuration.
1388 * @param[in] connection_callbacks Struct containing callback functions for connection events:
1389 *
1390 * @return 0 on success, negative error code on synchronous failure
1391 *
1392 * @note Asynchronous errors are reported via the establishment_error callback
1393 */
1395 const ct_connection_callbacks_t* connection_callbacks);
1396
1397/**
1398 * @ingroup preconnection
1399 * @brief Initiate a connection and send a message immediately upon establishment.
1400 *
1401 * Initiates a connection using the configured Preconnection. The connection is allocated
1402 * internally and provided to the user via the ready() callback. If the underlying protocol
1403 * supports 0-RTT or early data, the message may be sent during the handshake.
1404 * Otherwise the data will be sent immediately after establishment.
1405 *
1406 * CTaps does not take ownership of any passed pointer, so they can all be
1407 * safely freed after this connection returns.
1408 *
1409 * @param[in] preconnection Pointer to the Preconnection object containing the connection
1410 * configuration.
1411 * @param[in] connection_callbacks Struct containing callback functions for connection events:
1412 *
1413 *
1414 * @return 0 on success, negative error code on synchronous failure
1415 *
1416 * @note Asynchronous errors are reported via the establishment_error callback
1417 * @note the message context must have the MSG_SAFELY_REPLAYABLE property set to make use of 0-RTT
1418 */
1420 const ct_connection_callbacks_t* connection_callbacks,
1421 const ct_message_t* message,
1422 const ct_message_context_t* message_context);
1423
1424/**
1425 * @ingroup preconnection
1426 * @brief Start listening for incoming connections using the configured Preconnection.
1427 *
1428 * CTaps does not take ownership of any passed pointer, so they can all be
1429 * safely freed after this connection returns.
1430 *
1431 * @param[in] preconnection Pointer to preconnection with listener configuration
1432 * @param[in] listener_callbacks Callbacks for listener events (ready, connection_received, etc.)
1433 * @param[in] connection_callbacks Callbacks for connection events on accepted connections
1434 * @return 0 on success, negative error code on synchronous failure
1435 *
1436 * @see ct_listener_close() to stop accepting new connections
1437 */
1439 const ct_listener_callbacks_t* listener_callbacks,
1440 const ct_connection_callbacks_t* connection_callbacks);
1441
1442/**
1443 * @ingroup connection
1444 * @brief Send a message over a connection with default properties.
1445 *
1446 * Takes a deep copy of the sent message, application can free or
1447 * reuse the original message after this function returns.
1448 *
1449 * @param[in] connection The connection to send on
1450 * @param[in] message The message to send
1451 * @return 0 on success, negative error code on failure
1452 */
1454
1455/**
1456 * @ingroup connection
1457 * @brief Send a message with custom message context and properties.
1458 *
1459 * Takes a deep copy of the sent message, application can free or
1460 * reuse the original message after this function returns.
1461 *
1462 * @param[in] connection The connection to send on
1463 * @param[in] message The message to send
1464 * @param[in] message_context Message properties and context
1465 * @return 0 on success, negative error code on failure
1466 */
1468 const ct_message_context_t* message_context);
1469
1470/**
1471 * @ingroup connection
1472 * @brief Register callbacks to receive messages on a connection.
1473 *
1474 * CTaps does not take ownership of the passed receive_callbacks pointer,
1475 * so it can be safely freed after return.
1476 *
1477 * @param[in] connection The connection to receive on
1478 * @param[in] receive_callbacks Callbacks for receive events
1479 * @return 0 on success, negative error code on failure
1480 */
1482 const ct_receive_callbacks_t* receive_callbacks);
1483
1484/**
1485 * @ingroup connection
1486 * @brief Get shared connection properties for a connection
1487 * @param[in] connection The connection to query
1488 * @return pointer to transport properties shared with connections in the same connection group, or NULL if connection is NULL
1489 */
1492
1493/**
1494 * @ingroup connection
1495 * @brief Get relative priority when compared to other connections in the same group.
1496 *
1497 * Lower values are higher priority.
1498 *
1499 * Defaults to 100.
1500 *
1501 * @return Priority value, or UINT8_MAX if connection is NULL
1502 */
1504
1505/**
1506 * @ingroup connection
1507 * @brief Set relative priority for a connection compared to other connections in the same group.
1508 *
1509 * @return 0 on success, negative error code on failure
1510 * @note If a protocol does not support prioritization this does not return any error, but the value is not used.
1511 */
1512CT_EXTERN int ct_connection_set_priority(ct_connection_t* connection, uint8_t priority);
1513
1514/**
1515 * @ingroup connection
1516 * @brief Get the connection's callback context.
1517 * @param[in] connection connection to get callback context for
1518 * @return Void pointer assigned to callback context
1519 * null if connection is null or it hasn't been set
1520 */
1522
1523/**
1524 * @ingroup connection
1525 * @brief Get the UUID of a connection
1526 * @param[in] connection connection to get uuid for
1527 * @return Pointer to uuid string
1528 */
1529CT_EXTERN const char* ct_connection_get_uuid(const ct_connection_t* connection);
1530
1531/**
1532 * @ingroup connection
1533 * @brief Get the name of the underlying protocol
1534 * @param[in] connection connection to get protocol name for
1535 * @return Pointer to protocol name, NULL if connection is NULL
1536 */
1538
1539/**
1540 * @ingroup connection
1541 * @brief Get the currently active remote endpoint for the connection
1542 * @param[in] connection connection to get remote endpoint for
1543 * @return Pointer to endpoint, NULL if connection is NULL
1544 */
1547
1548/**
1549 * @ingroup connection
1550 * @brief Get the currently active local endpoint
1551 * @param[in] connection connection to get local endpoint for
1552 * @return Pointer to endpoint, NULL if connection is NULL
1553 */
1556
1557/**
1558 * @ingroup connection
1559 * @brief Get the current state of a connection.
1560 * @param[in] connection The connection to query
1561 * @return connection lifecycle state, -1 if connection is NULL
1562 */
1564
1565/**
1566 * @ingroup connection
1567 * @brief Check if a connection's state is CT_CONN_STATE_CLOSED.
1568 *
1569 * @see ct_connection_get_state() for a generic getter
1570 *
1571 * @param[in] connection The connection to check
1572 * @return true if connection is closed, false if open or connection is NULL
1573 */
1575
1576/**
1577 * @ingroup connection
1578 * @brief Check if a connection's state is CT_CONN_STATE_ESTABLISHED.
1579 *
1580 * @see ct_connection_get_state() for a generic getter
1581 *
1582 * @param[in] connection The connection to check
1583 * @return true if connection state matches, false otherwise, including if connection is NULL
1584 */
1586
1587/**
1588 * @ingroup connection
1589 * @brief Check if a connection's state is CT_CONN_STATE_ESTABLISHING
1590 *
1591 * @see ct_connection_get_state() for a generic getter
1592 *
1593 * @param[in] connection The connection to check
1594 * @return true if connection state matches, false otherwise, including if connection is NULL
1595 */
1597
1598/**
1599 * @ingroup connection
1600 * @brief Check if a connection's state is CT_CONN_STATE_CLOSING
1601 *
1602 * @see ct_connection_get_state() for a generic getter
1603 *
1604 * @param[in] connection The connection to check
1605 * @return true if connection state matches, false otherwise, including if connection is NULL
1606 */
1608
1609/**
1610 * @ingroup connection
1611 * @brief Check if a connection's state is CT_CONN_STATE_CLOSED or CT_CONN_STATE_CLOSING
1612 *
1613 * @see ct_connection_get_state() for a generic getter
1614 *
1615 * @param[in] connection The connection to check
1616 * @return true if connection state matches, false otherwise, including if connection is NULL
1617 */
1619
1620/**
1621 * @ingroup connection
1622 * @brief Check if a connection is a client connection.
1623 *
1624 * @param[in] connection The connection to check
1625 * @return true if connection role matches, false otherwise, including if connection is NULL
1626 */
1628
1629/**
1630 * @ingroup connection
1631 * @brief Check if a connection is a server connection.
1632 * @param[in] connection The connection to check
1633 * @return true if connection role matches, false otherwise, including if connection is NULL
1634 */
1636
1637/**
1638 * @ingroup connection
1639 * @brief Check the value of the canSend connection property.
1640 * @param[in] connection The connection to check
1641 * @return false if connection is NULL or if canSend is false.
1642 */
1644
1645/**
1646 * @ingroup connection
1647 * @brief Check the value of the canReceive connection property.
1648 *
1649 * @param[in] connection The connection to check
1650 * @return false if connection is NULL or if canReceive is false.
1651 */
1653
1654/**
1655 * @ingroup connection
1656 * @brief Free resources in a connection.
1657 * @param[in] connection Connection to free
1658 */
1660
1661/**
1662 * @ingroup connection
1663 * @brief Close a connection gracefully.
1664 *
1665 * Exact behaviour depends on the underlying transport protocol.
1666 * For TCP, this performs a graceful shutdown (e.g., FIN).
1667 * For UDP this simply stops further sends and receives and closes the socket.
1668 * For QUIC it closes the connection, if the connection it is invoked on
1669 * is the last open connection in the connection group. Otherwise it closes
1670 * the connection one way (sending a FIN), stopping sending but allowing receives to continue
1671 * until the remote also closes.
1672 *
1673 * @param[in] connection Connection to close
1674 */
1676
1677/**
1678 * @ingroup connection
1679 * @brief Forcefully abort a connection without graceful shutdown.
1680 *
1681 * Unlike ct_connection_close() which performs a graceful shutdown (e.g., FIN),
1682 * this immediately terminates the connection (e.g., RST). Use when an error
1683 * condition requires immediate termination.
1684 *
1685 * @param[in] connection Connection to abort
1686 */
1688
1689/**
1690 * @ingroup connection
1691 * @brief Clone a connection to create a new connection in the same connection group.
1692 *
1693 * Creates a new connection that shares the same transport session as the parent
1694 * connection. This enables a multi-streaming protocols like QUIC to create
1695 * multiple logical connections (streams) over a single transport session.
1696 *
1697 * The callbacks of the source connection are copied into the cloned connection.
1698 * The ready callback is invoked with the cloned connection as a parameter, when
1699 * connection succeeds.
1700 *
1701 * @note The cloned connection will share callbacks with the source connection.
1702 * When the clone is ready, it will invoke the source connection's ready callback
1703 * with the cloned connection as a parameter.
1704 *
1705 * @param[in] source_connection The connection to clone
1706 * @param[in] framer Optional framer for the cloned connection (NULL to inherit)
1707 * @param[in] connection_properties Optional properties for cloned connection (Not implemented)
1708 * @return 0 on success, negative error code on failure
1709 */
1711 const ct_framer_impl_t* framer,
1712 const ct_transport_properties_t* connection_properties);
1713
1714/**
1715 * @ingroup connection
1716 * @brief Clone a connection with only mandatory parameters.
1717 *
1718 * @see ct_connection_clone_full
1719 */
1721
1722/**
1723 * @ingroup connection
1724 * @brief Get the total number of connections in a connection group (including closed ones).
1725 *
1726 * @param[in] connection The connection to query
1727 * @return The total number of connections in the group
1728 */
1730
1731/**
1732 * @ingroup connection
1733 * @brief Get the number of open connections in a connection group.
1734 *
1735 * @param[in] connection The connection to query
1736 * @return The number of open (non-closed) connections in the group
1737 */
1739
1740/**
1741 * @ingroup connection
1742 * @brief Close all connections in the same connection group gracefully.
1743 *
1744 * Performs graceful shutdown of all connections in the group (the connection
1745 * and all its clones). This is equivalent to calling ct_connection_close() on
1746 * each connection in the group.
1747 *
1748 * @param[in] connection Any connection in the group to close
1749 */
1751
1752/**
1753 * @ingroup connection
1754 * @brief Forcefully abort all connections in the same connection group.
1755 *
1756 * Immediately terminates all connections in the group without graceful shutdown.
1757 * This is equivalent to calling ct_connection_abort() on each connection in the group.
1758 *
1759 * @param[in] connection Any connection in the group to abort
1760 */
1762
1763
1764/**
1765 * @ingroup connection
1766 * @brief Enumeration of currently supported transport protocols.
1767 */
1768typedef enum {
1769 CT_PROTOCOL_ERROR = -1, ///< returned from getters in errors, e.g. null connection
1774
1775/**
1776 * @ingroup connection
1777 * @brief Get the transport protocol used by a connection.
1778 *
1779 * @param[in] connection The connection to query
1780 * @return The transport protocol enum value, or CT_PROTOCOL_ERROR if protocol cannot be determined
1781 */
1784
1785/**
1786 * @ingroup connection
1787 * @brief Check if a connection has sent early data (e.g., 0-RTT).
1788 *
1789 * @param[in] connection The connection to check
1790 * @return true if early data was sent, false if not or if connection is NULL
1791 */
1793
1794#endif // CTAPS_H
#define output_transport_property_setter_declaration(enum_name, string_name, property_type, token_name, default_value, type_enum)
Definition ctaps.h:370
const ct_local_endpoint_t * ct_message_context_get_local_endpoint(const ct_message_context_t *message_context)
Get the local endpoint from a message context.
#define output_message_context_setter_declaration(enum_name, string_name, property_type, token_name, default_value, type_enum)
Definition ctaps.h:1093
#define output_transport_property_getter_declaration(enum_name, string_name, property_type, token_name, default_value, type_enum)
Definition ctaps.h:360
#define output_transport_property_preference_getter_declaration( enum_name, string_name, property_type, token_name, default_value, type)
Definition ctaps.h:365
const ct_remote_endpoint_t * ct_message_context_get_remote_endpoint(const ct_message_context_t *message_context)
Get the remote endpoint from a message context.
ct_message_context_t * ct_message_context_new(void)
Initialize a message context with default values.
#define get_tcp_connection_properties(f)
Definition ctaps.h:339
#define output_transport_property_preference_set_adder(enum_name, string_name, property_type, token_name, default_value, type)
Definition ctaps.h:375
#define get_selection_property_list(f)
Definition ctaps.h:222
#define output_message_property_getter_declaration(enum_name, string_name, property_type, token_name, default_value, type_enum)
Definition ctaps.h:451
#define get_read_only_connection_properties(f)
Definition ctaps.h:334
void ct_message_context_free(ct_message_context_t *message_context)
Free resources in a message context.
#define CT_EXTERN
Definition ctaps.h:19
const ct_message_properties_t * ct_message_context_get_message_properties(const ct_message_context_t *message_context)
Get message properties from a message context.
#define output_message_property_setter_declaration(enum_name, string_name, property_type, token_name, default_value, type_enum)
Definition ctaps.h:456
#define get_message_property_list(f)
Definition ctaps.h:439
#define output_message_context_getter_declaration(enum_name, string_name, property_type, token_name, default_value, type_enum)
Definition ctaps.h:1088
#define get_writable_connection_property_list(f)
Definition ctaps.h:319
#define get_preference_set_selection_property_list(f)
Definition ctaps.h:240
void * ct_message_context_get_receive_context(const ct_message_context_t *message_context)
Get the receive context from a message context.
ct_connection_state_enum_t
Connection lifecycle states.
Definition ctaps.h:279
ct_capacity_profile_enum_t
QoS capacity profiles for traffic classification.
Definition ctaps.h:299
ct_connection_scheduler_enum_t
Connection scheduling algorithms for multipath.
Definition ctaps.h:291
ct_multipath_policy_enum_t
Policies for multipath traffic distribution.
Definition ctaps.h:312
@ CT_CONN_STATE_ESTABLISHED
Connection is ready for data transfer.
Definition ctaps.h:282
@ CT_CONN_STATE_CLOSED
Connection is fully closed.
Definition ctaps.h:284
@ CT_CONN_STATE_ESTABLISHING
Connection is being established.
Definition ctaps.h:281
@ CT_CONN_STATE_INVALID
Invalid state (used for error handling)
Definition ctaps.h:280
@ CT_CONN_STATE_CLOSING
Connection is closing gracefully.
Definition ctaps.h:283
@ CT_CAPACITY_PROFILE_CONSTANT_RATE_STREAMING
Constant bitrate streaming.
Definition ctaps.h:304
@ CT_CAPACITY_PROFILE_SCAVENGER
Background/bulk traffic.
Definition ctaps.h:301
@ CT_CAPACITY_PROFILE_BEST_EFFORT
Default best-effort traffic.
Definition ctaps.h:300
@ CT_CAPACITY_PROFILE_CAPACITY_SEEKING
Throughput-seeking traffic.
Definition ctaps.h:305
@ CT_CAPACITY_PROFILE_LOW_LATENCY_NON_INTERACTIVE
Non-interactive low-latency (e.g., streaming)
Definition ctaps.h:303
@ CT_CAPACITY_PROFILE_LOW_LATENCY_INTERACTIVE
Interactive low-latency (e.g., gaming, VoIP)
Definition ctaps.h:302
@ CT_CONN_SCHEDULER_WEIGHTED_FAIR_QUEUEING
Weighted fair queueing across paths.
Definition ctaps.h:292
@ CT_MULTIPATH_POLICY_HANDOVER
Use paths sequentially (failover only)
Definition ctaps.h:313
@ CT_MULTIPATH_POLICY_INTERACTIVE
Optimize for low latency.
Definition ctaps.h:314
@ CT_MULTIPATH_POLICY_AGGREGATE
Use all paths for maximum throughput.
Definition ctaps.h:315
void * ct_connection_get_callback_context(const ct_connection_t *connection)
Get the connection's callback context.
bool ct_connection_is_established(const ct_connection_t *connection)
Check if a connection's state is CT_CONN_STATE_ESTABLISHED.
const char * ct_connection_get_protocol_name(const ct_connection_t *connection)
Get the name of the underlying protocol.
int ct_connection_clone_full(const ct_connection_t *source_connection, const ct_framer_impl_t *framer, const ct_transport_properties_t *connection_properties)
Clone a connection to create a new connection in the same connection group.
int ct_connection_clone(ct_connection_t *source_connection)
Clone a connection with only mandatory parameters.
void ct_connection_close(ct_connection_t *connection)
Close a connection gracefully.
bool ct_connection_is_establishing(const ct_connection_t *connection)
Check if a connection's state is CT_CONN_STATE_ESTABLISHING.
const ct_local_endpoint_t * ct_connection_get_active_local_endpoint(const ct_connection_t *connection)
Get the currently active local endpoint.
bool ct_connection_can_receive(const ct_connection_t *connection)
Check the value of the canReceive connection property.
bool ct_connection_is_server(const ct_connection_t *connection)
Check if a connection is a server connection.
const char * ct_connection_get_uuid(const ct_connection_t *connection)
Get the UUID of a connection.
int ct_receive_message(ct_connection_t *connection, const ct_receive_callbacks_t *receive_callbacks)
Register callbacks to receive messages on a connection.
int ct_send_message(ct_connection_t *connection, const ct_message_t *message)
Send a message over a connection with default properties.
int ct_send_message_full(ct_connection_t *connection, const ct_message_t *message, const ct_message_context_t *message_context)
Send a message with custom message context and properties.
int ct_connection_set_priority(ct_connection_t *connection, uint8_t priority)
Set relative priority for a connection compared to other connections in the same group.
bool ct_connection_is_closing(const ct_connection_t *connection)
Check if a connection's state is CT_CONN_STATE_CLOSING.
bool ct_connection_is_closed_or_closing(const ct_connection_t *connection)
Check if a connection's state is CT_CONN_STATE_CLOSED or CT_CONN_STATE_CLOSING.
ct_protocol_enum_t
Enumeration of currently supported transport protocols.
Definition ctaps.h:1768
bool ct_connection_sent_early_data(const ct_connection_t *connection)
Check if a connection has sent early data (e.g., 0-RTT).
const ct_remote_endpoint_t * ct_connection_get_active_remote_endpoint(const ct_connection_t *connection)
Get the currently active remote endpoint for the connection.
size_t ct_connection_get_total_num_grouped_connections(const ct_connection_t *connection)
Get the total number of connections in a connection group (including closed ones).
void ct_connection_abort(ct_connection_t *connection)
Forcefully abort a connection without graceful shutdown.
void ct_connection_close_group(ct_connection_t *connection)
Close all connections in the same connection group gracefully.
void ct_connection_free(ct_connection_t *connection)
Free resources in a connection.
const ct_transport_properties_t * ct_connection_get_transport_properties(const ct_connection_t *connection)
Get shared connection properties for a connection.
size_t ct_connection_get_num_open_grouped_connections(const ct_connection_t *connection)
Get the number of open connections in a connection group.
void ct_connection_abort_group(ct_connection_t *connection)
Forcefully abort all connections in the same connection group.
bool ct_connection_is_client(const ct_connection_t *connection)
Check if a connection is a client connection.
uint8_t ct_connection_get_priority(const ct_connection_t *connection)
Get relative priority when compared to other connections in the same group.
bool ct_connection_is_closed(const ct_connection_t *connection)
Check if a connection's state is CT_CONN_STATE_CLOSED.
ct_connection_state_enum_t ct_connection_get_state(const ct_connection_t *connection)
Get the current state of a connection.
ct_protocol_enum_t ct_connection_get_transport_protocol(const ct_connection_t *connection)
Get the transport protocol used by a connection.
bool ct_connection_can_send(const ct_connection_t *connection)
Check the value of the canSend connection property.
@ CT_PROTOCOL_TCP
Definition ctaps.h:1770
@ CT_PROTOCOL_ERROR
returned from getters in errors, e.g. null connection
Definition ctaps.h:1769
@ CT_PROTOCOL_QUIC
Definition ctaps.h:1772
@ CT_PROTOCOL_UDP
Definition ctaps.h:1771
int(* ct_framer_done_encoding_callback)(ct_connection_t *connection, ct_message_t *encoded_message, ct_message_context_t *context)
Callback invoked by framer when message encoding is complete.
Definition ctaps.h:1260
void(* ct_framer_done_decoding_callback)(ct_connection_t *connection, ct_message_t *decoded_message, ct_message_context_t *context)
Callback invoked by framer when message decoding is complete.
Definition ctaps.h:1272
int ct_start_event_loop(void)
Start the CTaps event loop (blocking operation).
int ct_close(void)
Close and cleanup the CTaps library.
int ct_initialize(void)
Initialize the CTaps library.
void ct_listener_close(ct_listener_t *listener)
Close a listener and stop accepting new connections.
void ct_listener_free(ct_listener_t *listener)
Free resources in a listener.
bool ct_listener_is_closed(const ct_listener_t *listener)
Check if a listener is closed.
void * ct_listener_get_callback_context(const ct_listener_t *listener)
Get the callback context associated with a listener.
int ct_local_endpoint_with_service(ct_local_endpoint_t *local_endpoint, const char *service)
Set the service name for a local endpoint.
int ct_local_endpoint_with_interface(ct_local_endpoint_t *local_endpoint, const char *interface_name)
Set the network interface for a local endpoint.
uint16_t ct_local_endpoint_get_resolved_port(const ct_local_endpoint_t *local_endpoint)
Get the resolved port for a local endpoint after binding.
void ct_local_endpoint_with_port(ct_local_endpoint_t *local_endpoint, uint16_t port)
Set the port number for a local endpoint.
int ct_local_endpoint_from_sockaddr(ct_local_endpoint_t *local_endpoint, const struct sockaddr_storage *addr)
Initialize a local endpoint from a sockaddr structure.
void ct_local_endpoint_free(ct_local_endpoint_t *local_endpoint)
Free all resources in a local endpoint including the structure itself.
int ct_local_endpoint_with_ipv6(ct_local_endpoint_t *local_endpoint, struct in6_addr ipv6_addr)
Set the IPv6 address for a local endpoint.
const char * ct_local_endpoint_get_service(const ct_local_endpoint_t *local_endpoint)
Get the service for a local endpoint.
ct_local_endpoint_t * ct_local_endpoint_deep_copy(const ct_local_endpoint_t *local_endpoint)
Create a heap-allocated copy of a local endpoint.
ct_local_endpoint_t * ct_local_endpoint_new(void)
Create a new heap-allocated local endpoint.
int ct_local_endpoint_with_ipv4(ct_local_endpoint_t *local_endpoint, in_addr_t ipv4_addr)
Set the IPv4 address for a local endpoint.
int ct_add_log_file(const char *file_path, ct_log_level_enum_t min_level)
Add a file output destination for CTaps logs.
void ct_set_log_level(ct_log_level_enum_t level)
Set the minimum logging level for CTaps.
ct_log_level_enum_t
Log level enumeration for filtering log output.
Definition ctaps.h:125
@ CT_LOG_ERROR
Error messages.
Definition ctaps.h:130
@ CT_LOG_INFO
Informational messages (default)
Definition ctaps.h:128
@ CT_LOG_TRACE
Trace-level debugging (most verbose)
Definition ctaps.h:126
@ CT_LOG_DEBUG
Debug-level information.
Definition ctaps.h:127
@ CT_LOG_WARN
Warning messages.
Definition ctaps.h:129
ct_message_properties_t * ct_message_properties_new(void)
Create a new message properties object with default values.
void ct_message_properties_free(ct_message_properties_t *message_properties)
Free resources in message properties.
const char * ct_message_get_content(const ct_message_t *message)
Get the content buffer of a message.
ct_message_t * ct_message_deep_copy(const ct_message_t *message)
Create a deep copy of a message, including its content.
ct_message_t * ct_message_new(void)
Allocate a new message on the heap.
ct_message_t * ct_message_new_with_content(const char *content, size_t length)
Allocate a new message with content.
void ct_message_free(ct_message_t *message)
Free all resources in a message including the structure.
void ct_message_set_content(ct_message_t *message, const void *content, size_t length)
Set the content of a message, replacing any existing content.
size_t ct_message_get_length(const ct_message_t *message)
Get the length of a message.
int ct_preconnection_initiate_with_send(const ct_preconnection_t *preconnection, const ct_connection_callbacks_t *connection_callbacks, const ct_message_t *message, const ct_message_context_t *message_context)
Initiate a connection and send a message immediately upon establishment.
ct_preconnection_t * ct_preconnection_new(const ct_local_endpoint_t *const *local_endpoints, size_t num_local_endpoints, const ct_remote_endpoint_t *const *remote_endpoints, size_t num_remote_endpoints, const ct_transport_properties_t *transport_properties, const ct_security_parameters_t *security_parameters)
Create a new preconnection with transport properties and endpoints.
void ct_preconnection_free(ct_preconnection_t *preconnection)
Free a preconnection object.
int ct_preconnection_listen(const ct_preconnection_t *preconnection, const ct_listener_callbacks_t *listener_callbacks, const ct_connection_callbacks_t *connection_callbacks)
Start listening for incoming connections using the configured Preconnection.
int ct_preconnection_initiate(const ct_preconnection_t *preconnection, const ct_connection_callbacks_t *connection_callbacks)
Initiate a connection.
int ct_preconnection_set_framer(ct_preconnection_t *preconnection, const ct_framer_impl_t *framer_impl)
Set a message framer for the preconnection.
int ct_remote_endpoint_with_ipv4(ct_remote_endpoint_t *remote_endpoint, in_addr_t ipv4_addr)
Set the IPv4 address for a remote endpoint.
ct_remote_endpoint_t * ct_remote_endpoint_new(void)
Create a new heap-allocated remote endpoint.
int ct_remote_endpoint_with_service(ct_remote_endpoint_t *remote_endpoint, const char *service)
Set the service name for a remote endpoint.
void ct_remote_endpoint_free(ct_remote_endpoint_t *remote_endpoint)
Free all resources in a remote endpoint including the structure itself.
const char * ct_remote_endpoint_get_service(const ct_remote_endpoint_t *remote_endpoint)
Get the service for a remote endpoint.
void ct_remote_endpoint_with_port(ct_remote_endpoint_t *remote_endpoint, uint16_t port)
Set the port number for a remote endpoint.
int ct_remote_endpoint_with_hostname(ct_remote_endpoint_t *remote_endpoint, const char *hostname)
Set the hostname for a remote endpoint.
int ct_remote_endpoint_from_sockaddr(ct_remote_endpoint_t *remote_endpoint, const struct sockaddr_storage *addr)
Initialize a remote endpoint from a sockaddr structure.
int ct_remote_endpoint_with_ipv6(ct_remote_endpoint_t *remote_endpoint, struct in6_addr ipv6_addr)
Set the IPv6 address for a remote endpoint.
ct_remote_endpoint_t * ct_remote_endpoint_deep_copy(const ct_remote_endpoint_t *remote_endpoint)
Create a heap-allocated copy of a remote endpoint.
const char * ct_security_parameters_get_ticket_store_path(const ct_security_parameters_t *sec)
int ct_security_parameters_clear_alpn(ct_security_parameters_t *sec)
Free and clear all configured ALPN protocol identifiers from the security parameters.
int ct_security_parameters_set_session_ticket_encryption_key(ct_security_parameters_t *sec, const uint8_t *key, size_t key_len)
Set the session ticket encryption key for QUIC session resumption.
ct_security_parameters_t * ct_security_parameters_new(void)
Allocate a new security parameters object on the heap.
size_t ct_security_parameters_get_client_certificate_count(const ct_security_parameters_t *sec)
size_t ct_security_parameters_get_server_certificate_count(const ct_security_parameters_t *sec)
const uint8_t * ct_security_parameters_get_session_ticket_encryption_key(const ct_security_parameters_t *sec, size_t *key_len)
Get the session ticket encryption key.
const char * ct_security_parameters_get_server_name_identification(const ct_security_parameters_t *sec)
const char * ct_security_parameters_get_server_certificate_file(const ct_security_parameters_t *sec, size_t index)
int ct_security_parameters_add_client_certificate(ct_security_parameters_t *sec, const char *cert_file, const char *key_file)
Add a client certificate and private key for TLS connections.
int ct_security_parameters_set_ticket_store_path(ct_security_parameters_t *sec, const char *ticket_store_path)
Set the path to the ticket store for QUIC session resumption.
const char *const * ct_security_parameters_get_alpns(const ct_security_parameters_t *sec, size_t *num_alpns)
Get the configured ALPN protocol identifiers.
const char * ct_security_parameters_get_client_certificate_file(const ct_security_parameters_t *sec, size_t index)
void ct_security_parameters_free(ct_security_parameters_t *security_parameters)
Free resources in security parameters including the structure itself.
int ct_security_parameters_add_server_certificate(ct_security_parameters_t *sec, const char *cert_file, const char *key_file)
Add a server certificate and private key for TLS connections.
const char * ct_security_parameters_get_server_certificate_key_file(const ct_security_parameters_t *sec, size_t index)
int ct_security_parameters_add_alpn(ct_security_parameters_t *sec, const char *alpn)
Add an ALPN protocol identifier to the list of supported ALPNs for TLS connections.
int ct_security_parameters_set_server_name_identification(ct_security_parameters_t *sec, const char *sni)
Set the server name identification (SNI) for TLS connections.
const char * ct_security_parameters_get_client_certificate_key_file(const ct_security_parameters_t *sec, size_t index)
ct_selection_preference_enum_t
Preference levels for transport selection properties.
Definition ctaps.h:188
ct_multipath_enum_t
Multipath transport modes.
Definition ctaps.h:211
ct_direction_of_communication_enum_t
Direction of communication for a connection.
Definition ctaps.h:201
@ REQUIRE
Protocol MUST have this property (eliminates candidates)
Definition ctaps.h:193
@ NO_PREFERENCE
No preference - property does not affect selection.
Definition ctaps.h:191
@ PREFER
Prefer protocols with this property if available.
Definition ctaps.h:192
@ PROHIBIT
Protocol MUST NOT have this property (eliminates candidates)
Definition ctaps.h:189
@ AVOID
Prefer protocols without this property if possible.
Definition ctaps.h:190
@ CT_MULTIPATH_ACTIVE
Actively use multiple paths simultaneously.
Definition ctaps.h:213
@ CT_MULTIPATH_PASSIVE
Will accept multipath used by peer.
Definition ctaps.h:214
@ CT_MULTIPATH_DISABLED
Do not use multipath.
Definition ctaps.h:212
@ CT_DIRECTION_BIDIRECTIONAL
Two-way communication (send and receive)
Definition ctaps.h:202
@ CT_DIRECTION_UNIDIRECTIONAL_RECV
One-way, receive only.
Definition ctaps.h:204
@ CT_DIRECTION_UNIDIRECTIONAL_SEND
One-way, send only.
Definition ctaps.h:203
void ct_transport_properties_free(ct_transport_properties_t *props)
Free a transport properties object.
ct_transport_properties_t * ct_transport_properties_new(void)
Create a new transport properties object with default values.
Callback functions for connection lifecycle events.
Definition ctaps.h:1152
void * per_connection_context
User-provided context for the connection lifetime.
Definition ctaps.h:1196
Opaque handle representing a connection.
Opaque handle representing a framer layer, wrapping or unwrapping sent/received messages.
Definition ctaps.h:1284
Callback functions for listener events.
Definition ctaps.h:1205
void * per_listener_context
Definition ctaps.h:1244
Opaque handle representing a listener.
Opaque handle representing a local endpoint (generic or resolved to specific ip address and port).
Opaque handle representing message metadata to pass to sending protocol.
Collection of message properties for per-message transmission control.
Opaque handle representing a single message to be sent or received.
Opaque handle representing a preconnection.
Callback functions for receiving messages on a connection.
Definition ctaps.h:1111
void * per_receive_context
Per-receive user context accessible when this specific callback is invoked. Can be fetched within ct_...
Definition ctaps.h:1142
Opaque handle representing a remote endpoint (generic or resolved to specific ip address and port).
Opaque handle representing a security parameters used to configure security settings for connections ...
Opaque handle representing transport properties used for selecting and configuring protocols.