wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
negotiate.h
1#ifndef SALPN_NEGOTIATE_H
2#define SALPN_NEGOTIATE_H
3
6
7/* RFC 7301: server-side ALPN. The client offers a ProtocolNameList in its
8 * ALPN extension (extension_type 0x0010); the server picks one and echoes it
9 * in EncryptedExtensions. QUIC (RFC 9114) selects "h3". */
10
11#define SALPN_EXT_TYPE 0x0010
12
13/* Return 1 if the ProtocolNameList in alpn_ext_data (len bytes) offers "h3"
14 * (0x68 0x33), else 0 (absent, truncated, or a length field overruns). */
15int salpn_select_h3(const u8* alpn_ext_data, usz len);
16
17/* Return 1 if the ProtocolNameList in alpn_ext_data (len bytes) offers
18 * "hq-interop" (10 bytes), else 0 (absent, truncated, or a length field
19 * overruns). Same shape as salpn_select_h3, a second protocol id. */
20int salpn_select_hq(const u8* alpn_ext_data, usz len);
21
24typedef enum {
25 SALPN_NONE = 0,
26 SALPN_H3,
27 SALPN_HQ,
29 SALPN_RAW
30} salpn_choice;
31
32/* RFC 7301 3.1/3.2: pick a protocol from the client's ProtocolNameList
33 * (alpn_ext_data, len bytes) by this server's fixed preference order --
34 * h3 first, hq-interop second (quic-interop-runner's non-IETF HTTP/0.9
35 * ALPN id, see salpn_select_hq's doc). SALPN_NONE if the list
36 * offers neither (including an absent/malformed ALPN extension, len == 0
37 * or alpn_ext_data == 0) -- the caller then fails the handshake rather
38 * than falling back to a protocol the peer never offered. */
39salpn_choice salpn_negotiate(const u8* alpn_ext_data, usz len);
40
41/* Build the EncryptedExtensions ALPN extension selecting the outcome of
42 * salpn_negotiate: ext_type(2)=0x0010 ext_data_len(2) list_len(2)
43 * name_len(1) name. Writes into out (cap total), sets *out_len, returns 1;
44 * 0 if cap is too small or choice is SALPN_NONE (nothing to build --
45 * the caller must not have reached here with an unresolved negotiation). */
46int salpn_build_response(salpn_choice choice, u8* out, usz cap, usz* out_len);
47
54wired_span salpn_choice_name(salpn_choice choice, wired_span tok);
55
61int salpn_build_response_tok(wired_span name, wired_obuf* out);
62
63#endif
Value-type views that fold the SDK's recurring argument shapes into single parameters,...
Growing output buffer view for variable-length results.
Definition span.h:54
Read-only view of a byte range.
Definition span.h:30
Linux direct syscalls.
u64 usz
unsigned size (size_t equivalent)
Definition types.h:20
unsigned char u8
unsigned 8-bit integer / byte
Definition types.h:18