@amritk/nish-aarch64-linux 0.35.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
package/std/net/qpack.ts
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
*
|
|
9
9
|
* import { QpackDecoder, QpackEncoder, QPACK_OK } from "nish/net/qpack";
|
|
10
10
|
*
|
|
11
|
+
* const name: u8[] = [58, 112, 97, 116, 104]; // ":path"
|
|
12
|
+
* const value: u8[] = [47]; // "/"
|
|
13
|
+
*
|
|
11
14
|
* const enc = new QpackEncoder(); // one per connection
|
|
12
15
|
* const section: u8[] = [];
|
|
13
16
|
* enc.beginSection(section);
|
|
@@ -28,20 +31,21 @@
|
|
|
28
31
|
* block on (§2.1.2) and nothing to acknowledge (§4.4.1).
|
|
29
32
|
*
|
|
30
33
|
* **What is refused.** `QpackDecoder.decode` answers QPACK_DECOMPRESSION_FAILED
|
|
31
|
-
* for a section that ends inside a representation, an integer past 2^62 - 1
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* QPACK_DECODER_STREAM_ERROR for a
|
|
41
|
-
* it sent needs one), any Insert
|
|
42
|
-
* nothing) and a stream ID past
|
|
43
|
-
* so each is sticky: the same answer
|
|
44
|
-
* reading anything, and `reason` says
|
|
34
|
+
* for a section that ends inside a representation, an integer past 2^62 - 1 (or
|
|
35
|
+
* padded past the nine continuation bytes such an integer needs), a non-zero
|
|
36
|
+
* Required Insert Count (§4.5.1.1), a negative Base (§4.5.1.2), any reference
|
|
37
|
+
* to the dynamic table, relative or post-Base (§2.2.3), a static index past 98,
|
|
38
|
+
* and Huffman padding that is not EOS's prefix or an EOS inside a string.
|
|
39
|
+
*
|
|
40
|
+
* `receiveEncoderStream` answers QPACK_ENCODER_STREAM_ERROR for a Set Dynamic
|
|
41
|
+
* Table Capacity above 0 (§4.3.1), any Insert (§3.2.2: every entry is larger
|
|
42
|
+
* than the table) and any Duplicate (§2.2.3: there is nothing to duplicate).
|
|
43
|
+
* The encoder's `receiveDecoderStream` answers QPACK_DECODER_STREAM_ERROR for a
|
|
44
|
+
* Section Acknowledgment (§4.4.1: no section it sent needs one), any Insert
|
|
45
|
+
* Count Increment (§4.4.3: it has inserted nothing) and a stream ID past
|
|
46
|
+
* 2^62 - 1. Each of those is a connection error, so each is sticky: the same answer
|
|
47
|
+
* comes back from every later call without reading anything, and `reason` says
|
|
48
|
+
* which rule it was (`QPACK_REASON_*`).
|
|
45
49
|
*
|
|
46
50
|
* **What is accepted.** A Set Dynamic Table Capacity of 0 on the encoder
|
|
47
51
|
* stream, and a Stream Cancellation on the decoder stream, read a byte at a
|
|
@@ -598,6 +602,9 @@ const qpackPushString = (
|
|
|
598
602
|
* Appends a Stream Cancellation for `streamId` (§4.4.2), the one instruction a
|
|
599
603
|
* decoder of capacity 0 may send on its decoder stream, and may also omit.
|
|
600
604
|
* A stream ID outside 0 to 2^62 - 1 panics.
|
|
605
|
+
* @param out Where the instruction goes, appended after what it holds: one byte for a stream ID under 63,
|
|
606
|
+
* else one plus its continuation bytes.
|
|
607
|
+
* @param streamId The ID of the request stream whose section the peer's encoder may forget, 0 to 2^62 - 1.
|
|
601
608
|
*/
|
|
602
609
|
export const qpackPushStreamCancellation = (out: u8[], streamId: i64): void => {
|
|
603
610
|
qpackPushInteger(out, 64, 6, streamId)
|
|
@@ -730,21 +737,41 @@ const qpackReadString = (d: QpackDecoder, src: u8[], prefixBits: i32): i32 => {
|
|
|
730
737
|
* `decode` answers a section's fields as windows into `bytes`: field `i`'s
|
|
731
738
|
* name is `bytes[nameStart[i], + nameLength[i])`, its value likewise, and
|
|
732
739
|
* `neverIndexed[i]` is its N bit, which an intermediary forwarding it must
|
|
733
|
-
* keep (§4.5.4). All of them are replaced by every
|
|
740
|
+
* keep (§4.5.4). All of them are replaced by every `decode`.
|
|
734
741
|
*/
|
|
735
742
|
export class QpackDecoder {
|
|
743
|
+
/** @internal The Huffman decoder's tables, read by this module's `qpackReadString`; not for callers. */
|
|
736
744
|
huffman: HpackHuffman
|
|
737
|
-
/**
|
|
745
|
+
/**
|
|
746
|
+
* The connection error a call met, which every later call answers; `QPACK_OK` until then.
|
|
747
|
+
* @internal Reset by `http3.ts`'s `restart`; callers read the answers `decode` and
|
|
748
|
+
* `receiveEncoderStream` give.
|
|
749
|
+
*/
|
|
738
750
|
failed: i64
|
|
751
|
+
/**
|
|
752
|
+
* Every name and value of the last section `decode` answered, back to back; emptied by every
|
|
753
|
+
* `decode` call, including one that refuses, and valid until the next.
|
|
754
|
+
*/
|
|
739
755
|
bytes: u8[]
|
|
756
|
+
/** Where field `i`'s name starts in `bytes`, for `i` below `count`. */
|
|
740
757
|
nameStart: i32[]
|
|
758
|
+
/** How many bytes field `i`'s name has in `bytes`. */
|
|
741
759
|
nameLength: i32[]
|
|
760
|
+
/** Where field `i`'s value starts in `bytes`, for `i` below `count`. */
|
|
742
761
|
valueStart: i32[]
|
|
762
|
+
/** How many bytes field `i`'s value has in `bytes`. */
|
|
743
763
|
valueLength: i32[]
|
|
764
|
+
/**
|
|
765
|
+
* Field `i`'s N bit (§4.5.4): true when the peer marked it never to be indexed; always false
|
|
766
|
+
* for an Indexed Field Line, which has no such bit.
|
|
767
|
+
*/
|
|
744
768
|
neverIndexed: boolean[]
|
|
745
769
|
/** SETTINGS_MAX_FIELD_SECTION_SIZE as RFC 9114 §4.2.2 counts it. */
|
|
746
770
|
maxFieldSectionSize: i32
|
|
747
|
-
/**
|
|
771
|
+
/**
|
|
772
|
+
* Which rule the connection error broke, a `QPACK_REASON_*`; `QPACK_REASON_NONE` until a call
|
|
773
|
+
* answers QPACK_DECOMPRESSION_FAILED or QPACK_ENCODER_STREAM_ERROR. Reset by `http3.ts`'s `restart`.
|
|
774
|
+
*/
|
|
748
775
|
reason: i32
|
|
749
776
|
/** How many Set Dynamic Table Capacity 0 instructions the encoder stream carried, saturating at 2^31 - 1. */
|
|
750
777
|
capacityInstructions: i32
|
|
@@ -754,12 +781,25 @@ export class QpackDecoder {
|
|
|
754
781
|
* What the section being decoded may still add to `bytes` and its fields'
|
|
755
782
|
* overhead before it is past `maxFieldSectionSize`: every append is checked
|
|
756
783
|
* against it first, so a section past the limit never grows `bytes`.
|
|
784
|
+
* @internal Read and lowered by this module's `qpackReadString`; not for callers.
|
|
757
785
|
*/
|
|
758
786
|
room: i64
|
|
759
|
-
/**
|
|
787
|
+
/**
|
|
788
|
+
* @internal Where the next read of the section being decoded starts; read and advanced by this
|
|
789
|
+
* module's `qpackHasByte`, `qpackReadInteger` and `qpackReadString`.
|
|
790
|
+
*/
|
|
760
791
|
at: i32
|
|
792
|
+
/**
|
|
793
|
+
* @internal Where the section being decoded ends; read by this module's `qpackHasByte` and
|
|
794
|
+
* `qpackReadString`.
|
|
795
|
+
*/
|
|
761
796
|
end: i32
|
|
762
797
|
|
|
798
|
+
/**
|
|
799
|
+
* Makes a decoder with no fields, no connection error and no capacity instructions counted.
|
|
800
|
+
* @param maxFieldSectionSize The largest field section `decode` accepts, as RFC 9114 §4.2.2
|
|
801
|
+
* counts it: each field's name and value in bytes plus 32. A negative limit panics.
|
|
802
|
+
*/
|
|
763
803
|
constructor(maxFieldSectionSize: i32) {
|
|
764
804
|
if (maxFieldSectionSize < 0) {
|
|
765
805
|
panic(`QpackDecoder: a field-section limit of ${maxFieldSectionSize}`)
|
|
@@ -787,6 +827,13 @@ export class QpackDecoder {
|
|
|
787
827
|
* module comment lists what each means. A decoder whose encoder stream was
|
|
788
828
|
* refused answers QPACK_ENCODER_STREAM_ERROR again instead, since the
|
|
789
829
|
* connection is closing. Anything but `QPACK_OK` leaves no fields.
|
|
830
|
+
* @param section The buffer holding the section; only read, and its names and values are
|
|
831
|
+
* copied into `bytes`, so it may be reused once the call returns.
|
|
832
|
+
* @param off Where the section starts in `section`.
|
|
833
|
+
* @param len How many bytes the section has; a window outside `section` panics.
|
|
834
|
+
* @returns `QPACK_OK` with `count` fields; `QPACK_SECTION_TOO_LARGE`, which does not stick;
|
|
835
|
+
* QPACK_DECOMPRESSION_FAILED, which sticks; or, without reading anything, the
|
|
836
|
+
* QPACK_DECOMPRESSION_FAILED or QPACK_ENCODER_STREAM_ERROR an earlier call met.
|
|
790
837
|
*/
|
|
791
838
|
decode(section: u8[], off: i32, len: i32): i64 {
|
|
792
839
|
qpackCheckWindow("QpackDecoder.decode", section, off, len)
|
|
@@ -813,6 +860,12 @@ export class QpackDecoder {
|
|
|
813
860
|
* instruction a peer may send is Set Dynamic Table Capacity 0, the single
|
|
814
861
|
* byte `0x20`, so every other first byte is refused on sight: its top bits
|
|
815
862
|
* already say which instruction it begins, and none of them can be valid.
|
|
863
|
+
* @param buf The bytes the encoder stream carried; only read, nothing is kept.
|
|
864
|
+
* @param off Where they start in `buf`.
|
|
865
|
+
* @param len How many there are; zero is accepted, and a window outside `buf` panics.
|
|
866
|
+
* @returns `QPACK_OK` when every byte was a Set Dynamic Table Capacity 0; QPACK_ENCODER_STREAM_ERROR,
|
|
867
|
+
* which sticks, at the first byte that is not; or, without reading anything, the
|
|
868
|
+
* QPACK_DECOMPRESSION_FAILED or QPACK_ENCODER_STREAM_ERROR an earlier call met.
|
|
816
869
|
*/
|
|
817
870
|
receiveEncoderStream(buf: u8[], off: i32, len: i32): i64 {
|
|
818
871
|
qpackCheckWindow("QpackDecoder.receiveEncoderStream", buf, off, len)
|
|
@@ -842,7 +895,7 @@ export class QpackDecoder {
|
|
|
842
895
|
}
|
|
843
896
|
|
|
844
897
|
/** Empties the fields, keeping the arrays' storage for the next section. */
|
|
845
|
-
clear(): void {
|
|
898
|
+
private clear(): void {
|
|
846
899
|
while (this.bytes.length > 0) {
|
|
847
900
|
this.bytes.pop()
|
|
848
901
|
}
|
|
@@ -868,7 +921,7 @@ export class QpackDecoder {
|
|
|
868
921
|
* Takes `cost` from what the section has room for and answers true, or
|
|
869
922
|
* answers false and takes nothing when the section would pass its limit.
|
|
870
923
|
*/
|
|
871
|
-
take(cost: i64): boolean {
|
|
924
|
+
private take(cost: i64): boolean {
|
|
872
925
|
if (cost > this.room) {
|
|
873
926
|
return false
|
|
874
927
|
}
|
|
@@ -877,7 +930,7 @@ export class QpackDecoder {
|
|
|
877
930
|
}
|
|
878
931
|
|
|
879
932
|
/** The answer for a string read: `QPACK_OK`, past the limit, or the refusal `status` names. */
|
|
880
|
-
stringResult(status: i32): i64 {
|
|
933
|
+
private stringResult(status: i32): i64 {
|
|
881
934
|
if (status === QPACK_STRING_PAST_LIMIT) {
|
|
882
935
|
return QPACK_SECTION_TOO_LARGE
|
|
883
936
|
}
|
|
@@ -885,18 +938,18 @@ export class QpackDecoder {
|
|
|
885
938
|
}
|
|
886
939
|
|
|
887
940
|
/** Records `reason` and answers QPACK_DECOMPRESSION_FAILED. */
|
|
888
|
-
refuse(reason: i32): i64 {
|
|
941
|
+
private refuse(reason: i32): i64 {
|
|
889
942
|
this.reason = reason
|
|
890
943
|
return QPACK_DECOMPRESSION_FAILED
|
|
891
944
|
}
|
|
892
945
|
|
|
893
946
|
/** The refusal for a negative `qpackReadInteger` answer. */
|
|
894
|
-
refuseInteger(status: i64): i64 {
|
|
947
|
+
private refuseInteger(status: i64): i64 {
|
|
895
948
|
return this.refuse(qpackIntegerReason(status))
|
|
896
949
|
}
|
|
897
950
|
|
|
898
951
|
/** Records a field whose name and value end where `bytes` ends now. */
|
|
899
|
-
addField(nameStart: i32, valueStart: i32, neverIndexed: boolean): void {
|
|
952
|
+
private addField(nameStart: i32, valueStart: i32, neverIndexed: boolean): void {
|
|
900
953
|
this.nameStart.push(nameStart)
|
|
901
954
|
this.nameLength.push(valueStart - nameStart)
|
|
902
955
|
this.valueStart.push(valueStart)
|
|
@@ -909,7 +962,7 @@ export class QpackDecoder {
|
|
|
909
962
|
* The body of `decode`: the prefix, then one pass over the field lines,
|
|
910
963
|
* each told apart by its first byte's pattern (§4.5.2 to §4.5.6).
|
|
911
964
|
*/
|
|
912
|
-
decodeLines(src: u8[]): i64 {
|
|
965
|
+
private decodeLines(src: u8[]): i64 {
|
|
913
966
|
const insertCount: i64 = qpackReadInteger(this, src, 8)
|
|
914
967
|
if (insertCount < 0) {
|
|
915
968
|
return this.refuseInteger(insertCount)
|
|
@@ -1015,18 +1068,33 @@ export class QpackDecoder {
|
|
|
1015
1068
|
* anything on its own encoder stream once the stream type is written.
|
|
1016
1069
|
*/
|
|
1017
1070
|
export class QpackEncoder {
|
|
1018
|
-
huffman: HpackHuffman
|
|
1019
|
-
/**
|
|
1071
|
+
private huffman: HpackHuffman
|
|
1072
|
+
/**
|
|
1073
|
+
* The connection error the decoder stream met, which every later call answers; `QPACK_OK` until then.
|
|
1074
|
+
* @internal Reset by `http3.ts`'s `restart`; callers read the answers `receiveDecoderStream` gives.
|
|
1075
|
+
*/
|
|
1020
1076
|
failed: i64
|
|
1021
|
-
/**
|
|
1077
|
+
/**
|
|
1078
|
+
* Which rule the decoder stream broke, a `QPACK_REASON_*`; `QPACK_REASON_NONE` until
|
|
1079
|
+
* `receiveDecoderStream` answers QPACK_DECODER_STREAM_ERROR. Reset by `http3.ts`'s `restart`.
|
|
1080
|
+
*/
|
|
1022
1081
|
reason: i32
|
|
1023
|
-
/** How many Stream Cancellations the decoder stream carried, saturating at 2^31 - 1
|
|
1082
|
+
/** How many Stream Cancellations the decoder stream carried, saturating at 2^31 - 1. */
|
|
1024
1083
|
cancellations: i32
|
|
1084
|
+
/** The stream ID the last Stream Cancellation named; -1 until one arrives. */
|
|
1025
1085
|
lastCancelled: i64
|
|
1026
|
-
/**
|
|
1086
|
+
/**
|
|
1087
|
+
* The stream ID of a Stream Cancellation still being read.
|
|
1088
|
+
* @internal Reset by `http3.ts`'s `restart`; not for callers.
|
|
1089
|
+
*/
|
|
1027
1090
|
pendingId: i64
|
|
1091
|
+
/**
|
|
1092
|
+
* The shift of the next byte of a Stream Cancellation still being read; -1 between instructions.
|
|
1093
|
+
* @internal Reset by `http3.ts`'s `restart`; not for callers.
|
|
1094
|
+
*/
|
|
1028
1095
|
pendingShift: i32
|
|
1029
1096
|
|
|
1097
|
+
/** Makes an encoder whose decoder stream has carried nothing yet. */
|
|
1030
1098
|
constructor() {
|
|
1031
1099
|
this.huffman = new HpackHuffman()
|
|
1032
1100
|
this.failed = QPACK_OK
|
|
@@ -1040,6 +1108,7 @@ export class QpackEncoder {
|
|
|
1040
1108
|
/**
|
|
1041
1109
|
* Appends the prefix every field section of this encoder begins with: a
|
|
1042
1110
|
* Required Insert Count of 0 and a Base of 0, the bytes `00 00`.
|
|
1111
|
+
* @param out The buffer the section is being written to; the two bytes go after what it holds.
|
|
1043
1112
|
*/
|
|
1044
1113
|
beginSection(out: u8[]): void {
|
|
1045
1114
|
out.push(0)
|
|
@@ -1057,6 +1126,18 @@ export class QpackEncoder {
|
|
|
1057
1126
|
* A field marked `neverIndexed` is always a literal with the N bit set, even
|
|
1058
1127
|
* when the static table holds it, so that an intermediary re-encoding it
|
|
1059
1128
|
* keeps it out of every dynamic table downstream (§4.5.4, §7.1.3).
|
|
1129
|
+
*
|
|
1130
|
+
* A window outside its buffer panics.
|
|
1131
|
+
* @param out The buffer the section is being written to; the field line goes after what it holds.
|
|
1132
|
+
* @param name The buffer holding the name; only read. It matches a static entry only byte for
|
|
1133
|
+
* byte, so it should already be lowercase (RFC 9114 §4.2).
|
|
1134
|
+
* @param nameOff Where the name starts in `name`.
|
|
1135
|
+
* @param nameLen How many bytes the name has.
|
|
1136
|
+
* @param value The buffer holding the value; only read.
|
|
1137
|
+
* @param valueOff Where the value starts in `value`.
|
|
1138
|
+
* @param valueLen How many bytes the value has.
|
|
1139
|
+
* @param neverIndexed Whether to send the field as a literal with the N bit set.
|
|
1140
|
+
* @param huffman Whether a string may be Huffman-coded; it is only when that is shorter.
|
|
1060
1141
|
*/
|
|
1061
1142
|
encodeField(
|
|
1062
1143
|
out: u8[],
|
|
@@ -1104,6 +1185,13 @@ export class QpackEncoder {
|
|
|
1104
1185
|
* split it. A Section Acknowledgment and an Insert Count Increment are
|
|
1105
1186
|
* refused on their first byte: this encoder sent no section that needs
|
|
1106
1187
|
* acknowledging and inserted nothing to count.
|
|
1188
|
+
* @param buf The bytes the decoder stream carried; only read, nothing is kept.
|
|
1189
|
+
* @param off Where they start in `buf`.
|
|
1190
|
+
* @param len How many there are; zero is accepted, and a window outside `buf` panics.
|
|
1191
|
+
* @returns `QPACK_OK` when every byte belonged to a Stream Cancellation, finished or not;
|
|
1192
|
+
* QPACK_DECODER_STREAM_ERROR, which sticks, for a Section Acknowledgment, an Insert Count
|
|
1193
|
+
* Increment, a stream ID past 2^62 - 1, or one whose encoding runs past ten bytes; or that
|
|
1194
|
+
* same error again, without reading anything, once an earlier call met it.
|
|
1107
1195
|
*/
|
|
1108
1196
|
receiveDecoderStream(buf: u8[], off: i32, len: i32): i64 {
|
|
1109
1197
|
qpackCheckWindow("QpackEncoder.receiveDecoderStream", buf, off, len)
|
|
@@ -1147,7 +1235,7 @@ export class QpackEncoder {
|
|
|
1147
1235
|
}
|
|
1148
1236
|
|
|
1149
1237
|
/** Counts a Stream Cancellation for `streamId`. */
|
|
1150
|
-
cancelled(streamId: i64): void {
|
|
1238
|
+
private cancelled(streamId: i64): void {
|
|
1151
1239
|
if (this.cancellations < QPACK_COUNT_MAX) {
|
|
1152
1240
|
this.cancellations += 1
|
|
1153
1241
|
}
|
|
@@ -1155,7 +1243,7 @@ export class QpackEncoder {
|
|
|
1155
1243
|
}
|
|
1156
1244
|
|
|
1157
1245
|
/** Records `reason` and answers QPACK_DECODER_STREAM_ERROR, which sticks. */
|
|
1158
|
-
refuse(reason: i32): i64 {
|
|
1246
|
+
private refuse(reason: i32): i64 {
|
|
1159
1247
|
this.reason = reason
|
|
1160
1248
|
this.failed = QPACK_DECODER_STREAM_ERROR
|
|
1161
1249
|
return this.failed
|
package/std/net/quic-conn-ack.ts
CHANGED
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
* import { QuicAckRanges } from "nish/net/quic-conn-ack";
|
|
7
7
|
*
|
|
8
|
-
* const received = new QuicAckRanges()
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* const received: QuicAckRanges = new QuicAckRanges()
|
|
9
|
+
* const fresh: boolean = received.record(toI64(7), true) // true: 7 is new and asks for an ACK
|
|
10
|
+
* const again: boolean = received.record(toI64(7), true) // false: a duplicate, so drop the packet
|
|
11
|
+
* const payload: u8[] = []
|
|
12
|
+
* if (received.ackPending) {
|
|
13
|
+
* received.pushAck(payload, toI64(0)) // appends ACK [7, 7], clears ackPending
|
|
14
|
+
* }
|
|
11
15
|
*
|
|
12
16
|
* **Bounded.** At most `QUIC_ACK_MAX_RANGES` ranges are kept, highest first.
|
|
13
17
|
* A new range past that drops the lowest, and everything at or below what it
|
|
@@ -17,12 +21,12 @@
|
|
|
17
21
|
* peer that sends packet numbers full of holes costs a fixed amount of memory
|
|
18
22
|
* and loses only very late packets.
|
|
19
23
|
*
|
|
20
|
-
* **When to acknowledge
|
|
24
|
+
* **When to acknowledge.** That is the connection's choice; this module records
|
|
21
25
|
* whether something ack-eliciting arrived since the last ACK it wrote
|
|
22
26
|
* (`ackPending`). ACK frames carry an ACK Delay the caller supplies, and no
|
|
23
27
|
* ECN counts.
|
|
24
28
|
*
|
|
25
|
-
* Written from RFC 9000 §12.3, §13.2 and §19.3, not ported from another
|
|
29
|
+
* **Provenance.** Written from RFC 9000 §12.3, §13.2 and §19.3, not ported from another
|
|
26
30
|
* implementation. Private names carry the `quicAck` prefix
|
|
27
31
|
* (`docs/wp26-stdlib.md` §3e).
|
|
28
32
|
*/
|
|
@@ -42,16 +46,26 @@ export class QuicAckRanges {
|
|
|
42
46
|
largest: i64 = -1
|
|
43
47
|
/** Every packet number at or below this is answered as already received; -1 until a range is dropped. */
|
|
44
48
|
floor: i64 = -1
|
|
45
|
-
ranges: i64[]
|
|
49
|
+
private ranges: i64[]
|
|
50
|
+
/** How many disjoint ranges are held, at most `QUIC_ACK_MAX_RANGES`. */
|
|
46
51
|
count: i32 = 0
|
|
47
52
|
/** Whether an ack-eliciting packet arrived since the last `pushAck`. */
|
|
48
53
|
ackPending: boolean = false
|
|
49
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Makes an empty set, nothing received yet, with room for
|
|
57
|
+
* `QUIC_ACK_MAX_RANGES` ranges.
|
|
58
|
+
*/
|
|
50
59
|
constructor() {
|
|
51
60
|
this.ranges = new Array<i64>(QUIC_ACK_MAX_RANGES * 2)
|
|
52
61
|
}
|
|
53
62
|
|
|
54
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* The smallest packet number of range `k`, which the caller keeps below `count`.
|
|
65
|
+
*
|
|
66
|
+
* @param k The range's index, 0 for the highest range.
|
|
67
|
+
* @returns The range's smallest packet number, or -1 for an index outside the storage.
|
|
68
|
+
*/
|
|
55
69
|
low(k: i32): i64 {
|
|
56
70
|
const at: i32 = k * 2
|
|
57
71
|
if (at < 0 || at >= toI32(this.ranges.length)) {
|
|
@@ -60,7 +74,12 @@ export class QuicAckRanges {
|
|
|
60
74
|
return this.ranges[at]
|
|
61
75
|
}
|
|
62
76
|
|
|
63
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* The largest packet number of range `k`.
|
|
79
|
+
*
|
|
80
|
+
* @param k The range's index, 0 for the highest range; the caller keeps it below `count`.
|
|
81
|
+
* @returns The range's largest packet number, or -1 for an index outside the storage.
|
|
82
|
+
*/
|
|
64
83
|
high(k: i32): i64 {
|
|
65
84
|
const at: i32 = k * 2 + 1
|
|
66
85
|
if (at < 0 || at >= toI32(this.ranges.length)) {
|
|
@@ -69,7 +88,14 @@ export class QuicAckRanges {
|
|
|
69
88
|
return this.ranges[at]
|
|
70
89
|
}
|
|
71
90
|
|
|
72
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Sets range `k` to `[low, high]`. An index outside the storage changes nothing, and `count` is
|
|
93
|
+
* not moved: the caller keeps the ranges ordered and disjoint.
|
|
94
|
+
*
|
|
95
|
+
* @param k The range's index, 0 for the highest range.
|
|
96
|
+
* @param low The range's smallest packet number.
|
|
97
|
+
* @param high The range's largest packet number, at least `low`.
|
|
98
|
+
*/
|
|
73
99
|
set(k: i32, low: i64, high: i64): void {
|
|
74
100
|
const at: i32 = k * 2
|
|
75
101
|
const next: i32 = at + 1
|
|
@@ -80,7 +106,12 @@ export class QuicAckRanges {
|
|
|
80
106
|
this.ranges[next] = high
|
|
81
107
|
}
|
|
82
108
|
|
|
83
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Whether `pn` was received, or is at or below the floor and so cannot be told apart from one that was.
|
|
111
|
+
*
|
|
112
|
+
* @param pn The full (decoded) packet number to look up.
|
|
113
|
+
* @returns True when `pn` must be treated as already processed.
|
|
114
|
+
*/
|
|
84
115
|
contains(pn: i64): boolean {
|
|
85
116
|
if (pn <= this.floor) {
|
|
86
117
|
return true
|
|
@@ -101,6 +132,11 @@ export class QuicAckRanges {
|
|
|
101
132
|
* an acknowledgement. Answers `false`, changing nothing, for a packet number
|
|
102
133
|
* already received (or at or below the floor), or one that is not a packet
|
|
103
134
|
* number at all.
|
|
135
|
+
*
|
|
136
|
+
* @param pn The full (decoded) packet number, which must be in 0..2^62-1 to count.
|
|
137
|
+
* @param ackEliciting Whether the packet held a frame other than ACK, PADDING or
|
|
138
|
+
* CONNECTION_CLOSE, so that it sets `ackPending`.
|
|
139
|
+
* @returns True when `pn` was new and is now recorded; false for a duplicate or an out-of-range number.
|
|
104
140
|
*/
|
|
105
141
|
record(pn: i64, ackEliciting: boolean): boolean {
|
|
106
142
|
if (pn < 0 || pn > QUIC_MAX_VARINT || this.contains(pn)) {
|
|
@@ -138,7 +174,7 @@ export class QuicAckRanges {
|
|
|
138
174
|
}
|
|
139
175
|
|
|
140
176
|
/** Removes range `k`, moving the lower ones up. */
|
|
141
|
-
remove(k: i32): void {
|
|
177
|
+
private remove(k: i32): void {
|
|
142
178
|
for (let j: i32 = k; j + 1 < this.count; j += 1) {
|
|
143
179
|
this.set(j, this.low(j + 1), this.high(j + 1))
|
|
144
180
|
}
|
|
@@ -150,7 +186,7 @@ export class QuicAckRanges {
|
|
|
150
186
|
* is taken the lowest range is dropped first and the floor raised over it;
|
|
151
187
|
* if `pn` itself would be that lowest range, it is the one dropped.
|
|
152
188
|
*/
|
|
153
|
-
insert(k: i32, pn: i64): void {
|
|
189
|
+
private insert(k: i32, pn: i64): void {
|
|
154
190
|
if (this.count === QUIC_ACK_MAX_RANGES) {
|
|
155
191
|
if (k === this.count) {
|
|
156
192
|
this.floor = pn
|
|
@@ -170,6 +206,11 @@ export class QuicAckRanges {
|
|
|
170
206
|
* Appends an ACK frame for every range kept, with `ackDelay` (already
|
|
171
207
|
* scaled by this endpoint's ACK delay exponent), and clears `ackPending`.
|
|
172
208
|
* Answers `false`, appending nothing, when nothing has been received.
|
|
209
|
+
*
|
|
210
|
+
* @param out The packet payload being built; the frame is appended to its end.
|
|
211
|
+
* @param ackDelay The ACK Delay field's value: the time since the largest packet arrived, in
|
|
212
|
+
* microseconds divided by 2^ack_delay_exponent.
|
|
213
|
+
* @returns True when the frame was appended; false, leaving `out` and `ackPending` alone, otherwise.
|
|
173
214
|
*/
|
|
174
215
|
pushAck(out: u8[], ackDelay: i64): boolean {
|
|
175
216
|
if (this.count === 0 || !quicPushAck(out, this.ranges, this.count, ackDelay)) {
|
|
@@ -184,6 +225,13 @@ export class QuicAckRanges {
|
|
|
184
225
|
* and clears `ackPending`. Answers the offset past it, or -1, writing
|
|
185
226
|
* nothing and leaving `ackPending` as it was, when nothing has been
|
|
186
227
|
* received or the frame does not fit.
|
|
228
|
+
*
|
|
229
|
+
* @param buf The packet buffer to write into.
|
|
230
|
+
* @param at The byte offset in `buf` where the frame starts.
|
|
231
|
+
* @param end The byte offset the frame must end at or before.
|
|
232
|
+
* @param ackDelay The ACK Delay field's value: the time since the largest packet arrived, in
|
|
233
|
+
* microseconds divided by 2^ack_delay_exponent.
|
|
234
|
+
* @returns The byte offset one past the frame, or -1 when nothing was written.
|
|
187
235
|
*/
|
|
188
236
|
putAck(buf: u8[], at: i32, end: i32, ackDelay: i64): i32 {
|
|
189
237
|
if (this.count === 0) {
|