Line data Source code
1 : #ifndef HEADER_fd_src_waltz_quic_fd_quic_h
2 : #define HEADER_fd_src_waltz_quic_fd_quic_h
3 :
4 : /* fd_quic_t is a partial implementation of QUIC -- an encrypted,
5 : multiplexing transport layer network protocol.
6 :
7 : For now, IPv4 over Ethernet (EN10MB) flows are supported.
8 :
9 : This API is non-blocking and single-threaded. Any requests to the
10 : peer (such as "open a connection") are queued and processed on RX
11 : or service call. The user is notified of events via callbacks.
12 : The user must further ensure that RX (via fd_aio_t) is dispatched
13 : only from the thread with the active join to the target fd_quic_t.
14 :
15 : Scaling is achieved via fd_quic_t instances and steering of RX flows.
16 : For example, incoming RX that exceeds the throughput of one fd_quic_t
17 : may be load balanced based on QUIC dest conn ID, or UDP src flow ID.
18 :
19 : This implementation aims to be compliant to RFC 9000 and RFC 9001:
20 : - https://datatracker.ietf.org/doc/html/rfc9000
21 : - https://datatracker.ietf.org/doc/html/rfc9001
22 :
23 : ### Memory Management
24 :
25 : fd_quic is entirely pre-allocated. Currently, a QUIC object reserves
26 : space for a number of connection slots, with uniform stream,
27 : reassembly, and ACK buffers.
28 :
29 : ### Memory Layout
30 :
31 : fd_quic_t is the publicly exported memory layout of a QUIC object.
32 : The private memory region of a QUIC object extends beyond the end of
33 : this struct. fd_quic_t is not intended to be allocated directly,
34 : refer to the below for details.
35 :
36 : ### Lifecycle
37 :
38 : The below state diagram shows the lifecycle of an fd_quic_t.
39 :
40 : ┌───────────┐ new ┌───────────┐ join ┌──────────┐
41 : │ ├───────►│ ├──────►│ │
42 : │ allocated │ │ formatted │ │ joined │
43 : │ │◄───────┤ │◄──────┤ │
44 : └───────────┘ delete └───────────┘ leave └───▲───┬──┘
45 : │ │ set config
46 : │ │ set callbacks
47 : fini │ │ init
48 : ┌──┴───▼──┐
49 : ┌───│ │
50 : service │ │ ready │
51 : └──►│ │
52 : └─────────┘
53 :
54 : ### Lifecycle: Allocation & Formatting
55 :
56 : A QUIC object resides in a contiguous pre-allocated memory region.
57 : (Usually, in a Firedancer workspace) The footprint and internal
58 : layout depends on the pre-configured fd_quic_limits_t parameters.
59 : These limits are constant throughout the lifetime of an fd_quic_t.
60 :
61 : Use fd_quic_{align,footprint} to determine size and alignment of the
62 : memory region to be used. Use fd_quic_new to format such a memory
63 : region and to obtain an opaque handle. In the formatted state, the
64 : fd_quic_t is position-independent (may be mapped at different virtual
65 : addresses). This is useful for separating allocation and runtime use
66 : into different steps.
67 :
68 : ### Lifecycle: Joining
69 :
70 : Given an opaque handle, fd_quic_join runs basic coherence checks and
71 : returns a typed pointer to the object. The object is not modified
72 : by this operation. Each object may have multiple active joins, but
73 : only one of them may write. (Typically, a single join is used for
74 : service, and secondary joins for read-only monitoring)
75 :
76 : ### Lifecycle: Usage
77 :
78 : fd_quic_init initializes an fd_quic_t for use. On success, the QUIC
79 : becomes ready to serve from the thread that init was called from (it
80 : is invalid to service QUIC from another thread). */
81 :
82 : /* TODO provide fd_quic on non-hosted targets */
83 :
84 : #include "fd_quic_common.h"
85 : #include "fd_quic_enum.h"
86 :
87 : #include "../aio/fd_aio.h"
88 : #include "../tls/fd_tls.h"
89 :
90 : /* FD_QUIC_API marks public API declarations. No-op for now. */
91 : #define FD_QUIC_API
92 :
93 : /* Forward declarations */
94 :
95 : struct fd_quic_conn;
96 : typedef struct fd_quic_conn fd_quic_conn_t;
97 :
98 : struct fd_quic_stream;
99 : typedef struct fd_quic_stream fd_quic_stream_t;
100 :
101 : struct fd_quic_state_private;
102 : typedef struct fd_quic_state_private fd_quic_state_t;
103 :
104 : /* fd_quic_limits_t defines the memory layout of an fd_quic_t object.
105 : Limits are immutable and valid for the lifetime of an fd_quic_t
106 : (i.e. outlasts joins, until fd_quic_delete) */
107 :
108 : struct __attribute__((aligned(16UL))) fd_quic_limits {
109 : ulong conn_cnt; /* instance-wide, max concurrent conn count */
110 : ulong handshake_cnt; /* instance-wide, max concurrent handshake count */
111 : ulong log_depth; /* instance-wide, depth of shm log cache */
112 :
113 : ulong conn_id_cnt; /* per-conn, max conn ID count (min 4UL) */
114 : ulong stream_id_cnt; /* per-conn, max concurrent stream ID count */
115 : ulong inflight_pkt_cnt; /* per-conn, max inflight packet count */
116 :
117 : ulong tx_buf_sz; /* per-stream, tx buf sz in bytes */
118 : /* the user consumes rx directly from the network buffer */
119 :
120 : ulong stream_pool_cnt; /* instance-wide, number of streams in stream pool */
121 : };
122 : typedef struct fd_quic_limits fd_quic_limits_t;
123 :
124 : /* fd_quic_layout_t is an offset table describing the memory layout of
125 : an fd_quic_t object. It is deived from fd_quic_limits_t. */
126 :
127 : struct fd_quic_layout {
128 : ulong meta_sz; /* size of this struct */
129 : ulong log_off; /* offset to quic_log */
130 : ulong conns_off; /* offset of connection mem region */
131 : ulong conn_footprint; /* sizeof a conn */
132 : ulong conn_map_off; /* offset of conn map mem region */
133 : int lg_slot_cnt; /* see conn_map_new */
134 : ulong hs_pool_off; /* offset of the handshake pool */
135 : ulong stream_pool_off; /* offset of the stream pool */
136 : };
137 :
138 : typedef struct fd_quic_layout fd_quic_layout_t;
139 :
140 : /* fd_quic_now_t is the clock source used internally by quic for
141 : scheduling events. context is an arbitrary pointer earlier provided
142 : by the caller during config. */
143 :
144 : typedef ulong
145 : (*fd_quic_now_t)( void * context );
146 :
147 : /* fd_quic_config_t defines mutable config of an fd_quic_t. The config is
148 : immutable during an active join. */
149 :
150 : struct __attribute__((aligned(16UL))) fd_quic_config {
151 : /* Protocol config ***************************************/
152 :
153 : /* role: one of FD_QUIC_ROLE_{CLIENT,SERVER} */
154 : int role;
155 :
156 : /* retry: whether address validation using retry packets is enabled (RFC 9000, Section 8.1.2) */
157 : int retry;
158 :
159 : /* tick_per_us: clock ticks per microsecond */
160 : double tick_per_us;
161 :
162 : /* idle_timeout: Upper bound on conn idle timeout.
163 : Also sent to peer via max_idle_timeout transport param.
164 : If the peer specifies a lower idle timeout, that is used instead. */
165 : ulong idle_timeout;
166 4257 : # define FD_QUIC_DEFAULT_IDLE_TIMEOUT (ulong)(1e9) /* 1s */
167 :
168 : /* ack_delay: median delay on outgoing ACKs. Greater delays allow
169 : fd_quic to coalesce packet ACKs. */
170 : ulong ack_delay;
171 4257 : # define FD_QUIC_DEFAULT_ACK_DELAY (ulong)(50e6) /* 50ms */
172 :
173 : /* ack_threshold: immediately send an ACK when the number of
174 : unacknowledged stream bytes exceeds this value. */
175 : ulong ack_threshold;
176 2133 : # define FD_QUIC_DEFAULT_ACK_THRESHOLD (65536UL) /* 64 KiB */
177 :
178 : /* retry_ttl: time-to-live for retry tokens */
179 : ulong retry_ttl;
180 2130 : # define FD_QUIC_DEFAULT_RETRY_TTL (ulong)(1e9) /* 1s */
181 :
182 : /* TLS config ********************************************/
183 :
184 : /* identity_key: Ed25519 public key of node identity */
185 : uchar identity_public_key[ 32 ];
186 :
187 : /* Callback for signing TLS 1.3 certificate verify payload */
188 : fd_tls_sign_fn_t sign;
189 : void * sign_ctx;
190 :
191 0 : # define FD_QUIC_PATH_LEN 1023UL
192 : char keylog_file[ FD_QUIC_PATH_LEN+1UL ];
193 :
194 : ulong initial_rx_max_stream_data; /* per-stream, rx buf sz in bytes, set by the user. */
195 :
196 : /* Network config ****************************************/
197 :
198 : struct { /* Internet config */
199 : /* dscp: Differentiated services code point.
200 : Set on all outgoing IPv4 packets. */
201 : uchar dscp;
202 : } net;
203 : };
204 :
205 : /* Callback API *******************************************************/
206 :
207 : /* Note: QUIC library invokes callbacks during RX or service. Callback
208 : may only invoke fd_quic API methods labelled CB-safe. Callbacks are
209 : not re-entrant. */
210 :
211 : /* fd_quic_cb_conn_new_t: server received a new conn and completed
212 : handshakes. */
213 : typedef void
214 : (* fd_quic_cb_conn_new_t)( fd_quic_conn_t * conn,
215 : void * quic_ctx );
216 :
217 : /* fd_quic_cb_conn_handshake_complete_t: client completed a handshake
218 : of a conn it created. */
219 : typedef void
220 : (* fd_quic_cb_conn_handshake_complete_t)( fd_quic_conn_t * conn,
221 : void * quic_ctx );
222 :
223 : /* fd_quic_cb_conn_final_t: Conn termination notification. The conn
224 : object is freed immediately after returning. User should destroy any
225 : remaining references to conn in this callback. */
226 : typedef void
227 : (* fd_quic_cb_conn_final_t)( fd_quic_conn_t * conn,
228 : void * quic_ctx );
229 :
230 : /* fd_quic_cb_stream_notify_t signals a notable stream event.
231 : stream_ctx object is the user-provided stream context set in the new
232 : callback.
233 :
234 : TODO will only one notify max be served?
235 : TODO will stream be deallocated immediately after callback?
236 :
237 : notify_type is one of FD_QUIC_NOTIFY_{...} */
238 : typedef void
239 : (* fd_quic_cb_stream_notify_t)( fd_quic_stream_t * stream,
240 : void * stream_ctx,
241 : int notify_type );
242 :
243 : typedef int
244 : (* fd_quic_cb_stream_rx_t)( fd_quic_conn_t * conn,
245 : ulong stream_id,
246 : ulong offset,
247 : uchar const * data,
248 : ulong data_sz,
249 : int fin );
250 :
251 : /* fd_quic_cb_tls_keylog_t is called when a new encryption secret
252 : becomes available. line is a cstr containing the secret in NSS key
253 : log format (intended for tests only). */
254 :
255 : typedef void
256 : (* fd_quic_cb_tls_keylog_t)( void * quic_ctx,
257 : char const * line );
258 :
259 : /* fd_quic_callbacks_t defines the set of user-provided callbacks that
260 : are invoked by the QUIC library. Resets on leave. */
261 :
262 : struct fd_quic_callbacks {
263 : /* Function pointers to user callbacks */
264 :
265 : void * quic_ctx; /* user-provided context pointer
266 : for instance-wide callbacks */
267 :
268 : fd_quic_cb_conn_new_t conn_new; /* non-NULL, with quic_ctx */
269 : fd_quic_cb_conn_handshake_complete_t conn_hs_complete; /* non-NULL, with quic_ctx */
270 : fd_quic_cb_conn_final_t conn_final; /* non-NULL, with quic_ctx */
271 : fd_quic_cb_stream_notify_t stream_notify; /* non-NULL, with stream_ctx */
272 : fd_quic_cb_stream_rx_t stream_rx; /* non-NULL, with stream_ctx */
273 : fd_quic_cb_tls_keylog_t tls_keylog; /* nullable, with quic_ctx */
274 :
275 : /* Clock source */
276 :
277 : fd_quic_now_t now; /* non-NULL */
278 : void * now_ctx; /* user-provided context pointer for now_fn calls */
279 :
280 : };
281 : typedef struct fd_quic_callbacks fd_quic_callbacks_t;
282 :
283 : /* fd_quic metrics ****************************************************/
284 :
285 : /* TODO: evaluate performance impact of metrics */
286 :
287 : union fd_quic_metrics {
288 : struct {
289 : /* Network metrics */
290 : ulong net_rx_pkt_cnt; /* number of IP packets received */
291 : ulong net_rx_byte_cnt; /* total bytes received (including IP, UDP, QUIC headers) */
292 : ulong net_tx_pkt_cnt; /* number of IP packets sent */
293 : ulong net_tx_byte_cnt; /* total bytes sent */
294 : ulong retry_tx_cnt; /* number of Retry packets sent */
295 :
296 : /* Conn metrics */
297 : ulong conn_active_cnt; /* number of active conns */
298 : ulong conn_created_cnt; /* number of conns created */
299 : ulong conn_closed_cnt; /* number of conns gracefully closed */
300 : ulong conn_aborted_cnt; /* number of conns aborted */
301 : ulong conn_timeout_cnt; /* number of conns timed out */
302 : ulong conn_retry_cnt; /* number of conns established with retry */
303 : ulong conn_err_no_slots_cnt; /* number of conns that failed to create due to lack of slots */
304 : ulong conn_err_retry_fail_cnt; /* number of conns that failed during retry (e.g. invalid token) */
305 :
306 : /* Packet metrics */
307 : ulong pkt_net_hdr_err_cnt; /* number of packets dropped due to weird IPv4/UDP headers */
308 : ulong pkt_quic_hdr_err_cnt; /* number of packets dropped due to weird QUIC header */
309 : ulong pkt_undersz_cnt; /* number of QUIC packets dropped due to being too small */
310 : ulong pkt_oversz_cnt; /* number of QUIC packets dropped due to being too large */
311 : ulong pkt_decrypt_fail_cnt[4]; /* number of packets that failed decryption due to auth tag */
312 : ulong pkt_no_key_cnt[4]; /* number of packets that failed decryption due to missing key */
313 : ulong pkt_no_conn_cnt; /* number of packets with unknown conn ID (excl. Initial) */
314 : ulong pkt_tx_alloc_fail_cnt; /* number of pkt_meta alloc fails */
315 : ulong pkt_verneg_cnt; /* number of QUIC version negotiation packets or packets with wrong version */
316 :
317 : /* Frame metrics */
318 : ulong frame_rx_cnt[ 22 ]; /* number of frames received (indexed by implementation-defined IDs) */
319 : ulong frame_rx_err_cnt; /* number of frames failed */
320 :
321 : /* Handshake metrics */
322 : ulong hs_created_cnt; /* number of handshake flows created */
323 : ulong hs_err_alloc_fail_cnt; /* number of handshakes dropped due to alloc fail */
324 :
325 : /* Stream metrics */
326 : ulong stream_opened_cnt; /* number of streams opened */
327 : ulong stream_closed_cnt[5]; /* indexed by FD_QUIC_STREAM_NOTIFY_{...} */
328 : ulong stream_active_cnt; /* number of active streams */
329 : ulong stream_rx_event_cnt; /* number of stream RX events */
330 : ulong stream_rx_byte_cnt; /* total stream payload bytes received */
331 :
332 : /* ACK metrics */
333 : ulong ack_tx[ 5 ];
334 :
335 : /* Performance metrics */
336 : fd_histf_t service_duration[ 1 ]; /* time spent in service */
337 : fd_histf_t receive_duration[ 1 ]; /* time spent in RX calls */
338 : };
339 : };
340 : typedef union fd_quic_metrics fd_quic_metrics_t;
341 :
342 : /* fd_quic_t memory layout ********************************************/
343 :
344 : struct fd_quic {
345 : ulong magic; /* ==FD_QUIC_MAGIC */
346 :
347 : fd_quic_layout_t layout; /* position-independent, persistent, read only */
348 : fd_quic_limits_t limits; /* position-independent, persistent, read only */
349 : fd_quic_config_t config; /* position-independent, persistent, writable pre init */
350 : fd_quic_callbacks_t cb; /* position-dependent, reset on join, writable pre init */
351 : fd_quic_metrics_t metrics; /* position-independent, persistent, read only */
352 :
353 : fd_aio_t aio_rx; /* local AIO */
354 : fd_aio_t aio_tx; /* remote AIO */
355 :
356 : /* ... private variable-length structures follow ... */
357 : };
358 :
359 : FD_PROTOTYPES_BEGIN
360 :
361 : /* debugging */
362 :
363 : ulong
364 : fd_quic_conn_get_pkt_meta_free_count( fd_quic_conn_t * conn );
365 :
366 :
367 : /* Object lifecycle ***************************************************/
368 :
369 : /* fd_quic_{align,footprint} return the required alignment and footprint
370 : of a memory region suitable for use as an fd_quic_t. align returns
371 : FD_QUIC_ALIGN. limits is a temporary reference to the requested
372 :
373 : On failure, footprint will silently return 0 (and thus can be used by
374 : the caller to validate fd_quic_new params) */
375 :
376 : FD_QUIC_API FD_FN_CONST ulong
377 : fd_quic_align( void );
378 :
379 : FD_QUIC_API ulong
380 : fd_quic_footprint( fd_quic_limits_t const * limits );
381 :
382 : /* fd_quic_new formats an unused memory region for use as a QUIC client
383 : or server. mem is a non-NULL pointer to this region in the local
384 : address with the required footprint and alignment. limits is a
385 : temporary reference, identical to the one given to fd_quic_footprint
386 : used to figure out the required footprint. */
387 :
388 : FD_QUIC_API void *
389 : fd_quic_new( void * mem,
390 : fd_quic_limits_t const * limits );
391 :
392 : /* fd_quic_join joins the caller to the fd_quic. shquic points to the
393 : first byte of the memory region backing the QUIC in the caller's
394 : address space.
395 :
396 : Returns a pointer in the local address space to the public fd_quic_t
397 : region on success (do not assume this to be just a cast of shquic)
398 : and NULL on failure (logs details). Reasons for failure are that
399 : shquic is obviously not a pointer to a correctly formatted QUIC
400 : object. Every successful join should have a matching leave. The
401 : lifetime of the join is until the matching leave or the thread group
402 : is terminated. */
403 :
404 : FD_QUIC_API fd_quic_t *
405 : fd_quic_join( void * shquic );
406 :
407 : /* fd_quic_leave leaves a current local join and frees all dynamically
408 : managed resources (heap allocs, OS handles). Returns the given quic
409 : on success and NULL on failure (logs details). Reasons for failure
410 : include quic is NULL or no active join */
411 :
412 : FD_QUIC_API void *
413 : fd_quic_leave( fd_quic_t * quic );
414 :
415 : /* fd_quic_delete unformats a memory region used as an fd_quic_t.
416 : Assumes nobody is joined to the region. Returns the given quic
417 : pointer on success and NULL if used obviously in error (e.g. quic is
418 : obviously not an fd_quic_t ... logs details). The ownership of the
419 : memory region is transferred ot the caller. */
420 :
421 : FD_QUIC_API void *
422 : fd_quic_delete( fd_quic_t * quic );
423 :
424 : /* Configuration ******************************************************/
425 :
426 : /* fd_quic_{limits,config}_from_env populates the given QUIC limits or
427 : config from command-line args and env vars. If parg{c,v} are non-
428 : NULL, they are updated to strip the parsed args. The last element of
429 : the *argv array must be NULL. Returns given config on success and
430 : NULL on failure (logs details). It is up to the caller to properly
431 : initialize the given limits/config. */
432 :
433 : FD_QUIC_API fd_quic_limits_t *
434 : fd_quic_limits_from_env( int * pargc,
435 : char *** pargv,
436 : fd_quic_limits_t * limits );
437 :
438 : FD_QUIC_API fd_quic_config_t *
439 : fd_quic_config_from_env( int * pargc,
440 : char *** pargv,
441 : fd_quic_config_t * config );
442 :
443 : /* fd_quic_get_aio_net_rx returns this QUIC's aio base class. Valid
444 : for lifetime of QUIC. While pointer to aio can be obtained before
445 : init, calls to aio may only be dispatched by the thread with
446 : exclusive access to QUIC that owns it. */
447 :
448 : FD_QUIC_API fd_aio_t const *
449 : fd_quic_get_aio_net_rx( fd_quic_t * quic );
450 :
451 : /* fd_quic_set_aio_net_tx sets the fd_aio_t used by the fd_quic_t to
452 : send tx data to the network driver. Cleared on fini. */
453 :
454 : FD_QUIC_API void
455 : fd_quic_set_aio_net_tx( fd_quic_t * quic,
456 : fd_aio_t const * aio_tx );
457 :
458 : /* fd_quic_set_clock sets the clock source. Converts all timing values
459 : in the config to the new time scale. */
460 :
461 : FD_QUIC_API void
462 : fd_quic_set_clock( fd_quic_t * quic,
463 : fd_quic_now_t now_fn,
464 : void * now_ctx,
465 : double tick_per_us );
466 :
467 : /* fd_quic_set_clock_tickcount sets fd_tickcount as the clock source. */
468 :
469 : FD_QUIC_API void
470 : fd_quic_set_clock_tickcount( fd_quic_t * quic );
471 :
472 : /* Initialization *****************************************************/
473 :
474 : /* fd_quic_init initializes the QUIC such that it is ready to serve.
475 : permits the calling thread exclusive access during which no other
476 : thread may write to the QUIC. Exclusive rights get released when the
477 : thread exits or calls fd_quic_fini.
478 :
479 : Requires valid configuration and external objects (aio, callbacks).
480 : Returns given quic on success and NULL on failure (logs details).
481 : Performs various heap allocations and file system accesses such
482 : reading certs. Reasons for failure include invalid config or
483 : fd_tls error. */
484 :
485 : FD_QUIC_API fd_quic_t *
486 : fd_quic_init( fd_quic_t * quic );
487 :
488 : /* fd_quic_fini releases exclusive access over a QUIC. Zero-initializes
489 : references to external objects (aio, callbacks). Frees any heap
490 : allocs made by fd_quic_init. Returns quic. */
491 :
492 : FD_QUIC_API fd_quic_t *
493 : fd_quic_fini( fd_quic_t * quic );
494 :
495 : /* NOTE: Calling any of the below requires valid initialization from
496 : this thread group. */
497 :
498 : /* Connection API *****************************************************/
499 :
500 : /* fd_quic_connect initiates a new client connection to a remote QUIC
501 : server. On success, returns a pointer to the conn object managed by
502 : QUIC. On failure, returns NULL. Reasons for failure include quic
503 : not a valid join or out of free conns. Lifetime of returned conn is
504 : until conn_final callback.
505 :
506 : args
507 : dst_ip_addr destination ip address
508 : dst_udp_port destination port number */
509 :
510 : FD_QUIC_API fd_quic_conn_t *
511 : fd_quic_connect( fd_quic_t * quic, /* requires exclusive access */
512 : uint dst_ip_addr,
513 : ushort dst_udp_port,
514 : uint src_ip_addr,
515 : ushort src_udp_port );
516 :
517 : /* fd_quic_conn_close asynchronously initiates a shutdown of the conn.
518 : The given reason code is returned to the peer via a CONNECTION_CLOSE
519 : frame, if possible. Causes conn_final callback to be issued
520 : eventually. */
521 :
522 : FD_QUIC_API void
523 : fd_quic_conn_close( fd_quic_conn_t * conn,
524 : uint reason );
525 :
526 : /* Service API ********************************************************/
527 :
528 : /* fd_quic_get_next_wakeup returns the next requested service time.
529 : This is only intended for unit tests. */
530 :
531 : FD_QUIC_API ulong
532 : fd_quic_get_next_wakeup( fd_quic_t * quic );
533 :
534 : /* fd_quic_service services the next QUIC connection, including stream
535 : transmit ops, ACK transmit, loss timeout, and idle timeout. The
536 : user should call service at high frequency. Returns 1 if the service
537 : call did any work, or 0 otherwise. */
538 :
539 : FD_QUIC_API int
540 : fd_quic_service( fd_quic_t * quic );
541 :
542 : /* fd_quic_svc_validate checks for violations of service queue and free
543 : list invariants, such as cycles in linked lists. Prints to warning/
544 : error log and exits the process if checks fail. Intended for use in
545 : tests. */
546 :
547 : void
548 : fd_quic_svc_validate( fd_quic_t * quic );
549 :
550 : /* Stream Send API ****************************************************/
551 :
552 : /* fd_quic_conn_new_stream creates a new unidirectional stream on the
553 : given conn. On success, returns the newly created stream.
554 : On failure, returns NULL. Reasons for failure include invalid conn
555 : state or out of stream quota.
556 :
557 : The user does not own the returned pointer: its lifetime is managed
558 : by the connection. */
559 :
560 : FD_QUIC_API fd_quic_stream_t *
561 : fd_quic_conn_new_stream( fd_quic_conn_t * conn );
562 :
563 : /* fd_quic_stream_send sends a chunk on a stream in order.
564 :
565 : Use fd_quic_conn_new_stream to create a new stream for sending
566 : or use the new stream callback to obtain a stream for replying.
567 :
568 : args
569 : stream the stream to send on
570 : data points to first byte of buffer (ignored if data_sz==0)
571 : data_sz number of bytes to send
572 : fin final: bool
573 : set to indicate the stream is finalized by the last byte
574 : in the batch
575 : If the last buffer in the batch was rejected, the FIN
576 : flag is not set, and may be applied in a future send
577 : or via the fd_quic_stream_fin(...) function
578 :
579 : returns
580 : 0 success
581 : <0 one of FD_QUIC_SEND_ERR_{INVAL_STREAM,INVAL_CONN,AGAIN} */
582 : FD_QUIC_API int
583 : fd_quic_stream_send( fd_quic_stream_t * stream,
584 : void const * data,
585 : ulong data_sz,
586 : int fin );
587 :
588 : /* fd_quic_stream_fin: finish sending on a stream. Called to signal
589 : no more data will be sent to self-to-peer flow of stream. Peer may
590 : continue sending data on their side of the stream. Caller should
591 : only call stream_fin once per stream, except when fin was already
592 : indicated via stream_send. */
593 :
594 : FD_QUIC_API void
595 : fd_quic_stream_fin( fd_quic_stream_t * stream );
596 :
597 : FD_QUIC_API void
598 : fd_quic_process_packet( fd_quic_t * quic,
599 : uchar * data,
600 : ulong data_sz );
601 :
602 : uint
603 : fd_quic_tx_buffered_raw( fd_quic_t * quic,
604 : uchar ** tx_ptr_ptr,
605 : uchar * tx_buf,
606 : ushort * ipv4_id,
607 : uint dst_ipv4_addr,
608 : ushort dst_udp_port,
609 : uint src_ipv4_addr,
610 : ushort src_udp_port );
611 :
612 : FD_PROTOTYPES_END
613 :
614 : /* Convenience exports for consumers of API */
615 : #include "fd_quic_conn.h"
616 : #include "fd_quic_stream.h"
617 :
618 : /* FD_DEBUG_MODE: set to enable debug-only code
619 : TODO move to util? */
620 : #ifdef FD_DEBUG_MODE
621 : #define FD_DEBUG(...) __VA_ARGS__
622 : #else
623 : #define FD_DEBUG(...)
624 : #endif
625 :
626 : #endif /* HEADER_fd_src_waltz_quic_fd_quic_h */
|