wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
srvrun.h
Go to the documentation of this file.
1#ifndef WIRED_SRVRUN_SRVRUN_H
2#define WIRED_SRVRUN_SRVRUN_H
3
8#include "app/qpack/qpack/field.h"
11
15
24
32typedef void (*wired_wt_on_datagram)(
33 void* app_ctx, wired_wt_session* s, wired_span data);
34
45 void* app_ctx,
47 u64 stream_id,
48 wired_span data,
49 int fin);
50
67 void* app_ctx,
69 u64 stream_id,
70 int mapped,
71 u32 app_error_code);
72
82typedef void (*wired_wt_on_session)(
83 void* app_ctx, wired_wt_session* s, wired_span path, wired_span protocol);
84
96typedef void (*wired_wt_on_session_close)(void* app_ctx, wired_wt_session* s);
97
106 void* app_ctx, wired_wt_session* s);
107
119typedef void (*wired_rawq_on_session)(
120 void* app_ctx, wired_wt_session* s, wired_span alpn);
121
139
150 void* app_ctx,
151 wired_span authority,
152 wired_span path,
154
158typedef void (*wired_srvrun_on_step)(void* ctx, u64 now_ms);
159
161#define WIRED_HTTP_MAX_FIELDS 8
162
167
205
209#define WIRED_HTTP_FIELD_BYTES_MAX 384
210
217typedef int (*wired_http_handler)(void* ctx, wired_http_exchange* x);
218
245
251typedef struct {
252 const char* qlog_path;
253 const char* keylog_path;
254 const char* cert_path;
255 const char* key_path;
263
299 u16 port,
302 wired_srvrun_obs obs);
303
426
440 u16 port,
444 const wired_srvrun_opt* opt);
445
450
454
463
469 const wired_srvrun_env* env, wired_srvrun_wt_usage* out);
470
486 wired_srvrun_env* env,
487 u16 port,
491 const wired_srvrun_opt* opt);
492
507
535
564
583
590
602 wired_wt_session* s, u64 stream_id, wired_span payload);
603
613
621
630 wired_wt_session* s, u64 stream_id, wired_span payload);
631
654 wired_wt_session* s, u64 stream_id, wired_span payload, int fin);
655
667 wired_wt_session* s, u64 stream_id, u8 urgency);
668
686
699 wired_wt_session* s, u64 stream_id, const wired_wt_sched* k);
700
709
727
747
769 wired_wt_session* s, u64 stream_id, u32 error_code);
770
785 wired_wt_session* s, u64 stream_id, u32 error_code);
786
797
813
834 wired_wt_session* s, u32 app_error_code, wired_span message);
835
847
859
870
876
896 int index,
897 int n_total,
898 wired_srvinbox_ring* inbox_row,
899 wired_srvrun_env* env);
900
905
906#endif
draft-ietf-webtrans-http3-15 SS4: the WebTransport session state machine, independent of any specific...
RFC 9000 17.2 / RFC 9001 5 / RFC 8446 4.4: cold-start a server connection from a client Initial datag...
SPSC ring for worker-to-worker broadcast handoff.
RFC 9001 4 / 5 / RFC 9000 17.2: the socket-free core of the server wire loop.
int(* wired_srvloop_on_body)(void *ctx, const wired_h3reqdrive_req *req, u64 stream_id, wired_span chunk, int fin)
Receive a request body as it streams in (RFC 9114 4.1), instead of having it buffered whole into req'...
Definition srvloop.h:101
int(* wired_srvloop_handler)(void *ctx, const wired_h3reqdrive_req *req, u64 offset, wired_obuf *body_out, const char **content_type, int *more, u64 *total_size)
Build (a round of) the response body for a decoded request.
Definition srvloop.h:72
u64 wired_server_wt_est_kbps(wired_wt_session *s)
The connection's current delivery-rate estimate for s, in kbps: BBR's bottleneck bandwidth once it ha...
i64 wired_server_wt_open_uni_stream(wired_wt_session *s, wired_span payload)
Same as wired_server_wt_open_uni, but WITHOUT closing the stream: no FIN is sent after payload's fina...
int wired_server_broadcast_datagram_ring(wired_span data)
Queue one HTTP Datagram (RFC 9297) to EVERY active WebTransport session in the caller's server loop –...
int wired_server_wt_stream_hold(wired_wt_session *s, u64 stream_id, int hold)
Hold or release the receive flow-control credit of a client-initiated stream (RFC 9000 4....
int wired_server_wt_stream_stop(wired_wt_session *s, u64 stream_id, u32 error_code)
Asks the peer to stop sending on a PEER-initiated stream: queues one STOP_SENDING (RFC 9000 19....
qpack_field wired_http_field
One response header field line: lowercase name and value views (RFC 9114 4.2).
Definition srvrun.h:166
i64 wired_server_wt_open_uni(wired_wt_session *s, wired_span payload)
Open a new server-initiated unidirectional stream on s's connection (RFC 9000 2.1: id 3 mod 4) and se...
i64 wired_server_wt_open_bidi_stream(wired_wt_session *s, wired_span payload)
Same as wired_server_wt_open_uni_stream, but a server-initiated bidirectional stream (RFC 9000 2....
void wired_srvrun_broadcast_register(int index, int n_total, wired_srvinbox_ring *inbox_row, wired_srvrun_env *env)
Register the calling thread as srvthreads worker index of n_total, with its own N-ring inbox row (inb...
#define WIRED_HTTP_MAX_FIELDS
Most response header fields one wired_http_handler round may set.
Definition srvrun.h:161
int wired_server_wt_stream_reply_open(wired_wt_session *s, u64 stream_id, wired_span payload)
Same as wired_server_wt_stream_reply, but WITHOUT closing the stream – the opening round of a reply o...
void(* wired_wt_on_stream_data)(void *app_ctx, wired_wt_session *s, u64 stream_id, wired_span data, int fin)
draft-ietf-webtrans-http3-15 4.3: app-facing delivery of one reassembled chunk of a WebTransport bidi...
Definition srvrun.h:44
int * wired_srvrun_shutdown_word(void)
The process-wide graceful-shutdown word (RFC 9114 5.2): 0 until a shutdown is requested,...
void(* wired_wt_on_session)(void *app_ctx, wired_wt_session *s, wired_span path, wired_span protocol)
WebTransport subprotocol negotiation (draft-ietf-webtrans-http3-15 SS3.4): app-facing notification th...
Definition srvrun.h:82
int wired_server_wt_stream_priority(wired_wt_session *s, u64 stream_id, u8 urgency)
Set the send urgency of a server-sent stream that still holds its send slot (RFC 9218 2....
int wired_srvrun_serve_env(wired_srvrun_env *env, u16 port, wired_srvboot_id *id, wired_srvrun_handler h, wired_srvrun_obs obs, const wired_srvrun_opt *opt)
Same as wired_server_run_opt, but driven off caller-owned env instead of the SDK's single process-wid...
void(* wired_srvrun_on_step)(void *ctx, u64 now_ms)
Per-step application hook (wired_srvrun_opt.on_step).
Definition srvrun.h:158
void(* wired_wt_on_session_close)(void *app_ctx, wired_wt_session *s)
App-facing notification that a WebTransport session ended server-side: its own CONNECT stream closed,...
Definition srvrun.h:96
int wired_server_wt_stream_fin(wired_wt_session *s, u64 stream_id)
Ends a stream opened for appending with NO further bytes: a bare FIN on an otherwise-empty final roun...
int wired_server_run(u16 port, wired_srvboot_id *id, wired_srvrun_handler h, wired_srvrun_obs obs)
The complete server event loop: bind a UDP socket on port, then forever receive datagrams and drive t...
int wired_server_wt_stream_reset(wired_wt_session *s, u64 stream_id, u32 error_code)
Abort a stream opened for appending: queue a standard RESET_STREAM (RFC 9000 19.4) on stream_id carry...
void(* wired_rawq_on_session)(void *app_ctx, wired_wt_session *s, wired_span alpn)
draft-ietf-moq-transport-19 3.1.5 / -22 6.2.2 (native QUIC): app-facing notification that a raw-QUIC ...
Definition srvrun.h:119
int wired_server_run_opt(u16 port, wired_srvboot_id *id, wired_srvrun_handler h, wired_srvrun_obs obs, const wired_srvrun_opt *opt)
Same as wired_server_run, plus opt-in polling-driver behavior.
int wired_server_wt_stream_send(wired_wt_session *s, u64 stream_id, wired_span payload, int fin)
Append one more round of bytes to a stream opened with wired_server_wt_ open_uni_stream/open_bidi_str...
void wired_srvrun_env_wt_usage(const wired_srvrun_env *env, wired_srvrun_wt_usage *out)
Snapshot env's WebTransport usage counters into *out.
int wired_server_wt_close_session(wired_wt_session *s, u32 app_error_code, wired_span message)
draft-ietf-webtrans-http3-15 SS4.2/SS4.4/8.2 (WTH3-067): close s's WebTransport session: send a WT_CL...
int wired_server_session_is_raw(wired_wt_session *s)
1 when s is the implicit session of a raw-QUIC application connection (wired_rawq_on_session),...
int(* wired_http_handler)(void *ctx, wired_http_exchange *x)
Build (a round of) the response for a decoded request: like wired_srvloop_handler,...
Definition srvrun.h:217
int wired_server_wt_stream_inflight(wired_wt_session *s, u64 stream_id)
1 while a send slot on s's connection still holds stream_id – its bytes not yet fully acknowledged,...
int wired_server_wt_send_datagram_to(wired_wt_session *s, wired_span payload)
Queue one HTTP Datagram (RFC 9297) to this session's peer: the SDK prefixes the quarter-stream-id var...
void wired_srvrun_broadcast_unregister(void)
Unregister the calling thread's broadcast registry entry (symmetric with wired_srvrun_broadcast_regis...
void(* wired_wt_on_stream_reset)(void *app_ctx, wired_wt_session *s, u64 stream_id, int mapped, u32 app_error_code)
draft-ietf-webtrans-http3-15 4.4 (WTH3-040): app-facing delivery of a RESET_STREAM/STOP_SENDING recei...
Definition srvrun.h:66
int wired_server_wt_occupancy(wired_wt_occupancy *out)
Snapshot the calling loop's WebTransport occupancy into *out.
void(* wired_wt_on_datagram)(void *app_ctx, wired_wt_session *s, wired_span data)
draft-ietf-webtrans-http3-15 SS4: app-facing delivery of one received QUIC DATAGRAM (RFC 9221 5) asso...
Definition srvrun.h:32
int wired_server_broadcast_datagram(wired_span data)
RFC 9221 5 / draft-ietf-webtrans-http3-15 SS4: broadcast data as a QUIC DATAGRAM to every connection ...
int wired_server_wt_stream_schedule(wired_wt_session *s, u64 stream_id, const wired_wt_sched *k)
Set a server-sent stream's full send class (see wired_wt_sched).
i64 wired_server_wt_open_bidi(wired_wt_session *s, wired_span payload)
Same as wired_server_wt_open_uni, but a server-initiated bidirectional stream (RFC 9000 2....
struct wired_srvrun_env wired_srvrun_env
Opaque: one server loop instance's mutable state (connection table, response/rx storage,...
Definition srvrun.h:23
usz wired_srvrun_env_size(void)
Byte size of one wired_srvrun_env instance, for a caller allocating one (statically,...
void(* wired_wt_resource_check)(void *app_ctx, wired_span authority, wired_span path, wired_wt_resource_decision *out)
draft-ietf-webtrans-http3-15 SS3.2: app-facing resource lookup for one Extended CONNECT,...
Definition srvrun.h:149
int wired_server_wt_drain_session(wired_wt_session *s)
draft-ietf-webtrans-http3-15 4.7: ask the peer to wind s down by sending a WT_DRAIN_SESSION capsule o...
void(* wired_wt_on_session_draining)(void *app_ctx, wired_wt_session *s)
draft-ietf-webtrans-http3-15 4.7: the peer sent WT_DRAIN_SESSION on s's CONNECT stream – an advisory ...
Definition srvrun.h:105
int wired_server_wt_stream_reply(wired_wt_session *s, u64 stream_id, wired_span payload)
Send payload on this endpoint's send direction of the client-initiated bidirectional stream stream_id...
void wired_srvrun_env_init(wired_srvrun_env *env)
Zero-initialize env (its connection table, response/rx storage, and pacing scratch) before its first ...
AF_XDP driver integration for the HTTP/3 server: opens one AF_XDP socket plus its BPF redirect filter...
A QPACK field line's (name, value) pair as borrowed views (encoder input / decoder table lookups).
Definition field.h:8
RFC 9114 4.1 / 4.3.1, RFC 9204 4.5: recovered request pseudo-headers.
Definition request_drive.h:69
One request/response exchange handed to a wired_http_handler.
Definition srvrun.h:183
wired_obuf * body
receives this round's response body bytes (see wired_srvloop_handler)
Definition srvrun.h:190
u64 offset
response body bytes already delivered by prior rounds
Definition srvrun.h:187
u16 status
response status; 0 means 200 (first round only)
Definition srvrun.h:192
usz field_count
entries used in fields
Definition srvrun.h:198
const char * content_type
static NUL-terminated content-type, or 0 to omit (first round only)
Definition srvrun.h:194
wired_http_field fields[WIRED_HTTP_MAX_FIELDS]
extra response header fields, in order (first round only)
Definition srvrun.h:196
u64 total_size
full body length if known, first round only (see wired_srvloop_handler)
Definition srvrun.h:203
const wired_h3reqdrive_req * req
the decoded request; its views are not valid past the call
Definition srvrun.h:185
int more
set to 1 to request another round (see wired_srvloop_handler)
Definition srvrun.h:200
Growing output buffer view for variable-length results.
Definition span.h:54
Read-only view of a byte range.
Definition span.h:30
The fixed server identity a bootstrap needs: the X25519 handshake key pair, the ECDSA P-256 signing s...
Definition srvboot.h:23
A single-producer/single-consumer ring of depth WIRED_SRVINBOX_DEPTH.
Definition srvinbox.h:46
The application's request responder: the callback and its opaque context, registered on the loop as a...
Definition srvrun.h:234
wired_http_handler http
status- and header-aware responder; when set it is used instead of cb (0 keeps cb)
Definition srvrun.h:239
void * ctx
opaque context passed back to cb / http
Definition srvrun.h:236
wired_srvloop_on_body on_body
streams each request body here before the responder runs (see wired_srvloop_on_body for the sequencin...
Definition srvrun.h:243
wired_srvloop_handler cb
the response-body builder callback
Definition srvrun.h:235
Optional debug-log file paths, each 0 to disable (the default): a qlog (RFC 9002-shaped packet_sent/p...
Definition srvrun.h:251
const char * keylog_path
NSS key log file path, or 0 to disable.
Definition srvrun.h:253
const char * key_path
key.pem path, or 0 to disable SIGHUP reload
Definition srvrun.h:255
int cc_algo
CC_ALGO_* for fresh connections.
Definition srvrun.h:261
const char * qlog_path
qlog file path, or 0 to disable
Definition srvrun.h:252
const char * cert_path
cert.pem path, or 0 to disable SIGHUP reload
Definition srvrun.h:254
Opt-in polling-driver knobs, both off (0) by default so wired_server_run's behavior is unchanged.
Definition srvrun.h:306
wired_srvxdp * xdp
0 (the default) = unchanged UDP socket path; non-0 = an already-open AF_XDP driver (wired_srvxdp_open...
Definition srvrun.h:339
void * raw_session_ctx
opaque ctx passed to raw_on_session
Definition srvrun.h:424
void * wt_resource_ctx
opaque ctx passed to wt_resource_check
Definition srvrun.h:382
wired_wt_on_session wt_on_session
Session-established notification, 0 to disable (the default) – called once per accepted Extended CONN...
Definition srvrun.h:363
void * wt_origin_ctx
opaque ctx passed to wt_origin_check
Definition srvrun.h:414
void * wt_session_draining_ctx
opaque ctx passed to it
Definition srvrun.h:418
int no_signal_handlers
0 (the default) = install SIGTERM/SIGHUP as wired_server_run always has; 1 = skip signal installation...
Definition srvrun.h:344
int so_busy_poll_us
>0: also enable SO_BUSY_POLL (microseconds).
Definition srvrun.h:308
void * wt_session_close_ctx
opaque ctx passed to wt_on_session_close
Definition srvrun.h:395
const char * wt_protocols
WebTransport subprotocol negotiation (draft-ietf-webtrans-http3-15 SS3.4): the server's own supported...
Definition srvrun.h:358
wired_wt_on_stream_data wt_on_stream_data
draft-ietf-webtrans-http3-15 4.3: app-facing WebTransport bidi/uni stream-data delivery,...
Definition srvrun.h:321
wired_wt_on_datagram wt_on_datagram
draft-ietf-webtrans-http3-15 SS4: app-facing WebTransport datagram delivery, 0 to disable (the defaul...
Definition srvrun.h:315
int force_retry
RFC 9000 8.1.2: 1 = answer every tokenless Initial with a stateless Retry and only accept Initials pr...
Definition srvrun.h:375
int so_prefer_busy_poll
0 = disabled (default); 1 = also enable SO_PREFER_BUSY_POLL (requires so_busy_poll_us > 0 to have ker...
Definition srvrun.h:323
int core_id
AF_XDP multi-queue core-routing: -1 = disabled (the default, a dedicated sentinel like incoming_cpu s...
Definition srvrun.h:352
wired_srvrun_on_step on_step
Per-step application hook, 0 to disable (the default): called once per event-loop step after that ste...
Definition srvrun.h:404
wired_rawq_on_session raw_on_session
Raw-QUIC implicit-session notification, 0 to disable (the default).
Definition srvrun.h:422
int(* wt_origin_check)(void *ctx, wired_span origin, wired_span authority)
draft-ietf-webtrans-http3-15 SS3.1 / RFC 6454: app-facing Origin verdict for one WebTransport Extende...
Definition srvrun.h:413
wired_wt_on_session_close wt_on_session_close
Session-ended notification, 0 to disable (the default) – called once per WT session when it ends serv...
Definition srvrun.h:394
void * wt_datagram_ctx
opaque ctx passed to wt_on_datagram
Definition srvrun.h:316
int so_busy_poll_budget
Definition srvrun.h:326
void * on_step_ctx
opaque ctx passed to on_step
Definition srvrun.h:405
wired_wt_on_session_draining wt_on_session_draining
Peer WT_DRAIN_SESSION notification, 0 to disable (the default, which consumes the capsule silently).
Definition srvrun.h:417
wired_wt_resource_check wt_resource_check
draft-ietf-webtrans-http3-16 SS3.2: app-facing :authority/:path resource lookup, 0 to disable (the de...
Definition srvrun.h:381
int incoming_cpu
SET direction only.
Definition srvrun.h:333
void * wt_session_ctx
opaque ctx passed to wt_on_session
Definition srvrun.h:364
wired_wt_on_stream_reset wt_on_stream_reset
draft-ietf-webtrans-http3-15 4.4 (WTH3-040): app-facing WT stream-reset delivery, 0 to disable (the d...
Definition srvrun.h:387
int busy_poll
1: MSG_DONTWAIT spin loop instead of blocking poll(2)
Definition srvrun.h:307
void * wt_stream_reset_ctx
opaque ctx passed to wt_on_stream_reset
Definition srvrun.h:388
void * wt_stream_data_ctx
opaque ctx passed to wt_on_stream_data
Definition srvrun.h:322
draft-ietf-webtrans-http3-15 SS8: WebTransport feature-usage totals for one env, monotonic since wire...
Definition srvrun.h:458
u64 datagrams
HTTP Datagrams received for a session.
Definition srvrun.h:461
u64 sessions
Extended CONNECT sessions established.
Definition srvrun.h:459
u64 streams
incoming WT bidi/uni streams offered to a session
Definition srvrun.h:460
One open AF_XDP driver instance: the socket/rings, the TX frame pool, the learned peer MAC cache,...
Definition srvxdp.h:33
Current WebTransport occupancy of the server loop the caller runs in, against the compile-time capaci...
Definition srvrun.h:864
usz peer_streams_cap
most such streams the server holds at once
Definition srvrun.h:868
usz sessions_cap
most sessions the server holds at once
Definition srvrun.h:866
usz sessions
WT sessions open now, across all connections.
Definition srvrun.h:865
usz peer_streams
client-opened WT bidi/uni streams open now
Definition srvrun.h:867
draft-ietf-webtrans-http3-16 SS3.2 (WTH3-016/WTH3-018): the app's verdict for one Extended CONNECT's ...
Definition srvrun.h:134
u16 status
0 = accept; else the status to send instead
Definition srvrun.h:135
usz location_len
bytes at location
Definition srvrun.h:137
const u8 * location
Location header value, only for a 3xx status.
Definition srvrun.h:136
A server-sent stream's send class and its place inside a flow, set by wired_server_wt_stream_schedule...
Definition srvrun.h:672
u64 flow
Streams sharing a nonzero flow and class send in (order, tie) order, lowest first; 0 opts out (every ...
Definition srvrun.h:680
u8 urgency
RFC 9218 2.1 urgency, 0..7, lower first.
Definition srvrun.h:674
u16 fine
Second class key inside one urgency, lower first (the MoQT hub packs Subscriber Priority << 8 | Publi...
Definition srvrun.h:677
u64 order
Rank inside the flow, compared before tie.
Definition srvrun.h:682
u64 tie
Rank between equal orders inside the flow.
Definition srvrun.h:684
A WebTransport session.
Definition session.h:77
unsigned int u32
unsigned 32-bit integer
Definition types.h:15
long i64
signed 64-bit integer
Definition types.h:14
u64 usz
unsigned size (size_t equivalent)
Definition types.h:20
unsigned short u16
unsigned 16-bit integer
Definition types.h:17
unsigned char u8
unsigned 8-bit integer / byte
Definition types.h:18
unsigned long u64
unsigned 64-bit integer
Definition types.h:13
draft-ietf-webtrans-http3-15 SS4.2/SS5.6: the WebTransport-specific capsule types layered on top of t...