@amritk/nish-aarch64-linux 0.35.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
package/std/net/http3-server.ts
CHANGED
|
@@ -4,24 +4,46 @@
|
|
|
4
4
|
* it, a `QuicListener` in front for the datagrams no slot owns, for a
|
|
5
5
|
* program that owns its readiness loop.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* const
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
7
|
+
* import { pollAdd, pollCreate, pollWait, udpBind } from "nish:net";
|
|
8
|
+
* import { monotonicNanos } from "nish:process";
|
|
9
|
+
* import { secret, wipe } from "nish:secret";
|
|
10
|
+
* import { H3_ERROR, H3_NEED_MORE, Http3Config, Http3Connection } from "nish/net/http3";
|
|
11
|
+
* import { Http3Server } from "nish/net/http3-server";
|
|
12
|
+
* import { QuicServerConfig } from "nish/net/quic";
|
|
13
|
+
* import { QUIC_LISTENER_ENTROPY_SIZE } from "nish/net/quic-listener";
|
|
14
|
+
*
|
|
15
|
+
* // `quicConfig.alpn` is ["h3"]; `privateKey` is the P-256 key of its certificate.
|
|
16
|
+
* const run = (quicConfig: QuicServerConfig, privateKey: u8[], rounds: i32): void => {
|
|
17
|
+
* const fd: i32 = udpBind("0.0.0.0", 4433, 0);
|
|
18
|
+
* const listenerEntropy: u8[] = new Array<u8>(QUIC_LISTENER_ENTROPY_SIZE);
|
|
19
|
+
* crypto.getRandomValues(listenerEntropy);
|
|
20
|
+
* const server = new Http3Server(quicConfig, new Http3Config(), fd, 64, listenerEntropy);
|
|
21
|
+
* const loop: i32 = pollCreate();
|
|
22
|
+
* pollAdd(loop, fd, 1, 0);
|
|
23
|
+
* const ready: i32[] = new Array<i32>(8);
|
|
24
|
+
* const key = secret(privateKey);
|
|
25
|
+
* for (let round: i32 = 0; round < rounds; round++) {
|
|
26
|
+
* pollWait(loop, ready, server.timeout(monotonicNanos() / 1000000));
|
|
27
|
+
* const nanos: i64 = monotonicNanos();
|
|
28
|
+
* const now: i64 = nanos / 1000000; // milliseconds
|
|
29
|
+
* server.clock(nanos / 1000); // the same instant in microseconds, for the pacer
|
|
30
|
+
* server.receive(now, key); // every datagram waiting; signs handshakes with `key`
|
|
31
|
+
* server.tick(now); // the connections' timers
|
|
32
|
+
* let slot: i32 = server.ready();
|
|
33
|
+
* while (slot >= 0) {
|
|
34
|
+
* const h3: Http3Connection = server.connection(slot);
|
|
35
|
+
* let event: i32 = h3.next();
|
|
36
|
+
* while (event !== H3_NEED_MORE && event !== H3_ERROR) {
|
|
37
|
+
* // answer the event here: `h3.stream`, `h3.fields`, `h3.respond`, ...
|
|
38
|
+
* event = h3.next();
|
|
39
|
+
* }
|
|
40
|
+
* slot = server.ready();
|
|
41
|
+
* }
|
|
42
|
+
* server.flush(now); // what every touched slot has to send
|
|
43
|
+
* }
|
|
44
|
+
* wipe(key);
|
|
45
|
+
* server.stop(); // releases every slot, wipes the static keys
|
|
46
|
+
* };
|
|
25
47
|
*
|
|
26
48
|
* **Routing.** A datagram goes to the slot that owns its first packet's
|
|
27
49
|
* Destination Connection ID, found through a hash index of every slot's
|
|
@@ -43,19 +65,19 @@
|
|
|
43
65
|
* GSO where the platform has it and one datagram at a time where it does not.
|
|
44
66
|
* Each flight goes with the ECN codepoint its connection marked it with
|
|
45
67
|
* (`QuicFlight.ecn`, RFC 9000 §13.4), so the peer's ACK_ECN counts are
|
|
46
|
-
* validated and a CE mark shrinks the window. Where the platform sends no
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* one
|
|
52
|
-
*
|
|
53
|
-
* round trip is under a millisecond it
|
|
54
|
-
* millisecond to earn credit nor holds a slot back
|
|
55
|
-
* `clock` it counts whole milliseconds.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
68
|
+
* validated and a CE mark shrinks the window. Where the platform sends no ECN
|
|
69
|
+
* (Darwin, whose `udpSendTo` answers -95 to a marked send), the first marked
|
|
70
|
+
* send goes again unmarked and no slot marks after it.
|
|
71
|
+
*
|
|
72
|
+
* A -95 is also what a platform without segmentation offload answers, so a
|
|
73
|
+
* refused GSO send goes again one datagram at a time, still marked, and only a
|
|
74
|
+
* -95 to one of those turns marking off. The pacer counts the microseconds
|
|
75
|
+
* `clock` gives it, so on a path whose round trip is under a millisecond it
|
|
76
|
+
* neither waits for the next millisecond to earn credit nor holds a slot back
|
|
77
|
+
* for a whole one; without `clock` it counts whole milliseconds. A slot whose
|
|
78
|
+
* HTTP/3 side sent GOAWAY and whose requests have all finished, every byte
|
|
79
|
+
* acknowledged, is closed with H3_NO_ERROR; a closed slot is freed once its
|
|
80
|
+
* CONNECTION_CLOSE is out.
|
|
59
81
|
*
|
|
60
82
|
* **Timers** are a wheel of `H3_SERVER_WHEEL` one-millisecond buckets, a
|
|
61
83
|
* slot in at most one: after every datagram and every flush the slot is filed
|
|
@@ -66,15 +88,16 @@
|
|
|
66
88
|
*
|
|
67
89
|
* **Caps, fixed at start-up**: the slots, and inside each the QUIC
|
|
68
90
|
* configuration's streams and buffers and the `Http3Config`'s field section,
|
|
69
|
-
* body chunk and DATA frame.
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
91
|
+
* body chunk and DATA frame.
|
|
92
|
+
*
|
|
93
|
+
* A slot's connections and address are built on the first Initial accepted into
|
|
94
|
+
* it and kept, so a pool sized for its peak costs at start-up only its per-slot
|
|
95
|
+
* tables (the index, the wheel, the queues), and holds at most `size`
|
|
96
|
+
* connections once the peak has come; a datagram an established connection
|
|
97
|
+
* reads, and every datagram it sends, allocates nothing; nor does a datagram no
|
|
98
|
+
* slot owns, which the listener reads where it lies and answers into scratch
|
|
99
|
+
* made once, nor a handshake into a slot built before, whose state is the
|
|
100
|
+
* slot's — `docs/security/http3.md` (H3-1, H3-3).
|
|
78
101
|
*
|
|
79
102
|
* **The Date.** Every response carries one `date` field (RFC 9110 §6.6.1)
|
|
80
103
|
* from the pool's `HttpDate`, which formats the IMF-fixdate at most once a
|
|
@@ -123,8 +146,12 @@ export const H3_SERVER_WHEEL: i32 = 2048
|
|
|
123
146
|
/** The most datagrams one `receive` reads, so one busy socket cannot hold the loop. */
|
|
124
147
|
export const H3_SERVER_RECEIVE_BURST: i32 = 256
|
|
125
148
|
|
|
126
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* The answer budget's size: how many datagrams no slot owns that could get a stateless reset or a Version
|
|
151
|
+
* Negotiation packet may reach the listener at once.
|
|
152
|
+
*/
|
|
127
153
|
export const H3_SERVER_ANSWER_BURST: i32 = 16
|
|
154
|
+
/** The milliseconds that earn the answer budget one more, up to `H3_SERVER_ANSWER_BURST`. */
|
|
128
155
|
export const H3_SERVER_ANSWER_INTERVAL: i64 = 100
|
|
129
156
|
|
|
130
157
|
/** The address form `nish:net` reads and writes. */
|
|
@@ -155,18 +182,26 @@ const H3_SERVER_BUSY: i32 = 1
|
|
|
155
182
|
const http3ServerBucket = (time: i64): i32 => toI32(time % toI64(H3_SERVER_WHEEL))
|
|
156
183
|
|
|
157
184
|
/**
|
|
158
|
-
* The connection IDs of every slot, by hash: open
|
|
159
|
-
* `
|
|
160
|
-
*
|
|
185
|
+
* The connection IDs of every slot, by hash: an open-addressed table keyed
|
|
186
|
+
* with `salt`, each ID copied into the entry it was filed as. Each slot has
|
|
187
|
+
* `QUIC_CONN_LOCAL_CIDS + 1` entries, slot `s`'s from
|
|
188
|
+
* `s * (QUIC_CONN_LOCAL_CIDS + 1)` up: its local connection IDs, then the
|
|
189
|
+
* client's original DCID. The table has at least twice as many places as
|
|
190
|
+
* entries, so it never fills.
|
|
161
191
|
*/
|
|
162
192
|
export class Http3CidIndex {
|
|
163
|
-
table: i32[]
|
|
193
|
+
private table: i32[]
|
|
164
194
|
/** Entry `e`'s ID is `keys[e * 20 .. e * 20 + lengths[e])`; a length of 0 is no entry. */
|
|
165
|
-
keys: u8[]
|
|
166
|
-
lengths: i32[]
|
|
195
|
+
private keys: u8[]
|
|
196
|
+
private lengths: i32[]
|
|
167
197
|
/** The hash's key: eight bytes from the listener's entropy. */
|
|
168
198
|
salt: u8[]
|
|
169
199
|
|
|
200
|
+
/**
|
|
201
|
+
* An empty index for `slots` slots.
|
|
202
|
+
* @param slots How many slots it files IDs for, each `QUIC_CONN_LOCAL_CIDS + 1` entries.
|
|
203
|
+
* @param salt The hash's key: its first eight bytes are copied (zeros past a shorter one); not kept.
|
|
204
|
+
*/
|
|
170
205
|
constructor(slots: i32, salt: u8[]) {
|
|
171
206
|
const entries: i32 = slots * H3_SERVER_KEYS
|
|
172
207
|
let size: i32 = 8
|
|
@@ -183,7 +218,7 @@ export class Http3CidIndex {
|
|
|
183
218
|
}
|
|
184
219
|
|
|
185
220
|
/** The bucket the ID `buf[at .. at + length)` starts its probe at. */
|
|
186
|
-
bucket(buf: u8[], at: i32, length: i32): i32 {
|
|
221
|
+
private bucket(buf: u8[], at: i32, length: i32): i32 {
|
|
187
222
|
let h: i64 = toI64(length)
|
|
188
223
|
for (let k: i32 = 0; k < length && at + k >= 0 && at + k < toI32(buf.length); k++) {
|
|
189
224
|
const j: i32 = k & 7
|
|
@@ -195,7 +230,7 @@ export class Http3CidIndex {
|
|
|
195
230
|
}
|
|
196
231
|
|
|
197
232
|
/** Whether entry `e` holds the ID `buf[at .. at + length)`. */
|
|
198
|
-
holds(e: i32, buf: u8[], at: i32, length: i32): boolean {
|
|
233
|
+
private holds(e: i32, buf: u8[], at: i32, length: i32): boolean {
|
|
199
234
|
if (e < 0 || e >= toI32(this.lengths.length) || this.lengths[e] !== length) {
|
|
200
235
|
return false
|
|
201
236
|
}
|
|
@@ -208,7 +243,13 @@ export class Http3CidIndex {
|
|
|
208
243
|
return true
|
|
209
244
|
}
|
|
210
245
|
|
|
211
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* The slot owning the ID `buf[at .. at + length)`.
|
|
248
|
+
* @param buf The bytes holding the ID, read in place and not kept.
|
|
249
|
+
* @param at Where the ID starts in `buf`.
|
|
250
|
+
* @param length The ID's length in bytes.
|
|
251
|
+
* @returns The slot whose entry holds exactly this ID, or -1 when none does (always for a length of 0).
|
|
252
|
+
*/
|
|
212
253
|
find(buf: u8[], at: i32, length: i32): i32 {
|
|
213
254
|
const size: i32 = toI32(this.table.length)
|
|
214
255
|
let h: i32 = this.bucket(buf, at, length)
|
|
@@ -225,7 +266,15 @@ export class Http3CidIndex {
|
|
|
225
266
|
return -1
|
|
226
267
|
}
|
|
227
268
|
|
|
228
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* Files entry `e` as the ID `buf[at .. at + length)`; an ID already filed
|
|
271
|
+
* under any entry is left there, and nothing is filed.
|
|
272
|
+
* @param e The entry: slot `s`'s `j`th is `s * (QUIC_CONN_LOCAL_CIDS + 1) + j`. It must not be filed
|
|
273
|
+
* already (`remove` it first); one out of range files nothing.
|
|
274
|
+
* @param buf The bytes holding the ID, copied into the entry.
|
|
275
|
+
* @param at Where the ID starts in `buf`.
|
|
276
|
+
* @param length The ID's length in bytes, 1 to `QUIC_MAX_CID_LENGTH`; any other files nothing.
|
|
277
|
+
*/
|
|
229
278
|
insert(e: i32, buf: u8[], at: i32, length: i32): void {
|
|
230
279
|
if (length <= 0 || length > QUIC_MAX_CID_LENGTH || e < 0 || e >= toI32(this.lengths.length)) {
|
|
231
280
|
return
|
|
@@ -249,7 +298,10 @@ export class Http3CidIndex {
|
|
|
249
298
|
}
|
|
250
299
|
}
|
|
251
300
|
|
|
252
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* Takes entry `e` out, moving later entries of its probe run back so none is lost.
|
|
303
|
+
* @param e The entry, numbered as `insert` numbers it; one out of range or not filed is ignored.
|
|
304
|
+
*/
|
|
253
305
|
remove(e: i32): void {
|
|
254
306
|
if (e < 0 || e >= toI32(this.lengths.length) || this.lengths[e] === 0) {
|
|
255
307
|
return
|
|
@@ -294,21 +346,27 @@ export class Http3CidIndex {
|
|
|
294
346
|
}
|
|
295
347
|
|
|
296
348
|
/**
|
|
297
|
-
* Slots filed by the millisecond of their next deadline: `
|
|
298
|
-
*
|
|
299
|
-
*
|
|
349
|
+
* Slots filed by the millisecond of their next deadline: `H3_SERVER_WHEEL`
|
|
350
|
+
* buckets, each a linked list of its slots, and a bitmap of the buckets that
|
|
351
|
+
* hold any, so `next` passes 64 empty buckets at a time. A slot is filed in
|
|
352
|
+
* at most one bucket.
|
|
300
353
|
*/
|
|
301
354
|
export class Http3Wheel {
|
|
302
|
-
head: i32[]
|
|
303
|
-
nextOf: i32[]
|
|
304
|
-
prevOf: i32[]
|
|
305
|
-
/** The bucket a slot is filed in, or -1
|
|
306
|
-
bucketOf: i32[]
|
|
355
|
+
private head: i32[]
|
|
356
|
+
private nextOf: i32[]
|
|
357
|
+
private prevOf: i32[]
|
|
358
|
+
/** The bucket a slot is filed in, or -1. */
|
|
359
|
+
private bucketOf: i32[]
|
|
360
|
+
/** Per slot, the deadline in milliseconds `file` last filed it for, before any clamp to the horizon. */
|
|
307
361
|
dueAt: i64[]
|
|
308
|
-
bits: i64[]
|
|
362
|
+
private bits: i64[]
|
|
309
363
|
/** Every bucket before this time has been run. */
|
|
310
364
|
cursor: i64 = -1
|
|
311
365
|
|
|
366
|
+
/**
|
|
367
|
+
* An empty wheel whose cursor is not started.
|
|
368
|
+
* @param slots How many slots it files, 0 to `slots - 1`.
|
|
369
|
+
*/
|
|
312
370
|
constructor(slots: i32) {
|
|
313
371
|
this.head = new Array<i32>(H3_SERVER_WHEEL)
|
|
314
372
|
this.nextOf = new Array<i32>(slots)
|
|
@@ -320,7 +378,7 @@ export class Http3Wheel {
|
|
|
320
378
|
}
|
|
321
379
|
|
|
322
380
|
/** Marks bucket `b` filled or not. */
|
|
323
|
-
flag(b: i32, on: boolean): void {
|
|
381
|
+
private flag(b: i32, on: boolean): void {
|
|
324
382
|
const word: i32 = b >> 6
|
|
325
383
|
if (word < 0 || word >= toI32(this.bits.length)) {
|
|
326
384
|
return
|
|
@@ -329,7 +387,10 @@ export class Http3Wheel {
|
|
|
329
387
|
this.bits[word] = on ? this.bits[word] | bit : this.bits[word] & ~bit
|
|
330
388
|
}
|
|
331
389
|
|
|
332
|
-
/**
|
|
390
|
+
/**
|
|
391
|
+
* Takes `slot` out of its bucket.
|
|
392
|
+
* @param slot The slot; one out of range or not filed is ignored.
|
|
393
|
+
*/
|
|
333
394
|
unfile(slot: i32): void {
|
|
334
395
|
if (slot < 0 || slot >= toI32(this.bucketOf.length)) {
|
|
335
396
|
return
|
|
@@ -354,7 +415,14 @@ export class Http3Wheel {
|
|
|
354
415
|
this.bucketOf[slot] = -1
|
|
355
416
|
}
|
|
356
417
|
|
|
357
|
-
/**
|
|
418
|
+
/**
|
|
419
|
+
* Files `slot` under `due`, taking it out of any bucket it was in first. A
|
|
420
|
+
* `due` before the cursor is filed at the cursor, one past the horizon
|
|
421
|
+
* (`H3_SERVER_WHEEL - 1` milliseconds after the cursor) at the horizon.
|
|
422
|
+
* @param slot The slot; one out of range files nothing.
|
|
423
|
+
* @param due The deadline in milliseconds, on `now`'s clock; a negative one leaves the slot unfiled.
|
|
424
|
+
* @param now The current millisecond: it starts the cursor when no file or tick has yet.
|
|
425
|
+
*/
|
|
358
426
|
file(slot: i32, due: i64, now: i64): void {
|
|
359
427
|
this.unfile(slot)
|
|
360
428
|
if (due < 0 || slot < 0 || slot >= toI32(this.bucketOf.length)) {
|
|
@@ -384,7 +452,12 @@ export class Http3Wheel {
|
|
|
384
452
|
this.flag(b, true)
|
|
385
453
|
}
|
|
386
454
|
|
|
387
|
-
/**
|
|
455
|
+
/**
|
|
456
|
+
* The slot at the head of the bucket for `time`, taken out of it.
|
|
457
|
+
* @param time A millisecond: its bucket is `time` modulo `H3_SERVER_WHEEL`, which also holds a slot
|
|
458
|
+
* filed at the horizon for a later deadline, so the caller compares `dueAt`.
|
|
459
|
+
* @returns The slot taken, or -1 when the bucket is empty.
|
|
460
|
+
*/
|
|
388
461
|
take(time: i64): i32 {
|
|
389
462
|
const b: i32 = http3ServerBucket(time)
|
|
390
463
|
const slot: i32 = b >= 0 && b < H3_SERVER_WHEEL ? this.head[b] - 1 : -1
|
|
@@ -394,7 +467,12 @@ export class Http3Wheel {
|
|
|
394
467
|
return slot
|
|
395
468
|
}
|
|
396
469
|
|
|
397
|
-
/**
|
|
470
|
+
/**
|
|
471
|
+
* Milliseconds from `now` to the first filled bucket, at most the horizon.
|
|
472
|
+
* @param now The current millisecond; the search starts at the cursor, or at `now` before it starts.
|
|
473
|
+
* @returns 0 when that bucket's time is at or before `now`, the milliseconds until it otherwise, or -1
|
|
474
|
+
* when every bucket is empty.
|
|
475
|
+
*/
|
|
398
476
|
next(now: i64): i32 {
|
|
399
477
|
// From the cursor: a bucket before it has run, and one at `now` after a
|
|
400
478
|
// tick is the horizon's, a full turn of the wheel away.
|
|
@@ -426,14 +504,17 @@ export class Http3Wheel {
|
|
|
426
504
|
* is the HTTP/3 side of each and `quic(slot)` the QUIC side.
|
|
427
505
|
*/
|
|
428
506
|
export class Http3Server {
|
|
507
|
+
/** The QUIC configuration of the listener and every slot's connection; `stop` wipes its two keys. */
|
|
429
508
|
quicConfig: QuicServerConfig
|
|
430
509
|
/** The HTTP/3 configuration each slot's `Http3Connection` is built with. */
|
|
431
|
-
config: Http3Config
|
|
510
|
+
private config: Http3Config
|
|
511
|
+
/** Answers the datagrams no slot owns, and accepts new connections into free slots; `stop` releases it. */
|
|
432
512
|
listener: QuicListener
|
|
433
513
|
/** What the listener answers into, made once: its reply and IDs are refilled in their own room. */
|
|
434
514
|
answer: QuicListenerAnswer
|
|
435
515
|
/** The slots built so far, 0 up: each built on the first Initial accepted into it, or the first ask for it. */
|
|
436
516
|
quics: QuicConnection[]
|
|
517
|
+
/** The HTTP/3 side of each slot in `quics`, at the same index: what `connection` answers. */
|
|
437
518
|
conns: Http3Connection[]
|
|
438
519
|
/**
|
|
439
520
|
* The `date` every slot's responses carry, formatted once a second for all
|
|
@@ -441,14 +522,16 @@ export class Http3Server {
|
|
|
441
522
|
* `connection` and `ready`. `date.pin` fixes its clock.
|
|
442
523
|
*/
|
|
443
524
|
date: HttpDate
|
|
525
|
+
/** The connection IDs of every slot holding a connection, which route each datagram to its slot. */
|
|
444
526
|
index: Http3CidIndex
|
|
527
|
+
/** Each slot's next deadline, filed by `flush` and run by `tick`; `timeout` reads it. */
|
|
445
528
|
wheel: Http3Wheel
|
|
446
529
|
/**
|
|
447
530
|
* Where each slot sends now: its client's address as the first datagram
|
|
448
531
|
* came from, then wherever the connection follows the client to
|
|
449
|
-
* (`QuicConnection.sendAddress`, copied here by `
|
|
450
|
-
* validated until `quic(slot).addressValidated` is set (RFC 9000 §8.1): a
|
|
451
|
-
* Retry token the listener checked, with `retry` on, or a Handshake packet
|
|
532
|
+
* (`QuicConnection.sendAddress`, copied here by `flush` before each slot's flight once
|
|
533
|
+
* `quic(slot).pathKnown`). Not validated until `quic(slot).addressValidated` is set (RFC 9000 §8.1): a
|
|
534
|
+
* Retry token the listener checked, with `quicConfig.retry` on, or a Handshake packet
|
|
452
535
|
* from the client. Before then it is the source of one UDP datagram, which
|
|
453
536
|
* anyone can forge, so a cap or an allow-list keyed on it waits for that.
|
|
454
537
|
* After the handshake it changes when the client's address does (a NAT
|
|
@@ -457,46 +540,53 @@ export class Http3Server {
|
|
|
457
540
|
*/
|
|
458
541
|
addresses: u8[][]
|
|
459
542
|
/** What `receive` reads into, and where `flush` writes a flight. */
|
|
460
|
-
rx: u8[]
|
|
461
|
-
tx: u8[]
|
|
462
|
-
from: u8[]
|
|
463
|
-
meta: i32[]
|
|
543
|
+
private rx: u8[]
|
|
544
|
+
private tx: u8[]
|
|
545
|
+
private from: u8[]
|
|
546
|
+
private meta: i32[]
|
|
547
|
+
/**
|
|
548
|
+
* `QUIC_CONN_ENTROPY_SIZE` bytes of scratch, refilled from `crypto.getRandomValues` for each slot built
|
|
549
|
+
* and each connection accepted; it holds the last one's until the next, and `stop` zeroes it.
|
|
550
|
+
*/
|
|
464
551
|
entropy: u8[]
|
|
465
|
-
flight: QuicFlight
|
|
552
|
+
private flight: QuicFlight
|
|
466
553
|
/** Signs every slot's CertificateVerify in `serve`, one for the server, keeping nothing per signature. */
|
|
467
|
-
signer: TlsP256Signer
|
|
554
|
+
private signer: TlsP256Signer
|
|
468
555
|
/** Each slot's connection-ID index signature, so it is refiled only when its IDs changed. */
|
|
469
|
-
signatures: i64[]
|
|
470
|
-
state: i32[]
|
|
556
|
+
private signatures: i64[]
|
|
557
|
+
private state: i32[]
|
|
471
558
|
/** The slots with datagrams for the program, a ring, and the slots with something to send, a stack. */
|
|
472
|
-
readyRing: i32[]
|
|
473
|
-
dirtyStack: i32[]
|
|
559
|
+
private readyRing: i32[]
|
|
560
|
+
private dirtyStack: i32[]
|
|
474
561
|
/** Released slots, a stack: a slot never built is taken from `used` instead. */
|
|
475
|
-
free: i32[]
|
|
562
|
+
private free: i32[]
|
|
476
563
|
/** Per slot: 1 while on the ready ring, 2 while on the dirty stack. */
|
|
477
|
-
queued: i32[]
|
|
564
|
+
private queued: i32[]
|
|
478
565
|
/** When the answer budget was last topped up, -1 before the first answer. */
|
|
479
|
-
answerRefilled: i64 = -1
|
|
566
|
+
private answerRefilled: i64 = -1
|
|
480
567
|
/** The caller's clock in microseconds, from `clock`, or -1: what each connection's pacer counts. */
|
|
481
|
-
micros: i64 = -1
|
|
568
|
+
private micros: i64 = -1
|
|
569
|
+
/** The UDP socket every datagram is read from and sent on, as the constructor was given it. */
|
|
482
570
|
fd: i32 = -1
|
|
483
|
-
readyHead: i32 = 0
|
|
484
|
-
readyCount: i32 = 0
|
|
485
|
-
dirtyCount: i32 = 0
|
|
486
|
-
freeCount: i32 = 0
|
|
571
|
+
private readyHead: i32 = 0
|
|
572
|
+
private readyCount: i32 = 0
|
|
573
|
+
private dirtyCount: i32 = 0
|
|
574
|
+
private freeCount: i32 = 0
|
|
487
575
|
/** How many slots the pool may hold, which `size` answers. */
|
|
488
|
-
slots: i32 = 1
|
|
576
|
+
private slots: i32 = 1
|
|
489
577
|
/** The slots ever accepted into, 0 up: one past it has never held a connection, so is free without being on `free`. */
|
|
490
|
-
used: i32 = 0
|
|
578
|
+
private used: i32 = 0
|
|
491
579
|
/** Set by `stop`: a slot built after it is released as it is made, so it holds no keys. */
|
|
492
|
-
stopped: boolean = false
|
|
580
|
+
private stopped: boolean = false
|
|
493
581
|
/** What is left of the answer budget (see `answerRefilled`). */
|
|
494
|
-
answerBudget: i32 = 0
|
|
495
|
-
/**
|
|
582
|
+
private answerBudget: i32 = 0
|
|
583
|
+
/** Connections accepted into a slot, for a log or a test; saturating at 2^31 - 1. */
|
|
496
584
|
accepted: i32 = 0
|
|
585
|
+
/** Initials dropped because no slot was free, saturating at 2^31 - 1. */
|
|
497
586
|
refused: i32 = 0
|
|
587
|
+
/** Datagrams no slot owns dropped past the answer budget before the listener read them, saturating. */
|
|
498
588
|
limited: i32 = 0
|
|
499
|
-
sendErrors: i32 = 0
|
|
589
|
+
private sendErrors: i32 = 0
|
|
500
590
|
/** Whether the platform sends ECN marks: true until a marked send answers -95, and every slot's `ecnMarking` with it. */
|
|
501
591
|
ecn: boolean = true
|
|
502
592
|
/**
|
|
@@ -504,8 +594,8 @@ export class Http3Server {
|
|
|
504
594
|
* constructor for the stream table `quicConfig` gives every slot: `null`
|
|
505
595
|
* when its streams have none. Each pool makes a buffer only when a stream
|
|
506
596
|
* first needs one, so an idle server holds none (QUIC-3). It is made even
|
|
507
|
-
* for a configuration `quicConnConfigFits` refuses;
|
|
508
|
-
*
|
|
597
|
+
* for a configuration `quicConnConfigFits` refuses; a slot's connection
|
|
598
|
+
* shares it only when its stream buffers are the pools' size.
|
|
509
599
|
*/
|
|
510
600
|
streamPools: QuicStreamPools | null = null
|
|
511
601
|
/** The `bodyChunk`-byte read buffers every slot's `Http3Connection` borrows, one at most each. */
|
|
@@ -522,6 +612,12 @@ export class Http3Server {
|
|
|
522
612
|
* built on the first Initial accepted into it. From here on
|
|
523
613
|
* `quicConfig`'s `statelessResetKey` and `retryTokenKey` are the server's:
|
|
524
614
|
* `stop` wipes them, so the configuration is this server's alone.
|
|
615
|
+
* @param quicConfig The QUIC configuration, kept by reference and shared by the listener and every slot.
|
|
616
|
+
* @param config The HTTP/3 configuration, kept by reference; its `bodyChunk` and `maxFieldSectionSize`
|
|
617
|
+
* size the shared buffer pools.
|
|
618
|
+
* @param fd The bound UDP socket, kept; the server does not close it.
|
|
619
|
+
* @param size How many slots, 1 to 65536; any other panics.
|
|
620
|
+
* @param listenerEntropy `QUIC_LISTENER_ENTROPY_SIZE` random bytes, copied and then zeroed in this array.
|
|
525
621
|
*/
|
|
526
622
|
constructor(quicConfig: QuicServerConfig, config: Http3Config, fd: i32, size: i32, listenerEntropy: u8[]) {
|
|
527
623
|
if (size < 1 || size > 65536) {
|
|
@@ -590,7 +686,7 @@ export class Http3Server {
|
|
|
590
686
|
* were made for, its HTTP/3 connection on the pool's buffers and `date`,
|
|
591
687
|
* and its address.
|
|
592
688
|
*/
|
|
593
|
-
build(): void {
|
|
689
|
+
private build(): void {
|
|
594
690
|
crypto.getRandomValues(this.entropy)
|
|
595
691
|
const quic = new QuicConnection(this.quicConfig, this.entropy)
|
|
596
692
|
quic.ecnMarking = this.ecn
|
|
@@ -610,7 +706,7 @@ export class Http3Server {
|
|
|
610
706
|
}
|
|
611
707
|
|
|
612
708
|
/** `slot` when it is one of the pool's, built with every slot before it if it was not; 0 when it is out of range. */
|
|
613
|
-
slotAt(slot: i32): i32 {
|
|
709
|
+
private slotAt(slot: i32): i32 {
|
|
614
710
|
const at: i32 = slot >= 0 && slot < this.slots ? slot : H3_SERVER_ZERO
|
|
615
711
|
while (toI32(this.quics.length) <= at) {
|
|
616
712
|
this.build()
|
|
@@ -619,21 +715,31 @@ export class Http3Server {
|
|
|
619
715
|
}
|
|
620
716
|
|
|
621
717
|
/** Whether every slot holds a connection: none released, and none left never used. */
|
|
622
|
-
full(): boolean {
|
|
718
|
+
private full(): boolean {
|
|
623
719
|
return this.freeCount <= 0 && this.used >= this.slots
|
|
624
720
|
}
|
|
625
721
|
|
|
626
|
-
/**
|
|
722
|
+
/**
|
|
723
|
+
* How many slots the pool has, built or not.
|
|
724
|
+
* @returns The constructor's `size`, 1 to 65536.
|
|
725
|
+
*/
|
|
627
726
|
size(): i32 {
|
|
628
727
|
return this.slots
|
|
629
728
|
}
|
|
630
729
|
|
|
631
|
-
/**
|
|
730
|
+
/**
|
|
731
|
+
* How many slots hold a connection.
|
|
732
|
+
* @returns 0 to `size()`.
|
|
733
|
+
*/
|
|
632
734
|
busy(): i32 {
|
|
633
735
|
return this.used - this.freeCount
|
|
634
736
|
}
|
|
635
737
|
|
|
636
|
-
/**
|
|
738
|
+
/**
|
|
739
|
+
* Whether `slot` holds a connection.
|
|
740
|
+
* @param slot Any number.
|
|
741
|
+
* @returns True from the accept into it until it is freed; false for a slot out of range.
|
|
742
|
+
*/
|
|
637
743
|
holds(slot: i32): boolean {
|
|
638
744
|
return slot >= 0 && slot < toI32(this.state.length) && this.state[slot] === H3_SERVER_BUSY
|
|
639
745
|
}
|
|
@@ -643,18 +749,29 @@ export class Http3Server {
|
|
|
643
749
|
* of range names the first. A slot not built yet is built here, with every
|
|
644
750
|
* slot before it, so a program that binds something to each slot's
|
|
645
751
|
* connection up front gets the one its slot keeps.
|
|
752
|
+
* @param slot The slot, 0 to `size() - 1`.
|
|
753
|
+
* @returns The slot's connection, kept by the pool and reused by every connection the slot holds.
|
|
646
754
|
*/
|
|
647
755
|
connection(slot: i32): Http3Connection {
|
|
648
756
|
this.date.current()
|
|
649
757
|
return this.conns[this.slotAt(slot)]
|
|
650
758
|
}
|
|
651
759
|
|
|
652
|
-
/**
|
|
760
|
+
/**
|
|
761
|
+
* The QUIC connection of `slot`, built as `connection` builds it; a slot out of range names the first.
|
|
762
|
+
* @param slot The slot, 0 to `size() - 1`.
|
|
763
|
+
* @returns The slot's QUIC connection, kept by the pool and reset for each connection the slot holds.
|
|
764
|
+
*/
|
|
653
765
|
quic(slot: i32): QuicConnection {
|
|
654
766
|
return this.quics[this.slotAt(slot)]
|
|
655
767
|
}
|
|
656
768
|
|
|
657
|
-
/**
|
|
769
|
+
/**
|
|
770
|
+
* Marks `slot` as having news for the program, so that `ready` answers it,
|
|
771
|
+
* and something to send, so that the next `flush` sends it; a slot already
|
|
772
|
+
* marked is not marked twice.
|
|
773
|
+
* @param slot The slot; one that holds no connection is ignored.
|
|
774
|
+
*/
|
|
658
775
|
touch(slot: i32): void {
|
|
659
776
|
if (!this.holds(slot)) {
|
|
660
777
|
return
|
|
@@ -669,7 +786,7 @@ export class Http3Server {
|
|
|
669
786
|
}
|
|
670
787
|
|
|
671
788
|
/** Puts `slot` on the dirty stack, for `flush`. */
|
|
672
|
-
dirty(slot: i32): void {
|
|
789
|
+
private dirty(slot: i32): void {
|
|
673
790
|
if ((this.queued[slot] & 2) === 0 && this.dirtyCount < toI32(this.dirtyStack.length)) {
|
|
674
791
|
this.dirtyStack[this.dirtyCount] = slot
|
|
675
792
|
this.dirtyCount = this.dirtyCount + 1
|
|
@@ -677,7 +794,11 @@ export class Http3Server {
|
|
|
677
794
|
}
|
|
678
795
|
}
|
|
679
796
|
|
|
680
|
-
/**
|
|
797
|
+
/**
|
|
798
|
+
* The next slot with news for the program: call its connection's `next` until it has none.
|
|
799
|
+
* @returns A slot holding a connection that a datagram or `touch` marked since `ready` last answered it,
|
|
800
|
+
* each such slot once, or -1 when none is left.
|
|
801
|
+
*/
|
|
681
802
|
ready(): i32 {
|
|
682
803
|
this.date.current()
|
|
683
804
|
while (this.readyCount > 0) {
|
|
@@ -693,11 +814,15 @@ export class Http3Server {
|
|
|
693
814
|
}
|
|
694
815
|
|
|
695
816
|
/**
|
|
696
|
-
* Reads every datagram waiting on the socket, at most
|
|
697
|
-
* `H3_SERVER_RECEIVE_BURST
|
|
817
|
+
* Reads every datagram waiting on the socket, in at most
|
|
818
|
+
* `H3_SERVER_RECEIVE_BURST` receives, and hands each to its slot or the listener,
|
|
698
819
|
* signing a handshake's CertificateVerify with `key` (ECDSA P-256) when one
|
|
699
820
|
* asks. A GRO receive is cut into its datagrams in place. Answers how many
|
|
700
821
|
* datagrams it read.
|
|
822
|
+
* @param now The current millisecond on the caller's monotonic clock.
|
|
823
|
+
* @param key The certificate's private key; read only to sign, and not kept.
|
|
824
|
+
* @returns How many datagrams it handed on, each GRO segment counted, those then dropped included; it
|
|
825
|
+
* stops at the first receive that finds nothing or fails.
|
|
701
826
|
*/
|
|
702
827
|
receive(now: i64, key: Secret<u8[]>): i32 {
|
|
703
828
|
let count: i32 = 0
|
|
@@ -728,6 +853,14 @@ export class Http3Server {
|
|
|
728
853
|
/**
|
|
729
854
|
* One datagram, `buf[at .. at + len)`, from `address`: to the slot that
|
|
730
855
|
* owns its first packet's Destination Connection ID, or to the listener.
|
|
856
|
+
* One too short to carry its DCID, or whose DCID is longer than
|
|
857
|
+
* `QUIC_MAX_CID_LENGTH`, or a window outside `buf`, is dropped.
|
|
858
|
+
* @param buf The bytes holding the datagram, read in place.
|
|
859
|
+
* @param at Where the datagram starts in `buf`.
|
|
860
|
+
* @param len Its length in bytes.
|
|
861
|
+
* @param address Where it came from, in `nish:net`'s 18-byte form; copied when it starts a connection.
|
|
862
|
+
* @param now The current millisecond on the caller's monotonic clock.
|
|
863
|
+
* @param key The certificate's private key, as `receive` takes it.
|
|
731
864
|
*/
|
|
732
865
|
datagram(buf: u8[], at: i32, len: i32, address: u8[], now: i64, key: Secret<u8[]>): void {
|
|
733
866
|
if (len < 1 || at < 0 || at + len > toI32(buf.length)) {
|
|
@@ -759,7 +892,7 @@ export class Http3Server {
|
|
|
759
892
|
* in `buf` and answering into `answer`, and may make a connection in a
|
|
760
893
|
* free slot, which reads the same window. Nothing is copied (H3-3).
|
|
761
894
|
*/
|
|
762
|
-
unowned(buf: u8[], at: i32, len: i32, address: u8[], now: i64, key: Secret<u8[]>): void {
|
|
895
|
+
private unowned(buf: u8[], at: i32, len: i32, address: u8[], now: i64, key: Secret<u8[]>): void {
|
|
763
896
|
if (!this.worthListening(buf, at, len, now)) {
|
|
764
897
|
return
|
|
765
898
|
}
|
|
@@ -812,7 +945,7 @@ export class Http3Server {
|
|
|
812
945
|
* A stateless reset and a Version Negotiation packet, the answers that do
|
|
813
946
|
* not start a connection, are also held to `takeAnswer`'s budget.
|
|
814
947
|
*/
|
|
815
|
-
worthListening(buf: u8[], at: i32, len: i32, now: i64): boolean {
|
|
948
|
+
private worthListening(buf: u8[], at: i32, len: i32, now: i64): boolean {
|
|
816
949
|
const first: i32 = toI32(buf[at])
|
|
817
950
|
if ((first & 0x80) === 0) {
|
|
818
951
|
return len > QUIC_LISTENER_MIN_RESET && this.takeAnswer(now)
|
|
@@ -844,7 +977,7 @@ export class Http3Server {
|
|
|
844
977
|
* the datagram is dropped before the listener sees it, so a flood of
|
|
845
978
|
* garbage costs no answer and no MAC past the budget (H3-3); counted in `limited`.
|
|
846
979
|
*/
|
|
847
|
-
takeAnswer(now: i64): boolean {
|
|
980
|
+
private takeAnswer(now: i64): boolean {
|
|
848
981
|
if (this.answerRefilled < 0 || now < this.answerRefilled) {
|
|
849
982
|
this.answerRefilled = now
|
|
850
983
|
this.answerBudget = H3_SERVER_ANSWER_BURST
|
|
@@ -869,6 +1002,8 @@ export class Http3Server {
|
|
|
869
1002
|
* 1000` where `now` is `monotonicNanos() / 1000000`. The pacer counts it;
|
|
870
1003
|
* every timer still counts `now`. One that is not inside `now`'s
|
|
871
1004
|
* millisecond is not read.
|
|
1005
|
+
* @param micros The instant in microseconds; one outside the millisecond `now` names, such as -1, makes
|
|
1006
|
+
* the pacer count whole milliseconds.
|
|
872
1007
|
*/
|
|
873
1008
|
clock(micros: i64): void {
|
|
874
1009
|
this.micros = micros
|
|
@@ -879,6 +1014,13 @@ export class Http3Server {
|
|
|
879
1014
|
* handshake asks, and refiles its IDs and timer. The connection decides
|
|
880
1015
|
* from the address whether the client moved (RFC 9000 §9.3); an address
|
|
881
1016
|
* that is not 18 bytes long leaves it where it is.
|
|
1017
|
+
* @param slot A slot that holds a connection, as `datagram` finds it; the slot is not checked.
|
|
1018
|
+
* @param buf The bytes holding the datagram, read in place.
|
|
1019
|
+
* @param at Where the datagram starts in `buf`.
|
|
1020
|
+
* @param len Its length in bytes.
|
|
1021
|
+
* @param address Where it came from, in `nish:net`'s 18-byte form.
|
|
1022
|
+
* @param now The current millisecond on the caller's monotonic clock.
|
|
1023
|
+
* @param key The certificate's private key, as `receive` takes it.
|
|
882
1024
|
*/
|
|
883
1025
|
serve(slot: i32, buf: u8[], at: i32, len: i32, address: u8[], now: i64, key: Secret<u8[]>): void {
|
|
884
1026
|
const quic: QuicConnection = this.quics[slot]
|
|
@@ -896,7 +1038,7 @@ export class Http3Server {
|
|
|
896
1038
|
}
|
|
897
1039
|
|
|
898
1040
|
/** Files `slot`'s connection IDs in the index again when they changed. */
|
|
899
|
-
refile(slot: i32): void {
|
|
1041
|
+
private refile(slot: i32): void {
|
|
900
1042
|
const quic: QuicConnection = this.quics[slot]
|
|
901
1043
|
const signature: i64 =
|
|
902
1044
|
(quic.cids.nextLocal << 16) |
|
|
@@ -929,7 +1071,7 @@ export class Http3Server {
|
|
|
929
1071
|
* Sends `buf[at .. at + len)` to `to` with the ECN codepoint `ecn`, cut
|
|
930
1072
|
* into `segment`-byte datagrams when it is above 0; answers whether it went.
|
|
931
1073
|
*/
|
|
932
|
-
send(buf: u8[], at: i32, len: i32, to: u8[], segment: i32, ecn: i32): boolean {
|
|
1074
|
+
private send(buf: u8[], at: i32, len: i32, to: u8[], segment: i32, ecn: i32): boolean {
|
|
933
1075
|
const sent: i32 = udpSendTo(this.fd, buf, at, len, to, segment, ecn)
|
|
934
1076
|
if (sent >= 0) {
|
|
935
1077
|
return true
|
|
@@ -980,6 +1122,7 @@ export class Http3Server {
|
|
|
980
1122
|
* slot whose HTTP/3 side is done after GOAWAY, frees a slot whose
|
|
981
1123
|
* connection has closed, and files each in the wheel under its next
|
|
982
1124
|
* deadline.
|
|
1125
|
+
* @param now The current millisecond on the caller's monotonic clock.
|
|
983
1126
|
*/
|
|
984
1127
|
flush(now: i64): void {
|
|
985
1128
|
while (this.dirtyCount > 0) {
|
|
@@ -993,7 +1136,7 @@ export class Http3Server {
|
|
|
993
1136
|
}
|
|
994
1137
|
|
|
995
1138
|
/** `flush` of one slot. */
|
|
996
|
-
flushSlot(slot: i32, now: i64): void {
|
|
1139
|
+
private flushSlot(slot: i32, now: i64): void {
|
|
997
1140
|
const quic: QuicConnection = this.quics[slot]
|
|
998
1141
|
quic.recovery.micros = this.micros
|
|
999
1142
|
if (this.conns[slot].isDone() && !quic.closed()) {
|
|
@@ -1060,7 +1203,7 @@ export class Http3Server {
|
|
|
1060
1203
|
}
|
|
1061
1204
|
|
|
1062
1205
|
/** Takes every one of `slot`'s connection IDs out of the index. */
|
|
1063
|
-
unindex(slot: i32): void {
|
|
1206
|
+
private unindex(slot: i32): void {
|
|
1064
1207
|
const first: i32 = slot * H3_SERVER_KEYS
|
|
1065
1208
|
for (let j: i32 = 0; j < H3_SERVER_KEYS; j++) {
|
|
1066
1209
|
this.index.remove(first + j)
|
|
@@ -1068,7 +1211,7 @@ export class Http3Server {
|
|
|
1068
1211
|
}
|
|
1069
1212
|
|
|
1070
1213
|
/** Frees `slot`: its IDs leave the index and its timer the wheel. */
|
|
1071
|
-
release(slot: i32): void {
|
|
1214
|
+
private release(slot: i32): void {
|
|
1072
1215
|
this.unindex(slot)
|
|
1073
1216
|
this.wheel.unfile(slot)
|
|
1074
1217
|
this.conns[slot].release()
|
|
@@ -1081,19 +1224,19 @@ export class Http3Server {
|
|
|
1081
1224
|
|
|
1082
1225
|
/**
|
|
1083
1226
|
* Stops the server for good and wipes the keys it holds: every built slot's
|
|
1084
|
-
* connection is released (`QuicConnection.release`, which sends nothing),
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
*
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1096
|
-
* anyone can forge.
|
|
1227
|
+
* connection is released (`QuicConnection.release`, which sends nothing), as
|
|
1228
|
+
* is one built after, by `connection` or `quic`; the listener is released;
|
|
1229
|
+
* and the configuration's `statelessResetKey` and `retryTokenKey`, the
|
|
1230
|
+
* index's salt, the connections' entropy scratch and the listener's last
|
|
1231
|
+
* answer (a Retry's or a reset's token) are zeroed. From then on every
|
|
1232
|
+
* datagram is dropped and no connection is accepted.
|
|
1233
|
+
*
|
|
1234
|
+
* The configuration's two keys are the server's once it is made with them: a
|
|
1235
|
+
* program that keeps a copy of either, to start the next server with, wipes
|
|
1236
|
+
* its own copy. The keys are zeroed in place, so give each server a
|
|
1237
|
+
* `QuicServerConfig` of its own: any other listener, connection or server
|
|
1238
|
+
* made with the same one would go on MACing Retry tokens and deriving
|
|
1239
|
+
* stateless reset tokens under an all-zero key, which anyone can forge.
|
|
1097
1240
|
*/
|
|
1098
1241
|
stop(): void {
|
|
1099
1242
|
this.stopped = true
|
|
@@ -1112,7 +1255,10 @@ export class Http3Server {
|
|
|
1112
1255
|
this.answer.wipe()
|
|
1113
1256
|
}
|
|
1114
1257
|
|
|
1115
|
-
/**
|
|
1258
|
+
/**
|
|
1259
|
+
* Runs the timers due by `now`, and marks each slot it ran for `flush`.
|
|
1260
|
+
* @param now The current millisecond on the caller's monotonic clock.
|
|
1261
|
+
*/
|
|
1116
1262
|
tick(now: i64): void {
|
|
1117
1263
|
const wheel: Http3Wheel = this.wheel
|
|
1118
1264
|
if (wheel.cursor < 0) {
|
|
@@ -1146,7 +1292,12 @@ export class Http3Server {
|
|
|
1146
1292
|
}
|
|
1147
1293
|
}
|
|
1148
1294
|
|
|
1149
|
-
/**
|
|
1295
|
+
/**
|
|
1296
|
+
* Milliseconds until `tick` has a timer to run, for `pollWait`.
|
|
1297
|
+
* @param now The current millisecond on the caller's monotonic clock.
|
|
1298
|
+
* @returns 0 when a timer is due now, the milliseconds until the first otherwise (at most about
|
|
1299
|
+
* `H3_SERVER_WHEEL`), or -1 when no slot is filed.
|
|
1300
|
+
*/
|
|
1150
1301
|
timeout(now: i64): i32 {
|
|
1151
1302
|
return this.wheel.next(now)
|
|
1152
1303
|
}
|