@moq/net 0.4.0 → 0.4.2
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/announced.d.ts +14 -0
- package/announced.d.ts.map +1 -1
- package/announced.js.map +1 -1
- package/broadcast.d.ts +27 -10
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +47 -21
- package/broadcast.js.map +1 -1
- package/connection/accept.js +14 -4
- package/connection/accept.js.map +1 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +14 -4
- package/connection/connect.js.map +1 -1
- package/connection/established.d.ts +2 -1
- package/connection/established.d.ts.map +1 -1
- package/connection/established.js.map +1 -1
- package/connection/forward.js +61 -47
- package/connection/forward.js.map +1 -1
- package/connection/goaway.d.ts +34 -0
- package/connection/goaway.d.ts.map +1 -0
- package/connection/goaway.js +176 -0
- package/connection/goaway.js.map +1 -0
- package/connection/handshake.d.ts +5 -2
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +45 -10
- package/connection/handshake.js.map +1 -1
- package/connection/pool.d.ts +24 -11
- package/connection/pool.d.ts.map +1 -1
- package/connection/pool.js +50 -18
- package/connection/pool.js.map +1 -1
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +189 -35
- package/connection/reload.js.map +1 -1
- package/error.d.ts +11 -0
- package/error.d.ts.map +1 -1
- package/error.js +35 -0
- package/error.js.map +1 -1
- package/errors.d.ts +1 -1
- package/errors.d.ts.map +1 -1
- package/errors.js +1 -1
- package/errors.js.map +1 -1
- package/group.d.ts.map +1 -1
- package/group.js +5 -4
- package/group.js.map +1 -1
- package/hop.d.ts +8 -0
- package/hop.d.ts.map +1 -1
- package/hop.js +16 -0
- package/hop.js.map +1 -1
- package/ietf/adapter.d.ts +9 -1
- package/ietf/adapter.d.ts.map +1 -1
- package/ietf/adapter.js +46 -17
- package/ietf/adapter.js.map +1 -1
- package/ietf/cluster.d.ts +3 -3
- package/ietf/cluster.js +3 -3
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts +1 -1
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +118 -41
- package/ietf/connection.js.map +1 -1
- package/ietf/error.js +27 -2
- package/ietf/error.js.map +1 -1
- package/ietf/fetch.d.ts +7 -20
- package/ietf/fetch.d.ts.map +1 -1
- package/ietf/fetch.js +52 -22
- package/ietf/fetch.js.map +1 -1
- package/ietf/filter.d.ts +2 -0
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +4 -0
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts +9 -1
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +20 -0
- package/ietf/goaway.js.map +1 -1
- package/ietf/hidden.d.ts +2 -0
- package/ietf/hidden.d.ts.map +1 -0
- package/ietf/hidden.js +30 -0
- package/ietf/hidden.js.map +1 -0
- package/ietf/index.d.ts +2 -1
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +2 -1
- package/ietf/index.js.map +1 -1
- package/ietf/object.d.ts +15 -8
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +54 -36
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +12 -0
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +82 -12
- package/ietf/parameters.js.map +1 -1
- package/ietf/properties.d.ts +1 -0
- package/ietf/properties.d.ts.map +1 -1
- package/ietf/properties.js +14 -0
- package/ietf/properties.js.map +1 -1
- package/ietf/publish.d.ts +19 -2
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +40 -6
- package/ietf/publish.js.map +1 -1
- package/ietf/publish_namespace.d.ts +2 -2
- package/ietf/publish_namespace.js +2 -2
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.js +383 -214
- package/ietf/publisher.js.map +1 -1
- package/ietf/subscribe.d.ts +7 -1
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +25 -18
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +8 -2
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +20 -11
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +226 -88
- package/ietf/subscriber.js.map +1 -1
- package/ietf/token.d.ts +2 -0
- package/ietf/token.d.ts.map +1 -0
- package/ietf/token.js +99 -0
- package/ietf/token.js.map +1 -0
- package/ietf/track.d.ts +4 -0
- package/ietf/track.d.ts.map +1 -1
- package/ietf/track.js +6 -20
- package/ietf/track.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/internal.d.ts +19 -3
- package/internal.d.ts.map +1 -1
- package/internal.js +43 -0
- package/internal.js.map +1 -1
- package/lite/announce.d.ts +46 -2
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +133 -15
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts +1 -1
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +30 -9
- package/lite/connection.js.map +1 -1
- package/lite/datagram.d.ts +3 -2
- package/lite/datagram.d.ts.map +1 -1
- package/lite/datagram.js +7 -8
- package/lite/datagram.js.map +1 -1
- package/lite/group.d.ts +12 -8
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +37 -16
- package/lite/group.js.map +1 -1
- package/lite/message.d.ts +2 -2
- package/lite/message.d.ts.map +1 -1
- package/lite/message.js +14 -5
- package/lite/message.js.map +1 -1
- package/lite/publisher.js +174 -133
- package/lite/publisher.js.map +1 -1
- package/lite/setup.d.ts +1 -1
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +22 -19
- package/lite/setup.js.map +1 -1
- package/lite/subscribe.d.ts +10 -4
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +20 -10
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +10 -2
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +333 -188
- package/lite/subscriber.js.map +1 -1
- package/lite/version.d.ts +11 -0
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +56 -0
- package/lite/version.js.map +1 -1
- package/origin.d.ts +46 -19
- package/origin.d.ts.map +1 -1
- package/origin.js +529 -189
- package/origin.js.map +1 -1
- package/package.json +8 -4
- package/stream.d.ts +79 -14
- package/stream.d.ts.map +1 -1
- package/stream.js +375 -133
- package/stream.js.map +1 -1
- package/tail.d.ts +18 -0
- package/tail.d.ts.map +1 -0
- package/tail.js +167 -0
- package/tail.js.map +1 -0
- package/track.d.ts +46 -7
- package/track.d.ts.map +1 -1
- package/track.js +263 -101
- package/track.js.map +1 -1
- package/util/abort.d.ts +2 -0
- package/util/abort.d.ts.map +1 -0
- package/util/abort.js +20 -0
- package/util/abort.js.map +1 -0
- package/util/u64.d.ts +39 -0
- package/util/u64.d.ts.map +1 -0
- package/util/u64.js +83 -0
- package/util/u64.js.map +1 -0
- package/util/varint.d.ts +29 -0
- package/util/varint.d.ts.map +1 -0
- package/util/varint.js +198 -0
- package/util/varint.js.map +1 -0
- package/varint.d.ts +10 -6
- package/varint.d.ts.map +1 -1
- package/varint.js +40 -237
- package/varint.js.map +1 -1
- package/wire.d.ts +19 -3
- package/wire.d.ts.map +1 -1
- package/wire.js.map +1 -1
- package/ietf/control.d.ts +0 -135
- package/ietf/control.d.ts.map +0 -1
- package/ietf/control.js +0 -242
- package/ietf/control.js.map +0 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/* @ts-self-types="./goaway.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* GOAWAY handling for the reconnect loop: the peer's drain signal and the policy for the
|
|
4
|
+
* redirect it may name. Mirrors `Goaway` and `Redirect` in `moq_tokio::connection`.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { RefusedRedirect } from "../error.js";
|
|
9
|
+
import * as Time from "../time.js";
|
|
10
|
+
/** The handover cap when the caller names none. */
|
|
11
|
+
export const DEFAULT_HANDOVER = Time.Milli(10_000);
|
|
12
|
+
/**
|
|
13
|
+
* How long a drained session may keep serving: the cap, lowered to the peer's deadline when
|
|
14
|
+
* it named a positive one. Absence is not a zero-length handover.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function handover(cap, timeout) {
|
|
19
|
+
return timeout !== undefined && timeout > 0 ? Time.Milli(Math.min(cap, timeout)) : cap;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The URL a redirect is judged against. A WebSocket fallback that won the race is the host
|
|
23
|
+
* we dialed; the primary URL was not, so same-host must not treat it as the current peer.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export function dialed(primary, transport, websocket) {
|
|
28
|
+
return transport === "websocket" && websocket ? websocket : primary;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether a certificate pin constrains this session. The pin is a WebTransport option, so it
|
|
32
|
+
* holds the host only when that transport is the one that connected.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export function pinnedTransport(transport, configured) {
|
|
37
|
+
return configured && transport === "webtransport";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The URL a GOAWAY assigns: `undefined` keeps the current URL (the peer named none, or the
|
|
41
|
+
* policy ignores a URI it could parse), and a URL replaces it. Throws {@link RefusedRedirect}
|
|
42
|
+
* for an explicit URI the policy will not follow, including a malformed one under `ignore`.
|
|
43
|
+
*
|
|
44
|
+
* `pinned` is a certificate pin on the connection, which can only verify the host it was
|
|
45
|
+
* configured for, so it refuses a host change even under `follow`.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export function target(policy, uri, current, pinned) {
|
|
50
|
+
if (uri === "")
|
|
51
|
+
return undefined;
|
|
52
|
+
// The URI can carry credentials, so the error names the reason, never the URI.
|
|
53
|
+
// Parse before `ignore`: a malformed redirect is terminal even when the policy
|
|
54
|
+
// would otherwise stay on the current URL.
|
|
55
|
+
let next;
|
|
56
|
+
try {
|
|
57
|
+
next = new URL(uri);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw new RefusedRedirect("the GOAWAY URI is malformed");
|
|
61
|
+
}
|
|
62
|
+
if (policy === "ignore")
|
|
63
|
+
return undefined;
|
|
64
|
+
if (schemeTier(next.protocol) < schemeTier(current.protocol)) {
|
|
65
|
+
throw new RefusedRedirect("the GOAWAY redirect downgrades the scheme");
|
|
66
|
+
}
|
|
67
|
+
// Only as far as the URL itself says: a name is dialed, never resolved here, so this
|
|
68
|
+
// refuses a peer naming a local address outright, not one hiding it behind a hostname.
|
|
69
|
+
// That gap is why `same-host` is the default.
|
|
70
|
+
if (isLocal(next) && !isLocal(current)) {
|
|
71
|
+
throw new RefusedRedirect("the GOAWAY redirect widens reachability to a local address");
|
|
72
|
+
}
|
|
73
|
+
// Host only, not the full authority: the port is what a peer legitimately moves us
|
|
74
|
+
// across when it hands off to a sibling process on the same box.
|
|
75
|
+
const sameHost = next.hostname === current.hostname;
|
|
76
|
+
if (policy === "same-host" && !sameHost) {
|
|
77
|
+
throw new RefusedRedirect("the GOAWAY redirect leaves the current host");
|
|
78
|
+
}
|
|
79
|
+
if (pinned && !sameHost) {
|
|
80
|
+
throw new RefusedRedirect("the GOAWAY redirect leaves the host a certificate pin verifies");
|
|
81
|
+
}
|
|
82
|
+
return next;
|
|
83
|
+
}
|
|
84
|
+
/** Rank a scheme so a redirect cannot silently drop encryption; unknown schemes rank lowest. */
|
|
85
|
+
function schemeTier(protocol) {
|
|
86
|
+
switch (protocol) {
|
|
87
|
+
case "https:":
|
|
88
|
+
case "wss:":
|
|
89
|
+
case "moqt:":
|
|
90
|
+
case "moql:":
|
|
91
|
+
return 2;
|
|
92
|
+
case "http:":
|
|
93
|
+
case "ws:":
|
|
94
|
+
case "tcp:":
|
|
95
|
+
return 1;
|
|
96
|
+
default:
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Whether a URL says it names something only reachable from this host or network. A judgement
|
|
102
|
+
* about the URL, not about where a dial lands: `false` means "not local on its face".
|
|
103
|
+
*
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
export function isLocal(url) {
|
|
107
|
+
const host = url.hostname.toLowerCase();
|
|
108
|
+
// No host at all, e.g. a `unix:` socket path.
|
|
109
|
+
if (host === "")
|
|
110
|
+
return true;
|
|
111
|
+
if (host === "localhost" || host.endsWith(".localhost"))
|
|
112
|
+
return true;
|
|
113
|
+
if (host.startsWith("[") && host.endsWith("]")) {
|
|
114
|
+
const segments = parseIpv6(host.slice(1, -1));
|
|
115
|
+
return segments !== undefined && isLocalV6(segments);
|
|
116
|
+
}
|
|
117
|
+
const v4 = parseIpv4(host);
|
|
118
|
+
return v4 !== undefined && isLocalV4(v4);
|
|
119
|
+
}
|
|
120
|
+
function parseIpv4(host) {
|
|
121
|
+
const parts = host.split(".");
|
|
122
|
+
if (parts.length !== 4)
|
|
123
|
+
return undefined;
|
|
124
|
+
const octets = parts.map((part) => (/^\d{1,3}$/.test(part) ? Number(part) : Number.NaN));
|
|
125
|
+
return octets.every((octet) => octet <= 255) ? octets : undefined;
|
|
126
|
+
}
|
|
127
|
+
function isLocalV4([a, b, c, d]) {
|
|
128
|
+
return (a === 127 ||
|
|
129
|
+
a === 10 ||
|
|
130
|
+
(a === 172 && b >= 16 && b <= 31) ||
|
|
131
|
+
(a === 192 && b === 168) ||
|
|
132
|
+
(a === 169 && b === 254) ||
|
|
133
|
+
(a === 0 && b === 0 && c === 0 && d === 0));
|
|
134
|
+
}
|
|
135
|
+
/** Parse an IPv6 literal (without brackets) into its eight 16-bit segments. */
|
|
136
|
+
function parseIpv6(host) {
|
|
137
|
+
// Drop a zone id; it scopes the address without changing it.
|
|
138
|
+
let text = host.split("%")[0] ?? "";
|
|
139
|
+
// A trailing dotted quad (`::ffff:127.0.0.1`) spells the last two segments.
|
|
140
|
+
const lastColon = text.lastIndexOf(":");
|
|
141
|
+
const quad = parseIpv4(text.slice(lastColon + 1));
|
|
142
|
+
if (quad) {
|
|
143
|
+
const [a = 0, b = 0, c = 0, d = 0] = quad;
|
|
144
|
+
const word = (hi, lo) => ((hi << 8) | lo).toString(16);
|
|
145
|
+
text = `${text.slice(0, lastColon + 1)}${word(a, b)}:${word(c, d)}`;
|
|
146
|
+
}
|
|
147
|
+
const halves = text.split("::");
|
|
148
|
+
if (halves.length > 2)
|
|
149
|
+
return undefined;
|
|
150
|
+
const words = (part) => (part === "" ? [] : part.split(":"));
|
|
151
|
+
const head = words(halves[0] ?? "");
|
|
152
|
+
const rest = halves.length === 2 ? words(halves[1] ?? "") : [];
|
|
153
|
+
const missing = 8 - head.length - rest.length;
|
|
154
|
+
if (halves.length === 2 ? missing < 0 : missing !== 0)
|
|
155
|
+
return undefined;
|
|
156
|
+
const all = [...head, ...Array(missing).fill("0"), ...rest];
|
|
157
|
+
const segments = all.map((word) => (/^[0-9a-f]{1,4}$/i.test(word) ? Number.parseInt(word, 16) : Number.NaN));
|
|
158
|
+
return segments.some(Number.isNaN) ? undefined : segments;
|
|
159
|
+
}
|
|
160
|
+
function isLocalV6(segments) {
|
|
161
|
+
// An IPv4-mapped address reaches the same host as the v4 it wraps.
|
|
162
|
+
if (segments.slice(0, 5).every((s) => s === 0) && segments[5] === 0xffff) {
|
|
163
|
+
const [hi = 0, lo = 0] = segments.slice(6);
|
|
164
|
+
return isLocalV4([hi >> 8, hi & 0xff, lo >> 8, lo & 0xff]);
|
|
165
|
+
}
|
|
166
|
+
const first = segments[0] ?? 0;
|
|
167
|
+
const zeroPrefix = segments.slice(0, 7).every((s) => s === 0);
|
|
168
|
+
const last = segments[7] ?? 0;
|
|
169
|
+
return (
|
|
170
|
+
// Loopback (::1) and unspecified (::).
|
|
171
|
+
(zeroPrefix && (last === 1 || last === 0)) ||
|
|
172
|
+
// Unique local (fc00::/7) and link local (fe80::/10).
|
|
173
|
+
(first & 0xfe00) === 0xfc00 ||
|
|
174
|
+
(first & 0xffc0) === 0xfe80);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=goaway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goaway.js","sourceRoot":"","sources":["../../src/connection/goaway.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAoCnC,mDAAmD;AACnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAe,EAAE,OAAoB;IAC7D,OAAO,OAAO,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACxF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,OAAY,EAAE,SAAuC,EAAE,SAAe;IAC5F,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,SAAuC,EAAE,UAAmB;IAC3F,OAAO,UAAU,IAAI,SAAS,KAAK,cAAc,CAAC;AACnD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,MAAM,CAAC,MAAgB,EAAE,GAAW,EAAE,OAAY,EAAE,MAAe;IAClF,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAEjC,+EAA+E;IAC/E,+EAA+E;IAC/E,2CAA2C;IAC3C,IAAI,IAAS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H,CAAC","sourcesContent":["/**\n * GOAWAY handling for the reconnect loop: the peer's drain signal and the policy for the\n * redirect it may name. Mirrors `Goaway` and `Redirect` in `moq_tokio::connection`.\n *\n * @module\n */\nimport { RefusedRedirect } from \"../error.ts\";\nimport * as Time from \"../time.ts\";\n\n/** A peer's GOAWAY as a session received it. */\nexport interface Drain {\n\t/** Where to reconnect, including any credentials it needs. Empty means the same endpoint. */\n\treadonly uri: string;\n\t/** When the peer force-closes the session. Undefined when the wire carried none. */\n\treadonly timeout?: Time.Milli;\n}\n\n/**\n * What to do with the URI a peer names in its GOAWAY.\n *\n * - `same-host` (the default) follows it only onto the host already dialed, so a peer can move\n * the connection between ports or schemes but not to another host.\n * - `follow` also lets the peer name the host. The name is dialed as written, so only use it\n * with a relay trusted not to point the connection into the local network.\n * - `ignore` reconnects to the current URL whatever the peer names.\n *\n * A malformed or refused URI ends the connection with {@link RefusedRedirect}.\n */\nexport type Redirect = \"follow\" | \"same-host\" | \"ignore\";\n\n/** How a reconnecting connection reacts to a peer's GOAWAY. */\nexport interface GoawayProps {\n\t/** What to do with the URI the peer names (default: `same-host`). */\n\tredirect?: Redirect;\n\n\t/**\n\t * How long the old session keeps serving after the GOAWAY while the replacement dials\n\t * (default: 10000ms). A cap: a shorter deadline from the peer wins, a longer one does not\n\t * extend it.\n\t */\n\thandover?: Time.Milli;\n}\n\n/** The handover cap when the caller names none. */\nexport const DEFAULT_HANDOVER = Time.Milli(10_000);\n\n/**\n * How long a drained session may keep serving: the cap, lowered to the peer's deadline when\n * it named a positive one. Absence is not a zero-length handover.\n *\n * @internal\n */\nexport function handover(cap: Time.Milli, timeout?: Time.Milli): Time.Milli {\n\treturn timeout !== undefined && timeout > 0 ? Time.Milli(Math.min(cap, timeout)) : cap;\n}\n\n/**\n * The URL a redirect is judged against. A WebSocket fallback that won the race is the host\n * we dialed; the primary URL was not, so same-host must not treat it as the current peer.\n *\n * @internal\n */\nexport function dialed(primary: URL, transport: \"webtransport\" | \"websocket\", websocket?: URL): URL {\n\treturn transport === \"websocket\" && websocket ? websocket : primary;\n}\n\n/**\n * Whether a certificate pin constrains this session. The pin is a WebTransport option, so it\n * holds the host only when that transport is the one that connected.\n *\n * @internal\n */\nexport function pinnedTransport(transport: \"webtransport\" | \"websocket\", configured: boolean): boolean {\n\treturn configured && transport === \"webtransport\";\n}\n\n/**\n * The URL a GOAWAY assigns: `undefined` keeps the current URL (the peer named none, or the\n * policy ignores a URI it could parse), and a URL replaces it. Throws {@link RefusedRedirect}\n * for an explicit URI the policy will not follow, including a malformed one under `ignore`.\n *\n * `pinned` is a certificate pin on the connection, which can only verify the host it was\n * configured for, so it refuses a host change even under `follow`.\n *\n * @internal\n */\nexport function target(policy: Redirect, uri: string, current: URL, pinned: boolean): URL | undefined {\n\tif (uri === \"\") return undefined;\n\n\t// The URI can carry credentials, so the error names the reason, never the URI.\n\t// Parse before `ignore`: a malformed redirect is terminal even when the policy\n\t// would otherwise stay on the current URL.\n\tlet next: URL;\n\ttry {\n\t\tnext = new URL(uri);\n\t} catch {\n\t\tthrow new RefusedRedirect(\"the GOAWAY URI is malformed\");\n\t}\n\tif (policy === \"ignore\") return undefined;\n\n\tif (schemeTier(next.protocol) < schemeTier(current.protocol)) {\n\t\tthrow new RefusedRedirect(\"the GOAWAY redirect downgrades the scheme\");\n\t}\n\n\t// Only as far as the URL itself says: a name is dialed, never resolved here, so this\n\t// refuses a peer naming a local address outright, not one hiding it behind a hostname.\n\t// That gap is why `same-host` is the default.\n\tif (isLocal(next) && !isLocal(current)) {\n\t\tthrow new RefusedRedirect(\"the GOAWAY redirect widens reachability to a local address\");\n\t}\n\n\t// Host only, not the full authority: the port is what a peer legitimately moves us\n\t// across when it hands off to a sibling process on the same box.\n\tconst sameHost = next.hostname === current.hostname;\n\tif (policy === \"same-host\" && !sameHost) {\n\t\tthrow new RefusedRedirect(\"the GOAWAY redirect leaves the current host\");\n\t}\n\tif (pinned && !sameHost) {\n\t\tthrow new RefusedRedirect(\"the GOAWAY redirect leaves the host a certificate pin verifies\");\n\t}\n\n\treturn next;\n}\n\n/** Rank a scheme so a redirect cannot silently drop encryption; unknown schemes rank lowest. */\nfunction schemeTier(protocol: string): number {\n\tswitch (protocol) {\n\t\tcase \"https:\":\n\t\tcase \"wss:\":\n\t\tcase \"moqt:\":\n\t\tcase \"moql:\":\n\t\t\treturn 2;\n\t\tcase \"http:\":\n\t\tcase \"ws:\":\n\t\tcase \"tcp:\":\n\t\t\treturn 1;\n\t\tdefault:\n\t\t\treturn 0;\n\t}\n}\n\n/**\n * Whether a URL says it names something only reachable from this host or network. A judgement\n * about the URL, not about where a dial lands: `false` means \"not local on its face\".\n *\n * @internal\n */\nexport function isLocal(url: URL): boolean {\n\tconst host = url.hostname.toLowerCase();\n\t// No host at all, e.g. a `unix:` socket path.\n\tif (host === \"\") return true;\n\tif (host === \"localhost\" || host.endsWith(\".localhost\")) return true;\n\n\tif (host.startsWith(\"[\") && host.endsWith(\"]\")) {\n\t\tconst segments = parseIpv6(host.slice(1, -1));\n\t\treturn segments !== undefined && isLocalV6(segments);\n\t}\n\n\tconst v4 = parseIpv4(host);\n\treturn v4 !== undefined && isLocalV4(v4);\n}\n\nfunction parseIpv4(host: string): number[] | undefined {\n\tconst parts = host.split(\".\");\n\tif (parts.length !== 4) return undefined;\n\tconst octets = parts.map((part) => (/^\\d{1,3}$/.test(part) ? Number(part) : Number.NaN));\n\treturn octets.every((octet) => octet <= 255) ? octets : undefined;\n}\n\nfunction isLocalV4([a, b, c, d]: number[]): boolean {\n\treturn (\n\t\ta === 127 ||\n\t\ta === 10 ||\n\t\t(a === 172 && b >= 16 && b <= 31) ||\n\t\t(a === 192 && b === 168) ||\n\t\t(a === 169 && b === 254) ||\n\t\t(a === 0 && b === 0 && c === 0 && d === 0)\n\t);\n}\n\n/** Parse an IPv6 literal (without brackets) into its eight 16-bit segments. */\nfunction parseIpv6(host: string): number[] | undefined {\n\t// Drop a zone id; it scopes the address without changing it.\n\tlet text = host.split(\"%\")[0] ?? \"\";\n\n\t// A trailing dotted quad (`::ffff:127.0.0.1`) spells the last two segments.\n\tconst lastColon = text.lastIndexOf(\":\");\n\tconst quad = parseIpv4(text.slice(lastColon + 1));\n\tif (quad) {\n\t\tconst [a = 0, b = 0, c = 0, d = 0] = quad;\n\t\tconst word = (hi: number, lo: number) => ((hi << 8) | lo).toString(16);\n\t\ttext = `${text.slice(0, lastColon + 1)}${word(a, b)}:${word(c, d)}`;\n\t}\n\n\tconst halves = text.split(\"::\");\n\tif (halves.length > 2) return undefined;\n\tconst words = (part: string) => (part === \"\" ? [] : part.split(\":\"));\n\tconst head = words(halves[0] ?? \"\");\n\tconst rest = halves.length === 2 ? words(halves[1] ?? \"\") : [];\n\tconst missing = 8 - head.length - rest.length;\n\tif (halves.length === 2 ? missing < 0 : missing !== 0) return undefined;\n\n\tconst all = [...head, ...Array<string>(missing).fill(\"0\"), ...rest];\n\tconst segments = all.map((word) => (/^[0-9a-f]{1,4}$/i.test(word) ? Number.parseInt(word, 16) : Number.NaN));\n\treturn segments.some(Number.isNaN) ? undefined : segments;\n}\n\nfunction isLocalV6(segments: number[]): boolean {\n\t// An IPv4-mapped address reaches the same host as the v4 it wraps.\n\tif (segments.slice(0, 5).every((s) => s === 0) && segments[5] === 0xffff) {\n\t\tconst [hi = 0, lo = 0] = segments.slice(6);\n\t\treturn isLocalV4([hi >> 8, hi & 0xff, lo >> 8, lo & 0xff]);\n\t}\n\tconst first = segments[0] ?? 0;\n\tconst zeroPrefix = segments.slice(0, 7).every((s) => s === 0);\n\tconst last = segments[7] ?? 0;\n\treturn (\n\t\t// Loopback (::1) and unspecified (::).\n\t\t(zeroPrefix && (last === 1 || last === 0)) ||\n\t\t// Unique local (fc00::/7) and link local (fe80::/10).\n\t\t(first & 0xfe00) === 0xfc00 ||\n\t\t(first & 0xffc0) === 0xfe80\n\t);\n}\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as Ietf from "../ietf/index";
|
|
2
|
-
import { Stream } from "../stream";
|
|
2
|
+
import { Reader, Stream } from "../stream";
|
|
3
3
|
/**
|
|
4
4
|
* Draft-17+ SETUP exchange. Each side opens a uni stream, writes its Setup
|
|
5
5
|
* message, and reads the peer's Setup off an incoming uni stream. The two
|
|
6
6
|
* halves run in parallel and the protocol is symmetric, so both `connect`
|
|
7
7
|
* (client) and `accept` (server) use this same function.
|
|
8
8
|
*
|
|
9
|
-
* Returns the control stream
|
|
9
|
+
* Returns the control stream, the uni streams that arrived before it (see
|
|
10
|
+
* {@link receiveSetup}), plus what the peer's SETUP declared: whether it requires
|
|
10
11
|
* solicitation, which decides whether we announce namespaces unprompted (see the MoQ Solicit
|
|
11
12
|
* extension), and its Hop ID (see the MoQ Cluster extension). We declare both ourselves on
|
|
12
13
|
* every session: we send SUBSCRIBE_NAMESPACE for each prefix we want, so an unsolicited
|
|
@@ -15,7 +16,9 @@ import { Stream } from "../stream";
|
|
|
15
16
|
*/
|
|
16
17
|
export declare function exchangeSetup(transport: WebTransport, version: Ietf.IetfVersion, implementation: string): Promise<{
|
|
17
18
|
control: Stream;
|
|
19
|
+
early: Reader[];
|
|
18
20
|
solicit: boolean | undefined;
|
|
21
|
+
hidden: boolean;
|
|
19
22
|
cluster: Ietf.Cluster.Hops;
|
|
20
23
|
}>;
|
|
21
24
|
//# sourceMappingURL=handshake.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/connection/handshake.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../../src/connection/handshake.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAyB,MAAM,cAAc,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CAClC,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;CAC3B,CAAC,CA0BD"}
|
package/connection/handshake.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/* @ts-self-types="./handshake.d.ts" */
|
|
2
|
+
import { StreamError } from "../error.js";
|
|
2
3
|
import { randomHop } from "../hop.js";
|
|
3
4
|
import * as Ietf from "../ietf/index.js";
|
|
4
|
-
import { Reader, Stream, Writer } from "../stream.js";
|
|
5
|
+
import { Reader, Stream, UnexpectedEnd, Writer } from "../stream.js";
|
|
5
6
|
/**
|
|
6
7
|
* Draft-17+ SETUP exchange. Each side opens a uni stream, writes its Setup
|
|
7
8
|
* message, and reads the peer's Setup off an incoming uni stream. The two
|
|
8
9
|
* halves run in parallel and the protocol is symmetric, so both `connect`
|
|
9
10
|
* (client) and `accept` (server) use this same function.
|
|
10
11
|
*
|
|
11
|
-
* Returns the control stream
|
|
12
|
+
* Returns the control stream, the uni streams that arrived before it (see
|
|
13
|
+
* {@link receiveSetup}), plus what the peer's SETUP declared: whether it requires
|
|
12
14
|
* solicitation, which decides whether we announce namespaces unprompted (see the MoQ Solicit
|
|
13
15
|
* extension), and its Hop ID (see the MoQ Cluster extension). We declare both ourselves on
|
|
14
16
|
* every session: we send SUBSCRIBE_NAMESPACE for each prefix we want, so an unsolicited
|
|
@@ -20,6 +22,7 @@ export async function exchangeSetup(transport, version, implementation) {
|
|
|
20
22
|
const params = new Ietf.SetupOptions();
|
|
21
23
|
params.setBytes(Ietf.SetupOption.Implementation, encoder.encode(implementation));
|
|
22
24
|
Ietf.solicitIntoSetup(params);
|
|
25
|
+
Ietf.hiddenIntoSetup(params);
|
|
23
26
|
// One id per session, like the moq-lite connection: nothing in this process forwards
|
|
24
27
|
// between sessions, so there is nothing for a shared id to detect.
|
|
25
28
|
const self = randomHop();
|
|
@@ -31,7 +34,9 @@ export async function exchangeSetup(transport, version, implementation) {
|
|
|
31
34
|
]);
|
|
32
35
|
return {
|
|
33
36
|
control: new Stream({ writer, reader: received.reader }),
|
|
37
|
+
early: received.early,
|
|
34
38
|
solicit: received.solicit,
|
|
39
|
+
hidden: received.hidden,
|
|
35
40
|
cluster: { self, peer: received.cluster },
|
|
36
41
|
};
|
|
37
42
|
}
|
|
@@ -43,21 +48,51 @@ async function sendSetup(transport, version, setupMsg) {
|
|
|
43
48
|
await setupMsg.encode(writer, version);
|
|
44
49
|
return writer;
|
|
45
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Read the peer's SETUP off its uni stream. Any other uni stream that beats it (padding,
|
|
53
|
+
* or group data for a subscription the peer already holds) is held, type unread, for the
|
|
54
|
+
* session to classify once it starts: the drafts say to buffer early data rather than
|
|
55
|
+
* reject it. QUIC stream credit bounds how many can pile up.
|
|
56
|
+
*/
|
|
46
57
|
async function receiveSetup(transport, version) {
|
|
47
58
|
const uniReader = transport.incomingUnidirectionalStreams.getReader();
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
const early = [];
|
|
60
|
+
let reader;
|
|
61
|
+
try {
|
|
62
|
+
for (;;) {
|
|
63
|
+
const next = await uniReader.read();
|
|
64
|
+
if (next.done)
|
|
65
|
+
throw new Error("no incoming uni stream for SETUP");
|
|
66
|
+
const stream = new Reader(next.value, undefined, version);
|
|
67
|
+
// A stream that ended or reset before its full type is that stream's failure, not the session's.
|
|
68
|
+
// Malformed bytes are still the peer's fault, so a bad type fails the handshake.
|
|
69
|
+
if (await stream.done().catch(() => true))
|
|
70
|
+
continue;
|
|
71
|
+
// Full width, so an unknown type past 2^53 is held for the classifier to refuse.
|
|
72
|
+
const streamType = await stream.peekU62().catch((err) => {
|
|
73
|
+
if (err instanceof StreamError || err instanceof UnexpectedEnd)
|
|
74
|
+
return undefined;
|
|
75
|
+
throw err;
|
|
76
|
+
});
|
|
77
|
+
if (streamType === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
if (streamType === BigInt(Ietf.Setup.id)) {
|
|
80
|
+
reader = stream;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
early.push(stream);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
uniReader.releaseLock();
|
|
56
88
|
}
|
|
89
|
+
await reader.u53(); // the SETUP type, peeked above
|
|
57
90
|
const setup = await Ietf.Setup.decode(reader, version);
|
|
58
91
|
return {
|
|
59
92
|
reader,
|
|
93
|
+
early,
|
|
60
94
|
solicit: Ietf.solicitFromSetup(setup.parameters),
|
|
95
|
+
hidden: Ietf.hiddenFromSetup(setup.parameters),
|
|
61
96
|
cluster: Ietf.Cluster.fromSetup(setup.parameters, version),
|
|
62
97
|
};
|
|
63
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.js","sourceRoot":"","sources":["../../src/connection/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"handshake.js","sourceRoot":"","sources":["../../src/connection/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAY,SAAS,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,c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E,SAAS;YACvC,IAAI,UAAU,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC1C,MAAM,GAAG,MAAM,CAAC;gBAChB,MAAM;YACP,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;IACF,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,WAAW,EAAE,CAAC;IACzB,CAAC;IAED,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,+BAA+B;IACnD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEvD,OAAO;QACN,MAAM;QACN,KAAK;QACL,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC;QAChD,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC;QAC9C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;KAC1D,CAAC;AACH,CAAC","sourcesContent":["import { StreamError } from \"../error.ts\";\nimport { type Hop, randomHop } from \"../hop.ts\";\nimport * as Ietf from \"../ietf/index.ts\";\nimport { Reader, Stream, UnexpectedEnd, Writer } from \"../stream.ts\";\n\n/**\n * Draft-17+ SETUP exchange. Each side opens a uni stream, writes its Setup\n * message, and reads the peer's Setup off an incoming uni stream. The two\n * halves run in parallel and the protocol is symmetric, so both `connect`\n * (client) and `accept` (server) use this same function.\n *\n * Returns the control stream, the uni streams that arrived before it (see\n * {@link receiveSetup}), plus what the peer's SETUP declared: whether it requires\n * solicitation, which decides whether we announce namespaces unprompted (see the MoQ Solicit\n * extension), and its Hop ID (see the MoQ Cluster extension). We declare both ourselves on\n * every session: we send SUBSCRIBE_NAMESPACE for each prefix we want, so an unsolicited\n * advertisement can tell us nothing we won't have asked for, and a peer that knows our Hop\n * ID can withhold the advertisements that already flowed through us.\n */\nexport async function exchangeSetup(\n\ttransport: WebTransport,\n\tversion: Ietf.IetfVersion,\n\timplementation: string,\n): Promise<{\n\tcontrol: Stream;\n\tearly: Reader[];\n\tsolicit: boolean | undefined;\n\thidden: boolean;\n\tcluster: Ietf.Cluster.Hops;\n}> {\n\tconst encoder = new TextEncoder();\n\tconst params = new Ietf.SetupOptions();\n\tparams.setBytes(Ietf.SetupOption.Implementation, encoder.encode(implementation));\n\tIetf.solicitIntoSetup(params);\n\tIetf.hiddenIntoSetup(params);\n\n\t// One id per session, like the moq-lite connection: nothing in this process forwards\n\t// between sessions, so there is nothing for a shared id to detect.\n\tconst self = randomHop();\n\tIetf.Cluster.intoSetup(params, self, version);\n\n\tconst setupMsg = new Ietf.Setup({ parameters: params });\n\n\tconst [writer, received] = await Promise.all([\n\t\tsendSetup(transport, version, setupMsg),\n\t\treceiveSetup(transport, version),\n\t]);\n\n\treturn {\n\t\tcontrol: new Stream({ writer, reader: received.reader }),\n\t\tearly: received.early,\n\t\tsolicit: received.solicit,\n\t\thidden: received.hidden,\n\t\tcluster: { self, peer: received.cluster },\n\t};\n}\n\nasync function sendSetup(transport: WebTransport, version: Ietf.IetfVersion, setupMsg: Ietf.Setup): Promise<Writer> {\n\t// Via Writer.open for its deadline: a peer can advertise a stream limit of zero and\n\t// never raise it, which would otherwise hang the handshake rather than failing it.\n\tconst writer = await Writer.open(transport, { version });\n\tawait writer.u53(Ietf.Setup.id); // 0x2F00 stream type\n\tawait setupMsg.encode(writer, version);\n\treturn writer;\n}\n\n/**\n * Read the peer's SETUP off its uni stream. Any other uni stream that beats it (padding,\n * or group data for a subscription the peer already holds) is held, type unread, for the\n * session to classify once it starts: the drafts say to buffer early data rather than\n * reject it. QUIC stream credit bounds how many can pile up.\n */\nasync function receiveSetup(\n\ttransport: WebTransport,\n\tversion: Ietf.IetfVersion,\n): Promise<{\n\treader: Reader;\n\tearly: Reader[];\n\tsolicit: boolean | undefined;\n\thidden: boolean;\n\tcluster: Hop | undefined;\n}> {\n\tconst uniReader = transport.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\tReadableStream<Uint8Array>\n\t>;\n\tconst early: Reader[] = [];\n\n\tlet reader: Reader;\n\ttry {\n\t\tfor (;;) {\n\t\t\tconst next = await uniReader.read();\n\t\t\tif (next.done) throw new Error(\"no incoming uni stream for SETUP\");\n\n\t\t\tconst stream = new Reader(next.value, undefined, version);\n\t\t\t// A stream that ended or reset before its full type is that stream's failure, not the session's.\n\t\t\t// Malformed bytes are still the peer's fault, so a bad type fails the handshake.\n\t\t\tif (await stream.done().catch(() => true)) continue;\n\t\t\t// Full width, so an unknown type past 2^53 is held for the classifier to refuse.\n\t\t\tconst streamType = await stream.peekU62().catch((err: unknown) => {\n\t\t\t\tif (err instanceof StreamError || err instanceof UnexpectedEnd) return undefined;\n\t\t\t\tthrow err;\n\t\t\t});\n\t\t\tif (streamType === undefined) continue;\n\t\t\tif (streamType === BigInt(Ietf.Setup.id)) {\n\t\t\t\treader = stream;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tearly.push(stream);\n\t\t}\n\t} finally {\n\t\tuniReader.releaseLock();\n\t}\n\n\tawait reader.u53(); // the SETUP type, peeked above\n\tconst setup = await Ietf.Setup.decode(reader, version);\n\n\treturn {\n\t\treader,\n\t\tearly,\n\t\tsolicit: Ietf.solicitFromSetup(setup.parameters),\n\t\thidden: Ietf.hiddenFromSetup(setup.parameters),\n\t\tcluster: Ietf.Cluster.fromSetup(setup.parameters, version),\n\t};\n}\n"]}
|
package/connection/pool.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { type AcceptProps as AcceptPropsType, accept } from "./accept";
|
|
|
13
13
|
import { isWebTransportSupported } from "./browser";
|
|
14
14
|
import { type CertificateHash as CertificateHashType, type ConnectProps as ConnectPropsType, certificateHash, connect, type WebSocketProps as WebSocketPropsType, type WebTransportProps as WebTransportPropsType } from "./connect";
|
|
15
15
|
import type { Established as EstablishedType } from "./established";
|
|
16
|
+
import type { GoawayProps, Redirect as RedirectType } from "./goaway";
|
|
16
17
|
import { type ReloadDelay, type ReloadStatus } from "./reload";
|
|
17
18
|
import type { Probe as ProbeType, Stats as StatsType } from "./stats";
|
|
18
19
|
import type { Transport as TransportType } from "./transport";
|
|
@@ -31,11 +32,9 @@ export interface ConnectionProps {
|
|
|
31
32
|
*/
|
|
32
33
|
linger?: Time.Milli;
|
|
33
34
|
/**
|
|
34
|
-
* Share a pooled transport keyed on the URL
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* certificate, caller-owned origins) require `share: false` and get a private
|
|
38
|
-
* reconnect loop with the same handle semantics.
|
|
35
|
+
* Share a pooled transport keyed on the URL. By default, options specific to this
|
|
36
|
+
* handle use a private reconnect loop; otherwise connections share by URL.
|
|
37
|
+
* Explicit `true` refuses options a pool cannot honor.
|
|
39
38
|
*/
|
|
40
39
|
share?: boolean;
|
|
41
40
|
/** WebTransport options applied to each connection attempt (not reactive). */
|
|
@@ -44,12 +43,18 @@ export interface ConnectionProps {
|
|
|
44
43
|
websocket?: WebSocketPropsType;
|
|
45
44
|
/** Whether the relay supports broadcast discovery. */
|
|
46
45
|
discovery?: boolean;
|
|
47
|
-
/** The origin whose broadcasts are served, spanning reconnects.
|
|
46
|
+
/** The origin whose broadcasts are served, spanning reconnects. Implies a private loop. */
|
|
48
47
|
publish?: Origin.Consumer;
|
|
49
|
-
/** The origin fed with the peer's announced broadcasts, spanning reconnects.
|
|
48
|
+
/** The origin fed with the peer's announced broadcasts, spanning reconnects. Implies a private loop. */
|
|
50
49
|
consume?: Origin.Producer;
|
|
51
50
|
/** Backoff settings for the reconnect loop; an unset field uses its default. */
|
|
52
51
|
delay?: ReloadDelay;
|
|
52
|
+
/**
|
|
53
|
+
* How to react to the relay's GOAWAY; an unset field uses its default. Every connection
|
|
54
|
+
* migrates on GOAWAY, dialing the replacement while the old session finishes its groups.
|
|
55
|
+
* This only tunes where it may go and for how long the old session serves.
|
|
56
|
+
*/
|
|
57
|
+
goaway?: GoawayProps;
|
|
53
58
|
/** A Connection owns the abort signal for each connection attempt. */
|
|
54
59
|
signal?: never;
|
|
55
60
|
/** A one-shot transport cannot be reused by the reconnect loop; call {@link Connection.connect} instead. */
|
|
@@ -72,9 +77,13 @@ export interface ConnectionProps {
|
|
|
72
77
|
* connection so the next handle dials fresh; a new URL on this handle starts another
|
|
73
78
|
* sequence. {@link closed} settles only when this handle is released.
|
|
74
79
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
80
|
+
* A relay's GOAWAY migrates rather than drops: the replacement dials at once while the old
|
|
81
|
+
* session finishes its groups, and the handle and its origin carry across. A redirect the
|
|
82
|
+
* {@link ConnectionProps.goaway} policy refuses stops the loop like an auth rejection does.
|
|
83
|
+
*
|
|
84
|
+
* Options the pool cannot honor (transport options, discovery, delay, goaway, a pinned
|
|
85
|
+
* certificate, caller-owned origins) use a private loop. An explicit `share: true`
|
|
86
|
+
* refuses them. A supplied transport cannot reconnect at all; pass it to {@link Connection.connect}
|
|
78
87
|
* instead.
|
|
79
88
|
*
|
|
80
89
|
* @public
|
|
@@ -149,7 +158,7 @@ export declare class Connection {
|
|
|
149
158
|
* and URL switches: a switch retracts everything from
|
|
150
159
|
* the old relay's origin, then the new one's arrivals stream in.
|
|
151
160
|
*/
|
|
152
|
-
announced(scope?: Path.Pattern): Announce.Consumer;
|
|
161
|
+
announced(scope?: Path.Pattern, options?: Announce.Options): Announce.Consumer;
|
|
153
162
|
/** Snapshot the live connection's transport counters, or undefined while disconnected. */
|
|
154
163
|
stats(): Promise<StatsType | undefined>;
|
|
155
164
|
/**
|
|
@@ -168,6 +177,10 @@ export declare namespace Connection {
|
|
|
168
177
|
type AcceptProps = AcceptPropsType;
|
|
169
178
|
/** Backoff settings for a private reconnect loop. */
|
|
170
179
|
type Backoff = ReloadDelay;
|
|
180
|
+
/** How a connection reacts to the relay's GOAWAY. */
|
|
181
|
+
type Goaway = GoawayProps;
|
|
182
|
+
/** What to do with the URI a relay names in its GOAWAY. */
|
|
183
|
+
type Redirect = RedirectType;
|
|
171
184
|
/** Current state of a {@link Connection}. */
|
|
172
185
|
type Status = ReloadStatus;
|
|
173
186
|
/** The current connection's PROBE estimates. */
|
package/connection/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/connection/pool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,MAAM,EAAQ,MAAM,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,WAAW,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACN,KAAK,eAAe,IAAI,mBAAmB,EAC3C,KAAK,YAAY,IAAI,gBAAgB,EACrC,eAAe,EACf,OAAO,EACP,KAAK,cAAc,IAAI,kBAAkB,EACzC,KAAK,iBAAiB,IAAI,qBAAqB,EAC/C,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,IAAI,aAAa,EAAE,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;AAC5F,yBAAiB,UAAU,CAAC;IAC3B,sCAAsC;IACtC,KAAY,KAAK,GAAG,eAAe,CAAC;IACpC,8CAA8C;IAC9C,KAAY,YAAY,GAAG,gBAAgB,CAAC;IAC5C,6CAA6C;IAC7C,KAAY,WAAW,GAAG,eAAe,CAAC;IAC1C,qDAAqD;IACrD,KAAY,OAAO,GAAG,WAAW,CAAC;IAClC,qDAAqD;IACrD,KAAY,MAAM,GAAG,WAAW,CAAC;IACjC,2DAA2D;IAC3D,KAAY,QAAQ,GAAG,YAAY,CAAC;IACpC,6CAA6C;IAC7C,KAAY,MAAM,GAAG,YAAY,CAAC;IAClC,gDAAgD;IAChD,KAAY,KAAK,GAAG,SAAS,CAAC;IAC9B,4DAA4D;IAC5D,KAAY,KAAK,GAAG,SAAS,CAAC;IAC9B,8CAA8C;IAC9C,KAAY,SAAS,GAAG,aAAa,CAAC;IACtC,yCAAyC;IACzC,KAAY,cAAc,GAAG,kBAAkB,CAAC;IAChD,sEAAsE;IACtE,KAAY,iBAAiB,GAAG,qBAAqB,CAAC;IACtD,kEAAkE;IAClE,KAAY,eAAe,GAAG,mBAAmB,CAAC;IAClD,uCAAuC;IACvC,KAAY,WAAW,GAAG,eAAe,CAAC;CAC1C"}
|
package/connection/pool.js
CHANGED
|
@@ -32,9 +32,13 @@ const LINGER_MS = Time.Milli(2000);
|
|
|
32
32
|
* connection so the next handle dials fresh; a new URL on this handle starts another
|
|
33
33
|
* sequence. {@link closed} settles only when this handle is released.
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* A relay's GOAWAY migrates rather than drops: the replacement dials at once while the old
|
|
36
|
+
* session finishes its groups, and the handle and its origin carry across. A redirect the
|
|
37
|
+
* {@link ConnectionProps.goaway} policy refuses stops the loop like an auth rejection does.
|
|
38
|
+
*
|
|
39
|
+
* Options the pool cannot honor (transport options, discovery, delay, goaway, a pinned
|
|
40
|
+
* certificate, caller-owned origins) use a private loop. An explicit `share: true`
|
|
41
|
+
* refuses them. A supplied transport cannot reconnect at all; pass it to {@link Connection.connect}
|
|
38
42
|
* instead.
|
|
39
43
|
*
|
|
40
44
|
* @public
|
|
@@ -103,7 +107,7 @@ export class Connection {
|
|
|
103
107
|
#origin = new Signal(undefined);
|
|
104
108
|
#bandwidth = new Signal(undefined);
|
|
105
109
|
#error = new Signal(undefined);
|
|
106
|
-
#signals
|
|
110
|
+
#signals;
|
|
107
111
|
/**
|
|
108
112
|
* Take a handle on the connection for {@link ConnectionProps.url}.
|
|
109
113
|
*
|
|
@@ -114,6 +118,7 @@ export class Connection {
|
|
|
114
118
|
*/
|
|
115
119
|
constructor(props) {
|
|
116
120
|
refuse(props);
|
|
121
|
+
this.#signals = new Effect();
|
|
117
122
|
this.url = Signal.from(props?.url);
|
|
118
123
|
this.enabled = Signal.from(props?.enabled ?? true);
|
|
119
124
|
this.status = this.#status;
|
|
@@ -126,7 +131,7 @@ export class Connection {
|
|
|
126
131
|
// Key on the serialized URL: URL objects use identity equality, and an equivalent
|
|
127
132
|
// instance must not release and redial.
|
|
128
133
|
const href = this.#signals.computed((effect) => effect.get(this.url)?.href);
|
|
129
|
-
if (props
|
|
134
|
+
if (props && (props.share === false || requiresPrivate(props))) {
|
|
130
135
|
this.#runPrivate(props, href);
|
|
131
136
|
return;
|
|
132
137
|
}
|
|
@@ -163,6 +168,7 @@ export class Connection {
|
|
|
163
168
|
// A handle nobody watches wants unlimited retries; an auth rejection still
|
|
164
169
|
// stops this URL, and a new one starts another sequence.
|
|
165
170
|
delay: { timeout: Time.Milli(0), ...props.delay },
|
|
171
|
+
goaway: props.goaway,
|
|
166
172
|
});
|
|
167
173
|
this.#signals.cleanup(() => loop.close());
|
|
168
174
|
this.#signals.run((effect) => {
|
|
@@ -181,7 +187,7 @@ export class Connection {
|
|
|
181
187
|
* and URL switches: a switch retracts everything from
|
|
182
188
|
* the old relay's origin, then the new one's arrivals stream in.
|
|
183
189
|
*/
|
|
184
|
-
announced(scope = Path.Pattern.all()) {
|
|
190
|
+
announced(scope = Path.Pattern.all(), options) {
|
|
185
191
|
const producer = new Announce.Producer();
|
|
186
192
|
const consumer = producer.consume();
|
|
187
193
|
// Closing the consumer closes the shared state, so stop appending after that.
|
|
@@ -197,7 +203,7 @@ export class Connection {
|
|
|
197
203
|
const origin = effect.get(this.#origin);
|
|
198
204
|
if (!origin)
|
|
199
205
|
return;
|
|
200
|
-
const upstream = origin.announced(scope);
|
|
206
|
+
const upstream = origin.announced(scope, options);
|
|
201
207
|
effect.cleanup(() => upstream.close());
|
|
202
208
|
// Track what this origin announced so a URL switch retracts it; the last
|
|
203
209
|
// event rides along for the retraction.
|
|
@@ -205,7 +211,7 @@ export class Connection {
|
|
|
205
211
|
effect.spawn(async () => {
|
|
206
212
|
try {
|
|
207
213
|
for (;;) {
|
|
208
|
-
const entry = await
|
|
214
|
+
const entry = await effect.race(upstream.next());
|
|
209
215
|
if (!entry)
|
|
210
216
|
break;
|
|
211
217
|
if (Announce.isActive(entry.kind))
|
|
@@ -252,7 +258,7 @@ function refuse(props) {
|
|
|
252
258
|
if (extra.signal) {
|
|
253
259
|
throw new Error("a Connection owns its abort signal; do not pass one");
|
|
254
260
|
}
|
|
255
|
-
if (props.share
|
|
261
|
+
if (props.share !== true || !requiresPrivate(props))
|
|
256
262
|
return;
|
|
257
263
|
if (props.publish || props.consume) {
|
|
258
264
|
throw new Error("caller-owned origins cannot be shared; pass share: false");
|
|
@@ -273,6 +279,19 @@ function refuse(props) {
|
|
|
273
279
|
if (props.delay !== undefined) {
|
|
274
280
|
throw new Error("delay cannot be shared; pass share: false");
|
|
275
281
|
}
|
|
282
|
+
if (props.goaway !== undefined) {
|
|
283
|
+
throw new Error("goaway cannot be shared; pass share: false");
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/** Options tied to one handle cannot be represented by a URL-keyed shared entry. */
|
|
287
|
+
function requiresPrivate(props) {
|
|
288
|
+
return (props.webtransport !== undefined ||
|
|
289
|
+
props.websocket !== undefined ||
|
|
290
|
+
props.discovery !== undefined ||
|
|
291
|
+
props.delay !== undefined ||
|
|
292
|
+
props.goaway !== undefined ||
|
|
293
|
+
props.publish !== undefined ||
|
|
294
|
+
props.consume !== undefined);
|
|
276
295
|
}
|
|
277
296
|
/** The process-wide pool backing {@link Connection}. */
|
|
278
297
|
const pool = new Map();
|
|
@@ -291,14 +310,27 @@ function acquire(key, linger) {
|
|
|
291
310
|
// instead; an auth rejection still stops this URL, and evicts below.
|
|
292
311
|
delay: { timeout: Time.Milli(0) },
|
|
293
312
|
});
|
|
294
|
-
const created = { origin, connection, refs: 0, linger: linger ?? LINGER_MS };
|
|
295
|
-
// The loop only stops on a peer saying these credentials will never work
|
|
296
|
-
// entry so a later handle dials fresh rather
|
|
297
|
-
// handles already on it keep it until they
|
|
298
|
-
//
|
|
313
|
+
const created = { key, origin, connection, refs: 0, linger: linger ?? LINGER_MS };
|
|
314
|
+
// The loop only stops on a peer saying these credentials will never work, or on a
|
|
315
|
+
// GOAWAY redirect it refused. Drop the entry so a later handle dials fresh rather
|
|
316
|
+
// than joining a loop that has stopped; handles already on it keep it until they
|
|
317
|
+
// release.
|
|
299
318
|
connection.error.subscribe((err) => {
|
|
300
|
-
if (err !== undefined && pool.get(key) === created)
|
|
301
|
-
pool.delete(key);
|
|
319
|
+
if (err !== undefined && pool.get(created.key) === created)
|
|
320
|
+
pool.delete(created.key);
|
|
321
|
+
});
|
|
322
|
+
// An accepted redirect moves the entry to the URL it now dials, so a later handle
|
|
323
|
+
// configured with that URL shares it, and one asking for the old URL dials fresh.
|
|
324
|
+
// A live entry already at the target wins: this one leaves the pool and serves only
|
|
325
|
+
// the handles it has until they release it.
|
|
326
|
+
connection.redirect.subscribe((redirect) => {
|
|
327
|
+
if (!redirect || redirect.href === created.key)
|
|
328
|
+
return;
|
|
329
|
+
if (pool.get(created.key) === created)
|
|
330
|
+
pool.delete(created.key);
|
|
331
|
+
created.key = redirect.href;
|
|
332
|
+
if (!pool.has(created.key))
|
|
333
|
+
pool.set(created.key, created);
|
|
302
334
|
});
|
|
303
335
|
entry = created;
|
|
304
336
|
pool.set(key, created);
|
|
@@ -321,8 +353,8 @@ function acquire(key, linger) {
|
|
|
321
353
|
if (taken.refs > 0)
|
|
322
354
|
return;
|
|
323
355
|
taken.timer = setTimeout(() => {
|
|
324
|
-
if (pool.get(key) === taken)
|
|
325
|
-
pool.delete(key);
|
|
356
|
+
if (pool.get(taken.key) === taken)
|
|
357
|
+
pool.delete(taken.key);
|
|
326
358
|
taken.connection.close();
|
|
327
359
|
taken.origin.close();
|
|
328
360
|
}, taken.linger);
|