@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/quic-frame.ts
CHANGED
|
@@ -14,18 +14,21 @@
|
|
|
14
14
|
* at = frame.end;
|
|
15
15
|
* }
|
|
16
16
|
*
|
|
17
|
-
* **Every frame type of RFC 9000 is read
|
|
18
|
-
* DATAGRAM, 0x30 and 0x31, so a type outside those is the one parse
|
|
19
|
-
* well-formed packet cannot produce.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
17
|
+
* **Coverage.** Every frame type of RFC 9000 is read, 0x00 to 0x1e, and RFC
|
|
18
|
+
* 9221's DATAGRAM, 0x30 and 0x31, so a type outside those is the one parse
|
|
19
|
+
* error a well-formed packet cannot produce.
|
|
20
|
+
*
|
|
21
|
+
* What a frame *means* is `nish/net/quic`'s: this module checks only what §19
|
|
22
|
+
* says of the encoding itself, and answers the transport error the RFC names
|
|
23
|
+
* for each break — `QUIC_ERROR_FRAME_ENCODING` for a truncated field, a length
|
|
24
|
+
* past the packet, an ACK range below packet number zero, an offset past 2^62 −
|
|
25
|
+
* 1, a stream count past 2^60, an empty NEW_TOKEN, a connection ID outside 1 to
|
|
26
|
+
* 20 bytes or a Retire Prior To above its own sequence number;
|
|
27
|
+
* `QUIC_ERROR_PROTOCOL_VIOLATION` for a frame type spelled in more bytes than
|
|
28
|
+
* it needs (§12.4).
|
|
29
|
+
*
|
|
30
|
+
* Every read is bounds-checked against the window the caller gives, so nothing
|
|
31
|
+
* a peer sends can make this module panic.
|
|
29
32
|
*
|
|
30
33
|
* **No copy of the bulk.** A CRYPTO, STREAM or DATAGRAM frame's data, a
|
|
31
34
|
* NEW_TOKEN's token, a PATH_CHALLENGE's eight bytes and a CONNECTION_CLOSE's
|
|
@@ -36,7 +39,7 @@
|
|
|
36
39
|
* every field it reads and resets the rest, and stores nothing but numbers,
|
|
37
40
|
* so a payload made inside an arena block can be read inside it.
|
|
38
41
|
*
|
|
39
|
-
* **
|
|
42
|
+
* **Writers.** They come in two forms. A `put` writer writes one frame into a
|
|
40
43
|
* caller's buffer at an offset, before an end, and answers the offset past
|
|
41
44
|
* it, or -1 with nothing written; a `push` writer appends one to an array
|
|
42
45
|
* and answers whether it could, by growing the array and calling the `put`
|
|
@@ -67,15 +70,21 @@ import {
|
|
|
67
70
|
|
|
68
71
|
// ---- Frame types (RFC 9000 §19, Table 3 of §12.4) ------------------------------
|
|
69
72
|
|
|
73
|
+
/** PADDING (§19.1): a single zero byte that means nothing, used to make a packet bigger. */
|
|
70
74
|
export const QUIC_FRAME_PADDING: i32 = 0x00
|
|
75
|
+
/** PING (§19.2): the type alone, sent to get an acknowledgement or to keep a connection alive. */
|
|
71
76
|
export const QUIC_FRAME_PING: i32 = 0x01
|
|
72
77
|
/** ACK without ECN counts. */
|
|
73
78
|
export const QUIC_FRAME_ACK: i32 = 0x02
|
|
74
79
|
/** ACK with the three ECN counts after the ranges. */
|
|
75
80
|
export const QUIC_FRAME_ACK_ECN: i32 = 0x03
|
|
81
|
+
/** RESET_STREAM (§19.4): the sender abandons a stream, with an error code and the final size. */
|
|
76
82
|
export const QUIC_FRAME_RESET_STREAM: i32 = 0x04
|
|
83
|
+
/** STOP_SENDING (§19.5): asks the peer to stop sending on a stream, with an error code. */
|
|
77
84
|
export const QUIC_FRAME_STOP_SENDING: i32 = 0x05
|
|
85
|
+
/** CRYPTO (§19.6): TLS handshake bytes at an offset in one packet number space's crypto stream. */
|
|
78
86
|
export const QUIC_FRAME_CRYPTO: i32 = 0x06
|
|
87
|
+
/** NEW_TOKEN (§19.7): a server's token for the client to present in a later connection's Initial. */
|
|
79
88
|
export const QUIC_FRAME_NEW_TOKEN: i32 = 0x07
|
|
80
89
|
/**
|
|
81
90
|
* The first of the eight STREAM types, 0x08 to 0x0f. `quicParseFrame` answers
|
|
@@ -83,22 +92,35 @@ export const QUIC_FRAME_NEW_TOKEN: i32 = 0x07
|
|
|
83
92
|
* `offset`, `dataLength` and `fin` (§19.8).
|
|
84
93
|
*/
|
|
85
94
|
export const QUIC_FRAME_STREAM: i32 = 0x08
|
|
95
|
+
/** MAX_DATA (§19.9): the connection's flow-control limit, in bytes across every stream. */
|
|
86
96
|
export const QUIC_FRAME_MAX_DATA: i32 = 0x10
|
|
97
|
+
/** MAX_STREAM_DATA (§19.10): one stream's flow-control limit, in bytes. */
|
|
87
98
|
export const QUIC_FRAME_MAX_STREAM_DATA: i32 = 0x11
|
|
99
|
+
/** MAX_STREAMS (§19.11) for bidirectional streams: how many the peer may open in all. */
|
|
88
100
|
export const QUIC_FRAME_MAX_STREAMS_BIDI: i32 = 0x12
|
|
101
|
+
/** MAX_STREAMS (§19.11) for unidirectional streams: how many the peer may open in all. */
|
|
89
102
|
export const QUIC_FRAME_MAX_STREAMS_UNI: i32 = 0x13
|
|
103
|
+
/** DATA_BLOCKED (§19.12): the sender has data to send but the connection limit holds it back. */
|
|
90
104
|
export const QUIC_FRAME_DATA_BLOCKED: i32 = 0x14
|
|
105
|
+
/** STREAM_DATA_BLOCKED (§19.13): the sender is held back by one stream's limit. */
|
|
91
106
|
export const QUIC_FRAME_STREAM_DATA_BLOCKED: i32 = 0x15
|
|
107
|
+
/** STREAMS_BLOCKED (§19.14) for bidirectional streams: the sender wants to open more than it may. */
|
|
92
108
|
export const QUIC_FRAME_STREAMS_BLOCKED_BIDI: i32 = 0x16
|
|
109
|
+
/** STREAMS_BLOCKED (§19.14) for unidirectional streams: the sender wants to open more than it may. */
|
|
93
110
|
export const QUIC_FRAME_STREAMS_BLOCKED_UNI: i32 = 0x17
|
|
111
|
+
/** NEW_CONNECTION_ID (§19.15): another connection ID the peer may use, with its reset token. */
|
|
94
112
|
export const QUIC_FRAME_NEW_CONNECTION_ID: i32 = 0x18
|
|
113
|
+
/** RETIRE_CONNECTION_ID (§19.16): the sender stops using the peer's connection ID of a sequence number. */
|
|
95
114
|
export const QUIC_FRAME_RETIRE_CONNECTION_ID: i32 = 0x19
|
|
115
|
+
/** PATH_CHALLENGE (§19.17): eight bytes the peer must echo in a PATH_RESPONSE to validate a path. */
|
|
96
116
|
export const QUIC_FRAME_PATH_CHALLENGE: i32 = 0x1a
|
|
117
|
+
/** PATH_RESPONSE (§19.18): the eight bytes of a PATH_CHALLENGE, echoed back. */
|
|
97
118
|
export const QUIC_FRAME_PATH_RESPONSE: i32 = 0x1b
|
|
98
119
|
/** CONNECTION_CLOSE with a transport error code and the frame type that caused it. */
|
|
99
120
|
export const QUIC_FRAME_CONNECTION_CLOSE: i32 = 0x1c
|
|
100
121
|
/** CONNECTION_CLOSE with an application error code, allowed only in 1-RTT packets. */
|
|
101
122
|
export const QUIC_FRAME_CONNECTION_CLOSE_APP: i32 = 0x1d
|
|
123
|
+
/** HANDSHAKE_DONE (§19.20): the server confirms the handshake; only a server sends it. */
|
|
102
124
|
export const QUIC_FRAME_HANDSHAKE_DONE: i32 = 0x1e
|
|
103
125
|
/**
|
|
104
126
|
* DATAGRAM (RFC 9221 §4): an unreliable application payload. Type 0x30 runs
|
|
@@ -111,22 +133,39 @@ export const QUIC_FRAME_DATAGRAM_LENGTH: i32 = 0x31
|
|
|
111
133
|
|
|
112
134
|
// ---- Transport error codes (RFC 9000 §20.1) ------------------------------------
|
|
113
135
|
|
|
136
|
+
/** NO_ERROR: the connection closes without an error; also `quicParseFrame`'s answer for a good frame. */
|
|
114
137
|
export const QUIC_ERROR_NO_ERROR: i64 = 0x00
|
|
138
|
+
/** INTERNAL_ERROR: the endpoint broke on its own, not because of anything the peer sent. */
|
|
115
139
|
export const QUIC_ERROR_INTERNAL: i64 = 0x01
|
|
140
|
+
/** CONNECTION_REFUSED: the server will not accept the connection. */
|
|
116
141
|
export const QUIC_ERROR_CONNECTION_REFUSED: i64 = 0x02
|
|
142
|
+
/** FLOW_CONTROL_ERROR: the peer sent more data than the advertised limits allow. */
|
|
117
143
|
export const QUIC_ERROR_FLOW_CONTROL: i64 = 0x03
|
|
144
|
+
/** STREAM_LIMIT_ERROR: the peer opened a stream past the limit it was given. */
|
|
118
145
|
export const QUIC_ERROR_STREAM_LIMIT: i64 = 0x04
|
|
146
|
+
/** STREAM_STATE_ERROR: a frame arrived for a stream not in a state that permits it. */
|
|
119
147
|
export const QUIC_ERROR_STREAM_STATE: i64 = 0x05
|
|
148
|
+
/** FINAL_SIZE_ERROR: a stream's final size changed, or data arrived past it. */
|
|
120
149
|
export const QUIC_ERROR_FINAL_SIZE: i64 = 0x06
|
|
150
|
+
/** FRAME_ENCODING_ERROR: a frame is badly formed, such as truncated or with a length past the packet. */
|
|
121
151
|
export const QUIC_ERROR_FRAME_ENCODING: i64 = 0x07
|
|
152
|
+
/** TRANSPORT_PARAMETER_ERROR: the peer's transport parameters are malformed or invalid. */
|
|
122
153
|
export const QUIC_ERROR_TRANSPORT_PARAMETER: i64 = 0x08
|
|
154
|
+
/** CONNECTION_ID_LIMIT_ERROR: the peer gave more connection IDs than `active_connection_id_limit`. */
|
|
123
155
|
export const QUIC_ERROR_CONNECTION_ID_LIMIT: i64 = 0x09
|
|
156
|
+
/** PROTOCOL_VIOLATION: the peer broke the protocol in a way no more specific code names. */
|
|
124
157
|
export const QUIC_ERROR_PROTOCOL_VIOLATION: i64 = 0x0a
|
|
158
|
+
/** INVALID_TOKEN: a server received a client Initial whose Token field it cannot accept, from a Retry or NEW_TOKEN. */
|
|
125
159
|
export const QUIC_ERROR_INVALID_TOKEN: i64 = 0x0b
|
|
160
|
+
/** APPLICATION_ERROR: the application closed, reported in a transport close where 0x1d may not be sent. */
|
|
126
161
|
export const QUIC_ERROR_APPLICATION: i64 = 0x0c
|
|
162
|
+
/** CRYPTO_BUFFER_EXCEEDED: the peer sent more CRYPTO data than the endpoint buffers. */
|
|
127
163
|
export const QUIC_ERROR_CRYPTO_BUFFER_EXCEEDED: i64 = 0x0d
|
|
164
|
+
/** KEY_UPDATE_ERROR: the peer made a mistake in a key update (RFC 9001 §6). */
|
|
128
165
|
export const QUIC_ERROR_KEY_UPDATE: i64 = 0x0e
|
|
166
|
+
/** AEAD_LIMIT_REACHED: the keys reached their confidentiality or integrity limit (RFC 9001 §6.6). */
|
|
129
167
|
export const QUIC_ERROR_AEAD_LIMIT_REACHED: i64 = 0x0f
|
|
168
|
+
/** NO_VIABLE_PATH: no network path is fit for QUIC, such as one whose MTU is too small. */
|
|
130
169
|
export const QUIC_ERROR_NO_VIABLE_PATH: i64 = 0x10
|
|
131
170
|
/** CRYPTO_ERROR is this plus the TLS alert description (RFC 9001 §4.8): 0x0100 to 0x01ff. */
|
|
132
171
|
export const QUIC_ERROR_CRYPTO: i64 = 0x0100
|
|
@@ -172,31 +211,68 @@ export const QUIC_PATH_DATA_SIZE: i32 = 8
|
|
|
172
211
|
* phrase as the data.
|
|
173
212
|
*/
|
|
174
213
|
export class QuicFrame {
|
|
214
|
+
/** The stream a STREAM, RESET_STREAM, STOP_SENDING, MAX_STREAM_DATA or STREAM_DATA_BLOCKED frame names. */
|
|
175
215
|
streamId: i64 = 0
|
|
216
|
+
/** The byte offset in the stream (STREAM) or the handshake stream (CRYPTO) where the data starts. */
|
|
176
217
|
offset: i64 = 0
|
|
218
|
+
/** The frame's one number: a limit, a final size or a sequence number, as the list above gives per type. */
|
|
177
219
|
value: i64 = 0
|
|
220
|
+
/** The application or transport error code of a RESET_STREAM, STOP_SENDING or CONNECTION_CLOSE. */
|
|
178
221
|
errorCode: i64 = 0
|
|
222
|
+
/** The frame type a transport CONNECTION_CLOSE (0x1c) blames; 0 for the application form. */
|
|
179
223
|
frameType: i64 = 0
|
|
224
|
+
/** A NEW_CONNECTION_ID's Retire Prior To: every peer ID with a lower sequence number is to be retired. */
|
|
180
225
|
retirePriorTo: i64 = 0
|
|
226
|
+
/** The largest packet number an ACK acknowledges. */
|
|
181
227
|
largest: i64 = 0
|
|
228
|
+
/** An ACK's delay as sent, not yet scaled by the peer's `ack_delay_exponent`. */
|
|
182
229
|
ackDelay: i64 = 0
|
|
230
|
+
/**
|
|
231
|
+
* An ACK's ranges as `[smallest, largest]` packet-number pairs, highest
|
|
232
|
+
* first. Only the first `ackRangeCount` pairs are meaningful; the array
|
|
233
|
+
* keeps its `QUIC_FRAME_MAX_ACK_RANGES * 2` length.
|
|
234
|
+
*/
|
|
183
235
|
ackRanges: i64[]
|
|
236
|
+
/**
|
|
237
|
+
* How many ranges the ACK carried, which can exceed `ackRangeCount` when ranges past the stored cap
|
|
238
|
+
* were read and dropped.
|
|
239
|
+
*/
|
|
184
240
|
ackRangeTotal: i64 = 0
|
|
241
|
+
/** An ACK_ECN's cumulative count of packets received marked ECT(0). */
|
|
185
242
|
ect0: i64 = 0
|
|
243
|
+
/** An ACK_ECN's cumulative count of packets received marked ECT(1). */
|
|
186
244
|
ect1: i64 = 0
|
|
245
|
+
/** An ACK_ECN's cumulative count of packets received marked ECN-CE (congestion experienced). */
|
|
187
246
|
ce: i64 = 0
|
|
188
247
|
/** The frame type, with every STREAM type answered as `QUIC_FRAME_STREAM`. */
|
|
189
248
|
type: i32 = 0
|
|
190
249
|
/** One past the frame's last byte, where the next frame starts. */
|
|
191
250
|
end: i32 = 0
|
|
251
|
+
/**
|
|
252
|
+
* Where the frame's data (stream or CRYPTO bytes, token, path data, datagram or reason phrase)
|
|
253
|
+
* starts in the payload.
|
|
254
|
+
*/
|
|
192
255
|
dataStart: i32 = 0
|
|
256
|
+
/** How many bytes of data start at `dataStart`. */
|
|
193
257
|
dataLength: i32 = 0
|
|
258
|
+
/**
|
|
259
|
+
* How many `[smallest, largest]` pairs of `ackRanges` hold an ACK range, at most
|
|
260
|
+
* `QUIC_FRAME_MAX_ACK_RANGES`.
|
|
261
|
+
*/
|
|
194
262
|
ackRangeCount: i32 = 0
|
|
263
|
+
/** Where a NEW_CONNECTION_ID's connection ID starts in the payload. */
|
|
195
264
|
connectionIdStart: i32 = 0
|
|
265
|
+
/** A NEW_CONNECTION_ID's connection ID length in bytes, 1 to 20. */
|
|
196
266
|
connectionIdLength: i32 = 0
|
|
267
|
+
/** Where a NEW_CONNECTION_ID's 16-byte stateless reset token starts in the payload. */
|
|
197
268
|
resetTokenStart: i32 = 0
|
|
269
|
+
/** A STREAM frame's FIN bit (the stream ends with this data), or a DATAGRAM that carried a Length. */
|
|
198
270
|
fin: boolean = false
|
|
199
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Makes an empty frame with room for `QUIC_FRAME_MAX_ACK_RANGES` ACK
|
|
274
|
+
* ranges, for `quicParseFrame` to fill.
|
|
275
|
+
*/
|
|
200
276
|
constructor() {
|
|
201
277
|
// Sized once, so reading an ACK stores nothing new into the frame.
|
|
202
278
|
this.ackRanges = new Array<i64>(QUIC_FRAME_MAX_ACK_RANGES * 2)
|
|
@@ -212,8 +288,11 @@ export class QuicFrame {
|
|
|
212
288
|
* read inside it.
|
|
213
289
|
*/
|
|
214
290
|
class QuicFrameReader {
|
|
291
|
+
/** @internal Read in quic-frame.ts outside the class. */
|
|
215
292
|
at: i32
|
|
293
|
+
/** @internal Read in quic-frame.ts outside the class. */
|
|
216
294
|
end: i32
|
|
295
|
+
/** @internal Read in quic-frame.ts outside the class. */
|
|
217
296
|
failed: boolean = false
|
|
218
297
|
|
|
219
298
|
constructor(at: i32, end: i32) {
|
|
@@ -496,6 +575,15 @@ const quicFrameReadBody = (r: QuicFrameReader, d: u8[], frame: QuicFrame, type:
|
|
|
496
575
|
* further, and `frame.type` still holds the type when it was read, which is
|
|
497
576
|
* what CONNECTION_CLOSE reports. A window outside `payload` is
|
|
498
577
|
* `QUIC_ERROR_INTERNAL`, the caller's fault rather than the peer's.
|
|
578
|
+
*
|
|
579
|
+
* @param frame The frame to fill, reused across frames and packets; its windows (`dataStart` and the
|
|
580
|
+
* like) are offsets into `payload`, so they mean something only while `payload` is unchanged.
|
|
581
|
+
* @param payload The decrypted packet payload, as the peer sent it; only read, never kept.
|
|
582
|
+
* @param at The offset of the frame's first byte, its type.
|
|
583
|
+
* @param end One past the last byte the frame may use, normally the payload's end; a frame reaching past
|
|
584
|
+
* it is `QUIC_ERROR_FRAME_ENCODING`.
|
|
585
|
+
* @returns `QUIC_ERROR_NO_ERROR` (0) for a good frame, otherwise the `QUIC_ERROR_*` code to close the
|
|
586
|
+
* connection with.
|
|
499
587
|
*/
|
|
500
588
|
export const quicParseFrame = (frame: QuicFrame, payload: u8[], at: i32, end: i32): i64 => {
|
|
501
589
|
quicFrameReset(frame, at)
|
|
@@ -538,6 +626,13 @@ export const quicParseFrame = (frame: QuicFrame, payload: u8[], at: i32, end: i3
|
|
|
538
626
|
* ACK, CRYPTO and the transport CONNECTION_CLOSE; a 0-RTT packet anything
|
|
539
627
|
* but ACK, CRYPTO, NEW_TOKEN, HANDSHAKE_DONE and the retire and response
|
|
540
628
|
* frames a client cannot have a reason to send yet; a 1-RTT packet anything.
|
|
629
|
+
*
|
|
630
|
+
* @param type The frame type as `quicParseFrame` answers it in `QuicFrame.type`, every STREAM type as
|
|
631
|
+
* `QUIC_FRAME_STREAM`.
|
|
632
|
+
* @param packetType The packet's `QUIC_PACKET_*` type from `nish/net/quic-packet`, `QUIC_PACKET_SHORT`
|
|
633
|
+
* for 1-RTT.
|
|
634
|
+
* @returns True when §12.4 permits the frame there; false when it does not permit that frame in that
|
|
635
|
+
* packet type, and for a packet type that carries no frames, such as Retry.
|
|
541
636
|
*/
|
|
542
637
|
export const quicFrameAllowed = (type: i32, packetType: i32): boolean => {
|
|
543
638
|
if (packetType === QUIC_PACKET_SHORT) {
|
|
@@ -570,6 +665,10 @@ export const quicFrameAllowed = (type: i32, packetType: i32): boolean => {
|
|
|
570
665
|
/**
|
|
571
666
|
* Whether a frame of `type` asks for an acknowledgement (RFC 9000 §13.2):
|
|
572
667
|
* every frame but ACK, PADDING and CONNECTION_CLOSE.
|
|
668
|
+
*
|
|
669
|
+
* @param type The frame type as `quicParseFrame` answers it.
|
|
670
|
+
* @returns True when a packet holding this frame is ack-eliciting, which is what decides whether the
|
|
671
|
+
* peer must acknowledge it promptly.
|
|
573
672
|
*/
|
|
574
673
|
export const quicFrameAckEliciting = (type: i32): boolean =>
|
|
575
674
|
!(
|
|
@@ -621,7 +720,12 @@ const quicFrameGrow = (out: u8[], size: i32): i32 => {
|
|
|
621
720
|
const quicFrameVarints3 = (a: i64, b: i64, c: i64): boolean =>
|
|
622
721
|
quicVarintSize(a) !== 0 && quicVarintSize(b) !== 0 && quicVarintSize(c) !== 0
|
|
623
722
|
|
|
624
|
-
/**
|
|
723
|
+
/**
|
|
724
|
+
* Appends `count` PADDING frames, which are `count` zero bytes. A count below one appends nothing.
|
|
725
|
+
*
|
|
726
|
+
* @param out The bytes to grow, such as a packet payload being built.
|
|
727
|
+
* @param count How many bytes of padding to append.
|
|
728
|
+
*/
|
|
625
729
|
export const quicPushPadding = (out: u8[], count: i32): void => {
|
|
626
730
|
quicPacketGrow(out, count)
|
|
627
731
|
}
|
|
@@ -629,6 +733,12 @@ export const quicPushPadding = (out: u8[], count: i32): void => {
|
|
|
629
733
|
/**
|
|
630
734
|
* Writes `count` PADDING frames, zero bytes, into `buf[at .. at + count)`,
|
|
631
735
|
* clamped to `buf`, and answers the offset past them.
|
|
736
|
+
*
|
|
737
|
+
* @param buf The buffer to write into.
|
|
738
|
+
* @param at The offset of the first zero byte.
|
|
739
|
+
* @param count How many zero bytes to write; fewer are written where `buf` ends first.
|
|
740
|
+
* @returns The offset past the last byte written, which is short of `at + count` when `buf` was too small and
|
|
741
|
+
* `at` itself when nothing could be written.
|
|
632
742
|
*/
|
|
633
743
|
export const quicPutPadding = (buf: u8[], at: i32, count: i32): i32 => {
|
|
634
744
|
let k: i32 = 0
|
|
@@ -639,7 +749,15 @@ export const quicPutPadding = (buf: u8[], at: i32, count: i32): i32 => {
|
|
|
639
749
|
return at + k
|
|
640
750
|
}
|
|
641
751
|
|
|
642
|
-
/**
|
|
752
|
+
/**
|
|
753
|
+
* Writes a frame that is its type alone, PING or HANDSHAKE_DONE; -1 for another type or no room.
|
|
754
|
+
*
|
|
755
|
+
* @param buf The buffer to write into.
|
|
756
|
+
* @param at The offset to write the one byte at.
|
|
757
|
+
* @param end One past the last byte the frame may use, such as the end of the packet's room.
|
|
758
|
+
* @param type `QUIC_FRAME_PING` or `QUIC_FRAME_HANDSHAKE_DONE`.
|
|
759
|
+
* @returns `at + 1`, or -1 with nothing written.
|
|
760
|
+
*/
|
|
643
761
|
export const quicPutTypeOnly = (buf: u8[], at: i32, end: i32, type: i32): i32 => {
|
|
644
762
|
if ((type !== QUIC_FRAME_PING && type !== QUIC_FRAME_HANDSHAKE_DONE) || !quicFrameRoom(buf, at, end, 1)) {
|
|
645
763
|
return -1
|
|
@@ -647,7 +765,13 @@ export const quicPutTypeOnly = (buf: u8[], at: i32, end: i32, type: i32): i32 =>
|
|
|
647
765
|
return quicFramePutByte(buf, at, type)
|
|
648
766
|
}
|
|
649
767
|
|
|
650
|
-
/**
|
|
768
|
+
/**
|
|
769
|
+
* Appends a frame that is its type alone: PING or HANDSHAKE_DONE. Answers `false` for another type.
|
|
770
|
+
*
|
|
771
|
+
* @param out The bytes to append the frame's one byte to.
|
|
772
|
+
* @param type `QUIC_FRAME_PING` or `QUIC_FRAME_HANDSHAKE_DONE`.
|
|
773
|
+
* @returns True when the frame was appended; false, appending nothing, for any other type.
|
|
774
|
+
*/
|
|
651
775
|
export const quicPushTypeOnly = (out: u8[], type: i32): boolean => {
|
|
652
776
|
if (type !== QUIC_FRAME_PING && type !== QUIC_FRAME_HANDSHAKE_DONE) {
|
|
653
777
|
return false
|
|
@@ -660,6 +784,11 @@ export const quicPushTypeOnly = (out: u8[], type: i32): boolean => {
|
|
|
660
784
|
* The size of the ACK frame `quicPutAck` writes for these ranges, or 0 when
|
|
661
785
|
* it would refuse them: no ranges, ranges out of order or touching, a pair
|
|
662
786
|
* the array does not hold, or a value no varint holds.
|
|
787
|
+
*
|
|
788
|
+
* @param ranges Packet number pairs laid out flat, `[smallest, largest]` for each range, highest range first.
|
|
789
|
+
* @param rangeCount How many pairs to read from the front of `ranges`; the rest of the array is ignored.
|
|
790
|
+
* @param ackDelay The ACK Delay field, already scaled by this endpoint's `ack_delay_exponent`.
|
|
791
|
+
* @returns The frame's size in bytes, or 0 when `quicPutAck` would refuse these arguments.
|
|
663
792
|
*/
|
|
664
793
|
export const quicAckSize = (ranges: i64[], rangeCount: i32, ackDelay: i64): i32 => {
|
|
665
794
|
if (rangeCount < 1 || rangeCount * 2 > toI32(ranges.length) || quicVarintSize(ackDelay) === 0) {
|
|
@@ -700,6 +829,15 @@ export const quicAckSize = (ranges: i64[], rangeCount: i32, ackDelay: i64): i32
|
|
|
700
829
|
* largest at least two below the smallest of the pair before it), with
|
|
701
830
|
* `ackDelay` already scaled by this endpoint's exponent. Answers -1, writing
|
|
702
831
|
* nothing, where `quicAckSize` answers 0 or the frame does not fit.
|
|
832
|
+
*
|
|
833
|
+
* @param buf The buffer to write into.
|
|
834
|
+
* @param at The offset of the frame's first byte.
|
|
835
|
+
* @param end One past the last byte the frame may use.
|
|
836
|
+
* @param ranges Packet number pairs laid out flat, `[smallest, largest]` for each range, highest range first.
|
|
837
|
+
* @param rangeCount How many pairs to read from the front of `ranges`.
|
|
838
|
+
* @param ackDelay The ACK Delay field, already scaled: microseconds shifted right by the exponent.
|
|
839
|
+
* @returns The offset past the frame, or -1 with nothing written. The frame is always type 0x02, without ECN
|
|
840
|
+
* counts.
|
|
703
841
|
*/
|
|
704
842
|
export const quicPutAck = (
|
|
705
843
|
buf: u8[],
|
|
@@ -734,7 +872,15 @@ export const quicPutAck = (
|
|
|
734
872
|
return cursor
|
|
735
873
|
}
|
|
736
874
|
|
|
737
|
-
/**
|
|
875
|
+
/**
|
|
876
|
+
* Appends the ACK frame `quicPutAck` writes. Answers `false`, appending nothing, where it refuses.
|
|
877
|
+
*
|
|
878
|
+
* @param out The bytes to append the frame to.
|
|
879
|
+
* @param ranges Packet number pairs laid out flat, `[smallest, largest]` for each range, highest range first.
|
|
880
|
+
* @param rangeCount How many pairs to read from the front of `ranges`.
|
|
881
|
+
* @param ackDelay The ACK Delay field, already scaled by this endpoint's `ack_delay_exponent`.
|
|
882
|
+
* @returns True when the frame was appended.
|
|
883
|
+
*/
|
|
738
884
|
export const quicPushAck = (out: u8[], ranges: i64[], rangeCount: i32, ackDelay: i64): boolean => {
|
|
739
885
|
const size: i32 = quicAckSize(ranges, rangeCount, ackDelay)
|
|
740
886
|
if (size === 0) {
|
|
@@ -747,6 +893,11 @@ export const quicPushAck = (out: u8[], ranges: i64[], rangeCount: i32, ackDelay:
|
|
|
747
893
|
/**
|
|
748
894
|
* The bytes a CRYPTO frame's header takes for `length` bytes of data at
|
|
749
895
|
* `offset`: the type, the offset and the length.
|
|
896
|
+
*
|
|
897
|
+
* @param offset The crypto stream offset, in bytes, of the frame's first data byte, up to 2^62 − 1.
|
|
898
|
+
* @param length How many data bytes the frame carries.
|
|
899
|
+
* @returns The header's size in bytes, not counting the data, which is what a sender subtracts from a
|
|
900
|
+
* packet's room to see how much data fits.
|
|
750
901
|
*/
|
|
751
902
|
export const quicCryptoOverhead = (offset: i64, length: i32): i32 =>
|
|
752
903
|
1 + quicVarintSize(offset) + quicVarintSize(toI64(length))
|
|
@@ -755,6 +906,15 @@ export const quicCryptoOverhead = (offset: i64, length: i32): i32 =>
|
|
|
755
906
|
* Writes a CRYPTO frame (§19.6) carrying `data[from .. from + length)` at
|
|
756
907
|
* stream offset `offset`. Answers -1, writing nothing, for a window outside
|
|
757
908
|
* `data`, an offset whose end passes 2^62 − 1, or no room.
|
|
909
|
+
*
|
|
910
|
+
* @param buf The buffer to write into.
|
|
911
|
+
* @param at The offset of the frame's first byte.
|
|
912
|
+
* @param end One past the last byte the frame may use.
|
|
913
|
+
* @param offset The crypto stream offset, in bytes, of the first byte carried.
|
|
914
|
+
* @param data The handshake bytes to take the window from; copied, not kept.
|
|
915
|
+
* @param from The offset in `data` of the first byte to carry.
|
|
916
|
+
* @param length How many bytes to carry.
|
|
917
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
758
918
|
*/
|
|
759
919
|
export const quicPutCrypto = (
|
|
760
920
|
buf: u8[],
|
|
@@ -780,7 +940,16 @@ export const quicPutCrypto = (
|
|
|
780
940
|
return cursor + length
|
|
781
941
|
}
|
|
782
942
|
|
|
783
|
-
/**
|
|
943
|
+
/**
|
|
944
|
+
* Appends the CRYPTO frame `quicPutCrypto` writes. Answers `false`, appending nothing, where it refuses.
|
|
945
|
+
*
|
|
946
|
+
* @param out The bytes to append the frame to.
|
|
947
|
+
* @param offset The crypto stream offset, in bytes, of the first byte carried.
|
|
948
|
+
* @param data The handshake bytes to take the window from; copied, not kept.
|
|
949
|
+
* @param from The offset in `data` of the first byte to carry.
|
|
950
|
+
* @param length How many bytes to carry.
|
|
951
|
+
* @returns True when the frame was appended.
|
|
952
|
+
*/
|
|
784
953
|
export const quicPushCrypto = (out: u8[], offset: i64, data: u8[], from: i32, length: i32): boolean => {
|
|
785
954
|
if (!quicFrameWindowFits(data, from, length) || offset < 0 || offset > QUIC_MAX_VARINT - toI64(length)) {
|
|
786
955
|
return false
|
|
@@ -794,6 +963,11 @@ export const quicPushCrypto = (out: u8[], offset: i64, data: u8[], from: i32, le
|
|
|
794
963
|
* The bytes a STREAM frame's header takes for `length` bytes of data on
|
|
795
964
|
* `streamId` at `offset`: the type, the stream ID, the offset when it is not
|
|
796
965
|
* zero, and the length, which `quicPutStream` always writes.
|
|
966
|
+
*
|
|
967
|
+
* @param streamId The stream the frame is for; meaningful up to 2^62 − 1.
|
|
968
|
+
* @param offset The stream offset, in bytes, of the frame's first data byte.
|
|
969
|
+
* @param length How many data bytes the frame carries.
|
|
970
|
+
* @returns The header's size in bytes, not counting the data.
|
|
797
971
|
*/
|
|
798
972
|
export const quicStreamOverhead = (streamId: i64, offset: i64, length: i32): i32 =>
|
|
799
973
|
1 + quicVarintSize(streamId) + (offset === 0 ? 0 : quicVarintSize(offset)) + quicVarintSize(toI64(length))
|
|
@@ -807,6 +981,17 @@ export const quicStreamOverhead = (streamId: i64, offset: i64, length: i32): i32
|
|
|
807
981
|
* always written, so another frame may follow; the Offset field only when it
|
|
808
982
|
* is not zero. Answers -1, writing nothing, for a `length` past the array, a
|
|
809
983
|
* stream ID that is not a varint, an end past 2^62 − 1, or no room.
|
|
984
|
+
*
|
|
985
|
+
* @param buf The buffer to write into.
|
|
986
|
+
* @param at The offset of the frame's first byte.
|
|
987
|
+
* @param end One past the last byte the frame may use.
|
|
988
|
+
* @param streamId The stream the data belongs to.
|
|
989
|
+
* @param offset The stream offset, in bytes, of the first byte carried.
|
|
990
|
+
* @param data The bytes to carry, read as a ring; copied, not kept.
|
|
991
|
+
* @param from The index in `data` of the first byte to carry, inside the array when `length` is above zero.
|
|
992
|
+
* @param length How many bytes to carry, at most `data.length`; 0 for a frame that only carries FIN.
|
|
993
|
+
* @param fin Whether these bytes end the stream, so that `offset + length` is its final size.
|
|
994
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
810
995
|
*/
|
|
811
996
|
export const quicPutStream = (
|
|
812
997
|
buf: u8[],
|
|
@@ -852,6 +1037,15 @@ export const quicPutStream = (
|
|
|
852
1037
|
* `streamId` at `offset`, with FIN when `fin`, as `quicPutStream` writes it.
|
|
853
1038
|
* Answers `false`, appending nothing, for a window outside `data`, a stream
|
|
854
1039
|
* ID that is not a varint or an end past 2^62 − 1.
|
|
1040
|
+
*
|
|
1041
|
+
* @param out The bytes to append the frame to.
|
|
1042
|
+
* @param streamId The stream the data belongs to.
|
|
1043
|
+
* @param offset The stream offset, in bytes, of the first byte carried.
|
|
1044
|
+
* @param data The bytes to take the window from; copied, not kept, and not read as a ring.
|
|
1045
|
+
* @param from The offset in `data` of the first byte to carry.
|
|
1046
|
+
* @param length How many bytes to carry; 0 for a frame that only carries FIN.
|
|
1047
|
+
* @param fin Whether these bytes end the stream.
|
|
1048
|
+
* @returns True when the frame was appended.
|
|
855
1049
|
*/
|
|
856
1050
|
export const quicPushStream = (
|
|
857
1051
|
out: u8[],
|
|
@@ -896,6 +1090,14 @@ const quicFrameValueFits = (type: i32, value: i64): boolean => {
|
|
|
896
1090
|
* MAX_STREAMS_UNI, DATA_BLOCKED, STREAMS_BLOCKED_BIDI, STREAMS_BLOCKED_UNI or
|
|
897
1091
|
* RETIRE_CONNECTION_ID. Answers -1 for another type, a value no varint holds,
|
|
898
1092
|
* a stream count past 2^60, or no room.
|
|
1093
|
+
*
|
|
1094
|
+
* @param buf The buffer to write into.
|
|
1095
|
+
* @param at The offset of the frame's first byte.
|
|
1096
|
+
* @param end One past the last byte the frame may use.
|
|
1097
|
+
* @param type One of the seven `QUIC_FRAME_*` types above.
|
|
1098
|
+
* @param value What the type carries: a limit in bytes for MAX_DATA and DATA_BLOCKED, a count of streams for
|
|
1099
|
+
* the four stream-count types, a sequence number for RETIRE_CONNECTION_ID.
|
|
1100
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
899
1101
|
*/
|
|
900
1102
|
export const quicPutValue = (buf: u8[], at: i32, end: i32, type: i32, value: i64): i32 => {
|
|
901
1103
|
if (!quicFrameValueFits(type, value) || !quicFrameRoom(buf, at, end, 1 + quicVarintSize(value))) {
|
|
@@ -904,7 +1106,14 @@ export const quicPutValue = (buf: u8[], at: i32, end: i32, type: i32, value: i64
|
|
|
904
1106
|
return quicFramePutVarint(buf, quicFramePutByte(buf, at, type), value)
|
|
905
1107
|
}
|
|
906
1108
|
|
|
907
|
-
/**
|
|
1109
|
+
/**
|
|
1110
|
+
* Appends the frame `quicPutValue` writes. Answers `false`, appending nothing, where it refuses.
|
|
1111
|
+
*
|
|
1112
|
+
* @param out The bytes to append the frame to.
|
|
1113
|
+
* @param type One of the seven types `quicPutValue` writes.
|
|
1114
|
+
* @param value What the type carries: bytes, a count of streams or a sequence number, as for `quicPutValue`.
|
|
1115
|
+
* @returns True when the frame was appended.
|
|
1116
|
+
*/
|
|
908
1117
|
export const quicPushValue = (out: u8[], type: i32, value: i64): boolean => {
|
|
909
1118
|
if (!quicFrameValueFits(type, value)) {
|
|
910
1119
|
return false
|
|
@@ -917,6 +1126,15 @@ export const quicPushValue = (out: u8[], type: i32, value: i64): boolean => {
|
|
|
917
1126
|
/**
|
|
918
1127
|
* Writes a MAX_STREAM_DATA or STREAM_DATA_BLOCKED frame: the stream ID and
|
|
919
1128
|
* the limit. Answers -1 for another type, a value no varint holds, or no room.
|
|
1129
|
+
*
|
|
1130
|
+
* @param buf The buffer to write into.
|
|
1131
|
+
* @param at The offset of the frame's first byte.
|
|
1132
|
+
* @param end One past the last byte the frame may use.
|
|
1133
|
+
* @param type `QUIC_FRAME_MAX_STREAM_DATA` or `QUIC_FRAME_STREAM_DATA_BLOCKED`.
|
|
1134
|
+
* @param streamId The stream the limit is for.
|
|
1135
|
+
* @param value The stream's limit in bytes: the new one for MAX_STREAM_DATA, the one the sender is blocked at
|
|
1136
|
+
* for STREAM_DATA_BLOCKED.
|
|
1137
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
920
1138
|
*/
|
|
921
1139
|
export const quicPutStreamValue = (
|
|
922
1140
|
buf: u8[],
|
|
@@ -938,7 +1156,15 @@ export const quicPutStreamValue = (
|
|
|
938
1156
|
return quicFramePutVarint(buf, cursor, value)
|
|
939
1157
|
}
|
|
940
1158
|
|
|
941
|
-
/**
|
|
1159
|
+
/**
|
|
1160
|
+
* Appends the frame `quicPutStreamValue` writes. Answers `false`, appending nothing, where it refuses.
|
|
1161
|
+
*
|
|
1162
|
+
* @param out The bytes to append the frame to.
|
|
1163
|
+
* @param type `QUIC_FRAME_MAX_STREAM_DATA` or `QUIC_FRAME_STREAM_DATA_BLOCKED`.
|
|
1164
|
+
* @param streamId The stream the limit is for.
|
|
1165
|
+
* @param value The stream's limit in bytes.
|
|
1166
|
+
* @returns True when the frame was appended.
|
|
1167
|
+
*/
|
|
942
1168
|
export const quicPushStreamValue = (out: u8[], type: i32, streamId: i64, value: i64): boolean => {
|
|
943
1169
|
if (
|
|
944
1170
|
(type !== QUIC_FRAME_MAX_STREAM_DATA && type !== QUIC_FRAME_STREAM_DATA_BLOCKED) ||
|
|
@@ -972,6 +1198,16 @@ const quicFrameNewCidSize = (sequence: i64, retirePriorTo: i64, cidLength: i32,
|
|
|
972
1198
|
* of `connectionId`. Answers -1 for a connection ID outside 1 to 20 bytes or
|
|
973
1199
|
* past the array, a reset token that is not 16 bytes, a Retire Prior To
|
|
974
1200
|
* above the sequence number, a value no varint holds, or no room.
|
|
1201
|
+
*
|
|
1202
|
+
* @param buf The buffer to write into.
|
|
1203
|
+
* @param at The offset of the frame's first byte.
|
|
1204
|
+
* @param end One past the last byte the frame may use.
|
|
1205
|
+
* @param sequence The sequence number this endpoint gives the new connection ID.
|
|
1206
|
+
* @param retirePriorTo The peer is to retire every connection ID of a lower sequence number; 0 retires none.
|
|
1207
|
+
* @param connectionId The bytes of the new ID, which may be a longer buffer; copied, not kept.
|
|
1208
|
+
* @param cidLength How many bytes of `connectionId` are the ID, 1 to 20.
|
|
1209
|
+
* @param resetToken The 16-byte stateless reset token tied to the ID; copied, not kept.
|
|
1210
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
975
1211
|
*/
|
|
976
1212
|
export const quicPutNewConnectionId = (
|
|
977
1213
|
buf: u8[],
|
|
@@ -1000,6 +1236,13 @@ export const quicPutNewConnectionId = (
|
|
|
1000
1236
|
* Appends a NEW_CONNECTION_ID frame (§19.15). Answers `false` for a
|
|
1001
1237
|
* connection ID outside 1 to 20 bytes, a reset token that is not 16 bytes, a
|
|
1002
1238
|
* Retire Prior To above the sequence number, or a value no varint holds.
|
|
1239
|
+
*
|
|
1240
|
+
* @param out The bytes to append the frame to.
|
|
1241
|
+
* @param sequence The sequence number this endpoint gives the new connection ID.
|
|
1242
|
+
* @param retirePriorTo The peer is to retire every connection ID of a lower sequence number; 0 retires none.
|
|
1243
|
+
* @param connectionId The new ID, the whole array; copied, not kept.
|
|
1244
|
+
* @param resetToken The 16-byte stateless reset token tied to the ID; copied, not kept.
|
|
1245
|
+
* @returns True when the frame was appended; false, appending nothing, otherwise.
|
|
1003
1246
|
*/
|
|
1004
1247
|
export const quicPushNewConnectionId = (
|
|
1005
1248
|
out: u8[],
|
|
@@ -1032,6 +1275,14 @@ export const quicPushNewConnectionId = (
|
|
|
1032
1275
|
* Writes a PATH_CHALLENGE or PATH_RESPONSE frame carrying the eight bytes
|
|
1033
1276
|
* `data[from .. from + 8)`. Answers -1 for another type, a window outside
|
|
1034
1277
|
* `data`, or no room.
|
|
1278
|
+
*
|
|
1279
|
+
* @param buf The buffer to write into.
|
|
1280
|
+
* @param at The offset of the frame's first byte.
|
|
1281
|
+
* @param end One past the last byte the frame may use.
|
|
1282
|
+
* @param type `QUIC_FRAME_PATH_CHALLENGE` or `QUIC_FRAME_PATH_RESPONSE`.
|
|
1283
|
+
* @param data Holds the eight bytes: fresh random ones for a challenge, the challenge's own for a response.
|
|
1284
|
+
* @param from The offset in `data` of the first of the eight bytes.
|
|
1285
|
+
* @returns The offset past the frame, nine bytes on, or -1 with nothing written.
|
|
1035
1286
|
*/
|
|
1036
1287
|
export const quicPutPathData = (buf: u8[], at: i32, end: i32, type: i32, data: u8[], from: i32): i32 => {
|
|
1037
1288
|
if (
|
|
@@ -1046,7 +1297,15 @@ export const quicPutPathData = (buf: u8[], at: i32, end: i32, type: i32, data: u
|
|
|
1046
1297
|
return cursor + QUIC_PATH_DATA_SIZE
|
|
1047
1298
|
}
|
|
1048
1299
|
|
|
1049
|
-
/**
|
|
1300
|
+
/**
|
|
1301
|
+
* Appends the frame `quicPutPathData` writes. Answers `false`, appending nothing, where it refuses.
|
|
1302
|
+
*
|
|
1303
|
+
* @param out The bytes to append the frame to.
|
|
1304
|
+
* @param type `QUIC_FRAME_PATH_CHALLENGE` or `QUIC_FRAME_PATH_RESPONSE`.
|
|
1305
|
+
* @param data Holds the eight bytes to carry.
|
|
1306
|
+
* @param from The offset in `data` of the first of the eight bytes.
|
|
1307
|
+
* @returns True when the frame was appended.
|
|
1308
|
+
*/
|
|
1050
1309
|
export const quicPushPathData = (out: u8[], type: i32, data: u8[], from: i32): boolean => {
|
|
1051
1310
|
if (
|
|
1052
1311
|
(type !== QUIC_FRAME_PATH_CHALLENGE && type !== QUIC_FRAME_PATH_RESPONSE) ||
|
|
@@ -1061,6 +1320,15 @@ export const quicPushPathData = (out: u8[], type: i32, data: u8[], from: i32): b
|
|
|
1061
1320
|
/**
|
|
1062
1321
|
* Writes a RESET_STREAM frame (§19.4) or, with `finalSize` at -1, a
|
|
1063
1322
|
* STOP_SENDING frame (§19.5). Answers -1 for a value no varint holds, or no room.
|
|
1323
|
+
*
|
|
1324
|
+
* @param buf The buffer to write into.
|
|
1325
|
+
* @param at The offset of the frame's first byte.
|
|
1326
|
+
* @param end One past the last byte the frame may use.
|
|
1327
|
+
* @param streamId The stream being reset or asked to stop.
|
|
1328
|
+
* @param errorCode The application's error code for why.
|
|
1329
|
+
* @param finalSize For RESET_STREAM, the stream's final size: how many bytes of it were ever sent.
|
|
1330
|
+
* -1 asks for STOP_SENDING instead.
|
|
1331
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
1064
1332
|
*/
|
|
1065
1333
|
export const quicPutStreamError = (
|
|
1066
1334
|
buf: u8[],
|
|
@@ -1088,7 +1356,15 @@ export const quicPutStreamError = (
|
|
|
1088
1356
|
return cursor
|
|
1089
1357
|
}
|
|
1090
1358
|
|
|
1091
|
-
/**
|
|
1359
|
+
/**
|
|
1360
|
+
* Appends the frame `quicPutStreamError` writes. Answers `false`, appending nothing, where it refuses.
|
|
1361
|
+
*
|
|
1362
|
+
* @param out The bytes to append the frame to.
|
|
1363
|
+
* @param streamId The stream being reset or asked to stop.
|
|
1364
|
+
* @param errorCode The application's error code for why.
|
|
1365
|
+
* @param finalSize The stream's final size in bytes for RESET_STREAM, or -1 for STOP_SENDING.
|
|
1366
|
+
* @returns True when the frame was appended.
|
|
1367
|
+
*/
|
|
1092
1368
|
export const quicPushStreamError = (out: u8[], streamId: i64, errorCode: i64, finalSize: i64): boolean => {
|
|
1093
1369
|
const reset: boolean = finalSize !== -1
|
|
1094
1370
|
if (!quicFrameVarints3(streamId, errorCode, reset ? finalSize : 0)) {
|
|
@@ -1120,6 +1396,15 @@ const quicFrameCloseSize = (application: boolean, errorCode: i64, frameType: i64
|
|
|
1120
1396
|
* caused the error (0 when none did); with `application` true the 0x1d form,
|
|
1121
1397
|
* which has no frame type. `reason` is the phrase, UTF-8, possibly empty.
|
|
1122
1398
|
* Answers -1 for a value no varint holds, or no room.
|
|
1399
|
+
*
|
|
1400
|
+
* @param buf The buffer to write into.
|
|
1401
|
+
* @param at The offset of the frame's first byte.
|
|
1402
|
+
* @param end One past the last byte the frame may use.
|
|
1403
|
+
* @param application Whether the close is the application's (0x1d) rather than the transport's (0x1c).
|
|
1404
|
+
* @param errorCode A `QUIC_ERROR_*` code for a transport close, the application's own code otherwise.
|
|
1405
|
+
* @param frameType The frame type that caused a transport error, 0 when none did; ignored when `application`.
|
|
1406
|
+
* @param reason The whole array is the reason phrase; copied, not kept.
|
|
1407
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
1123
1408
|
*/
|
|
1124
1409
|
export const quicPutConnectionClose = (
|
|
1125
1410
|
buf: u8[],
|
|
@@ -1149,7 +1434,17 @@ export const quicPutConnectionClose = (
|
|
|
1149
1434
|
return cursor + reasonLength
|
|
1150
1435
|
}
|
|
1151
1436
|
|
|
1152
|
-
/**
|
|
1437
|
+
/**
|
|
1438
|
+
* Appends the frame `quicPutConnectionClose` writes. Answers `false`, appending nothing, where it
|
|
1439
|
+
* refuses.
|
|
1440
|
+
*
|
|
1441
|
+
* @param out The bytes to append the frame to.
|
|
1442
|
+
* @param application Whether the close is the application's (0x1d) rather than the transport's (0x1c).
|
|
1443
|
+
* @param errorCode A `QUIC_ERROR_*` code for a transport close, the application's own code otherwise.
|
|
1444
|
+
* @param frameType The frame type that caused a transport error, 0 when none did; ignored when `application`.
|
|
1445
|
+
* @param reason The whole array is the reason phrase, UTF-8, possibly empty; copied, not kept.
|
|
1446
|
+
* @returns True when the frame was appended.
|
|
1447
|
+
*/
|
|
1153
1448
|
export const quicPushConnectionClose = (
|
|
1154
1449
|
out: u8[],
|
|
1155
1450
|
application: boolean,
|
|
@@ -1168,6 +1463,10 @@ export const quicPushConnectionClose = (
|
|
|
1168
1463
|
/**
|
|
1169
1464
|
* Appends a NEW_TOKEN frame (§19.7) carrying `token`. Answers `false` for an
|
|
1170
1465
|
* empty token, which §19.7 forbids.
|
|
1466
|
+
*
|
|
1467
|
+
* @param out The bytes to append the frame to.
|
|
1468
|
+
* @param token The whole array is the token the client is to present later; copied, not kept.
|
|
1469
|
+
* @returns True when the frame was appended; false, appending nothing, for an empty token.
|
|
1171
1470
|
*/
|
|
1172
1471
|
export const quicPushNewToken = (out: u8[], token: u8[]): boolean => {
|
|
1173
1472
|
const length: i32 = toI32(token.length)
|
|
@@ -1185,12 +1484,23 @@ export const quicPushNewToken = (out: u8[], token: u8[]): boolean => {
|
|
|
1185
1484
|
* The size of the DATAGRAM frame `quicPutDatagram` writes for a payload of
|
|
1186
1485
|
* `length` bytes: the type, the Length and the payload. This is the size RFC
|
|
1187
1486
|
* 9221 §3 holds to `max_datagram_frame_size`.
|
|
1487
|
+
*
|
|
1488
|
+
* @param length The payload's size in bytes.
|
|
1489
|
+
* @returns The whole frame's size in bytes.
|
|
1188
1490
|
*/
|
|
1189
1491
|
export const quicDatagramSize = (length: i32): i32 => 1 + quicVarintSize(toI64(length)) + length
|
|
1190
1492
|
|
|
1191
1493
|
/**
|
|
1192
1494
|
* Writes a DATAGRAM frame with a Length (type 0x31, RFC 9221 §4) carrying
|
|
1193
1495
|
* `data[from .. from + length)`. Answers -1 for a window outside `data` or no room.
|
|
1496
|
+
*
|
|
1497
|
+
* @param buf The buffer to write into.
|
|
1498
|
+
* @param at The offset of the frame's first byte.
|
|
1499
|
+
* @param end One past the last byte the frame may use.
|
|
1500
|
+
* @param data The payload's bytes; copied, not kept.
|
|
1501
|
+
* @param from The offset in `data` of the payload's first byte.
|
|
1502
|
+
* @param length The payload's size in bytes.
|
|
1503
|
+
* @returns The offset past the frame, or -1 with nothing written.
|
|
1194
1504
|
*/
|
|
1195
1505
|
export const quicPutDatagram = (buf: u8[], at: i32, end: i32, data: u8[], from: i32, length: i32): i32 => {
|
|
1196
1506
|
if (!quicFrameWindowFits(data, from, length) || !quicFrameRoom(buf, at, end, quicDatagramSize(length))) {
|