@amritk/nish-aarch64-linux 0.36.0 → 0.38.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 (103) hide show
  1. package/INSTALL.md +92 -71
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +75 -14
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/core/arrays.d.ts +4 -0
  8. package/runtime/core/arrays.mjs +33 -0
  9. package/runtime/nish.d.ts +1045 -512
  10. package/runtime/nish.h +53 -6
  11. package/runtime/page.d.ts +53 -0
  12. package/runtime/page.mjs +146 -0
  13. package/runtime/runtime-async.c +740 -0
  14. package/runtime/runtime-cross.c +2 -1
  15. package/runtime/runtime-region.c +85 -7
  16. package/runtime/runtime-text.c +1068 -0
  17. package/runtime/runtime-wasm.c +65 -9
  18. package/runtime/runtime.c +50 -961
  19. package/runtime/vite.mjs +48 -11
  20. package/scripts/build.sh +231 -31
  21. package/std/LICENSE-fdlibm +8 -0
  22. package/std/README.md +109 -82
  23. package/std/array.ts +266 -0
  24. package/std/bytes.ts +23 -19
  25. package/std/compress/checksum.ts +1 -1
  26. package/std/crypto/aes.ts +48 -43
  27. package/std/crypto/base64url.ts +7 -5
  28. package/std/crypto/bcrypt-batch.ts +13 -13
  29. package/std/crypto/bcrypt.ts +33 -27
  30. package/std/crypto/chacha20poly1305.ts +16 -14
  31. package/std/crypto/ed25519.ts +19 -16
  32. package/std/crypto/hmac.ts +7 -6
  33. package/std/crypto/jwt.ts +23 -20
  34. package/std/crypto/p256.ts +63 -56
  35. package/std/crypto/p384.ts +23 -20
  36. package/std/crypto/pki.ts +18 -15
  37. package/std/crypto/rsa.ts +23 -19
  38. package/std/crypto/x25519.ts +11 -10
  39. package/std/crypto/x509.ts +69 -62
  40. package/std/host/ring.ts +124 -0
  41. package/std/host/text.ts +86 -0
  42. package/std/json-equal.ts +12 -11
  43. package/std/json-number.ts +12 -12
  44. package/std/json-tokenizer.ts +26 -22
  45. package/std/json-typed.ts +92 -78
  46. package/std/json-value.ts +38 -33
  47. package/std/json.ts +32 -28
  48. package/std/math.ts +743 -41
  49. package/std/net/dns-resolver.ts +46 -6
  50. package/std/net/dns.ts +50 -13
  51. package/std/net/fetch.ts +1744 -295
  52. package/std/net/handler.ts +30 -0
  53. package/std/net/hpack.ts +29 -26
  54. package/std/net/http-compress.ts +42 -28
  55. package/std/net/http-fields.ts +19 -4
  56. package/std/net/http1-client-codec.ts +29 -25
  57. package/std/net/http1-codec.ts +62 -91
  58. package/std/net/http1-server.ts +79 -57
  59. package/std/net/http2-frame.ts +17 -16
  60. package/std/net/http2-tls.ts +17 -15
  61. package/std/net/http2.ts +67 -54
  62. package/std/net/http3-frame.ts +11 -10
  63. package/std/net/http3-server.ts +36 -35
  64. package/std/net/http3.ts +70 -58
  65. package/std/net/postgres-async.ts +1005 -0
  66. package/std/net/postgres.ts +185 -164
  67. package/std/net/prefork.ts +38 -34
  68. package/std/net/qpack.ts +15 -14
  69. package/std/net/quic-conn-ack.ts +1 -0
  70. package/std/net/quic-conn-cid.ts +11 -0
  71. package/std/net/quic-conn-params.ts +41 -14
  72. package/std/net/quic-datagram.ts +7 -0
  73. package/std/net/quic-frame.ts +48 -12
  74. package/std/net/quic-listener.ts +61 -44
  75. package/std/net/quic-packet.ts +71 -52
  76. package/std/net/quic-recovery.ts +59 -21
  77. package/std/net/quic-stream.ts +83 -55
  78. package/std/net/quic.ts +204 -152
  79. package/std/net/serve.ts +763 -0
  80. package/std/net/tls/client.ts +1 -0
  81. package/std/net/tls/codec.ts +81 -12
  82. package/std/net/tls/record-client.ts +30 -18
  83. package/std/net/tls/record-server.ts +74 -46
  84. package/std/net/tls/record.ts +33 -24
  85. package/std/net/tls/ticket.ts +2 -0
  86. package/std/net/tls/verify.ts +8 -7
  87. package/std/net/tls-tcp.ts +58 -50
  88. package/std/net/tls.ts +55 -43
  89. package/std/net/url.ts +12 -9
  90. package/std/net/websocket.ts +23 -19
  91. package/std/net/webtransport.ts +24 -18
  92. package/std/random.ts +8 -6
  93. package/std/regex.ts +70 -59
  94. package/std/sync/ring.ts +24 -21
  95. package/std/sync/shm.ts +9 -7
  96. package/std/term-io.ts +17 -14
  97. package/std/term-probe.ts +11 -10
  98. package/std/term-rate.ts +71 -61
  99. package/std/term.ts +73 -59
  100. package/std/text.ts +242 -15
  101. package/std/threads.ts +19 -15
  102. package/std/yaml-json.ts +17 -15
  103. package/std/yaml-write.ts +21 -14
@@ -14,15 +14,16 @@
14
14
  * if (now >= recovery.deadline(blocked)) { recovery.onTimeout(now, blocked); }
15
15
  *
16
16
  * **What it tracks.** Each space keeps its ack-eliciting packets in a fixed
17
- * ring (`QuicSentPackets`), in the order they were sent, so the memory is
18
- * fixed when the connection is made and nothing is allocated per packet. A
19
- * packet that elicits no acknowledgement (one that carries only ACK, PADDING
20
- * or CONNECTION_CLOSE) is not recorded: it is never in flight, and neither
21
- * an RTT sample nor a loss is ever taken from it (RFC 9002 §2, §5.1). The
22
- * caller keeps what each packet carried in its own arrays, indexed by the
23
- * slot `onPacketSent` answers, and reads `acked` and `lost` after each
24
- * `onAck` and `onTimeout` to learn which slots were settled. A slot named
25
- * there keeps its packet number, time and size until the next call.
17
+ * ring (`QuicSentPackets`), in the order they were sent, so the memory is fixed
18
+ * when the connection is made and nothing is allocated per packet. A packet
19
+ * that elicits no acknowledgement (one that carries only ACK, PADDING or
20
+ * CONNECTION_CLOSE) is not recorded: it is never in flight, and neither an RTT
21
+ * sample nor a loss is ever taken from it (RFC 9002 §2, §5.1).
22
+ *
23
+ * The caller keeps what each packet carried in its own arrays, indexed by the
24
+ * slot `onPacketSent` answers, and reads `acked` and `lost` after each `onAck`
25
+ * and `onTimeout` to learn which slots were settled. A slot named there keeps
26
+ * its packet number, time and size until the next call.
26
27
  *
27
28
  * **Time and units.** Every time and every duration is the caller's
28
29
  * monotonic clock in milliseconds, which is also the timer granularity
@@ -52,18 +53,21 @@
52
53
  * **ECN** (§7.1, B.7; RFC 9000 §13.4.2 and its Appendix A.4). A caller that
53
54
  * marks its packets ECT(0) asks `ecnCodepoint()` what to mark with, says so
54
55
  * with `onEctSent` for every packet it marked, and hands an ACK_ECN frame's
55
- * counts to `onAckEcn`. The counts are validated against the packets marked
56
- * before they are used: an ACK that newly acknowledges a marked packet
57
- * without counts, a count that falls, counts past the packets marked, or an
58
- * increase in ECT(0) and ECN-CE short of the marked packets newly
59
- * acknowledged fails validation, as does every packet of the testing period
60
- * being lost, and a failed path is marked no more (`QUIC_RECOVERY_ECN_FAILED`).
61
- * Only the first `QUIC_RECOVERY_ECN_TESTING_PACKETS` are marked until one
62
- * validates. A rise in the ECN-CE count is a congestion event, from the
63
- * largest packet newly acknowledged, so it halves the window once per
64
- * recovery period as a loss does. Counts that arrive with an ACK that does
65
- * not raise the largest acknowledged are neither validated nor used: they
66
- * may be older than those already read.
56
+ * counts to `onAckEcn`.
57
+ *
58
+ * The counts are validated against the packets marked before they are used: an
59
+ * ACK that newly acknowledges a marked packet without counts, a count that
60
+ * falls, counts past the packets marked, or an increase in ECT(0) and ECN-CE
61
+ * short of the marked packets newly acknowledged fails validation, as does
62
+ * every packet of the testing period being lost, and a failed path is marked no
63
+ * more (`QUIC_RECOVERY_ECN_FAILED`). Only the first
64
+ * `QUIC_RECOVERY_ECN_TESTING_PACKETS` are marked until one validates.
65
+ *
66
+ * A rise in the ECN-CE count is a congestion event, from the largest packet
67
+ * newly acknowledged, so it halves the window once per recovery period as a
68
+ * loss does. Counts that arrive with an ACK that does not raise the largest
69
+ * acknowledged are neither validated nor used: they may be older than those
70
+ * already read.
67
71
  *
68
72
  * **What a peer cannot do.** Every input is checked: the ranges of an
69
73
  * acknowledgement are read only up to the count given and the array's
@@ -180,10 +184,16 @@ const quicRecoveryMax = (a: i64, b: i64): i64 => (a > b ? a : b)
180
184
  * acknowledged (§7.6.2).
181
185
  */
182
186
  export class QuicSentPackets {
187
+ /** @internal Read only by this module; `pnAt` answers for a slot. */
183
188
  pn: i64[]
189
+ /**
190
+ * When each slot's packet was sent, the `now` `onPacketSent` was given, in milliseconds;
191
+ * loss detection and RTT samples read it.
192
+ */
184
193
  timeSent: i64[]
185
194
  /** When each packet was sent on the pacer's clock, in microseconds. */
186
195
  fineSent: i64[]
196
+ /** @internal Read only by this module: each slot's packet size in bytes, for the congestion window. */
187
197
  size: i32[]
188
198
  /** Each slot's state, with `QUIC_RECOVERY_MARKED` set if its packet was sent marked ECT(0). */
189
199
  state: u8[]
@@ -203,16 +213,24 @@ export class QuicSentPackets {
203
213
  bytesInFlight: i64 = 0
204
214
  private capacity: i32 = 0
205
215
  private head: i32 = 0
216
+ /**
217
+ * How many packets the ring keeps, in flight and settled; a test reads it to see what a flight
218
+ * recorded.
219
+ */
206
220
  count: i32 = 0
207
221
  /** How many recorded packets are still in flight: neither acknowledged nor lost. */
208
222
  inFlight: i32 = 0
223
+ /** @internal Read by `net/quic.ts`: how many slots of `acked` the last `onAck` filled. */
209
224
  ackedCount: i32 = 0
225
+ /** How many slots of `lost` the last `onAck` or `onTimeout` filled. */
210
226
  lostCount: i32 = 0
211
227
  /** How many of this space's packets, recorded or not, were sent marked ECT(0). */
212
228
  ectSent: i64 = 0
213
229
  /** The ECN counts of the last ACK_ECN frame validated in this space (RFC 9000 §19.3.2). */
214
230
  ect0: i64 = 0
231
+ /** The ECT(1) count of the last ACK_ECN frame validated in this space. */
215
232
  ect1: i64 = 0
233
+ /** The ECN-CE count of the last ACK_ECN frame validated in this space; a rise is a congestion event. */
216
234
  ce: i64 = 0
217
235
 
218
236
  /**
@@ -474,6 +492,10 @@ const quicRecoveryInRanges = (ranges: i64[], count: i32, pn: i64): boolean => {
474
492
  * counts a test or a log reads (`congestionEvents`, `persistentCongestions`).
475
493
  */
476
494
  export class QuicRecovery {
495
+ /**
496
+ * The sent-packet ring of each packet number space, indexed by `QUIC_RECOVERY_INITIAL` and its
497
+ * siblings.
498
+ */
477
499
  spaces: QuicSentPackets[]
478
500
  /** latest_rtt (§5.1): the last sample, in milliseconds. */
479
501
  latestRtt: i64 = 0
@@ -495,6 +517,10 @@ export class QuicRecovery {
495
517
  recoveryStart: i64 = -1
496
518
  /** The pacer's credit in bytes (§7.7), and the time it was last topped up in microseconds, or -1. */
497
519
  pacerBudget: i64 = 0
520
+ /**
521
+ * When the pacer's credit was last topped up, in microseconds on the pacer's clock, or -1 before the
522
+ * first time.
523
+ */
498
524
  pacerTime: i64 = -1
499
525
  /** The smoothed RTT the pacer's rate is taken from, in microseconds: `smoothedRtt` on the pacer's clock. */
500
526
  pacerRtt: i64 = 0
@@ -506,6 +532,10 @@ export class QuicRecovery {
506
532
  timeoutSpace: i32 = -1
507
533
  /** How many congestion events reduced the window, and how many of them were persistent congestion. */
508
534
  congestionEvents: i32 = 0
535
+ /**
536
+ * How many of `congestionEvents` were persistent congestion (§7.6), which collapses the window to
537
+ * its minimum.
538
+ */
509
539
  persistentCongestions: i32 = 0
510
540
  /** How many congestion events a rise in the ECN-CE count caused (§7.1). */
511
541
  ecnCongestionEvents: i32 = 0
@@ -513,7 +543,15 @@ export class QuicRecovery {
513
543
  ecnState: i32 = 0
514
544
  /** The packets marked while testing, and of those recorded, how many and how many of them were lost. */
515
545
  ecnTestSent: i32 = 0
546
+ /**
547
+ * How many of the packets marked while testing ECN are recorded in a space's ring, so their loss can
548
+ * be seen.
549
+ */
516
550
  ecnTestRecorded: i32 = 0
551
+ /**
552
+ * How many marked packets were lost before ECN validated: once it reaches `ecnTestRecorded`, ECN
553
+ * fails (RFC 9000 A.4).
554
+ */
517
555
  ecnTestLost: i32 = 0
518
556
  /** Whether the handshake is confirmed (RFC 9001 §4.1.2), which the caller sets: the peer's max_ack_delay then bounds its ACK delays, and the Application Data space has a probe timeout. */
519
557
  handshakeConfirmed: boolean = false
@@ -23,15 +23,17 @@
23
23
  * const next: i32 = streams.putNextChunk(out, at, end) // `at` when no frame fits
24
24
  *
25
25
  * **IDs** (§2.1). The low bit says who opened a stream (0 the client, 1 the
26
- * server) and the next one whether it carries data both ways (0) or only
27
- * from its opener (1). This side is a server: it opens IDs 1 and 3 modulo 4,
28
- * and the client 0 and 2. A frame for a stream of the client's that is past
29
- * the limit this side advertised is STREAM_LIMIT_ERROR; for one of the
30
- * server's that it has not opened, STREAM_STATE_ERROR; and a frame that only
31
- * makes sense on a side the stream does not have (STREAM, RESET_STREAM or
32
- * STREAM_DATA_BLOCKED on the server's unidirectional stream; MAX_STREAM_DATA
33
- * or STOP_SENDING on the client's) is STREAM_STATE_ERROR (§19.4-§19.13). A
34
- * client's stream opens every lower one of its type with it (§3.2).
26
+ * server) and the next one whether it carries data both ways (0) or only from
27
+ * its opener (1).
28
+ *
29
+ * This side is a server: it opens IDs 1 and 3 modulo 4, and the client 0 and 2.
30
+ * A frame for a stream of the client's that is past the limit this side
31
+ * advertised is STREAM_LIMIT_ERROR; for one of the server's that it has not
32
+ * opened, STREAM_STATE_ERROR; and a frame that only makes sense on a side the
33
+ * stream does not have (STREAM, RESET_STREAM or STREAM_DATA_BLOCKED on the
34
+ * server's unidirectional stream; MAX_STREAM_DATA or STOP_SENDING on the
35
+ * client's) is STREAM_STATE_ERROR (§19.4-§19.13). A client's stream opens every
36
+ * lower one of its type with it (§3.2).
35
37
  *
36
38
  * **Fixed slots.** The table is sized once, from the configuration: one slot
37
39
  * per stream that may be open at once — as many client-opened bidirectional
@@ -43,31 +45,34 @@
43
45
  *
44
46
  * **Lent buffers.** A slot holds no buffers of its own. A side borrows a
45
47
  * `bufferSize`-byte buffer, and a bit per byte beside it, from the table's
46
- * `QuicStreamPools` when it first needs one: the receive side on the first
47
- * byte that lands, the send side on the first byte written. Each goes back,
48
- * its used extent zeroed, once it is done with: the receive side once the
49
- * application has read to the final size or the stream is reset, the send
50
- * side once every byte up to the final size is acknowledged or the stream
51
- * is reset, never before, since a lost byte is resent from the send buffer.
52
- * The pools hold two buffers per slot at most, the reserve's included, so a
53
- * borrow never fails, and
54
- * a server shares one pool across all its connections (`share`), so what it
55
- * holds follows the streams moving bytes, not the slots it was sized for.
56
- * Once the pools are warm, nothing a peer sends and nothing the application
57
- * writes allocates.
48
+ * `QuicStreamPools` when it first needs one: the receive side on the first byte
49
+ * that lands, the send side on the first byte written.
50
+ *
51
+ * Each goes back, its used extent zeroed, once it is done with: the receive
52
+ * side once the application has read to the final size or the stream is reset,
53
+ * the send side once every byte up to the final size is acknowledged or the
54
+ * stream is reset, never before, since a lost byte is resent from the send
55
+ * buffer.
56
+ *
57
+ * The pools hold two buffers per slot at most, the reserve's included, so a
58
+ * borrow never fails, and a server shares one pool across all its connections
59
+ * (`share`), so what it holds follows the streams moving bytes, not the slots
60
+ * it was sized for. Once the pools are warm, nothing a peer sends and nothing
61
+ * the application writes allocates.
58
62
  *
59
63
  * **Receiving** (§3.2, §2.2). Data lands in the receive buffer at its offset
60
64
  * modulo the buffer's size, in any order and overlapping, with a bit set per
61
- * byte; what continues the stream from the last byte read is what
62
- * `read` hands out. The credit this side gives a stream (MAX_STREAM_DATA) is
63
- * never more than what the buffer can hold past the last byte read, so a
64
- * byte beyond it is FLOW_CONTROL_ERROR and the buffer cannot overflow; it is
65
- * raised by a whole buffer once the application has read half of one. The
66
- * connection's credit (MAX_DATA) is raised the same way, by `windowData`
67
- * once half of it is read. A FIN or RESET_STREAM fixes the final size, and
68
- * a frame that disagrees with it, or a size below what already arrived, is
69
- * FINAL_SIZE_ERROR (§4.5). A reset stream's bytes count as read for the
70
- * connection's credit.
65
+ * byte; what continues the stream from the last byte read is what `read` hands
66
+ * out. The credit this side gives a stream (MAX_STREAM_DATA) is never more than
67
+ * what the buffer can hold past the last byte read, so a byte beyond it is
68
+ * FLOW_CONTROL_ERROR and the buffer cannot overflow; it is raised by a whole
69
+ * buffer once the application has read half of one.
70
+ *
71
+ * The connection's credit (MAX_DATA) is raised the same way, by `windowData`
72
+ * once half of it is read. A FIN or RESET_STREAM fixes the final size, and a
73
+ * frame that disagrees with it, or a size below what already arrived, is
74
+ * FINAL_SIZE_ERROR (§4.5). A reset stream's bytes count as read for the
75
+ * connection's credit.
71
76
  *
72
77
  * **Sending** (§3.1). The application writes into the send buffer as far as
73
78
  * it has room, a chunk at a time: what `write` takes is its back-pressure,
@@ -247,39 +252,43 @@ export const quicStreamSetBit = (bits: u8[], k: i32, on: boolean): void => {
247
252
  const quicStreamMin = (a: i64, b: i64): i64 => (a < b ? a : b)
248
253
 
249
254
  /**
250
- * The buffers a connection's streams borrow: `data` lends the receive and
251
- * send buffers of `bufferSize` bytes, `bits` the bitmaps beside them, a bit
252
- * per byte. One table makes a private set for itself; a server makes one set
253
- * for every slot and hands it to each connection's table with
254
- * `QuicStreams.share`, so the memory follows the streams moving bytes rather
255
- * than the slots the server was sized for. Each pool's ceiling is two
256
- * buffers for every stream it serves, one a side, which is what holding
257
- * every buffer at once costs. The reserve below counts against it too, so a
258
- * send side that finds the pools out takes the reserve's last buffer
259
- * (`lendSend`): with that side holding none, not every buffer is lent, and
260
- * the one left over is in the reserve.
255
+ * The buffers a connection's streams borrow: `data` lends the receive and send
256
+ * buffers of `bufferSize` bytes, `bits` the bitmaps beside them, a bit per
257
+ * byte. One table makes a private set for itself; a server makes one set for
258
+ * every slot and hands it to each connection's table with `QuicStreams.share`,
259
+ * so the memory follows the streams moving bytes rather than the slots the
260
+ * server was sized for. Each pool's ceiling is two buffers for every stream it
261
+ * serves, one a side, which is what holding every buffer at once costs.
262
+ *
263
+ * The reserve below counts against it too, so a send side that finds the pools
264
+ * out takes the reserve's last buffer (`lendSend`): with that side holding
265
+ * none, not every buffer is lent, and the one left over is in the reserve.
261
266
  *
262
267
  * Frames are handled inside the arena scope a packet is opened in, where
263
268
  * nothing may allocate, grow a list or push onto one. So the frames lend and
264
- * take back receive buffers through a reserve the pools keep beside their
265
- * free lists, by index alone: `lend` hands one out, `keep` takes one back
266
- * zeroed. Before each scope `prime` trims the reserve to `hold` buffers,
267
- * giving the rest to the pools, and tops it up to as many as the packet
268
- * could start receive sides, taking them. `hold` is one connection's stream
269
- * count, and the reserve three times that long, so a packet that lends
270
- * nothing and takes back every buffer its connection held still fits. Once
271
- * warm, the reserve mostly circulates on its own and `prime` costs a handful
272
- * of comparisons, with no take or give. The pools count the reserve's
273
- * buffers as lent. `prime` and the `drain` before each give-back outside a
274
- * packet trim it to `hold` for the whole server, not each connection, but
275
- * `keep` inside a packet can raise it to three times `hold`, and it stays
276
- * there until the next `prime` or `drain`.
269
+ * take back receive buffers through a reserve the pools keep beside their free
270
+ * lists, by index alone: `lend` hands one out, `keep` takes one back zeroed.
271
+ * Before each scope `prime` trims the reserve to `hold` buffers, giving the
272
+ * rest to the pools, and tops it up to as many as the packet could start
273
+ * receive sides, taking them.
274
+ *
275
+ * `hold` is one connection's stream count, and the reserve three times that
276
+ * long, so a packet that lends nothing and takes back every buffer its
277
+ * connection held still fits. Once warm, the reserve mostly circulates on its
278
+ * own and `prime` costs a handful of comparisons, with no take or give. The
279
+ * pools count the reserve's buffers as lent. `prime` and the `drain` before
280
+ * each give-back outside a packet trim it to `hold` for the whole server, not
281
+ * each connection, but `keep` inside a packet can raise it to three times
282
+ * `hold`, and it stays there until the next `prime` or `drain`.
277
283
  */
278
284
  export class QuicStreamPools {
285
+ /** The pool of stream buffers, `bufferSize` bytes each, that the send and receive sides borrow. */
279
286
  data: BufferPool
287
+ /** The pool of bitmaps beside them, a bit per buffer byte: which bytes are unread or acknowledged. */
280
288
  bits: BufferPool
281
289
  /** The reserve: `ready` buffers and their bitmaps, taken from the pools and not lent to a stream; the rest of each list is `none`. */
282
290
  readyData: u8[][]
291
+ /** The reserve's bitmaps, one beside each `readyData` buffer at the same index. */
283
292
  readyBits: u8[][]
284
293
  /** The empty array a free reserve entry holds. */
285
294
  private none: u8[]
@@ -460,6 +469,7 @@ export const quicStreamGrowFree = (free: u8[][], target: i32, none: u8[]): void
460
469
  * it asked this side to stop — and written only by `QuicStreams`.
461
470
  */
462
471
  export class QuicStream {
472
+ /** The stream ID (RFC 9000 §2.1), or -1 while the slot is free. */
463
473
  id: i64 = -1
464
474
  /**
465
475
  * The receive buffer: byte `o` of the stream at `o % size`, its bit in
@@ -467,6 +477,7 @@ export class QuicStream {
467
477
  * first byte arrives and after the side is done, and borrowed in between.
468
478
  */
469
479
  recvBuf: u8[]
480
+ /** The bitmap beside `recvBuf`: a bit per buffer byte, set while that byte has arrived and is unread. */
470
481
  recvHave: u8[]
471
482
  /**
472
483
  * How far the application has read.
@@ -495,6 +506,7 @@ export class QuicStream {
495
506
  * packet is sent again from it.
496
507
  */
497
508
  sendBuf: u8[]
509
+ /** The bitmap beside `sendBuf`: a bit per buffer byte, set once acknowledged and not yet released. */
498
510
  sendAcked: u8[]
499
511
  /** Every byte below this was acknowledged, and its room released. */
500
512
  sendBase: i64 = 0
@@ -509,6 +521,7 @@ export class QuicStream {
509
521
  sendLimit: i64 = 0
510
522
  /** Bytes a lost packet carried, `[resendLow, resendHigh)`, or -1; `resendFin` when the FIN was among them. */
511
523
  resendLow: i64 = -1
524
+ /** One past the last byte to send again, or -1 when nothing is owed; see `resendLow`. */
512
525
  resendHigh: i64 = -1
513
526
  /**
514
527
  * The error code of this side's RESET_STREAM, and its final size.
@@ -529,7 +542,9 @@ export class QuicStream {
529
542
  * @internal Read in quic-stream.ts outside the class.
530
543
  */
531
544
  size: i32 = 0
545
+ /** The send side's state (RFC 9000 §3.1), a `QUIC_SEND_*` constant. */
532
546
  sendState: i32 = 0
547
+ /** The receive side's state (RFC 9000 §3.2), a `QUIC_RECV_*` constant. */
533
548
  recvState: i32 = 0
534
549
  /**
535
550
  * Whether the application wrote the FIN, a frame carried it, and the peer acknowledged it.
@@ -715,6 +730,7 @@ export class QuicStream {
715
730
  * counters are readable for a test or a log.
716
731
  */
717
732
  export class QuicStreams {
733
+ /** The stream slots, a fixed count set at construction; a free one has `id` -1. */
718
734
  slots: QuicStream[]
719
735
  /** Open addressing by ID: `index[h]` is a slot plus one, 0 for empty. */
720
736
  private index: i32[]
@@ -747,10 +763,15 @@ export class QuicStreams {
747
763
  localStreams: i64 = 0
748
764
  /** How many of each type the client opened, the limit advertised, and how many of them finished. */
749
765
  peerBidiOpened: i64 = 0
766
+ /** How many unidirectional streams the client opened. */
750
767
  peerUniOpened: i64 = 0
768
+ /** The bidirectional stream limit this side last advertised to the client (MAX_STREAMS). */
751
769
  peerBidiLimit: i64 = 0
770
+ /** The unidirectional stream limit this side last advertised to the client (MAX_STREAMS). */
752
771
  peerUniLimit: i64 = 0
772
+ /** How many of the client's bidirectional streams finished, which is what lets the limit rise. */
753
773
  peerBidiClosed: i64 = 0
774
+ /** How many of the client's unidirectional streams finished, which is what lets the limit rise. */
754
775
  peerUniClosed: i64 = 0
755
776
  /** How many of each type this side opened, the client's limits, and how many of this side's are open. */
756
777
  private localBidiOpened: i64 = 0
@@ -764,12 +785,15 @@ export class QuicStreams {
764
785
  private peerUniCredit: i64 = 0
765
786
  /** The connection's receive credit: what was advertised, its window, what arrived, and what was read. */
766
787
  recvMaxData: i64 = 0
788
+ /** The connection's receive window in bytes: how far past what was read the credit is raised. */
767
789
  windowData: i64 = 0
790
+ /** Bytes the connection received, counted at each stream's highest offset, against `recvMaxData`. */
768
791
  recvTotal: i64 = 0
769
792
  private recvConsumed: i64 = 0
770
793
  /** The connection's send credit from the peer, what was sent against it, and what is written but not sent. */
771
794
  sendMaxData: i64 = 0
772
795
  private sendTotal: i64 = 0
796
+ /** Bytes the application wrote to every stream, sent or not; a write may not take it past `sendMaxData`. */
773
797
  writtenTotal: i64 = 0
774
798
  /** The transport error `locate` answered -2 for. */
775
799
  private locateError: i64 = 0
@@ -780,11 +804,15 @@ export class QuicStreams {
780
804
  private streamsBlockedUniAt: i64 = -1
781
805
  /** What the last `putNextChunk` or `putNextControl` wrote, for the packet's record. */
782
806
  lastId: i64 = 0
807
+ /** The stream offset of the last chunk `putNextChunk` wrote. */
783
808
  lastOffset: i64 = 0
809
+ /** The stream the last control frame `putNextControl` wrote names, or 0 for a connection-level one. */
784
810
  lastValue: i64 = 0
785
811
  /** The bytes of each stream's buffer, each way. */
786
812
  bufferSize: i32 = 0
813
+ /** The bytes of the last chunk `putNextChunk` wrote. */
787
814
  lastLength: i32 = 0
815
+ /** Which control frame `putNextControl` last wrote, a `QUIC_STREAM_CONTROL_*` constant. */
788
816
  lastKind: i32 = 0
789
817
  private eventHead: i32 = 0
790
818
  private eventCount: i32 = 0