wired
libc-free QUIC/HTTP3 SDK in C for x86_64-linux
Loading...
Searching...
No Matches
dyntable.h
1#ifndef QPACK_DYNTABLE_H
2#define QPACK_DYNTABLE_H
3
4#include "app/qpack/qpack/field.h"
5
6/* RFC 9204 3.2. QPACK dynamic table: inserted (name, value) entries kept
7 * back to back in a byte ring the size of the largest capacity the table
8 * can be given, so the capacity is the only limit on an entry (3.2.2).
9 * Absolute indices grow from 0 with each insert; old entries are evicted
10 * when capacity is exceeded. No allocation, no libc. */
11
15#define QPACK_DYN_MAX_CAPACITY 2016
18#define QPACK_DYN_MAX_ENTRIES (QPACK_DYN_MAX_CAPACITY / 32)
19
27
31typedef struct {
35 u8 bytes[2 * QPACK_DYN_MAX_CAPACITY];
36 qpack_dyn_entry ring[QPACK_DYN_MAX_ENTRIES];
47} qpack_dyn;
48
49/* RFC 9204 3.2. Initialise an empty table with the given byte capacity
50 * (clamped to QPACK_DYN_MAX_CAPACITY). */
51void qpack_dyn_init(qpack_dyn* t, usz capacity);
52
53/* RFC 9204 3.2 / 3.2.1. Insert the (name, value) pair, evicting oldest
54 * entries as needed to fit. Returns 1 on success, 0 if the entry cannot fit
55 * even in an empty table. f must not view this table's own bytes: copy a
56 * referenced entry out first, since eviction may reuse them. */
57int qpack_dyn_insert(qpack_dyn* t, const qpack_field* f);
58
59/* RFC 9204 3.2. Borrowed views of the live entry `off` places after the
60 * oldest (off < t->count); valid until the next insert. */
61void qpack_dyn_entry_at(const qpack_dyn* t, usz off, qpack_field* out);
62
63/* RFC 9204 3.2.1. Current total size in bytes. */
64usz qpack_dyn_size(const qpack_dyn* t);
65
66/* RFC 9204 3.2.2. Apply a new dynamic table capacity from a received Set
67 * Dynamic Table Capacity instruction (Section 4.3.1) once it has already
68 * passed qpack_capacity_within_limit: evicts entries from the end of
69 * the table until its size is at most new_capacity (a no-op if the
70 * capacity is being raised, or set to 0 to clear the table entirely).
71 * Clamped to QPACK_DYN_MAX_CAPACITY. */
72void qpack_dyn_set_capacity(qpack_dyn* t, usz new_capacity);
73
74/* RFC 9204 4.3.1. A received Set Dynamic Table Capacity instruction's value is
75 * valid only up to the limit the server advertised in
76 * SETTINGS_QPACK_MAX_TABLE_CAPACITY. Returns 1 if capacity is within that
77 * limit, 0 if it exceeds it -- the caller treats 0 as a connection error of
78 * type QPACK_ENCODER_STREAM_ERROR. */
79int qpack_capacity_within_limit(u64 capacity, u64 max_table_capacity);
80
81#endif
RFC 9204 3.2.
Definition dyntable.h:22
u16 name_len
name bytes
Definition dyntable.h:24
u16 off
byte ring offset of the name's first byte
Definition dyntable.h:23
u16 value_len
value bytes, right after the name
Definition dyntable.h:25
RFC 9204 3.2.
Definition dyntable.h:31
usz count
number of live entries
Definition dyntable.h:38
qpack_dyn_entry ring[QPACK_DYN_MAX_ENTRIES]
live entry positions
Definition dyntable.h:36
usz tail
byte ring offset of the next entry
Definition dyntable.h:39
usz head
ring slot of the oldest live entry
Definition dyntable.h:37
u64 dropped
absolute index of the oldest live entry
Definition dyntable.h:40
u8 bytes[2 *QPACK_DYN_MAX_CAPACITY]
Entry bytes; ring byte i is stored at both i and i + QPACK_DYN_MAX_CAPACITY, so an entry that runs pa...
Definition dyntable.h:35
u64 max_capacity
RFC 9204 4.5.1.1: the decoder's advertised maximum capacity, the MaxEntries base for Required Insert ...
Definition dyntable.h:46
usz size
sum of entry sizes (RFC 9204 3.2.1)
Definition dyntable.h:41
usz capacity
maximum allowed size in bytes
Definition dyntable.h:42
A QPACK field line's (name, value) pair as borrowed views (encoder input / decoder table lookups).
Definition field.h:8
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