@moq/net 0.3.4 → 0.4.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/README.md +2 -2
- package/announce.d.ts +7 -0
- package/announce.d.ts.map +1 -0
- package/announce.js +8 -0
- package/announce.js.map +1 -0
- package/announced.d.ts +35 -91
- package/announced.d.ts.map +1 -1
- package/announced.js +21 -156
- package/announced.js.map +1 -1
- package/bandwidth.d.ts +163 -0
- package/bandwidth.d.ts.map +1 -0
- package/bandwidth.js +304 -0
- package/bandwidth.js.map +1 -0
- package/bandwidth_api.d.ts +7 -0
- package/bandwidth_api.d.ts.map +1 -0
- package/bandwidth_api.js +8 -0
- package/bandwidth_api.js.map +1 -0
- package/broadcast.d.ts +20 -28
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +60 -42
- package/broadcast.js.map +1 -1
- package/connection/accept.d.ts +16 -1
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +39 -24
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts.map +1 -1
- package/connection/browser.js +9 -7
- package/connection/browser.js.map +1 -1
- package/connection/connect.d.ts +30 -6
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +97 -50
- package/connection/connect.js.map +1 -1
- package/connection/established.d.ts +16 -21
- package/connection/established.d.ts.map +1 -1
- package/connection/established.js.map +1 -1
- package/connection/forward.d.ts +2 -0
- package/connection/forward.d.ts.map +1 -0
- package/connection/forward.js +159 -0
- package/connection/forward.js.map +1 -0
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +2 -2
- package/connection/handshake.js.map +1 -1
- package/connection/index.d.ts +5 -5
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +4 -5
- package/connection/index.js.map +1 -1
- package/connection/pool.d.ts +188 -0
- package/connection/pool.d.ts.map +1 -0
- package/connection/pool.js +351 -0
- package/connection/pool.js.map +1 -0
- package/connection/reload.d.ts +14 -93
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +216 -80
- package/connection/reload.js.map +1 -1
- package/connection/stats.d.ts +3 -26
- package/connection/stats.d.ts.map +1 -1
- package/connection/stats.js.map +1 -1
- package/connection/transport.d.ts +0 -7
- package/connection/transport.d.ts.map +1 -1
- package/consume.d.ts +1 -43
- package/consume.d.ts.map +1 -1
- package/consume.js +1 -1
- package/consume.js.map +1 -1
- package/error.d.ts +180 -29
- package/error.d.ts.map +1 -1
- package/error.js +310 -16
- package/error.js.map +1 -1
- package/errors.d.ts +7 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +8 -0
- package/errors.js.map +1 -0
- package/group.d.ts +9 -43
- package/group.d.ts.map +1 -1
- package/group.js +283 -69
- package/group.js.map +1 -1
- package/hop.d.ts +107 -0
- package/hop.d.ts.map +1 -0
- package/hop.js +103 -0
- package/hop.js.map +1 -0
- package/ietf/aliases.d.ts +1 -78
- package/ietf/aliases.d.ts.map +1 -1
- package/ietf/cluster.d.ts +6 -120
- package/ietf/cluster.d.ts.map +1 -1
- package/ietf/cluster.js +81 -41
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts +6 -72
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +11 -47
- package/ietf/connection.js.map +1 -1
- package/ietf/error.d.ts +11 -0
- package/ietf/error.d.ts.map +1 -0
- package/ietf/error.js +168 -0
- package/ietf/error.js.map +1 -0
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +6 -1
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +22 -5
- package/ietf/goaway.js.map +1 -1
- package/ietf/parameters.d.ts +2 -2
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +15 -17
- package/ietf/parameters.js.map +1 -1
- package/ietf/publish_namespace.d.ts +25 -0
- package/ietf/publish_namespace.d.ts.map +1 -1
- package/ietf/publish_namespace.js +63 -0
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.d.ts +1 -82
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +219 -125
- package/ietf/publisher.js.map +1 -1
- package/ietf/solicit.d.ts +1 -40
- package/ietf/solicit.d.ts.map +1 -1
- package/ietf/subscribe.d.ts +1 -5
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +8 -9
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscriber.d.ts +1 -65
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +154 -73
- package/ietf/subscriber.js.map +1 -1
- package/ietf/version.d.ts +12 -1
- package/ietf/version.d.ts.map +1 -1
- package/ietf/version.js +13 -0
- package/ietf/version.js.map +1 -1
- package/index.d.ts +11 -6
- package/index.d.ts.map +1 -1
- package/index.js +10 -5
- package/index.js.map +1 -1
- package/internal.d.ts +99 -1
- package/internal.d.ts.map +1 -1
- package/internal.js +65 -0
- package/internal.js.map +1 -1
- package/lite/announce.d.ts +15 -9
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +47 -20
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts +9 -59
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +20 -32
- package/lite/connection.js.map +1 -1
- package/lite/fetch.d.ts +15 -1
- package/lite/fetch.d.ts.map +1 -1
- package/lite/fetch.js +39 -7
- package/lite/fetch.js.map +1 -1
- package/lite/goaway.d.ts.map +1 -1
- package/lite/goaway.js +7 -1
- package/lite/goaway.js.map +1 -1
- package/lite/group.d.ts +18 -4
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +31 -10
- package/lite/group.js.map +1 -1
- package/lite/priority.d.ts +1 -61
- package/lite/priority.d.ts.map +1 -1
- package/lite/priority.js +4 -5
- package/lite/priority.js.map +1 -1
- package/lite/publisher.d.ts +1 -69
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +559 -232
- package/lite/publisher.js.map +1 -1
- package/lite/setup.d.ts +7 -7
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +13 -13
- package/lite/setup.js.map +1 -1
- package/lite/subscribe.d.ts +61 -13
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +186 -44
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +8 -57
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +179 -117
- package/lite/subscriber.js.map +1 -1
- package/lite/track.d.ts +4 -10
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +34 -29
- package/lite/track.js.map +1 -1
- package/lite/version.d.ts +31 -6
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +71 -11
- package/lite/version.js.map +1 -1
- package/origin.d.ts +229 -29
- package/origin.d.ts.map +1 -1
- package/origin.js +1087 -37
- package/origin.js.map +1 -1
- package/package.json +3 -2
- package/path.d.ts +25 -7
- package/path.d.ts.map +1 -1
- package/path.js +5 -3
- package/path.js.map +1 -1
- package/stream.d.ts.map +1 -1
- package/stream.js +25 -16
- package/stream.js.map +1 -1
- package/time.d.ts +15 -2
- package/time.d.ts.map +1 -1
- package/time.js +28 -9
- package/time.js.map +1 -1
- package/track.d.ts +171 -82
- package/track.d.ts.map +1 -1
- package/track.js +633 -184
- package/track.js.map +1 -1
- package/util/log.d.ts +5 -0
- package/util/log.d.ts.map +1 -0
- package/util/log.js +17 -0
- package/util/log.js.map +1 -0
- package/wire.d.ts +67 -0
- package/wire.d.ts.map +1 -0
- package/wire.js +32 -0
- package/wire.js.map +1 -0
- package/zod.d.ts +1 -1
- package/zod.d.ts.map +1 -1
- package/zod.js.map +1 -1
- package/mock.d.ts +0 -66
- package/mock.d.ts.map +0 -1
- package/mock.js +0 -243
- package/mock.js.map +0 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/* @ts-self-types="./forward.d.ts" */
|
|
2
|
+
import { isActive } from "../announced.js";
|
|
3
|
+
import { wireOf } from "../wire.js";
|
|
4
|
+
/**
|
|
5
|
+
* Wire a session into `origin` for the session's lifetime: forward the peer's announced
|
|
6
|
+
* routes into the table, and answer the origin's open requests with blind
|
|
7
|
+
* subscriptions.
|
|
8
|
+
*
|
|
9
|
+
* Each active announcement inserts a route covering the announced prefix, served
|
|
10
|
+
* lazily through this connection, so nothing touches the wire until somebody requests
|
|
11
|
+
* a path under it. A retraction removes the entry, and so does the session dying (the
|
|
12
|
+
* announce stream ends with it), which is what scopes remote routes to the session
|
|
13
|
+
* that announced them. A reconnect wires a fresh session to the same origin and
|
|
14
|
+
* re-populates it.
|
|
15
|
+
*
|
|
16
|
+
* Without discovery there are no announcements to forward, so the table stays empty and
|
|
17
|
+
* requests are the only way through; see the origin's `request`.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export function forwardAnnounced(conn, origin) {
|
|
22
|
+
const originWire = wireOf(origin);
|
|
23
|
+
// Reassigned if discovery dies under a live session, so the origin stops counting this
|
|
24
|
+
// one as a discovering session. Called through a closure so the session's death always
|
|
25
|
+
// detaches whichever attachment is current.
|
|
26
|
+
let detach = originWire.attach(conn.discovery);
|
|
27
|
+
let dead = false;
|
|
28
|
+
void conn.closed.then(() => {
|
|
29
|
+
dead = true;
|
|
30
|
+
detach();
|
|
31
|
+
});
|
|
32
|
+
void serveRequests(conn, origin);
|
|
33
|
+
if (!conn.discovery) {
|
|
34
|
+
console.warn("relay does not support broadcast discovery; broadcasts resolve on request only.");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const announced = conn.announced();
|
|
38
|
+
const inserted = new Map();
|
|
39
|
+
// End the stream the moment the session closes rather than waiting for the wire to
|
|
40
|
+
// error it, so the retractions below land promptly.
|
|
41
|
+
void conn.closed.then(() => announced.close());
|
|
42
|
+
void (async () => {
|
|
43
|
+
let failure;
|
|
44
|
+
try {
|
|
45
|
+
for (;;) {
|
|
46
|
+
const event = await announced.next();
|
|
47
|
+
if (!event)
|
|
48
|
+
break;
|
|
49
|
+
if (isActive(event.kind)) {
|
|
50
|
+
const existing = inserted.get(event.prefix);
|
|
51
|
+
if (existing) {
|
|
52
|
+
existing.update(event.route);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const handle = originWire.receive(event.prefix, event.route);
|
|
56
|
+
inserted.set(event.prefix, handle);
|
|
57
|
+
void drive(handle, conn);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const handle = inserted.get(event.prefix);
|
|
62
|
+
inserted.delete(event.prefix);
|
|
63
|
+
handle?.close();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
// The session died mid-stream, or the relay refused or reset the stream. The
|
|
69
|
+
// cleanup below retracts everything this stream fed either way.
|
|
70
|
+
failure = err;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
for (const handle of inserted.values())
|
|
74
|
+
handle.close();
|
|
75
|
+
inserted.clear();
|
|
76
|
+
announced.close();
|
|
77
|
+
// Discovery ended while the session lives, and nothing reopens the stream on this
|
|
78
|
+
// connection. Downgrade the attachment rather than leaving the origin claiming a
|
|
79
|
+
// discovery that no longer works: announcement-gated consumers would wait forever
|
|
80
|
+
// on a table this session can no longer fill. Now they fall back to standing
|
|
81
|
+
// requests, which this session still answers.
|
|
82
|
+
if (!dead) {
|
|
83
|
+
console.warn("broadcast discovery failed; broadcasts resolve on request only.", failure);
|
|
84
|
+
detach();
|
|
85
|
+
detach = originWire.attach(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Answer the origin's open requests with blind subscriptions for the session's lifetime.
|
|
92
|
+
*
|
|
93
|
+
* Every session answers, discovery or not: subscribing to an unannounced path is always
|
|
94
|
+
* legal, and a missing broadcast surfaces as a reset on the first track. The first session
|
|
95
|
+
* to answer wins; when this session dies its answers are withdrawn so a later session
|
|
96
|
+
* answers again, which is what makes a request span reconnects.
|
|
97
|
+
*
|
|
98
|
+
* A path the table already routes is left alone. A request resolves to the table's route over
|
|
99
|
+
* any blind answer, so answering one would only park a handle nothing reads.
|
|
100
|
+
*/
|
|
101
|
+
async function drive(handle, conn) {
|
|
102
|
+
const session = wireOf(conn);
|
|
103
|
+
try {
|
|
104
|
+
for await (const request of handle.requested()) {
|
|
105
|
+
request.accept(session.consume(request.path));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
handle.close();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function serveRequests(conn, origin) {
|
|
113
|
+
const table = wireOf(origin);
|
|
114
|
+
const session = wireOf(conn);
|
|
115
|
+
// The withdraws for the answers this session provided, so a dead session only takes
|
|
116
|
+
// back its own. Keyed by path but remembering the slot, because a path outlives its
|
|
117
|
+
// slot: the last handle closing tears the slot down and a new request installs a fresh
|
|
118
|
+
// one, and those two writes coalesce into a single wakeup. Matching on the path alone
|
|
119
|
+
// would read the new slot as already answered and leave it unanswered forever.
|
|
120
|
+
const answered = new Map();
|
|
121
|
+
let dead = false;
|
|
122
|
+
const closed = conn.closed.then(() => {
|
|
123
|
+
dead = true;
|
|
124
|
+
});
|
|
125
|
+
for (;;) {
|
|
126
|
+
const map = table.requests.peek();
|
|
127
|
+
if (!map || dead)
|
|
128
|
+
break;
|
|
129
|
+
for (const [path, slot] of map) {
|
|
130
|
+
if (slot.blind === 0)
|
|
131
|
+
continue;
|
|
132
|
+
if (answered.get(path)?.slot === slot || slot.answer !== undefined)
|
|
133
|
+
continue;
|
|
134
|
+
if (table.routes(path))
|
|
135
|
+
continue;
|
|
136
|
+
const withdraw = table.answer(path, session.consume(path));
|
|
137
|
+
if (withdraw)
|
|
138
|
+
answered.set(path, { slot, withdraw });
|
|
139
|
+
}
|
|
140
|
+
// A withdrawn request already released the answer; just forget our claim on the path.
|
|
141
|
+
// A replaced slot counts as withdrawn: the answer we hold belongs to the slot that
|
|
142
|
+
// went away, not to whatever now occupies the path.
|
|
143
|
+
for (const [path, entry] of [...answered]) {
|
|
144
|
+
if (map.get(path) === entry.slot && entry.slot.blind > 0)
|
|
145
|
+
continue;
|
|
146
|
+
answered.delete(path);
|
|
147
|
+
entry.withdraw();
|
|
148
|
+
}
|
|
149
|
+
// Woken by the table too, not just the requests: a path that stops being routed needs
|
|
150
|
+
// the blind answer this loop skipped while it was.
|
|
151
|
+
await Promise.race([table.changed(), closed]);
|
|
152
|
+
}
|
|
153
|
+
// Session gone: withdraw our answers, waking a standby session to provide fresh ones.
|
|
154
|
+
for (const { withdraw } of answered.values()) {
|
|
155
|
+
withdraw();
|
|
156
|
+
}
|
|
157
|
+
answered.clear();
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=forward.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forward.js","sourceRoot":"","sources":["../../src/connection/forward.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGpC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAiB,EAAE,MAAsB;IACzE,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,uFAAuF;IACvF,uFAAuF;IACvF,4CAA4C;IAC5C,IAAI,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAE/C,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;QAC1B,IAAI,GAAG,IAAI,CAAC;QACZ,MAAM,EAAE,CAAC;IACV,CAAC,CAAC,CAAC;IAEH,KAAK,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,iFAAiF,CAAC,CAAC;QA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AC;QAClB,CAAC;QAED,sFAAsF;QACtF,mDAAmD;QACnD,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,sFAAsF;IACtF,KAAK,MAAM,EAAE,QAAQ,EAAE,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QAC9C,QAAQ,EAAE,CAAC;IACZ,CAAC;IACD,QAAQ,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Feeds a session's announced routes into an origin; the `consume` connect option.\n *\n * @module\n */\nimport type { Dispose } from \"@moq/signals\";\nimport { isActive } from \"../announced.ts\";\nimport type { Dynamic, Producer as OriginProducer, RequestSlot } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { wireOf } from \"../wire.ts\";\nimport type { Established } from \"./established.ts\";\n\n/**\n * Wire a session into `origin` for the session's lifetime: forward the peer's announced\n * routes into the table, and answer the origin's open requests with blind\n * subscriptions.\n *\n * Each active announcement inserts a route covering the announced prefix, served\n * lazily through this connection, so nothing touches the wire until somebody requests\n * a path under it. A retraction removes the entry, and so does the session dying (the\n * announce stream ends with it), which is what scopes remote routes to the session\n * that announced them. A reconnect wires a fresh session to the same origin and\n * re-populates it.\n *\n * Without discovery there are no announcements to forward, so the table stays empty and\n * requests are the only way through; see the origin's `request`.\n *\n * @internal\n */\nexport function forwardAnnounced(conn: Established, origin: OriginProducer): void {\n\tconst originWire = wireOf(origin);\n\t// Reassigned if discovery dies under a live session, so the origin stops counting this\n\t// one as a discovering session. Called through a closure so the session's death always\n\t// detaches whichever attachment is current.\n\tlet detach = originWire.attach(conn.discovery);\n\n\tlet dead = false;\n\tvoid conn.closed.then(() => {\n\t\tdead = true;\n\t\tdetach();\n\t});\n\n\tvoid serveRequests(conn, origin);\n\n\tif (!conn.discovery) {\n\t\tconsole.warn(\"relay does not support broadcast discovery; broadcasts resolve on request only.\");\n\t\treturn;\n\t}\n\n\tconst announced = conn.announced();\n\tconst inserted = new Map<Path.Valid, Dynamic>();\n\n\t// End the stream the moment the session closes rather than waiting for the wire to\n\t// error it, so the retractions below land promptly.\n\tvoid conn.closed.then(() => announced.close());\n\n\tvoid (async () => {\n\t\tlet failure: unknown;\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst event = await announced.next();\n\t\t\t\tif (!event) break;\n\n\t\t\t\tif (isActive(event.kind)) {\n\t\t\t\t\tconst existing = inserted.get(event.prefix);\n\t\t\t\t\tif (existing) {\n\t\t\t\t\t\texisting.update(event.route);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst handle = originWire.receive(event.prefix, event.route);\n\t\t\t\t\t\tinserted.set(event.prefix, handle);\n\t\t\t\t\t\tvoid drive(handle, conn);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst handle = inserted.get(event.prefix);\n\t\t\t\t\tinserted.delete(event.prefix);\n\t\t\t\t\thandle?.close();\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (err) {\n\t\t\t// The session died mid-stream, or the relay refused or reset the stream. The\n\t\t\t// cleanup below retracts everything this stream fed either way.\n\t\t\tfailure = err;\n\t\t} finally {\n\t\t\tfor (const handle of inserted.values()) handle.close();\n\t\t\tinserted.clear();\n\t\t\tannounced.close();\n\n\t\t\t// Discovery ended while the session lives, and nothing reopens the stream on this\n\t\t\t// connection. Downgrade the attachment rather than leaving the origin claiming a\n\t\t\t// discovery that no longer works: announcement-gated consumers would wait forever\n\t\t\t// on a table this session can no longer fill. Now they fall back to standing\n\t\t\t// requests, which this session still answers.\n\t\t\tif (!dead) {\n\t\t\t\tconsole.warn(\"broadcast discovery failed; broadcasts resolve on request only.\", failure);\n\t\t\t\tdetach();\n\t\t\t\tdetach = originWire.attach(false);\n\t\t\t}\n\t\t}\n\t})();\n}\n\n/**\n * Answer the origin's open requests with blind subscriptions for the session's lifetime.\n *\n * Every session answers, discovery or not: subscribing to an unannounced path is always\n * legal, and a missing broadcast surfaces as a reset on the first track. The first session\n * to answer wins; when this session dies its answers are withdrawn so a later session\n * answers again, which is what makes a request span reconnects.\n *\n * A path the table already routes is left alone. A request resolves to the table's route over\n * any blind answer, so answering one would only park a handle nothing reads.\n */\nasync function drive(handle: Dynamic, conn: Established): Promise<void> {\n\tconst session = wireOf(conn);\n\ttry {\n\t\tfor await (const request of handle.requested()) {\n\t\t\trequest.accept(session.consume(request.path));\n\t\t}\n\t} catch {\n\t\thandle.close();\n\t}\n}\n\nasync function serveRequests(conn: Established, origin: OriginProducer): Promise<void> {\n\tconst table = wireOf(origin);\n\tconst session = wireOf(conn);\n\t// The withdraws for the answers this session provided, so a dead session only takes\n\t// back its own. Keyed by path but remembering the slot, because a path outlives its\n\t// slot: the last handle closing tears the slot down and a new request installs a fresh\n\t// one, and those two writes coalesce into a single wakeup. Matching on the path alone\n\t// would read the new slot as already answered and leave it unanswered forever.\n\tconst answered = new Map<Path.Valid, { slot: RequestSlot; withdraw: Dispose }>();\n\n\tlet dead = false;\n\tconst closed = conn.closed.then(() => {\n\t\tdead = true;\n\t});\n\n\tfor (;;) {\n\t\tconst map = table.requests.peek();\n\t\tif (!map || dead) break;\n\n\t\tfor (const [path, slot] of map) {\n\t\t\tif (slot.blind === 0) continue;\n\t\t\tif (answered.get(path)?.slot === slot || slot.answer !== undefined) continue;\n\t\t\tif (table.routes(path)) continue;\n\t\t\tconst withdraw = table.answer(path, session.consume(path));\n\t\t\tif (withdraw) answered.set(path, { slot, withdraw });\n\t\t}\n\n\t\t// A withdrawn request already released the answer; just forget our claim on the path.\n\t\t// A replaced slot counts as withdrawn: the answer we hold belongs to the slot that\n\t\t// went away, not to whatever now occupies the path.\n\t\tfor (const [path, entry] of [...answered]) {\n\t\t\tif (map.get(path) === entry.slot && entry.slot.blind > 0) continue;\n\t\t\tanswered.delete(path);\n\t\t\tentry.withdraw();\n\t\t}\n\n\t\t// Woken by the table too, not just the requests: a path that stops being routed needs\n\t\t// the blind answer this loop skipped while it was.\n\t\tawait Promise.race([table.changed(), closed]);\n\t}\n\n\t// Session gone: withdraw our answers, waking a standby session to provide fresh ones.\n\tfor (const { withdraw } of answered.values()) {\n\t\twithdraw();\n\t}\n\tanswered.clear();\n}\n"]}
|
|
@@ -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":"AACA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAU,MAAM,EAAU,MAAM,cAAc,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CAClC,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;CAAE,CAAC,CAuBxF"}
|
package/connection/handshake.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* @ts-self-types="./handshake.d.ts" */
|
|
2
|
+
import { randomHop } from "../hop.js";
|
|
2
3
|
import * as Ietf from "../ietf/index.js";
|
|
3
|
-
import { randomOrigin } from "../origin.js";
|
|
4
4
|
import { Reader, Stream, Writer } from "../stream.js";
|
|
5
5
|
/**
|
|
6
6
|
* Draft-17+ SETUP exchange. Each side opens a uni stream, writes its Setup
|
|
@@ -22,7 +22,7 @@ export async function exchangeSetup(transport, version, implementation) {
|
|
|
22
22
|
Ietf.solicitIntoSetup(params);
|
|
23
23
|
// One id per session, like the moq-lite connection: nothing in this process forwards
|
|
24
24
|
// between sessions, so there is nothing for a shared id to detect.
|
|
25
|
-
const self =
|
|
25
|
+
const self = randomHop();
|
|
26
26
|
Ietf.Cluster.intoSetup(params, self, version);
|
|
27
27
|
const setupMsg = new Ietf.Setup({ parameters: params });
|
|
28
28
|
const [writer, received] = await Promise.all([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handshake.js","sourceRoot":"","sources":["../../src/connection/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,SAAuB,EACvB,OAAyB,EACzB,cAAsB;IAEtB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;IACvC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;IACjF,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE9B,qFAAqF;IACrF,mEAAmE;IACnE,MAAM,IAAI,GAAG,SAAS,EAAE,CAAC;IACzB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAE9C,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IAExD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC5C,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,QAA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,KAAK,CAAC,0CAA0C,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEvD,OAAO;QACN,MAAM;QACN,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC;QAChD,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;KAC1D,CAAC;AACH,CAAC","sourcesContent":["import { type Hop, randomHop } from \"../hop.ts\";\nimport * as Ietf from \"../ietf/index.ts\";\nimport { Reader, Stream, 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 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<{ control: Stream; solicit: boolean | undefined; cluster: Ietf.Cluster.Hops }> {\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\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\tsolicit: received.solicit,\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\nasync function receiveSetup(\n\ttransport: WebTransport,\n\tversion: Ietf.IetfVersion,\n): Promise<{ reader: Reader; solicit: boolean | undefined; cluster: Hop | undefined }> {\n\tconst uniReader = transport.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\tReadableStream<Uint8Array>\n\t>;\n\tconst next = await uniReader.read();\n\tuniReader.releaseLock();\n\tif (next.done) throw new Error(\"no incoming uni stream for SETUP\");\n\n\tconst reader = new Reader(next.value, undefined, version);\n\n\tconst streamType = await reader.u53();\n\tif (streamType !== Ietf.Setup.id) {\n\t\tthrow new Error(`unexpected stream type on setup uni: 0x${streamType.toString(16)}`);\n\t}\n\tconst setup = await Ietf.Setup.decode(reader, version);\n\n\treturn {\n\t\treader,\n\t\tsolicit: Ietf.solicitFromSetup(setup.parameters),\n\t\tcluster: Ietf.Cluster.fromSetup(setup.parameters, version),\n\t};\n}\n"]}
|
package/connection/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A reconnecting, shareable handle on a MoQ session, plus one-shot connect/accept.
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export { type AcceptProps, accept } from "./accept";
|
|
7
7
|
export { isWebTransportSupported } from "./browser";
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
8
|
+
export { type CertificateHash, type ConnectProps, certificateHash, connect, type WebSocketProps, type WebTransportProps, } from "./connect";
|
|
9
|
+
export type { Established } from "./established";
|
|
10
|
+
export { Connection, type ConnectionProps } from "./pool";
|
|
11
11
|
export type { Probe, Stats } from "./stats";
|
|
12
12
|
export type { Transport } from "./transport";
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,eAAe,EACf,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,iBAAiB,GACtB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAC7D,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
package/connection/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/* @ts-self-types="./index.d.ts" */
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* A reconnecting, shareable handle on a MoQ session, plus one-shot connect/accept.
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export { accept } from "./accept.js";
|
|
8
8
|
export { isWebTransportSupported } from "./browser.js";
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export * from "./reload.js";
|
|
9
|
+
export { certificateHash, connect, } from "./connect.js";
|
|
10
|
+
export { Connection } from "./pool.js";
|
|
12
11
|
//# sourceMappingURL=index.js.map
|
package/connection/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAoB,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAGN,eAAe,EACf,OAAO,GAGP,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,UAAU,EAAwB,MAAM,WAAW,CAAC","sourcesContent":["/**\n * A reconnecting, shareable handle on a MoQ session, plus one-shot connect/accept.\n *\n * @module\n */\nexport { type AcceptProps, accept } from \"./accept.ts\";\nexport { isWebTransportSupported } from \"./browser.ts\";\nexport {\n\ttype CertificateHash,\n\ttype ConnectProps,\n\tcertificateHash,\n\tconnect,\n\ttype WebSocketProps,\n\ttype WebTransportProps,\n} from \"./connect.ts\";\nexport type { Established } from \"./established.ts\";\nexport { Connection, type ConnectionProps } from \"./pool.ts\";\nexport type { Probe, Stats } from \"./stats.ts\";\nexport type { Transport } from \"./transport.ts\";\n"]}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A reconnecting, shareable connection: one origin and one reconnect loop per relay URL.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type GetPromise, type Getter, Signal } from "@moq/signals";
|
|
7
|
+
import * as Announce from "../announced";
|
|
8
|
+
import type { Handle } from "../bandwidth";
|
|
9
|
+
import * as Origin from "../origin";
|
|
10
|
+
import * as Path from "../path";
|
|
11
|
+
import * as Time from "../time";
|
|
12
|
+
import { type AcceptProps as AcceptPropsType, accept } from "./accept";
|
|
13
|
+
import { isWebTransportSupported } from "./browser";
|
|
14
|
+
import { type CertificateHash as CertificateHashType, type ConnectProps as ConnectPropsType, certificateHash, connect, type WebSocketProps as WebSocketPropsType, type WebTransportProps as WebTransportPropsType } from "./connect";
|
|
15
|
+
import type { Established as EstablishedType } from "./established";
|
|
16
|
+
import { type ReloadDelay, type ReloadStatus } from "./reload";
|
|
17
|
+
import type { Probe as ProbeType, Stats as StatsType } from "./stats";
|
|
18
|
+
import type { Transport as TransportType } from "./transport";
|
|
19
|
+
/** Options for {@link Connection}. */
|
|
20
|
+
export interface ConnectionProps {
|
|
21
|
+
/** The relay to connect to; pass a `Signal` to switch relays live. */
|
|
22
|
+
url?: URL | Signal<URL | undefined>;
|
|
23
|
+
/** Whether to connect at all (default: true); pass a `Signal` to toggle live. */
|
|
24
|
+
enabled?: boolean | Signal<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* How long the underlying connection outlives its last handle (default: 2000ms).
|
|
27
|
+
*
|
|
28
|
+
* The window is what makes moving an element around the DOM free: the connection and
|
|
29
|
+
* everything it discovered are still warm when the new owner asks for them. The longest
|
|
30
|
+
* linger requested by any handle sharing the connection wins.
|
|
31
|
+
*/
|
|
32
|
+
linger?: Time.Milli;
|
|
33
|
+
/**
|
|
34
|
+
* Share a pooled transport keyed on the URL (default: true).
|
|
35
|
+
*
|
|
36
|
+
* Options the pool cannot honor (transport options, discovery, delay, a pinned
|
|
37
|
+
* certificate, caller-owned origins) require `share: false` and get a private
|
|
38
|
+
* reconnect loop with the same handle semantics.
|
|
39
|
+
*/
|
|
40
|
+
share?: boolean;
|
|
41
|
+
/** WebTransport options applied to each connection attempt (not reactive). */
|
|
42
|
+
webtransport?: WebTransportPropsType;
|
|
43
|
+
/** WebSocket fallback options applied to each connection attempt (not reactive). */
|
|
44
|
+
websocket?: WebSocketPropsType;
|
|
45
|
+
/** Whether the relay supports broadcast discovery. */
|
|
46
|
+
discovery?: boolean;
|
|
47
|
+
/** The origin whose broadcasts are served, spanning reconnects. Requires {@link ConnectionProps.share} `false`. */
|
|
48
|
+
publish?: Origin.Consumer;
|
|
49
|
+
/** The origin fed with the peer's announced broadcasts, spanning reconnects. Requires {@link ConnectionProps.share} `false`. */
|
|
50
|
+
consume?: Origin.Producer;
|
|
51
|
+
/** Backoff settings for the reconnect loop; an unset field uses its default. */
|
|
52
|
+
delay?: ReloadDelay;
|
|
53
|
+
/** A Connection owns the abort signal for each connection attempt. */
|
|
54
|
+
signal?: never;
|
|
55
|
+
/** A one-shot transport cannot be reused by the reconnect loop; call {@link Connection.connect} instead. */
|
|
56
|
+
transport?: never;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A cloneable handle on a MoQ connection: `new Connection({ url })` reconnects and, by
|
|
60
|
+
* default, shares one origin and one reconnect loop with every other handle on that URL.
|
|
61
|
+
*
|
|
62
|
+
* The shared {@link origin} is wired to both directions. Everything the relay announces
|
|
63
|
+
* lands in it, a publish into it is announced to the relay, and a page that publishes and
|
|
64
|
+
* watches the same path resolves it locally with no round trip.
|
|
65
|
+
*
|
|
66
|
+
* {@link close} releases this handle; the connection survives its last handle by a short
|
|
67
|
+
* linger window (see {@link ConnectionProps.linger}), so a component torn down and rebuilt
|
|
68
|
+
* reuses the warm connection instead of redialing.
|
|
69
|
+
*
|
|
70
|
+
* The loop reconnects for as long as a handle holds it, so an outage of any length recovers
|
|
71
|
+
* on its own. An auth rejection stops retrying those credentials and retires the shared
|
|
72
|
+
* connection so the next handle dials fresh; a new URL on this handle starts another
|
|
73
|
+
* sequence. {@link closed} settles only when this handle is released.
|
|
74
|
+
*
|
|
75
|
+
* Options the pool cannot honor (transport options, discovery, delay, a pinned
|
|
76
|
+
* certificate, caller-owned origins) take `share: false` and get a private loop. A
|
|
77
|
+
* supplied transport cannot reconnect at all; pass it to {@link Connection.connect}
|
|
78
|
+
* instead.
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export declare class Connection {
|
|
83
|
+
#private;
|
|
84
|
+
/** Establish a one-shot session; a supplied transport belongs here, not in the reconnect loop. */
|
|
85
|
+
static readonly connect: typeof connect;
|
|
86
|
+
/** Accept a one-shot session on an already-open transport. */
|
|
87
|
+
static readonly accept: typeof accept;
|
|
88
|
+
/** SHA-256 of a certificate, for pinning via `webtransport.serverCertificateHashes`. */
|
|
89
|
+
static readonly certificateHash: typeof certificateHash;
|
|
90
|
+
/** Whether this runtime can connect with WebTransport. */
|
|
91
|
+
static readonly isWebTransportSupported: typeof isWebTransportSupported;
|
|
92
|
+
/** Relay URL to connect to; updating it reconnects to that URL. */
|
|
93
|
+
url: Signal<URL | undefined>;
|
|
94
|
+
/** Whether to hold a connection at all; clearing it releases this handle's share. */
|
|
95
|
+
enabled: Signal<boolean>;
|
|
96
|
+
/** Current status of the connection. */
|
|
97
|
+
readonly status: Getter<ReloadStatus>;
|
|
98
|
+
/**
|
|
99
|
+
* The failure that stopped retrying the current URL, or undefined while the loop is live.
|
|
100
|
+
*
|
|
101
|
+
* Set on an auth rejection or when a private retry window expires. Cleared when a new URL
|
|
102
|
+
* or a disable/re-enable starts another sequence, not on a page hide/show.
|
|
103
|
+
*/
|
|
104
|
+
readonly error: Getter<Error | undefined>;
|
|
105
|
+
/**
|
|
106
|
+
* The wire transport the current session runs over, or undefined while disconnected.
|
|
107
|
+
*
|
|
108
|
+
* The session itself is deliberately not exposed: it is shared, so no handle may close
|
|
109
|
+
* or reconfigure it, and everything else it offers is reachable through {@link origin}.
|
|
110
|
+
*/
|
|
111
|
+
readonly transport: Getter<TransportType | undefined>;
|
|
112
|
+
/** The current connection's PROBE estimates, or undefined while disconnected. */
|
|
113
|
+
readonly probe: Getter<ProbeType | undefined>;
|
|
114
|
+
/**
|
|
115
|
+
* The send-side bandwidth allocator for the current URL, or undefined
|
|
116
|
+
* while disabled or URL-less.
|
|
117
|
+
*
|
|
118
|
+
* Every handle on this URL shares the same instance, so publishers reserve
|
|
119
|
+
* against one registry. Borrowed, not owned: the type has no close, since
|
|
120
|
+
* closing it would starve every other handle.
|
|
121
|
+
*/
|
|
122
|
+
readonly bandwidth: Getter<Handle | undefined>;
|
|
123
|
+
/**
|
|
124
|
+
* The origin for the current URL, or undefined while disabled or URL-less.
|
|
125
|
+
*
|
|
126
|
+
* Publish into it or consume from it; a shared handle's origin is the same one every
|
|
127
|
+
* other handle on this URL uses, and it spans the connection's reconnects. Borrowed,
|
|
128
|
+
* not owned: the type has no close, since closing it would tear the origin down under
|
|
129
|
+
* every other handle.
|
|
130
|
+
*/
|
|
131
|
+
readonly origin: Getter<Origin.Table | undefined>;
|
|
132
|
+
/**
|
|
133
|
+
* Settles once this handle is released via {@link close}: `null` on a clean close, or
|
|
134
|
+
* the abort {@link Error}. Peek it synchronously (`undefined` while open), observe it
|
|
135
|
+
* reactively, or `await` it. Attempt failures live on {@link error} instead.
|
|
136
|
+
*/
|
|
137
|
+
get closed(): GetPromise<Error | null>;
|
|
138
|
+
/**
|
|
139
|
+
* Take a handle on the connection for {@link ConnectionProps.url}.
|
|
140
|
+
*
|
|
141
|
+
* Dials immediately when a URL is given and `enabled` is not false; otherwise waits for
|
|
142
|
+
* the signals to say go. The handle owns nothing but its own share: {@link close}
|
|
143
|
+
* releases it, and the underlying connection and origin live for as long as any handle
|
|
144
|
+
* (plus the linger window) wants them.
|
|
145
|
+
*/
|
|
146
|
+
constructor(props?: ConnectionProps);
|
|
147
|
+
/**
|
|
148
|
+
* Subscribe to broadcast announcements matching `scope`, spanning reconnects
|
|
149
|
+
* and URL switches: a switch retracts everything from
|
|
150
|
+
* the old relay's origin, then the new one's arrivals stream in.
|
|
151
|
+
*/
|
|
152
|
+
announced(scope?: Path.Pattern): Announce.Consumer;
|
|
153
|
+
/** Snapshot the live connection's transport counters, or undefined while disconnected. */
|
|
154
|
+
stats(): Promise<StatsType | undefined>;
|
|
155
|
+
/**
|
|
156
|
+
* Release this handle. The shared connection closes once its last handle is gone and
|
|
157
|
+
* the linger window passes; other handles on the URL are unaffected. Idempotent.
|
|
158
|
+
*/
|
|
159
|
+
close(abort?: Error): void;
|
|
160
|
+
}
|
|
161
|
+
/** Types on {@link Connection}: the handle is the class, these are its associated types. */
|
|
162
|
+
export declare namespace Connection {
|
|
163
|
+
/** Options for {@link Connection}. */
|
|
164
|
+
type Props = ConnectionProps;
|
|
165
|
+
/** Options for {@link Connection.connect}. */
|
|
166
|
+
type ConnectProps = ConnectPropsType;
|
|
167
|
+
/** Options for {@link Connection.accept}. */
|
|
168
|
+
type AcceptProps = AcceptPropsType;
|
|
169
|
+
/** Backoff settings for a private reconnect loop. */
|
|
170
|
+
type Backoff = ReloadDelay;
|
|
171
|
+
/** Current state of a {@link Connection}. */
|
|
172
|
+
type Status = ReloadStatus;
|
|
173
|
+
/** The current connection's PROBE estimates. */
|
|
174
|
+
type Probe = ProbeType;
|
|
175
|
+
/** A point-in-time snapshot of the transport's counters. */
|
|
176
|
+
type Stats = StatsType;
|
|
177
|
+
/** The wire transport a session runs over. */
|
|
178
|
+
type Transport = TransportType;
|
|
179
|
+
/** Tuning for the WebSocket fallback. */
|
|
180
|
+
type WebSocketProps = WebSocketPropsType;
|
|
181
|
+
/** WebTransport options, including friendlier certificate pinning. */
|
|
182
|
+
type WebTransportProps = WebTransportPropsType;
|
|
183
|
+
/** A server certificate hash used to pin a self-signed server. */
|
|
184
|
+
type CertificateHash = CertificateHashType;
|
|
185
|
+
/** An established one-shot session. */
|
|
186
|
+
type Established = EstablishedType;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/connection/pool.ts"],"names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