@amritk/nish-aarch64-linux 0.34.1 → 0.36.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 (126) hide show
  1. package/INSTALL.md +22 -13
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +86 -16
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +49 -0
  6. package/runtime/async.mjs +27 -0
  7. package/runtime/nish.d.ts +4681 -427
  8. package/runtime/nish.h +6 -2
  9. package/runtime/nish.mjs +4 -0
  10. package/runtime/runtime-net.c +22 -0
  11. package/runtime/runtime-shm.c +93 -2
  12. package/runtime/vite.d.ts +30 -0
  13. package/runtime/vite.mjs +150 -0
  14. package/scripts/build.sh +108 -13
  15. package/std/README.md +131 -131
  16. package/std/base64.ts +34 -5
  17. package/std/bytes.ts +258 -42
  18. package/std/cli-args.ts +296 -70
  19. package/std/cli-flags.ts +184 -19
  20. package/std/cli.ts +475 -54
  21. package/std/collections.ts +121 -23
  22. package/std/compress/checksum.ts +44 -14
  23. package/std/compress/deflate.ts +224 -111
  24. package/std/compress/gzip.ts +217 -53
  25. package/std/compress/zlib.ts +63 -7
  26. package/std/crypto/aes.ts +80 -9
  27. package/std/crypto/base64url.ts +22 -0
  28. package/std/crypto/bcrypt-batch.ts +88 -21
  29. package/std/crypto/bcrypt.ts +60 -0
  30. package/std/crypto/chacha20poly1305.ts +53 -0
  31. package/std/crypto/ct.ts +32 -13
  32. package/std/crypto/ed25519.ts +47 -0
  33. package/std/crypto/hkdf.ts +198 -13
  34. package/std/crypto/hmac.ts +235 -31
  35. package/std/crypto/jwt.ts +192 -63
  36. package/std/crypto/p256.ts +159 -16
  37. package/std/crypto/p384.ts +28 -3
  38. package/std/crypto/pki-roots.ts +32 -2
  39. package/std/crypto/pki.ts +81 -15
  40. package/std/crypto/rsa.ts +33 -3
  41. package/std/crypto/sha1.ts +3 -0
  42. package/std/crypto/sha256.ts +24 -1
  43. package/std/crypto/sha512.ts +99 -14
  44. package/std/crypto/x25519.ts +152 -14
  45. package/std/crypto/x509-random.ts +10 -0
  46. package/std/crypto/x509.ts +67 -7
  47. package/std/json-equal.ts +19 -0
  48. package/std/json-format.ts +112 -13
  49. package/std/json-number.ts +64 -14
  50. package/std/json-pointer.ts +23 -1
  51. package/std/json-tokenizer.ts +100 -29
  52. package/std/json-typed.ts +713 -66
  53. package/std/json-value.ts +400 -124
  54. package/std/json.ts +138 -10
  55. package/std/map.ts +25 -7
  56. package/std/math.ts +36 -4
  57. package/std/net/buffer-pool.ts +42 -11
  58. package/std/net/dns-config.ts +109 -23
  59. package/std/net/dns-message.ts +62 -7
  60. package/std/net/dns-resolver.ts +247 -53
  61. package/std/net/dns.ts +203 -35
  62. package/std/net/fetch.ts +151 -61
  63. package/std/net/handler.ts +278 -80
  64. package/std/net/hpack.ts +262 -52
  65. package/std/net/http-compress.ts +125 -15
  66. package/std/net/http-fields.ts +85 -9
  67. package/std/net/http1-client-codec.ts +100 -19
  68. package/std/net/http1-codec.ts +297 -77
  69. package/std/net/http1-server.ts +430 -94
  70. package/std/net/http2-frame.ts +272 -35
  71. package/std/net/http2-tls.ts +135 -34
  72. package/std/net/http2.ts +247 -106
  73. package/std/net/http3-frame.ts +154 -17
  74. package/std/net/http3-server.ts +275 -101
  75. package/std/net/http3.ts +307 -115
  76. package/std/net/outbound.ts +37 -3
  77. package/std/net/postgres-carrier.ts +144 -8
  78. package/std/net/postgres.ts +801 -112
  79. package/std/net/prefork.ts +164 -31
  80. package/std/net/qpack.ts +105 -18
  81. package/std/net/quic-conn-ack.ts +59 -12
  82. package/std/net/quic-conn-cid.ts +124 -27
  83. package/std/net/quic-conn-params.ts +70 -10
  84. package/std/net/quic-datagram.ts +43 -3
  85. package/std/net/quic-frame.ts +286 -12
  86. package/std/net/quic-listener.ts +101 -32
  87. package/std/net/quic-packet.ts +302 -21
  88. package/std/net/quic-recovery.ts +264 -52
  89. package/std/net/quic-stream.ts +353 -91
  90. package/std/net/quic.ts +1124 -201
  91. package/std/net/router.ts +87 -40
  92. package/std/net/tls/client.ts +166 -51
  93. package/std/net/tls/codec.ts +413 -56
  94. package/std/net/tls/record-client.ts +110 -55
  95. package/std/net/tls/record-server.ts +159 -59
  96. package/std/net/tls/record.ts +109 -12
  97. package/std/net/tls/schedule.ts +235 -26
  98. package/std/net/tls/ticket.ts +159 -40
  99. package/std/net/tls/verify.ts +49 -3
  100. package/std/net/tls-tcp.ts +250 -45
  101. package/std/net/tls.ts +221 -59
  102. package/std/net/upstream.ts +81 -45
  103. package/std/net/url.ts +97 -13
  104. package/std/net/websocket.ts +122 -12
  105. package/std/net/webtransport.ts +220 -89
  106. package/std/pair.ts +10 -2
  107. package/std/random.ts +34 -9
  108. package/std/regex.ts +352 -198
  109. package/std/region.ts +70 -15
  110. package/std/secret.ts +52 -11
  111. package/std/sort.ts +17 -2
  112. package/std/sqlite.ts +256 -35
  113. package/std/sync/ring.ts +430 -40
  114. package/std/sync/shm.ts +222 -15
  115. package/std/term-io.ts +137 -64
  116. package/std/term-pixels.ts +144 -19
  117. package/std/term-probe.ts +66 -25
  118. package/std/term-rate.ts +128 -57
  119. package/std/term.ts +332 -121
  120. package/std/testing.ts +130 -32
  121. package/std/text.ts +73 -7
  122. package/std/threads.ts +229 -41
  123. package/std/yaml-json.ts +94 -82
  124. package/std/yaml-lines.ts +47 -15
  125. package/std/yaml-write.ts +24 -16
  126. 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,7 +35,7 @@
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
+ * **Retry tokens** (§8.1.4). They are this server's own format: a marker byte, the
38
39
  * 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
41
  * `retryTokenKey` over all of that, the Retry's Source Connection ID (which
@@ -46,7 +47,7 @@
46
47
  * INVALID_TOKEN (§8.1.2); a token without the marker, which some other
47
48
  * server issued, is treated as no token at all (§8.1.3).
48
49
  *
49
- * **Stateless resets** (§10.3) end in the token `quicStatelessResetToken`
50
+ * **Stateless resets** (§10.3). They end in the token `quicStatelessResetToken`
50
51
  * derives (computed in place, by `quicConnResetTokenInto`) from the configuration's static key and the packet's connection
51
52
  * ID, so a server that restarted with the same key can end the connections
52
53
  * it lost. RFC 9000 §10.3 and §10.3.3 bound them, and each bound is held
@@ -59,7 +60,7 @@
59
60
  * `QUIC_LISTENER_RESET_INTERVAL` milliseconds. Each reset's other bytes are
60
61
  * unpredictable, from the listener's own generator.
61
62
  *
62
- * **Pacing** (RFC 9002 §7.7) is the carrier's send loop, so it is here
63
+ * **Pacing** (RFC 9002 §7.7). It is the carrier's send loop, so it is here
63
64
  * beside the rest of what the carrier calls: `quicListenerTakePaced` takes a
64
65
  * connection's next datagram only when its pacer has the credit for it, and
65
66
  * `quicListenerPaceTime` says when it will. The pacer earns 5/4 of the
@@ -227,8 +228,15 @@ export class QuicListenerAnswer {
227
228
  retryScid: u8[]
228
229
  kind: i32 = 0
229
230
  retried: boolean = false
230
- room: i32 = 0
231
+ private room: i32 = 0
231
232
 
233
+ /**
234
+ * An empty answer with room for a reply of `room` bytes.
235
+ *
236
+ * @param room The bytes reserved for `reply`, usually `QUIC_LISTENER_ANSWER_SIZE`; 0 or less reserves
237
+ * none. `originalDcid` and `retryScid` get room for `QUIC_MAX_CID_LENGTH` (20) bytes each whatever it
238
+ * is. That is capacity: all three start empty, their lengths 0 until an answer or `wipe` sets them.
239
+ */
232
240
  constructor(room: i32) {
233
241
  this.room = room > 0 ? room : 0
234
242
  this.reply = quicListenerRoom(this.room)
@@ -242,7 +250,8 @@ export class QuicListenerAnswer {
242
250
  * leave no copy beyond the arrays' lengths either. Each is left that long
243
251
  * and all zero, `kind` a drop. An answer whose reply grew past its room
244
252
  * keeps what lies beyond the longest length it is wiped at; one made with
245
- * `QUIC_LISTENER_ANSWER_SIZE` never grows.
253
+ * `QUIC_LISTENER_ANSWER_SIZE` never grows. The caller's to call once it
254
+ * has sent the answer `QuicListener.handle` gave, and before it drops it.
246
255
  */
247
256
  wipe(): void {
248
257
  quicListenerWipeRoom(this.reply, this.room)
@@ -332,49 +341,58 @@ const quicListenerWindowFits = (length: i32, at: i32, len: i32): boolean =>
332
341
  * `handleWindow` reads the datagram where it lies and keeps nothing.
333
342
  */
334
343
  export class QuicListener {
335
- config: QuicServerConfig
344
+ private config: QuicServerConfig
336
345
  seed: u8[]
337
346
  /** Unpredictable bytes not yet used, from `poolHead`, and the counter the next block is made from. */
338
347
  pool: u8[]
339
348
  /** The counter's eight bytes, the generator's HMAC message. */
340
- block: u8[]
349
+ private block: u8[]
341
350
  /** What `handleWindow` parses a datagram's header into, in place. */
342
- header: QuicHeader
351
+ private header: QuicHeader
343
352
  /** Every HMAC and HKDF the listener computes runs here; its `sha256` makes tokens, resets and the generator's blocks. */
344
353
  kdf: HkdfScratch
345
354
  /** A full HMAC-SHA256 tag, wiped once its 16 bytes are used. */
346
355
  tag: u8[]
347
356
  /** A Retry token MAC's length fields: the Retry SCID's one byte, the address's four. */
348
- lengths: u8[]
357
+ private lengths: u8[]
349
358
  /** The Initial secrets of an INVALID_TOKEN close, and its keys, both directions. */
350
359
  initialClient: u8[]
351
360
  initialServer: u8[]
352
361
  readSlot: QuicKeysSlot
353
362
  writeSlot: QuicKeysSlot
354
- packet: QuicPacket
363
+ private packet: QuicPacket
355
364
  /** 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[]
365
+ private peerCid: u8[]
366
+ private ownCid: u8[]
358
367
  /** An empty array: the INVALID_TOKEN close's token and reason. */
359
- none: u8[]
368
+ private none: u8[]
360
369
  /** Version 1's fixed Retry key (RFC 9001 §5.8), expanded once. */
361
- retryKey: AesKey
370
+ private retryKey: AesKey
362
371
  /** What `handle` answers into before it copies the answer out. */
363
372
  spare: QuicListenerAnswer
364
- counter: i64 = 0
373
+ private counter: i64 = 0
365
374
  /** The latest time the caller gave, in milliseconds; time never runs backwards here. */
366
- now: i64 = 0
375
+ private now: i64 = 0
367
376
  /** 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
377
+ private resetRefilled: i64 = -1
378
+ private resetBudget: i32 = 0
370
379
  poolHead: i32 = 0
371
380
  /** Stateless resets sent, and ones the rate limit held back. */
372
381
  resetsSent: i32 = 0
373
382
  resetsLimited: i32 = 0
374
383
  /** Whether the configuration and entropy were usable. */
375
- usable: boolean = false
384
+ private usable: boolean = false
376
385
 
377
- /** A listener under `config`; `entropy`'s `QUIC_LISTENER_ENTROPY_SIZE` bytes are copied, then wiped in the caller's array. */
386
+ /**
387
+ * A listener under `config`; `entropy`'s `QUIC_LISTENER_ENTROPY_SIZE` bytes are copied, then wiped in
388
+ * the caller's array.
389
+ *
390
+ * @param config The server's configuration, kept by reference: its static keys and Retry token lifetime.
391
+ * Keys of the wrong size, or a lifetime outside 1 to `QUIC_LISTENER_MAX_TOKEN_LIFETIME` ms, make a
392
+ * listener that drops every datagram.
393
+ * @param entropy `QUIC_LISTENER_ENTROPY_SIZE` (32) random bytes, the seed of every unpredictable byte
394
+ * the listener sends. Zeroed on return; any other length makes a listener that drops every datagram.
395
+ */
378
396
  constructor(config: QuicServerConfig, entropy: u8[]) {
379
397
  this.config = config
380
398
  this.seed = new Array<u8>(QUIC_LISTENER_ENTROPY_SIZE)
@@ -434,7 +452,7 @@ export class QuicListener {
434
452
  * One unpredictable value in 0 to 255: the next byte of HMAC-SHA256 under
435
453
  * the seed of a counter, a block at a time, each byte wiped once taken.
436
454
  */
437
- randomByte(): i32 {
455
+ private randomByte(): i32 {
438
456
  if (this.poolHead >= QUIC_LISTENER_POOL) {
439
457
  this.refill()
440
458
  }
@@ -448,7 +466,7 @@ export class QuicListener {
448
466
  }
449
467
 
450
468
  /** Writes `count` unpredictable bytes into `out` at `at`. */
451
- randomInto(out: u8[], at: i32, count: i32): void {
469
+ private randomInto(out: u8[], at: i32, count: i32): void {
452
470
  for (let k: i32 = 0; k < count; k += 1) {
453
471
  const b: i32 = this.randomByte()
454
472
  if (at + k >= 0 && at + k < toI32(out.length)) {
@@ -458,7 +476,7 @@ export class QuicListener {
458
476
  }
459
477
 
460
478
  /** The generator's next block, HMAC-SHA256 under the seed of the counter, into `pool`. */
461
- refill(): void {
479
+ private refill(): void {
462
480
  quicListenerPutNumber(this.block, 0, this.counter, QUIC_LISTENER_BLOCK)
463
481
  this.counter = this.counter + 1
464
482
  const mac: HmacSha256Scratch = this.kdf.sha256
@@ -481,6 +499,16 @@ export class QuicListener {
481
499
  * the module header for the rules; nothing a peer sends makes it panic,
482
500
  * and nothing it does keeps arena memory. A window outside `datagram` is
483
501
  * the caller's mistake, and panics.
502
+ *
503
+ * @param datagram The array the datagram lies in; read, not kept.
504
+ * @param at The index in `datagram` of its first byte.
505
+ * @param len The datagram's length in bytes.
506
+ * @param address The client's address and port, as bytes; bound into a Retry token.
507
+ * @param now The caller's monotonic time in milliseconds; an earlier time than the last is taken as the
508
+ * last.
509
+ * @param answer Where the answer goes, overwritten each call and owned by the caller.
510
+ * @returns `answer.kind`: `QUIC_LISTEN_DROP`, `QUIC_LISTEN_ACCEPT`, `QUIC_LISTEN_VERSION_NEGOTIATION`,
511
+ * `QUIC_LISTEN_RETRY`, `QUIC_LISTEN_INVALID_TOKEN` or `QUIC_LISTEN_STATELESS_RESET`.
484
512
  */
485
513
  handleWindow(datagram: u8[], at: i32, len: i32, address: u8[], now: i64, answer: QuicListenerAnswer): i32 {
486
514
  if (!quicListenerWindowFits(toI32(datagram.length), at, len)) {
@@ -551,6 +579,11 @@ export class QuicListener {
551
579
  * made with exactly the room its reply takes: for a caller that keeps each
552
580
  * answer, at the cost of one `QuicListenerAnswer` a datagram. A carrier
553
581
  * makes one answer and calls `handleWindow`.
582
+ *
583
+ * @param datagram The whole datagram; read, not kept.
584
+ * @param address The client's address and port, as bytes.
585
+ * @param now The caller's monotonic time in milliseconds.
586
+ * @returns A new answer, the caller's to keep and, once done with, to wipe.
554
587
  */
555
588
  handle(datagram: u8[], address: u8[], now: i64): QuicListenerAnswer {
556
589
  const spare: QuicListenerAnswer = this.spare
@@ -580,7 +613,7 @@ export class QuicListener {
580
613
  * TODO(WP34 Q1): every other packet format is `nish/net/quic-packet`'s; this
581
614
  * belongs beside `quicRetryPacket` there, which this stage may not edit.
582
615
  */
583
- versionNegotiation(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
616
+ private versionNegotiation(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
584
617
  const unused: i32 = this.randomByte()
585
618
  const dcidLength: i32 = header.dcidLength
586
619
  const scidLength: i32 = header.scidLength
@@ -605,7 +638,7 @@ export class QuicListener {
605
638
  * first `QUIC_LISTENER_TOKEN_MAC_SIZE` bytes are the token's MAC; the
606
639
  * caller wipes `tag` once it has used them.
607
640
  */
608
- tokenMac(
641
+ private tokenMac(
609
642
  head: u8[],
610
643
  headAt: i32,
611
644
  headLength: i32,
@@ -640,7 +673,7 @@ export class QuicListener {
640
673
  * (compared in constant time), and it was issued no later than now and
641
674
  * less than `retryTokenLifetime` ago. The token is read in `datagram`.
642
675
  */
643
- tokenValid(datagram: u8[], header: QuicHeader, address: u8[]): boolean {
676
+ private tokenValid(datagram: u8[], header: QuicHeader, address: u8[]): boolean {
644
677
  const tokenAt: i32 = header.tokenStart
645
678
  const length: i32 = header.tokenLength
646
679
  if (length < QUIC_LISTENER_TOKEN_HEAD + QUIC_LISTENER_TOKEN_MAC_SIZE) {
@@ -677,7 +710,7 @@ export class QuicListener {
677
710
  * marker byte, the time, the DCID, then the MAC — under the integrity tag
678
711
  * of RFC 9001 §5.8. Each part is written where it goes in `reply`.
679
712
  */
680
- retry(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader, address: u8[]): void {
713
+ private retry(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader, address: u8[]): void {
681
714
  const scidLength: i32 = header.scidLength
682
715
  const odcidLength: i32 = header.dcidLength
683
716
  const retryScidAt: i32 = 7 + scidLength
@@ -714,7 +747,7 @@ export class QuicListener {
714
747
  * pseudo-packet and the AEAD's temporaries go with the arena block.
715
748
  * Answers whether it was made.
716
749
  */
717
- retryTag(reply: u8[], tagAt: i32, datagram: u8[], odcidAt: i32, odcidLength: i32): boolean {
750
+ private retryTag(reply: u8[], tagAt: i32, datagram: u8[], odcidAt: i32, odcidLength: i32): boolean {
718
751
  using _scope = arena()
719
752
  const pseudo: u8[] = new Array<u8>(1 + odcidLength + tagAt)
720
753
  quicListenerPutNumber(pseudo, 0, toI64(odcidLength), 1)
@@ -739,7 +772,7 @@ export class QuicListener {
739
772
  * own slots, the Initial is opened in an arena block, and the close is
740
773
  * written and sealed in `reply`.
741
774
  */
742
- invalidToken(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
775
+ private invalidToken(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
743
776
  const secrets: boolean = quicInitialSecretsInto(
744
777
  this.kdf,
745
778
  datagram,
@@ -815,7 +848,7 @@ export class QuicListener {
815
848
  }
816
849
 
817
850
  /** 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 {
851
+ private opens(read: QuicKeys, datagram: u8[], header: QuicHeader): boolean {
819
852
  using _scope = arena()
820
853
  const packet: QuicPacket = this.packet
821
854
  const clear: u8[] = quicUnprotectHeader(read, datagram, header, -1, packet)
@@ -824,7 +857,7 @@ export class QuicListener {
824
857
  }
825
858
 
826
859
  /** Takes one stateless reset from the rate limit's budget, topping it up first. Answers whether one was there. */
827
- takeReset(): boolean {
860
+ private takeReset(): boolean {
828
861
  if (this.resetRefilled < 0) {
829
862
  this.resetRefilled = this.now
830
863
  this.resetBudget = QUIC_LISTENER_RESET_BURST
@@ -854,7 +887,13 @@ export class QuicListener {
854
887
  * shorter; a datagram too short for that to leave 21 bytes, or one past
855
888
  * the rate limit, gets nothing.
856
889
  */
857
- statelessReset(answer: QuicListenerAnswer, n: i32, datagram: u8[], dcidAt: i32, dcidLength: i32): void {
890
+ private statelessReset(
891
+ answer: QuicListenerAnswer,
892
+ n: i32,
893
+ datagram: u8[],
894
+ dcidAt: i32,
895
+ dcidLength: i32
896
+ ): void {
858
897
  if (n <= QUIC_LISTENER_MIN_RESET || !this.takeReset()) {
859
898
  return
860
899
  }
@@ -889,6 +928,10 @@ export class QuicListener {
889
928
  * but only when the connection's pacer has the credit for a full datagram
890
929
  * (RFC 9002 §7.7); `null` when it has not, or when nothing is due. The
891
930
  * datagram is charged to the pacer at its real size.
931
+ *
932
+ * @param conn The connection to send for.
933
+ * @param now The caller's time in milliseconds.
934
+ * @returns A new datagram to send, the caller's; or `null` when the pacer holds it back or nothing is due.
892
935
  */
893
936
  export const quicListenerTakePaced = (conn: QuicConnection, now: i64): u8[] | null => {
894
937
  if (conn.recovery.pacerDelay(now, QUIC_CONN_DATAGRAM_SIZE) > 0) {
@@ -904,6 +947,10 @@ export const quicListenerTakePaced = (conn: QuicConnection, now: i64): u8[] | nu
904
947
  /**
905
948
  * When `quicListenerTakePaced` next lets `conn` send a full datagram, in the
906
949
  * caller's milliseconds: `now` when it may already.
950
+ *
951
+ * @param conn The connection to ask about.
952
+ * @param now The caller's time in milliseconds.
953
+ * @returns A time in milliseconds, `now` or later. It says nothing of whether a datagram is due.
907
954
  */
908
955
  export const quicListenerPaceTime = (conn: QuicConnection, now: i64): i64 =>
909
956
  now + conn.recovery.pacerDelay(now, QUIC_CONN_DATAGRAM_SIZE)
@@ -922,6 +969,10 @@ const quicListenerQuantum = (conn: QuicConnection): i32 =>
922
969
  /**
923
970
  * When `quicListenerTakeFlight` next lets `conn` start a flight, in the
924
971
  * caller's milliseconds: `now` when it may already.
972
+ *
973
+ * @param conn The connection to ask about.
974
+ * @param now The caller's time in milliseconds.
975
+ * @returns A time in milliseconds, `now` or later. It says nothing of whether a datagram is due.
925
976
  */
926
977
  export const quicListenerFlightTime = (conn: QuicConnection, now: i64): i64 =>
927
978
  now + conn.recovery.pacerDelay(now, quicListenerQuantum(conn))
@@ -952,6 +1003,15 @@ export class QuicFlight {
952
1003
  * `QUIC_CONN_DATAGRAM_SIZE`, which can only be the last of a segmented send,
953
1004
  * at `QUIC_LISTENER_FLIGHT_MAX` datagrams, when `cap` has no room for
954
1005
  * another, and before a datagram whose ECN codepoint would not be the first's.
1006
+ *
1007
+ * @param conn The connection to send for.
1008
+ * @param now The caller's time in milliseconds.
1009
+ * @param buf Where the flight is written.
1010
+ * @param at The index in `buf` of the flight's first byte.
1011
+ * @param cap The bytes of `buf` from `at` the flight may use; under `QUIC_CONN_DATAGRAM_SIZE` sends nothing.
1012
+ * @param flight Overwritten with the flight's datagram count, segment size and ECN codepoint; all 0
1013
+ * when nothing was written.
1014
+ * @returns The flight's length in bytes, or 0 when the pacer holds it back or nothing is due.
955
1015
  */
956
1016
  export const quicListenerTakeFlight = (
957
1017
  conn: QuicConnection,
@@ -1001,6 +1061,15 @@ export const quicListenerTakeFlight = (
1001
1061
  * `now`: one datagram when `segment` is 0, else a GRO receive cut every
1002
1062
  * `segment` bytes (the last may be shorter). Each is read in place. Answers
1003
1063
  * how many it handed over.
1064
+ *
1065
+ * @param conn The connection the datagrams belong to.
1066
+ * @param buf The receive buffer; read, not kept.
1067
+ * @param off The index in `buf` of the first byte received.
1068
+ * @param len The bytes received.
1069
+ * @param segment The GRO segment size in bytes, or 0 (or less) for a single datagram.
1070
+ * @param now The caller's time in milliseconds.
1071
+ * @returns How many datagrams were handed over: always 1 when `segment` is 0 or less, whatever `len`;
1072
+ * otherwise one per `segment` bytes of `len`, rounded up, which is 0 when `len` is 0 or less.
1004
1073
  */
1005
1074
  export const quicListenerReceiveSegments = (
1006
1075
  conn: QuicConnection,