@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
package/lite/subscriber.js
CHANGED
|
@@ -3,13 +3,15 @@ import { Signal } from "@moq/signals";
|
|
|
3
3
|
import * as announce from "../announced.js";
|
|
4
4
|
import * as broadcast from "../broadcast.js";
|
|
5
5
|
import { BroadcastCache } from "../consume.js";
|
|
6
|
-
import { error, ProtocolViolation, reason } from "../error.js";
|
|
6
|
+
import { controlTimeout, error, ProtocolViolation, reason, StreamCode, StreamError } from "../error.js";
|
|
7
7
|
import * as netGroup from "../group.js";
|
|
8
|
-
import {
|
|
8
|
+
import { Cost, MAX_HOPS, routesEqual, UNKNOWN_HOP } from "../hop.js";
|
|
9
|
+
import { groupBounds, scopeCaptures, scopeHead, scopeOverlaps } from "../internal.js";
|
|
9
10
|
import * as Path from "../path.js";
|
|
10
11
|
import { Stream } from "../stream.js";
|
|
11
12
|
import * as Time from "../time.js";
|
|
12
|
-
import { withTimeout } from "../util/timeout.js";
|
|
13
|
+
import { TimeoutError, withTimeout } from "../util/timeout.js";
|
|
14
|
+
import { overrideBroadcastWire, wireOf } from "../wire.js";
|
|
13
15
|
import { AnnounceInit, AnnounceOk, AnnounceRequest, decodeAnnounceBroadcastMaybe } from "./announce.js";
|
|
14
16
|
import { Datagram as DatagramMessage } from "./datagram.js";
|
|
15
17
|
import * as DatagramStream from "./datagram_stream.js";
|
|
@@ -18,9 +20,9 @@ import { sendOrder } from "./priority.js";
|
|
|
18
20
|
import { Probe } from "./probe.js";
|
|
19
21
|
import { ProbeLevel } from "./setup.js";
|
|
20
22
|
import { StreamId } from "./stream.js";
|
|
21
|
-
import { decodeSubscribeResponse, decodeSubscribeResponseMaybe, Subscribe, SubscribeUpdate } from "./subscribe.js";
|
|
23
|
+
import { decodeSubscribeResponse, decodeSubscribeResponseMaybe, EMPTY_RANGE, emptyRange, exclusiveGroupEnd, inclusiveGroupEnd, Subscribe, SubscribeUpdate, } from "./subscribe.js";
|
|
22
24
|
import { TrackInfo, Track as TrackMessage } from "./track.js";
|
|
23
|
-
import { hasAnnounceId, hasAnnounceOk, hasDatagrams,
|
|
25
|
+
import { hasAnnounceId, hasAnnounceOk, hasDatagrams, hasProbeRtt, restartSupported, Version } from "./version.js";
|
|
24
26
|
// Bound on how long stream-open plus the first response (SUBSCRIBE_OK on older
|
|
25
27
|
// drafts, or TRACK_INFO on lite-05+) may take. Browsers cap concurrent QUIC streams
|
|
26
28
|
// (Chrome ~100) and we open with waitUntilAvailable, so past the cap the open blocks
|
|
@@ -69,9 +71,8 @@ export class Subscriber {
|
|
|
69
71
|
#quic;
|
|
70
72
|
// The version of the connection.
|
|
71
73
|
version;
|
|
72
|
-
// Shared with the Publisher so
|
|
73
|
-
|
|
74
|
-
origin;
|
|
74
|
+
// Shared with the Publisher so reflected announces can be dropped on receipt.
|
|
75
|
+
hop;
|
|
75
76
|
// Our subscribed tracks. `timescale` resolves once known (from TRACK_INFO on
|
|
76
77
|
// lite-05+, or implicit defaults on older drafts); group streams block on it
|
|
77
78
|
// before decoding any frame, since a group's QUIC stream can race ahead.
|
|
@@ -94,43 +95,40 @@ export class Subscriber {
|
|
|
94
95
|
* Creates a new Subscriber instance.
|
|
95
96
|
* @param quic - The WebTransport session to use
|
|
96
97
|
* @param version - The protocol version
|
|
97
|
-
* @param origin -
|
|
98
|
+
* @param origin - Hop id shared with the Publisher
|
|
98
99
|
* @param probe - Optional sink for the peer's PROBE estimates
|
|
99
100
|
* @param peerSetup - Optional peer SETUP slot for capability gating (lite-05+)
|
|
100
101
|
*
|
|
101
102
|
* @internal
|
|
102
103
|
*/
|
|
103
|
-
constructor(quic, version,
|
|
104
|
+
constructor(quic, version, hop, probe, peerSetup) {
|
|
104
105
|
this.#quic = quic;
|
|
105
106
|
this.version = version;
|
|
106
|
-
this.
|
|
107
|
+
this.hop = hop;
|
|
107
108
|
this.#probe = probe;
|
|
108
109
|
this.#peerSetup = peerSetup;
|
|
109
110
|
}
|
|
110
111
|
/**
|
|
111
|
-
* Subscribe to broadcast announcements
|
|
112
|
+
* Subscribe to broadcast announcements matching `scope`. Paths are relative
|
|
113
|
+
* to the session, not the scope.
|
|
112
114
|
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
+
* Reflected announces (those whose hop chain already includes this
|
|
116
|
+
* connection) are always dropped: moq-lite-06 has none to keep, and older
|
|
117
|
+
* versions stay consistent with that.
|
|
115
118
|
*/
|
|
116
|
-
announced(
|
|
117
|
-
const announced = new announce.Producer(
|
|
118
|
-
|
|
119
|
+
announced(scope = Path.Pattern.all()) {
|
|
120
|
+
const announced = new announce.Producer();
|
|
121
|
+
// The wire speaks announce interest by prefix, and echoes suffixes beneath it.
|
|
122
|
+
void this.#runAnnounced(announced, scopeHead(scope), scope);
|
|
119
123
|
return announced.consume();
|
|
120
124
|
}
|
|
121
|
-
async #runAnnounced(announced, prefix,
|
|
125
|
+
async #runAnnounced(announced, prefix, scope) {
|
|
122
126
|
console.debug(`announced: prefix=${prefix}`);
|
|
123
|
-
// Lite04/05: send our own session-level
|
|
127
|
+
// Lite04/05: send our own session-level Hop ID so the peer can skip announces
|
|
124
128
|
// whose hop chain already passed through us. Encoding drops it on every other
|
|
125
129
|
// version, where we drop the reflected announce on receipt instead. Matches the
|
|
126
130
|
// Rust subscriber's `exclude_hop: self.self_origin.id` in `run_announce_prefix`.
|
|
127
|
-
const msg = new AnnounceRequest(prefix, this.
|
|
128
|
-
// Drop reflected announces so callers asking for "someone else's broadcasts"
|
|
129
|
-
// don't re-see their own publishes. A caller can always ask for this, and it is
|
|
130
|
-
// required on versions that don't carry excludeHop above: there the peer isn't
|
|
131
|
-
// filtering them out for us, so filtering here keeps what the app sees the same
|
|
132
|
-
// as lite-05. Lite01-03 carry no real hop ids, so the check never matches there.
|
|
133
|
-
const dropReflected = options.ignoreSelf || !hasExcludeHop(this.version);
|
|
131
|
+
const msg = new AnnounceRequest(prefix, this.hop);
|
|
134
132
|
// Opened outside the try so the catch can reach it: a protocol violation below has
|
|
135
133
|
// to reset the stream, not just close our side of it.
|
|
136
134
|
let stream;
|
|
@@ -145,17 +143,16 @@ export class Subscriber {
|
|
|
145
143
|
// Send the announce interest.
|
|
146
144
|
await stream.writer.u53(StreamId.Announce);
|
|
147
145
|
await msg.encode(stream.writer, this.version);
|
|
148
|
-
// Lite05+: the publisher reports its own
|
|
146
|
+
// Lite05+: the publisher reports its own Hop ID before any announces.
|
|
149
147
|
// It no longer stamps itself onto each hop chain, so we append it here to
|
|
150
|
-
// keep the
|
|
148
|
+
// keep the reflected-announce loop check seeing the full chain.
|
|
151
149
|
let responderOrigin;
|
|
152
150
|
if (hasAnnounceOk(this.version)) {
|
|
153
151
|
const ok = await AnnounceOk.decode(stream.reader, this.version);
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
responderOrigin = ok.origin === UNKNOWN_ORIGIN ? undefined : ok.origin;
|
|
152
|
+
// Keep a withheld 0: it names nobody for loop detection, but it is the
|
|
153
|
+
// anonymous mark and must travel the reconstructed chain. Assigned identities
|
|
154
|
+
// stay off this hop and are never forwarded.
|
|
155
|
+
responderOrigin = ok.hop;
|
|
159
156
|
}
|
|
160
157
|
const advertised = new Map();
|
|
161
158
|
switch (this.version) {
|
|
@@ -170,12 +167,17 @@ export class Subscriber {
|
|
|
170
167
|
// ANNOUNCE_OK, so nothing names the publisher.
|
|
171
168
|
for (const suffix of init.suffixes) {
|
|
172
169
|
const path = Path.join(prefix, suffix);
|
|
173
|
-
if (advertised.has(
|
|
170
|
+
if (advertised.has(path)) {
|
|
174
171
|
throw new ProtocolViolation(`duplicate announce for ${path}`);
|
|
175
172
|
}
|
|
176
|
-
|
|
173
|
+
const route = { hops: [UNKNOWN_HOP], cost: Cost.zero };
|
|
174
|
+
const live = scopeOverlaps(scope, path);
|
|
175
|
+
const captures = scopeCaptures(scope, path);
|
|
176
|
+
advertised.set(path, { publisher: undefined, live, route, captures });
|
|
177
|
+
if (!live)
|
|
178
|
+
continue;
|
|
177
179
|
console.debug(`announced: broadcast=${path} active=true`);
|
|
178
|
-
announced.append({
|
|
180
|
+
announced.append({ prefix: path, captures, kind: "announced", route });
|
|
179
181
|
}
|
|
180
182
|
break;
|
|
181
183
|
}
|
|
@@ -185,7 +187,7 @@ export class Subscriber {
|
|
|
185
187
|
}
|
|
186
188
|
// Lite06+: announce ids. Each received `active` implicitly assigns the next
|
|
187
189
|
// per-stream ordinal; `endedId`/`restart` reference it. Tracked even for
|
|
188
|
-
// announces we skip
|
|
190
|
+
// announces we skip as reflected, since the sender doesn't know we skipped.
|
|
189
191
|
let nextAnnounceId = 0n;
|
|
190
192
|
const announcedById = new Map();
|
|
191
193
|
// Receive announce updates (for Draft03, this includes initial state)
|
|
@@ -199,45 +201,55 @@ export class Subscriber {
|
|
|
199
201
|
break;
|
|
200
202
|
if (announce instanceof Error)
|
|
201
203
|
throw announce;
|
|
202
|
-
let
|
|
204
|
+
let path;
|
|
203
205
|
let active;
|
|
204
206
|
// Present on active/restart; ended messages never carry hops worth checking.
|
|
205
207
|
let hops;
|
|
208
|
+
let cost;
|
|
206
209
|
switch (announce.status) {
|
|
207
210
|
case "active":
|
|
208
|
-
suffix
|
|
211
|
+
// The wire names the suffix beneath the interest prefix; the consumer
|
|
212
|
+
// sees the covered path from the session root.
|
|
213
|
+
path = Path.join(prefix, announce.suffix);
|
|
209
214
|
active = true;
|
|
210
215
|
hops = announce.hops;
|
|
216
|
+
cost = announce.cost;
|
|
211
217
|
if (hasAnnounceId(this.version)) {
|
|
212
|
-
announcedById.set(nextAnnounceId++,
|
|
218
|
+
announcedById.set(nextAnnounceId++, path);
|
|
213
219
|
}
|
|
214
220
|
break;
|
|
215
221
|
case "ended":
|
|
216
|
-
|
|
222
|
+
path = Path.join(prefix, announce.suffix);
|
|
217
223
|
active = false;
|
|
218
224
|
break;
|
|
219
225
|
case "endedId": {
|
|
220
226
|
// Resolve and retire the id; an unknown or retired id is a protocol violation.
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
227
|
+
const resolved = announcedById.get(announce.id);
|
|
228
|
+
if (resolved === undefined)
|
|
223
229
|
throw new ProtocolViolation(`unknown announce id: ${announce.id}`);
|
|
224
230
|
announcedById.delete(announce.id);
|
|
225
|
-
|
|
231
|
+
if (resolved === null)
|
|
232
|
+
continue;
|
|
233
|
+
path = resolved;
|
|
226
234
|
active = false;
|
|
227
235
|
break;
|
|
228
236
|
}
|
|
229
237
|
case "restart": {
|
|
230
238
|
// Resolve the id; it stays live (the replacement reuses it).
|
|
231
|
-
const
|
|
232
|
-
if (
|
|
239
|
+
const resolved = announcedById.get(announce.id);
|
|
240
|
+
if (resolved === undefined)
|
|
233
241
|
throw new ProtocolViolation(`unknown announce id: ${announce.id}`);
|
|
234
|
-
|
|
242
|
+
if (resolved === null)
|
|
243
|
+
continue;
|
|
244
|
+
path = resolved;
|
|
235
245
|
active = true;
|
|
236
246
|
hops = announce.hops;
|
|
247
|
+
cost = announce.cost;
|
|
237
248
|
break;
|
|
238
249
|
}
|
|
250
|
+
case "skipped":
|
|
251
|
+
continue;
|
|
239
252
|
}
|
|
240
|
-
const path = Path.join(prefix, suffix);
|
|
241
253
|
// One current advertisement per path per stream, decided before anything below
|
|
242
254
|
// can skip this announcement. A second ANNOUNCE_START for a path the peer
|
|
243
255
|
// already advertised is a violation whether or not its route would be usable
|
|
@@ -250,7 +262,7 @@ export class Subscriber {
|
|
|
250
262
|
// a duplicate means the same thing on both sides of it. Mirrors the branch the
|
|
251
263
|
// Rust announce loop takes before `start_announce`.
|
|
252
264
|
const duplicateIsRestart = restartSupported(this.version) && !hasAnnounceId(this.version);
|
|
253
|
-
if (announce.status === "active" && !duplicateIsRestart && advertised.has(
|
|
265
|
+
if (announce.status === "active" && !duplicateIsRestart && advertised.has(path)) {
|
|
254
266
|
throw new ProtocolViolation(`duplicate announce for ${path}`);
|
|
255
267
|
}
|
|
256
268
|
// Retract the path: forget the advertisement, drop the shared consume entry so a
|
|
@@ -258,63 +270,101 @@ export class Subscriber {
|
|
|
258
270
|
// and tell the consumer. A no-op for an advertisement never surfaced, which is
|
|
259
271
|
// what an id retiring a skipped announce resolves to.
|
|
260
272
|
const retract = () => {
|
|
261
|
-
const previous = advertised.get(
|
|
262
|
-
advertised.delete(
|
|
273
|
+
const previous = advertised.get(path);
|
|
274
|
+
advertised.delete(path);
|
|
263
275
|
if (!previous?.live)
|
|
264
276
|
return;
|
|
265
277
|
this.#consumes.evict(path);
|
|
266
278
|
console.debug(`announced: broadcast=${path} active=false`);
|
|
267
|
-
announced.append({
|
|
279
|
+
announced.append({
|
|
280
|
+
prefix: path,
|
|
281
|
+
captures: previous.captures,
|
|
282
|
+
kind: "retracted",
|
|
283
|
+
route: previous.route,
|
|
284
|
+
});
|
|
268
285
|
};
|
|
269
286
|
// In Lite05+ the sender's origin arrives via AnnounceOk, not in each hop
|
|
270
287
|
// list, so fold it back in before checking.
|
|
271
|
-
if (hops !== undefined
|
|
288
|
+
if (hops !== undefined) {
|
|
272
289
|
const full = responderOrigin !== undefined ? [...hops, responderOrigin] : hops;
|
|
273
|
-
if (full.includes(this.
|
|
290
|
+
if (full.includes(this.hop)) {
|
|
274
291
|
// A reflected restart means the peer's remaining route loops back through
|
|
275
292
|
// us, so the route is gone even though the message says active. The
|
|
276
293
|
// advertisement stays live: the peer still holds the path and its id still
|
|
277
294
|
// resolves here.
|
|
278
295
|
retract();
|
|
279
|
-
advertised.set(
|
|
296
|
+
advertised.set(path, {
|
|
297
|
+
publisher: undefined,
|
|
298
|
+
live: false,
|
|
299
|
+
route: { hops: full, cost: Cost.zero },
|
|
300
|
+
captures: undefined,
|
|
301
|
+
});
|
|
280
302
|
continue;
|
|
281
303
|
}
|
|
282
304
|
}
|
|
283
|
-
if (active) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
305
|
+
if (!active) {
|
|
306
|
+
retract();
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
// The first hop identifies the original publisher; an empty chain means the
|
|
310
|
+
// peer itself originated it. See `restart_announce` in the Rust subscriber.
|
|
311
|
+
const publisher = hops?.[0] ?? responderOrigin;
|
|
312
|
+
// A publisher with no identity (an empty chain from a peer that withheld its
|
|
313
|
+
// own id, or a lite-03 UNKNOWN placeholder) never proves continuity: two such
|
|
314
|
+
// advertisements can be unrelated publishers. Mirrors the
|
|
315
|
+
// `publisher == Hop::UNKNOWN` arm of the Rust `restart_announce`.
|
|
316
|
+
const identified = publisher !== undefined && publisher !== UNKNOWN_HOP;
|
|
317
|
+
const fullHops = hops !== undefined && responderOrigin !== undefined
|
|
318
|
+
? [...hops, responderOrigin]
|
|
319
|
+
: [...(hops ?? [])];
|
|
320
|
+
// A received empty list is the anonymous mark, not a local announcement.
|
|
321
|
+
if (fullHops.length === 0)
|
|
322
|
+
fullHops.push(UNKNOWN_HOP);
|
|
323
|
+
// Appending a withheld AnnounceOk(0) onto a 32-entry list is the same
|
|
324
|
+
// drop Rust's Hops::push makes: do not expose an overlong chain.
|
|
325
|
+
if (fullHops.length > MAX_HOPS) {
|
|
326
|
+
console.debug(`announced: broadcast=${path} dropped (hop chain at MAX_HOPS)`);
|
|
327
|
+
advertised.set(path, {
|
|
328
|
+
publisher: undefined,
|
|
329
|
+
live: false,
|
|
330
|
+
route: { hops: [], cost: Cost.zero },
|
|
331
|
+
captures: undefined,
|
|
332
|
+
});
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const route = { hops: fullHops, cost: cost ?? Cost.zero };
|
|
336
|
+
const captures = scopeCaptures(scope, path);
|
|
337
|
+
if (!scopeOverlaps(scope, path)) {
|
|
338
|
+
advertised.set(path, { publisher, live: false, route, captures });
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
// A second advertisement for a path we already carry is a restart: either an
|
|
342
|
+
// explicit ANNOUNCE_UPDATE, or (lite-05) a duplicate ANNOUNCE.
|
|
343
|
+
const previous = advertised.get(path);
|
|
344
|
+
if (previous?.live) {
|
|
345
|
+
if (identified && previous.publisher === publisher) {
|
|
346
|
+
// Same publisher, new route. In-flight subscriptions resume across it.
|
|
347
|
+
// Emit the route so a forwarder can re-price without retracting.
|
|
348
|
+
if (!routesEqual(previous.route, route)) {
|
|
349
|
+
advertised.set(path, { publisher, live: true, route, captures });
|
|
300
350
|
console.debug(`announced: broadcast=${path} rerouted`);
|
|
301
|
-
|
|
351
|
+
announced.append({ prefix: path, captures, kind: "updated", route });
|
|
302
352
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
353
|
+
else {
|
|
354
|
+
console.debug(`announced: broadcast=${path} rerouted`);
|
|
355
|
+
}
|
|
356
|
+
continue;
|
|
306
357
|
}
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
// the *next* takeover would read as a first announcement and skip its own end.
|
|
310
|
-
advertised.set(suffix, { publisher, live: true });
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
358
|
+
// A different publisher took the path, so cached track info and existing
|
|
359
|
+
// subscriptions must not carry over. Surface a real end before the start.
|
|
313
360
|
retract();
|
|
314
|
-
continue;
|
|
315
361
|
}
|
|
362
|
+
// After `retract()`, which clears the entry: the path is advertised again, by
|
|
363
|
+
// whoever just took it over. Recording it before would leave nothing behind, so
|
|
364
|
+
// the *next* takeover would read as a first announcement and skip its own end.
|
|
365
|
+
advertised.set(path, { publisher, live: true, route, captures });
|
|
316
366
|
console.debug(`announced: broadcast=${path} active=true`);
|
|
317
|
-
announced.append({
|
|
367
|
+
announced.append({ prefix: path, captures, kind: "announced", route });
|
|
318
368
|
}
|
|
319
369
|
announced.close();
|
|
320
370
|
}
|
|
@@ -354,7 +404,7 @@ export class Subscriber {
|
|
|
354
404
|
const consumer = new ConsumeBroadcast(this, path);
|
|
355
405
|
void (async () => {
|
|
356
406
|
for (;;) {
|
|
357
|
-
const request = await consumer.requested();
|
|
407
|
+
const request = await wireOf(consumer).requested();
|
|
358
408
|
if (!request)
|
|
359
409
|
break;
|
|
360
410
|
void this.#runSubscribe(path, request);
|
|
@@ -365,19 +415,24 @@ export class Subscriber {
|
|
|
365
415
|
async #runSubscribe(broadcast, request) {
|
|
366
416
|
const id = this.#subscribeNext++;
|
|
367
417
|
const subscription = request.subscription;
|
|
418
|
+
const initialBounds = groupBounds(subscription.groups);
|
|
419
|
+
if (emptyRange({ startGroup: initialBounds.start, endGroup: initialBounds.end })) {
|
|
420
|
+
request.reject(new Error(EMPTY_RANGE));
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
368
423
|
// `timescale` stays undefined until TRACK_INFO (or, on older drafts,
|
|
369
424
|
// implicit defaults) resolves it; runGroup blocks on it before decoding.
|
|
370
425
|
const timescale = new Signal(undefined);
|
|
371
426
|
console.debug(`subscribe start: id=${id} broadcast=${broadcast} track=${request.name}`);
|
|
427
|
+
const bounds = groupBounds(subscription.groups);
|
|
372
428
|
const msg = new Subscribe({
|
|
373
429
|
id,
|
|
374
430
|
broadcast,
|
|
375
431
|
track: request.name,
|
|
376
432
|
priority: subscription.priority ?? 0,
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
endGroup: subscription.endGroup,
|
|
433
|
+
maxAge: subscription.maxAge,
|
|
434
|
+
startGroup: subscription.groups?.start === undefined ? undefined : bounds.start,
|
|
435
|
+
endGroup: inclusiveGroupEnd(bounds.end),
|
|
381
436
|
});
|
|
382
437
|
// Open the stream under a timeout. The stream handle flows back via `state`
|
|
383
438
|
// so the timeout path can abort it if it finishes opening after the deadline.
|
|
@@ -389,7 +444,9 @@ export class Subscriber {
|
|
|
389
444
|
console.debug(`subscribe ok: id=${id} broadcast=${broadcast} track=${request.name}`);
|
|
390
445
|
}
|
|
391
446
|
catch (err) {
|
|
392
|
-
|
|
447
|
+
// The setup outlived its deadline waiting for the first response: a control
|
|
448
|
+
// timeout, not content that arrived late.
|
|
449
|
+
const e = err instanceof TimeoutError ? controlTimeout(err) : error(err);
|
|
393
450
|
request.reject(e);
|
|
394
451
|
this.#subscribes.delete(id);
|
|
395
452
|
console.warn(`subscribe error: id=${id} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);
|
|
@@ -500,15 +557,14 @@ export class Subscriber {
|
|
|
500
557
|
#toModelInfo(info) {
|
|
501
558
|
return {
|
|
502
559
|
timescale: Time.Timescale(info.timescale),
|
|
503
|
-
// Publisher Max
|
|
560
|
+
// Publisher Max Age rides on the wire, so the local retention window
|
|
504
561
|
// matches what the upstream advertises (relays re-serve with the same bound).
|
|
505
|
-
|
|
562
|
+
maxAge: Time.Milli(info.maxAge),
|
|
506
563
|
priority: info.priority,
|
|
507
|
-
ordered: info.ordered,
|
|
508
564
|
};
|
|
509
565
|
}
|
|
510
566
|
// Resolve a track's immutable model info via a TRACK stream (lite-05+), for the
|
|
511
|
-
// ConsumeBroadcast backing track.Consumer.
|
|
567
|
+
// ConsumeBroadcast backing track.Consumer.query(). On older drafts there's no TRACK
|
|
512
568
|
// stream, so this rejects rather than fabricating defaults.
|
|
513
569
|
async resolveTrackInfo(broadcast, track) {
|
|
514
570
|
if (!supportsTrackStream(this.version)) {
|
|
@@ -547,7 +603,7 @@ export class Subscriber {
|
|
|
547
603
|
const stream = await Stream.open(this.#quic, { sendOrder: sendOrder({ priority }) });
|
|
548
604
|
try {
|
|
549
605
|
await stream.writer.u53(StreamId.Fetch);
|
|
550
|
-
await new FetchMessage(broadcast, track, priority, sequence).encode(stream.writer, this.version);
|
|
606
|
+
await new FetchMessage({ broadcast, track, priority, group: sequence }).encode(stream.writer, this.version);
|
|
551
607
|
}
|
|
552
608
|
catch (err) {
|
|
553
609
|
stream.abort(error(err));
|
|
@@ -636,10 +692,11 @@ export class Subscriber {
|
|
|
636
692
|
const stopped = Promise.race([track.closed, stream.reader.closed]).then(() => null);
|
|
637
693
|
let lastSent = {
|
|
638
694
|
priority: msg.priority,
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
695
|
+
maxAge: Time.Milli(msg.maxAge),
|
|
696
|
+
groups: {
|
|
697
|
+
start: msg.startGroup === undefined ? undefined : { included: msg.startGroup },
|
|
698
|
+
end: msg.endGroup === undefined ? undefined : { excluded: exclusiveGroupEnd(msg.endGroup) ?? 0 },
|
|
699
|
+
},
|
|
643
700
|
};
|
|
644
701
|
for (;;) {
|
|
645
702
|
const current = track.subscription.peek();
|
|
@@ -650,12 +707,18 @@ export class Subscriber {
|
|
|
650
707
|
return;
|
|
651
708
|
continue;
|
|
652
709
|
}
|
|
710
|
+
// Demand collapsing to nothing is refused the same way an initial empty
|
|
711
|
+
// request is: the error closes the track, so every local subscriber sees it.
|
|
712
|
+
const bounds = groupBounds(current.groups);
|
|
713
|
+
if (emptyRange({ startGroup: bounds.start, endGroup: bounds.end }))
|
|
714
|
+
throw new Error(EMPTY_RANGE);
|
|
715
|
+
// Round-trip the other Subscribe parameters so the publisher doesn't
|
|
716
|
+
// interpret SUBSCRIBE_UPDATE as a reset of ordered/maxAge/etc.
|
|
653
717
|
const update = new SubscribeUpdate({
|
|
654
718
|
priority: current.priority ?? 0,
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
endGroup: current.endGroup,
|
|
719
|
+
maxAge: current.maxAge,
|
|
720
|
+
startGroup: current.groups?.start === undefined ? undefined : bounds.start,
|
|
721
|
+
endGroup: inclusiveGroupEnd(bounds.end),
|
|
659
722
|
});
|
|
660
723
|
await update.encode(stream.writer, this.version);
|
|
661
724
|
lastSent = { ...current };
|
|
@@ -663,11 +726,12 @@ export class Subscriber {
|
|
|
663
726
|
}
|
|
664
727
|
}
|
|
665
728
|
#sameSubscription(a, b) {
|
|
729
|
+
const ag = groupBounds(a.groups);
|
|
730
|
+
const bg = groupBounds(b.groups);
|
|
666
731
|
return ((a.priority ?? 0) === (b.priority ?? 0) &&
|
|
667
|
-
(a.
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
a.endGroup === b.endGroup);
|
|
732
|
+
(a.maxAge ?? 0) === (b.maxAge ?? 0) &&
|
|
733
|
+
ag.start === bg.start &&
|
|
734
|
+
ag.end === bg.end);
|
|
671
735
|
}
|
|
672
736
|
/**
|
|
673
737
|
* Handles a group message.
|
|
@@ -695,7 +759,7 @@ export class Subscriber {
|
|
|
695
759
|
if (track.closed.peek() !== undefined) {
|
|
696
760
|
// Subscription ended before the scale resolved; nothing to decode.
|
|
697
761
|
producer.close();
|
|
698
|
-
stream.stop(new
|
|
762
|
+
stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" }));
|
|
699
763
|
return;
|
|
700
764
|
}
|
|
701
765
|
await Signal.race(timescale, track.closed);
|
|
@@ -724,7 +788,7 @@ export class Subscriber {
|
|
|
724
788
|
producer.writeFrame({ payload, timestamp });
|
|
725
789
|
}
|
|
726
790
|
producer.close();
|
|
727
|
-
stream.stop(new
|
|
791
|
+
stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" }));
|
|
728
792
|
}
|
|
729
793
|
catch (err) {
|
|
730
794
|
const e = error(err);
|
|
@@ -793,7 +857,7 @@ export class Subscriber {
|
|
|
793
857
|
if (!scale)
|
|
794
858
|
return;
|
|
795
859
|
const timestamp = new Time.Timestamp(dg.timestamp, Time.Timescale(scale));
|
|
796
|
-
entry.track.
|
|
860
|
+
entry.track.insertDatagram(dg.sequence, timestamp, dg.payload);
|
|
797
861
|
}
|
|
798
862
|
/**
|
|
799
863
|
* Opens a PROBE bidi stream to receive bandwidth estimates from the publisher.
|
|
@@ -870,7 +934,7 @@ export class Subscriber {
|
|
|
870
934
|
}
|
|
871
935
|
}
|
|
872
936
|
/**
|
|
873
|
-
* A broadcast consumed from a lite session. It resolves `track.Consumer.
|
|
937
|
+
* A broadcast consumed from a lite session. It resolves `track.Consumer.query()` and
|
|
874
938
|
* `.fetchGroup()` over the wire (lite-05+ TRACK / FETCH streams) by reaching into the
|
|
875
939
|
* {@link Subscriber} it was opened from, the way the Rust `BroadcastConsumer` holds its
|
|
876
940
|
* session. Live subscribes still flow through the inherited requested() queue.
|
|
@@ -880,6 +944,10 @@ class ConsumeBroadcast extends broadcast.Consumer {
|
|
|
880
944
|
#path;
|
|
881
945
|
constructor(subscriber, path, state) {
|
|
882
946
|
super(state);
|
|
947
|
+
overrideBroadcastWire(this, {
|
|
948
|
+
resolveTrackInfo: (name) => subscriber.resolveTrackInfo(path, name),
|
|
949
|
+
fetchGroup: (name, sequence, options) => subscriber.fetchGroup(path, name, sequence, options),
|
|
950
|
+
});
|
|
883
951
|
this.#subscriber = subscriber;
|
|
884
952
|
this.#path = path;
|
|
885
953
|
}
|
|
@@ -888,11 +956,5 @@ class ConsumeBroadcast extends broadcast.Consumer {
|
|
|
888
956
|
clone() {
|
|
889
957
|
return new ConsumeBroadcast(this.#subscriber, this.#path, this.shareState());
|
|
890
958
|
}
|
|
891
|
-
resolveTrackInfo(name) {
|
|
892
|
-
return this.#subscriber.resolveTrackInfo(this.#path, name);
|
|
893
|
-
}
|
|
894
|
-
fetchGroup(name, sequence, options) {
|
|
895
|
-
return this.#subscriber.fetchGroup(this.#path, name, sequence, options);
|
|
896
|
-
}
|
|
897
959
|
}
|
|
898
960
|
//# sourceMappingURL=subscriber.js.map
|