nish 0.35.0 → 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 (118) hide show
  1. package/docs/AI.md +9 -2
  2. package/docs/INSTALL.md +6 -1
  3. package/package.json +15 -5
  4. package/runtime/nish.d.ts +4612 -430
  5. package/runtime/vite.d.ts +30 -0
  6. package/runtime/vite.mjs +150 -0
  7. package/scripts/build.sh +108 -13
  8. package/std/base64.ts +34 -5
  9. package/std/bytes.ts +256 -40
  10. package/std/cli-args.ts +296 -70
  11. package/std/cli-flags.ts +184 -19
  12. package/std/cli.ts +475 -54
  13. package/std/collections.ts +121 -23
  14. package/std/compress/checksum.ts +44 -14
  15. package/std/compress/deflate.ts +224 -111
  16. package/std/compress/gzip.ts +217 -53
  17. package/std/compress/zlib.ts +63 -7
  18. package/std/crypto/aes.ts +80 -9
  19. package/std/crypto/base64url.ts +22 -0
  20. package/std/crypto/bcrypt-batch.ts +88 -21
  21. package/std/crypto/bcrypt.ts +60 -0
  22. package/std/crypto/chacha20poly1305.ts +53 -0
  23. package/std/crypto/ct.ts +32 -13
  24. package/std/crypto/ed25519.ts +47 -0
  25. package/std/crypto/hkdf.ts +198 -13
  26. package/std/crypto/hmac.ts +235 -31
  27. package/std/crypto/jwt.ts +192 -63
  28. package/std/crypto/p256.ts +159 -16
  29. package/std/crypto/p384.ts +28 -3
  30. package/std/crypto/pki-roots.ts +32 -2
  31. package/std/crypto/pki.ts +81 -15
  32. package/std/crypto/rsa.ts +33 -3
  33. package/std/crypto/sha1.ts +3 -0
  34. package/std/crypto/sha256.ts +24 -1
  35. package/std/crypto/sha512.ts +99 -14
  36. package/std/crypto/x25519.ts +152 -14
  37. package/std/crypto/x509-random.ts +10 -0
  38. package/std/crypto/x509.ts +67 -7
  39. package/std/json-equal.ts +19 -0
  40. package/std/json-format.ts +112 -13
  41. package/std/json-number.ts +64 -14
  42. package/std/json-pointer.ts +23 -1
  43. package/std/json-tokenizer.ts +100 -29
  44. package/std/json-typed.ts +713 -66
  45. package/std/json-value.ts +400 -124
  46. package/std/json.ts +138 -10
  47. package/std/map.ts +25 -7
  48. package/std/math.ts +36 -4
  49. package/std/net/buffer-pool.ts +42 -11
  50. package/std/net/dns-config.ts +109 -23
  51. package/std/net/dns-message.ts +62 -7
  52. package/std/net/dns-resolver.ts +247 -53
  53. package/std/net/dns.ts +203 -35
  54. package/std/net/fetch.ts +151 -61
  55. package/std/net/handler.ts +278 -80
  56. package/std/net/hpack.ts +262 -52
  57. package/std/net/http-compress.ts +125 -15
  58. package/std/net/http-fields.ts +85 -9
  59. package/std/net/http1-client-codec.ts +100 -19
  60. package/std/net/http1-codec.ts +235 -27
  61. package/std/net/http1-server.ts +343 -85
  62. package/std/net/http2-frame.ts +272 -35
  63. package/std/net/http2-tls.ts +135 -34
  64. package/std/net/http2.ts +247 -106
  65. package/std/net/http3-frame.ts +154 -17
  66. package/std/net/http3-server.ts +246 -96
  67. package/std/net/http3.ts +307 -115
  68. package/std/net/outbound.ts +37 -3
  69. package/std/net/postgres-carrier.ts +144 -8
  70. package/std/net/postgres.ts +723 -103
  71. package/std/net/prefork.ts +164 -31
  72. package/std/net/qpack.ts +105 -18
  73. package/std/net/quic-conn-ack.ts +59 -12
  74. package/std/net/quic-conn-cid.ts +124 -27
  75. package/std/net/quic-conn-params.ts +70 -10
  76. package/std/net/quic-datagram.ts +43 -3
  77. package/std/net/quic-frame.ts +286 -12
  78. package/std/net/quic-listener.ts +101 -32
  79. package/std/net/quic-packet.ts +302 -21
  80. package/std/net/quic-recovery.ts +228 -44
  81. package/std/net/quic-stream.ts +353 -91
  82. package/std/net/quic.ts +489 -171
  83. package/std/net/router.ts +87 -40
  84. package/std/net/tls/client.ts +166 -51
  85. package/std/net/tls/codec.ts +413 -56
  86. package/std/net/tls/record-client.ts +110 -55
  87. package/std/net/tls/record-server.ts +159 -59
  88. package/std/net/tls/record.ts +109 -12
  89. package/std/net/tls/schedule.ts +235 -26
  90. package/std/net/tls/ticket.ts +159 -40
  91. package/std/net/tls/verify.ts +49 -3
  92. package/std/net/tls-tcp.ts +250 -45
  93. package/std/net/tls.ts +221 -59
  94. package/std/net/upstream.ts +81 -45
  95. package/std/net/url.ts +97 -13
  96. package/std/net/websocket.ts +122 -12
  97. package/std/net/webtransport.ts +220 -89
  98. package/std/pair.ts +10 -2
  99. package/std/random.ts +34 -9
  100. package/std/regex.ts +352 -198
  101. package/std/region.ts +70 -15
  102. package/std/secret.ts +52 -11
  103. package/std/sort.ts +17 -2
  104. package/std/sqlite.ts +256 -35
  105. package/std/sync/ring.ts +205 -35
  106. package/std/sync/shm.ts +194 -16
  107. package/std/term-io.ts +137 -64
  108. package/std/term-pixels.ts +144 -19
  109. package/std/term-probe.ts +66 -25
  110. package/std/term-rate.ts +128 -57
  111. package/std/term.ts +332 -121
  112. package/std/testing.ts +130 -32
  113. package/std/text.ts +73 -7
  114. package/std/threads.ts +229 -41
  115. package/std/yaml-json.ts +94 -82
  116. package/std/yaml-lines.ts +47 -15
  117. package/std/yaml-write.ts +24 -16
  118. package/std/yaml.ts +764 -384
package/std/net/http3.ts CHANGED
@@ -12,19 +12,31 @@
12
12
  * this module reads and writes that connection's streams. `nish/net/http3-server`
13
13
  * runs it over a UDP socket with ALPN `h3`.
14
14
  *
15
- * import { Http3Config, Http3Connection, H3_NEED_MORE, H3_ERROR, H3_REQUEST, H3_DATA, H3_END } from "nish/net/http3";
15
+ * import { Http3Config, Http3Connection, H3_NEED_MORE, H3_ERROR, H3_END } from "nish/net/http3";
16
+ * import { httpFieldBytes } from "nish/net/http-fields";
17
+ * import { QuicConnection } from "nish/net/quic";
16
18
  *
17
- * const h3 = new Http3Connection(new Http3Config(), quic); // once per slot; restart() per connection
18
- * // after quic.receive(...):
19
- * let event: i32 = h3.next();
20
- * while (event !== H3_NEED_MORE && event !== H3_ERROR) {
21
- * // H3_REQUEST: h3.stream, h3.fields (method, path, get("accept"))
22
- * // H3_DATA: h3.data[h3.dataStart .. h3.dataStart + h3.dataLength)
23
- * // H3_END: the request is whole; respond
24
- * event = h3.next();
19
+ * // Once per slot, beside a server QuicConnection; restart() per connection.
20
+ * function open(quic: QuicConnection): Http3Connection {
21
+ * return new Http3Connection(new Http3Config(), quic);
22
+ * }
23
+ *
24
+ * // After each quic.receive(...):
25
+ * function serve(h3: Http3Connection): void {
26
+ * const names: u8[][] = [httpFieldBytes("content-type")];
27
+ * const values: u8[][] = [httpFieldBytes("text/plain")];
28
+ * const body: u8[] = httpFieldBytes("hello\n");
29
+ * let event: i32 = h3.next();
30
+ * while (event !== H3_NEED_MORE && event !== H3_ERROR) {
31
+ * // H3_REQUEST: h3.stream, h3.fields (method, path, get("accept"))
32
+ * // H3_DATA: h3.data[h3.dataStart .. h3.dataStart + h3.dataLength)
33
+ * if (event === H3_END) { // the request is whole: respond
34
+ * h3.respond(h3.stream, 200, names, values, false);
35
+ * h3.writeData(h3.stream, body, 0, toI32(body.length), true); // answers how much it took
36
+ * }
37
+ * event = h3.next();
38
+ * }
25
39
  * }
26
- * h3.respond(stream, 200, names, values, false);
27
- * h3.writeData(stream, body, 0, n, true); // answers how much it took
28
40
  *
29
41
  * **Events.** `next()` reads the streams the QUIC connection has news for and
30
42
  * answers the first thing that means something to the program: `H3_REQUEST`
@@ -89,7 +101,7 @@
89
101
  * **Caps are start-up numbers**, all in `Http3Config`. The stream state for
90
102
  * every QUIC stream slot and the control frame are made by the constructor;
91
103
  * the body chunk and the field section are borrowed, around one read, from
92
- * pools that a server's connections share (`share`) and that a standalone
104
+ * pools that a server's connections share and that a standalone
93
105
  * connection keeps one buffer each of. A field section's
94
106
  * names and values are copied into arrays the connection keeps, which grow to
95
107
  * the largest section seen and are then reused, so a warm connection
@@ -397,44 +409,55 @@ const http3Min = (a: i64, b: i64): i64 => (a < b ? a : b)
397
409
  export class Http3Connection {
398
410
  // Pointers and 64-bit fields first, then 32-bit ones, then flags: the
399
411
  // order the layout packs without padding.
412
+ /** @internal Read by `webtransport.ts` for `webtransportSessions`; callers keep their own `Http3Config`. */
400
413
  config: Http3Config
414
+ /** The QUIC connection this one runs on, given to the constructor and kept for its life. */
401
415
  quic: QuicConnection
416
+ /**
417
+ * The QPACK decoder of the client's field sections, at dynamic table capacity 0; it also reads the
418
+ * client's encoder stream.
419
+ */
402
420
  decoder: QpackDecoder
421
+ /** The QPACK encoder of this side's field sections; it also reads the client's decoder stream. */
403
422
  encoder: QpackEncoder
404
423
  /** The last request's or trailers' fields, valid until the next of either. */
405
424
  fields: HttpFields
406
425
  /** The client's SETTINGS. */
407
426
  peer: Http3Settings
408
- header: Http3FrameHeader
427
+ private header: Http3FrameHeader
409
428
  /**
410
429
  * H3_DATA's bytes, and where a payload being skipped is read to: a
411
430
  * `bodyChunk`-byte buffer borrowed from `dataPool` for the read that needs
412
- * it and held while an H3_DATA window is live, else `none`.
431
+ * it and held while an H3_DATA window is live, else an empty array. Any
432
+ * event but H3_DATA gives the buffer back, zeroed as far as reads wrote.
413
433
  */
414
434
  data: u8[]
415
435
  /** A HEADERS payload read whole, for the decoder: a buffer borrowed from `sectionPool` around one read and decode, else `none`. */
416
- section: u8[]
436
+ private section: u8[]
417
437
  /** The empty array `data` and `section` are while they hold nothing borrowed. */
418
- none: u8[]
419
- /** Where `data` is borrowed from: the connection's own pool until `share` hands it its server's. */
438
+ private none: u8[]
439
+ /** Where `data` is borrowed from: the connection's own pool until its server lends it the server's. */
420
440
  dataPool: BufferPool
421
- /** Where `section` is borrowed from, likewise. */
441
+ /**
442
+ * Where the buffer a HEADERS payload is read into whole, for the decoder, is borrowed from around one
443
+ * read and decode: the connection's own pool until its server lends it the server's.
444
+ */
422
445
  sectionPool: BufferPool
423
446
  /** A control frame's payload, read whole. */
424
- control: u8[]
447
+ private control: u8[]
425
448
  /** Frame headers, SETTINGS and GOAWAY on their way out. */
426
- scratch: u8[]
449
+ private scratch: u8[]
427
450
  /** Zeros, the payload of a filler frame. */
428
- zeros: u8[]
451
+ private zeros: u8[]
429
452
  /** A response's field section, encoded, emptied and reused. */
430
- encoded: u8[]
453
+ private encoded: u8[]
431
454
  /** Copies of the decoded names and values, in arrays by size class (`copyOf`), and the lists handed to `fields`. */
432
- pools: u8[][][]
433
- poolUsed: i32[]
434
- nameList: u8[][]
435
- valueList: u8[][]
436
- statusName: u8[]
437
- statusValue: u8[]
455
+ private pools: u8[][][]
456
+ private poolUsed: i32[]
457
+ private nameList: u8[][]
458
+ private valueList: u8[][]
459
+ private statusName: u8[]
460
+ private statusValue: u8[]
438
461
  /**
439
462
  * The `date` every response carries (RFC 9110 §6.6.1), as the 29 bytes of
440
463
  * an IMF-fixdate, or empty for none. A bare connection has no clock, so it
@@ -443,30 +466,30 @@ export class Http3Connection {
443
466
  */
444
467
  date: u8[]
445
468
  /** The bytes of `date`, the field's name, made once. */
446
- dateName: u8[]
447
- /** The SETTINGS this side sends. */
469
+ private dateName: u8[]
470
+ /** The identifiers of the SETTINGS this side sends, in the order sent; fixed by the constructor. */
448
471
  settingIds: i64[]
449
- settingValues: i64[]
472
+ private settingValues: i64[]
450
473
  /** Per QUIC stream slot: the stream the state is for, or -1. */
451
- slotId: i64[]
474
+ private slotId: i64[]
452
475
  /** The frame being read: its type, and what is left of its payload (-1 between frames). */
453
- frameType: i64[]
454
- frameLeft: i64[]
476
+ private frameType: i64[]
477
+ private frameLeft: i64[]
455
478
  /** DATA bytes received on the request, and its `content-length` or -1. */
456
- dataTotal: i64[]
457
- contentLength: i64[]
479
+ private dataTotal: i64[]
480
+ private contentLength: i64[]
458
481
  /** Bytes still owed on the stream: a filler's payload, and the DATA frame's payload the program is writing. */
459
- fillLeft: i64[]
460
- dataLeft: i64[]
461
- phase: i32[]
462
- flags: i32[]
482
+ private fillLeft: i64[]
483
+ private dataLeft: i64[]
484
+ private phase: i32[]
485
+ private flags: i32[]
463
486
  /** A frame header (or a stream type) being read, `headLen[k]` bytes of `head[k * 16 ..]`. */
464
- headLen: i32[]
465
- head: u8[]
487
+ private headLen: i32[]
488
+ private head: u8[]
466
489
  /** Frame-header bytes owed before anything else, `pendLen[k]` of `pend[k * 16 + pendAt[k] ..]`. */
467
- pendAt: i32[]
468
- pendLen: i32[]
469
- pend: u8[]
490
+ private pendAt: i32[]
491
+ private pendLen: i32[]
492
+ private pend: u8[]
470
493
  /**
471
494
  * Streams `next` steps again before asking QUIC for news, a ring of
472
495
  * `againCount` from `againHead`: WebTransport streams the program let go,
@@ -474,56 +497,84 @@ export class Http3Connection {
474
497
  * `waitCount` of them. A stream is on each at most once (its flags say),
475
498
  * so neither needs more room than there are stream slots.
476
499
  */
477
- again: i64[]
478
- waiting: i64[]
479
- /** This side's streams, and the client's critical ones; -1 until there. */
480
- ownControl: i64 = -1
481
- ownEncoder: i64 = -1
482
- ownDecoder: i64 = -1
500
+ private again: i64[]
501
+ private waiting: i64[]
502
+ /** This side's control, encoder and decoder streams; -1 until opened. */
503
+ private ownControl: i64 = -1
504
+ private ownEncoder: i64 = -1
505
+ private ownDecoder: i64 = -1
506
+ /** The ID of the client's control stream, or -1 until its stream type has been read. */
483
507
  peerControl: i64 = -1
508
+ /** The ID of the client's QPACK encoder stream, or -1 until its stream type has been read. */
484
509
  peerEncoder: i64 = -1
510
+ /** The ID of the client's QPACK decoder stream, or -1 until its stream type has been read. */
485
511
  peerDecoder: i64 = -1
486
512
  /** The stream `next` is reading, or -1. */
487
- active: i64 = -1
488
- /** The ID this side's GOAWAY named, or -1; the client's last GOAWAY push ID, and its MAX_PUSH_ID. */
489
- goawayId: i64 = -1
490
- peerGoaway: i64 = -1
513
+ private active: i64 = -1
514
+ /** The ID this side's GOAWAY named, or -1; the client's last GOAWAY push ID. */
515
+ private goawayId: i64 = -1
516
+ private peerGoaway: i64 = -1
517
+ /**
518
+ * The client's MAX_PUSH_ID, or -1 until it sends one. It is checked (it may not fall, and bounds
519
+ * CANCEL_PUSH) and otherwise unused, since this side never pushes.
520
+ */
491
521
  maxPushId: i64 = -1
492
522
  /** The last event's stream. */
493
523
  stream: i64 = -1
494
- /** H3_RESET's and H3_ERROR's code. */
524
+ /** H3_RESET's, H3_STOPPED's and H3_ERROR's code. */
495
525
  errorCode: i64 = 0
496
526
  /** H3_GOAWAY's push ID. */
497
527
  lastStreamId: i64 = 0
498
528
  /** H3_STREAM's session ID. */
499
529
  session: i64 = -1
500
- /** The QUIC stream slot of the last event's stream: still right when the read that made the event freed it. */
530
+ /**
531
+ * The QUIC stream slot of the last event's stream: still right when the read that made the event freed it.
532
+ * @internal Read by `webtransport.ts` to find its own per-slot state; not for callers.
533
+ */
501
534
  slot: i32 = -1
502
- /** H3_DATA's window onto `data`. */
535
+ /** Where H3_DATA's window onto `data` starts. */
503
536
  dataStart: i32 = 0
537
+ /** H3_DATA's window length in bytes, 1 to `bodyChunk`; valid until the next `next()`. */
504
538
  dataLength: i32 = 0
505
539
  /** How much of `control` is filled. */
506
- controlFill: i32 = 0
540
+ private controlFill: i32 = 0
507
541
  /** How far into the borrowed `data` reads have written: what its give-back zeroes. */
508
- dataUsed: i32 = 0
542
+ private dataUsed: i32 = 0
543
+ /** 0 while the connection is open; 1 once it failed (H3_ERROR), which only `restart` undoes. */
509
544
  state: i32 = 0
510
- /** Requests open: taken and not yet finished both ways. */
545
+ /**
546
+ * Requests open, taken and not yet finished both ways, plus the bidirectional WebTransport streams held
547
+ * after this side's GOAWAY for a session below it.
548
+ */
511
549
  live: i32 = 0
512
- /** Counters for a log or a test, each saturating: requests refused after GOAWAY, answered 431, and reset for a rule. */
550
+ /**
551
+ * Counters for a log or a test, each saturating and zeroed by `restart`. This one: request streams refused
552
+ * because their ID is at or past the one this side's GOAWAY named, and WebTransport streams dropped
553
+ * because their session's is.
554
+ */
513
555
  rejected: i32 = 0
556
+ /**
557
+ * Requests whose field section was past `maxFieldSectionSize`: answered with a 431, or reset when the 431
558
+ * did not fit.
559
+ */
514
560
  tooLarge: i32 = 0
561
+ /**
562
+ * Requests reset for breaking a rule (a stream error, §8): a malformed message, a body that disagrees
563
+ * with `content-length`, a stream that ends before its HEADERS, a trailer section too large.
564
+ */
515
565
  streamErrors: i32 = 0
516
- againHead: i32 = 0
517
- againCount: i32 = 0
518
- waitCount: i32 = 0
566
+ private againHead: i32 = 0
567
+ private againCount: i32 = 0
568
+ private waitCount: i32 = 0
519
569
  /** How many times `restart` ran: a layer above that keeps state per connection compares it to know when to forget its own. */
520
570
  generation: i32 = 0
521
571
  /** Whether the client's SETTINGS have arrived. */
522
572
  settingsSeen: boolean = false
523
573
  /** Whether H3_RESET came from the client. */
524
574
  resetByPeer: boolean = false
525
- /** Whether extended CONNECT is on, and WebTransport. */
526
- connect: boolean = false
575
+ /** Whether extended CONNECT is on. */
576
+ private connect: boolean = false
577
+ /** Whether WebTransport is on: `webtransportSessions` above 0. Fixed by the constructor. */
527
578
  webtransport: boolean = false
528
579
 
529
580
  /**
@@ -532,6 +583,11 @@ export class Http3Connection {
532
583
  * one on every request stream fit half the connection's window, and let
533
584
  * the client open the three unidirectional streams it needs and this side
534
585
  * open its own three (§6.2). A cap out of range panics.
586
+ *
587
+ * @param config The caps; kept, not copied, so it must not change after this call.
588
+ * @param quic The server QUIC connection to run on, kept for this connection's life. Its stream caps
589
+ * are checked as above, and it must take DATAGRAM frames exactly when `webtransportSessions` is above
590
+ * 0, or this panics.
535
591
  */
536
592
  constructor(config: Http3Config, quic: QuicConnection) {
537
593
  const buffer: i32 = quic.streams.bufferSize
@@ -688,7 +744,10 @@ export class Http3Connection {
688
744
 
689
745
  // ---- The connection -----------------------------------------------------------
690
746
 
691
- /** Closes the connection with `code` (a connection error) and answers H3_ERROR. */
747
+ /**
748
+ * Closes the connection with `code` (a connection error) and answers H3_ERROR.
749
+ * @internal Called by `webtransport.ts` to fail the connection on a malformed datagram; not for callers.
750
+ */
692
751
  fail(code: i64): i32 {
693
752
  if (this.state !== H3_STATE_FAILED) {
694
753
  this.state = H3_STATE_FAILED
@@ -702,6 +761,9 @@ export class Http3Connection {
702
761
  * Whether this side sent GOAWAY and every request it took has finished
703
762
  * both ways, every byte of each response acknowledged: the carrier may
704
763
  * close the connection.
764
+ *
765
+ * @returns True when this side's GOAWAY has gone out, `live` is 0 and QUIC has closed every request
766
+ * stream the client opened; false otherwise, and always before `goaway()` has sent one.
705
767
  */
706
768
  isDone(): boolean {
707
769
  const streams = this.quic.streams
@@ -709,7 +771,7 @@ export class Http3Connection {
709
771
  }
710
772
 
711
773
  /** Writes `buf[0 .. n)` to this side's new stream `id` whole, as its first bytes; answers whether it took them. */
712
- writeNew(id: i64, buf: u8[], n: i32): boolean {
774
+ private writeNew(id: i64, buf: u8[], n: i32): boolean {
713
775
  return n > 0 && this.quic.streamWrite(id, buf, H3_ZERO, n, false) === n
714
776
  }
715
777
 
@@ -719,7 +781,7 @@ export class Http3Connection {
719
781
  * §4.2). A stream the client's MAX_STREAMS does not allow yet is opened on
720
782
  * a later call.
721
783
  */
722
- start(): void {
784
+ private start(): void {
723
785
  const end: i32 = toI32(this.scratch.length)
724
786
  if (this.ownControl < 0) {
725
787
  const id: i64 = this.quic.openStream(false)
@@ -766,6 +828,11 @@ export class Http3Connection {
766
828
  * Reads what the QUIC connection has for the program and answers the next
767
829
  * event (see the module comment). Call it after every datagram the QUIC
768
830
  * connection takes, until it answers H3_NEED_MORE or H3_ERROR.
831
+ *
832
+ * @returns One of the `H3_*` events: H3_REQUEST, H3_DATA, H3_TRAILERS, H3_END, H3_RESET, H3_WRITABLE,
833
+ * H3_GOAWAY, and with WebTransport on H3_STREAM, H3_STOPPED and H3_DROPPED; H3_NEED_MORE when
834
+ * nothing more is there, or while the QUIC handshake is not done; H3_ERROR once the connection has
835
+ * failed, or the QUIC connection has closed, and on every call after.
769
836
  */
770
837
  next(): i32 {
771
838
  // The last H3_DATA window ends here. A body read chunk by chunk keeps the
@@ -782,6 +849,10 @@ export class Http3Connection {
782
849
  * back to the old pools whatever it holds. Panics unless their buffers are
783
850
  * `bodyChunk` and `maxFieldSectionSize` bytes long, as this connection's
784
851
  * reads need.
852
+ *
853
+ * @param data The pool H3_DATA's buffer is borrowed from from now on; kept, not copied.
854
+ * @param section The pool a HEADERS payload's buffer is borrowed from from now on; kept, not copied.
855
+ * @internal Called by `http3-server.ts` when it builds a slot; not for callers.
785
856
  */
786
857
  share(data: BufferPool, section: BufferPool): void {
787
858
  if (data.size !== this.config.bodyChunk || section.size !== this.config.maxFieldSectionSize) {
@@ -794,20 +865,24 @@ export class Http3Connection {
794
865
  this.sectionPool = section
795
866
  }
796
867
 
797
- /** Releases the QUIC connection (`QuicConnection.release`) and gives back every pooled buffer this connection holds. */
868
+ /**
869
+ * Releases the QUIC connection (`QuicConnection.release`) and gives back every pooled buffer this
870
+ * connection holds.
871
+ * @internal Called by `http3-server.ts` when it frees a slot or has stopped; not for callers.
872
+ */
798
873
  release(): void {
799
874
  this.quic.release()
800
875
  this.giveBack()
801
876
  }
802
877
 
803
878
  /** Gives back `data` and `section` if either is borrowed: the connection holds no pooled buffer after it. */
804
- giveBack(): void {
879
+ private giveBack(): void {
805
880
  this.giveData()
806
881
  this.giveSection(H3_ZERO)
807
882
  }
808
883
 
809
884
  /** `data`, borrowed from `dataPool` first if it is not already. */
810
- borrowData(): u8[] {
885
+ private borrowData(): u8[] {
811
886
  if (this.data.length === 0) {
812
887
  this.data = this.dataPool.take()
813
888
  this.dataUsed = 0
@@ -816,7 +891,7 @@ export class Http3Connection {
816
891
  }
817
892
 
818
893
  /** Gives `data` back to `dataPool`, zeroed as far as reads wrote, if it is borrowed. */
819
- giveData(): void {
894
+ private giveData(): void {
820
895
  if (this.data.length > 0) {
821
896
  this.dataPool.give(this.data, this.dataUsed)
822
897
  this.data = this.none
@@ -825,7 +900,7 @@ export class Http3Connection {
825
900
  }
826
901
 
827
902
  /** Reads up to `want` bytes of stream `id` into the start of `data`, borrowed for it: `streamRead`'s answer. */
828
- readData(id: i64, want: i32): i32 {
903
+ private readData(id: i64, want: i32): i32 {
829
904
  const n: i32 = this.quic.streamRead(id, this.borrowData(), H3_ZERO, want)
830
905
  if (n > this.dataUsed) {
831
906
  this.dataUsed = n
@@ -834,7 +909,7 @@ export class Http3Connection {
834
909
  }
835
910
 
836
911
  /** `section`, borrowed from `sectionPool`. */
837
- borrowSection(): u8[] {
912
+ private borrowSection(): u8[] {
838
913
  if (this.section.length === 0) {
839
914
  this.section = this.sectionPool.take()
840
915
  }
@@ -842,7 +917,7 @@ export class Http3Connection {
842
917
  }
843
918
 
844
919
  /** Gives `section` back to `sectionPool`, zeroed over `[0, used)`, if it is borrowed. */
845
- giveSection(used: i32): void {
920
+ private giveSection(used: i32): void {
846
921
  if (this.section.length > 0) {
847
922
  this.sectionPool.give(this.section, used)
848
923
  this.section = this.none
@@ -850,7 +925,7 @@ export class Http3Connection {
850
925
  }
851
926
 
852
927
  /** `next`'s work: everything but the lending of `data` around it. */
853
- nextEvent(): i32 {
928
+ private nextEvent(): i32 {
854
929
  if (this.state === H3_STATE_FAILED) {
855
930
  return H3_ERROR
856
931
  }
@@ -887,7 +962,7 @@ export class Http3Connection {
887
962
  }
888
963
 
889
964
  /** The oldest stream on the `again` ring, taken off it. */
890
- takeAgain(): i64 {
965
+ private takeAgain(): i64 {
891
966
  const size: i32 = toI32(this.again.length)
892
967
  const id: i64 = this.again[this.againHead]
893
968
  this.againHead = (this.againHead + 1) % size
@@ -900,7 +975,7 @@ export class Http3Connection {
900
975
  }
901
976
 
902
977
  /** Puts stream `id`, slot `k`, on the `again` ring, unless it is there. */
903
- stepAgain(k: i32, id: i64): void {
978
+ private stepAgain(k: i32, id: i64): void {
904
979
  const size: i32 = toI32(this.again.length)
905
980
  if ((this.flags[k] & H3_FLAG_AGAIN) !== 0 || this.againCount >= size) {
906
981
  return
@@ -911,7 +986,7 @@ export class Http3Connection {
911
986
  }
912
987
 
913
988
  /** The next event stream `id` has, or H3_NEED_MORE when it has nothing more to say now. */
914
- step(id: i64): i32 {
989
+ private step(id: i64): i32 {
915
990
  const k: i32 = this.quic.streams.slotOf(id)
916
991
  if (k < 0 || k >= toI32(this.slotId.length)) {
917
992
  return H3_NEED_MORE
@@ -938,7 +1013,7 @@ export class Http3Connection {
938
1013
  }
939
1014
 
940
1015
  /** The state of a stream the client just opened in slot `k`. */
941
- open(k: i32, id: i64): void {
1016
+ private open(k: i32, id: i64): void {
942
1017
  this.slotId[k] = id
943
1018
  this.frameType[k] = H3_SKIP_TYPE
944
1019
  this.frameLeft[k] = -1
@@ -969,7 +1044,7 @@ export class Http3Connection {
969
1044
  }
970
1045
 
971
1046
  /** §5.2: a request past the GOAWAY this side sent is refused, both ways, unprocessed. */
972
- reject(k: i32, id: i64): void {
1047
+ private reject(k: i32, id: i64): void {
973
1048
  this.quic.streamReset(id, H3_REQUEST_REJECTED)
974
1049
  this.quic.streamStopSending(id, H3_REQUEST_REJECTED)
975
1050
  this.flags[k] = H3_FLAG_SEND_DONE
@@ -978,7 +1053,7 @@ export class Http3Connection {
978
1053
  }
979
1054
 
980
1055
  /** One of this side's own streams has news: the client may not stop it (§6.2.1, RFC 9204 §4.2). */
981
- ownStream(k: i32): i32 {
1056
+ private ownStream(k: i32): i32 {
982
1057
  const stream: QuicStream = this.quic.streams.slots[k]
983
1058
  if (stream.stopCode >= 0) {
984
1059
  return this.fail(H3_CLOSED_CRITICAL_STREAM)
@@ -987,7 +1062,7 @@ export class Http3Connection {
987
1062
  }
988
1063
 
989
1064
  /** Lets a slot's request count as finished once both of its sides are done. */
990
- settle(k: i32): void {
1065
+ private settle(k: i32): void {
991
1066
  const done: i32 = H3_FLAG_SEND_DONE | H3_FLAG_RECV_DONE | H3_FLAG_COUNTED
992
1067
  if ((this.flags[k] & done) === done) {
993
1068
  this.flags[k] = this.flags[k] & ~H3_FLAG_COUNTED
@@ -996,7 +1071,7 @@ export class Http3Connection {
996
1071
  }
997
1072
 
998
1073
  /** Marks flags on slot `k` and settles it. */
999
- mark(k: i32, bits: i32): void {
1074
+ private mark(k: i32, bits: i32): void {
1000
1075
  this.flags[k] = this.flags[k] | bits
1001
1076
  this.settle(k)
1002
1077
  }
@@ -1008,7 +1083,7 @@ export class Http3Connection {
1008
1083
  * `header` filled, 0 when more is needed, or the `QUIC_STREAM_*` answer
1009
1084
  * that ended the read.
1010
1085
  */
1011
- readHeader(k: i32, id: i64): i32 {
1086
+ private readHeader(k: i32, id: i64): i32 {
1012
1087
  const base: i32 = k * H3_HEAD
1013
1088
  while (this.headLen[k] < H3_HEAD) {
1014
1089
  const have: i32 = this.headLen[k]
@@ -1037,7 +1112,7 @@ export class Http3Connection {
1037
1112
  // ---- Unidirectional streams ------------------------------------------------------
1038
1113
 
1039
1114
  /** The next event of the client's unidirectional stream `id` in slot `k`. */
1040
- uniStep(k: i32, id: i64): i32 {
1115
+ private uniStep(k: i32, id: i64): i32 {
1041
1116
  while (this.state !== H3_STATE_FAILED) {
1042
1117
  const phase: i32 = this.phase[k]
1043
1118
  if (phase === H3_PHASE_UNI_TYPE) {
@@ -1086,7 +1161,7 @@ export class Http3Connection {
1086
1161
  }
1087
1162
 
1088
1163
  /** The client's unidirectional stream `id` turned out to be of `type` (§6.2). */
1089
- typed(k: i32, id: i64, type: i64): i32 {
1164
+ private typed(k: i32, id: i64, type: i64): i32 {
1090
1165
  if (type === H3_STREAM_CONTROL) {
1091
1166
  if (this.peerControl >= 0) {
1092
1167
  return this.fail(H3_STREAM_CREATION_ERROR)
@@ -1128,7 +1203,7 @@ export class Http3Connection {
1128
1203
  }
1129
1204
 
1130
1205
  /** Frames on the client's control stream (§6.2.1, §7.2). */
1131
- controlStep(k: i32, id: i64): i32 {
1206
+ private controlStep(k: i32, id: i64): i32 {
1132
1207
  while (this.state !== H3_STATE_FAILED) {
1133
1208
  if (this.frameLeft[k] < 0) {
1134
1209
  const got: i32 = this.readHeader(k, id)
@@ -1194,7 +1269,7 @@ export class Http3Connection {
1194
1269
  }
1195
1270
 
1196
1271
  /** Acts on a whole control frame of `type` in `control[0 .. controlFill)`. */
1197
- controlFrame(type: i64): i32 {
1272
+ private controlFrame(type: i64): i32 {
1198
1273
  if (type === H3_FRAME_SETTINGS) {
1199
1274
  const result: i64 = h3ReadSettings(this.peer, this.control, H3_ZERO, this.controlFill)
1200
1275
  if (result !== H3_SETTINGS_OK) {
@@ -1247,7 +1322,7 @@ export class Http3Connection {
1247
1322
  }
1248
1323
 
1249
1324
  /** Reads and drops what is left of stream `id`, slot `k`, to its end or reset. */
1250
- discard(k: i32, id: i64): i32 {
1325
+ private discard(k: i32, id: i64): i32 {
1251
1326
  const n: i32 = this.drop(id)
1252
1327
  if (n < 0) {
1253
1328
  this.phase[k] = H3_PHASE_DONE
@@ -1257,7 +1332,7 @@ export class Http3Connection {
1257
1332
  }
1258
1333
 
1259
1334
  /** Reads stream `id` into `data` until nothing more is there; answers 0, or the `QUIC_STREAM_*` that ended it. */
1260
- drop(id: i64): i32 {
1335
+ private drop(id: i64): i32 {
1261
1336
  let n: i32 = this.readData(id, this.config.bodyChunk)
1262
1337
  while (n > 0) {
1263
1338
  n = this.readData(id, this.config.bodyChunk)
@@ -1272,7 +1347,7 @@ export class Http3Connection {
1272
1347
  * held, unread, and the program told with H3_STREAM. A session ID that is
1273
1348
  * not a client-initiated bidirectional stream is H3_ID_ERROR (draft-02 §4).
1274
1349
  */
1275
- held(k: i32, id: i64, session: i64): i32 {
1350
+ private held(k: i32, id: i64, session: i64): i32 {
1276
1351
  if (!http3IsRequest(session)) {
1277
1352
  return this.fail(H3_ID_ERROR)
1278
1353
  }
@@ -1296,7 +1371,7 @@ export class Http3Connection {
1296
1371
  * FIN and H3_RESET at the client's RESET_STREAM; H3_STOPPED once for the
1297
1372
  * client's STOP_SENDING; and H3_WRITABLE.
1298
1373
  */
1299
- wtStep(k: i32, id: i64): i32 {
1374
+ private wtStep(k: i32, id: i64): i32 {
1300
1375
  const stream: QuicStream = this.quic.streams.slots[k]
1301
1376
  if (stream.stopCode >= 0 && (this.flags[k] & H3_FLAG_SEND_DONE) === 0) {
1302
1377
  this.mark(k, H3_FLAG_SEND_DONE)
@@ -1357,7 +1432,7 @@ export class Http3Connection {
1357
1432
  }
1358
1433
 
1359
1434
  /** The slot of WebTransport stream `id` when it is known here, else -1. */
1360
- wtSlot(id: i64): i32 {
1435
+ private wtSlot(id: i64): i32 {
1361
1436
  if (this.state === H3_STATE_FAILED) {
1362
1437
  return -1
1363
1438
  }
@@ -1377,6 +1452,10 @@ export class Http3Connection {
1377
1452
  * Lets a stream H3_STREAM held go: its bytes come as H3_DATA from the next
1378
1453
  * `next()`, and the program may write it. Answers 0, or H3_CLOSED for a
1379
1454
  * stream that is not one held.
1455
+ *
1456
+ * @param id The stream H3_STREAM named in `stream`.
1457
+ * @returns 0 once the stream is let go; H3_CLOSED for a stream not held, one already accepted, or
1458
+ * any stream once the connection has failed.
1380
1459
  */
1381
1460
  acceptStream(id: i64): i32 {
1382
1461
  const k: i32 = this.wtSlot(id)
@@ -1392,6 +1471,12 @@ export class Http3Connection {
1392
1471
  * Refuses WebTransport stream `id` with `code`: its side here is reset,
1393
1472
  * the client's asked to stop, and what it sent read and dropped. Answers 0,
1394
1473
  * or H3_CLOSED for a stream that is not a WebTransport one.
1474
+ *
1475
+ * @param id A WebTransport stream known here, held or accepted, the client's or this side's.
1476
+ * @param code The application error code its RESET_STREAM and STOP_SENDING carry. A side already
1477
+ * finished, reset or being dropped is left as it is.
1478
+ * @returns 0; H3_CLOSED for a stream that is not a WebTransport one known here, or any stream once
1479
+ * the connection has failed.
1395
1480
  */
1396
1481
  refuseStream(id: i64, code: i64): i32 {
1397
1482
  const k: i32 = this.wtSlot(id)
@@ -1404,7 +1489,7 @@ export class Http3Connection {
1404
1489
  }
1405
1490
 
1406
1491
  /** Asks the client to stop stream `id`, slot `k`, with `code`, and drops what it still sends, unless its side is over or being dropped. */
1407
- stopReading(k: i32, id: i64, code: i64): void {
1492
+ private stopReading(k: i32, id: i64, code: i64): void {
1408
1493
  if (this.phase[k] !== H3_PHASE_DONE && this.phase[k] !== H3_PHASE_DISCARD) {
1409
1494
  this.quic.streamStopSending(id, code)
1410
1495
  this.phase[k] = H3_PHASE_DISCARD
@@ -1418,6 +1503,14 @@ export class Http3Connection {
1418
1503
  * the signal 0x41, and the session ID, which go before anything written.
1419
1504
  * Answers its ID, H3_AGAIN while the client's MAX_STREAMS allows no more,
1420
1505
  * or H3_CLOSED with WebTransport off or the connection failed.
1506
+ *
1507
+ * @param session The session's ID: the ID of the client-initiated bidirectional stream that carried
1508
+ * its CONNECT. It is written as given; whether such a session is open here is not checked.
1509
+ * @param bidirectional True for a bidirectional stream (signal 0x41), false for a unidirectional one
1510
+ * (type 0x54) this side only writes.
1511
+ * @returns The new stream's ID; H3_AGAIN when QUIC can open no stream of that kind now; H3_CLOSED
1512
+ * with WebTransport off, the connection failed, or a `session` that is not a client-initiated
1513
+ * bidirectional stream ID.
1421
1514
  */
1422
1515
  openStream(session: i64, bidirectional: boolean): i64 {
1423
1516
  if (!this.webtransport || this.state === H3_STATE_FAILED || !http3IsRequest(session) || session < 0) {
@@ -1452,6 +1545,15 @@ export class Http3Connection {
1452
1545
  * many it took — fewer only when the send buffer filled, and H3_WRITABLE
1453
1546
  * then names the stream — or H3_AGAIN when it took none, or H3_CLOSED for
1454
1547
  * a stream with no side here to write, finished, reset, held or stopped.
1548
+ * A window outside `buf` panics.
1549
+ *
1550
+ * @param id A WebTransport stream this side writes, accepted or opened by `openStream`.
1551
+ * @param buf The bytes; copied into the stream's send buffer, so the caller may reuse it.
1552
+ * @param off Where the bytes start in `buf`.
1553
+ * @param len How many bytes to offer; 0 with `fin` sends only the FIN.
1554
+ * @param fin True to finish this side of the stream once all `len` bytes are taken.
1555
+ * @returns The bytes taken, 1 to `len`, or 0 for a FIN alone; H3_AGAIN when it took none, a `len` of
1556
+ * 0 without `fin` among them; H3_CLOSED as above, or any stream once the connection has failed.
1455
1557
  */
1456
1558
  writeStream(id: i64, buf: u8[], off: i32, len: i32, fin: boolean): i32 {
1457
1559
  h3CheckWindow("Http3Connection.writeStream", buf, off, len)
@@ -1480,7 +1582,15 @@ export class Http3Connection {
1480
1582
  return n > 0 || (fin && len === 0) ? n : H3_AGAIN
1481
1583
  }
1482
1584
 
1483
- /** Resets this side of WebTransport stream `id` with `code`; the client's side goes on. Answers 0 or H3_CLOSED. */
1585
+ /**
1586
+ * Resets this side of WebTransport stream `id` with `code`; the client's side goes on.
1587
+ *
1588
+ * @param id A WebTransport stream known here.
1589
+ * @param code The application error code RESET_STREAM carries; nothing is sent when this side is
1590
+ * already finished or reset.
1591
+ * @returns 0; H3_CLOSED for a stream that is not a WebTransport one known here, or any stream once
1592
+ * the connection has failed.
1593
+ */
1484
1594
  resetStream(id: i64, code: i64): i32 {
1485
1595
  const k: i32 = this.wtSlot(id)
1486
1596
  if (k < 0) {
@@ -1494,6 +1604,12 @@ export class Http3Connection {
1494
1604
  * Asks the client to stop its side of WebTransport stream `id` with
1495
1605
  * `code`, and drops what it still sends; this side's goes on. Answers 0 or
1496
1606
  * H3_CLOSED.
1607
+ *
1608
+ * @param id A WebTransport stream known here.
1609
+ * @param code The application error code STOP_SENDING carries; nothing is sent when the client's
1610
+ * side has already ended or is being dropped.
1611
+ * @returns 0; H3_CLOSED for a stream that is not a WebTransport one known here, or any stream once
1612
+ * the connection has failed.
1497
1613
  */
1498
1614
  stopStream(id: i64, code: i64): i32 {
1499
1615
  const k: i32 = this.wtSlot(id)
@@ -1507,7 +1623,7 @@ export class Http3Connection {
1507
1623
  // ---- Request streams ------------------------------------------------------------
1508
1624
 
1509
1625
  /** The next event of request stream `id` in slot `k`. */
1510
- requestStep(k: i32, id: i64): i32 {
1626
+ private requestStep(k: i32, id: i64): i32 {
1511
1627
  const stream: QuicStream = this.quic.streams.slots[k]
1512
1628
  while (this.state !== H3_STATE_FAILED) {
1513
1629
  const phase: i32 = this.phase[k]
@@ -1619,7 +1735,7 @@ export class Http3Connection {
1619
1735
  * trailers, and anything else unknown and skipped, or refused where
1620
1736
  * RFC 9114 says so. A stream that ends here ends the request.
1621
1737
  */
1622
- requestFrame(k: i32, id: i64): i32 {
1738
+ private requestFrame(k: i32, id: i64): i32 {
1623
1739
  const stream: QuicStream = this.quic.streams.slots[k]
1624
1740
  const resetCode: i64 = stream.resetCode
1625
1741
  const got: i32 = this.readHeader(k, id)
@@ -1709,7 +1825,7 @@ export class Http3Connection {
1709
1825
  * field section, or its trailers. Decodes it, copies it into `fields` and
1710
1826
  * checks it there.
1711
1827
  */
1712
- fieldSection(k: i32, id: i64, length: i32): i32 {
1828
+ private fieldSection(k: i32, id: i64, length: i32): i32 {
1713
1829
  const result: i64 = this.decoder.decode(this.section, H3_ZERO, length)
1714
1830
  const first: boolean = this.phase[k] === H3_PHASE_HEADERS
1715
1831
  if (result === QPACK_SECTION_TOO_LARGE) {
@@ -1740,7 +1856,7 @@ export class Http3Connection {
1740
1856
  }
1741
1857
 
1742
1858
  /** Copies the decoder's fields into the connection's own arrays and the lists `fields` reads. */
1743
- copyFields(): void {
1859
+ private copyFields(): void {
1744
1860
  const d: QpackDecoder = this.decoder
1745
1861
  http3EmptyList(this.nameList)
1746
1862
  http3EmptyList(this.valueList)
@@ -1760,7 +1876,7 @@ export class Http3Connection {
1760
1876
  * size than any before it, and the total stays bounded by the field-section
1761
1877
  * cap (`docs/security/http3.md`, H3-2).
1762
1878
  */
1763
- copyOf(d: QpackDecoder, start: i32, length: i32): u8[] {
1879
+ private copyOf(d: QpackDecoder, start: i32, length: i32): u8[] {
1764
1880
  let j: i32 = 0
1765
1881
  while (j < H3_FIELD_CLASSES - 1 && 1 << j <= length) {
1766
1882
  j++
@@ -1786,7 +1902,7 @@ export class Http3Connection {
1786
1902
  * The request stream ended, cleanly (`n` is `QUIC_STREAM_END`) or by the
1787
1903
  * client's RESET_STREAM with `resetCode`, at a frame boundary.
1788
1904
  */
1789
- ended(k: i32, id: i64, n: i32, resetCode: i64): i32 {
1905
+ private ended(k: i32, id: i64, n: i32, resetCode: i64): i32 {
1790
1906
  const phase: i32 = this.phase[k]
1791
1907
  this.phase[k] = H3_PHASE_DONE
1792
1908
  this.mark(k, H3_FLAG_RECV_DONE)
@@ -1816,7 +1932,7 @@ export class Http3Connection {
1816
1932
  }
1817
1933
 
1818
1934
  /** Resets this side's half of request stream `id` with `code`, unless it is done already. */
1819
- abandon(k: i32, id: i64, code: i64): void {
1935
+ private abandon(k: i32, id: i64, code: i64): void {
1820
1936
  if ((this.flags[k] & H3_FLAG_SEND_DONE) === 0) {
1821
1937
  this.quic.streamReset(id, code)
1822
1938
  }
@@ -1824,7 +1940,7 @@ export class Http3Connection {
1824
1940
  }
1825
1941
 
1826
1942
  /** A stream error (§8): the request is reset both ways with `code`, and the program told when it knew the request. */
1827
- streamError(k: i32, id: i64, code: i64): i32 {
1943
+ private streamError(k: i32, id: i64, code: i64): i32 {
1828
1944
  this.streamErrors = h3Count(this.streamErrors)
1829
1945
  this.abandon(k, id, code)
1830
1946
  this.quic.streamStopSending(id, code)
@@ -1836,7 +1952,7 @@ export class Http3Connection {
1836
1952
  }
1837
1953
 
1838
1954
  /** H3_DROPPED for request stream `id` with WebTransport on, which waits on such a stream; H3_NEED_MORE without. */
1839
- dropped(id: i64): i32 {
1955
+ private dropped(id: i64): i32 {
1840
1956
  if (!this.webtransport) {
1841
1957
  return H3_NEED_MORE
1842
1958
  }
@@ -1845,7 +1961,7 @@ export class Http3Connection {
1845
1961
  }
1846
1962
 
1847
1963
  /** H3_RESET for `id` with `code`. */
1848
- resetEvent(id: i64, code: i64, byPeer: boolean): i32 {
1964
+ private resetEvent(id: i64, code: i64, byPeer: boolean): i32 {
1849
1965
  this.stream = id
1850
1966
  this.errorCode = code
1851
1967
  this.resetByPeer = byPeer
@@ -1859,7 +1975,7 @@ export class Http3Connection {
1859
1975
  * SETTINGS_MAX_FIELD_SECTION_SIZE has room for a bare 431 but not for one
1860
1976
  * with the date gets it without the date rather than a reset.
1861
1977
  */
1862
- answerTooLarge(k: i32, id: i64): i32 {
1978
+ private answerTooLarge(k: i32, id: i64): i32 {
1863
1979
  this.tooLarge = h3Count(this.tooLarge)
1864
1980
  const empty: u8[][] = this.nameList
1865
1981
  http3EmptyList(empty)
@@ -1880,7 +1996,7 @@ export class Http3Connection {
1880
1996
  * written, and once the buffer has room again the program is told with
1881
1997
  * H3_WRITABLE. Answers that, or H3_NEED_MORE.
1882
1998
  */
1883
- writable(k: i32, id: i64): i32 {
1999
+ private writable(k: i32, id: i64): i32 {
1884
2000
  if ((this.flags[k] & H3_FLAG_BLOCKED) === 0 || (this.flags[k] & H3_FLAG_SEND_DONE) !== 0) {
1885
2001
  return H3_NEED_MORE
1886
2002
  }
@@ -1895,7 +2011,7 @@ export class Http3Connection {
1895
2011
  // ---- Writing ----------------------------------------------------------------------
1896
2012
 
1897
2013
  /** The slot of request stream `id` when the program may write to it, else -1. */
1898
- writeSlot(id: i64): i32 {
2014
+ private writeSlot(id: i64): i32 {
1899
2015
  if (this.state === H3_STATE_FAILED || !http3IsRequest(id)) {
1900
2016
  return -1
1901
2017
  }
@@ -1915,7 +2031,7 @@ export class Http3Connection {
1915
2031
  * a frame header, a filler's payload — as far as the send buffer takes
1916
2032
  * them. Answers whether none are owed now.
1917
2033
  */
1918
- drain(k: i32, id: i64): boolean {
2034
+ private drain(k: i32, id: i64): boolean {
1919
2035
  const base: i32 = k * H3_HEAD
1920
2036
  while (this.pendLen[k] > 0) {
1921
2037
  const n: i32 = this.quic.streamWrite(id, this.pend, base + this.pendAt[k], this.pendLen[k], false)
@@ -1937,7 +2053,7 @@ export class Http3Connection {
1937
2053
  }
1938
2054
 
1939
2055
  /** Queues `buf[0 .. n)`, a frame header, as the bytes owed first on slot `k`. */
1940
- owe(k: i32, buf: u8[], n: i32): void {
2056
+ private owe(k: i32, buf: u8[], n: i32): void {
1941
2057
  const base: i32 = k * H3_HEAD
1942
2058
  for (let j: i32 = 0; j < n && j < H3_HEAD && j < toI32(buf.length); j++) {
1943
2059
  this.pend[base + j] = buf[j]
@@ -1951,7 +2067,7 @@ export class Http3Connection {
1951
2067
  * the room left is filled with a reserved frame the client skips (§7.2.8),
1952
2068
  * so that QUIC names the stream again once acknowledgements free room.
1953
2069
  */
1954
- arm(k: i32, id: i64): void {
2070
+ private arm(k: i32, id: i64): void {
1955
2071
  const stream: QuicStream = this.quic.streams.slots[k]
1956
2072
  const room: i64 = stream.room()
1957
2073
  this.mark(k, H3_FLAG_BLOCKED)
@@ -1990,7 +2106,15 @@ export class Http3Connection {
1990
2106
  * SETTINGS_MAX_FIELD_SECTION_SIZE as any field does. Answers 0, H3_AGAIN,
1991
2107
  * or H3_TOO_LARGE.
1992
2108
  */
1993
- writeHead(k: i32, id: i64, status: i32, names: u8[][], values: u8[][], fin: boolean, dated: boolean): i32 {
2109
+ private writeHead(
2110
+ k: i32,
2111
+ id: i64,
2112
+ status: i32,
2113
+ names: u8[][],
2114
+ values: u8[][],
2115
+ fin: boolean,
2116
+ dated: boolean
2117
+ ): i32 {
1994
2118
  const out: u8[] = this.encoded
1995
2119
  http3Empty(out)
1996
2120
  this.encoder.beginSection(out)
@@ -2067,6 +2191,18 @@ export class Http3Connection {
2067
2191
  * that is not an open request; H3_INVALID for a second head, a status out
2068
2192
  * of range or a field `httpFieldsCheckOutgoing` refuses; H3_TOO_LARGE for a
2069
2193
  * section past the client's SETTINGS_MAX_FIELD_SECTION_SIZE; or H3_AGAIN.
2194
+ *
2195
+ * @param id The request stream, as H3_REQUEST named it in `stream`.
2196
+ * @param status The final status, 200 to 599.
2197
+ * @param names The field names, lowercase and valid, as many as `values`; encoded, not kept.
2198
+ * @param values The field values, one per name; encoded, not kept.
2199
+ * @param endStream True to end the stream with the head, for a response with no body.
2200
+ * @returns 0 once the whole HEADERS frame is in the send buffer; H3_CLOSED for a stream that is not
2201
+ * an open request: unknown, not yet handed to the program, its response finished or reset, stopped
2202
+ * by the client, or any stream once the connection has failed;
2203
+ * H3_INVALID as above; H3_TOO_LARGE for a section past the client's limit or a frame past the
2204
+ * stream's buffer; H3_AGAIN while the send buffer lacks room for the frame, and H3_WRITABLE then
2205
+ * names the stream.
2070
2206
  */
2071
2207
  respond(id: i64, status: i32, names: u8[][], values: u8[][], endStream: boolean): i32 {
2072
2208
  const k: i32 = this.writeSlot(id)
@@ -2088,6 +2224,14 @@ export class Http3Connection {
2088
2224
  * Writes a trailer section on request stream `id` after its body, which
2089
2225
  * ends the stream. Answers as `respond` does; H3_INVALID before the head
2090
2226
  * or inside a DATA frame `writeData` has not finished.
2227
+ *
2228
+ * @param id The request stream, after `respond`.
2229
+ * @param names The trailer field names, lowercase and valid, as many as `values`; encoded, not kept.
2230
+ * @param values The trailer field values, one per name; encoded, not kept.
2231
+ * @returns 0 once the whole frame is in the send buffer and the stream ended; H3_CLOSED for a stream
2232
+ * that is not an open request: unknown, not yet handed to the program, its response finished or
2233
+ * reset, stopped by the client, or any stream once the connection has failed;
2234
+ * H3_INVALID as above; H3_TOO_LARGE or H3_AGAIN as `respond` answers them.
2091
2235
  */
2092
2236
  writeTrailers(id: i64, names: u8[][], values: u8[][]): i32 {
2093
2237
  const k: i32 = this.writeSlot(id)
@@ -2113,6 +2257,19 @@ export class Http3Connection {
2113
2257
  * took none;
2114
2258
  * H3_CLOSED, or H3_INVALID before the head or when `endStream` would cut
2115
2259
  * short the DATA frame the last call started.
2260
+ * A window outside `buf` panics.
2261
+ *
2262
+ * @param id The request stream, after `respond`.
2263
+ * @param buf The body bytes; copied into the stream's send buffer, so the caller may reuse it.
2264
+ * @param off Where the bytes start in `buf`.
2265
+ * @param len How many bytes to offer; 0 with `endStream` sends only the end.
2266
+ * @param endStream True to end the stream once all `len` bytes are taken.
2267
+ * @returns The bytes taken, 1 to `len` — fewer when the send buffer filled, or when the stream closed
2268
+ * partway — or 0 for a `len` of 0; H3_AGAIN when it took none, or while bytes an earlier call
2269
+ * left owed cannot go; H3_CLOSED for a stream that is not an open request: unknown, not yet handed
2270
+ * to the program, its response finished or reset, stopped by the client, or any stream once the
2271
+ * connection has failed;
2272
+ * H3_INVALID as above.
2116
2273
  */
2117
2274
  writeData(id: i64, buf: u8[], off: i32, len: i32, endStream: boolean): i32 {
2118
2275
  h3CheckWindow("Http3Connection.writeData", buf, off, len)
@@ -2180,6 +2337,18 @@ export class Http3Connection {
2180
2337
  * H3_AGAIN while the send buffer lacks room, and H3_WRITABLE then names the
2181
2338
  * stream; or as `writeData` refuses, and H3_TOO_LARGE for a frame past the
2182
2339
  * stream's buffer.
2340
+ * A window outside `buf` panics.
2341
+ *
2342
+ * @param id The request stream, after `respond`.
2343
+ * @param buf The frame's payload; copied into the stream's send buffer, so the caller may reuse it.
2344
+ * @param off Where the payload starts in `buf`.
2345
+ * @param len The payload's length in bytes; the frame with its header must fit the stream's buffer.
2346
+ * @param fin True to end the stream after the frame.
2347
+ * @returns 0 once the whole frame is in the send buffer; H3_AGAIN while the send buffer lacks room for
2348
+ * it, and H3_WRITABLE then names the stream; H3_CLOSED for a stream that is not an open request:
2349
+ * unknown, not yet handed to the program, its response finished or reset, stopped by the client, or
2350
+ * any stream once the connection has failed;
2351
+ * H3_INVALID before the head or inside a DATA frame `writeData` has not finished; H3_TOO_LARGE.
2183
2352
  */
2184
2353
  writeDataWhole(id: i64, buf: u8[], off: i32, len: i32, fin: boolean): i32 {
2185
2354
  h3CheckWindow("Http3Connection.writeDataWhole", buf, off, len)
@@ -2216,6 +2385,13 @@ export class Http3Connection {
2216
2385
  * Resets request stream `id` both ways with `code` — H3_REQUEST_CANCELLED,
2217
2386
  * or H3_REQUEST_REJECTED for one the program did not process (§4.1.1).
2218
2387
  * Answers 0 or H3_CLOSED.
2388
+ *
2389
+ * @param id The request stream, as H3_REQUEST named it.
2390
+ * @param code The error code RESET_STREAM and STOP_SENDING carry; STOP_SENDING is not sent once the
2391
+ * request has been read to its end.
2392
+ * @returns 0; H3_CLOSED for a stream that is not an open request: unknown, not yet handed to the
2393
+ * program, its response finished or reset, stopped by the client, or any stream once the connection
2394
+ * has failed.
2219
2395
  */
2220
2396
  reset(id: i64, code: i64): i32 {
2221
2397
  const k: i32 = this.writeSlot(id)
@@ -2235,6 +2411,12 @@ export class Http3Connection {
2235
2411
  * not opened, opened by a later stream's frame (RFC 9000 §3.2), or still
2236
2412
  * waiting for its HEADERS. A WebTransport stream that names it as its
2237
2413
  * session may wait for it.
2414
+ *
2415
+ * @param id A stream ID, as a WebTransport stream named its session.
2416
+ * @returns True while the request may still come: not opened and within what the client may open now,
2417
+ * opened but not yet read here, or waiting for its HEADERS; false for an ID that is no
2418
+ * client-initiated bidirectional stream, one at or past this side's GOAWAY, a WebTransport stream,
2419
+ * or one whose field section has been read or refused.
2238
2420
  */
2239
2421
  awaitsRequest(id: i64): boolean {
2240
2422
  if (!http3IsRequest(id) || id < 0 || (this.goawayId >= 0 && id >= this.goawayId)) {
@@ -2258,6 +2440,12 @@ export class Http3Connection {
2258
2440
  * side has finished its response — a refused WebTransport session's
2259
2441
  * stream, after its status. Answers 0, or H3_CLOSED for a stream that is
2260
2442
  * not a request here.
2443
+ *
2444
+ * @param id The request stream.
2445
+ * @param code The error code STOP_SENDING carries; nothing is sent when the client's side has already
2446
+ * ended or is being dropped.
2447
+ * @returns 0, also when there was nothing left to stop; H3_CLOSED for an ID that is no request stream
2448
+ * known here, or any stream once the connection has failed.
2261
2449
  */
2262
2450
  discardRequest(id: i64, code: i64): i32 {
2263
2451
  if (this.state === H3_STATE_FAILED || !http3IsRequest(id)) {
@@ -2278,6 +2466,10 @@ export class Http3Connection {
2278
2466
  * call never raises the ID, and sends nothing when the ID has not fallen.
2279
2467
  * Answers 0, or H3_AGAIN before this side's control stream is open or while
2280
2468
  * it has no room for the frame.
2469
+ *
2470
+ * @returns 0 once the frame is in the control stream's send buffer, or when there was nothing new to
2471
+ * send; H3_AGAIN before this side's control stream is open, while it has no room for the whole
2472
+ * frame, and on a connection that has failed.
2281
2473
  */
2282
2474
  goaway(): i32 {
2283
2475
  if (this.ownControl < 0 || this.state === H3_STATE_FAILED) {