@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.ts
CHANGED
|
@@ -7,11 +7,15 @@
|
|
|
7
7
|
* Sans-IO, like the rest of `nish/net`.
|
|
8
8
|
*
|
|
9
9
|
* import { QuicConnection, QuicServerConfig } from "nish/net/quic";
|
|
10
|
+
* import { tlsSignEcdsaP256 } from "nish/net/tls";
|
|
10
11
|
*
|
|
11
12
|
* const conn = new QuicConnection(config, entropy); // entropy: QUIC_CONN_ENTROPY_SIZE random bytes
|
|
12
13
|
* conn.receiveWindow(buf, off, len, now); // every datagram the client sends; now in ms
|
|
13
14
|
* const input: u8[] | null = conn.signatureInput();
|
|
14
|
-
* if (input !== null) {
|
|
15
|
+
* if (input !== null) {
|
|
16
|
+
* const signature: u8[] | null = tlsSignEcdsaP256(key, input); // key: Secret<u8[]>
|
|
17
|
+
* if (signature !== null) { conn.sign(signature); }
|
|
18
|
+
* }
|
|
15
19
|
* let n: i32 = conn.takeDatagramInto(out, 0, now); // out: at least QUIC_CONN_DATAGRAM_SIZE bytes
|
|
16
20
|
* while (n > 0) { … send out[0 .. n) to the client … ; n = conn.takeDatagramInto(out, 0, now); }
|
|
17
21
|
* let id: i64 = conn.nextStreamEvent(); // a stream with news: read it, write it
|
|
@@ -30,7 +34,7 @@
|
|
|
30
34
|
* client's are parsed and checked (RFC 9000 §7.3, §7.4) before the server's
|
|
31
35
|
* flight leaves.
|
|
32
36
|
*
|
|
33
|
-
* **Streams
|
|
37
|
+
* **Streams.** They are `nish/net/quic-stream`'s: both kinds, opened by either
|
|
34
38
|
* side, with flow control per stream and for the connection raised as the
|
|
35
39
|
* application reads, and the stream limits raised as streams finish. The
|
|
36
40
|
* application sees them through a small surface: `nextStreamEvent` names a
|
|
@@ -48,7 +52,7 @@
|
|
|
48
52
|
* congestion window, and is never sent again. `readDatagram` hands out what
|
|
49
53
|
* arrived. Each way is a fixed ring (`nish/net/quic-datagram`).
|
|
50
54
|
*
|
|
51
|
-
* **Loss recovery** (RFC 9002) is `nish/net/quic-recovery`'s: every
|
|
55
|
+
* **Loss recovery** (RFC 9002). It is `nish/net/quic-recovery`'s: every
|
|
52
56
|
* ack-eliciting packet is recorded in its space's ring with what it carried
|
|
53
57
|
* (its CRYPTO range, its STREAM chunks, HANDSHAKE_DONE and the control
|
|
54
58
|
* frames), the client's ACKs give the RTT estimate and show what was lost by
|
|
@@ -419,6 +423,11 @@ export const QUIC_CONN_CONFIDENTIALITY_LIMIT: i64 = 8388608
|
|
|
419
423
|
* with AEAD_LIMIT_REACHED. AES-GCM's is 2^52, ChaCha20-Poly1305's 2^36.
|
|
420
424
|
*/
|
|
421
425
|
export const QUIC_CONN_INTEGRITY_LIMIT_GCM: i64 = 4503599627370496
|
|
426
|
+
/**
|
|
427
|
+
* ChaCha20-Poly1305's integrity limit (RFC 9001 §6.6), 2^36 packets that fail
|
|
428
|
+
* to authenticate over a connection, across every key, before it closes with
|
|
429
|
+
* AEAD_LIMIT_REACHED. The connection counts failures against the limit of the AEAD it negotiated.
|
|
430
|
+
*/
|
|
422
431
|
export const QUIC_CONN_INTEGRITY_LIMIT_CHACHA: i64 = 68719476736
|
|
423
432
|
/**
|
|
424
433
|
* How many skipped packet numbers the server remembers (RFC 9000 §21.4): an
|
|
@@ -428,7 +437,17 @@ export const QUIC_CONN_INTEGRITY_LIMIT_CHACHA: i64 = 68719476736
|
|
|
428
437
|
* reaches back at least 7 × 129 = 903 packets.
|
|
429
438
|
*/
|
|
430
439
|
export const QUIC_CONN_SKIP_RING: i32 = 8
|
|
440
|
+
/**
|
|
441
|
+
* The fewest Application Data packets between two skipped packet numbers
|
|
442
|
+
* (RFC 9000 §21.4). Large enough that the gaps cost the client almost
|
|
443
|
+
* nothing in ACK ranges.
|
|
444
|
+
*/
|
|
431
445
|
export const QUIC_CONN_SKIP_MIN: i64 = 128
|
|
446
|
+
/**
|
|
447
|
+
* How many distances past `QUIC_CONN_SKIP_MIN` a skip may fall at: the next
|
|
448
|
+
* skipped number is `QUIC_CONN_SKIP_MIN` plus 0 to 896 past the number after
|
|
449
|
+
* the last skip, so skips fall 129 to 1025 numbers apart.
|
|
450
|
+
*/
|
|
432
451
|
export const QUIC_CONN_SKIP_SPREAD: i64 = 897
|
|
433
452
|
/**
|
|
434
453
|
* The HMAC counter the skip distances are drawn under, past any connection
|
|
@@ -604,6 +623,14 @@ export class QuicStreamData {
|
|
|
604
623
|
data: u8[]
|
|
605
624
|
fin: boolean = false
|
|
606
625
|
|
|
626
|
+
/**
|
|
627
|
+
* A run as `readStream` hands it out.
|
|
628
|
+
*
|
|
629
|
+
* @param streamId The RFC 9000 stream ID the bytes arrived on.
|
|
630
|
+
* @param data The bytes, in stream order; the run owns this array, so the caller may keep it. Empty
|
|
631
|
+
* for a run that only carries the FIN.
|
|
632
|
+
* @param fin True when the run ends at the stream's FIN, so nothing more follows on `streamId`.
|
|
633
|
+
*/
|
|
607
634
|
constructor(streamId: i64, data: u8[], fin: boolean) {
|
|
608
635
|
this.streamId = streamId
|
|
609
636
|
this.data = data
|
|
@@ -620,11 +647,22 @@ export class QuicStreamData {
|
|
|
620
647
|
* before the Handshake one starts.
|
|
621
648
|
*/
|
|
622
649
|
class QuicConnReassembly {
|
|
650
|
+
/** @internal Read in quic.ts outside the class. */
|
|
623
651
|
ring: u8[]
|
|
652
|
+
/**
|
|
653
|
+
* @internal Only its own class reads it; kept public with `ring`, its family, read in quic.ts outside
|
|
654
|
+
* the class.
|
|
655
|
+
*/
|
|
624
656
|
have: u8[]
|
|
625
|
-
/**
|
|
657
|
+
/**
|
|
658
|
+
* The level whose bytes the ring holds.
|
|
659
|
+
* @internal Read in quic.ts outside the class.
|
|
660
|
+
*/
|
|
626
661
|
level: i32 = 0
|
|
627
|
-
/**
|
|
662
|
+
/**
|
|
663
|
+
* How many bytes of the level have been handed to TLS.
|
|
664
|
+
* @internal Read in quic.ts outside the class.
|
|
665
|
+
*/
|
|
628
666
|
delivered: i64 = 0
|
|
629
667
|
|
|
630
668
|
constructor(capacity: i32) {
|
|
@@ -632,26 +670,32 @@ class QuicConnReassembly {
|
|
|
632
670
|
this.have = new Array<u8>((capacity + 7) >> 3)
|
|
633
671
|
}
|
|
634
672
|
|
|
635
|
-
/**
|
|
673
|
+
/**
|
|
674
|
+
* Empties the ring for level `level`.
|
|
675
|
+
* @internal Read in quic.ts outside the class.
|
|
676
|
+
*/
|
|
636
677
|
reset(level: i32): void {
|
|
637
678
|
this.level = level
|
|
638
679
|
this.delivered = 0
|
|
639
680
|
this.have.fill(toU8(0))
|
|
640
681
|
}
|
|
641
682
|
|
|
642
|
-
/**
|
|
683
|
+
/**
|
|
684
|
+
* The ring slot of stream offset `offset`.
|
|
685
|
+
* @internal Read in quic.ts outside the class.
|
|
686
|
+
*/
|
|
643
687
|
slot(offset: i64): i32 {
|
|
644
688
|
const capacity: i32 = toI32(this.ring.length)
|
|
645
689
|
return capacity > 0 ? toI32(offset % toI64(capacity)) : 0
|
|
646
690
|
}
|
|
647
691
|
|
|
648
692
|
/** Whether the byte in ring slot `s` arrived and is not yet handed out. */
|
|
649
|
-
arrived(s: i32): boolean {
|
|
693
|
+
private arrived(s: i32): boolean {
|
|
650
694
|
return quicStreamBit(this.have, s)
|
|
651
695
|
}
|
|
652
696
|
|
|
653
697
|
/** Marks ring slot `s` as holding a byte, or not. */
|
|
654
|
-
mark(s: i32, on: boolean): void {
|
|
698
|
+
private mark(s: i32, on: boolean): void {
|
|
655
699
|
quicStreamSetBit(this.have, s, on)
|
|
656
700
|
}
|
|
657
701
|
|
|
@@ -659,6 +703,7 @@ class QuicConnReassembly {
|
|
|
659
703
|
* Takes `data[from .. from + length)`, which sits at stream offset
|
|
660
704
|
* `offset`. Answers `false`, taking nothing, when it reaches `capacity` or
|
|
661
705
|
* more past what was delivered. Bytes already delivered are skipped.
|
|
706
|
+
* @internal Read in quic.ts outside the class.
|
|
662
707
|
*/
|
|
663
708
|
insert(offset: i64, data: u8[], from: i32, length: i32): boolean {
|
|
664
709
|
const capacity: i32 = toI32(this.ring.length)
|
|
@@ -679,7 +724,10 @@ class QuicConnReassembly {
|
|
|
679
724
|
return true
|
|
680
725
|
}
|
|
681
726
|
|
|
682
|
-
/**
|
|
727
|
+
/**
|
|
728
|
+
* How many bytes from `delivered` have arrived without a gap, up to the end of the ring's array.
|
|
729
|
+
* @internal Read in quic.ts outside the class.
|
|
730
|
+
*/
|
|
683
731
|
run(): i32 {
|
|
684
732
|
const capacity: i32 = toI32(this.ring.length)
|
|
685
733
|
const start: i32 = this.slot(this.delivered)
|
|
@@ -690,7 +738,10 @@ class QuicConnReassembly {
|
|
|
690
738
|
return n
|
|
691
739
|
}
|
|
692
740
|
|
|
693
|
-
/**
|
|
741
|
+
/**
|
|
742
|
+
* Hands out the `n` bytes `run` counted: their bits cleared, `delivered` moved past them.
|
|
743
|
+
* @internal Read in quic.ts outside the class.
|
|
744
|
+
*/
|
|
694
745
|
consume(n: i32): void {
|
|
695
746
|
const start: i32 = this.slot(this.delivered)
|
|
696
747
|
for (let k: i32 = 0; k < n; k += 1) {
|
|
@@ -718,6 +769,7 @@ class QuicConnSpace {
|
|
|
718
769
|
nextPn: i64 = 0
|
|
719
770
|
/** The largest packet number the client acknowledged here, or -1. */
|
|
720
771
|
largestAcked: i64 = -1
|
|
772
|
+
/** @internal Read in quic.ts outside the class. */
|
|
721
773
|
received: QuicAckRanges
|
|
722
774
|
/**
|
|
723
775
|
* Every CRYPTO byte TLS wrote at this level, from stream offset 0, its
|
|
@@ -725,8 +777,10 @@ class QuicConnSpace {
|
|
|
725
777
|
* a lost range can be sent again; the array is reused by the next
|
|
726
778
|
* connection in the slot. The bytes from `cryptoOutHead` (offset
|
|
727
779
|
* `cryptoOutOffset`) are not sent yet.
|
|
780
|
+
* @internal Read in quic.ts outside the class.
|
|
728
781
|
*/
|
|
729
782
|
cryptoOut: u8[]
|
|
783
|
+
/** @internal Read in quic.ts outside the class. */
|
|
730
784
|
cryptoOutLength: i32 = 0
|
|
731
785
|
/**
|
|
732
786
|
* How many ack-eliciting probe packets this space still owes, which the
|
|
@@ -734,25 +788,47 @@ class QuicConnSpace {
|
|
|
734
788
|
* §6.2.4), or an early resend (§6.2.3).
|
|
735
789
|
*/
|
|
736
790
|
probes: i32 = 0
|
|
791
|
+
/** @internal Read in quic.ts outside the class. */
|
|
737
792
|
cryptoOutOffset: i64 = 0
|
|
738
|
-
/**
|
|
793
|
+
/**
|
|
794
|
+
* How many CRYPTO bytes the client sent here that were handed to TLS, for a duplicate arriving after the next level started.
|
|
795
|
+
* @internal Read in quic.ts outside the class.
|
|
796
|
+
*/
|
|
739
797
|
cryptoInDelivered: i64 = 0
|
|
740
|
-
/**
|
|
798
|
+
/**
|
|
799
|
+
* CRYPTO bytes declared lost, to send before new ones: `[cryptoResendLow, cryptoResendHigh)`, or -1.
|
|
800
|
+
* @internal Read in quic.ts outside the class.
|
|
801
|
+
*/
|
|
741
802
|
cryptoResendLow: i64 = -1
|
|
803
|
+
/** @internal Read in quic.ts outside the class. */
|
|
742
804
|
cryptoResendHigh: i64 = -1
|
|
743
805
|
/** Each packet's CRYPTO frame (offset, and length 0 for none), and its `QUIC_CONN_SENT_*` bits. */
|
|
744
|
-
sentCryptoOffset: i64[]
|
|
745
|
-
sentCryptoLength: i32[]
|
|
746
|
-
sentFlags: u8[]
|
|
747
|
-
/**
|
|
806
|
+
private sentCryptoOffset: i64[]
|
|
807
|
+
private sentCryptoLength: i32[]
|
|
808
|
+
private sentFlags: u8[]
|
|
809
|
+
/**
|
|
810
|
+
* Each packet's STREAM chunks, `QUIC_CONN_PACKET_STREAMS` to a row: how many, then each one's stream, offset, length and FIN.
|
|
811
|
+
* @internal Only its own class reads it; kept public with `sentStreamId`, its family, read in quic.ts
|
|
812
|
+
* outside the class.
|
|
813
|
+
*/
|
|
748
814
|
sentStreamCount: i32[]
|
|
815
|
+
/** @internal Read in quic.ts outside the class. */
|
|
749
816
|
sentStreamId: i64[]
|
|
817
|
+
/** @internal Read in quic.ts outside the class. */
|
|
750
818
|
sentStreamOffset: i64[]
|
|
819
|
+
/** @internal Read in quic.ts outside the class. */
|
|
751
820
|
sentStreamLength: i32[]
|
|
821
|
+
/** @internal Read in quic.ts outside the class. */
|
|
752
822
|
sentStreamFin: u8[]
|
|
753
|
-
/**
|
|
823
|
+
/**
|
|
824
|
+
* Each packet's control frames, `QUIC_CONN_PACKET_CONTROL` to a row: their kind and value (a sequence number or a stream).
|
|
825
|
+
* @internal Only its own class reads it; kept public with `sentControlKind`, its family, read in quic.ts
|
|
826
|
+
* outside the class.
|
|
827
|
+
*/
|
|
754
828
|
sentControlCount: i32[]
|
|
829
|
+
/** @internal Read in quic.ts outside the class. */
|
|
755
830
|
sentControlKind: u8[]
|
|
831
|
+
/** @internal Read in quic.ts outside the class. */
|
|
756
832
|
sentControlValue: i64[]
|
|
757
833
|
/**
|
|
758
834
|
* Where this space's packet keys live, made once for the slot (QUIC-3):
|
|
@@ -760,17 +836,31 @@ class QuicConnSpace {
|
|
|
760
836
|
* second of each, which a key update derives the next generation into.
|
|
761
837
|
*/
|
|
762
838
|
keySlots: QuicKeysSlot[]
|
|
763
|
-
/**
|
|
839
|
+
/**
|
|
840
|
+
* `TLS_LEVEL_INITIAL`, `_HANDSHAKE` or `_APPLICATION`, which is also the space's index.
|
|
841
|
+
* @internal Read in quic.ts outside the class.
|
|
842
|
+
*/
|
|
764
843
|
level: i32 = 0
|
|
844
|
+
/** @internal Read in quic.ts outside the class. */
|
|
765
845
|
cryptoOutHead: i32 = 0
|
|
766
|
-
/**
|
|
846
|
+
/**
|
|
847
|
+
* The packet `buildDatagram` is putting together here: where it starts in the datagram, or -1 for none, and its payload's end.
|
|
848
|
+
* @internal Read in quic.ts outside the class.
|
|
849
|
+
*/
|
|
767
850
|
builtStart: i32 = -1
|
|
851
|
+
/** @internal Read in quic.ts outside the class. */
|
|
768
852
|
builtEnd: i32 = 0
|
|
769
|
-
/**
|
|
853
|
+
/**
|
|
854
|
+
* The row the packet being built is described in: one past the last slot.
|
|
855
|
+
* @internal Read in quic.ts outside the class.
|
|
856
|
+
*/
|
|
770
857
|
staging: i32 = 0
|
|
771
858
|
/** Whether the keys were discarded (RFC 9001 §4.9): nothing is sent or received here again. */
|
|
772
859
|
discarded: boolean = false
|
|
773
|
-
/**
|
|
860
|
+
/**
|
|
861
|
+
* Whether the packet being built elicits an acknowledgement, and so is recorded.
|
|
862
|
+
* @internal Read in quic.ts outside the class.
|
|
863
|
+
*/
|
|
774
864
|
stagedEliciting: boolean = false
|
|
775
865
|
|
|
776
866
|
constructor(level: i32) {
|
|
@@ -801,7 +891,10 @@ class QuicConnSpace {
|
|
|
801
891
|
this.sentControlValue = new Array<i64>(chunkRows * QUIC_CONN_PACKET_CONTROL)
|
|
802
892
|
}
|
|
803
893
|
|
|
804
|
-
/**
|
|
894
|
+
/**
|
|
895
|
+
* Puts the space back as a new connection has it, keeping its arrays, for a slot reused for another peer.
|
|
896
|
+
* @internal Read in quic.ts outside the class.
|
|
897
|
+
*/
|
|
805
898
|
reset(): void {
|
|
806
899
|
this.readKeys = null
|
|
807
900
|
this.writeKeys = null
|
|
@@ -823,6 +916,7 @@ class QuicConnSpace {
|
|
|
823
916
|
* Appends `bytes[0 .. length)` to the CRYPTO stream kept, writing into the
|
|
824
917
|
* array's old room before growing it: TLS's output buffer is read in
|
|
825
918
|
* place, so its flight is not copied on the way.
|
|
919
|
+
* @internal Read in quic.ts outside the class.
|
|
826
920
|
*/
|
|
827
921
|
appendCrypto(bytes: u8[], length: i32): void {
|
|
828
922
|
for (let k: i32 = 0; k < length && k < toI32(bytes.length); k += 1) {
|
|
@@ -840,45 +934,69 @@ class QuicConnSpace {
|
|
|
840
934
|
* Key slot `k` of this space: in the Initial and Handshake spaces 0 holds
|
|
841
935
|
* the read keys and 1 the write keys; in Application Data 0 and 1 hold
|
|
842
936
|
* the read keys' generations and 2 and 3 the write keys'.
|
|
937
|
+
*
|
|
938
|
+
* @param k The slot index, 0 to 1 in the Initial and Handshake spaces and 0 to 3 in Application Data.
|
|
939
|
+
* @returns The slot itself, borrowed from the space and reused across keys; slot 0 for a `k` out of range.
|
|
843
940
|
*/
|
|
844
941
|
keySlot(k: i32): QuicKeysSlot {
|
|
845
942
|
const at: i32 = k >= 0 && k < toI32(this.keySlots.length) ? k : 0
|
|
846
943
|
return this.keySlots[at]
|
|
847
944
|
}
|
|
848
945
|
|
|
849
|
-
/**
|
|
946
|
+
/**
|
|
947
|
+
* Zeroes every key this space's slots hold, the AES schedules included.
|
|
948
|
+
* @internal Read in quic.ts outside the class.
|
|
949
|
+
*/
|
|
850
950
|
wipeKeySlots(): void {
|
|
851
951
|
for (const slot of this.keySlots) {
|
|
852
952
|
slot.wipe()
|
|
853
953
|
}
|
|
854
954
|
}
|
|
855
955
|
|
|
856
|
-
/**
|
|
956
|
+
/**
|
|
957
|
+
* The number of STREAM chunks row `row` holds, or 0.
|
|
958
|
+
* @internal Read in quic.ts outside the class.
|
|
959
|
+
*/
|
|
857
960
|
streamCount(row: i32): i32 {
|
|
858
961
|
return row >= 0 && row < toI32(this.sentStreamCount.length) ? this.sentStreamCount[row] : 0
|
|
859
962
|
}
|
|
860
963
|
|
|
861
|
-
/**
|
|
964
|
+
/**
|
|
965
|
+
* The number of control frames row `row` holds, or 0.
|
|
966
|
+
* @internal Read in quic.ts outside the class.
|
|
967
|
+
*/
|
|
862
968
|
controlCount(row: i32): i32 {
|
|
863
969
|
return row >= 0 && row < toI32(this.sentControlCount.length) ? this.sentControlCount[row] : 0
|
|
864
970
|
}
|
|
865
971
|
|
|
866
|
-
/**
|
|
972
|
+
/**
|
|
973
|
+
* The CRYPTO frame's length in row `row`, or 0.
|
|
974
|
+
* @internal Read in quic.ts outside the class.
|
|
975
|
+
*/
|
|
867
976
|
cryptoLength(row: i32): i32 {
|
|
868
977
|
return row >= 0 && row < toI32(this.sentCryptoLength.length) ? this.sentCryptoLength[row] : 0
|
|
869
978
|
}
|
|
870
979
|
|
|
871
|
-
/**
|
|
980
|
+
/**
|
|
981
|
+
* The CRYPTO frame's offset in row `row`, or 0.
|
|
982
|
+
* @internal Read in quic.ts outside the class.
|
|
983
|
+
*/
|
|
872
984
|
cryptoOffset(row: i32): i64 {
|
|
873
985
|
return row >= 0 && row < toI32(this.sentCryptoOffset.length) ? this.sentCryptoOffset[row] : 0
|
|
874
986
|
}
|
|
875
987
|
|
|
876
|
-
/**
|
|
988
|
+
/**
|
|
989
|
+
* The `QUIC_CONN_SENT_*` bits of row `row`.
|
|
990
|
+
* @internal Read in quic.ts outside the class.
|
|
991
|
+
*/
|
|
877
992
|
flags(row: i32): i32 {
|
|
878
993
|
return row >= 0 && row < toI32(this.sentFlags.length) ? toI32(this.sentFlags[row]) : 0
|
|
879
994
|
}
|
|
880
995
|
|
|
881
|
-
/**
|
|
996
|
+
/**
|
|
997
|
+
* Empties the staging row, for the next packet.
|
|
998
|
+
* @internal Read in quic.ts outside the class.
|
|
999
|
+
*/
|
|
882
1000
|
clearStaged(): void {
|
|
883
1001
|
this.stagedEliciting = false
|
|
884
1002
|
this.setCrypto(this.staging, QUIC_CONN_NONE, QUIC_CONN_FROM)
|
|
@@ -887,14 +1005,17 @@ class QuicConnSpace {
|
|
|
887
1005
|
}
|
|
888
1006
|
|
|
889
1007
|
/** Sets row `row`'s CRYPTO frame. */
|
|
890
|
-
setCrypto(row: i32, offset: i64, length: i32): void {
|
|
1008
|
+
private setCrypto(row: i32, offset: i64, length: i32): void {
|
|
891
1009
|
if (row >= 0 && row < toI32(this.sentCryptoOffset.length) && row < toI32(this.sentCryptoLength.length)) {
|
|
892
1010
|
this.sentCryptoOffset[row] = offset
|
|
893
1011
|
this.sentCryptoLength[row] = length
|
|
894
1012
|
}
|
|
895
1013
|
}
|
|
896
1014
|
|
|
897
|
-
/**
|
|
1015
|
+
/**
|
|
1016
|
+
* Sets row `row`'s bits.
|
|
1017
|
+
* @internal Read in quic.ts outside the class.
|
|
1018
|
+
*/
|
|
898
1019
|
setFlags(row: i32, flags: i32): void {
|
|
899
1020
|
if (row >= 0 && row < toI32(this.sentFlags.length)) {
|
|
900
1021
|
this.sentFlags[row] = toU8(flags)
|
|
@@ -902,7 +1023,7 @@ class QuicConnSpace {
|
|
|
902
1023
|
}
|
|
903
1024
|
|
|
904
1025
|
/** Sets how many STREAM chunks and control frames row `row` holds. */
|
|
905
|
-
setCounts(row: i32, streams: i32, control: i32): void {
|
|
1026
|
+
private setCounts(row: i32, streams: i32, control: i32): void {
|
|
906
1027
|
if (row >= 0 && row < toI32(this.sentStreamCount.length) && row < toI32(this.sentControlCount.length)) {
|
|
907
1028
|
this.sentStreamCount[row] = streams
|
|
908
1029
|
this.sentControlCount[row] = control
|
|
@@ -910,7 +1031,7 @@ class QuicConnSpace {
|
|
|
910
1031
|
}
|
|
911
1032
|
|
|
912
1033
|
/** Sets STREAM chunk `j` of row `row`. */
|
|
913
|
-
setChunk(row: i32, j: i32, id: i64, offset: i64, length: i32, fin: boolean): void {
|
|
1034
|
+
private setChunk(row: i32, j: i32, id: i64, offset: i64, length: i32, fin: boolean): void {
|
|
914
1035
|
const at: i32 = row * QUIC_CONN_PACKET_STREAMS + j
|
|
915
1036
|
if (
|
|
916
1037
|
at >= 0 &&
|
|
@@ -927,7 +1048,7 @@ class QuicConnSpace {
|
|
|
927
1048
|
}
|
|
928
1049
|
|
|
929
1050
|
/** Sets control frame `j` of row `row`. */
|
|
930
|
-
setControl(row: i32, j: i32, kind: i32, value: i64): void {
|
|
1051
|
+
private setControl(row: i32, j: i32, kind: i32, value: i64): void {
|
|
931
1052
|
const at: i32 = row * QUIC_CONN_PACKET_CONTROL + j
|
|
932
1053
|
if (at >= 0 && at < toI32(this.sentControlKind.length) && at < toI32(this.sentControlValue.length)) {
|
|
933
1054
|
this.sentControlKind[at] = toU8(kind)
|
|
@@ -935,13 +1056,19 @@ class QuicConnSpace {
|
|
|
935
1056
|
}
|
|
936
1057
|
}
|
|
937
1058
|
|
|
938
|
-
/**
|
|
1059
|
+
/**
|
|
1060
|
+
* Stages a CRYPTO frame at `offset`, `length` bytes, in the packet being built.
|
|
1061
|
+
* @internal Read in quic.ts outside the class.
|
|
1062
|
+
*/
|
|
939
1063
|
stageCrypto(offset: i64, length: i32): void {
|
|
940
1064
|
this.setCrypto(this.staging, offset, length)
|
|
941
1065
|
this.stagedEliciting = true
|
|
942
1066
|
}
|
|
943
1067
|
|
|
944
|
-
/**
|
|
1068
|
+
/**
|
|
1069
|
+
* Stages a STREAM chunk in the packet being built; the caller keeps under `QUIC_CONN_PACKET_STREAMS`.
|
|
1070
|
+
* @internal Read in quic.ts outside the class.
|
|
1071
|
+
*/
|
|
945
1072
|
stageChunk(id: i64, offset: i64, length: i32, fin: boolean): void {
|
|
946
1073
|
const streams: i32 = this.streamCount(this.staging)
|
|
947
1074
|
this.setChunk(this.staging, streams, id, offset, length, fin)
|
|
@@ -949,7 +1076,10 @@ class QuicConnSpace {
|
|
|
949
1076
|
this.stagedEliciting = true
|
|
950
1077
|
}
|
|
951
1078
|
|
|
952
|
-
/**
|
|
1079
|
+
/**
|
|
1080
|
+
* Stages a control frame in the packet being built; the caller keeps under `QUIC_CONN_PACKET_CONTROL`.
|
|
1081
|
+
* @internal Read in quic.ts outside the class.
|
|
1082
|
+
*/
|
|
953
1083
|
stageControl(kind: i32, value: i64): void {
|
|
954
1084
|
const control: i32 = this.controlCount(this.staging)
|
|
955
1085
|
this.setControl(this.staging, control, kind, value)
|
|
@@ -957,7 +1087,10 @@ class QuicConnSpace {
|
|
|
957
1087
|
this.stagedEliciting = true
|
|
958
1088
|
}
|
|
959
1089
|
|
|
960
|
-
/**
|
|
1090
|
+
/**
|
|
1091
|
+
* Copies the staging row to row `row`, the slot of the packet just sealed.
|
|
1092
|
+
* @internal Read in quic.ts outside the class.
|
|
1093
|
+
*/
|
|
961
1094
|
commitStaged(row: i32): void {
|
|
962
1095
|
const from: i32 = this.staging
|
|
963
1096
|
this.setCrypto(row, this.cryptoOffset(from), this.cryptoLength(from))
|
|
@@ -992,7 +1125,10 @@ class QuicConnSpace {
|
|
|
992
1125
|
}
|
|
993
1126
|
}
|
|
994
1127
|
|
|
995
|
-
/**
|
|
1128
|
+
/**
|
|
1129
|
+
* Queues CRYPTO bytes `[offset, offset + length)` to be sent again, merged with what is queued already.
|
|
1130
|
+
* @internal Read in quic.ts outside the class.
|
|
1131
|
+
*/
|
|
996
1132
|
resendCrypto(offset: i64, length: i32): void {
|
|
997
1133
|
if (length <= 0 || this.discarded) {
|
|
998
1134
|
return
|
|
@@ -1011,7 +1147,10 @@ class QuicConnSpace {
|
|
|
1011
1147
|
}
|
|
1012
1148
|
}
|
|
1013
1149
|
|
|
1014
|
-
/**
|
|
1150
|
+
/**
|
|
1151
|
+
* How many CRYPTO bytes are waiting to be sent.
|
|
1152
|
+
* @internal Read in quic.ts outside the class.
|
|
1153
|
+
*/
|
|
1015
1154
|
cryptoUnsent(): i32 {
|
|
1016
1155
|
return this.cryptoOutLength - this.cryptoOutHead
|
|
1017
1156
|
}
|
|
@@ -1079,6 +1218,11 @@ const quicConnWipePacketKey = (keys: QuicKeys | null): void => {
|
|
|
1079
1218
|
* `nish/net/quic-listener` derives the same token from a packet's ID alone
|
|
1080
1219
|
* once the connection is gone, which is what lets a server that lost its
|
|
1081
1220
|
* state end the connection.
|
|
1221
|
+
*
|
|
1222
|
+
* @param key The server's static reset key, `QUIC_CONN_STATIC_KEY_SIZE` bytes
|
|
1223
|
+
* (`QuicServerConfig.statelessResetKey`).
|
|
1224
|
+
* @param cid The connection ID the token is for, all of its bytes.
|
|
1225
|
+
* @returns A fresh 16-byte token (`QUIC_RESET_TOKEN_SIZE`); the full MAC it was cut from is wiped.
|
|
1082
1226
|
*/
|
|
1083
1227
|
export const quicStatelessResetToken = (key: u8[], cid: u8[]): u8[] => {
|
|
1084
1228
|
const mac: u8[] = hmacSha256(key, cid)
|
|
@@ -1092,6 +1236,14 @@ export const quicStatelessResetToken = (key: u8[], cid: u8[]): u8[] => {
|
|
|
1092
1236
|
* `out[outAt ..]`, computed in a connection's own HMAC scratch inside an
|
|
1093
1237
|
* arena block, so issuing an ID keeps nothing (QUIC-3). The scratch and the
|
|
1094
1238
|
* full MAC are wiped before it returns.
|
|
1239
|
+
*
|
|
1240
|
+
* @param mac The connection's HMAC-SHA256 scratch, wiped on return.
|
|
1241
|
+
* @param key The server's static reset key, `QUIC_CONN_STATIC_KEY_SIZE` bytes.
|
|
1242
|
+
* @param cid The array holding the connection ID.
|
|
1243
|
+
* @param at Where the ID starts in `cid`.
|
|
1244
|
+
* @param length The ID's length in bytes, at most 20: the caller's to keep, as nothing checks it.
|
|
1245
|
+
* @param out Where the 16-byte token goes; bytes that would fall past its end are not written.
|
|
1246
|
+
* @param outAt Where in `out` the token starts.
|
|
1095
1247
|
*/
|
|
1096
1248
|
export const quicConnResetTokenInto = (
|
|
1097
1249
|
mac: HmacSha256Scratch,
|
|
@@ -1215,33 +1367,38 @@ const quicConnConfigFits = (config: QuicServerConfig): boolean =>
|
|
|
1215
1367
|
* that runs many connections routes datagrams by (`ownsConnectionId`).
|
|
1216
1368
|
*/
|
|
1217
1369
|
export class QuicConnection {
|
|
1218
|
-
config: QuicServerConfig
|
|
1370
|
+
private config: QuicServerConfig
|
|
1219
1371
|
/** The error code the connection closed with: a transport error, `0x100 + alert`, or the application's code. */
|
|
1220
1372
|
error: i64 = 0
|
|
1221
1373
|
/** For a transport error: the type of the frame that caused it, or 0. */
|
|
1222
|
-
errorFrameType: i64 = 0
|
|
1223
|
-
serverRandom: u8[]
|
|
1374
|
+
private errorFrameType: i64 = 0
|
|
1375
|
+
private serverRandom: u8[]
|
|
1224
1376
|
/** The x25519 private key `begin` takes from the entropy, until the handshake hands it to `TlsServer`. */
|
|
1225
1377
|
readonly ephemeral: Secret<u8[]>
|
|
1378
|
+
/** The 32-byte HMAC key, taken from the entropy, that each new local connection ID is derived from; `release` wipes it. */
|
|
1226
1379
|
cidSeed: u8[]
|
|
1227
|
-
/**
|
|
1380
|
+
/**
|
|
1381
|
+
* The DCID of the client's first Initial, which the Initial keys come from: its first `originalDcidLength` bytes.
|
|
1382
|
+
* @internal Read by http3-server.ts.
|
|
1383
|
+
*/
|
|
1228
1384
|
originalDcid: u8[]
|
|
1229
1385
|
/** The SCID of the client's first Initial: where long-header packets go, and what its transport parameters must name. */
|
|
1230
|
-
peerScid: u8[]
|
|
1386
|
+
private peerScid: u8[]
|
|
1231
1387
|
/** The server's first connection ID, the SCID of every long-header packet it sends. */
|
|
1232
|
-
localScid: u8[]
|
|
1388
|
+
private localScid: u8[]
|
|
1389
|
+
/** The `TlsServer` running this connection's handshake: null until the client's first Initial has opened, and again after `reset`. */
|
|
1233
1390
|
tls: TlsServer | null = null
|
|
1234
1391
|
/** The slot's `TlsServer`, made by its first handshake and `restart`ed by every one after (QUIC-3). */
|
|
1235
1392
|
tlsSlot: TlsServer | null = null
|
|
1236
1393
|
/** Its configuration, made once: the parameters it carries are `localEncoded`, rewritten for each connection. */
|
|
1237
|
-
tlsConfig: TlsServerConfig
|
|
1394
|
+
private tlsConfig: TlsServerConfig
|
|
1238
1395
|
/** The server's transport parameters, set for each connection, and their encoding. */
|
|
1239
1396
|
localParameters: QuicTransportParameters
|
|
1240
1397
|
localEncoded: u8[]
|
|
1241
1398
|
/** The client's transport parameters, parsed into the slot's own object. */
|
|
1242
|
-
parsedParameters: QuicTransportParameters
|
|
1399
|
+
private parsedParameters: QuicTransportParameters
|
|
1243
1400
|
/** Where every key derivation and HMAC of the connection runs. */
|
|
1244
|
-
kdf: HkdfScratch
|
|
1401
|
+
private kdf: HkdfScratch
|
|
1245
1402
|
/** The Initial secrets of RFC 9001 §5.2, the client's and the server's. */
|
|
1246
1403
|
initialClient: u8[]
|
|
1247
1404
|
initialServer: u8[]
|
|
@@ -1260,8 +1417,8 @@ export class QuicConnection {
|
|
|
1260
1417
|
readonly nextReadSecret384: Secret<u8[]>
|
|
1261
1418
|
readonly writeSecret384: Secret<u8[]>
|
|
1262
1419
|
/** A connection ID being issued and its stateless reset token, before the table copies them. */
|
|
1263
|
-
cidScratch: u8[]
|
|
1264
|
-
tokenScratch: u8[]
|
|
1420
|
+
private cidScratch: u8[]
|
|
1421
|
+
private tokenScratch: u8[]
|
|
1265
1422
|
initial: QuicConnSpace
|
|
1266
1423
|
handshake: QuicConnSpace
|
|
1267
1424
|
application: QuicConnSpace
|
|
@@ -1271,13 +1428,13 @@ export class QuicConnection {
|
|
|
1271
1428
|
/** The client's transport parameters, once the handshake has checked them; until then, every default. */
|
|
1272
1429
|
peerParameters: QuicTransportParameters
|
|
1273
1430
|
/** The defaults `peerParameters` starts from, made once and set back by `reset`. */
|
|
1274
|
-
defaultParameters: QuicTransportParameters
|
|
1431
|
+
private defaultParameters: QuicTransportParameters
|
|
1275
1432
|
/** Bytes received and sent, for the anti-amplification limit (RFC 9000 §8.1). */
|
|
1276
1433
|
bytesReceived: i64 = 0
|
|
1277
1434
|
bytesSent: i64 = 0
|
|
1278
1435
|
/** The ALPN protocol the handshake chose. */
|
|
1279
1436
|
alpn: string = ""
|
|
1280
|
-
/** The client's `server_name
|
|
1437
|
+
/** The client's `server_name` the handshake read, or empty when it sent none. */
|
|
1281
1438
|
serverName: string = ""
|
|
1282
1439
|
/** The streams, both ways (`nish/net/quic-stream`). */
|
|
1283
1440
|
streams: QuicStreams
|
|
@@ -1285,9 +1442,9 @@ export class QuicConnection {
|
|
|
1285
1442
|
datagramsOut: QuicDatagramQueue
|
|
1286
1443
|
datagramsIn: QuicDatagramQueue
|
|
1287
1444
|
/** The CRYPTO bytes the client sent, put back in order. */
|
|
1288
|
-
cryptoIn: QuicConnReassembly
|
|
1445
|
+
private cryptoIn: QuicConnReassembly
|
|
1289
1446
|
/** PATH_CHALLENGE data to answer: a ring of four, eight bytes each, `pathCount` from `pathHead`. */
|
|
1290
|
-
pathData: u8[]
|
|
1447
|
+
private pathData: u8[]
|
|
1291
1448
|
/**
|
|
1292
1449
|
* The client's address (RFC 9000 §9), each in `nish:net`'s 18-byte form,
|
|
1293
1450
|
* for a carrier that passes one to `receiveWindowFrom`: `pathCurrent` is
|
|
@@ -1296,9 +1453,9 @@ export class QuicConnection {
|
|
|
1296
1453
|
* handshake's, or one a PATH_RESPONSE answered. `pathArrival` is the
|
|
1297
1454
|
* datagram being read's. Made once and overwritten in place.
|
|
1298
1455
|
*/
|
|
1299
|
-
pathCurrent: u8[]
|
|
1456
|
+
private pathCurrent: u8[]
|
|
1300
1457
|
pathValidated: u8[]
|
|
1301
|
-
pathArrival: u8[]
|
|
1458
|
+
private pathArrival: u8[]
|
|
1302
1459
|
/**
|
|
1303
1460
|
* A PATH_CHALLENGE that came from another address in a datagram that
|
|
1304
1461
|
* moved nothing (§9.1): answered there by `takeProbeInto`, from
|
|
@@ -1308,35 +1465,35 @@ export class QuicConnection {
|
|
|
1308
1465
|
* the same way (`sendResponsesBack`).
|
|
1309
1466
|
*/
|
|
1310
1467
|
probeAddress: u8[]
|
|
1311
|
-
probeData: u8[]
|
|
1468
|
+
private probeData: u8[]
|
|
1312
1469
|
/**
|
|
1313
1470
|
* The last `QUIC_CONN_CHALLENGES` PATH_CHALLENGE data sent on the path
|
|
1314
1471
|
* being validated, eight bytes each, `challengeCount` of them, the latest
|
|
1315
1472
|
* at `(challengesDrawn - 1) % QUIC_CONN_CHALLENGES`: each drawn from the
|
|
1316
1473
|
* ID seed's HMAC under `QUIC_CONN_CHALLENGE_SEQUENCE`, so unguessable.
|
|
1317
1474
|
*/
|
|
1318
|
-
challengeData: u8[]
|
|
1475
|
+
private challengeData: u8[]
|
|
1319
1476
|
/** Bytes received from and sent to the path being validated, for its own 3x limit (§9.3, §8.1). */
|
|
1320
1477
|
pathReceived: i64 = 0
|
|
1321
1478
|
pathSent: i64 = 0
|
|
1322
|
-
probeBudget: i64 = 0
|
|
1479
|
+
private probeBudget: i64 = 0
|
|
1323
1480
|
/** When the PATH_CHALLENGE goes again with fresh data, and when validation gives up (§8.2.4); -1 when not validating. */
|
|
1324
1481
|
challengeResendAt: i64 = -1
|
|
1325
1482
|
challengeUntil: i64 = -1
|
|
1326
1483
|
challengesDrawn: i64 = 0
|
|
1327
|
-
frame: QuicFrame
|
|
1484
|
+
private frame: QuicFrame
|
|
1328
1485
|
/** The header and the packet numbers of the packet being read, reused for every one. */
|
|
1329
|
-
header: QuicHeader
|
|
1330
|
-
packet: QuicPacket
|
|
1486
|
+
private header: QuicHeader
|
|
1487
|
+
private packet: QuicPacket
|
|
1331
1488
|
/** For a connection `acceptRetry` set up: the DCID of the client's Initial before the Retry, and the Retry's SCID. */
|
|
1332
|
-
retryOriginalDcid: u8[]
|
|
1333
|
-
retryScid: u8[]
|
|
1489
|
+
private retryOriginalDcid: u8[]
|
|
1490
|
+
private retryScid: u8[]
|
|
1334
1491
|
/** An empty array, which a cleared secret or ID is set to. */
|
|
1335
|
-
none: u8[]
|
|
1492
|
+
private none: u8[]
|
|
1336
1493
|
/** The latest time the caller gave, in milliseconds; time never runs backwards here. */
|
|
1337
1494
|
now: i64 = 0
|
|
1338
1495
|
/** When the idle timer last restarted (RFC 9000 §10.1), or -1 before the first packet. */
|
|
1339
|
-
idleSince: i64 = -1
|
|
1496
|
+
private idleSince: i64 = -1
|
|
1340
1497
|
/**
|
|
1341
1498
|
* The other read keys of the Application Data space (RFC 9001 §6.3):
|
|
1342
1499
|
* the next generation's while `otherIsNext`, and for a probe timeout
|
|
@@ -1344,23 +1501,23 @@ export class QuicConnection {
|
|
|
1344
1501
|
*/
|
|
1345
1502
|
otherReadKeys: QuicKeys | null = null
|
|
1346
1503
|
/** The lowest and highest packet numbers opened with the current read keys, or -1. */
|
|
1347
|
-
readPhaseLowest: i64 = -1
|
|
1348
|
-
readPhaseHighest: i64 = -1
|
|
1504
|
+
private readPhaseLowest: i64 = -1
|
|
1505
|
+
private readPhaseHighest: i64 = -1
|
|
1349
1506
|
/** The first packet number sent with the current write keys. */
|
|
1350
|
-
writePhaseFirst: i64 = 0
|
|
1507
|
+
private writePhaseFirst: i64 = 0
|
|
1351
1508
|
/** When the previous read keys go and the next are derived, or -1. */
|
|
1352
|
-
keyRetainUntil: i64 = -1
|
|
1509
|
+
private keyRetainUntil: i64 = -1
|
|
1353
1510
|
/**
|
|
1354
1511
|
* When a closed connection's closing or draining period ends (RFC 9000
|
|
1355
1512
|
* §10.2), and `runClocks` wipes every key it kept for it, or -1: before
|
|
1356
1513
|
* the close, while a close this side owes has not gone out, and once the
|
|
1357
1514
|
* keys are wiped.
|
|
1358
1515
|
*/
|
|
1359
|
-
closingUntil: i64 = -1
|
|
1516
|
+
private closingUntil: i64 = -1
|
|
1360
1517
|
/** The packet number of a client key update read but not applied yet, or -1. */
|
|
1361
|
-
phasePending: i64 = -1
|
|
1518
|
+
private phasePending: i64 = -1
|
|
1362
1519
|
/** The largest DATAGRAM frame the client takes (its `max_datagram_frame_size`), 0 for none. */
|
|
1363
|
-
peerMaxDatagramFrame: i64 = 0
|
|
1520
|
+
private peerMaxDatagramFrame: i64 = 0
|
|
1364
1521
|
/**
|
|
1365
1522
|
* The AEAD limits this connection keeps (RFC 9001 §6.6): packets one 1-RTT
|
|
1366
1523
|
* write key seals, and packets that fail to authenticate over the
|
|
@@ -1380,14 +1537,17 @@ export class QuicConnection {
|
|
|
1380
1537
|
* the next goes, and `skipsDrawn` how many distances were drawn.
|
|
1381
1538
|
*/
|
|
1382
1539
|
nextSkip: i64 = -1
|
|
1383
|
-
skipped: i64[]
|
|
1540
|
+
private skipped: i64[]
|
|
1384
1541
|
skipsDrawn: i64 = 0
|
|
1385
1542
|
/** How many of `challengeData`'s slots hold a challenge sent on the path being validated. */
|
|
1386
|
-
challengeCount: i32 = 0
|
|
1543
|
+
private challengeCount: i32 = 0
|
|
1544
|
+
/** @internal Read by http3-server.ts. */
|
|
1387
1545
|
originalDcidLength: i32 = 0
|
|
1388
|
-
peerScidLength: i32 = 0
|
|
1389
|
-
pathHead: i32 = 0
|
|
1546
|
+
private peerScidLength: i32 = 0
|
|
1547
|
+
private pathHead: i32 = 0
|
|
1548
|
+
/** How many PATH_CHALLENGE payloads wait to be answered, 0 to 4. */
|
|
1390
1549
|
pathCount: i32 = 0
|
|
1550
|
+
/** Where the connection is in its life: one of the `QUIC_STATE_*` constants. */
|
|
1391
1551
|
state: i32 = 0
|
|
1392
1552
|
/** Packets dropped without closing the connection: unparseable, unauthenticated, duplicated, or for keys not held. */
|
|
1393
1553
|
dropped: i32 = 0
|
|
@@ -1401,7 +1561,7 @@ export class QuicConnection {
|
|
|
1401
1561
|
/** Handshake data sent again early, against `QUIC_CONN_EARLY_RESENDS` (RFC 9002 §6.2.3). */
|
|
1402
1562
|
earlyResends: i32 = 0
|
|
1403
1563
|
/** The level at which the packet just read showed the client lacks the server's handshake data, or -1. */
|
|
1404
|
-
resendLevel: i32 = -1
|
|
1564
|
+
private resendLevel: i32 = -1
|
|
1405
1565
|
/**
|
|
1406
1566
|
* ECN (RFC 9000 §13.4): `ecnMarking` is the carrier's to set when it sends
|
|
1407
1567
|
* this connection's datagrams with the ECN bits of `datagramEcn`, which
|
|
@@ -1416,45 +1576,45 @@ export class QuicConnection {
|
|
|
1416
1576
|
/** Whether `error` is an application code (CONNECTION_CLOSE 0x1d) rather than a transport error. */
|
|
1417
1577
|
errorIsApplication: boolean = false
|
|
1418
1578
|
/** Whether the one CONNECTION_CLOSE this side owes has gone out. */
|
|
1419
|
-
closeSent: boolean = false
|
|
1579
|
+
private closeSent: boolean = false
|
|
1420
1580
|
/** Whether the client's address is validated: a Handshake packet from it was processed. */
|
|
1421
1581
|
addressValidated: boolean = false
|
|
1422
1582
|
/** Whether the handshake is complete, which for a server is also confirmed (RFC 9001 §4.1.2). */
|
|
1423
1583
|
handshakeComplete: boolean = false
|
|
1424
|
-
handshakeDonePending: boolean = false
|
|
1584
|
+
private handshakeDonePending: boolean = false
|
|
1425
1585
|
/**
|
|
1426
1586
|
* Whether `afterTls` has taken the application traffic secrets out of
|
|
1427
1587
|
* `TlsServer`. It takes them once: `wipeSecret` leaves them known, so a
|
|
1428
1588
|
* second take would derive the 1-RTT keys from the zeros it left.
|
|
1429
1589
|
*/
|
|
1430
|
-
applicationTaken: boolean = false
|
|
1590
|
+
private applicationTaken: boolean = false
|
|
1431
1591
|
/** Whether the connection was set up by `acceptRetry`. */
|
|
1432
|
-
retried: boolean = false
|
|
1592
|
+
private retried: boolean = false
|
|
1433
1593
|
/** Whether an ack-eliciting packet went out since the last packet was received. */
|
|
1434
|
-
elicitingSent: boolean = false
|
|
1594
|
+
private elicitingSent: boolean = false
|
|
1435
1595
|
/** Whether `otherReadKeys` are the next generation's rather than the previous one's. */
|
|
1436
1596
|
otherIsNext: boolean = false
|
|
1437
1597
|
/** The Key Phase bit of the current read keys, and of the current write keys. */
|
|
1438
1598
|
readPhase: boolean = false
|
|
1439
1599
|
writePhase: boolean = false
|
|
1440
1600
|
/** Whether the packet just read brought CRYPTO bytes for TLS, or retired an ID that wants replacing. */
|
|
1441
|
-
cryptoArrived: boolean = false
|
|
1442
|
-
topUpOwed: boolean = false
|
|
1601
|
+
private cryptoArrived: boolean = false
|
|
1602
|
+
private topUpOwed: boolean = false
|
|
1443
1603
|
/** Whether `pathCurrent` holds the client's address: the carrier passes addresses, and a first Initial gave one. */
|
|
1444
1604
|
pathKnown: boolean = false
|
|
1445
1605
|
/** Whether the datagram being read came from an address other than `pathCurrent`. */
|
|
1446
|
-
arrivalOther: boolean = false
|
|
1606
|
+
private arrivalOther: boolean = false
|
|
1447
1607
|
/** Whether `pathCurrent` is not validated yet: a PATH_CHALLENGE is out on it. */
|
|
1448
1608
|
pathValidating: boolean = false
|
|
1449
1609
|
/** Whether a PATH_CHALLENGE is due in the next datagram, and whether the one being built carries a PATH_CHALLENGE or PATH_RESPONSE. */
|
|
1450
|
-
challengeOwed: boolean = false
|
|
1451
|
-
pathFrameStaged: boolean = false
|
|
1610
|
+
private challengeOwed: boolean = false
|
|
1611
|
+
private pathFrameStaged: boolean = false
|
|
1452
1612
|
/** Whether a PATH_RESPONSE is owed on `probeAddress`, and whether the datagram being read carried a challenge for it. */
|
|
1453
1613
|
probeOwed: boolean = false
|
|
1454
|
-
probeStaged: boolean = false
|
|
1614
|
+
private probeStaged: boolean = false
|
|
1455
1615
|
/** Whether the packet being read carries a non-probing frame (§9.1), and whether a packet of the datagram moves the connection (§9.3). */
|
|
1456
|
-
nonProbing: boolean = false
|
|
1457
|
-
migrateOwed: boolean = false
|
|
1616
|
+
private nonProbing: boolean = false
|
|
1617
|
+
private migrateOwed: boolean = false
|
|
1458
1618
|
|
|
1459
1619
|
/**
|
|
1460
1620
|
* A connection under `config`, with `entropy` its `QUIC_CONN_ENTROPY_SIZE`
|
|
@@ -1463,6 +1623,11 @@ export class QuicConnection {
|
|
|
1463
1623
|
* Entropy of another length, or limits outside what `QuicServerConfig`
|
|
1464
1624
|
* documents, leave the connection closing with INTERNAL_ERROR before it
|
|
1465
1625
|
* reads anything; it then sends nothing.
|
|
1626
|
+
*
|
|
1627
|
+
* @param config The server's limits and keys. The connection keeps a reference and reads it for
|
|
1628
|
+
* its whole life, `reset`s included, so do not change it under a live connection.
|
|
1629
|
+
* @param entropy `QUIC_CONN_ENTROPY_SIZE` (104) random bytes for this connection's first peer;
|
|
1630
|
+
* zeroed in place once copied.
|
|
1466
1631
|
*/
|
|
1467
1632
|
constructor(config: QuicServerConfig, entropy: u8[]) {
|
|
1468
1633
|
this.config = config
|
|
@@ -1549,6 +1714,9 @@ export class QuicConnection {
|
|
|
1549
1714
|
* the constructor's configuration's. A slot reset this way allocates
|
|
1550
1715
|
* nothing, and neither does the next handshake (QUIC-3 in
|
|
1551
1716
|
* `docs/security/quic.md`).
|
|
1717
|
+
*
|
|
1718
|
+
* @param entropy `QUIC_CONN_ENTROPY_SIZE` (104) fresh random bytes for the next peer, never ones
|
|
1719
|
+
* used before; zeroed in place once copied.
|
|
1552
1720
|
*/
|
|
1553
1721
|
reset(entropy: u8[]): void {
|
|
1554
1722
|
this.wipeAll()
|
|
@@ -1620,7 +1788,7 @@ export class QuicConnection {
|
|
|
1620
1788
|
}
|
|
1621
1789
|
|
|
1622
1790
|
/** Takes `entropy` (and wipes it), or closes with INTERNAL_ERROR for entropy or a configuration that does not fit. */
|
|
1623
|
-
begin(entropy: u8[]): void {
|
|
1791
|
+
private begin(entropy: u8[]): void {
|
|
1624
1792
|
quicCidCopy(this.serverRandom, entropy, 0, 32)
|
|
1625
1793
|
exposeWith(this.ephemeral, entropy, quicConnEphemeralIn)
|
|
1626
1794
|
quicCidCopy(this.localScid, entropy, 64, QUIC_CONN_CID_LENGTH)
|
|
@@ -1636,13 +1804,17 @@ export class QuicConnection {
|
|
|
1636
1804
|
}
|
|
1637
1805
|
|
|
1638
1806
|
/** Counts a dropped packet; the count stops at the largest `i32` rather than overflow. */
|
|
1639
|
-
drop(): void {
|
|
1807
|
+
private drop(): void {
|
|
1640
1808
|
if (this.dropped < 2147483647) {
|
|
1641
1809
|
this.dropped += 1
|
|
1642
1810
|
}
|
|
1643
1811
|
}
|
|
1644
1812
|
|
|
1645
|
-
/**
|
|
1813
|
+
/**
|
|
1814
|
+
* Whether the connection has closed, either way.
|
|
1815
|
+
*
|
|
1816
|
+
* @returns True once it is closing, draining or timed out; it stays true until `reset`.
|
|
1817
|
+
*/
|
|
1646
1818
|
closed(): boolean {
|
|
1647
1819
|
return (
|
|
1648
1820
|
this.state === QUIC_STATE_CLOSING ||
|
|
@@ -1660,6 +1832,10 @@ export class QuicConnection {
|
|
|
1660
1832
|
* validated, so the anti-amplification limit does not apply. Call it
|
|
1661
1833
|
* before the first `receive`; answers whether it took: not once the
|
|
1662
1834
|
* connection has started, and not for an ID over 20 bytes.
|
|
1835
|
+
*
|
|
1836
|
+
* @param originalDcid The DCID of the client's first Initial, from the checked Retry token; copied.
|
|
1837
|
+
* @param retryScid The SCID the Retry packet carried; copied.
|
|
1838
|
+
* @returns True when the connection took the Retry, false (and nothing changed) otherwise.
|
|
1663
1839
|
*/
|
|
1664
1840
|
acceptRetry(originalDcid: u8[], retryScid: u8[]): boolean {
|
|
1665
1841
|
if (
|
|
@@ -1675,7 +1851,10 @@ export class QuicConnection {
|
|
|
1675
1851
|
return true
|
|
1676
1852
|
}
|
|
1677
1853
|
|
|
1678
|
-
/**
|
|
1854
|
+
/**
|
|
1855
|
+
* Closes the connection with transport error `code`, caused by a frame of `frameType` (0 for none).
|
|
1856
|
+
* @internal Read by http3.ts.
|
|
1857
|
+
*/
|
|
1679
1858
|
fail(code: i64, frameType: i64): void {
|
|
1680
1859
|
if (this.closed()) {
|
|
1681
1860
|
return
|
|
@@ -1691,6 +1870,9 @@ export class QuicConnection {
|
|
|
1691
1870
|
* (CONNECTION_CLOSE 0x1d; RFC 9000 §10.2). The next `takeDatagram` answers
|
|
1692
1871
|
* the close, and nothing after it. Closing twice, or after the client
|
|
1693
1872
|
* closed, does nothing.
|
|
1873
|
+
*
|
|
1874
|
+
* @param code The application's error code, sent in the CONNECTION_CLOSE; keeping it to 0 to 2^62 - 1 is
|
|
1875
|
+
* the caller's, as nothing checks it.
|
|
1694
1876
|
*/
|
|
1695
1877
|
close(code: i64): void {
|
|
1696
1878
|
if (this.closed()) {
|
|
@@ -1711,12 +1893,12 @@ export class QuicConnection {
|
|
|
1711
1893
|
* `deadline()` names, so that a connection nobody `release()`s does not
|
|
1712
1894
|
* keep them.
|
|
1713
1895
|
*/
|
|
1714
|
-
startClosingPeriod(): void {
|
|
1896
|
+
private startClosingPeriod(): void {
|
|
1715
1897
|
this.closingUntil = this.now + this.recovery.probeTimeout() * 3
|
|
1716
1898
|
}
|
|
1717
1899
|
|
|
1718
1900
|
/** The space of packets of `type`, or `null` for a 0-RTT or Retry packet. */
|
|
1719
|
-
spaceOf(type: i32): QuicConnSpace | null {
|
|
1901
|
+
private spaceOf(type: i32): QuicConnSpace | null {
|
|
1720
1902
|
if (type === QUIC_PACKET_INITIAL) {
|
|
1721
1903
|
return this.initial
|
|
1722
1904
|
}
|
|
@@ -1730,7 +1912,7 @@ export class QuicConnection {
|
|
|
1730
1912
|
}
|
|
1731
1913
|
|
|
1732
1914
|
/** The space of TLS level `level`. */
|
|
1733
|
-
spaceAt(level: i32): QuicConnSpace {
|
|
1915
|
+
private spaceAt(level: i32): QuicConnSpace {
|
|
1734
1916
|
if (level === TLS_LEVEL_INITIAL) {
|
|
1735
1917
|
return this.initial
|
|
1736
1918
|
}
|
|
@@ -1742,12 +1924,22 @@ export class QuicConnection {
|
|
|
1742
1924
|
* connection: one of its active connection IDs, or, until the handshake is
|
|
1743
1925
|
* done, the DCID of the client's first Initial. A closed connection still
|
|
1744
1926
|
* answers for its IDs; the caller drops it once it is done with it.
|
|
1927
|
+
*
|
|
1928
|
+
* @param dcid The destination connection ID of the datagram's first packet, all of its bytes.
|
|
1929
|
+
* @returns True when the datagram should be handed to this connection.
|
|
1745
1930
|
*/
|
|
1746
1931
|
ownsConnectionId(dcid: u8[]): boolean {
|
|
1747
1932
|
return this.ownsConnectionIdAt(dcid, QUIC_CONN_FROM, toI32(dcid.length))
|
|
1748
1933
|
}
|
|
1749
1934
|
|
|
1750
|
-
/**
|
|
1935
|
+
/**
|
|
1936
|
+
* `ownsConnectionId` of the ID `buf[at .. at + length)`, read in place, so a carrier routes without a copy.
|
|
1937
|
+
*
|
|
1938
|
+
* @param buf The array holding the ID, usually the received datagram.
|
|
1939
|
+
* @param at Where the ID starts in `buf`.
|
|
1940
|
+
* @param length The ID's length in bytes.
|
|
1941
|
+
* @returns True when the datagram should be handed to this connection.
|
|
1942
|
+
*/
|
|
1751
1943
|
ownsConnectionIdAt(buf: u8[], at: i32, length: i32): boolean {
|
|
1752
1944
|
if (this.cids.ownsLocalAt(buf, at, length)) {
|
|
1753
1945
|
return true
|
|
@@ -1760,7 +1952,13 @@ export class QuicConnection {
|
|
|
1760
1952
|
)
|
|
1761
1953
|
}
|
|
1762
1954
|
|
|
1763
|
-
/**
|
|
1955
|
+
/**
|
|
1956
|
+
* `receiveWindow` of a whole datagram.
|
|
1957
|
+
*
|
|
1958
|
+
* @param datagram The UDP payload, read and never written.
|
|
1959
|
+
* @param now The caller's monotonic time in milliseconds.
|
|
1960
|
+
* @returns 0, or the transport or application error the connection has closed with.
|
|
1961
|
+
*/
|
|
1764
1962
|
receive(datagram: u8[], now: i64): i64 {
|
|
1765
1963
|
return this.receiveWindow(datagram, QUIC_CONN_FROM, toI32(datagram.length), now)
|
|
1766
1964
|
}
|
|
@@ -1775,6 +1973,12 @@ export class QuicConnection {
|
|
|
1775
1973
|
* cannot be used is dropped and counted (see the module header). Once the
|
|
1776
1974
|
* connection has closed, or its idle timeout has passed by `now`, every
|
|
1777
1975
|
* datagram is ignored.
|
|
1976
|
+
*
|
|
1977
|
+
* @param buf The array holding the datagram; read, never written, and not kept past the call.
|
|
1978
|
+
* @param off Where the datagram starts in `buf`.
|
|
1979
|
+
* @param len The datagram's length in bytes; a client's first Initial needs at least 1200.
|
|
1980
|
+
* @param now The caller's monotonic time in milliseconds.
|
|
1981
|
+
* @returns 0, or the error the connection has closed with (also once it was already closed).
|
|
1778
1982
|
*/
|
|
1779
1983
|
receiveWindow(buf: u8[], off: i32, len: i32, now: i64): i64 {
|
|
1780
1984
|
return this.receiveWindowFrom(buf, off, len, this.none, now)
|
|
@@ -1785,6 +1989,13 @@ export class QuicConnection {
|
|
|
1785
1989
|
* `nish:net` address: the connection follows the client from one address
|
|
1786
1990
|
* to another (RFC 9000 §9) — see "Paths" in the module header. An
|
|
1787
1991
|
* address of any other length is no address, as `receiveWindow` gives.
|
|
1992
|
+
*
|
|
1993
|
+
* @param buf The array holding the datagram; read, never written, and not kept past the call.
|
|
1994
|
+
* @param off Where the datagram starts in `buf`.
|
|
1995
|
+
* @param len The datagram's length in bytes; a client's first Initial needs at least 1200.
|
|
1996
|
+
* @param address The 18-byte `nish:net` address the datagram came from; copied, not kept.
|
|
1997
|
+
* @param now The caller's monotonic time in milliseconds.
|
|
1998
|
+
* @returns 0, or the error the connection has closed with (also once it was already closed).
|
|
1788
1999
|
*/
|
|
1789
2000
|
receiveWindowFrom(buf: u8[], off: i32, len: i32, address: u8[], now: i64): i64 {
|
|
1790
2001
|
this.runClocks(now)
|
|
@@ -1844,7 +2055,7 @@ export class QuicConnection {
|
|
|
1844
2055
|
* `TlsServer` — is made by `establish` once the Initial has opened, so an
|
|
1845
2056
|
* Initial that does not authenticate costs only its keys.
|
|
1846
2057
|
*/
|
|
1847
|
-
start(buf: u8[], header: QuicHeader): boolean {
|
|
2058
|
+
private start(buf: u8[], header: QuicHeader): boolean {
|
|
1848
2059
|
if (
|
|
1849
2060
|
header.dcidLength < 8 ||
|
|
1850
2061
|
header.dcidLength > QUIC_MAX_CID_LENGTH ||
|
|
@@ -1890,7 +2101,7 @@ export class QuicConnection {
|
|
|
1890
2101
|
* `acceptRetry` set one up, and the first ID's stateless reset token
|
|
1891
2102
|
* (§18.2).
|
|
1892
2103
|
*/
|
|
1893
|
-
establish(): void {
|
|
2104
|
+
private establish(): void {
|
|
1894
2105
|
const none: u8[] = this.none
|
|
1895
2106
|
const token: u8[] = this.tokenScratch
|
|
1896
2107
|
quicConnResetTokenInto(
|
|
@@ -1979,7 +2190,7 @@ export class QuicConnection {
|
|
|
1979
2190
|
* One packet of a datagram. Answers whether the packet was used: whether it
|
|
1980
2191
|
* authenticated as this connection's.
|
|
1981
2192
|
*/
|
|
1982
|
-
receivePacket(buf: u8[], header: QuicHeader): boolean {
|
|
2193
|
+
private receivePacket(buf: u8[], header: QuicHeader): boolean {
|
|
1983
2194
|
const type: i32 = header.type
|
|
1984
2195
|
const first: boolean = this.state === QUIC_STATE_WAIT_INITIAL
|
|
1985
2196
|
if (first && (type !== QUIC_PACKET_INITIAL || !this.start(buf, header))) {
|
|
@@ -1996,7 +2207,7 @@ export class QuicConnection {
|
|
|
1996
2207
|
}
|
|
1997
2208
|
|
|
1998
2209
|
/** Undoes `start`, for a first Initial that turned out not to authenticate. */
|
|
1999
|
-
unstart(): void {
|
|
2210
|
+
private unstart(): void {
|
|
2000
2211
|
this.state = QUIC_STATE_WAIT_INITIAL
|
|
2001
2212
|
this.addressValidated = false
|
|
2002
2213
|
this.idleSince = -1
|
|
@@ -2014,7 +2225,7 @@ export class QuicConnection {
|
|
|
2014
2225
|
* the CRYPTO bytes and what it answers — runs after it. Answers whether
|
|
2015
2226
|
* the packet was used.
|
|
2016
2227
|
*/
|
|
2017
|
-
openPacket(buf: u8[], header: QuicHeader, first: boolean): boolean {
|
|
2228
|
+
private openPacket(buf: u8[], header: QuicHeader, first: boolean): boolean {
|
|
2018
2229
|
const type: i32 = header.type
|
|
2019
2230
|
const space: QuicConnSpace | null = this.spaceOf(type)
|
|
2020
2231
|
if (space === null || !this.addressedHere(buf, header)) {
|
|
@@ -2085,7 +2296,13 @@ export class QuicConnection {
|
|
|
2085
2296
|
* an allocation, which is what lets the block release the packet's
|
|
2086
2297
|
* temporaries. Answers whether the packet was used rather than dropped.
|
|
2087
2298
|
*/
|
|
2088
|
-
openScoped(
|
|
2299
|
+
private openScoped(
|
|
2300
|
+
buf: u8[],
|
|
2301
|
+
header: QuicHeader,
|
|
2302
|
+
space: QuicConnSpace,
|
|
2303
|
+
keys: QuicKeys,
|
|
2304
|
+
first: boolean
|
|
2305
|
+
): boolean {
|
|
2089
2306
|
const packet: QuicPacket = this.packet
|
|
2090
2307
|
// Every key generation shares the header-protection key (RFC 9001 §6),
|
|
2091
2308
|
// so the current keys take it off whatever the Key Phase bit says.
|
|
@@ -2157,7 +2374,7 @@ export class QuicConnection {
|
|
|
2157
2374
|
* already had — and an update past `QUIC_CONN_MAX_KEY_UPDATES` is too.
|
|
2158
2375
|
* Answers whether the connection is still open.
|
|
2159
2376
|
*/
|
|
2160
|
-
notePhase(pn: i64, other: boolean): boolean {
|
|
2377
|
+
private notePhase(pn: i64, other: boolean): boolean {
|
|
2161
2378
|
if (other && !this.otherIsNext) {
|
|
2162
2379
|
if (this.readPhaseLowest >= 0 && pn > this.readPhaseLowest) {
|
|
2163
2380
|
this.fail(QUIC_ERROR_KEY_UPDATE, QUIC_CONN_NONE)
|
|
@@ -2192,7 +2409,7 @@ export class QuicConnection {
|
|
|
2192
2409
|
* update, before anything acknowledges the packet; the read keys move on,
|
|
2193
2410
|
* and the previous ones are kept for a probe timeout.
|
|
2194
2411
|
*/
|
|
2195
|
-
applyPhase(pn: i64): void {
|
|
2412
|
+
private applyPhase(pn: i64): void {
|
|
2196
2413
|
if (this.writePhase === this.readPhase) {
|
|
2197
2414
|
this.keyUpdates = this.keyUpdates + 1
|
|
2198
2415
|
if (!this.updateWriteKeys()) {
|
|
@@ -2224,7 +2441,7 @@ export class QuicConnection {
|
|
|
2224
2441
|
* key, IV and secret wiped. Answers whether it could, which it cannot only
|
|
2225
2442
|
* for keys `quicKeys` did not make.
|
|
2226
2443
|
*/
|
|
2227
|
-
updateWriteKeys(): boolean {
|
|
2444
|
+
private updateWriteKeys(): boolean {
|
|
2228
2445
|
const keys: QuicKeys | null = this.application.writeKeys
|
|
2229
2446
|
if (keys === null) {
|
|
2230
2447
|
return false
|
|
@@ -2253,7 +2470,7 @@ export class QuicConnection {
|
|
|
2253
2470
|
* before it ends, so the call keeps nothing in the arena. Answers the
|
|
2254
2471
|
* slot's keys, or `null` for a secret of the wrong length.
|
|
2255
2472
|
*/
|
|
2256
|
-
keysFrom(slot: QuicKeysSlot, aead: i32, held: Secret<u8[]>): QuicKeys | null {
|
|
2473
|
+
private keysFrom(slot: QuicKeysSlot, aead: i32, held: Secret<u8[]>): QuicKeys | null {
|
|
2257
2474
|
let made: boolean = false
|
|
2258
2475
|
{
|
|
2259
2476
|
using _scope = arena()
|
|
@@ -2273,7 +2490,12 @@ export class QuicConnection {
|
|
|
2273
2490
|
* block, which are zeroed before it ends. Answers the slot's keys, or
|
|
2274
2491
|
* `null`, leaving `next` as it was, for keys `quicKeys` did not make.
|
|
2275
2492
|
*/
|
|
2276
|
-
nextKeys(
|
|
2493
|
+
private nextKeys(
|
|
2494
|
+
slot: QuicKeysSlot,
|
|
2495
|
+
keys: QuicKeys,
|
|
2496
|
+
current: Secret<u8[]>,
|
|
2497
|
+
next: Secret<u8[]>
|
|
2498
|
+
): QuicKeys | null {
|
|
2277
2499
|
let made: boolean = false
|
|
2278
2500
|
{
|
|
2279
2501
|
using _scope = arena()
|
|
@@ -2298,7 +2520,7 @@ export class QuicConnection {
|
|
|
2298
2520
|
* installed and a probe timeout after each update, never while a packet is
|
|
2299
2521
|
* being opened, so what a packet's Key Phase bit says shows in no timing.
|
|
2300
2522
|
*/
|
|
2301
|
-
prepareNextReadKeys(): void {
|
|
2523
|
+
private prepareNextReadKeys(): void {
|
|
2302
2524
|
const keys: QuicKeys | null = this.application.readKeys
|
|
2303
2525
|
quicConnWipePacketKey(this.otherReadKeys)
|
|
2304
2526
|
this.otherReadKeys = null
|
|
@@ -2321,7 +2543,7 @@ export class QuicConnection {
|
|
|
2321
2543
|
* the original DCID), a short header to an active local ID. Read in place
|
|
2322
2544
|
* from `buf`.
|
|
2323
2545
|
*/
|
|
2324
|
-
addressedHere(buf: u8[], header: QuicHeader): boolean {
|
|
2546
|
+
private addressedHere(buf: u8[], header: QuicHeader): boolean {
|
|
2325
2547
|
if (header.type === QUIC_PACKET_SHORT) {
|
|
2326
2548
|
return this.cids.ownsLocalAt(buf, header.dcidStart, header.dcidLength)
|
|
2327
2549
|
}
|
|
@@ -2350,7 +2572,7 @@ export class QuicConnection {
|
|
|
2350
2572
|
* does not parse and a frame the packet type may not carry close the
|
|
2351
2573
|
* connection (RFC 9000 §12.4).
|
|
2352
2574
|
*/
|
|
2353
|
-
receiveFrames(
|
|
2575
|
+
private receiveFrames(
|
|
2354
2576
|
space: QuicConnSpace,
|
|
2355
2577
|
packetType: i32,
|
|
2356
2578
|
payload: u8[],
|
|
@@ -2387,7 +2609,7 @@ export class QuicConnection {
|
|
|
2387
2609
|
}
|
|
2388
2610
|
|
|
2389
2611
|
/** Closes the connection with `error` from a stream frame of `type`, unless it is 0. */
|
|
2390
|
-
failOn(error: i64, type: i64): void {
|
|
2612
|
+
private failOn(error: i64, type: i64): void {
|
|
2391
2613
|
if (error !== QUIC_ERROR_NO_ERROR) {
|
|
2392
2614
|
this.fail(error, type)
|
|
2393
2615
|
}
|
|
@@ -2397,7 +2619,7 @@ export class QuicConnection {
|
|
|
2397
2619
|
* One frame, which the packet type is allowed to carry: it starts at
|
|
2398
2620
|
* `payload[frameStart]`, and the packet's header is `header` in `buf`.
|
|
2399
2621
|
*/
|
|
2400
|
-
receiveFrame(
|
|
2622
|
+
private receiveFrame(
|
|
2401
2623
|
space: QuicConnSpace,
|
|
2402
2624
|
frame: QuicFrame,
|
|
2403
2625
|
payload: u8[],
|
|
@@ -2507,7 +2729,7 @@ export class QuicConnection {
|
|
|
2507
2729
|
}
|
|
2508
2730
|
|
|
2509
2731
|
/** The client closed the connection: enter the draining state, sending nothing more (RFC 9000 §10.2.2). */
|
|
2510
|
-
drain(code: i64, application: boolean): void {
|
|
2732
|
+
private drain(code: i64, application: boolean): void {
|
|
2511
2733
|
this.state = QUIC_STATE_DRAINING
|
|
2512
2734
|
this.error = code
|
|
2513
2735
|
this.errorIsApplication = application
|
|
@@ -2521,7 +2743,7 @@ export class QuicConnection {
|
|
|
2521
2743
|
* §5, §6.1, §7): each packet it newly acknowledges releases what it
|
|
2522
2744
|
* carried, and each it shows lost has its frames queued again.
|
|
2523
2745
|
*/
|
|
2524
|
-
receiveAck(space: QuicConnSpace, frame: QuicFrame): void {
|
|
2746
|
+
private receiveAck(space: QuicConnSpace, frame: QuicFrame): void {
|
|
2525
2747
|
if (frame.largest >= space.nextPn || (space.level === TLS_LEVEL_APPLICATION && this.acksSkipped(frame))) {
|
|
2526
2748
|
this.fail(QUIC_ERROR_PROTOCOL_VIOLATION, toI64(frame.type))
|
|
2527
2749
|
return
|
|
@@ -2565,7 +2787,7 @@ export class QuicConnection {
|
|
|
2565
2787
|
* `QUIC_FRAME_MAX_ACK_RANGES` is not, and loss recovery does not act on
|
|
2566
2788
|
* it either.
|
|
2567
2789
|
*/
|
|
2568
|
-
acksSkipped(frame: QuicFrame): boolean {
|
|
2790
|
+
private acksSkipped(frame: QuicFrame): boolean {
|
|
2569
2791
|
const ranges: i64[] = frame.ackRanges
|
|
2570
2792
|
for (let k: i32 = 0; k < toI32(this.skipped.length); k += 1) {
|
|
2571
2793
|
const pn: i64 = this.skipped[k]
|
|
@@ -2584,7 +2806,7 @@ export class QuicConnection {
|
|
|
2584
2806
|
* to scale is held at 2^40 microseconds first, which is still far past any
|
|
2585
2807
|
* `max_ack_delay` it is then bounded by (RFC 9002 §5.3).
|
|
2586
2808
|
*/
|
|
2587
|
-
ackDelayOf(field: i64): i64 {
|
|
2809
|
+
private ackDelayOf(field: i64): i64 {
|
|
2588
2810
|
let exponent: i64 = this.peerParameters.ackDelayExponent
|
|
2589
2811
|
if (exponent < 0 || exponent > 20) {
|
|
2590
2812
|
exponent = 3
|
|
@@ -2595,7 +2817,7 @@ export class QuicConnection {
|
|
|
2595
2817
|
}
|
|
2596
2818
|
|
|
2597
2819
|
/** Every packet of `space` that loss recovery's last call declared lost: what each carried is queued again. */
|
|
2598
|
-
packetsLost(space: QuicConnSpace, sent: QuicSentPackets): void {
|
|
2820
|
+
private packetsLost(space: QuicConnSpace, sent: QuicSentPackets): void {
|
|
2599
2821
|
for (let k: i32 = 0; k < sent.lostCount; k += 1) {
|
|
2600
2822
|
this.requeue(space, sent.lostSlot(k))
|
|
2601
2823
|
}
|
|
@@ -2608,7 +2830,7 @@ export class QuicConnection {
|
|
|
2608
2830
|
* one not queued already, and each stream control frame that still says
|
|
2609
2831
|
* something. A DATAGRAM is never in a record, so it never goes again.
|
|
2610
2832
|
*/
|
|
2611
|
-
requeue(space: QuicConnSpace, row: i32): void {
|
|
2833
|
+
private requeue(space: QuicConnSpace, row: i32): void {
|
|
2612
2834
|
space.resendCrypto(space.cryptoOffset(row), space.cryptoLength(row))
|
|
2613
2835
|
if ((space.flags(row) & QUIC_CONN_SENT_HANDSHAKE_DONE) !== 0) {
|
|
2614
2836
|
this.handshakeDonePending = true
|
|
@@ -2641,7 +2863,7 @@ export class QuicConnection {
|
|
|
2641
2863
|
}
|
|
2642
2864
|
|
|
2643
2865
|
/** A lost control frame of kind `kind` (a sequence number or a stream in `value`), queued again unless it no longer matters. */
|
|
2644
|
-
requeueControl(kind: i32, value: i64): void {
|
|
2866
|
+
private requeueControl(kind: i32, value: i64): void {
|
|
2645
2867
|
if (kind === QUIC_CONN_CONTROL_NEW_CID) {
|
|
2646
2868
|
for (const entry of this.cids.local) {
|
|
2647
2869
|
if (entry.used && entry.sequence === value) {
|
|
@@ -2666,7 +2888,7 @@ export class QuicConnection {
|
|
|
2666
2888
|
* it twice (`QUIC_CONN_HANDSHAKE_PROBES`), so that one more lost datagram
|
|
2667
2889
|
* does not cost another, doubled, probe timeout.
|
|
2668
2890
|
*/
|
|
2669
|
-
probe(): void {
|
|
2891
|
+
private probe(): void {
|
|
2670
2892
|
for (let level: i32 = 0; level < 3; level += 1) {
|
|
2671
2893
|
const space: QuicConnSpace = this.spaceAt(level)
|
|
2672
2894
|
const sent: QuicSentPackets | null = this.recovery.space(level)
|
|
@@ -2698,7 +2920,7 @@ export class QuicConnection {
|
|
|
2698
2920
|
* one datagram at most. The anti-amplification limit holds it like any
|
|
2699
2921
|
* datagram (`takeDatagramInto`).
|
|
2700
2922
|
*/
|
|
2701
|
-
resendEarly(level: i32): void {
|
|
2923
|
+
private resendEarly(level: i32): void {
|
|
2702
2924
|
if (
|
|
2703
2925
|
this.earlyResends >= QUIC_CONN_EARLY_RESENDS ||
|
|
2704
2926
|
this.initial.probes > 0 ||
|
|
@@ -2740,7 +2962,7 @@ export class QuicConnection {
|
|
|
2740
2962
|
* its alert unexpected_message (RFC 9001 §4.8). A frame too far ahead is
|
|
2741
2963
|
* CRYPTO_BUFFER_EXCEEDED.
|
|
2742
2964
|
*/
|
|
2743
|
-
receiveCrypto(space: QuicConnSpace, frame: QuicFrame, payload: u8[]): void {
|
|
2965
|
+
private receiveCrypto(space: QuicConnSpace, frame: QuicFrame, payload: u8[]): void {
|
|
2744
2966
|
const reassembly: QuicConnReassembly = this.cryptoIn
|
|
2745
2967
|
if (space.level < reassembly.level) {
|
|
2746
2968
|
if (frame.offset + toI64(frame.dataLength) > space.cryptoInDelivered) {
|
|
@@ -2765,7 +2987,7 @@ export class QuicConnection {
|
|
|
2765
2987
|
}
|
|
2766
2988
|
|
|
2767
2989
|
/** Hands TLS what now continues the CRYPTO stream, from the buffer itself; an alert closes with CRYPTO_ERROR. */
|
|
2768
|
-
feedTls(): void {
|
|
2990
|
+
private feedTls(): void {
|
|
2769
2991
|
const tls: TlsServer | null = this.tls
|
|
2770
2992
|
const reassembly: QuicConnReassembly = this.cryptoIn
|
|
2771
2993
|
if (tls === null) {
|
|
@@ -2797,7 +3019,7 @@ export class QuicConnection {
|
|
|
2797
3019
|
* PROTOCOL_VIOLATION (§3); otherwise its payload waits for
|
|
2798
3020
|
* `readDatagram`, or is dropped when the ring is full.
|
|
2799
3021
|
*/
|
|
2800
|
-
receiveDatagram(frame: QuicFrame, payload: u8[], frameStart: i32): void {
|
|
3022
|
+
private receiveDatagram(frame: QuicFrame, payload: u8[], frameStart: i32): void {
|
|
2801
3023
|
const size: i64 = toI64(frame.end - frameStart)
|
|
2802
3024
|
if (this.config.maxDatagramFrameSize === 0 || size > this.config.maxDatagramFrameSize) {
|
|
2803
3025
|
// `fin` is how the frame says it was 0x31, the type with a Length.
|
|
@@ -2815,12 +3037,12 @@ export class QuicConnection {
|
|
|
2815
3037
|
* eight bytes. Only the latest four are kept, so a burst of challenges
|
|
2816
3038
|
* cannot grow anything.
|
|
2817
3039
|
*/
|
|
2818
|
-
receivePathChallenge(frame: QuicFrame, payload: u8[]): void {
|
|
3040
|
+
private receivePathChallenge(frame: QuicFrame, payload: u8[]): void {
|
|
2819
3041
|
this.queuePathResponse(payload, frame.dataStart)
|
|
2820
3042
|
}
|
|
2821
3043
|
|
|
2822
3044
|
/** Queues a PATH_RESPONSE of the eight bytes at `data[from]` on the current path. */
|
|
2823
|
-
queuePathResponse(data: u8[], from: i32): void {
|
|
3045
|
+
private queuePathResponse(data: u8[], from: i32): void {
|
|
2824
3046
|
if (this.pathCount >= 4) {
|
|
2825
3047
|
this.pathHead = 0
|
|
2826
3048
|
this.pathCount = 0
|
|
@@ -2843,7 +3065,7 @@ export class QuicConnection {
|
|
|
2843
3065
|
* `probeAddress` is dropped, as a response may be: its data is about to
|
|
2844
3066
|
* be overwritten.
|
|
2845
3067
|
*/
|
|
2846
|
-
stageProbe(frame: QuicFrame, payload: u8[]): void {
|
|
3068
|
+
private stageProbe(frame: QuicFrame, payload: u8[]): void {
|
|
2847
3069
|
quicConnCopyAt(this.probeData, 0, payload, frame.dataStart, QUIC_PATH_DATA_SIZE)
|
|
2848
3070
|
this.probeOwed = false
|
|
2849
3071
|
this.probeStaged = true
|
|
@@ -2856,7 +3078,7 @@ export class QuicConnection {
|
|
|
2856
3078
|
* ignored; before that, none can be expected, and it is a
|
|
2857
3079
|
* PROTOCOL_VIOLATION (§19.18).
|
|
2858
3080
|
*/
|
|
2859
|
-
receivePathResponse(frame: QuicFrame, payload: u8[]): void {
|
|
3081
|
+
private receivePathResponse(frame: QuicFrame, payload: u8[]): void {
|
|
2860
3082
|
if (this.challengesDrawn === 0) {
|
|
2861
3083
|
this.fail(QUIC_ERROR_PROTOCOL_VIOLATION, toI64(QUIC_FRAME_PATH_RESPONSE))
|
|
2862
3084
|
return
|
|
@@ -2991,7 +3213,7 @@ export class QuicConnection {
|
|
|
2991
3213
|
* when they do not. The streams take the client's limits from them, and
|
|
2992
3214
|
* the datagrams its `max_datagram_frame_size`.
|
|
2993
3215
|
*/
|
|
2994
|
-
checkPeerParameters(tls: TlsServer): boolean {
|
|
3216
|
+
private checkPeerParameters(tls: TlsServer): boolean {
|
|
2995
3217
|
const p: QuicTransportParameters = quicParseTransportParametersInto(
|
|
2996
3218
|
this.parsedParameters,
|
|
2997
3219
|
tls.clientTransportParameters,
|
|
@@ -3023,7 +3245,7 @@ export class QuicConnection {
|
|
|
3023
3245
|
}
|
|
3024
3246
|
|
|
3025
3247
|
/** Discards a space's keys and CRYPTO state (RFC 9001 §4.9), wiping the keys. */
|
|
3026
|
-
discard(space: QuicConnSpace): void {
|
|
3248
|
+
private discard(space: QuicConnSpace): void {
|
|
3027
3249
|
if (space.discarded) {
|
|
3028
3250
|
return
|
|
3029
3251
|
}
|
|
@@ -3049,7 +3271,7 @@ export class QuicConnection {
|
|
|
3049
3271
|
* the seed and need no more entropy. It runs in the connection's HMAC
|
|
3050
3272
|
* scratch inside an arena block, and wipes the MAC and the scratch.
|
|
3051
3273
|
*/
|
|
3052
|
-
deriveConnectionId(sequence: i64): void {
|
|
3274
|
+
private deriveConnectionId(sequence: i64): void {
|
|
3053
3275
|
const mac: HmacSha256Scratch = this.kdf.sha256
|
|
3054
3276
|
using _scope = arena()
|
|
3055
3277
|
const counter: u8[] = new Array<u8>(8)
|
|
@@ -3080,7 +3302,7 @@ export class QuicConnection {
|
|
|
3080
3302
|
* in the slot's scratch and copied into the table, so issuing keeps
|
|
3081
3303
|
* nothing (QUIC-3).
|
|
3082
3304
|
*/
|
|
3083
|
-
topUpConnectionIds(): void {
|
|
3305
|
+
private topUpConnectionIds(): void {
|
|
3084
3306
|
if (!this.handshakeComplete) {
|
|
3085
3307
|
return
|
|
3086
3308
|
}
|
|
@@ -3107,7 +3329,13 @@ export class QuicConnection {
|
|
|
3107
3329
|
}
|
|
3108
3330
|
}
|
|
3109
3331
|
|
|
3110
|
-
/**
|
|
3332
|
+
/**
|
|
3333
|
+
* What CertificateVerify must sign while the handshake waits for it, else `null` (see
|
|
3334
|
+
* `TlsServer.signatureInput`).
|
|
3335
|
+
*
|
|
3336
|
+
* @returns The bytes to sign with the certificate's key, or `null` when no signature is owed or the
|
|
3337
|
+
* connection has closed.
|
|
3338
|
+
*/
|
|
3111
3339
|
signatureInput(): u8[] | null {
|
|
3112
3340
|
const tls: TlsServer | null = this.tls
|
|
3113
3341
|
if (tls === null || this.closed()) {
|
|
@@ -3121,6 +3349,12 @@ export class QuicConnection {
|
|
|
3121
3349
|
* rest of the server's flight. Answers 0, or the CRYPTO_ERROR the
|
|
3122
3350
|
* connection closed with when TLS refused it (a call at the wrong time, or
|
|
3123
3351
|
* an empty signature: `internal_error`).
|
|
3352
|
+
*
|
|
3353
|
+
* @param signature The certificate key's signature over `signatureInput()`, in the encoding the
|
|
3354
|
+
* negotiated TLS signature scheme uses.
|
|
3355
|
+
* @returns 0 when TLS took the signature, or the error the connection has closed with (also when it
|
|
3356
|
+
* was already closed). It is also 0, with nothing signed, when the connection has no TLS session
|
|
3357
|
+
* and has not failed.
|
|
3124
3358
|
*/
|
|
3125
3359
|
sign(signature: u8[]): i64 {
|
|
3126
3360
|
const tls: TlsServer | null = this.tls
|
|
@@ -3143,7 +3377,7 @@ export class QuicConnection {
|
|
|
3143
3377
|
* for none. Until the client's transport parameters are read, the server's
|
|
3144
3378
|
* own alone.
|
|
3145
3379
|
*/
|
|
3146
|
-
idleTimeout(): i64 {
|
|
3380
|
+
private idleTimeout(): i64 {
|
|
3147
3381
|
const local: i64 = this.config.maxIdleTimeout
|
|
3148
3382
|
const peer: i64 = this.peerParameters.maxIdleTimeout
|
|
3149
3383
|
let timeout: i64 = local
|
|
@@ -3160,7 +3394,11 @@ export class QuicConnection {
|
|
|
3160
3394
|
return timeout < floor ? floor : timeout
|
|
3161
3395
|
}
|
|
3162
3396
|
|
|
3163
|
-
/**
|
|
3397
|
+
/**
|
|
3398
|
+
* When the idle timeout passes, or -1 when there is none or the timer has not started.
|
|
3399
|
+
*
|
|
3400
|
+
* @returns The time in the caller's milliseconds, or -1.
|
|
3401
|
+
*/
|
|
3164
3402
|
idleDeadline(): i64 {
|
|
3165
3403
|
const timeout: i64 = this.idleTimeout()
|
|
3166
3404
|
return timeout >= 0 && this.idleSince >= 0 ? this.idleSince + timeout : -1
|
|
@@ -3177,6 +3415,8 @@ export class QuicConnection {
|
|
|
3177
3415
|
* gone out (`takeDatagram` sends it), once a closed connection's keys are
|
|
3178
3416
|
* wiped, and with no idle timeout, nothing in flight, no update pending
|
|
3179
3417
|
* and no path being validated.
|
|
3418
|
+
*
|
|
3419
|
+
* @returns The time in the caller's milliseconds at which to call `handleTimer`, or -1.
|
|
3180
3420
|
*/
|
|
3181
3421
|
deadline(): i64 {
|
|
3182
3422
|
if (this.closed()) {
|
|
@@ -3207,6 +3447,8 @@ export class QuicConnection {
|
|
|
3207
3447
|
* Whether the anti-amplification limit stops the server sending (RFC 9000
|
|
3208
3448
|
* §8.1): the client's address is not validated and three times what it
|
|
3209
3449
|
* sent leaves no room for a whole datagram.
|
|
3450
|
+
*
|
|
3451
|
+
* @returns True while the address (or a new path being validated) has no budget left for a datagram.
|
|
3210
3452
|
*/
|
|
3211
3453
|
amplificationBlocked(): boolean {
|
|
3212
3454
|
return (
|
|
@@ -3220,7 +3462,7 @@ export class QuicConnection {
|
|
|
3220
3462
|
* what came from it since the connection moved there, less what went
|
|
3221
3463
|
* (RFC 9000 §9.3.1, §8.1). Unlimited, as `QUIC_MAX_VARINT`, on a validated path.
|
|
3222
3464
|
*/
|
|
3223
|
-
pathBudget(): i64 {
|
|
3465
|
+
private pathBudget(): i64 {
|
|
3224
3466
|
return this.pathValidating ? this.pathReceived * 3 - this.pathSent : QUIC_MAX_VARINT
|
|
3225
3467
|
}
|
|
3226
3468
|
|
|
@@ -3237,6 +3479,8 @@ export class QuicConnection {
|
|
|
3237
3479
|
* §6.2.4): `takeDatagram` then sends it. `receive` and `takeDatagram` run
|
|
3238
3480
|
* it themselves. Time never runs backwards here: an earlier `now` than one
|
|
3239
3481
|
* already given counts as that one.
|
|
3482
|
+
*
|
|
3483
|
+
* @param now The caller's monotonic time in milliseconds.
|
|
3240
3484
|
*/
|
|
3241
3485
|
handleTimer(now: i64): void {
|
|
3242
3486
|
this.runClocks(now)
|
|
@@ -3247,7 +3491,7 @@ export class QuicConnection {
|
|
|
3247
3491
|
* `handleTimer`'s idle timeout, key retention and the end of the closing
|
|
3248
3492
|
* or draining period, which `receive` runs before it reads a datagram.
|
|
3249
3493
|
*/
|
|
3250
|
-
runClocks(now: i64): void {
|
|
3494
|
+
private runClocks(now: i64): void {
|
|
3251
3495
|
if (now > this.now) {
|
|
3252
3496
|
this.now = now
|
|
3253
3497
|
}
|
|
@@ -3287,7 +3531,7 @@ export class QuicConnection {
|
|
|
3287
3531
|
* move, so there is always an address to go back to: the case where
|
|
3288
3532
|
* there is none, which RFC 9000 §9.3.2 closes silently, cannot arise.
|
|
3289
3533
|
*/
|
|
3290
|
-
runPathClock(): void {
|
|
3534
|
+
private runPathClock(): void {
|
|
3291
3535
|
if (!this.pathValidating) {
|
|
3292
3536
|
return
|
|
3293
3537
|
}
|
|
@@ -3311,7 +3555,7 @@ export class QuicConnection {
|
|
|
3311
3555
|
* from elsewhere cannot move the connection, nor take the server's
|
|
3312
3556
|
* flight. A carrier that passes no address leaves every path rule off.
|
|
3313
3557
|
*/
|
|
3314
|
-
notePath(address: u8[]): boolean {
|
|
3558
|
+
private notePath(address: u8[]): boolean {
|
|
3315
3559
|
this.arrivalOther = false
|
|
3316
3560
|
this.migrateOwed = false
|
|
3317
3561
|
this.probeStaged = false
|
|
@@ -3343,7 +3587,7 @@ export class QuicConnection {
|
|
|
3343
3587
|
* (`takeProbeInto`). A datagram that authenticated nothing does neither.
|
|
3344
3588
|
* What came from the path being validated adds to its limit.
|
|
3345
3589
|
*/
|
|
3346
|
-
afterPath(counted: boolean, len: i32): void {
|
|
3590
|
+
private afterPath(counted: boolean, len: i32): void {
|
|
3347
3591
|
if (!counted) {
|
|
3348
3592
|
return
|
|
3349
3593
|
}
|
|
@@ -3378,7 +3622,7 @@ export class QuicConnection {
|
|
|
3378
3622
|
* NAT rebinding never does (§9.5). Answers whether the challenge staged
|
|
3379
3623
|
* in `probeData` is already queued on the new path (`sendResponsesBack`).
|
|
3380
3624
|
*/
|
|
3381
|
-
migrate(address: u8[]): boolean {
|
|
3625
|
+
private migrate(address: u8[]): boolean {
|
|
3382
3626
|
const swapped: boolean = this.sendResponsesBack()
|
|
3383
3627
|
quicConnCopyAt(this.pathCurrent, 0, address, 0, QUIC_CONN_ADDRESS_SIZE)
|
|
3384
3628
|
if (quicConnSameAddress(address, this.pathValidated, false)) {
|
|
@@ -3404,7 +3648,7 @@ export class QuicConnection {
|
|
|
3404
3648
|
* and the answer is true; otherwise false. A response still owed on the
|
|
3405
3649
|
* probe route is never overwritten: the ring's are dropped instead.
|
|
3406
3650
|
*/
|
|
3407
|
-
sendResponsesBack(): boolean {
|
|
3651
|
+
private sendResponsesBack(): boolean {
|
|
3408
3652
|
if (this.pathCount <= 0) {
|
|
3409
3653
|
return false
|
|
3410
3654
|
}
|
|
@@ -3438,7 +3682,7 @@ export class QuicConnection {
|
|
|
3438
3682
|
* them with the two before, and owes the challenge; its resend is due a
|
|
3439
3683
|
* probe timeout later.
|
|
3440
3684
|
*/
|
|
3441
|
-
drawChallenge(): void {
|
|
3685
|
+
private drawChallenge(): void {
|
|
3442
3686
|
this.deriveConnectionId(QUIC_CONN_CHALLENGE_SEQUENCE + this.challengesDrawn)
|
|
3443
3687
|
const slot: i32 = toI32(this.challengesDrawn % toI64(QUIC_CONN_CHALLENGES))
|
|
3444
3688
|
quicConnCopyAt(this.challengeData, slot * QUIC_PATH_DATA_SIZE, this.cidScratch, 0, QUIC_PATH_DATA_SIZE)
|
|
@@ -3458,7 +3702,7 @@ export class QuicConnection {
|
|
|
3458
3702
|
* network path behind a rebinding NAT (§9.4); ECN is tested again either
|
|
3459
3703
|
* way (§13.4.2).
|
|
3460
3704
|
*/
|
|
3461
|
-
pathConfirmed(): void {
|
|
3705
|
+
private pathConfirmed(): void {
|
|
3462
3706
|
const portOnly: boolean = quicConnSameAddress(this.pathCurrent, this.pathValidated, true)
|
|
3463
3707
|
quicConnCopyAt(this.pathValidated, 0, this.pathCurrent, 0, QUIC_CONN_ADDRESS_SIZE)
|
|
3464
3708
|
this.endValidation()
|
|
@@ -3469,7 +3713,7 @@ export class QuicConnection {
|
|
|
3469
3713
|
}
|
|
3470
3714
|
|
|
3471
3715
|
/** Stops validating a path: no challenge is owed, kept or timed. */
|
|
3472
|
-
endValidation(): void {
|
|
3716
|
+
private endValidation(): void {
|
|
3473
3717
|
this.pathValidating = false
|
|
3474
3718
|
this.challengeOwed = false
|
|
3475
3719
|
this.challengeCount = 0
|
|
@@ -3480,14 +3724,14 @@ export class QuicConnection {
|
|
|
3480
3724
|
}
|
|
3481
3725
|
|
|
3482
3726
|
/** Adds `n` bytes sent to the path being validated's count. */
|
|
3483
|
-
notePathSent(n: i32): void {
|
|
3727
|
+
private notePathSent(n: i32): void {
|
|
3484
3728
|
if (this.pathValidating) {
|
|
3485
3729
|
this.pathSent = this.pathSent + toI64(n)
|
|
3486
3730
|
}
|
|
3487
3731
|
}
|
|
3488
3732
|
|
|
3489
3733
|
/** Clears every path field for a new connection, in the arrays the slot keeps. */
|
|
3490
|
-
forgetPath(): void {
|
|
3734
|
+
private forgetPath(): void {
|
|
3491
3735
|
quicConnZeroAt(this.pathCurrent)
|
|
3492
3736
|
quicConnZeroAt(this.pathValidated)
|
|
3493
3737
|
quicConnZeroAt(this.pathArrival)
|
|
@@ -3511,6 +3755,9 @@ export class QuicConnection {
|
|
|
3511
3755
|
* address `receiveWindowFrom` last moved it to, or the first Initial's.
|
|
3512
3756
|
* A carrier sends every datagram of `takeDatagramInto` here; it is empty
|
|
3513
3757
|
* (all zero) for a connection fed by `receiveWindow` alone.
|
|
3758
|
+
*
|
|
3759
|
+
* @returns The connection's own address array, borrowed: it changes in place when the connection
|
|
3760
|
+
* moves, so copy it to keep it.
|
|
3514
3761
|
*/
|
|
3515
3762
|
sendAddress(): u8[] {
|
|
3516
3763
|
return this.pathCurrent
|
|
@@ -3524,6 +3771,13 @@ export class QuicConnection {
|
|
|
3524
3771
|
* path (§8.1), whichever is less. The carrier sends it to
|
|
3525
3772
|
* `probeAddress`, before `takeDatagramInto`'s datagrams. It is answered
|
|
3526
3773
|
* once and never sent again (§13.3).
|
|
3774
|
+
*
|
|
3775
|
+
* @param out Where the datagram is written.
|
|
3776
|
+
* @param at Where in `out` it starts; `out` needs `QUIC_CONN_DATAGRAM_SIZE` bytes from here.
|
|
3777
|
+
* @param now The caller's monotonic time in milliseconds; timers due by then run first.
|
|
3778
|
+
* @returns The datagram's length in bytes, or 0 when no PATH_RESPONSE is owed, the connection is closed,
|
|
3779
|
+
* the handshake is not complete, the room is short, or the packet cannot be built within the path's budget (the
|
|
3780
|
+
* owed PATH_RESPONSE is then dropped).
|
|
3527
3781
|
*/
|
|
3528
3782
|
takeProbeInto(out: u8[], at: i32, now: i64): i32 {
|
|
3529
3783
|
this.handleTimer(now)
|
|
@@ -3551,7 +3805,7 @@ export class QuicConnection {
|
|
|
3551
3805
|
}
|
|
3552
3806
|
|
|
3553
3807
|
/** `takeProbeInto`'s packet, of `size` bytes at `out[at]`, built and sealed; 0 when it does not fit. */
|
|
3554
|
-
buildProbe(out: u8[], at: i32, size: i32): i32 {
|
|
3808
|
+
private buildProbe(out: u8[], at: i32, size: i32): i32 {
|
|
3555
3809
|
const space: QuicConnSpace = this.application
|
|
3556
3810
|
const overhead: i32 = this.overhead(space)
|
|
3557
3811
|
if (overhead === 0 || size < overhead + 1 + QUIC_PATH_DATA_SIZE) {
|
|
@@ -3575,7 +3829,7 @@ export class QuicConnection {
|
|
|
3575
3829
|
}
|
|
3576
3830
|
|
|
3577
3831
|
/** Loss recovery's timer, if it is due (RFC 9002 §6.2, A.9). */
|
|
3578
|
-
runRecoveryTimer(): void {
|
|
3832
|
+
private runRecoveryTimer(): void {
|
|
3579
3833
|
if (this.closed() || this.state === QUIC_STATE_WAIT_INITIAL) {
|
|
3580
3834
|
return
|
|
3581
3835
|
}
|
|
@@ -3600,6 +3854,8 @@ export class QuicConnection {
|
|
|
3600
3854
|
* or answered it less than a probe timeout ago, so the next read keys are
|
|
3601
3855
|
* not ready), and until the client has acknowledged a packet sent with the
|
|
3602
3856
|
* current keys.
|
|
3857
|
+
*
|
|
3858
|
+
* @returns True when the update started, false when it may not yet.
|
|
3603
3859
|
*/
|
|
3604
3860
|
updateKeys(): boolean {
|
|
3605
3861
|
if (
|
|
@@ -3620,7 +3876,7 @@ export class QuicConnection {
|
|
|
3620
3876
|
* `QUIC_CONN_SKIP_SEQUENCE`, so a client that saw where the last gaps fell
|
|
3621
3877
|
* cannot tell where the next will.
|
|
3622
3878
|
*/
|
|
3623
|
-
scheduleSkip(from: i64): void {
|
|
3879
|
+
private scheduleSkip(from: i64): void {
|
|
3624
3880
|
this.deriveConnectionId(QUIC_CONN_SKIP_SEQUENCE + this.skipsDrawn)
|
|
3625
3881
|
this.skipsDrawn = this.skipsDrawn + 1
|
|
3626
3882
|
let draw: i64 = 0
|
|
@@ -3639,6 +3895,8 @@ export class QuicConnection {
|
|
|
3639
3895
|
* stopped, or it has room to write again after a short write — or -1
|
|
3640
3896
|
* when there is none. Each stream comes up once however much happened;
|
|
3641
3897
|
* read and write it until it has nothing more to say.
|
|
3898
|
+
*
|
|
3899
|
+
* @returns A stream ID, or -1.
|
|
3642
3900
|
*/
|
|
3643
3901
|
nextStreamEvent(): i64 {
|
|
3644
3902
|
return this.streams.nextEvent()
|
|
@@ -3650,6 +3908,9 @@ export class QuicConnection {
|
|
|
3650
3908
|
* `QUIC_STREAM_ERR_STATE` when not connected, or `QUIC_STREAM_ERR_LIMIT`
|
|
3651
3909
|
* when the client's MAX_STREAMS is reached (STREAMS_BLOCKED then goes out)
|
|
3652
3910
|
* or `localStreams` of the server's are open.
|
|
3911
|
+
*
|
|
3912
|
+
* @param bidirectional True for a stream both sides send on, false for one only the server sends on.
|
|
3913
|
+
* @returns The new stream's ID, or a negative `QUIC_STREAM_ERR_*`.
|
|
3653
3914
|
*/
|
|
3654
3915
|
openStream(bidirectional: boolean): i64 {
|
|
3655
3916
|
if (this.state !== QUIC_STATE_CONNECTED) {
|
|
@@ -3667,6 +3928,13 @@ export class QuicConnection {
|
|
|
3667
3928
|
* only the client sends on, one already finished or reset, or one the
|
|
3668
3929
|
* client asked to stop (STOP_SENDING, which this side answered with
|
|
3669
3930
|
* RESET_STREAM).
|
|
3931
|
+
*
|
|
3932
|
+
* @param id The stream's ID.
|
|
3933
|
+
* @param buf The bytes to send; copied into the stream's buffer, so the caller may reuse it.
|
|
3934
|
+
* @param from Where the bytes start in `buf`.
|
|
3935
|
+
* @param length How many bytes to offer.
|
|
3936
|
+
* @param fin True to finish the sending side once all `length` bytes are taken.
|
|
3937
|
+
* @returns The number of bytes taken, 0 to `length`, or a negative `QUIC_STREAM_ERR_*`.
|
|
3670
3938
|
*/
|
|
3671
3939
|
streamWrite(id: i64, buf: u8[], from: i32, length: i32, fin: boolean): i32 {
|
|
3672
3940
|
if (this.state !== QUIC_STATE_CONNECTED) {
|
|
@@ -3681,12 +3949,26 @@ export class QuicConnection {
|
|
|
3681
3949
|
* once every byte up to the FIN was read, `QUIC_STREAM_ERR_RESET` once the
|
|
3682
3950
|
* client reset the stream (its code is the stream's `resetCode`), or
|
|
3683
3951
|
* another `QUIC_STREAM_ERR_*`. Reading is what gives the client more credit.
|
|
3952
|
+
*
|
|
3953
|
+
* @param id The stream's ID.
|
|
3954
|
+
* @param buf Where the bytes go.
|
|
3955
|
+
* @param at Where in `buf` they start.
|
|
3956
|
+
* @param length The most bytes to read.
|
|
3957
|
+
* @returns The number of bytes read, 0, `QUIC_STREAM_END`, or a negative `QUIC_STREAM_ERR_*`.
|
|
3684
3958
|
*/
|
|
3685
3959
|
streamRead(id: i64, buf: u8[], at: i32, length: i32): i32 {
|
|
3686
3960
|
return this.streams.read(id, buf, at, length)
|
|
3687
3961
|
}
|
|
3688
3962
|
|
|
3689
|
-
/**
|
|
3963
|
+
/**
|
|
3964
|
+
* Abandons stream `id`'s sending side with application error `code` (RESET_STREAM). Answers
|
|
3965
|
+
* `QUIC_STREAM_OK` or a `QUIC_STREAM_ERR_*`.
|
|
3966
|
+
*
|
|
3967
|
+
* @param id The stream's ID; it must be one the server sends on.
|
|
3968
|
+
* @param code The application's error code, sent to the client in RESET_STREAM.
|
|
3969
|
+
* @returns `QUIC_STREAM_OK`, or a negative `QUIC_STREAM_ERR_*` (`QUIC_STREAM_ERR_STATE` when not
|
|
3970
|
+
* connected).
|
|
3971
|
+
*/
|
|
3690
3972
|
streamReset(id: i64, code: i64): i32 {
|
|
3691
3973
|
if (this.state !== QUIC_STATE_CONNECTED) {
|
|
3692
3974
|
return QUIC_STREAM_ERR_STATE
|
|
@@ -3694,7 +3976,15 @@ export class QuicConnection {
|
|
|
3694
3976
|
return this.streams.resetStream(id, code)
|
|
3695
3977
|
}
|
|
3696
3978
|
|
|
3697
|
-
/**
|
|
3979
|
+
/**
|
|
3980
|
+
* Asks the client to stop sending on stream `id`, with application error `code` (STOP_SENDING).
|
|
3981
|
+
* Answers `QUIC_STREAM_OK` or a `QUIC_STREAM_ERR_*`.
|
|
3982
|
+
*
|
|
3983
|
+
* @param id The stream's ID; it must be one the client sends on.
|
|
3984
|
+
* @param code The application's error code, sent to the client in STOP_SENDING.
|
|
3985
|
+
* @returns `QUIC_STREAM_OK`, or a negative `QUIC_STREAM_ERR_*` (`QUIC_STREAM_ERR_STATE` when not
|
|
3986
|
+
* connected).
|
|
3987
|
+
*/
|
|
3698
3988
|
streamStopSending(id: i64, code: i64): i32 {
|
|
3699
3989
|
if (this.state !== QUIC_STATE_CONNECTED) {
|
|
3700
3990
|
return QUIC_STREAM_ERR_STATE
|
|
@@ -3707,6 +3997,8 @@ export class QuicConnection {
|
|
|
3707
3997
|
* none: the all-at-once form of `nextStreamEvent` and `streamRead`, which
|
|
3708
3998
|
* allocates the run it answers. `fin` marks the last of its stream; a
|
|
3709
3999
|
* stream the client reset is passed over.
|
|
4000
|
+
*
|
|
4001
|
+
* @returns A new run the caller owns, or `null` when no stream has data or a FIN waiting.
|
|
3710
4002
|
*/
|
|
3711
4003
|
readStream(): QuicStreamData | null {
|
|
3712
4004
|
let id: i64 = this.streams.nextEvent()
|
|
@@ -3736,6 +4028,12 @@ export class QuicConnection {
|
|
|
3736
4028
|
* connected, the stream is unknown, its side is already finished (or the
|
|
3737
4029
|
* client stopped it), or the data would pass the credit the client gave
|
|
3738
4030
|
* for the stream or the connection, or the room in the stream's buffer.
|
|
4031
|
+
*
|
|
4032
|
+
* @param id The stream's ID.
|
|
4033
|
+
* @param data The bytes to send; copied, so the caller may reuse it.
|
|
4034
|
+
* @param fin True to finish the sending side after `data`.
|
|
4035
|
+
* @returns `QUIC_STREAM_OK` when every byte was queued, or a negative `QUIC_STREAM_ERR_*` with nothing
|
|
4036
|
+
* queued.
|
|
3739
4037
|
*/
|
|
3740
4038
|
writeStream(id: i64, data: u8[], fin: boolean): i32 {
|
|
3741
4039
|
if (this.state !== QUIC_STATE_CONNECTED) {
|
|
@@ -3767,6 +4065,8 @@ export class QuicConnection {
|
|
|
3767
4065
|
* client's `max_datagram_frame_size` with the frame's type and Length, and
|
|
3768
4066
|
* a 1-RTT packet of `QUIC_CONN_DATAGRAM_SIZE` with the longest packet
|
|
3769
4067
|
* number; 0 when the client takes none, or the server sends none.
|
|
4068
|
+
*
|
|
4069
|
+
* @returns The payload size in bytes, 0 up to a little under `QUIC_CONN_DATAGRAM_SIZE`.
|
|
3770
4070
|
*/
|
|
3771
4071
|
maxDatagramPayload(): i32 {
|
|
3772
4072
|
const entry: QuicCidEntry | null = this.cids.currentPeerEntry()
|
|
@@ -3798,6 +4098,11 @@ export class QuicConnection {
|
|
|
3798
4098
|
* none, `QUIC_DATAGRAM_ERR_TOO_BIG` for a frame past the client's limit or
|
|
3799
4099
|
* a payload past `maxDatagramPayload()`, or `QUIC_DATAGRAM_ERR_FULL` while
|
|
3800
4100
|
* the ring holds `QUIC_CONN_DATAGRAM_QUEUE` waiting.
|
|
4101
|
+
*
|
|
4102
|
+
* @param buf The array holding the payload; copied into the ring, so the caller may reuse it.
|
|
4103
|
+
* @param from Where the payload starts in `buf`.
|
|
4104
|
+
* @param length The payload's length in bytes.
|
|
4105
|
+
* @returns `QUIC_DATAGRAM_OK`, or one of the `QUIC_DATAGRAM_ERR_*` codes above with nothing queued.
|
|
3801
4106
|
*/
|
|
3802
4107
|
sendDatagram(buf: u8[], from: i32, length: i32): i32 {
|
|
3803
4108
|
if (
|
|
@@ -3825,6 +4130,11 @@ export class QuicConnection {
|
|
|
3825
4130
|
* at most `cap` bytes, and forgets it. Answers its length,
|
|
3826
4131
|
* `QUIC_DATAGRAM_NONE` when none is waiting, or `QUIC_DATAGRAM_ERR_ROOM`,
|
|
3827
4132
|
* keeping it, when it does not fit.
|
|
4133
|
+
*
|
|
4134
|
+
* @param buf Where the payload goes.
|
|
4135
|
+
* @param at Where in `buf` it starts.
|
|
4136
|
+
* @param cap The most bytes `buf` has room for from `at`.
|
|
4137
|
+
* @returns The payload's length in bytes, `QUIC_DATAGRAM_NONE`, or `QUIC_DATAGRAM_ERR_ROOM`.
|
|
3828
4138
|
*/
|
|
3829
4139
|
readDatagram(buf: u8[], at: i32, cap: i32): i32 {
|
|
3830
4140
|
return this.datagramsIn.pop(buf, at, cap)
|
|
@@ -3835,6 +4145,9 @@ export class QuicConnection {
|
|
|
3835
4145
|
/**
|
|
3836
4146
|
* The next datagram to send, or `null` when nothing is due: the
|
|
3837
4147
|
* allocating form of `takeDatagramInto`, which a test or a recording uses.
|
|
4148
|
+
*
|
|
4149
|
+
* @param now The caller's monotonic time in milliseconds.
|
|
4150
|
+
* @returns A new array the caller owns, at most `QUIC_CONN_DATAGRAM_SIZE` bytes, or `null`.
|
|
3838
4151
|
*/
|
|
3839
4152
|
takeDatagram(now: i64): u8[] | null {
|
|
3840
4153
|
const out: u8[] = new Array<u8>(QUIC_CONN_DATAGRAM_SIZE)
|
|
@@ -3863,6 +4176,11 @@ export class QuicConnection {
|
|
|
3863
4176
|
* inside an arena block: nothing it does allocates past the call. This is
|
|
3864
4177
|
* not paced: a carrier that paces calls `nish/net/quic-listener`'s
|
|
3865
4178
|
* `quicListenerTakeFlight` instead.
|
|
4179
|
+
*
|
|
4180
|
+
* @param out Where the datagram is written.
|
|
4181
|
+
* @param at Where in `out` it starts; `out` needs `QUIC_CONN_DATAGRAM_SIZE` bytes from here.
|
|
4182
|
+
* @param now The caller's monotonic time in milliseconds; timers due by then run first.
|
|
4183
|
+
* @returns The datagram's length in bytes, at most `QUIC_CONN_DATAGRAM_SIZE`, or 0.
|
|
3866
4184
|
*/
|
|
3867
4185
|
takeDatagramInto(out: u8[], at: i32, now: i64): i32 {
|
|
3868
4186
|
this.handleTimer(now)
|
|
@@ -3908,7 +4226,7 @@ export class QuicConnection {
|
|
|
3908
4226
|
* the packet number due to be skipped is (RFC 9000 §21.4): remembered,
|
|
3909
4227
|
* never sealed nor recorded, and the next skip drawn.
|
|
3910
4228
|
*/
|
|
3911
|
-
beforeDatagram(): void {
|
|
4229
|
+
private beforeDatagram(): void {
|
|
3912
4230
|
const limit: i64 = this.confidentialityLimit
|
|
3913
4231
|
if (this.sealedUnderKey >= limit - limit / 4) {
|
|
3914
4232
|
this.updateKeys()
|
|
@@ -3931,7 +4249,7 @@ export class QuicConnection {
|
|
|
3931
4249
|
* last padded when an Initial elicits, then each sealed where it lies.
|
|
3932
4250
|
* Answers the datagram's length, or 0 when no space had anything.
|
|
3933
4251
|
*/
|
|
3934
|
-
buildDatagram(out: u8[], at: i32): i32 {
|
|
4252
|
+
private buildDatagram(out: u8[], at: i32): i32 {
|
|
3935
4253
|
let remaining: i32 = QUIC_CONN_DATAGRAM_SIZE
|
|
3936
4254
|
// A path being validated has its own 3x limit (§9.3.1), which the
|
|
3937
4255
|
// datagram may not pass; `amplificationBlocked` kept it above the floor.
|
|
@@ -4031,7 +4349,7 @@ export class QuicConnection {
|
|
|
4031
4349
|
* its packet number, and the AEAD tag. 0 when the space cannot send: no
|
|
4032
4350
|
* keys, discarded, or no packet number length for its next number.
|
|
4033
4351
|
*/
|
|
4034
|
-
overhead(space: QuicConnSpace): i32 {
|
|
4352
|
+
private overhead(space: QuicConnSpace): i32 {
|
|
4035
4353
|
if (space.writeKeys === null || space.discarded) {
|
|
4036
4354
|
return 0
|
|
4037
4355
|
}
|
|
@@ -4062,7 +4380,7 @@ export class QuicConnection {
|
|
|
4062
4380
|
* written to the space's staging row, and `stagedEliciting` says whether
|
|
4063
4381
|
* anything elicits an acknowledgement.
|
|
4064
4382
|
*/
|
|
4065
|
-
buildPayloadInto(
|
|
4383
|
+
private buildPayloadInto(
|
|
4066
4384
|
space: QuicConnSpace,
|
|
4067
4385
|
out: u8[],
|
|
4068
4386
|
start: i32,
|
|
@@ -4101,7 +4419,7 @@ export class QuicConnection {
|
|
|
4101
4419
|
* level's kept stream, then those not sent yet. The level's CRYPTO stream
|
|
4102
4420
|
* is kept whole, so a byte's index in `cryptoOut` is its offset.
|
|
4103
4421
|
*/
|
|
4104
|
-
buildCrypto(space: QuicConnSpace, out: u8[], at: i32, end: i32): i32 {
|
|
4422
|
+
private buildCrypto(space: QuicConnSpace, out: u8[], at: i32, end: i32): i32 {
|
|
4105
4423
|
if (space.cryptoResendLow >= 0) {
|
|
4106
4424
|
const low: i64 = space.cryptoResendLow
|
|
4107
4425
|
const want: i32 = toI32(space.cryptoResendHigh - low)
|
|
@@ -4157,7 +4475,7 @@ export class QuicConnection {
|
|
|
4157
4475
|
* (RFC 9000 §9.3); the path's own 3x limit still bounds them, and a
|
|
4158
4476
|
* challenge is drawn at most once a probe timeout.
|
|
4159
4477
|
*/
|
|
4160
|
-
buildPathFrames(space: QuicConnSpace, out: u8[], start: i32, end: i32): i32 {
|
|
4478
|
+
private buildPathFrames(space: QuicConnSpace, out: u8[], start: i32, end: i32): i32 {
|
|
4161
4479
|
let at: i32 = start
|
|
4162
4480
|
while (this.pathCount > 0 && end - at >= 9) {
|
|
4163
4481
|
const next: i32 = quicPutPathData(
|
|
@@ -4205,7 +4523,7 @@ export class QuicConnection {
|
|
|
4205
4523
|
* the packet's record: `QUIC_CONN_PACKET_CONTROL` control frames and
|
|
4206
4524
|
* `QUIC_CONN_PACKET_STREAMS` STREAM frames, and every DATAGRAM that fits.
|
|
4207
4525
|
*/
|
|
4208
|
-
buildApplication(space: QuicConnSpace, out: u8[], start: i32, end: i32): i32 {
|
|
4526
|
+
private buildApplication(space: QuicConnSpace, out: u8[], start: i32, end: i32): i32 {
|
|
4209
4527
|
let at: i32 = start
|
|
4210
4528
|
if (this.handshakeDonePending && at < end) {
|
|
4211
4529
|
at = quicPutTypeOnly(out, at, end, QUIC_FRAME_HANDSHAKE_DONE)
|
|
@@ -4281,7 +4599,7 @@ export class QuicConnection {
|
|
|
4281
4599
|
* the packet's length, or 0 when it could not be sealed, which only keys
|
|
4282
4600
|
* `quicKeys` did not make cause.
|
|
4283
4601
|
*/
|
|
4284
|
-
sealAt(space: QuicConnSpace, out: u8[], start: i32, payloadEnd: i32): i32 {
|
|
4602
|
+
private sealAt(space: QuicConnSpace, out: u8[], start: i32, payloadEnd: i32): i32 {
|
|
4285
4603
|
// RFC 9001 §6.6: at the confidentiality limit, with no key update made
|
|
4286
4604
|
// (`beforeDatagram`), the connection closes, and no packet, its
|
|
4287
4605
|
// CONNECTION_CLOSE included, is sealed under the key again.
|
|
@@ -4347,7 +4665,7 @@ export class QuicConnection {
|
|
|
4347
4665
|
* what the packet carried is queued again at once, as though lost.
|
|
4348
4666
|
* Answers the slot recovery recorded it in, or -1.
|
|
4349
4667
|
*/
|
|
4350
|
-
recordSent(space: QuicConnSpace, pn: i64, size: i32): i32 {
|
|
4668
|
+
private recordSent(space: QuicConnSpace, pn: i64, size: i32): i32 {
|
|
4351
4669
|
if (!space.stagedEliciting) {
|
|
4352
4670
|
return -1
|
|
4353
4671
|
}
|
|
@@ -4371,7 +4689,7 @@ export class QuicConnection {
|
|
|
4371
4689
|
}
|
|
4372
4690
|
|
|
4373
4691
|
/** An acknowledged packet in row `row`: each stream chunk and stream control frame it carried is settled. */
|
|
4374
|
-
untrack(space: QuicConnSpace, row: i32): void {
|
|
4692
|
+
private untrack(space: QuicConnSpace, row: i32): void {
|
|
4375
4693
|
const streams: i32 = space.streamCount(row)
|
|
4376
4694
|
for (let j: i32 = 0; j < streams; j += 1) {
|
|
4377
4695
|
const at: i32 = row * QUIC_CONN_PACKET_STREAMS + j
|
|
@@ -4408,7 +4726,7 @@ export class QuicConnection {
|
|
|
4408
4726
|
* 0x1d (§12.4). Before the handshake is complete no 1-RTT packet carries
|
|
4409
4727
|
* it, because the client cannot yet read one.
|
|
4410
4728
|
*/
|
|
4411
|
-
takeCloseInto(out: u8[], at: i32): i32 {
|
|
4729
|
+
private takeCloseInto(out: u8[], at: i32): i32 {
|
|
4412
4730
|
if (this.closeSent) {
|
|
4413
4731
|
return 0
|
|
4414
4732
|
}
|
|
@@ -4486,7 +4804,7 @@ export class QuicConnection {
|
|
|
4486
4804
|
* reset tokens and `TlsServer`'s expected client Finished and resumption
|
|
4487
4805
|
* secret.
|
|
4488
4806
|
*/
|
|
4489
|
-
wipeAll(): void {
|
|
4807
|
+
private wipeAll(): void {
|
|
4490
4808
|
this.discard(this.initial)
|
|
4491
4809
|
this.discard(this.handshake)
|
|
4492
4810
|
this.discard(this.application)
|
|
@@ -4523,7 +4841,7 @@ export class QuicConnection {
|
|
|
4523
4841
|
* and so `release()`, `reset`, the idle timeout and the end of the
|
|
4524
4842
|
* closing or draining period.
|
|
4525
4843
|
*/
|
|
4526
|
-
wipe(): void {
|
|
4844
|
+
private wipe(): void {
|
|
4527
4845
|
wipe(this.ephemeral)
|
|
4528
4846
|
wipe(this.readSecret256)
|
|
4529
4847
|
wipe(this.nextReadSecret256)
|