nish 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/AI.md +9 -2
- package/docs/INSTALL.md +6 -1
- package/package.json +15 -5
- 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-listener.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* the RFC means: nothing it answers depends on any connection.
|
|
9
9
|
*
|
|
10
10
|
* import { QuicListener, QuicListenerAnswer, QUIC_LISTEN_ACCEPT, QUIC_LISTENER_ANSWER_SIZE } from "nish/net/quic-listener";
|
|
11
|
+
* import { QuicConnection } from "nish/net/quic";
|
|
11
12
|
*
|
|
12
13
|
* const listener = new QuicListener(config, entropy); // entropy: QUIC_LISTENER_ENTROPY_SIZE random bytes
|
|
13
14
|
* const answer = new QuicListenerAnswer(QUIC_LISTENER_ANSWER_SIZE); // once, beside the listener
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
* listener a packet for a connection that is still alive would give that
|
|
35
36
|
* token, which ends the connection, to whoever sent it (RFC 9000 §21.11).
|
|
36
37
|
*
|
|
37
|
-
* **Retry tokens** (§8.1.4) are this server's own format: a marker byte, the
|
|
38
|
+
* **Retry tokens** (§8.1.4). They are this server's own format: a marker byte, the
|
|
38
39
|
* time the token was issued, and the client's original Destination
|
|
39
40
|
* Connection ID, then 16 bytes of HMAC-SHA256 under the configuration's
|
|
40
41
|
* `retryTokenKey` over all of that, the Retry's Source Connection ID (which
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
* INVALID_TOKEN (§8.1.2); a token without the marker, which some other
|
|
47
48
|
* server issued, is treated as no token at all (§8.1.3).
|
|
48
49
|
*
|
|
49
|
-
* **Stateless resets** (§10.3) end in the token `quicStatelessResetToken`
|
|
50
|
+
* **Stateless resets** (§10.3). They end in the token `quicStatelessResetToken`
|
|
50
51
|
* derives (computed in place, by `quicConnResetTokenInto`) from the configuration's static key and the packet's connection
|
|
51
52
|
* ID, so a server that restarted with the same key can end the connections
|
|
52
53
|
* it lost. RFC 9000 §10.3 and §10.3.3 bound them, and each bound is held
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
* `QUIC_LISTENER_RESET_INTERVAL` milliseconds. Each reset's other bytes are
|
|
60
61
|
* unpredictable, from the listener's own generator.
|
|
61
62
|
*
|
|
62
|
-
* **Pacing** (RFC 9002 §7.7) is the carrier's send loop, so it is here
|
|
63
|
+
* **Pacing** (RFC 9002 §7.7). It is the carrier's send loop, so it is here
|
|
63
64
|
* beside the rest of what the carrier calls: `quicListenerTakePaced` takes a
|
|
64
65
|
* connection's next datagram only when its pacer has the credit for it, and
|
|
65
66
|
* `quicListenerPaceTime` says when it will. The pacer earns 5/4 of the
|
|
@@ -227,8 +228,15 @@ export class QuicListenerAnswer {
|
|
|
227
228
|
retryScid: u8[]
|
|
228
229
|
kind: i32 = 0
|
|
229
230
|
retried: boolean = false
|
|
230
|
-
room: i32 = 0
|
|
231
|
+
private room: i32 = 0
|
|
231
232
|
|
|
233
|
+
/**
|
|
234
|
+
* An empty answer with room for a reply of `room` bytes.
|
|
235
|
+
*
|
|
236
|
+
* @param room The bytes reserved for `reply`, usually `QUIC_LISTENER_ANSWER_SIZE`; 0 or less reserves
|
|
237
|
+
* none. `originalDcid` and `retryScid` get room for `QUIC_MAX_CID_LENGTH` (20) bytes each whatever it
|
|
238
|
+
* is. That is capacity: all three start empty, their lengths 0 until an answer or `wipe` sets them.
|
|
239
|
+
*/
|
|
232
240
|
constructor(room: i32) {
|
|
233
241
|
this.room = room > 0 ? room : 0
|
|
234
242
|
this.reply = quicListenerRoom(this.room)
|
|
@@ -242,7 +250,8 @@ export class QuicListenerAnswer {
|
|
|
242
250
|
* leave no copy beyond the arrays' lengths either. Each is left that long
|
|
243
251
|
* and all zero, `kind` a drop. An answer whose reply grew past its room
|
|
244
252
|
* keeps what lies beyond the longest length it is wiped at; one made with
|
|
245
|
-
* `QUIC_LISTENER_ANSWER_SIZE` never grows.
|
|
253
|
+
* `QUIC_LISTENER_ANSWER_SIZE` never grows. The caller's to call once it
|
|
254
|
+
* has sent the answer `QuicListener.handle` gave, and before it drops it.
|
|
246
255
|
*/
|
|
247
256
|
wipe(): void {
|
|
248
257
|
quicListenerWipeRoom(this.reply, this.room)
|
|
@@ -332,49 +341,58 @@ const quicListenerWindowFits = (length: i32, at: i32, len: i32): boolean =>
|
|
|
332
341
|
* `handleWindow` reads the datagram where it lies and keeps nothing.
|
|
333
342
|
*/
|
|
334
343
|
export class QuicListener {
|
|
335
|
-
config: QuicServerConfig
|
|
344
|
+
private config: QuicServerConfig
|
|
336
345
|
seed: u8[]
|
|
337
346
|
/** Unpredictable bytes not yet used, from `poolHead`, and the counter the next block is made from. */
|
|
338
347
|
pool: u8[]
|
|
339
348
|
/** The counter's eight bytes, the generator's HMAC message. */
|
|
340
|
-
block: u8[]
|
|
349
|
+
private block: u8[]
|
|
341
350
|
/** What `handleWindow` parses a datagram's header into, in place. */
|
|
342
|
-
header: QuicHeader
|
|
351
|
+
private header: QuicHeader
|
|
343
352
|
/** Every HMAC and HKDF the listener computes runs here; its `sha256` makes tokens, resets and the generator's blocks. */
|
|
344
353
|
kdf: HkdfScratch
|
|
345
354
|
/** A full HMAC-SHA256 tag, wiped once its 16 bytes are used. */
|
|
346
355
|
tag: u8[]
|
|
347
356
|
/** A Retry token MAC's length fields: the Retry SCID's one byte, the address's four. */
|
|
348
|
-
lengths: u8[]
|
|
357
|
+
private lengths: u8[]
|
|
349
358
|
/** The Initial secrets of an INVALID_TOKEN close, and its keys, both directions. */
|
|
350
359
|
initialClient: u8[]
|
|
351
360
|
initialServer: u8[]
|
|
352
361
|
readSlot: QuicKeysSlot
|
|
353
362
|
writeSlot: QuicKeysSlot
|
|
354
|
-
packet: QuicPacket
|
|
363
|
+
private packet: QuicPacket
|
|
355
364
|
/** The client's SCID and the DCID it sent to, copied out for `quicPutLongHeader`, which reads IDs from 0. */
|
|
356
|
-
peerCid: u8[]
|
|
357
|
-
ownCid: u8[]
|
|
365
|
+
private peerCid: u8[]
|
|
366
|
+
private ownCid: u8[]
|
|
358
367
|
/** An empty array: the INVALID_TOKEN close's token and reason. */
|
|
359
|
-
none: u8[]
|
|
368
|
+
private none: u8[]
|
|
360
369
|
/** Version 1's fixed Retry key (RFC 9001 §5.8), expanded once. */
|
|
361
|
-
retryKey: AesKey
|
|
370
|
+
private retryKey: AesKey
|
|
362
371
|
/** What `handle` answers into before it copies the answer out. */
|
|
363
372
|
spare: QuicListenerAnswer
|
|
364
|
-
counter: i64 = 0
|
|
373
|
+
private counter: i64 = 0
|
|
365
374
|
/** The latest time the caller gave, in milliseconds; time never runs backwards here. */
|
|
366
|
-
now: i64 = 0
|
|
375
|
+
private now: i64 = 0
|
|
367
376
|
/** When the reset budget was last topped up (-1: never yet), and the stateless resets that may go now. */
|
|
368
|
-
resetRefilled: i64 = -1
|
|
369
|
-
resetBudget: i32 = 0
|
|
377
|
+
private resetRefilled: i64 = -1
|
|
378
|
+
private resetBudget: i32 = 0
|
|
370
379
|
poolHead: i32 = 0
|
|
371
380
|
/** Stateless resets sent, and ones the rate limit held back. */
|
|
372
381
|
resetsSent: i32 = 0
|
|
373
382
|
resetsLimited: i32 = 0
|
|
374
383
|
/** Whether the configuration and entropy were usable. */
|
|
375
|
-
usable: boolean = false
|
|
384
|
+
private usable: boolean = false
|
|
376
385
|
|
|
377
|
-
/**
|
|
386
|
+
/**
|
|
387
|
+
* A listener under `config`; `entropy`'s `QUIC_LISTENER_ENTROPY_SIZE` bytes are copied, then wiped in
|
|
388
|
+
* the caller's array.
|
|
389
|
+
*
|
|
390
|
+
* @param config The server's configuration, kept by reference: its static keys and Retry token lifetime.
|
|
391
|
+
* Keys of the wrong size, or a lifetime outside 1 to `QUIC_LISTENER_MAX_TOKEN_LIFETIME` ms, make a
|
|
392
|
+
* listener that drops every datagram.
|
|
393
|
+
* @param entropy `QUIC_LISTENER_ENTROPY_SIZE` (32) random bytes, the seed of every unpredictable byte
|
|
394
|
+
* the listener sends. Zeroed on return; any other length makes a listener that drops every datagram.
|
|
395
|
+
*/
|
|
378
396
|
constructor(config: QuicServerConfig, entropy: u8[]) {
|
|
379
397
|
this.config = config
|
|
380
398
|
this.seed = new Array<u8>(QUIC_LISTENER_ENTROPY_SIZE)
|
|
@@ -434,7 +452,7 @@ export class QuicListener {
|
|
|
434
452
|
* One unpredictable value in 0 to 255: the next byte of HMAC-SHA256 under
|
|
435
453
|
* the seed of a counter, a block at a time, each byte wiped once taken.
|
|
436
454
|
*/
|
|
437
|
-
randomByte(): i32 {
|
|
455
|
+
private randomByte(): i32 {
|
|
438
456
|
if (this.poolHead >= QUIC_LISTENER_POOL) {
|
|
439
457
|
this.refill()
|
|
440
458
|
}
|
|
@@ -448,7 +466,7 @@ export class QuicListener {
|
|
|
448
466
|
}
|
|
449
467
|
|
|
450
468
|
/** Writes `count` unpredictable bytes into `out` at `at`. */
|
|
451
|
-
randomInto(out: u8[], at: i32, count: i32): void {
|
|
469
|
+
private randomInto(out: u8[], at: i32, count: i32): void {
|
|
452
470
|
for (let k: i32 = 0; k < count; k += 1) {
|
|
453
471
|
const b: i32 = this.randomByte()
|
|
454
472
|
if (at + k >= 0 && at + k < toI32(out.length)) {
|
|
@@ -458,7 +476,7 @@ export class QuicListener {
|
|
|
458
476
|
}
|
|
459
477
|
|
|
460
478
|
/** The generator's next block, HMAC-SHA256 under the seed of the counter, into `pool`. */
|
|
461
|
-
refill(): void {
|
|
479
|
+
private refill(): void {
|
|
462
480
|
quicListenerPutNumber(this.block, 0, this.counter, QUIC_LISTENER_BLOCK)
|
|
463
481
|
this.counter = this.counter + 1
|
|
464
482
|
const mac: HmacSha256Scratch = this.kdf.sha256
|
|
@@ -481,6 +499,16 @@ export class QuicListener {
|
|
|
481
499
|
* the module header for the rules; nothing a peer sends makes it panic,
|
|
482
500
|
* and nothing it does keeps arena memory. A window outside `datagram` is
|
|
483
501
|
* the caller's mistake, and panics.
|
|
502
|
+
*
|
|
503
|
+
* @param datagram The array the datagram lies in; read, not kept.
|
|
504
|
+
* @param at The index in `datagram` of its first byte.
|
|
505
|
+
* @param len The datagram's length in bytes.
|
|
506
|
+
* @param address The client's address and port, as bytes; bound into a Retry token.
|
|
507
|
+
* @param now The caller's monotonic time in milliseconds; an earlier time than the last is taken as the
|
|
508
|
+
* last.
|
|
509
|
+
* @param answer Where the answer goes, overwritten each call and owned by the caller.
|
|
510
|
+
* @returns `answer.kind`: `QUIC_LISTEN_DROP`, `QUIC_LISTEN_ACCEPT`, `QUIC_LISTEN_VERSION_NEGOTIATION`,
|
|
511
|
+
* `QUIC_LISTEN_RETRY`, `QUIC_LISTEN_INVALID_TOKEN` or `QUIC_LISTEN_STATELESS_RESET`.
|
|
484
512
|
*/
|
|
485
513
|
handleWindow(datagram: u8[], at: i32, len: i32, address: u8[], now: i64, answer: QuicListenerAnswer): i32 {
|
|
486
514
|
if (!quicListenerWindowFits(toI32(datagram.length), at, len)) {
|
|
@@ -551,6 +579,11 @@ export class QuicListener {
|
|
|
551
579
|
* made with exactly the room its reply takes: for a caller that keeps each
|
|
552
580
|
* answer, at the cost of one `QuicListenerAnswer` a datagram. A carrier
|
|
553
581
|
* makes one answer and calls `handleWindow`.
|
|
582
|
+
*
|
|
583
|
+
* @param datagram The whole datagram; read, not kept.
|
|
584
|
+
* @param address The client's address and port, as bytes.
|
|
585
|
+
* @param now The caller's monotonic time in milliseconds.
|
|
586
|
+
* @returns A new answer, the caller's to keep and, once done with, to wipe.
|
|
554
587
|
*/
|
|
555
588
|
handle(datagram: u8[], address: u8[], now: i64): QuicListenerAnswer {
|
|
556
589
|
const spare: QuicListenerAnswer = this.spare
|
|
@@ -580,7 +613,7 @@ export class QuicListener {
|
|
|
580
613
|
* TODO(WP34 Q1): every other packet format is `nish/net/quic-packet`'s; this
|
|
581
614
|
* belongs beside `quicRetryPacket` there, which this stage may not edit.
|
|
582
615
|
*/
|
|
583
|
-
versionNegotiation(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
|
|
616
|
+
private versionNegotiation(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
|
|
584
617
|
const unused: i32 = this.randomByte()
|
|
585
618
|
const dcidLength: i32 = header.dcidLength
|
|
586
619
|
const scidLength: i32 = header.scidLength
|
|
@@ -605,7 +638,7 @@ export class QuicListener {
|
|
|
605
638
|
* first `QUIC_LISTENER_TOKEN_MAC_SIZE` bytes are the token's MAC; the
|
|
606
639
|
* caller wipes `tag` once it has used them.
|
|
607
640
|
*/
|
|
608
|
-
tokenMac(
|
|
641
|
+
private tokenMac(
|
|
609
642
|
head: u8[],
|
|
610
643
|
headAt: i32,
|
|
611
644
|
headLength: i32,
|
|
@@ -640,7 +673,7 @@ export class QuicListener {
|
|
|
640
673
|
* (compared in constant time), and it was issued no later than now and
|
|
641
674
|
* less than `retryTokenLifetime` ago. The token is read in `datagram`.
|
|
642
675
|
*/
|
|
643
|
-
tokenValid(datagram: u8[], header: QuicHeader, address: u8[]): boolean {
|
|
676
|
+
private tokenValid(datagram: u8[], header: QuicHeader, address: u8[]): boolean {
|
|
644
677
|
const tokenAt: i32 = header.tokenStart
|
|
645
678
|
const length: i32 = header.tokenLength
|
|
646
679
|
if (length < QUIC_LISTENER_TOKEN_HEAD + QUIC_LISTENER_TOKEN_MAC_SIZE) {
|
|
@@ -677,7 +710,7 @@ export class QuicListener {
|
|
|
677
710
|
* marker byte, the time, the DCID, then the MAC — under the integrity tag
|
|
678
711
|
* of RFC 9001 §5.8. Each part is written where it goes in `reply`.
|
|
679
712
|
*/
|
|
680
|
-
retry(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader, address: u8[]): void {
|
|
713
|
+
private retry(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader, address: u8[]): void {
|
|
681
714
|
const scidLength: i32 = header.scidLength
|
|
682
715
|
const odcidLength: i32 = header.dcidLength
|
|
683
716
|
const retryScidAt: i32 = 7 + scidLength
|
|
@@ -714,7 +747,7 @@ export class QuicListener {
|
|
|
714
747
|
* pseudo-packet and the AEAD's temporaries go with the arena block.
|
|
715
748
|
* Answers whether it was made.
|
|
716
749
|
*/
|
|
717
|
-
retryTag(reply: u8[], tagAt: i32, datagram: u8[], odcidAt: i32, odcidLength: i32): boolean {
|
|
750
|
+
private retryTag(reply: u8[], tagAt: i32, datagram: u8[], odcidAt: i32, odcidLength: i32): boolean {
|
|
718
751
|
using _scope = arena()
|
|
719
752
|
const pseudo: u8[] = new Array<u8>(1 + odcidLength + tagAt)
|
|
720
753
|
quicListenerPutNumber(pseudo, 0, toI64(odcidLength), 1)
|
|
@@ -739,7 +772,7 @@ export class QuicListener {
|
|
|
739
772
|
* own slots, the Initial is opened in an arena block, and the close is
|
|
740
773
|
* written and sealed in `reply`.
|
|
741
774
|
*/
|
|
742
|
-
invalidToken(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
|
|
775
|
+
private invalidToken(answer: QuicListenerAnswer, datagram: u8[], header: QuicHeader): void {
|
|
743
776
|
const secrets: boolean = quicInitialSecretsInto(
|
|
744
777
|
this.kdf,
|
|
745
778
|
datagram,
|
|
@@ -815,7 +848,7 @@ export class QuicListener {
|
|
|
815
848
|
}
|
|
816
849
|
|
|
817
850
|
/** Whether the Initial `header` read in `datagram` opens under `read`; what opening it allocates goes with the arena block. */
|
|
818
|
-
opens(read: QuicKeys, datagram: u8[], header: QuicHeader): boolean {
|
|
851
|
+
private opens(read: QuicKeys, datagram: u8[], header: QuicHeader): boolean {
|
|
819
852
|
using _scope = arena()
|
|
820
853
|
const packet: QuicPacket = this.packet
|
|
821
854
|
const clear: u8[] = quicUnprotectHeader(read, datagram, header, -1, packet)
|
|
@@ -824,7 +857,7 @@ export class QuicListener {
|
|
|
824
857
|
}
|
|
825
858
|
|
|
826
859
|
/** Takes one stateless reset from the rate limit's budget, topping it up first. Answers whether one was there. */
|
|
827
|
-
takeReset(): boolean {
|
|
860
|
+
private takeReset(): boolean {
|
|
828
861
|
if (this.resetRefilled < 0) {
|
|
829
862
|
this.resetRefilled = this.now
|
|
830
863
|
this.resetBudget = QUIC_LISTENER_RESET_BURST
|
|
@@ -854,7 +887,13 @@ export class QuicListener {
|
|
|
854
887
|
* shorter; a datagram too short for that to leave 21 bytes, or one past
|
|
855
888
|
* the rate limit, gets nothing.
|
|
856
889
|
*/
|
|
857
|
-
statelessReset(
|
|
890
|
+
private statelessReset(
|
|
891
|
+
answer: QuicListenerAnswer,
|
|
892
|
+
n: i32,
|
|
893
|
+
datagram: u8[],
|
|
894
|
+
dcidAt: i32,
|
|
895
|
+
dcidLength: i32
|
|
896
|
+
): void {
|
|
858
897
|
if (n <= QUIC_LISTENER_MIN_RESET || !this.takeReset()) {
|
|
859
898
|
return
|
|
860
899
|
}
|
|
@@ -889,6 +928,10 @@ export class QuicListener {
|
|
|
889
928
|
* but only when the connection's pacer has the credit for a full datagram
|
|
890
929
|
* (RFC 9002 §7.7); `null` when it has not, or when nothing is due. The
|
|
891
930
|
* datagram is charged to the pacer at its real size.
|
|
931
|
+
*
|
|
932
|
+
* @param conn The connection to send for.
|
|
933
|
+
* @param now The caller's time in milliseconds.
|
|
934
|
+
* @returns A new datagram to send, the caller's; or `null` when the pacer holds it back or nothing is due.
|
|
892
935
|
*/
|
|
893
936
|
export const quicListenerTakePaced = (conn: QuicConnection, now: i64): u8[] | null => {
|
|
894
937
|
if (conn.recovery.pacerDelay(now, QUIC_CONN_DATAGRAM_SIZE) > 0) {
|
|
@@ -904,6 +947,10 @@ export const quicListenerTakePaced = (conn: QuicConnection, now: i64): u8[] | nu
|
|
|
904
947
|
/**
|
|
905
948
|
* When `quicListenerTakePaced` next lets `conn` send a full datagram, in the
|
|
906
949
|
* caller's milliseconds: `now` when it may already.
|
|
950
|
+
*
|
|
951
|
+
* @param conn The connection to ask about.
|
|
952
|
+
* @param now The caller's time in milliseconds.
|
|
953
|
+
* @returns A time in milliseconds, `now` or later. It says nothing of whether a datagram is due.
|
|
907
954
|
*/
|
|
908
955
|
export const quicListenerPaceTime = (conn: QuicConnection, now: i64): i64 =>
|
|
909
956
|
now + conn.recovery.pacerDelay(now, QUIC_CONN_DATAGRAM_SIZE)
|
|
@@ -922,6 +969,10 @@ const quicListenerQuantum = (conn: QuicConnection): i32 =>
|
|
|
922
969
|
/**
|
|
923
970
|
* When `quicListenerTakeFlight` next lets `conn` start a flight, in the
|
|
924
971
|
* caller's milliseconds: `now` when it may already.
|
|
972
|
+
*
|
|
973
|
+
* @param conn The connection to ask about.
|
|
974
|
+
* @param now The caller's time in milliseconds.
|
|
975
|
+
* @returns A time in milliseconds, `now` or later. It says nothing of whether a datagram is due.
|
|
925
976
|
*/
|
|
926
977
|
export const quicListenerFlightTime = (conn: QuicConnection, now: i64): i64 =>
|
|
927
978
|
now + conn.recovery.pacerDelay(now, quicListenerQuantum(conn))
|
|
@@ -952,6 +1003,15 @@ export class QuicFlight {
|
|
|
952
1003
|
* `QUIC_CONN_DATAGRAM_SIZE`, which can only be the last of a segmented send,
|
|
953
1004
|
* at `QUIC_LISTENER_FLIGHT_MAX` datagrams, when `cap` has no room for
|
|
954
1005
|
* another, and before a datagram whose ECN codepoint would not be the first's.
|
|
1006
|
+
*
|
|
1007
|
+
* @param conn The connection to send for.
|
|
1008
|
+
* @param now The caller's time in milliseconds.
|
|
1009
|
+
* @param buf Where the flight is written.
|
|
1010
|
+
* @param at The index in `buf` of the flight's first byte.
|
|
1011
|
+
* @param cap The bytes of `buf` from `at` the flight may use; under `QUIC_CONN_DATAGRAM_SIZE` sends nothing.
|
|
1012
|
+
* @param flight Overwritten with the flight's datagram count, segment size and ECN codepoint; all 0
|
|
1013
|
+
* when nothing was written.
|
|
1014
|
+
* @returns The flight's length in bytes, or 0 when the pacer holds it back or nothing is due.
|
|
955
1015
|
*/
|
|
956
1016
|
export const quicListenerTakeFlight = (
|
|
957
1017
|
conn: QuicConnection,
|
|
@@ -1001,6 +1061,15 @@ export const quicListenerTakeFlight = (
|
|
|
1001
1061
|
* `now`: one datagram when `segment` is 0, else a GRO receive cut every
|
|
1002
1062
|
* `segment` bytes (the last may be shorter). Each is read in place. Answers
|
|
1003
1063
|
* how many it handed over.
|
|
1064
|
+
*
|
|
1065
|
+
* @param conn The connection the datagrams belong to.
|
|
1066
|
+
* @param buf The receive buffer; read, not kept.
|
|
1067
|
+
* @param off The index in `buf` of the first byte received.
|
|
1068
|
+
* @param len The bytes received.
|
|
1069
|
+
* @param segment The GRO segment size in bytes, or 0 (or less) for a single datagram.
|
|
1070
|
+
* @param now The caller's time in milliseconds.
|
|
1071
|
+
* @returns How many datagrams were handed over: always 1 when `segment` is 0 or less, whatever `len`;
|
|
1072
|
+
* otherwise one per `segment` bytes of `len`, rounded up, which is 0 when `len` is 0 or less.
|
|
1004
1073
|
*/
|
|
1005
1074
|
export const quicListenerReceiveSegments = (
|
|
1006
1075
|
conn: QuicConnection,
|