@amritk/nish-x86_64-linux 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.
- package/INSTALL.md +6 -1
- package/bin/nish +0 -0
- package/docs/AI.md +9 -2
- package/package.json +1 -1
- package/runtime/nish.d.ts +4612 -430
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +108 -13
- package/std/base64.ts +34 -5
- package/std/bytes.ts +256 -40
- 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 +80 -9
- package/std/crypto/base64url.ts +22 -0
- package/std/crypto/bcrypt-batch.ts +88 -21
- package/std/crypto/bcrypt.ts +60 -0
- package/std/crypto/chacha20poly1305.ts +53 -0
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +47 -0
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +235 -31
- package/std/crypto/jwt.ts +192 -63
- package/std/crypto/p256.ts +159 -16
- package/std/crypto/p384.ts +28 -3
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +81 -15
- package/std/crypto/rsa.ts +33 -3
- 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 +152 -14
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +67 -7
- package/std/json-equal.ts +19 -0
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +64 -14
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +100 -29
- package/std/json-typed.ts +713 -66
- package/std/json-value.ts +400 -124
- package/std/json.ts +138 -10
- 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 +151 -61
- package/std/net/handler.ts +278 -80
- package/std/net/hpack.ts +262 -52
- package/std/net/http-compress.ts +125 -15
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +100 -19
- package/std/net/http1-codec.ts +235 -27
- package/std/net/http1-server.ts +343 -85
- package/std/net/http2-frame.ts +272 -35
- package/std/net/http2-tls.ts +135 -34
- package/std/net/http2.ts +247 -106
- package/std/net/http3-frame.ts +154 -17
- package/std/net/http3-server.ts +246 -96
- package/std/net/http3.ts +307 -115
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +723 -103
- package/std/net/prefork.ts +164 -31
- package/std/net/qpack.ts +105 -18
- package/std/net/quic-conn-ack.ts +59 -12
- package/std/net/quic-conn-cid.ts +124 -27
- package/std/net/quic-conn-params.ts +70 -10
- package/std/net/quic-datagram.ts +43 -3
- package/std/net/quic-frame.ts +286 -12
- package/std/net/quic-listener.ts +101 -32
- package/std/net/quic-packet.ts +302 -21
- package/std/net/quic-recovery.ts +228 -44
- package/std/net/quic-stream.ts +353 -91
- package/std/net/quic.ts +489 -171
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +166 -51
- package/std/net/tls/codec.ts +413 -56
- package/std/net/tls/record-client.ts +110 -55
- package/std/net/tls/record-server.ts +159 -59
- package/std/net/tls/record.ts +109 -12
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +159 -40
- package/std/net/tls/verify.ts +49 -3
- package/std/net/tls-tcp.ts +250 -45
- package/std/net/tls.ts +221 -59
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +97 -13
- package/std/net/websocket.ts +122 -12
- package/std/net/webtransport.ts +220 -89
- package/std/pair.ts +10 -2
- package/std/random.ts +34 -9
- package/std/regex.ts +352 -198
- 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 +205 -35
- package/std/sync/shm.ts +194 -16
- package/std/term-io.ts +137 -64
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +66 -25
- package/std/term-rate.ts +128 -57
- package/std/term.ts +332 -121
- package/std/testing.ts +130 -32
- package/std/text.ts +73 -7
- package/std/threads.ts +229 -41
- package/std/yaml-json.ts +94 -82
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +24 -16
- package/std/yaml.ts +764 -384
package/std/net/quic-stream.ts
CHANGED
|
@@ -9,6 +9,19 @@
|
|
|
9
9
|
* connection's stream calls (`openStream`, `streamWrite`, `streamRead`,
|
|
10
10
|
* `nextStreamEvent` and the rest), not directly.
|
|
11
11
|
*
|
|
12
|
+
* const pools = new QuicStreamPools(65536, 111, 64) // 64 connections of 100 + 3 + 8 slots
|
|
13
|
+
* const streams = new QuicStreams(100, 3, 8, 65536, 1048576) // client bidi, client uni, own; bytes
|
|
14
|
+
* streams.share(pools) // before any stream has borrowed
|
|
15
|
+
* streams.setPeerLimits(maxData, bidiLocal, bidiRemote, uni, maxStreamsBidi, maxStreamsUni)
|
|
16
|
+
* streams.prime(packetLength) // per packet, before its frames: fills the reserve
|
|
17
|
+
* const error: i64 = streams.onStream(frame.streamId, frame.offset, payload, frame.dataStart,
|
|
18
|
+
* frame.dataLength, frame.fin) // 0, or the transport error to close with
|
|
19
|
+
* const id: i64 = frame.streamId // the stream the frame was for
|
|
20
|
+
* const got: i32 = streams.read(id, into, 0, 4096) // bytes, 0, QUIC_STREAM_END or an error
|
|
21
|
+
* const taken: i32 = streams.write(id, reply, 0, toI32(reply.length), true)
|
|
22
|
+
* streams.beginPacket()
|
|
23
|
+
* const next: i32 = streams.putNextChunk(out, at, end) // `at` when no frame fits
|
|
24
|
+
*
|
|
12
25
|
* **IDs** (§2.1). The low bit says who opened a stream (0 the client, 1 the
|
|
13
26
|
* server) and the next one whether it carries data both ways (0) or only
|
|
14
27
|
* from its opener (1). This side is a server: it opens IDs 1 and 3 modulo 4,
|
|
@@ -185,19 +198,41 @@ const QUIC_STREAM_ZERO: i64 = 0
|
|
|
185
198
|
const QUIC_STREAM_ONE: i32 = 1
|
|
186
199
|
const QUIC_STREAM_NO_BYTES: i32 = 0
|
|
187
200
|
|
|
188
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* Whether `id` is a stream this side, the server, opens: its low bit is 1.
|
|
203
|
+
*
|
|
204
|
+
* @param id A stream ID (§2.1).
|
|
205
|
+
* @returns True for a server-opened stream, false for a client-opened one.
|
|
206
|
+
*/
|
|
189
207
|
export const quicStreamIsLocal = (id: i64): boolean => (id & 1) !== 0
|
|
190
208
|
|
|
191
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Whether `id` is a unidirectional stream: its second bit is 1.
|
|
211
|
+
*
|
|
212
|
+
* @param id A stream ID (§2.1).
|
|
213
|
+
* @returns True when only the opener sends on it, false for a bidirectional stream.
|
|
214
|
+
*/
|
|
192
215
|
export const quicStreamIsUni = (id: i64): boolean => (id & 2) !== 0
|
|
193
216
|
|
|
194
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Whether bit `k` of `bits` is set; false outside the array.
|
|
219
|
+
*
|
|
220
|
+
* @param bits A bitmap, bit `k` in byte `k >> 3` at bit `k & 7`.
|
|
221
|
+
* @param k The bit's index, from 0.
|
|
222
|
+
* @returns True when the bit is set; false when it is clear or `k` is outside the array.
|
|
223
|
+
*/
|
|
195
224
|
export const quicStreamBit = (bits: u8[], k: i32): boolean => {
|
|
196
225
|
const at: i32 = k >> 3
|
|
197
226
|
return at >= 0 && at < toI32(bits.length) && (toI32(bits[at]) & (QUIC_STREAM_ONE << (k & 7))) !== 0
|
|
198
227
|
}
|
|
199
228
|
|
|
200
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* Sets or clears bit `k` of `bits`.
|
|
231
|
+
*
|
|
232
|
+
* @param bits A bitmap, bit `k` in byte `k >> 3` at bit `k & 7`; changed in place.
|
|
233
|
+
* @param k The bit's index, from 0. An index outside the array changes nothing.
|
|
234
|
+
* @param on True to set the bit, false to clear it.
|
|
235
|
+
*/
|
|
201
236
|
export const quicStreamSetBit = (bits: u8[], k: i32, on: boolean): void => {
|
|
202
237
|
const at: i32 = k >> 3
|
|
203
238
|
if (at < 0 || at >= toI32(bits.length)) {
|
|
@@ -247,15 +282,25 @@ export class QuicStreamPools {
|
|
|
247
282
|
readyData: u8[][]
|
|
248
283
|
readyBits: u8[][]
|
|
249
284
|
/** The empty array a free reserve entry holds. */
|
|
250
|
-
none: u8[]
|
|
285
|
+
private none: u8[]
|
|
251
286
|
/** How many buffers the reserve holds. */
|
|
252
287
|
ready: i32 = 0
|
|
253
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* The most the reserve keeps from one packet to the next: one connection's stream count.
|
|
290
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
291
|
+
*/
|
|
254
292
|
hold: i32 = 0
|
|
255
293
|
/** How many buffers each pool's free list has been grown to hold, by `fit`. */
|
|
256
|
-
room: i32 = 0
|
|
294
|
+
private room: i32 = 0
|
|
257
295
|
|
|
258
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Pools for `connections` connections of `streams` stream slots each, `bufferSize` bytes each way.
|
|
298
|
+
*
|
|
299
|
+
* @param bufferSize The bytes of each stream buffer; each bitmap is a bit per byte of it.
|
|
300
|
+
* @param streams The stream slots of one connection, its `QuicStreams` count.
|
|
301
|
+
* @param connections How many connections share the pools. Each pool holds at most
|
|
302
|
+
* `streams * 2 * connections` buffers.
|
|
303
|
+
*/
|
|
259
304
|
constructor(bufferSize: i32, streams: i32, connections: i32) {
|
|
260
305
|
this.data = new BufferPool("QuicStreams.data", bufferSize, streams * 2 * connections)
|
|
261
306
|
this.bits = new BufferPool("QuicStreams.bits", (bufferSize + 7) >> 3, streams * 2 * connections)
|
|
@@ -273,6 +318,7 @@ export class QuicStreamPools {
|
|
|
273
318
|
* Readies the reserve for a packet that could start `need` receive sides:
|
|
274
319
|
* trims it to `hold` buffers, then tops it up to `need`. Takes and gives
|
|
275
320
|
* only when it is outside that window. Never inside an arena scope.
|
|
321
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
276
322
|
*/
|
|
277
323
|
prime(need: i32): void {
|
|
278
324
|
this.drain(this.hold)
|
|
@@ -284,7 +330,10 @@ export class QuicStreamPools {
|
|
|
284
330
|
this.fit()
|
|
285
331
|
}
|
|
286
332
|
|
|
287
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* Gives the reserve's buffers past the first `most` back to the pools, each already zeroed by `keep`. Never inside an arena scope.
|
|
335
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
336
|
+
*/
|
|
288
337
|
drain(most: i32): void {
|
|
289
338
|
while (this.ready > most) {
|
|
290
339
|
this.ready = this.ready - 1
|
|
@@ -303,7 +352,7 @@ export class QuicStreamPools {
|
|
|
303
352
|
* the arena must not move by it (QUIC-3). The room doubles, so the pushes
|
|
304
353
|
* cost O(1) for each buffer made.
|
|
305
354
|
*/
|
|
306
|
-
fit(): void {
|
|
355
|
+
private fit(): void {
|
|
307
356
|
const made: i32 = this.data.made
|
|
308
357
|
if (made <= this.room) {
|
|
309
358
|
return
|
|
@@ -320,7 +369,10 @@ export class QuicStreamPools {
|
|
|
320
369
|
this.room = target
|
|
321
370
|
}
|
|
322
371
|
|
|
323
|
-
/**
|
|
372
|
+
/**
|
|
373
|
+
* Lends the reserve's last buffer, into `stream`'s receive side. Panics when the reserve is empty: a packet handled without `prime`.
|
|
374
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
375
|
+
*/
|
|
324
376
|
lend(stream: QuicStream): void {
|
|
325
377
|
if (this.ready <= 0) {
|
|
326
378
|
panic("QuicStreams: a receive buffer was wanted with none primed")
|
|
@@ -338,6 +390,7 @@ export class QuicStreamPools {
|
|
|
338
390
|
* the same ceiling, so once the pools have made every buffer and lent them
|
|
339
391
|
* all, a send side wanting one means the reserve holds it. Never inside an
|
|
340
392
|
* arena scope, where a take would allocate.
|
|
393
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
341
394
|
*/
|
|
342
395
|
lendSend(stream: QuicStream): void {
|
|
343
396
|
if (this.data.free.length === 0 && this.data.made >= this.data.ceiling && this.ready > 0) {
|
|
@@ -358,6 +411,7 @@ export class QuicStreamPools {
|
|
|
358
411
|
* first `used` bytes of the buffer and the bits of them. Safe inside an
|
|
359
412
|
* arena scope. Panics when the reserve is full: more given back between
|
|
360
413
|
* two `drain`s than one connection holds, a table's bug.
|
|
414
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
361
415
|
*/
|
|
362
416
|
keep(buf: u8[], have: u8[], used: i32): void {
|
|
363
417
|
if (this.ready >= toI32(this.readyData.length)) {
|
|
@@ -370,7 +424,12 @@ export class QuicStreamPools {
|
|
|
370
424
|
this.ready = this.ready + 1
|
|
371
425
|
}
|
|
372
426
|
|
|
373
|
-
/**
|
|
427
|
+
/**
|
|
428
|
+
* How many buffers and bitmaps are lent to streams now, the reserve's left out: 0 once every stream
|
|
429
|
+
* that borrowed has given back.
|
|
430
|
+
*
|
|
431
|
+
* @returns The buffers plus the bitmaps out on loan, so a side holding both counts 2.
|
|
432
|
+
*/
|
|
374
433
|
lent(): i32 {
|
|
375
434
|
return this.data.lent() + this.bits.lent() - this.ready - this.ready
|
|
376
435
|
}
|
|
@@ -380,6 +439,10 @@ export class QuicStreamPools {
|
|
|
380
439
|
* Pushes `none` onto `free` until it is `target` long, then pops each one off
|
|
381
440
|
* again: the capacity stays, so giving back that many buffers to the pool the
|
|
382
441
|
* list belongs to never grows the arena.
|
|
442
|
+
*
|
|
443
|
+
* @param free A pool's free list; its length is unchanged on return.
|
|
444
|
+
* @param target The capacity, in entries, the list is grown to. No larger than its length does nothing.
|
|
445
|
+
* @param none The placeholder pushed and popped, the table's empty array.
|
|
383
446
|
*/
|
|
384
447
|
export const quicStreamGrowFree = (free: u8[][], target: i32, none: u8[]): void => {
|
|
385
448
|
const length: i32 = toI32(free.length)
|
|
@@ -405,7 +468,10 @@ export class QuicStream {
|
|
|
405
468
|
*/
|
|
406
469
|
recvBuf: u8[]
|
|
407
470
|
recvHave: u8[]
|
|
408
|
-
/**
|
|
471
|
+
/**
|
|
472
|
+
* How far the application has read.
|
|
473
|
+
* @internal Read by http3.ts, and in quic-stream.ts outside the class.
|
|
474
|
+
*/
|
|
409
475
|
recvRead: i64 = 0
|
|
410
476
|
/** Every byte below this has arrived. */
|
|
411
477
|
recvContiguous: i64 = 0
|
|
@@ -417,7 +483,10 @@ export class QuicStream {
|
|
|
417
483
|
recvLimit: i64 = 0
|
|
418
484
|
/** The peer's RESET_STREAM error code, or -1. */
|
|
419
485
|
resetCode: i64 = -1
|
|
420
|
-
/**
|
|
486
|
+
/**
|
|
487
|
+
* The STOP_SENDING error code this side asked with, or -1.
|
|
488
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
489
|
+
*/
|
|
421
490
|
stopSendingCode: i64 = -1
|
|
422
491
|
/**
|
|
423
492
|
* The send buffer: byte `o` at `o % size`, its bit in `sendAcked` set once
|
|
@@ -433,38 +502,75 @@ export class QuicStream {
|
|
|
433
502
|
sendNext: i64 = 0
|
|
434
503
|
/** One past the last byte written. */
|
|
435
504
|
sendEnd: i64 = 0
|
|
436
|
-
/**
|
|
505
|
+
/**
|
|
506
|
+
* The credit the peer gave: no byte at or past this offset may be sent.
|
|
507
|
+
* @internal Read by quic.ts, and in quic-stream.ts outside the class.
|
|
508
|
+
*/
|
|
437
509
|
sendLimit: i64 = 0
|
|
438
510
|
/** Bytes a lost packet carried, `[resendLow, resendHigh)`, or -1; `resendFin` when the FIN was among them. */
|
|
439
511
|
resendLow: i64 = -1
|
|
440
512
|
resendHigh: i64 = -1
|
|
441
|
-
/**
|
|
513
|
+
/**
|
|
514
|
+
* The error code of this side's RESET_STREAM, and its final size.
|
|
515
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
516
|
+
*/
|
|
442
517
|
resetSentCode: i64 = 0
|
|
518
|
+
/** @internal Read in quic-stream.ts outside the class. */
|
|
443
519
|
resetFinal: i64 = 0
|
|
444
520
|
/** The peer's STOP_SENDING error code, or -1. */
|
|
445
521
|
stopCode: i64 = -1
|
|
446
|
-
/**
|
|
522
|
+
/**
|
|
523
|
+
* The limit the last STREAM_DATA_BLOCKED named, or -1.
|
|
524
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
525
|
+
*/
|
|
447
526
|
blockedAt: i64 = -1
|
|
448
|
-
/**
|
|
527
|
+
/**
|
|
528
|
+
* The bytes of each buffer once borrowed, which the offsets wrap at whether or not one is.
|
|
529
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
530
|
+
*/
|
|
449
531
|
size: i32 = 0
|
|
450
532
|
sendState: i32 = 0
|
|
451
533
|
recvState: i32 = 0
|
|
452
|
-
/**
|
|
534
|
+
/**
|
|
535
|
+
* Whether the application wrote the FIN, a frame carried it, and the peer acknowledged it.
|
|
536
|
+
* @internal Read by quic.ts, and in quic-stream.ts outside the class.
|
|
537
|
+
*/
|
|
453
538
|
finQueued: boolean = false
|
|
539
|
+
/** @internal Read in quic-stream.ts outside the class. */
|
|
454
540
|
finSent: boolean = false
|
|
541
|
+
/** @internal Read in quic-stream.ts outside the class. */
|
|
455
542
|
finAcked: boolean = false
|
|
543
|
+
/** @internal Read in quic-stream.ts outside the class. */
|
|
456
544
|
resendFin: boolean = false
|
|
457
|
-
/**
|
|
545
|
+
/**
|
|
546
|
+
* What this stream owes the peer: MAX_STREAM_DATA, STREAM_DATA_BLOCKED, RESET_STREAM, STOP_SENDING.
|
|
547
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
548
|
+
*/
|
|
458
549
|
maxDataOwed: boolean = false
|
|
550
|
+
/** @internal Read in quic-stream.ts outside the class. */
|
|
459
551
|
blockedOwed: boolean = false
|
|
552
|
+
/** @internal Read in quic-stream.ts outside the class. */
|
|
460
553
|
resetOwed: boolean = false
|
|
554
|
+
/** @internal Read in quic-stream.ts outside the class. */
|
|
461
555
|
stopOwed: boolean = false
|
|
462
|
-
/**
|
|
556
|
+
/**
|
|
557
|
+
* Whether a write was cut short for room, so freed room is an event.
|
|
558
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
559
|
+
*/
|
|
463
560
|
wantsWrite: boolean = false
|
|
464
|
-
/**
|
|
561
|
+
/**
|
|
562
|
+
* Whether the slot is in the event ring.
|
|
563
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
564
|
+
*/
|
|
465
565
|
queued: boolean = false
|
|
466
566
|
|
|
467
|
-
/**
|
|
567
|
+
/**
|
|
568
|
+
* A slot for buffers of `bufferSize` bytes, holding none: each side starts as `none`, the table's
|
|
569
|
+
* empty array.
|
|
570
|
+
*
|
|
571
|
+
* @param bufferSize The bytes of the buffer each side borrows later.
|
|
572
|
+
* @param none The table's empty array, which every side holds until it borrows; shared, never written.
|
|
573
|
+
*/
|
|
468
574
|
constructor(bufferSize: i32, none: u8[]) {
|
|
469
575
|
this.size = bufferSize
|
|
470
576
|
this.recvBuf = none
|
|
@@ -473,22 +579,37 @@ export class QuicStream {
|
|
|
473
579
|
this.sendAcked = none
|
|
474
580
|
}
|
|
475
581
|
|
|
476
|
-
/**
|
|
582
|
+
/**
|
|
583
|
+
* The buffer index of stream offset `offset`.
|
|
584
|
+
*
|
|
585
|
+
* @param offset A byte offset in the stream, 0 or more.
|
|
586
|
+
* @returns `offset` modulo the buffer size, or 0 when the size is 0.
|
|
587
|
+
*/
|
|
477
588
|
at(offset: i64): i32 {
|
|
478
589
|
return this.size > 0 ? toI32(offset % toI64(this.size)) : 0
|
|
479
590
|
}
|
|
480
591
|
|
|
481
|
-
/**
|
|
592
|
+
/**
|
|
593
|
+
* How many bytes can be read now.
|
|
594
|
+
* @internal Read by http3.ts and quic.ts, and in quic-stream.ts outside the class.
|
|
595
|
+
*/
|
|
482
596
|
readable(): i64 {
|
|
483
597
|
return this.recvContiguous - this.recvRead
|
|
484
598
|
}
|
|
485
599
|
|
|
486
|
-
/**
|
|
600
|
+
/**
|
|
601
|
+
* How many more bytes the send buffer takes.
|
|
602
|
+
*
|
|
603
|
+
* @returns The buffer size less the bytes written and not yet acknowledged.
|
|
604
|
+
*/
|
|
487
605
|
room(): i64 {
|
|
488
606
|
return toI64(this.size) - (this.sendEnd - this.sendBase)
|
|
489
607
|
}
|
|
490
608
|
|
|
491
|
-
/**
|
|
609
|
+
/**
|
|
610
|
+
* Whether the sending side has a frame to go: lost bytes, new bytes, or a FIN not yet sent.
|
|
611
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
612
|
+
*/
|
|
492
613
|
wantsToSend(): boolean {
|
|
493
614
|
if (this.sendState === QUIC_SEND_NONE || this.sendState >= QUIC_SEND_DATA_RECVD) {
|
|
494
615
|
return false
|
|
@@ -501,7 +622,10 @@ export class QuicStream {
|
|
|
501
622
|
)
|
|
502
623
|
}
|
|
503
624
|
|
|
504
|
-
/**
|
|
625
|
+
/**
|
|
626
|
+
* Whether both sides are done, so the slot can be freed (§3.3).
|
|
627
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
628
|
+
*/
|
|
505
629
|
finished(): boolean {
|
|
506
630
|
const sendDone: boolean =
|
|
507
631
|
this.sendState === QUIC_SEND_NONE ||
|
|
@@ -518,6 +642,7 @@ export class QuicStream {
|
|
|
518
642
|
* Empties the slot for stream `id`, with `recvLimit` and `sendLimit` its
|
|
519
643
|
* first credits. It holds no buffers here, and a borrowed bitmap comes
|
|
520
644
|
* back from its pool already zeroed.
|
|
645
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
521
646
|
*/
|
|
522
647
|
open(id: i64, recvLimit: i64, sendLimit: i64): void {
|
|
523
648
|
this.id = id
|
|
@@ -554,7 +679,10 @@ export class QuicStream {
|
|
|
554
679
|
this.wantsWrite = false
|
|
555
680
|
}
|
|
556
681
|
|
|
557
|
-
/**
|
|
682
|
+
/**
|
|
683
|
+
* Merges `[offset, offset + length)` into the range to send again, with the FIN when it was lost too.
|
|
684
|
+
* @internal Read in quic-stream.ts outside the class.
|
|
685
|
+
*/
|
|
558
686
|
resend(offset: i64, length: i32, fin: boolean): void {
|
|
559
687
|
if (this.sendState === QUIC_SEND_NONE || this.sendState >= QUIC_SEND_DATA_RECVD) {
|
|
560
688
|
return
|
|
@@ -589,15 +717,15 @@ export class QuicStream {
|
|
|
589
717
|
export class QuicStreams {
|
|
590
718
|
slots: QuicStream[]
|
|
591
719
|
/** Open addressing by ID: `index[h]` is a slot plus one, 0 for empty. */
|
|
592
|
-
index: i32[]
|
|
720
|
+
private index: i32[]
|
|
593
721
|
/** Slots with news for the application, `eventCount` of them from `eventHead`. */
|
|
594
|
-
events: i32[]
|
|
722
|
+
private events: i32[]
|
|
595
723
|
/**
|
|
596
724
|
* The free slots, a stack of `freeCount`, so a stream opens without a
|
|
597
725
|
* scan: a frame naming a high stream ID opens every lower one (§3.2), and
|
|
598
726
|
* each of those costs one pop, not a pass over the table.
|
|
599
727
|
*/
|
|
600
|
-
free: i32[]
|
|
728
|
+
private free: i32[]
|
|
601
729
|
/**
|
|
602
730
|
* Where the streams borrow their buffers: the table's own pools, or the
|
|
603
731
|
* set a server shares across its connections (`share`). `null` when the
|
|
@@ -605,12 +733,17 @@ export class QuicStreams {
|
|
|
605
733
|
*/
|
|
606
734
|
pools: QuicStreamPools | null = null
|
|
607
735
|
/** The empty array a side holds while it has no buffer borrowed. */
|
|
608
|
-
none: u8[]
|
|
736
|
+
private none: u8[]
|
|
609
737
|
/** How many receive sides hold a buffer now: the rest are what a packet could start. */
|
|
610
|
-
recvLent: i32 = 0
|
|
611
|
-
/**
|
|
738
|
+
private recvLent: i32 = 0
|
|
739
|
+
/**
|
|
740
|
+
* The configured limits on the client's streams at once and this side's own.
|
|
741
|
+
* @internal Read by http3.ts.
|
|
742
|
+
*/
|
|
612
743
|
maxBidi: i64 = 0
|
|
744
|
+
/** @internal Read by http3.ts. */
|
|
613
745
|
maxUni: i64 = 0
|
|
746
|
+
/** @internal Read by http3.ts. */
|
|
614
747
|
localStreams: i64 = 0
|
|
615
748
|
/** How many of each type the client opened, the limit advertised, and how many of them finished. */
|
|
616
749
|
peerBidiOpened: i64 = 0
|
|
@@ -620,31 +753,31 @@ export class QuicStreams {
|
|
|
620
753
|
peerBidiClosed: i64 = 0
|
|
621
754
|
peerUniClosed: i64 = 0
|
|
622
755
|
/** How many of each type this side opened, the client's limits, and how many of this side's are open. */
|
|
623
|
-
localBidiOpened: i64 = 0
|
|
624
|
-
localUniOpened: i64 = 0
|
|
625
|
-
localBidiLimit: i64 = 0
|
|
626
|
-
localUniLimit: i64 = 0
|
|
627
|
-
localOpen: i64 = 0
|
|
756
|
+
private localBidiOpened: i64 = 0
|
|
757
|
+
private localUniOpened: i64 = 0
|
|
758
|
+
private localBidiLimit: i64 = 0
|
|
759
|
+
private localUniLimit: i64 = 0
|
|
760
|
+
private localOpen: i64 = 0
|
|
628
761
|
/** The peer's credit for each stream type as it opens (its transport parameters). */
|
|
629
|
-
peerBidiLocalCredit: i64 = 0
|
|
630
|
-
peerBidiRemoteCredit: i64 = 0
|
|
631
|
-
peerUniCredit: i64 = 0
|
|
762
|
+
private peerBidiLocalCredit: i64 = 0
|
|
763
|
+
private peerBidiRemoteCredit: i64 = 0
|
|
764
|
+
private peerUniCredit: i64 = 0
|
|
632
765
|
/** The connection's receive credit: what was advertised, its window, what arrived, and what was read. */
|
|
633
766
|
recvMaxData: i64 = 0
|
|
634
767
|
windowData: i64 = 0
|
|
635
768
|
recvTotal: i64 = 0
|
|
636
|
-
recvConsumed: i64 = 0
|
|
769
|
+
private recvConsumed: i64 = 0
|
|
637
770
|
/** The connection's send credit from the peer, what was sent against it, and what is written but not sent. */
|
|
638
771
|
sendMaxData: i64 = 0
|
|
639
|
-
sendTotal: i64 = 0
|
|
772
|
+
private sendTotal: i64 = 0
|
|
640
773
|
writtenTotal: i64 = 0
|
|
641
774
|
/** The transport error `locate` answered -2 for. */
|
|
642
|
-
locateError: i64 = 0
|
|
775
|
+
private locateError: i64 = 0
|
|
643
776
|
/** The limit the last DATA_BLOCKED named, or -1. */
|
|
644
|
-
dataBlockedAt: i64 = -1
|
|
777
|
+
private dataBlockedAt: i64 = -1
|
|
645
778
|
/** The limit each STREAMS_BLOCKED named, or -1. */
|
|
646
|
-
streamsBlockedBidiAt: i64 = -1
|
|
647
|
-
streamsBlockedUniAt: i64 = -1
|
|
779
|
+
private streamsBlockedBidiAt: i64 = -1
|
|
780
|
+
private streamsBlockedUniAt: i64 = -1
|
|
648
781
|
/** What the last `putNextChunk` or `putNextControl` wrote, for the packet's record. */
|
|
649
782
|
lastId: i64 = 0
|
|
650
783
|
lastOffset: i64 = 0
|
|
@@ -653,30 +786,37 @@ export class QuicStreams {
|
|
|
653
786
|
bufferSize: i32 = 0
|
|
654
787
|
lastLength: i32 = 0
|
|
655
788
|
lastKind: i32 = 0
|
|
656
|
-
eventHead: i32 = 0
|
|
657
|
-
eventCount: i32 = 0
|
|
789
|
+
private eventHead: i32 = 0
|
|
790
|
+
private eventCount: i32 = 0
|
|
658
791
|
/** How many slots `free` holds. */
|
|
659
792
|
freeCount: i32 = 0
|
|
660
793
|
/** Where the next packet's search for a stream to send starts, and how many it has looked at. */
|
|
661
|
-
cursor: i32 = 0
|
|
662
|
-
scanned: i32 = 0
|
|
794
|
+
private cursor: i32 = 0
|
|
795
|
+
private scanned: i32 = 0
|
|
663
796
|
/** Whether the last `putNextChunk` carried the FIN, for the packet's record. */
|
|
664
797
|
lastFin: boolean = false
|
|
665
798
|
/** Whether some stream may owe a control frame, so `putNextControl` looks at the slots at all. */
|
|
666
|
-
streamOwes: boolean = false
|
|
799
|
+
private streamOwes: boolean = false
|
|
667
800
|
/** What the connection owes: MAX_DATA, DATA_BLOCKED, MAX_STREAMS and STREAMS_BLOCKED of each type. */
|
|
668
|
-
maxDataOwed: boolean = false
|
|
669
|
-
dataBlockedOwed: boolean = false
|
|
670
|
-
maxStreamsBidiOwed: boolean = false
|
|
671
|
-
maxStreamsUniOwed: boolean = false
|
|
672
|
-
streamsBlockedBidiOwed: boolean = false
|
|
673
|
-
streamsBlockedUniOwed: boolean = false
|
|
801
|
+
private maxDataOwed: boolean = false
|
|
802
|
+
private dataBlockedOwed: boolean = false
|
|
803
|
+
private maxStreamsBidiOwed: boolean = false
|
|
804
|
+
private maxStreamsUniOwed: boolean = false
|
|
805
|
+
private streamsBlockedBidiOwed: boolean = false
|
|
806
|
+
private streamsBlockedUniOwed: boolean = false
|
|
674
807
|
|
|
675
808
|
/**
|
|
676
809
|
* The table for a connection that lets the client open `maxBidi`
|
|
677
810
|
* bidirectional and `maxUni` unidirectional streams at once and opens
|
|
678
811
|
* `localStreams` of its own, each stream with `bufferSize` bytes each way,
|
|
679
812
|
* and a connection receive window of `windowData` bytes.
|
|
813
|
+
*
|
|
814
|
+
* @param maxBidi The client-opened bidirectional streams that may be open at once.
|
|
815
|
+
* @param maxUni The client-opened unidirectional streams that may be open at once.
|
|
816
|
+
* @param localStreams The streams this side may have open at once, of both types.
|
|
817
|
+
* @param bufferSize The bytes of each stream's buffer, each way: the most a stream's credit runs ahead
|
|
818
|
+
* of the application's reads.
|
|
819
|
+
* @param windowData The connection's receive window in bytes, the MAX_DATA step.
|
|
680
820
|
*/
|
|
681
821
|
constructor(maxBidi: i64, maxUni: i64, localStreams: i64, bufferSize: i32, windowData: i64) {
|
|
682
822
|
const count: i32 = toI32(maxBidi + maxUni + localStreams)
|
|
@@ -705,6 +845,8 @@ export class QuicStreams {
|
|
|
705
845
|
* table's own: how a server's connections share one set. Call it before
|
|
706
846
|
* any stream has borrowed, or after `reset`. Panics when the pools' buffers
|
|
707
847
|
* are not `bufferSize` bytes.
|
|
848
|
+
*
|
|
849
|
+
* @param pools The pools to borrow from, kept by reference; usually shared with other connections.
|
|
708
850
|
*/
|
|
709
851
|
share(pools: QuicStreamPools): void {
|
|
710
852
|
if (pools.data.size !== this.bufferSize) {
|
|
@@ -724,6 +866,7 @@ export class QuicStreams {
|
|
|
724
866
|
* table had when each slot owned its buffers: how many it holds turns on
|
|
725
867
|
* when the peer acknowledges, so a lazily grown private pool would go on
|
|
726
868
|
* allocating after any warm-up. A server's shared pools grow lazily.
|
|
869
|
+
* @internal Read by quic.ts.
|
|
727
870
|
*/
|
|
728
871
|
ownPools(): QuicStreamPools | null {
|
|
729
872
|
const pools: QuicStreamPools | null = this.pools
|
|
@@ -755,6 +898,8 @@ export class QuicStreams {
|
|
|
755
898
|
* `idle` already is. Once warm the buffers a packet gives back refill the
|
|
756
899
|
* reserve for the next one, so this costs a handful of comparisons, not a
|
|
757
900
|
* take per side.
|
|
901
|
+
*
|
|
902
|
+
* @param bytes The packet's length in bytes.
|
|
758
903
|
*/
|
|
759
904
|
prime(bytes: i32): void {
|
|
760
905
|
const pools: QuicStreamPools | null = this.ownPools()
|
|
@@ -786,7 +931,7 @@ export class QuicStreams {
|
|
|
786
931
|
* when the reserve is empty: a packet handled without `prime`, where a
|
|
787
932
|
* take would allocate inside the scope.
|
|
788
933
|
*/
|
|
789
|
-
borrowRecv(stream: QuicStream): void {
|
|
934
|
+
private borrowRecv(stream: QuicStream): void {
|
|
790
935
|
const pools: QuicStreamPools | null = this.pools
|
|
791
936
|
if (stream.recvBuf.length > 0 || this.bufferSize <= 0) {
|
|
792
937
|
return
|
|
@@ -803,7 +948,7 @@ export class QuicStreams {
|
|
|
803
948
|
* every byte a frame reached: below `recvHighest`, which past a whole
|
|
804
949
|
* buffer is all of it. Nothing when it holds none.
|
|
805
950
|
*/
|
|
806
|
-
giveRecv(stream: QuicStream): void {
|
|
951
|
+
private giveRecv(stream: QuicStream): void {
|
|
807
952
|
const pools: QuicStreamPools | null = this.pools
|
|
808
953
|
if (pools !== null && stream.recvBuf.length > 0) {
|
|
809
954
|
pools.keep(
|
|
@@ -818,7 +963,7 @@ export class QuicStreams {
|
|
|
818
963
|
}
|
|
819
964
|
|
|
820
965
|
/** Borrows `stream`'s send buffer and bitmap from the pools, unless it holds them already or the streams have none. */
|
|
821
|
-
borrowSend(stream: QuicStream): void {
|
|
966
|
+
private borrowSend(stream: QuicStream): void {
|
|
822
967
|
const pools: QuicStreamPools | null = this.ownPools()
|
|
823
968
|
if (pools !== null && stream.sendBuf.length === 0) {
|
|
824
969
|
pools.lendSend(stream)
|
|
@@ -832,7 +977,7 @@ export class QuicStreams {
|
|
|
832
977
|
* byte acknowledged, or the side reset — and before a reset moves
|
|
833
978
|
* `sendEnd` back.
|
|
834
979
|
*/
|
|
835
|
-
giveSend(stream: QuicStream): void {
|
|
980
|
+
private giveSend(stream: QuicStream): void {
|
|
836
981
|
const pools: QuicStreamPools | null = this.pools
|
|
837
982
|
if (pools !== null && stream.sendBuf.length > 0) {
|
|
838
983
|
pools.keep(stream.sendBuf, stream.sendAcked, toI32(quicStreamMin(stream.sendEnd, toI64(stream.size))))
|
|
@@ -899,6 +1044,16 @@ export class QuicStreams {
|
|
|
899
1044
|
* Takes the peer's transport parameters (RFC 9000 §18.2): its limits on
|
|
900
1045
|
* the streams this side opens, the credit each kind of stream starts with,
|
|
901
1046
|
* and the connection's.
|
|
1047
|
+
*
|
|
1048
|
+
* @param maxData `initial_max_data`: the connection's send credit, in bytes.
|
|
1049
|
+
* @param bidiLocal `initial_max_stream_data_bidi_local`: the bytes this side may send on a
|
|
1050
|
+
* client-opened bidirectional stream (local to the peer).
|
|
1051
|
+
* @param bidiRemote `initial_max_stream_data_bidi_remote`: the bytes this side may send on a
|
|
1052
|
+
* bidirectional stream it opens.
|
|
1053
|
+
* @param uni `initial_max_stream_data_uni`: the bytes this side may send on a unidirectional stream it
|
|
1054
|
+
* opens.
|
|
1055
|
+
* @param maxStreamsBidi `initial_max_streams_bidi`: how many bidirectional streams this side may open.
|
|
1056
|
+
* @param maxStreamsUni `initial_max_streams_uni`: how many unidirectional streams this side may open.
|
|
902
1057
|
*/
|
|
903
1058
|
setPeerLimits(
|
|
904
1059
|
maxData: i64,
|
|
@@ -917,12 +1072,17 @@ export class QuicStreams {
|
|
|
917
1072
|
}
|
|
918
1073
|
|
|
919
1074
|
/** The hash bucket `id` starts its probe at. */
|
|
920
|
-
bucket(id: i64): i32 {
|
|
1075
|
+
private bucket(id: i64): i32 {
|
|
921
1076
|
const mixed: i64 = (id >> 2) ^ (id << 3) ^ (id >> 13)
|
|
922
1077
|
return toI32(mixed & toI64(toI32(this.index.length) - 1))
|
|
923
1078
|
}
|
|
924
1079
|
|
|
925
|
-
/**
|
|
1080
|
+
/**
|
|
1081
|
+
* The slot of stream `id`, or -1 when it is not open.
|
|
1082
|
+
*
|
|
1083
|
+
* @param id A stream ID.
|
|
1084
|
+
* @returns The slot's index in the table, or -1 when no open stream has that ID.
|
|
1085
|
+
*/
|
|
926
1086
|
slotOf(id: i64): i32 {
|
|
927
1087
|
const size: i32 = toI32(this.index.length)
|
|
928
1088
|
let h: i32 = this.bucket(id)
|
|
@@ -942,14 +1102,19 @@ export class QuicStreams {
|
|
|
942
1102
|
return -1
|
|
943
1103
|
}
|
|
944
1104
|
|
|
945
|
-
/**
|
|
1105
|
+
/**
|
|
1106
|
+
* The stream `id`, or `null` when it is not open.
|
|
1107
|
+
*
|
|
1108
|
+
* @param id A stream ID.
|
|
1109
|
+
* @returns The stream's slot, owned by the table and reused once the stream is done; or `null`.
|
|
1110
|
+
*/
|
|
946
1111
|
find(id: i64): QuicStream | null {
|
|
947
1112
|
const k: i32 = this.slotOf(id)
|
|
948
1113
|
return k >= 0 && k < toI32(this.slots.length) ? this.slots[k] : null
|
|
949
1114
|
}
|
|
950
1115
|
|
|
951
1116
|
/** Puts slot `k` in the index under its stream's ID. */
|
|
952
|
-
indexInsert(k: i32, id: i64): void {
|
|
1117
|
+
private indexInsert(k: i32, id: i64): void {
|
|
953
1118
|
const size: i32 = toI32(this.index.length)
|
|
954
1119
|
let h: i32 = this.bucket(id)
|
|
955
1120
|
for (let probe: i32 = 0; probe < size; probe += 1) {
|
|
@@ -965,7 +1130,7 @@ export class QuicStreams {
|
|
|
965
1130
|
}
|
|
966
1131
|
|
|
967
1132
|
/** Takes slot `k`, holding `id`, out of the index, moving later entries of its probe run back so none is lost. */
|
|
968
|
-
indexRemove(k: i32, id: i64): void {
|
|
1133
|
+
private indexRemove(k: i32, id: i64): void {
|
|
969
1134
|
const size: i32 = toI32(this.index.length)
|
|
970
1135
|
const mask: i32 = size - 1
|
|
971
1136
|
let h: i32 = this.bucket(id)
|
|
@@ -1010,7 +1175,7 @@ export class QuicStreams {
|
|
|
1010
1175
|
}
|
|
1011
1176
|
|
|
1012
1177
|
/** Puts slot `k` on the event ring, unless it is there already. */
|
|
1013
|
-
queue(k: i32): void {
|
|
1178
|
+
private queue(k: i32): void {
|
|
1014
1179
|
const size: i32 = toI32(this.events.length)
|
|
1015
1180
|
if (k < 0 || k >= toI32(this.slots.length) || this.slots[k].queued || this.eventCount >= size) {
|
|
1016
1181
|
return
|
|
@@ -1029,6 +1194,7 @@ export class QuicStreams {
|
|
|
1029
1194
|
* or room to write again after a short write — or -1 when there is none.
|
|
1030
1195
|
* Each stream comes up once however much happened to it; read and write it
|
|
1031
1196
|
* until it has nothing more to say.
|
|
1197
|
+
* @internal Read by quic.ts.
|
|
1032
1198
|
*/
|
|
1033
1199
|
nextEvent(): i64 {
|
|
1034
1200
|
const size: i32 = toI32(this.events.length)
|
|
@@ -1049,7 +1215,7 @@ export class QuicStreams {
|
|
|
1049
1215
|
}
|
|
1050
1216
|
|
|
1051
1217
|
/** Puts slot `k` on the free stack. */
|
|
1052
|
-
pushFree(k: i32): void {
|
|
1218
|
+
private pushFree(k: i32): void {
|
|
1053
1219
|
const at: i32 = this.freeCount
|
|
1054
1220
|
if (at >= 0 && at < toI32(this.free.length)) {
|
|
1055
1221
|
this.free[at] = k
|
|
@@ -1058,7 +1224,7 @@ export class QuicStreams {
|
|
|
1058
1224
|
}
|
|
1059
1225
|
|
|
1060
1226
|
/** Takes a free slot off the stack, or -1 when every slot is in use. */
|
|
1061
|
-
takeFree(): i32 {
|
|
1227
|
+
private takeFree(): i32 {
|
|
1062
1228
|
const at: i32 = this.freeCount - 1
|
|
1063
1229
|
if (at < 0 || at >= toI32(this.free.length)) {
|
|
1064
1230
|
return -1
|
|
@@ -1068,7 +1234,7 @@ export class QuicStreams {
|
|
|
1068
1234
|
}
|
|
1069
1235
|
|
|
1070
1236
|
/** Opens `id` in a free slot with its first credits; answers the slot, or -1 when none is free. */
|
|
1071
|
-
openSlot(id: i64): i32 {
|
|
1237
|
+
private openSlot(id: i64): i32 {
|
|
1072
1238
|
const k: i32 = this.takeFree()
|
|
1073
1239
|
if (k < 0 || k >= toI32(this.slots.length)) {
|
|
1074
1240
|
return -1
|
|
@@ -1093,7 +1259,7 @@ export class QuicStreams {
|
|
|
1093
1259
|
* the peer opened counts toward raising its limit: MAX_STREAMS is owed
|
|
1094
1260
|
* once half the configured number have finished since the last one.
|
|
1095
1261
|
*/
|
|
1096
|
-
release(k: i32): void {
|
|
1262
|
+
private release(k: i32): void {
|
|
1097
1263
|
if (k < 0 || k >= toI32(this.slots.length)) {
|
|
1098
1264
|
return
|
|
1099
1265
|
}
|
|
@@ -1137,7 +1303,7 @@ export class QuicStreams {
|
|
|
1137
1303
|
* STREAM_STATE_ERROR for one of this side's that it has not opened or a
|
|
1138
1304
|
* unidirectional stream without the half the frame is about (§19.4-§19.13).
|
|
1139
1305
|
*/
|
|
1140
|
-
locate(id: i64, receiving: boolean): i32 {
|
|
1306
|
+
private locate(id: i64, receiving: boolean): i32 {
|
|
1141
1307
|
if (quicStreamIsUni(id) && quicStreamIsLocal(id) === receiving) {
|
|
1142
1308
|
this.locateError = QUIC_ERROR_STREAM_STATE
|
|
1143
1309
|
return -2
|
|
@@ -1185,7 +1351,7 @@ export class QuicStreams {
|
|
|
1185
1351
|
* side gave, for the stream and for the connection (§4.1): past either it
|
|
1186
1352
|
* is FLOW_CONTROL_ERROR. Answers 0 or that.
|
|
1187
1353
|
*/
|
|
1188
|
-
creditReceived(stream: QuicStream, end: i64): i64 {
|
|
1354
|
+
private creditReceived(stream: QuicStream, end: i64): i64 {
|
|
1189
1355
|
if (end > stream.recvLimit) {
|
|
1190
1356
|
return QUIC_ERROR_FLOW_CONTROL
|
|
1191
1357
|
}
|
|
@@ -1204,6 +1370,15 @@ export class QuicStreams {
|
|
|
1204
1370
|
* `offset`, and the FIN when `fin`. Answers 0, or the transport error that
|
|
1205
1371
|
* closes the connection: the stream's ID (see `locate`), a stream only this
|
|
1206
1372
|
* side sends on, the final size, or the credit.
|
|
1373
|
+
*
|
|
1374
|
+
* @param id The frame's stream ID.
|
|
1375
|
+
* @param offset The stream offset of the frame's first byte.
|
|
1376
|
+
* @param buf The packet holding the frame's data; copied from, not kept.
|
|
1377
|
+
* @param from The index in `buf` of the first byte.
|
|
1378
|
+
* @param length How many bytes the frame carries.
|
|
1379
|
+
* @param fin Whether the frame carries the FIN, fixing the final size at `offset + length`.
|
|
1380
|
+
* @returns `QUIC_ERROR_NO_ERROR` (0), or `QUIC_ERROR_STREAM_LIMIT`, `QUIC_ERROR_STREAM_STATE`,
|
|
1381
|
+
* `QUIC_ERROR_FINAL_SIZE` or `QUIC_ERROR_FLOW_CONTROL` to close the connection with.
|
|
1207
1382
|
*/
|
|
1208
1383
|
onStream(id: i64, offset: i64, buf: u8[], from: i32, length: i32, fin: boolean): i64 {
|
|
1209
1384
|
const k: i32 = this.locate(id, true)
|
|
@@ -1264,7 +1439,16 @@ export class QuicStreams {
|
|
|
1264
1439
|
return QUIC_ERROR_NO_ERROR
|
|
1265
1440
|
}
|
|
1266
1441
|
|
|
1267
|
-
/**
|
|
1442
|
+
/**
|
|
1443
|
+
* RESET_STREAM (§19.4): the peer abandons the stream at `finalSize` with `code`. Answers 0 or the
|
|
1444
|
+
* transport error.
|
|
1445
|
+
*
|
|
1446
|
+
* @param id The frame's stream ID.
|
|
1447
|
+
* @param code The application's error code, kept for the reader.
|
|
1448
|
+
* @param finalSize The stream's final size in bytes.
|
|
1449
|
+
* @returns `QUIC_ERROR_NO_ERROR` (0), or `QUIC_ERROR_STREAM_LIMIT`, `QUIC_ERROR_STREAM_STATE`,
|
|
1450
|
+
* `QUIC_ERROR_FINAL_SIZE` or `QUIC_ERROR_FLOW_CONTROL` to close the connection with.
|
|
1451
|
+
*/
|
|
1268
1452
|
onReset(id: i64, code: i64, finalSize: i64): i64 {
|
|
1269
1453
|
const k: i32 = this.locate(id, true)
|
|
1270
1454
|
if (k === -2) {
|
|
@@ -1303,6 +1487,11 @@ export class QuicStreams {
|
|
|
1303
1487
|
* STOP_SENDING (§19.5): the peer wants no more of the stream, which this
|
|
1304
1488
|
* side answers with RESET_STREAM carrying the same code (§3.5). Answers 0
|
|
1305
1489
|
* or the transport error.
|
|
1490
|
+
*
|
|
1491
|
+
* @param id The frame's stream ID.
|
|
1492
|
+
* @param code The application's error code, sent back in the RESET_STREAM.
|
|
1493
|
+
* @returns `QUIC_ERROR_NO_ERROR` (0), or `QUIC_ERROR_STREAM_LIMIT` or `QUIC_ERROR_STREAM_STATE` to
|
|
1494
|
+
* close the connection with.
|
|
1306
1495
|
*/
|
|
1307
1496
|
onStopSending(id: i64, code: i64): i64 {
|
|
1308
1497
|
const k: i32 = this.locate(id, false)
|
|
@@ -1321,7 +1510,14 @@ export class QuicStreams {
|
|
|
1321
1510
|
return QUIC_ERROR_NO_ERROR
|
|
1322
1511
|
}
|
|
1323
1512
|
|
|
1324
|
-
/**
|
|
1513
|
+
/**
|
|
1514
|
+
* MAX_STREAM_DATA (§19.10): more credit for the stream. Answers 0 or the transport error.
|
|
1515
|
+
*
|
|
1516
|
+
* @param id The frame's stream ID.
|
|
1517
|
+
* @param limit The new send limit, a stream offset in bytes; a lower one than held changes nothing.
|
|
1518
|
+
* @returns `QUIC_ERROR_NO_ERROR` (0), or `QUIC_ERROR_STREAM_LIMIT` or `QUIC_ERROR_STREAM_STATE` to
|
|
1519
|
+
* close the connection with.
|
|
1520
|
+
*/
|
|
1325
1521
|
onMaxStreamData(id: i64, limit: i64): i64 {
|
|
1326
1522
|
const k: i32 = this.locate(id, false)
|
|
1327
1523
|
if (k === -2) {
|
|
@@ -1340,13 +1536,19 @@ export class QuicStreams {
|
|
|
1340
1536
|
return QUIC_ERROR_NO_ERROR
|
|
1341
1537
|
}
|
|
1342
1538
|
|
|
1343
|
-
/**
|
|
1539
|
+
/**
|
|
1540
|
+
* STREAM_DATA_BLOCKED (§19.13): only the ID is checked; credit follows reading, not asking.
|
|
1541
|
+
* @internal Read by quic.ts.
|
|
1542
|
+
*/
|
|
1344
1543
|
onStreamDataBlocked(id: i64): i64 {
|
|
1345
1544
|
const k: i32 = this.locate(id, true)
|
|
1346
1545
|
return k === -2 ? this.locateError : QUIC_ERROR_NO_ERROR
|
|
1347
1546
|
}
|
|
1348
1547
|
|
|
1349
|
-
/**
|
|
1548
|
+
/**
|
|
1549
|
+
* MAX_DATA (§19.9): more credit for the connection.
|
|
1550
|
+
* @internal Read by quic.ts.
|
|
1551
|
+
*/
|
|
1350
1552
|
onMaxData(limit: i64): void {
|
|
1351
1553
|
if (limit > this.sendMaxData) {
|
|
1352
1554
|
this.sendMaxData = limit
|
|
@@ -1354,7 +1556,10 @@ export class QuicStreams {
|
|
|
1354
1556
|
}
|
|
1355
1557
|
}
|
|
1356
1558
|
|
|
1357
|
-
/**
|
|
1559
|
+
/**
|
|
1560
|
+
* MAX_STREAMS (§19.11): the peer lets this side open more streams of a type.
|
|
1561
|
+
* @internal Read by quic.ts.
|
|
1562
|
+
*/
|
|
1358
1563
|
onMaxStreams(uni: boolean, limit: i64): void {
|
|
1359
1564
|
if (uni && limit > this.localUniLimit) {
|
|
1360
1565
|
this.localUniLimit = limit
|
|
@@ -1366,7 +1571,7 @@ export class QuicStreams {
|
|
|
1366
1571
|
}
|
|
1367
1572
|
|
|
1368
1573
|
/** Counts `bytes` read (or abandoned by a reset) toward the connection's credit, raising it once half the window is used. */
|
|
1369
|
-
consume(bytes: i64): void {
|
|
1574
|
+
private consume(bytes: i64): void {
|
|
1370
1575
|
this.recvConsumed = this.recvConsumed + bytes
|
|
1371
1576
|
if (
|
|
1372
1577
|
this.recvConsumed + this.windowData - this.recvMaxData >= this.windowData / 2 &&
|
|
@@ -1382,6 +1587,7 @@ export class QuicStreams {
|
|
|
1382
1587
|
* unidirectional. Answers its ID, or `QUIC_STREAM_ERR_LIMIT` when the
|
|
1383
1588
|
* peer's limit is reached (STREAMS_BLOCKED is then owed) or every slot for
|
|
1384
1589
|
* this side's streams is taken.
|
|
1590
|
+
* @internal Read by quic.ts.
|
|
1385
1591
|
*/
|
|
1386
1592
|
open(bidi: boolean): i64 {
|
|
1387
1593
|
const opened: i64 = bidi ? this.localBidiOpened : this.localUniOpened
|
|
@@ -1415,6 +1621,16 @@ export class QuicStreams {
|
|
|
1415
1621
|
* FIN when `fin` and every byte fit. Answers how many bytes it took — fewer
|
|
1416
1622
|
* than `length` when the send buffer is full, and the stream's event fires
|
|
1417
1623
|
* once acknowledgements free room — or a `QUIC_STREAM_ERR_*`.
|
|
1624
|
+
*
|
|
1625
|
+
* @param id The stream ID.
|
|
1626
|
+
* @param buf The bytes to send; copied, not kept.
|
|
1627
|
+
* @param from The index in `buf` of the first byte.
|
|
1628
|
+
* @param length How many bytes to write, 0 or more; a `from + length` past `buf` answers `QUIC_STREAM_ERR_UNKNOWN`.
|
|
1629
|
+
* @param fin Whether this write ends the stream; queued only when all `length` bytes were taken.
|
|
1630
|
+
* @returns The bytes taken, 0 to `length`; or `QUIC_STREAM_ERR_UNKNOWN` (no such stream, or a window
|
|
1631
|
+
* outside `buf`), `QUIC_STREAM_ERR_DIRECTION` (a stream this side only receives on),
|
|
1632
|
+
* `QUIC_STREAM_ERR_STOPPED` (the peer sent STOP_SENDING) or `QUIC_STREAM_ERR_FINISHED` (the FIN is
|
|
1633
|
+
* queued or the side was reset).
|
|
1418
1634
|
*/
|
|
1419
1635
|
write(id: i64, buf: u8[], from: i32, length: i32, fin: boolean): i32 {
|
|
1420
1636
|
const k: i32 = this.slotOf(id)
|
|
@@ -1470,6 +1686,14 @@ export class QuicStreams {
|
|
|
1470
1686
|
* `QUIC_STREAM_END` or `QUIC_STREAM_ERR_RESET`, so read until one does.
|
|
1471
1687
|
* After `QuicConnection.release`, a stream that still owed bytes answers
|
|
1472
1688
|
* `QUIC_STREAM_END` and copies nothing: its buffer went back to the pool.
|
|
1689
|
+
*
|
|
1690
|
+
* @param id The stream ID.
|
|
1691
|
+
* @param buf Where the bytes go.
|
|
1692
|
+
* @param at The index in `buf` of the first byte written.
|
|
1693
|
+
* @param length The most bytes to read, 0 or more; an `at + length` past `buf` answers `QUIC_STREAM_ERR_UNKNOWN`.
|
|
1694
|
+
* @returns The bytes read, 0 or more; `QUIC_STREAM_END`; `QUIC_STREAM_ERR_RESET`;
|
|
1695
|
+
* `QUIC_STREAM_ERR_UNKNOWN` (no such stream, or a window outside `buf`); or
|
|
1696
|
+
* `QUIC_STREAM_ERR_DIRECTION` (a stream this side only sends on).
|
|
1473
1697
|
*/
|
|
1474
1698
|
read(id: i64, buf: u8[], at: i32, length: i32): i32 {
|
|
1475
1699
|
const k: i32 = this.slotOf(id)
|
|
@@ -1533,7 +1757,7 @@ export class QuicStreams {
|
|
|
1533
1757
|
}
|
|
1534
1758
|
|
|
1535
1759
|
/** Abandons the sending side of slot `k` with `code` (§3.1, §19.4): what was not sent is dropped and RESET_STREAM is owed. */
|
|
1536
|
-
resetSlot(k: i32, code: i64): void {
|
|
1760
|
+
private resetSlot(k: i32, code: i64): void {
|
|
1537
1761
|
if (k < 0 || k >= toI32(this.slots.length)) {
|
|
1538
1762
|
return
|
|
1539
1763
|
}
|
|
@@ -1557,7 +1781,15 @@ export class QuicStreams {
|
|
|
1557
1781
|
stream.blockedOwed = false
|
|
1558
1782
|
}
|
|
1559
1783
|
|
|
1560
|
-
/**
|
|
1784
|
+
/**
|
|
1785
|
+
* Resets stream `id`'s sending side with `code`. Answers `QUIC_STREAM_OK` or a `QUIC_STREAM_ERR_*`.
|
|
1786
|
+
*
|
|
1787
|
+
* @param id The stream ID.
|
|
1788
|
+
* @param code The application's error code for the RESET_STREAM.
|
|
1789
|
+
* @returns `QUIC_STREAM_OK`; `QUIC_STREAM_ERR_UNKNOWN` (no such stream); `QUIC_STREAM_ERR_DIRECTION`
|
|
1790
|
+
* (a stream this side only receives on); or `QUIC_STREAM_ERR_FINISHED` (every byte was already
|
|
1791
|
+
* acknowledged, or the side was already reset).
|
|
1792
|
+
*/
|
|
1561
1793
|
resetStream(id: i64, code: i64): i32 {
|
|
1562
1794
|
const k: i32 = this.slotOf(id)
|
|
1563
1795
|
if (k < 0 || k >= toI32(this.slots.length)) {
|
|
@@ -1574,7 +1806,16 @@ export class QuicStreams {
|
|
|
1574
1806
|
return QUIC_STREAM_OK
|
|
1575
1807
|
}
|
|
1576
1808
|
|
|
1577
|
-
/**
|
|
1809
|
+
/**
|
|
1810
|
+
* Asks the peer to stop sending on stream `id`, with `code` (STOP_SENDING, §3.5). Answers
|
|
1811
|
+
* `QUIC_STREAM_OK` or a `QUIC_STREAM_ERR_*`.
|
|
1812
|
+
*
|
|
1813
|
+
* @param id The stream ID.
|
|
1814
|
+
* @param code The application's error code; only the first call's is sent.
|
|
1815
|
+
* @returns `QUIC_STREAM_OK`; `QUIC_STREAM_ERR_UNKNOWN` (no such stream); `QUIC_STREAM_ERR_DIRECTION`
|
|
1816
|
+
* (a stream this side only sends on); or `QUIC_STREAM_ERR_FINISHED` (every byte already arrived,
|
|
1817
|
+
* or the stream was reset).
|
|
1818
|
+
*/
|
|
1578
1819
|
stopSending(id: i64, code: i64): i32 {
|
|
1579
1820
|
const k: i32 = this.slotOf(id)
|
|
1580
1821
|
if (k < 0 || k >= toI32(this.slots.length)) {
|
|
@@ -1607,6 +1848,11 @@ export class QuicStreams {
|
|
|
1607
1848
|
* the offset past it, with `lastId`, `lastOffset`, `lastLength` and
|
|
1608
1849
|
* `lastFin` describing it for the packet's record; or `at` when no stream
|
|
1609
1850
|
* has a frame that fits.
|
|
1851
|
+
*
|
|
1852
|
+
* @param buf The packet being built.
|
|
1853
|
+
* @param at The index in `buf` where the frame starts.
|
|
1854
|
+
* @param end The index in `buf` past the room the frame may use.
|
|
1855
|
+
* @returns The index past the frame written, or `at` when none was.
|
|
1610
1856
|
*/
|
|
1611
1857
|
putNextChunk(buf: u8[], at: i32, end: i32): i32 {
|
|
1612
1858
|
const count: i32 = toI32(this.slots.length)
|
|
@@ -1642,7 +1888,7 @@ export class QuicStreams {
|
|
|
1642
1888
|
* (§4.5); or, with no bytes left to send again, a lost FIN alone, as a
|
|
1643
1889
|
* frame of no bytes at the final size.
|
|
1644
1890
|
*/
|
|
1645
|
-
putResend(stream: QuicStream, buf: u8[], at: i32, end: i32): i32 {
|
|
1891
|
+
private putResend(stream: QuicStream, buf: u8[], at: i32, end: i32): i32 {
|
|
1646
1892
|
if (stream.resendLow >= 0) {
|
|
1647
1893
|
let low: i64 = stream.resendLow < stream.sendBase ? stream.sendBase : stream.resendLow
|
|
1648
1894
|
while (low < stream.resendHigh && quicStreamBit(stream.sendAcked, stream.at(low))) {
|
|
@@ -1699,7 +1945,7 @@ export class QuicStreams {
|
|
|
1699
1945
|
}
|
|
1700
1946
|
|
|
1701
1947
|
/** Describes the STREAM frame just written, for the packet's record. */
|
|
1702
|
-
noteChunk(id: i64, offset: i64, length: i32, fin: boolean): void {
|
|
1948
|
+
private noteChunk(id: i64, offset: i64, length: i32, fin: boolean): void {
|
|
1703
1949
|
this.lastId = id
|
|
1704
1950
|
this.lastOffset = offset
|
|
1705
1951
|
this.lastLength = length
|
|
@@ -1710,7 +1956,7 @@ export class QuicStreams {
|
|
|
1710
1956
|
* One STREAM frame of `stream`'s new bytes within both credits. A stream
|
|
1711
1957
|
* held back by a credit owes the matching BLOCKED frame, once per limit.
|
|
1712
1958
|
*/
|
|
1713
|
-
putNew(stream: QuicStream, k: i32, buf: u8[], at: i32, end: i32): i32 {
|
|
1959
|
+
private putNew(stream: QuicStream, k: i32, buf: u8[], at: i32, end: i32): i32 {
|
|
1714
1960
|
const unsent: i64 = stream.sendEnd - stream.sendNext
|
|
1715
1961
|
const streamCredit: i64 = stream.sendLimit - stream.sendNext
|
|
1716
1962
|
const connectionCredit: i64 = this.sendMaxData - this.sendTotal
|
|
@@ -1772,6 +2018,7 @@ export class QuicStreams {
|
|
|
1772
2018
|
* Answers the offset past it, with `lastKind` (a
|
|
1773
2019
|
* `QUIC_STREAM_CONTROL_*`) and `lastValue` (the stream it names, or 0)
|
|
1774
2020
|
* for the packet's record; or `at` when nothing owed fits.
|
|
2021
|
+
* @internal Read by quic.ts.
|
|
1775
2022
|
*/
|
|
1776
2023
|
putNextControl(buf: u8[], at: i32, end: i32): i32 {
|
|
1777
2024
|
this.lastValue = 0
|
|
@@ -1850,7 +2097,7 @@ export class QuicStreams {
|
|
|
1850
2097
|
}
|
|
1851
2098
|
|
|
1852
2099
|
/** The next control frame `stream` owes, if it fits; sets `lastKind`. */
|
|
1853
|
-
putStreamControl(stream: QuicStream, buf: u8[], at: i32, end: i32): i32 {
|
|
2100
|
+
private putStreamControl(stream: QuicStream, buf: u8[], at: i32, end: i32): i32 {
|
|
1854
2101
|
if (stream.maxDataOwed) {
|
|
1855
2102
|
const next: i32 = quicPutStreamValue(
|
|
1856
2103
|
buf,
|
|
@@ -1906,6 +2153,11 @@ export class QuicStreams {
|
|
|
1906
2153
|
* and its FIN when `fin`, was acknowledged: the bytes are marked, the
|
|
1907
2154
|
* buffer's start moves past every acknowledged one, and once all of them
|
|
1908
2155
|
* and the FIN are, the sending side is done (§3.1 "Data Recvd").
|
|
2156
|
+
*
|
|
2157
|
+
* @param id The stream ID the packet's record names.
|
|
2158
|
+
* @param offset The stream offset of the chunk's first byte.
|
|
2159
|
+
* @param length The chunk's bytes.
|
|
2160
|
+
* @param fin Whether the chunk carried the FIN.
|
|
1909
2161
|
*/
|
|
1910
2162
|
chunkAcked(id: i64, offset: i64, length: i32, fin: boolean): void {
|
|
1911
2163
|
const k: i32 = this.slotOf(id)
|
|
@@ -1942,7 +2194,15 @@ export class QuicStreams {
|
|
|
1942
2194
|
}
|
|
1943
2195
|
}
|
|
1944
2196
|
|
|
1945
|
-
/**
|
|
2197
|
+
/**
|
|
2198
|
+
* A packet that carried those bytes was lost: they are queued to go again, unless the side is done
|
|
2199
|
+
* or reset.
|
|
2200
|
+
*
|
|
2201
|
+
* @param id The stream ID the packet's record names; a stream no longer open is ignored.
|
|
2202
|
+
* @param offset The stream offset of the chunk's first byte.
|
|
2203
|
+
* @param length The chunk's bytes.
|
|
2204
|
+
* @param fin Whether the chunk carried the FIN.
|
|
2205
|
+
*/
|
|
1946
2206
|
chunkLost(id: i64, offset: i64, length: i32, fin: boolean): void {
|
|
1947
2207
|
const stream: QuicStream | null = this.find(id)
|
|
1948
2208
|
if (stream !== null) {
|
|
@@ -1954,6 +2214,7 @@ export class QuicStreams {
|
|
|
1954
2214
|
* A packet that carried control frame `kind` (for stream `value`, or 0)
|
|
1955
2215
|
* was acknowledged: a RESET_STREAM acknowledged ends its sending side
|
|
1956
2216
|
* (§3.1 "Reset Recvd").
|
|
2217
|
+
* @internal Read by quic.ts.
|
|
1957
2218
|
*/
|
|
1958
2219
|
controlAcked(kind: i32, value: i64): void {
|
|
1959
2220
|
if (kind !== QUIC_STREAM_CONTROL_RESET) {
|
|
@@ -1970,6 +2231,7 @@ export class QuicStreams {
|
|
|
1970
2231
|
* A packet that carried control frame `kind` was lost: it is owed again
|
|
1971
2232
|
* with the current value, while it still says something (§13.3) — a
|
|
1972
2233
|
* BLOCKED frame only while the limit it named still holds.
|
|
2234
|
+
* @internal Read by quic.ts.
|
|
1973
2235
|
*/
|
|
1974
2236
|
controlLost(kind: i32, value: i64): void {
|
|
1975
2237
|
if (kind === QUIC_STREAM_CONTROL_MAX_DATA) {
|
|
@@ -1990,7 +2252,7 @@ export class QuicStreams {
|
|
|
1990
2252
|
}
|
|
1991
2253
|
|
|
1992
2254
|
/** A lost control frame of stream `id`. */
|
|
1993
|
-
streamControlLost(kind: i32, id: i64): void {
|
|
2255
|
+
private streamControlLost(kind: i32, id: i64): void {
|
|
1994
2256
|
const stream: QuicStream | null = this.find(id)
|
|
1995
2257
|
if (stream === null) {
|
|
1996
2258
|
return
|