@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.
Files changed (128) hide show
  1. package/INSTALL.md +73 -59
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +50 -4
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/nish.d.ts +4849 -430
  8. package/runtime/nish.h +25 -0
  9. package/runtime/page.d.ts +53 -0
  10. package/runtime/page.mjs +146 -0
  11. package/runtime/runtime-async.c +557 -0
  12. package/runtime/runtime-wasm.c +63 -7
  13. package/runtime/vite.d.ts +30 -0
  14. package/runtime/vite.mjs +150 -0
  15. package/scripts/build.sh +252 -15
  16. package/std/README.md +107 -82
  17. package/std/base64.ts +34 -5
  18. package/std/bytes.ts +279 -59
  19. package/std/cli-args.ts +296 -70
  20. package/std/cli-flags.ts +184 -19
  21. package/std/cli.ts +475 -54
  22. package/std/collections.ts +121 -23
  23. package/std/compress/checksum.ts +44 -14
  24. package/std/compress/deflate.ts +224 -111
  25. package/std/compress/gzip.ts +217 -53
  26. package/std/compress/zlib.ts +63 -7
  27. package/std/crypto/aes.ts +128 -52
  28. package/std/crypto/base64url.ts +29 -5
  29. package/std/crypto/bcrypt-batch.ts +101 -34
  30. package/std/crypto/bcrypt.ts +93 -27
  31. package/std/crypto/chacha20poly1305.ts +69 -14
  32. package/std/crypto/ct.ts +32 -13
  33. package/std/crypto/ed25519.ts +66 -16
  34. package/std/crypto/hkdf.ts +198 -13
  35. package/std/crypto/hmac.ts +242 -37
  36. package/std/crypto/jwt.ts +204 -72
  37. package/std/crypto/p256.ts +222 -72
  38. package/std/crypto/p384.ts +51 -23
  39. package/std/crypto/pki-roots.ts +32 -2
  40. package/std/crypto/pki.ts +99 -30
  41. package/std/crypto/rsa.ts +56 -22
  42. package/std/crypto/sha1.ts +3 -0
  43. package/std/crypto/sha256.ts +24 -1
  44. package/std/crypto/sha512.ts +99 -14
  45. package/std/crypto/x25519.ts +163 -24
  46. package/std/crypto/x509-random.ts +10 -0
  47. package/std/crypto/x509.ts +133 -66
  48. package/std/host/ring.ts +124 -0
  49. package/std/json-equal.ts +31 -11
  50. package/std/json-format.ts +112 -13
  51. package/std/json-number.ts +76 -26
  52. package/std/json-pointer.ts +23 -1
  53. package/std/json-tokenizer.ts +126 -51
  54. package/std/json-typed.ts +757 -96
  55. package/std/json-value.ts +438 -157
  56. package/std/json.ts +170 -38
  57. package/std/map.ts +25 -7
  58. package/std/math.ts +36 -4
  59. package/std/net/buffer-pool.ts +42 -11
  60. package/std/net/dns-config.ts +109 -23
  61. package/std/net/dns-message.ts +62 -7
  62. package/std/net/dns-resolver.ts +247 -53
  63. package/std/net/dns.ts +203 -35
  64. package/std/net/fetch.ts +1267 -290
  65. package/std/net/handler.ts +296 -80
  66. package/std/net/hpack.ts +290 -77
  67. package/std/net/http-compress.ts +152 -36
  68. package/std/net/http-fields.ts +85 -9
  69. package/std/net/http1-client-codec.ts +129 -44
  70. package/std/net/http1-codec.ts +279 -114
  71. package/std/net/http1-server.ts +409 -139
  72. package/std/net/http2-frame.ts +289 -51
  73. package/std/net/http2-tls.ts +152 -49
  74. package/std/net/http2.ts +314 -160
  75. package/std/net/http3-frame.ts +165 -27
  76. package/std/net/http3-server.ts +282 -131
  77. package/std/net/http3.ts +377 -173
  78. package/std/net/outbound.ts +37 -3
  79. package/std/net/postgres-carrier.ts +144 -8
  80. package/std/net/postgres.ts +898 -260
  81. package/std/net/prefork.ts +202 -65
  82. package/std/net/qpack.ts +120 -32
  83. package/std/net/quic-conn-ack.ts +60 -12
  84. package/std/net/quic-conn-cid.ts +135 -27
  85. package/std/net/quic-conn-params.ts +109 -22
  86. package/std/net/quic-datagram.ts +50 -3
  87. package/std/net/quic-frame.ts +333 -23
  88. package/std/net/quic-listener.ts +161 -75
  89. package/std/net/quic-packet.ts +373 -73
  90. package/std/net/quic-recovery.ts +287 -65
  91. package/std/net/quic-stream.ts +436 -146
  92. package/std/net/quic.ts +693 -323
  93. package/std/net/router.ts +87 -40
  94. package/std/net/tls/client.ts +167 -51
  95. package/std/net/tls/codec.ts +494 -68
  96. package/std/net/tls/record-client.ts +140 -73
  97. package/std/net/tls/record-server.ts +233 -105
  98. package/std/net/tls/record.ts +142 -36
  99. package/std/net/tls/schedule.ts +235 -26
  100. package/std/net/tls/ticket.ts +161 -40
  101. package/std/net/tls/verify.ts +57 -10
  102. package/std/net/tls-tcp.ts +308 -95
  103. package/std/net/tls.ts +276 -102
  104. package/std/net/upstream.ts +81 -45
  105. package/std/net/url.ts +109 -22
  106. package/std/net/websocket.ts +140 -26
  107. package/std/net/webtransport.ts +243 -106
  108. package/std/pair.ts +10 -2
  109. package/std/random.ts +42 -15
  110. package/std/regex.ts +422 -257
  111. package/std/region.ts +70 -15
  112. package/std/secret.ts +52 -11
  113. package/std/sort.ts +17 -2
  114. package/std/sqlite.ts +256 -35
  115. package/std/sync/ring.ts +229 -56
  116. package/std/sync/shm.ts +203 -23
  117. package/std/term-io.ts +154 -78
  118. package/std/term-pixels.ts +144 -19
  119. package/std/term-probe.ts +77 -35
  120. package/std/term-rate.ts +199 -118
  121. package/std/term.ts +400 -175
  122. package/std/testing.ts +130 -32
  123. package/std/text.ts +84 -17
  124. package/std/threads.ts +248 -56
  125. package/std/yaml-json.ts +111 -97
  126. package/std/yaml-lines.ts +47 -15
  127. package/std/yaml-write.ts +45 -30
  128. package/std/yaml.ts +764 -384
@@ -8,6 +8,7 @@
8
8
  * the RFC means: nothing it answers depends on any connection.
9
9
  *
10
10
  * import { QuicListener, QuicListenerAnswer, QUIC_LISTEN_ACCEPT, QUIC_LISTENER_ANSWER_SIZE } from "nish/net/quic-listener";
11
+ * import { QuicConnection } from "nish/net/quic";
11
12
  *
12
13
  * const listener = new QuicListener(config, entropy); // entropy: QUIC_LISTENER_ENTROPY_SIZE random bytes
13
14
  * const answer = new QuicListenerAnswer(QUIC_LISTENER_ANSWER_SIZE); // once, beside the listener
@@ -34,32 +35,36 @@
34
35
  * listener a packet for a connection that is still alive would give that
35
36
  * token, which ends the connection, to whoever sent it (RFC 9000 §21.11).
36
37
  *
37
- * **Retry tokens** (§8.1.4) are this server's own format: a marker byte, the
38
- * time the token was issued, and the client's original Destination
38
+ * **Retry tokens** (§8.1.4). They are this server's own format: a marker byte,
39
+ * the time the token was issued, and the client's original Destination
39
40
  * Connection ID, then 16 bytes of HMAC-SHA256 under the configuration's
40
- * `retryTokenKey` over all of that, the Retry's Source Connection ID (which
41
- * the client's next Initial must be sent to) and the client's address as the
42
- * caller gives it, port included. So a token is good only from the address
43
- * it was sent to, only for the connection it was issued for, and only for
44
- * `retryTokenLifetime` milliseconds. A token that carries the marker and fails
45
- * any of that is an invalid Retry token, which closes the attempt with
46
- * INVALID_TOKEN (§8.1.2); a token without the marker, which some other
47
- * server issued, is treated as no token at all (§8.1.3).
41
+ * `retryTokenKey` over all of that, the Retry's Source Connection ID (which the
42
+ * client's next Initial must be sent to) and the client's address as the caller
43
+ * gives it, port included. So a token is good only from the address it was sent
44
+ * to, only for the connection it was issued for, and only for
45
+ * `retryTokenLifetime` milliseconds.
48
46
  *
49
- * **Stateless resets** (§10.3) end in the token `quicStatelessResetToken`
50
- * derives (computed in place, by `quicConnResetTokenInto`) from the configuration's static key and the packet's connection
51
- * ID, so a server that restarted with the same key can end the connections
52
- * it lost. RFC 9000 §10.3 and §10.3.3 bound them, and each bound is held
53
- * here. A reset is sent only for a short header, and is always shorter than
54
- * the datagram that caused it, so two endpoints resetting each other shrink
55
- * to nothing; one byte shorter for a datagram of 43 bytes or fewer, and
56
- * never under 21 bytes, so a datagram of 21 or fewer gets none. That also
57
- * bounds amplification at less than one to one. They are rate limited:
58
- * `QUIC_LISTENER_RESET_BURST` at once, then one per
59
- * `QUIC_LISTENER_RESET_INTERVAL` milliseconds. Each reset's other bytes are
60
- * unpredictable, from the listener's own generator.
47
+ * A token that carries the marker and fails any of that is an invalid Retry
48
+ * token, which closes the attempt with INVALID_TOKEN (§8.1.2); a token without
49
+ * the marker, which some other server issued, is treated as no token at all
50
+ * (§8.1.3).
61
51
  *
62
- * **Pacing** (RFC 9002 §7.7) is the carrier's send loop, so it is here
52
+ * **Stateless resets** (§10.3). They end in the token `quicStatelessResetToken`
53
+ * derives (computed in place, by `quicConnResetTokenInto`) from the
54
+ * configuration's static key and the packet's connection ID, so a server that
55
+ * restarted with the same key can end the connections it lost. RFC 9000 §10.3
56
+ * and §10.3.3 bound them, and each bound is held here.
57
+ *
58
+ * A reset is sent only for a short header, and is always shorter than the
59
+ * datagram that caused it, so two endpoints resetting each other shrink to
60
+ * nothing; one byte shorter for a datagram of 43 bytes or fewer, and never
61
+ * under 21 bytes, so a datagram of 21 or fewer gets none. That also bounds
62
+ * amplification at less than one to one. They are rate limited:
63
+ * `QUIC_LISTENER_RESET_BURST` at once, then one per
64
+ * `QUIC_LISTENER_RESET_INTERVAL` milliseconds. Each reset's other bytes are
65
+ * unpredictable, from the listener's own generator.
66
+ *
67
+ * **Pacing** (RFC 9002 §7.7). It is the carrier's send loop, so it is here
63
68
  * beside the rest of what the carrier calls: `quicListenerTakePaced` takes a
64
69
  * connection's next datagram only when its pacer has the credit for it, and
65
70
  * `quicListenerPaceTime` says when it will. The pacer earns 5/4 of the
@@ -77,18 +82,19 @@
77
82
  *
78
83
  * **GSO and GRO** (`nish:net`'s `UDP_SEGMENT` and `UDP_GRO`). A carrier that
79
84
  * sends with segmentation offload takes a whole flight at once:
80
- * `quicListenerTakeFlight` writes as many datagrams as the pacer has credit
81
- * for back to back into one buffer, every one `QUIC_CONN_DATAGRAM_SIZE`
82
- * bytes but the last, which is what one `udpSendTo` with that segment size
83
- * cuts back into datagrams; each is written in place, so a flight allocates
84
- * nothing. The flight is paced as a whole: it is as long as the pacer's
85
- * credit, and charged to it datagram by datagram, so a burst is never more
86
- * than the initial window however the carrier sends it. It starts only on a
87
- * millisecond's earning, up to four datagrams, so a fast connection's pacer,
88
- * which earns by the microsecond, does not let it out a datagram per send;
89
- * `quicListenerFlightTime` says when. On the receiving
90
- * side, `quicListenerReceiveSegments` hands a connection the datagrams of
91
- * one GRO receive, segment by segment, in place.
85
+ * `quicListenerTakeFlight` writes as many datagrams as the pacer has credit for
86
+ * back to back into one buffer, every one `QUIC_CONN_DATAGRAM_SIZE` bytes but
87
+ * the last, which is what one `udpSendTo` with that segment size cuts back into
88
+ * datagrams; each is written in place, so a flight allocates nothing.
89
+ *
90
+ * The flight is paced as a whole: it is as long as the pacer's credit, and
91
+ * charged to it datagram by datagram, so a burst is never more than the initial
92
+ * window however the carrier sends it. It starts only on a millisecond's
93
+ * earning, up to four datagrams, so a fast connection's pacer, which earns by
94
+ * the microsecond, does not let it out a datagram per send;
95
+ * `quicListenerFlightTime` says when. On the receiving side,
96
+ * `quicListenerReceiveSegments` hands a connection the datagrams of one GRO
97
+ * receive, segment by segment, in place.
92
98
  *
93
99
  * **ECN** (RFC 9000 §13.4). A carrier whose platform sends the ECN bits it
94
100
  * is given sets the connection's `ecnMarking` and sends each datagram with
@@ -222,13 +228,25 @@ export const QUIC_LISTENER_ANSWER_SIZE: i32 = QUIC_CONN_DATAGRAM_SIZE
222
228
  * with exactly the room its reply takes.
223
229
  */
224
230
  export class QuicListenerAnswer {
231
+ /** The datagram to send back to the peer's address; empty when the answer sends nothing. */
225
232
  reply: u8[]
233
+ /** After a Retry, the DCID of the client's first Initial, which `QuicConnection.acceptRetry` checks. */
226
234
  originalDcid: u8[]
235
+ /** After a Retry, the SCID the Retry chose, which `QuicConnection.acceptRetry` checks. */
227
236
  retryScid: u8[]
237
+ /** What to do with the datagram: a `QUIC_LISTEN_*`, `QUIC_LISTEN_DROP` after `wipe`. */
228
238
  kind: i32 = 0
239
+ /** Whether an accepted Initial carried a valid Retry token, so `originalDcid` and `retryScid` are set. */
229
240
  retried: boolean = false
230
- room: i32 = 0
241
+ private room: i32 = 0
231
242
 
243
+ /**
244
+ * An empty answer with room for a reply of `room` bytes.
245
+ *
246
+ * @param room The bytes reserved for `reply`, usually `QUIC_LISTENER_ANSWER_SIZE`; 0 or less reserves
247
+ * none. `originalDcid` and `retryScid` get room for `QUIC_MAX_CID_LENGTH` (20) bytes each whatever it
248
+ * is. That is capacity: all three start empty, their lengths 0 until an answer or `wipe` sets them.
249
+ */
232
250
  constructor(room: i32) {
233
251
  this.room = room > 0 ? room : 0
234
252
  this.reply = quicListenerRoom(this.room)
@@ -242,7 +260,8 @@ export class QuicListenerAnswer {
242
260
  * leave no copy beyond the arrays' lengths either. Each is left that long
243
261
  * and all zero, `kind` a drop. An answer whose reply grew past its room
244
262
  * keeps what lies beyond the longest length it is wiped at; one made with
245
- * `QUIC_LISTENER_ANSWER_SIZE` never grows.
263
+ * `QUIC_LISTENER_ANSWER_SIZE` never grows. The caller's to call once it
264
+ * has sent the answer `QuicListener.handle` gave, and before it drops it.
246
265
  */
247
266
  wipe(): void {
248
267
  quicListenerWipeRoom(this.reply, this.room)
@@ -332,49 +351,64 @@ const quicListenerWindowFits = (length: i32, at: i32, len: i32): boolean =>
332
351
  * `handleWindow` reads the datagram where it lies and keeps nothing.
333
352
  */
334
353
  export class QuicListener {
335
- config: QuicServerConfig
354
+ private config: QuicServerConfig
355
+ /** The 32 bytes of entropy every unpredictable byte is made from; `release` wipes it. */
336
356
  seed: u8[]
337
357
  /** Unpredictable bytes not yet used, from `poolHead`, and the counter the next block is made from. */
338
358
  pool: u8[]
339
359
  /** The counter's eight bytes, the generator's HMAC message. */
340
- block: u8[]
360
+ private block: u8[]
341
361
  /** What `handleWindow` parses a datagram's header into, in place. */
342
- header: QuicHeader
362
+ private header: QuicHeader
343
363
  /** Every HMAC and HKDF the listener computes runs here; its `sha256` makes tokens, resets and the generator's blocks. */
344
364
  kdf: HkdfScratch
345
365
  /** A full HMAC-SHA256 tag, wiped once its 16 bytes are used. */
346
366
  tag: u8[]
347
367
  /** A Retry token MAC's length fields: the Retry SCID's one byte, the address's four. */
348
- lengths: u8[]
368
+ private lengths: u8[]
349
369
  /** The Initial secrets of an INVALID_TOKEN close, and its keys, both directions. */
350
370
  initialClient: u8[]
371
+ /** The server's Initial secret of an INVALID_TOKEN close; `initialClient` is the client's. */
351
372
  initialServer: u8[]
373
+ /** The INVALID_TOKEN close's keys for reading the client's Initial. */
352
374
  readSlot: QuicKeysSlot
375
+ /** The INVALID_TOKEN close's keys for sealing the server's Initial. */
353
376
  writeSlot: QuicKeysSlot
354
- packet: QuicPacket
377
+ private packet: QuicPacket
355
378
  /** The client's SCID and the DCID it sent to, copied out for `quicPutLongHeader`, which reads IDs from 0. */
356
- peerCid: u8[]
357
- ownCid: u8[]
379
+ private peerCid: u8[]
380
+ private ownCid: u8[]
358
381
  /** An empty array: the INVALID_TOKEN close's token and reason. */
359
- none: u8[]
382
+ private none: u8[]
360
383
  /** Version 1's fixed Retry key (RFC 9001 §5.8), expanded once. */
361
- retryKey: AesKey
384
+ private retryKey: AesKey
362
385
  /** What `handle` answers into before it copies the answer out. */
363
386
  spare: QuicListenerAnswer
364
- counter: i64 = 0
387
+ private counter: i64 = 0
365
388
  /** The latest time the caller gave, in milliseconds; time never runs backwards here. */
366
- now: i64 = 0
389
+ private now: i64 = 0
367
390
  /** When the reset budget was last topped up (-1: never yet), and the stateless resets that may go now. */
368
- resetRefilled: i64 = -1
369
- resetBudget: i32 = 0
391
+ private resetRefilled: i64 = -1
392
+ private resetBudget: i32 = 0
393
+ /** Where the unused bytes of `pool` start: `QUIC_LISTENER_POOL` when it is spent. */
370
394
  poolHead: i32 = 0
371
395
  /** Stateless resets sent, and ones the rate limit held back. */
372
396
  resetsSent: i32 = 0
397
+ /** Stateless resets the rate limit held back, which a log or test reads to see the limit working. */
373
398
  resetsLimited: i32 = 0
374
399
  /** Whether the configuration and entropy were usable. */
375
- usable: boolean = false
400
+ private usable: boolean = false
376
401
 
377
- /** A listener under `config`; `entropy`'s `QUIC_LISTENER_ENTROPY_SIZE` bytes are copied, then wiped in the caller's array. */
402
+ /**
403
+ * A listener under `config`; `entropy`'s `QUIC_LISTENER_ENTROPY_SIZE` bytes are copied, then wiped in
404
+ * the caller's array.
405
+ *
406
+ * @param config The server's configuration, kept by reference: its static keys and Retry token lifetime.
407
+ * Keys of the wrong size, or a lifetime outside 1 to `QUIC_LISTENER_MAX_TOKEN_LIFETIME` ms, make a
408
+ * listener that drops every datagram.
409
+ * @param entropy `QUIC_LISTENER_ENTROPY_SIZE` (32) random bytes, the seed of every unpredictable byte
410
+ * the listener sends. Zeroed on return; any other length makes a listener that drops every datagram.
411
+ */
378
412
  constructor(config: QuicServerConfig, entropy: u8[]) {
379
413
  this.config = config
380
414
  this.seed = new Array<u8>(QUIC_LISTENER_ENTROPY_SIZE)
@@ -434,7 +468,7 @@ export class QuicListener {
434
468
  * One unpredictable value in 0 to 255: the next byte of HMAC-SHA256 under
435
469
  * the seed of a counter, a block at a time, each byte wiped once taken.
436
470
  */
437
- randomByte(): i32 {
471
+ private randomByte(): i32 {
438
472
  if (this.poolHead >= QUIC_LISTENER_POOL) {
439
473
  this.refill()
440
474
  }
@@ -448,7 +482,7 @@ export class QuicListener {
448
482
  }
449
483
 
450
484
  /** Writes `count` unpredictable bytes into `out` at `at`. */
451
- randomInto(out: u8[], at: i32, count: i32): void {
485
+ private randomInto(out: u8[], at: i32, count: i32): void {
452
486
  for (let k: i32 = 0; k < count; k += 1) {
453
487
  const b: i32 = this.randomByte()
454
488
  if (at + k >= 0 && at + k < toI32(out.length)) {
@@ -458,7 +492,7 @@ export class QuicListener {
458
492
  }
459
493
 
460
494
  /** The generator's next block, HMAC-SHA256 under the seed of the counter, into `pool`. */
461
- refill(): void {
495
+ private refill(): void {
462
496
  quicListenerPutNumber(this.block, 0, this.counter, QUIC_LISTENER_BLOCK)
463
497
  this.counter = this.counter + 1
464
498
  const mac: HmacSha256Scratch = this.kdf.sha256
@@ -481,6 +515,16 @@ export class QuicListener {
481
515
  * the module header for the rules; nothing a peer sends makes it panic,
482
516
  * and nothing it does keeps arena memory. A window outside `datagram` is
483
517
  * the caller's mistake, and panics.
518
+ *
519
+ * @param datagram The array the datagram lies in; read, not kept.
520
+ * @param at The index in `datagram` of its first byte.
521
+ * @param len The datagram's length in bytes.
522
+ * @param address The client's address and port, as bytes; bound into a Retry token.
523
+ * @param now The caller's monotonic time in milliseconds; an earlier time than the last is taken as the
524
+ * last.
525
+ * @param answer Where the answer goes, overwritten each call and owned by the caller.
526
+ * @returns `answer.kind`: `QUIC_LISTEN_DROP`, `QUIC_LISTEN_ACCEPT`, `QUIC_LISTEN_VERSION_NEGOTIATION`,
527
+ * `QUIC_LISTEN_RETRY`, `QUIC_LISTEN_INVALID_TOKEN` or `QUIC_LISTEN_STATELESS_RESET`.
484
528
  */
485
529
  handleWindow(datagram: u8[], at: i32, len: i32, address: u8[], now: i64, answer: QuicListenerAnswer): i32 {
486
530
  if (!quicListenerWindowFits(toI32(datagram.length), at, len)) {
@@ -551,6 +595,11 @@ export class QuicListener {
551
595
  * made with exactly the room its reply takes: for a caller that keeps each
552
596
  * answer, at the cost of one `QuicListenerAnswer` a datagram. A carrier
553
597
  * makes one answer and calls `handleWindow`.
598
+ *
599
+ * @param datagram The whole datagram; read, not kept.
600
+ * @param address The client's address and port, as bytes.
601
+ * @param now The caller's monotonic time in milliseconds.
602
+ * @returns A new answer, the caller's to keep and, once done with, to wipe.
554
603
  */
555
604
  handle(datagram: u8[], address: u8[], now: i64): QuicListenerAnswer {
556
605
  const spare: QuicListenerAnswer = this.spare
@@ -580,7 +629,7 @@ export class QuicListener {
580
629
  * TODO(WP34 Q1): every other packet format is `nish/net/quic-packet`'s; this
581
630
  * belongs beside `quicRetryPacket` there, which this stage may not edit.
582
631
  */
583
- versionNegotiation(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
632
+ private versionNegotiation(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
584
633
  const unused: i32 = this.randomByte()
585
634
  const dcidLength: i32 = header.dcidLength
586
635
  const scidLength: i32 = header.scidLength
@@ -605,7 +654,7 @@ export class QuicListener {
605
654
  * first `QUIC_LISTENER_TOKEN_MAC_SIZE` bytes are the token's MAC; the
606
655
  * caller wipes `tag` once it has used them.
607
656
  */
608
- tokenMac(
657
+ private tokenMac(
609
658
  head: u8[],
610
659
  headAt: i32,
611
660
  headLength: i32,
@@ -640,7 +689,7 @@ export class QuicListener {
640
689
  * (compared in constant time), and it was issued no later than now and
641
690
  * less than `retryTokenLifetime` ago. The token is read in `datagram`.
642
691
  */
643
- tokenValid(datagram: u8[], header: QuicHeader, address: u8[]): boolean {
692
+ private tokenValid(datagram: u8[], header: QuicHeader, address: u8[]): boolean {
644
693
  const tokenAt: i32 = header.tokenStart
645
694
  const length: i32 = header.tokenLength
646
695
  if (length < QUIC_LISTENER_TOKEN_HEAD + QUIC_LISTENER_TOKEN_MAC_SIZE) {
@@ -677,7 +726,7 @@ export class QuicListener {
677
726
  * marker byte, the time, the DCID, then the MAC — under the integrity tag
678
727
  * of RFC 9001 §5.8. Each part is written where it goes in `reply`.
679
728
  */
680
- retry(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader, address: u8[]): void {
729
+ private retry(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader, address: u8[]): void {
681
730
  const scidLength: i32 = header.scidLength
682
731
  const odcidLength: i32 = header.dcidLength
683
732
  const retryScidAt: i32 = 7 + scidLength
@@ -714,7 +763,7 @@ export class QuicListener {
714
763
  * pseudo-packet and the AEAD's temporaries go with the arena block.
715
764
  * Answers whether it was made.
716
765
  */
717
- retryTag(reply: u8[], tagAt: i32, datagram: u8[], odcidAt: i32, odcidLength: i32): boolean {
766
+ private retryTag(reply: u8[], tagAt: i32, datagram: u8[], odcidAt: i32, odcidLength: i32): boolean {
718
767
  using _scope = arena()
719
768
  const pseudo: u8[] = new Array<u8>(1 + odcidLength + tagAt)
720
769
  quicListenerPutNumber(pseudo, 0, toI64(odcidLength), 1)
@@ -739,7 +788,7 @@ export class QuicListener {
739
788
  * own slots, the Initial is opened in an arena block, and the close is
740
789
  * written and sealed in `reply`.
741
790
  */
742
- invalidToken(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
791
+ private invalidToken(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
743
792
  const secrets: boolean = quicInitialSecretsInto(
744
793
  this.kdf,
745
794
  datagram,
@@ -815,7 +864,7 @@ export class QuicListener {
815
864
  }
816
865
 
817
866
  /** Whether the Initial `header` read in `datagram` opens under `read`; what opening it allocates goes with the arena block. */
818
- opens(read: QuicKeys, datagram: u8[], header: QuicHeader): boolean {
867
+ private opens(read: QuicKeys, datagram: u8[], header: QuicHeader): boolean {
819
868
  using _scope = arena()
820
869
  const packet: QuicPacket = this.packet
821
870
  const clear: u8[] = quicUnprotectHeader(read, datagram, header, -1, packet)
@@ -824,7 +873,7 @@ export class QuicListener {
824
873
  }
825
874
 
826
875
  /** Takes one stateless reset from the rate limit's budget, topping it up first. Answers whether one was there. */
827
- takeReset(): boolean {
876
+ private takeReset(): boolean {
828
877
  if (this.resetRefilled < 0) {
829
878
  this.resetRefilled = this.now
830
879
  this.resetBudget = QUIC_LISTENER_RESET_BURST
@@ -854,7 +903,13 @@ export class QuicListener {
854
903
  * shorter; a datagram too short for that to leave 21 bytes, or one past
855
904
  * the rate limit, gets nothing.
856
905
  */
857
- statelessReset(answer: QuicListenerAnswer, n: i32, datagram: u8[], dcidAt: i32, dcidLength: i32): void {
906
+ private statelessReset(
907
+ answer: QuicListenerAnswer,
908
+ n: i32,
909
+ datagram: u8[],
910
+ dcidAt: i32,
911
+ dcidLength: i32
912
+ ): void {
858
913
  if (n <= QUIC_LISTENER_MIN_RESET || !this.takeReset()) {
859
914
  return
860
915
  }
@@ -889,6 +944,10 @@ export class QuicListener {
889
944
  * but only when the connection's pacer has the credit for a full datagram
890
945
  * (RFC 9002 §7.7); `null` when it has not, or when nothing is due. The
891
946
  * datagram is charged to the pacer at its real size.
947
+ *
948
+ * @param conn The connection to send for.
949
+ * @param now The caller's time in milliseconds.
950
+ * @returns A new datagram to send, the caller's; or `null` when the pacer holds it back or nothing is due.
892
951
  */
893
952
  export const quicListenerTakePaced = (conn: QuicConnection, now: i64): u8[] | null => {
894
953
  if (conn.recovery.pacerDelay(now, QUIC_CONN_DATAGRAM_SIZE) > 0) {
@@ -904,6 +963,10 @@ export const quicListenerTakePaced = (conn: QuicConnection, now: i64): u8[] | nu
904
963
  /**
905
964
  * When `quicListenerTakePaced` next lets `conn` send a full datagram, in the
906
965
  * caller's milliseconds: `now` when it may already.
966
+ *
967
+ * @param conn The connection to ask about.
968
+ * @param now The caller's time in milliseconds.
969
+ * @returns A time in milliseconds, `now` or later. It says nothing of whether a datagram is due.
907
970
  */
908
971
  export const quicListenerPaceTime = (conn: QuicConnection, now: i64): i64 =>
909
972
  now + conn.recovery.pacerDelay(now, QUIC_CONN_DATAGRAM_SIZE)
@@ -922,6 +985,10 @@ const quicListenerQuantum = (conn: QuicConnection): i32 =>
922
985
  /**
923
986
  * When `quicListenerTakeFlight` next lets `conn` start a flight, in the
924
987
  * caller's milliseconds: `now` when it may already.
988
+ *
989
+ * @param conn The connection to ask about.
990
+ * @param now The caller's time in milliseconds.
991
+ * @returns A time in milliseconds, `now` or later. It says nothing of whether a datagram is due.
925
992
  */
926
993
  export const quicListenerFlightTime = (conn: QuicConnection, now: i64): i64 =>
927
994
  now + conn.recovery.pacerDelay(now, quicListenerQuantum(conn))
@@ -941,17 +1008,27 @@ export class QuicFlight {
941
1008
 
942
1009
  /**
943
1010
  * Writes the next flight `conn` sends at `now` into `buf[at .. at + cap)`,
944
- * datagram after datagram, for one GSO send, and answers its length in
945
- * bytes (0 for none); `flight` says how many datagrams it holds and the
946
- * segment size. A flight starts only once the pacer has the credit
947
- * `quicListenerFlightTime` waits for, a millisecond's earning of one to four
948
- * datagrams; then each datagram goes only when the pacer has credit for a
949
- * full one (RFC 9002 §7.7) and is charged at its real size, as
950
- * `quicListenerTakePaced` does, so the flight is the pacer's whole credit
951
- * and no more. It stops at the first datagram shorter than
952
- * `QUIC_CONN_DATAGRAM_SIZE`, which can only be the last of a segmented send,
953
- * at `QUIC_LISTENER_FLIGHT_MAX` datagrams, when `cap` has no room for
954
- * another, and before a datagram whose ECN codepoint would not be the first's.
1011
+ * datagram after datagram, for one GSO send, and answers its length in bytes (0
1012
+ * for none); `flight` says how many datagrams it holds and the segment size.
1013
+ *
1014
+ * A flight starts only once the pacer has the credit `quicListenerFlightTime`
1015
+ * waits for, a millisecond's earning of one to four datagrams; then each
1016
+ * datagram goes only when the pacer has credit for a full one (RFC 9002 §7.7)
1017
+ * and is charged at its real size, as `quicListenerTakePaced` does, so the
1018
+ * flight is the pacer's whole credit and no more. It stops at the first
1019
+ * datagram shorter than `QUIC_CONN_DATAGRAM_SIZE`, which can only be the last
1020
+ * of a segmented send, at `QUIC_LISTENER_FLIGHT_MAX` datagrams, when `cap` has
1021
+ * no room for another, and before a datagram whose ECN codepoint would not be
1022
+ * the first's.
1023
+ *
1024
+ * @param conn The connection to send for.
1025
+ * @param now The caller's time in milliseconds.
1026
+ * @param buf Where the flight is written.
1027
+ * @param at The index in `buf` of the flight's first byte.
1028
+ * @param cap The bytes of `buf` from `at` the flight may use; under `QUIC_CONN_DATAGRAM_SIZE` sends nothing.
1029
+ * @param flight Overwritten with the flight's datagram count, segment size and ECN codepoint; all 0
1030
+ * when nothing was written.
1031
+ * @returns The flight's length in bytes, or 0 when the pacer holds it back or nothing is due.
955
1032
  */
956
1033
  export const quicListenerTakeFlight = (
957
1034
  conn: QuicConnection,
@@ -1001,6 +1078,15 @@ export const quicListenerTakeFlight = (
1001
1078
  * `now`: one datagram when `segment` is 0, else a GRO receive cut every
1002
1079
  * `segment` bytes (the last may be shorter). Each is read in place. Answers
1003
1080
  * how many it handed over.
1081
+ *
1082
+ * @param conn The connection the datagrams belong to.
1083
+ * @param buf The receive buffer; read, not kept.
1084
+ * @param off The index in `buf` of the first byte received.
1085
+ * @param len The bytes received.
1086
+ * @param segment The GRO segment size in bytes, or 0 (or less) for a single datagram.
1087
+ * @param now The caller's time in milliseconds.
1088
+ * @returns How many datagrams were handed over: always 1 when `segment` is 0 or less, whatever `len`;
1089
+ * otherwise one per `segment` bytes of `len`, rounded up, which is 0 when `len` is 0 or less.
1004
1090
  */
1005
1091
  export const quicListenerReceiveSegments = (
1006
1092
  conn: QuicConnection,