@moq/net 0.4.5 → 0.4.6

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/ietf/publisher.js CHANGED
@@ -1053,42 +1053,37 @@ export class Publisher {
1053
1053
  request.stream.abort(e);
1054
1054
  return "dropped";
1055
1055
  }
1056
- // The peer already closed out a refused request, and its STOP_SENDING can reject the
1057
- // wait on our FIN. That is the withdrawal finishing, not a reason to end the loop.
1056
+ // The peer may already have closed out a refused request. Ending it again is the
1057
+ // withdrawal finishing, not a reason to end the loop.
1058
1058
  if (answer !== "held")
1059
1059
  await this.#withdraw(path, requests).catch(() => undefined);
1060
1060
  return answer;
1061
1061
  }
1062
1062
  /**
1063
- * Close out a namespace's PUBLISH_NAMESPACE request with PUBLISH_NAMESPACE_DONE.
1063
+ * End a namespace's PUBLISH_NAMESPACE request: PUBLISH_NAMESPACE_DONE then FIN before
1064
+ * draft-17, a cancel in both directions after. Neither waits on the peer.
1064
1065
  */
1065
1066
  async #withdraw(path, requests) {
1066
1067
  const request = requests.get(path);
1067
1068
  if (!request)
1068
1069
  return;
1069
1070
  requests.delete(path);
1070
- // Draft-17+ removed PUBLISH_NAMESPACE_DONE: the close below is the whole
1071
- // withdrawal. Sending it anyway puts the type on the wire before the body throws,
1072
- // and a receiver reading 0x09 there has no choice but to treat it as a protocol
1073
- // violation.
1071
+ // Draft-17+ withdraws by cancelling the request in both directions; a FIN is only
1072
+ // allowed to end SUBSCRIBE_NAMESPACE and SUBSCRIBE_TRACKS.
1074
1073
  const version = this.#session.version;
1075
- if (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) {
1076
- try {
1077
- await request.stream.writer.u53(PublishNamespaceDone.id);
1078
- const done = new PublishNamespaceDone({ trackNamespace: request.path, requestId: request.requestId });
1079
- await done.encode(request.stream.writer, version);
1080
- }
1081
- catch {
1082
- // Stream might already be closed
1083
- }
1084
- request.stream.close();
1074
+ if (version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16) {
1075
+ request.stream.abort(new StreamError(StreamCode.Cancel, { message: "withdrawn" }));
1085
1076
  return;
1086
1077
  }
1078
+ try {
1079
+ await request.stream.writer.u53(PublishNamespaceDone.id);
1080
+ const done = new PublishNamespaceDone({ trackNamespace: request.path, requestId: request.requestId });
1081
+ await done.encode(request.stream.writer, version);
1082
+ }
1083
+ catch {
1084
+ // Stream might already be closed
1085
+ }
1087
1086
  request.stream.close();
1088
- // Wait for transport acknowledgment before opening a replacement request.
1089
- // This assumes the peer processes the withdrawal by then; FIN acknowledgment
1090
- // does not itself acknowledge application processing across streams.
1091
- await request.stream.writer.closed;
1092
1087
  }
1093
1088
  /**
1094
1089
  * Handles an incoming TRACK_STATUS_REQUEST on a bidi stream.
@@ -1 +1 @@
1
- {"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/ietf/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGrF,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAwC,MAAM,EAAE,MAAM,YAAY,CAAC;AAE1E,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAoB,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5E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K;IAC/B;QACC,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACrC,CAAC;CACD","sourcesContent":["import { type Dispose, type Getter, race, Signal } from \"@moq/signals\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport { controlTimeout, error, reason, StreamCode, StreamError } from \"../error.ts\";\nimport type * as group from \"../group.ts\";\nimport type { Hop, Route } from \"../hop.ts\";\nimport { hiddenBelow, hooks, presented } from \"../internal.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Stream, Writer } from \"../stream.ts\";\nimport { Milli, Timescale } from \"../time.ts\";\nimport type { Subscriber as TrackSubscriber } from \"../track.ts\";\nimport { TimeoutError, withTimeout } from \"../util/timeout.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { type Advertised, type Advertisements, wireOf } from \"../wire.ts\";\nimport type { Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { type RequestKind, requestReason, toRequestCode } from \"./error.ts\";\nimport { type Fetch, FetchError, FetchHeader } from \"./fetch.ts\";\nimport * as Filter from \"./filter.ts\";\nimport * as Message from \"./message.ts\";\nimport { FetchFrame, Frame, Group as GroupMessage } from \"./object.ts\";\nimport { Parameters } from \"./parameters.ts\";\nimport { fromWire, toWire } from \"./priority.ts\";\nimport * as Properties from \"./properties.ts\";\nimport { PublishDone, PublishDoneStatus } from \"./publish.ts\";\nimport {\n\tPublishNamespace,\n\tPublishNamespaceDone,\n\tPublishNamespaceOk,\n\tPublishNamespaceUpdate,\n} from \"./publish_namespace.ts\";\nimport { RequestError, RequestOk } from \"./request.ts\";\nimport { cancelled, finCancels } from \"./request_stream.ts\";\nimport { type Subscribe, SubscribeError, SubscribeOk } from \"./subscribe.ts\";\nimport {\n\ttype SubscribeNamespace,\n\tSubscribeNamespaceEntry,\n\tSubscribeNamespaceEntryDone,\n\tSubscribeNamespaceOk,\n} from \"./subscribe_namespace.ts\";\nimport type { TrackStatusRequest } from \"./track.ts\";\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/** First wait before re-offering a namespace the peer refused or we couldn't open for. */\nconst RETRY_BASE = 100;\n\n/** Ceiling on that wait. The loop retries for the life of the session, so it must not spin. */\nconst RETRY_MAX = 5000;\n\n/** Cluster parameters for one snapshot: the advertised hops, then our own id last. */\nfunction clusterFor(base: Cluster.Advert | undefined, route: Route): Cluster.Advert | undefined {\n\tif (!base) return undefined;\n\tconst self = base.hops.at(-1);\n\tif (self === undefined) return undefined;\n\tconst hops = route.hops.at(-1) === self ? [...route.hops] : [...route.hops, self];\n\treturn { hops, cost: route.cost.warm };\n}\n\n/**\n * What it takes to move the peer from `held` to `next`.\n *\n * - `\"same\"`: the peer would decode the same advertisement. The cold cost, and the whole\n * route without Cluster, never reach the wire, so a change there sends nothing.\n * - `\"restart\"`: nothing is held, nothing is wanted, or a different broadcast, which is\n * withdrawn and advertised again.\n * - Otherwise the same broadcast at a new hop chain or warm cost: the cluster parameters\n * the peer holds and the ones it should, for the target to update.\n */\nfunction change(\n\tbase: Cluster.Advert | undefined,\n\theld: Advertised | undefined,\n\tnext: Advertised | undefined,\n): \"same\" | \"restart\" | Reprice {\n\tif (held === undefined || next === undefined || held.identity !== next.identity) return \"restart\";\n\tconst from = clusterFor(base, held.route);\n\tconst to = clusterFor(base, next.route);\n\tif (from === undefined || to === undefined) return from === to ? \"same\" : \"restart\";\n\tif (from.cost === to.cost && sameHops(from.hops, to.hops)) return \"same\";\n\treturn { from, to };\n}\n\n/** A held advertisement's cluster parameters, and the ones the peer should hold instead. */\ninterface Reprice {\n\tfrom: Cluster.Advert;\n\tto: Cluster.Advert;\n}\n\n/** Whether two hop paths list the same hops in the same order. */\nfunction sameHops(a: Hop[], b: Hop[]): boolean {\n\treturn a.length === b.length && a.every((hop, i) => hop === b[i]);\n}\n\n/**\n * How long one advertisement may take to be answered. Matches the Rust publisher, and the\n * peer accepting the stream is only half the exchange: one it never answers on holds the\n * loop just as effectively as one it never grants.\n */\nconst ADVERTISE_TIMEOUT_MS = 5000;\n\n/** Sleep `delay`, jittered, so a relay's namespaces don't all retry on the same tick. */\nfunction retryAfter(delay: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, delay * (0.5 + Math.random() / 2)));\n}\n\n/**\n * What a refusal said about re-offering the namespace.\n *\n * A peer answers a request it declines with a retry interval, and ignoring it is how a\n * permanent refusal (unauthorized, uninterested) turns into a request every few seconds\n * for the life of the session. `\"never\"` is an interval of 0; a number is the epoch\n * milliseconds before which we must not come back.\n */\ntype Refused = \"never\" | number;\n\n/**\n * How the peer answered an advertisement or an update: it holds the namespace, it does\n * not and said nothing about coming back (`\"dropped\"`), or it refused.\n */\ntype Answer = \"held\" | \"dropped\" | Refused;\n\n/** The open PUBLISH_NAMESPACE request per advertised path. */\ntype Requests = Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>;\n\n/** What one announce loop knows about the peer, keyed the way that loop names namespaces. */\ninterface Namespaces {\n\t/** What the peer holds, by identity plus route. */\n\tactive: Map<Path.Valid, Advertised>;\n\n\t/** What the peer refused, and whether coming back is worth anything. */\n\trefused: Map<Path.Valid, Refused>;\n\n\t/** The identity each refusal was about, so a republish at the same path clears it. */\n\toffered: Map<Path.Valid, object>;\n}\n\n/** Where one announce loop sends its advertisements. */\ninterface Target {\n\t/** Advertise a namespace the peer does not hold. */\n\tadvertise(key: Path.Valid, next: Advertised): Promise<Answer>;\n\n\t/** Reprice a namespace the peer holds: the same broadcast at a new hop chain or cost. */\n\tupdate(key: Path.Valid, next: Advertised, reprice: Reprice): Promise<Answer>;\n\n\t/** Withdraw a namespace the peer holds. */\n\twithdraw(key: Path.Valid): Promise<void>;\n}\n\n/** What {@link Publisher.runGroup} needs to serve one group. */\ninterface RunGroup {\n\t/** The subscription's request ID, doubling as the track alias. */\n\trequestId: bigint;\n\n\t/** The group to serve. */\n\tgroup: group.Consumer;\n\n\t/** The track's advertised timescale, applied to every frame timestamp. */\n\ttimescale: Timescale;\n\n\t/** The publisher's tie-break priority, already converted to the IETF wire convention. */\n\tpublisherPriority: number;\n\n\t/**\n\t * Whether objects carry their presentation timestamp.\n\t *\n\t * False once the subscriber sends INCLUDE_PROPERTIES=0: that drops TIMESCALE from\n\t * SUBSCRIBE_OK, and a timestamp whose units were never declared is worse than none. Our\n\t * own reader discards it; another may read it as some default and time the media wrong.\n\t */\n\tstamped: boolean;\n\n\t/** The objects of this group the subscription's filter selects. */\n\tslice: GroupSlice;\n\n\t/** Settles when the subscriber leaves, dropping a group still queued for a stream slot. */\n\tunsubscribed: Promise<void>;\n\n\t/** The subscription's data stream count, which PUBLISH_DONE reports. */\n\tstreams: StreamCount;\n}\n\n/** How many data streams a subscription opened, fill streams included. */\ntype StreamCount = { opened: number };\n\n/** What {@link Publisher.runFill} needs to serve one subscription's backfill. */\ninterface RunFill {\n\t/** The subscription's request ID, which the fetch stream names. */\n\trequestId: bigint;\n\n\t/**\n\t * The subscriber's delivery priority, applied to the cache subscription the fill reads.\n\t *\n\t * Deliberately not the fetch stream's send order: this publisher leaves its group\n\t * streams at the transport's default, so ranking the fill alone would put backfill\n\t * ahead of the live groups it is catching up to.\n\t */\n\tpriority: number;\n\n\t/** The range the fill resolved to. */\n\tfill: FillServe;\n\n\t/**\n\t * An independent view of the same track, used to read the cached group without consuming\n\t * anything the subscription will deliver.\n\t */\n\tcache: TrackSubscriber;\n\n\t/** The track's advertised timescale, applied to every frame timestamp. */\n\ttimescale: Timescale;\n\n\t/** Whether objects carry their presentation timestamp; see {@link RunGroup.stamped}. */\n\tstamped: boolean;\n\n\t/** Settles when the subscriber leaves, releasing a fill still waiting on its group. */\n\tunsubscribed: Promise<void>;\n\n\t/** The subscription's data stream count, which PUBLISH_DONE reports. */\n\tstreams: StreamCount;\n}\n\n/**\n * Handles publishing broadcasts using moq-transport protocol.\n * Uses the stream-per-request pattern (real bidi streams for v17, virtual for v14-v16).\n *\n * @internal\n */\nexport class Publisher {\n\t#quic: WebTransport;\n\t#session: Session;\n\t#requiresSolicitation: boolean;\n\t#hidden: boolean;\n\n\t// The origin this session serves, borrowed: it outlives the session, and closing the\n\t// session leaves its broadcasts alone. The namespaces are advertised with an unsolicited\n\t// PUBLISH_NAMESPACE (see {@link runPublishNamespaces}), or on request if the peer asked\n\t// for that (see {@link runSubscribeNamespace}).\n\t#advertised: Getter<Advertisements | undefined>;\n\t#publish?: OriginConsumer;\n\n\t// What every advertisement carries on a session that negotiated the MoQ Cluster\n\t// extension: a hop path holding our own id, so the peer can tell that what it hears\n\t// back came from us. `undefined` when nothing negotiated it.\n\t#advert?: Cluster.Advert;\n\n\t/**\n\t * Creates a new Publisher instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\tquic,\n\t\tsession,\n\t\tpublish,\n\t\trequiresSolicitation,\n\t\thidden = false,\n\t\tcluster,\n\t}: {\n\t\t/** The WebTransport session, for uni streams. */\n\t\tquic: WebTransport;\n\t\t/** The session abstraction for bidi streams and request IDs. */\n\t\tsession: Session;\n\t\t/** The origin whose broadcasts this session serves; omit to publish nothing. */\n\t\tpublish?: OriginConsumer;\n\t\t/** Whether the peer's SETUP asked to be told on request (MoQ Solicit). */\n\t\trequiresSolicitation: boolean;\n\t\t/** Whether the peer declared MoQ Hidden. */\n\t\thidden?: boolean;\n\t\t/** The Hop IDs the SETUP exchange settled (MoQ Cluster). */\n\t\tcluster?: Cluster.Hops;\n\t}) {\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tconst origin = publish && wireOf(publish);\n\t\tthis.#advertised = origin?.advertised ?? new Signal(new Map());\n\t\tthis.#publish = publish;\n\t\tthis.#requiresSolicitation = requiresSolicitation;\n\t\tthis.#hidden = hidden;\n\t\tthis.#advert = Cluster.advertise(cluster);\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE request on a bidi stream.\n\t * Owns the full lifecycle: sends response, serves track data, waits for close.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribe(msg: Subscribe, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst name = msg.trackNamespace;\n\t\tlet broadcast: broadcast.Consumer | undefined;\n\t\tlet refusal: { errorCode: number; reasonPhrase: string } | undefined;\n\n\t\t// Legal requests we can't honor are refused one at a time. A subscription that\n\t\t// forwards nothing is only useful to a subscriber that later turns forwarding on,\n\t\t// and serving a Range Filter unfiltered would deliver objects it excluded.\n\t\tconst unsupported = !msg.forward\n\t\t\t? \"FORWARD=0 not supported\"\n\t\t\t: msg.rangeFilters\n\t\t\t\t? \"range filters not supported\"\n\t\t\t\t: undefined;\n\n\t\tif (unsupported) {\n\t\t\trefusal = { errorCode: toRequestCode(\"not_supported\", \"subscribe\", version), reasonPhrase: unsupported };\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tbroadcast =\n\t\t\t\t\tthis.#publish && (wireOf(this.#publish).local(name) ?? (await wireOf(this.#publish).demand(name)));\n\t\t\t\tif (!broadcast) {\n\t\t\t\t\trefusal = {\n\t\t\t\t\t\terrorCode: toRequestCode(\"does_not_exist\", \"subscribe\", version),\n\t\t\t\t\t\treasonPhrase: \"broadcast not found\",\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t} catch (err: unknown) {\n\t\t\t\tconst e = error(err);\n\t\t\t\tconst condition =\n\t\t\t\t\te instanceof StreamError && e.code === StreamCode.NotFound ? \"does_not_exist\" : \"internal\";\n\t\t\t\trefusal = { errorCode: toRequestCode(condition, \"subscribe\", version), reasonPhrase: reason(e) };\n\t\t\t}\n\t\t}\n\n\t\tif (refusal) {\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeError.id);\n\t\t\t\tconst err = new SubscribeError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode: refusal.errorCode,\n\t\t\t\t\treasonPhrase: refusal.reasonPhrase,\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\tconst err = new RequestError({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t\terrorCode: refusal.errorCode,\n\t\t\t\t\treasonPhrase: refusal.reasonPhrase,\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t}\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\t\tif (!broadcast) return;\n\n\t\tconst priority = fromWire(msg.subscriberPriority);\n\t\tconst track = wireOf(broadcast).subscribe(msg.trackName, {\n\t\t\tpriority,\n\t\t\t// moq-transport has no subscriber latency parameter. Keep everything the\n\t\t\t// producer retained and let the receiving subscriber enforce its own budget.\n\t\t\t// Keep the sentinel encodable if this demand crosses a Lite hop before the\n\t\t\t// producer's retention bound is known.\n\t\t\tmaxAge: Milli(Varint.MAX_U53),\n\t\t});\n\n\t\tlet cache: TrackSubscriber | undefined;\n\n\t\ttry {\n\t\t\t// Declaring the timescale is what opts the track into timestamps; every object\n\t\t\t// Timestamp below is in these units.\n\t\t\tconst info = await track.info();\n\t\t\tconst timescale = info.timescale;\n\t\t\t// The model ranks higher-first, the IETF wire lower-first. Every group this\n\t\t\t// subscription serves carries the same publisher priority, which is what lets a\n\t\t\t// relay prefer catalog and audio over video when it has no subscriber preference\n\t\t\t// to go on.\n\t\t\tconst publisherPriority = toWire(info.priority);\n\n\t\t\t// The filter and any fill are relative to the live edge, so snapshot it once: the\n\t\t\t// fill ends exactly where a Next Object subscription begins, which is what lets\n\t\t\t// the draft's current-group join (Next Object plus a StartGroup=1 fill) cover the\n\t\t\t// group with no gap and no overlap.\n\t\t\tconst edge = liveEdge(track);\n\t\t\tconst range = subscribeRange(msg, edge, version);\n\n\t\t\t// The wire request tells an upstream what we need; the cursor is what actually\n\t\t\t// trims this subscriber, since the producer fans every cached group out to every\n\t\t\t// sink regardless. An absent start joins at the latest group, which is what\n\t\t\t// moq-lite means by joining a live track. The range's end is the inclusive last\n\t\t\t// group; the model's `endGroup` is exclusive.\n\t\t\ttrack.update({\n\t\t\t\tpriority,\n\t\t\t\tmaxAge: Milli(Varint.MAX_U53),\n\t\t\t\tgroups: {\n\t\t\t\t\tstart: range.start ? { included: Number(range.start.group) } : undefined,\n\t\t\t\t\tend: range.end ? { included: Number(range.end.group) } : undefined,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst startGroup = range.start ? Number(range.start.group) : track.latest();\n\t\t\tif (startGroup !== undefined) track.setGroups({ start: { included: startGroup } });\n\n\t\t\t// A fill reads the group cache through its own consumer, independent of the\n\t\t\t// subscription's cursor. Forked from this subscriber rather than resolved through\n\t\t\t// the broadcast again: a dynamic serve is one request per peer subscription, so\n\t\t\t// asking the broadcast would mint a second producer nobody has accepted.\n\t\t\tconst fill =\n\t\t\t\tmsg.fill && Filter.isDraft20(version) ? fillRange(msg.fill, msg.filter, edge.largest) : undefined;\n\t\t\tcache = fill && fill.kind !== \"empty\" ? track.fork({ priority, maxAge: Milli(Varint.MAX_U53) }) : undefined;\n\n\t\t\t// Send SUBSCRIBE_OK\n\t\t\tawait stream.writer.u53(SubscribeOk.id);\n\t\t\tconst ok = new SubscribeOk({\n\t\t\t\trequestId:\n\t\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t\t? msg.requestId\n\t\t\t\t\t\t: undefined,\n\t\t\t\ttrackAlias: msg.requestId,\n\t\t\t\t// Required once the track has content; a fill-requesting subscriber sizes its\n\t\t\t\t// backfill against this. Below draft-20 round it down to the start of its\n\t\t\t\t// group, matching what the subscription serves there: a draft-20 subscriber\n\t\t\t\t// recovers a group's head with a FILL, which we serve, while older drafts\n\t\t\t\t// recover it with a joining FETCH, which we do not, so naming a mid-group\n\t\t\t\t// start would strand them.\n\t\t\t\tlargest:\n\t\t\t\t\tedge.largest &&\n\t\t\t\t\t(Filter.isDraft20(version)\n\t\t\t\t\t\t? { groupId: edge.largest.group, objectId: edge.largest.object }\n\t\t\t\t\t\t: { groupId: edge.largest.group, objectId: 0n }),\n\t\t\t\tproperties: msg.propertiesWanted\n\t\t\t\t\t? // Declaring the timescale is what opts the track into timestamps; every\n\t\t\t\t\t\t// object Timestamp below is in these units. We serve the newest group\n\t\t\t\t\t\t// first, matching moq-lite.\n\t\t\t\t\t\t{ timescale, priority: publisherPriority, groupOrder: Properties.DESCENDING }\n\t\t\t\t\t: // INCLUDE_PROPERTIES=0. The block stays present but empty, which also means\n\t\t\t\t\t\t// the track opts out of timestamps for this subscriber.\n\t\t\t\t\t\t{},\n\t\t\t});\n\t\t\tawait ok.encode(stream.writer, version);\n\t\t\tconsole.debug(`publish ok: broadcast=${name} track=${track.name}`);\n\n\t\t\t// Cancels groups still queued for a stream slot. Only the subscriber leaving counts:\n\t\t\t// a track that ran out of groups still has to flush the ones already queued, and we\n\t\t\t// close the stream ourselves below to say so.\n\t\t\tlet finished = false;\n\t\t\tlet unsubscribe!: () => void;\n\t\t\tconst unsubscribed = new Promise<void>((resolve) => {\n\t\t\t\tunsubscribe = resolve;\n\t\t\t});\n\n\t\t\t// Update replies and PUBLISH_DONE come from separate tasks but share this stream, and a\n\t\t\t// message is written in several pieces. Chain them so each goes out whole, in order,\n\t\t\t// and nothing follows PUBLISH_DONE.\n\t\t\tlet replies: Promise<void> = Promise.resolve();\n\t\t\tlet replied = false;\n\t\t\tconst reply = (write: () => Promise<void>): Promise<void> => {\n\t\t\t\tconst sent = replies.then(() => (replied ? undefined : write()));\n\t\t\t\treplies = sent.catch(() => undefined);\n\t\t\t\treturn sent;\n\t\t\t};\n\t\t\tlet publishError: Error | undefined;\n\n\t\t\tconst updates = (async () => {\n\t\t\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16)\n\t\t\t\t\treturn stream.reader.closed;\n\t\t\t\tfor (;;) {\n\t\t\t\t\tif (await stream.reader.done()) {\n\t\t\t\t\t\tif (finCancels(version)) return;\n\t\t\t\t\t\treturn stream.writer.closed;\n\t\t\t\t\t}\n\t\t\t\t\tif ((await stream.reader.u53()) !== 0x02) throw new Error(\"unexpected message on subscribe stream\");\n\t\t\t\t\tconst params = await Message.decode(stream.reader, async (r) => {\n\t\t\t\t\t\tawait r.u62();\n\t\t\t\t\t\tif (version === Version.DRAFT_17) await r.u62();\n\t\t\t\t\t\treturn Parameters.decode(r, version);\n\t\t\t\t\t});\n\t\t\t\t\tconst unsupported =\n\t\t\t\t\t\tparams.forward === false ||\n\t\t\t\t\t\tparams.bytes.size > 0 ||\n\t\t\t\t\t\tparams.subscriptionFilter !== undefined ||\n\t\t\t\t\t\tparams.largest !== undefined ||\n\t\t\t\t\t\tparams.rangeFilters ||\n\t\t\t\t\t\tparams.trackPropertyFilter ||\n\t\t\t\t\t\tparams.authorizationToken ||\n\t\t\t\t\t\t[...params.vars.keys()].some((key) => key !== 0x10n && key !== 0x20n);\n\t\t\t\t\tif (unsupported) {\n\t\t\t\t\t\t// Recorded before the reply, so a PUBLISH_DONE queued behind it reports the failure.\n\t\t\t\t\t\tconst failed = new UpdateFailed();\n\t\t\t\t\t\tpublishError = failed;\n\t\t\t\t\t\tawait reply(async () => {\n\t\t\t\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\t\t\t\tawait new RequestError({\n\t\t\t\t\t\t\t\trequestId: undefined,\n\t\t\t\t\t\t\t\terrorCode: toRequestCode(\"not_supported\", \"subscribe\", version),\n\t\t\t\t\t\t\t\treasonPhrase: \"REQUEST_UPDATE parameters not supported\",\n\t\t\t\t\t\t\t}).encode(stream.writer, version);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthrow failed;\n\t\t\t\t\t}\n\t\t\t\t\t// update() replaces every option, so carry the rest over as Rust does.\n\t\t\t\t\tif (params.subscriberPriority !== undefined)\n\t\t\t\t\t\ttrack.update({ ...track.subscription.peek(), priority: fromWire(params.subscriberPriority) });\n\t\t\t\t\tawait reply(async () => {\n\t\t\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\t\t\tawait new RequestOk({ requestId: undefined }).encode(stream.writer, version);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t\tconst requestEnded =\n\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t? updates\n\t\t\t\t\t: race([updates, stream.writer.closed]);\n\t\t\tvoid requestEnded.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (!finished) unsubscribe();\n\t\t\t\t},\n\t\t\t\t// Updates can fail after the serving loop ends while its last groups drain.\n\t\t\t\t(err: unknown) => {\n\t\t\t\t\tpublishError = error(err);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t},\n\t\t\t);\n\n\t\t\t// Every group started, until its stream finishes or resets, and the data streams\n\t\t\t// opened for PUBLISH_DONE to report.\n\t\t\tconst groups = new Set<Promise<void>>();\n\t\t\tconst streams: StreamCount = { opened: 0 };\n\n\t\t\t// Serve groups until the track ends or the requester cancels.\n\t\t\tconst serving = (async () => {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst group = await track.recvGroup();\n\t\t\t\t\tif (!group) return;\n\n\t\t\t\t\t// Past the filter's end. Dropped here rather than through `setGroups`, which\n\t\t\t\t\t// parks a capped group instead: this range is fixed for the life of the\n\t\t\t\t\t// subscription, so a group above it is never coming back in, and holding\n\t\t\t\t\t// one keeps the loop from ever ending. A producer that publishes beyond\n\t\t\t\t\t// the end and then closes would otherwise strand PUBLISH_DONE.\n\t\t\t\t\tif (range.end !== undefined && BigInt(group.sequence) > range.end.group) {\n\t\t\t\t\t\tgroup.close();\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst task = this.#runGroup({\n\t\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\t\tgroup,\n\t\t\t\t\t\ttimescale,\n\t\t\t\t\t\tpublisherPriority,\n\t\t\t\t\t\tstamped: msg.propertiesWanted,\n\t\t\t\t\t\tslice: groupSlice(range, group.sequence),\n\t\t\t\t\t\tunsubscribed,\n\t\t\t\t\t\tstreams,\n\t\t\t\t\t});\n\t\t\t\t\tgroups.add(task);\n\t\t\t\t\tvoid task.finally(() => groups.delete(task));\n\t\t\t\t}\n\t\t\t})();\n\n\t\t\t// The fill (when one was requested) runs alongside on its own fetch stream; its\n\t\t\t// failures reset that stream and never touch the subscription.\n\t\t\tconst filling =\n\t\t\t\tfill && cache\n\t\t\t\t\t? this.#runFill({\n\t\t\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\t\t\tpriority,\n\t\t\t\t\t\t\tfill,\n\t\t\t\t\t\t\tcache,\n\t\t\t\t\t\t\ttimescale,\n\t\t\t\t\t\t\tstamped: msg.propertiesWanted,\n\t\t\t\t\t\t\tunsubscribed,\n\t\t\t\t\t\t\tstreams,\n\t\t\t\t\t\t})\n\t\t\t\t\t: Promise.resolve();\n\n\t\t\tlet ended = false;\n\t\t\ttry {\n\t\t\t\tconst served = Symbol(\"served\");\n\t\t\t\tended = (await race([Promise.all([serving, filling]).then(() => served), requestEnded])) === served;\n\t\t\t} catch (err: unknown) {\n\t\t\t\tpublishError = error(err);\n\t\t\t}\n\n\t\t\t// PUBLISH_DONE waits until every stream this subscription will open is closed, as\n\t\t\t// the draft requires, so its count is final. The subscriber leaving cancels the\n\t\t\t// ones still queued instead.\n\t\t\tawait race([Promise.all(groups), unsubscribed]);\n\t\t\t// An error of our own (a refused or malformed update, a failed track) ends the\n\t\t\t// subscription while the requester may still listen, so its open streams reset\n\t\t\t// rather than finish as if complete, and PUBLISH_DONE still follows them. A stream\n\t\t\t// error is the requester cancelling, which the shortcut above already covers.\n\t\t\tif (publishError && !(publishError instanceof StreamError)) {\n\t\t\t\ttrack.close(publishError);\n\t\t\t\tawait Promise.all([...groups, filling]);\n\t\t\t}\n\n\t\t\t// Draft 14 on has no end location in PUBLISH_DONE: an END_OF_TRACK object is what\n\t\t\t// tells the subscriber where the track ended.\n\t\t\tconst final = track.final();\n\t\t\tif (ended && !publishError && final !== undefined) {\n\t\t\t\tawait this.#runEndOfTrack({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\tfinal,\n\t\t\t\t\tpublisherPriority,\n\t\t\t\t\tunsubscribed,\n\t\t\t\t\tstreams,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconsole.debug(`publish done: broadcast=${name} track=${track.name}`);\n\t\t\tif (publishError) {\n\t\t\t\tconsole.warn(`publish error: broadcast=${name} track=${track.name} error=${reason(publishError)}`);\n\t\t\t}\n\n\t\t\t// PUBLISH_DONE is required for every supported draft. The peer may have already\n\t\t\t// closed its side to unsubscribe, in which case there is nowhere to send it.\n\t\t\ttry {\n\t\t\t\tawait reply(async () => {\n\t\t\t\t\treplied = true;\n\t\t\t\t\tawait stream.writer.u53(PublishDone.id);\n\t\t\t\t\tconst done = new PublishDone({\n\t\t\t\t\t\trequestId:\n\t\t\t\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t\t\t\t? msg.requestId\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tstatusCode:\n\t\t\t\t\t\t\tpublishError instanceof UpdateFailed\n\t\t\t\t\t\t\t\t? PublishDoneStatus.UPDATE_FAILED\n\t\t\t\t\t\t\t\t: publishError\n\t\t\t\t\t\t\t\t\t? PublishDoneStatus.INTERNAL_ERROR\n\t\t\t\t\t\t\t\t\t: PublishDoneStatus.TRACK_ENDED,\n\t\t\t\t\t\tstreamCount: BigInt(streams.opened),\n\t\t\t\t\t\treasonPhrase:\n\t\t\t\t\t\t\tpublishError instanceof UpdateFailed\n\t\t\t\t\t\t\t\t? \"update failed\"\n\t\t\t\t\t\t\t\t: publishError\n\t\t\t\t\t\t\t\t\t? \"internal error\"\n\t\t\t\t\t\t\t\t\t: \"track ended\",\n\t\t\t\t\t});\n\t\t\t\t\tawait done.encode(stream.writer, version);\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\t// Stream might already be closed by peer.\n\t\t\t}\n\n\t\t\t// Our close follows PUBLISH_DONE; it must not cancel data still queued for delivery.\n\t\t\tfinished = true;\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${name} track=${track.name} error=${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\ttrack.close();\n\t\t\t// Idempotent, and the backstop for a throw between the fork and the fill starting:\n\t\t\t// #runFill closes it itself on every path it reaches.\n\t\t\tcache?.close();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a group and sends its frames using ObjectStream (Subgroup delivery mode).\n\t */\n\tasync #runGroup(options: RunGroup) {\n\t\tconst { requestId, group, timescale, publisherPriority, stamped, slice, unsubscribed, streams } = options;\n\t\ttry {\n\t\t\t// One stream per group is faster than a peer at its limit can retire them, so this\n\t\t\t// is the one path that doesn't wait for a slot: the transport would serve the opens\n\t\t\t// in the order we asked, which is oldest-first, exactly backwards for live media.\n\t\t\t// Failing here drops the group and lets the next one compete for the next slot.\n\t\t\tconst stream = await Writer.tryOpen(this.#quic, {\n\t\t\t\tcancel: unsubscribed,\n\t\t\t\tversion: this.#session.version,\n\t\t\t\twaitUntilAvailable: false,\n\t\t\t});\n\t\t\tif (!stream) {\n\t\t\t\tgroup.close(new Error(\"no stream slot\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstreams.opened += 1;\n\n\t\t\tconst header = new GroupMessage({\n\t\t\t\ttrackAlias: requestId,\n\t\t\t\tgroupId: group.sequence,\n\t\t\t\tsubGroupId: 0,\n\t\t\t\tpublisherPriority,\n\t\t\t\tflags: {\n\t\t\t\t\t// The object properties carry the timestamp, so there is nothing to write\n\t\t\t\t\t// when the track declared no units to read one in.\n\t\t\t\t\thasExtensions: stamped,\n\t\t\t\t\thasSubgroup: false,\n\t\t\t\t\thasSubgroupObject: false,\n\t\t\t\t\t// A stream capped by the range stops before the group may end, so its FIN\n\t\t\t\t\t// cannot claim END_OF_GROUP.\n\t\t\t\t\thasEnd: slice.until === undefined,\n\t\t\t\t\thasPriority: true,\n\t\t\t\t\t// Only honest when the stream really starts at the group's first object;\n\t\t\t\t\t// a trimmed head starts partway through.\n\t\t\t\t\tfirstObject: slice.skip === 0,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tawait hooks.guardGroup(group, () => header.encode(stream, this.#session.version));\n\t\t\t\t// The first written object goes on the wire as its absolute id, so a trimmed\n\t\t\t\t// head shows the true numbering rather than a silently renumbered group.\n\t\t\t\tlet first = true;\n\t\t\t\t// The next object id that could be written, which starts at the filter rather\n\t\t\t\t// than at zero. A backwards range (`startObject` above `endObject` in the same\n\t\t\t\t// group) is empty, and starting here is what lets the check below see that\n\t\t\t\t// before the read parks on an object the range already excludes.\n\t\t\t\tlet next = slice.skip;\n\n\t\t\t\tfor (;;) {\n\t\t\t\t\t// The filter ends inside this group: everything at `until` and beyond is\n\t\t\t\t\t// outside the requested range, so stop without waiting for the group's end.\n\t\t\t\t\tif (slice.until !== undefined && next >= slice.until) break;\n\n\t\t\t\t\t// Reading from the filter's start drops the objects below it: they are outside\n\t\t\t\t\t// the requested range, so skipping them is not a gap.\n\t\t\t\t\tconst read = await race([hooks.readGroupFrame(group, slice.skip), stream.closed]);\n\t\t\t\t\tif (!read) break;\n\t\t\t\t\tnext = read.sequence + 1;\n\t\t\t\t\tif (slice.until !== undefined && read.sequence >= slice.until) {\n\t\t\t\t\t\tread.complete();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst obj = new Frame({ payload: read.frame.payload, timestamp: read.frame.timestamp });\n\t\t\t\t\t\tconst delta = first ? read.sequence : 0;\n\t\t\t\t\t\tfirst = false;\n\t\t\t\t\t\tawait hooks.guardGroup(group, () =>\n\t\t\t\t\t\t\tobj.encode(stream, header.flags, timescale, this.#session.version, delta),\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tread.complete();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstream.close();\n\t\t\t} catch (err: unknown) {\n\t\t\t\tstream.reset(error(err));\n\t\t\t}\n\t\t} finally {\n\t\t\tgroup.close();\n\t\t}\n\t}\n\n\t/**\n\t * Mark the track's end with an END_OF_TRACK object on its own stream, at object 0 of the\n\t * group that will never exist.\n\t *\n\t * The last group's stream has usually finished before the track ends, so the marker cannot\n\t * ride on it. A failure only costs the subscriber the early boundary.\n\t */\n\tasync #runEndOfTrack(options: {\n\t\trequestId: bigint;\n\t\tfinal: number;\n\t\tpublisherPriority: number;\n\t\tunsubscribed: Promise<void>;\n\t\tstreams: StreamCount;\n\t}) {\n\t\tconst { requestId, final, publisherPriority, unsubscribed, streams } = options;\n\t\tconst version = this.#session.version;\n\t\tconst stream = await Writer.tryOpen(this.#quic, { cancel: unsubscribed, version }).catch(() => undefined);\n\t\tif (!stream) return;\n\t\tstreams.opened += 1;\n\n\t\ttry {\n\t\t\tconst header = new GroupMessage({\n\t\t\t\ttrackAlias: requestId,\n\t\t\t\tgroupId: final,\n\t\t\t\tsubGroupId: 0,\n\t\t\t\tpublisherPriority,\n\t\t\t\tflags: {\n\t\t\t\t\thasExtensions: false,\n\t\t\t\t\thasSubgroup: false,\n\t\t\t\t\thasSubgroupObject: false,\n\t\t\t\t\thasEnd: false,\n\t\t\t\t\thasPriority: true,\n\t\t\t\t\tfirstObject: true,\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait header.encode(stream, version);\n\t\t\tawait new Frame({ endOfTrack: true }).encode(stream, header.flags, Timescale.MILLI, version);\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tstream.reset(error(err));\n\t\t}\n\t}\n\n\t/**\n\t * Serve a draft-20 fill on its own fetch stream: the requested range, read from the\n\t * group cache, capped at the Largest Object snapshot.\n\t *\n\t * A fill is a promise once requested. An empty range opens no stream, but a range we\n\t * cannot serve still opens one and resets it right after the FETCH_HEADER, the draft's\n\t * fill-failure signal. Nothing here touches the subscription either way.\n\t */\n\tasync #runFill(options: RunFill) {\n\t\tconst { requestId, fill, cache, timescale, stamped, unsubscribed, streams } = options;\n\t\tconst version = this.#session.version;\n\n\t\t// Everything is inside the try so the cache fork is released on every path out,\n\t\t// including a transport failure while opening the stream.\n\t\tlet stream: Writer | undefined;\n\t\ttry {\n\t\t\tif (fill.kind === \"empty\") return;\n\n\t\t\tstream = await Writer.tryOpen(this.#quic, { cancel: unsubscribed, version });\n\t\t\tif (!stream) {\n\t\t\t\tconsole.debug(`fill stream failed to open: fill=${requestId}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstreams.opened += 1;\n\n\t\t\tawait stream.u53(FetchHeader.type);\n\t\t\tawait new FetchHeader({ requestId }).encode(stream, version);\n\n\t\t\tif (fill.kind !== \"group\") {\n\t\t\t\tthrow new Error(\"a fill spanning several groups is not supported\");\n\t\t\t}\n\n\t\t\tconst group = takeGroup(cache, Number(fill.sequence));\n\t\t\ttry {\n\t\t\t\tawait this.#writeFillGroup(stream, group, fill, timescale, stamped, unsubscribed);\n\t\t\t} finally {\n\t\t\t\tgroup.close();\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t\tconsole.debug(`fill complete: fill=${requestId}`);\n\t\t} catch (err: unknown) {\n\t\t\t// A fill never fails the subscription; its own stream carries the failure.\n\t\t\tconst e = error(err);\n\t\t\tconsole.debug(`fill failed, resetting its stream: fill=${requestId} error=${reason(e)}`);\n\t\t\tstream?.reset(e);\n\t\t} finally {\n\t\t\tcache.close();\n\t\t}\n\t}\n\n\t/**\n\t * Write one cached group's frames as draft-20 fetch objects.\n\t *\n\t * The cap is the Largest Object snapshot: the group may keep growing, but everything\n\t * past the snapshot belongs to the subscription, not the fill.\n\t */\n\tasync #writeFillGroup(\n\t\tstream: Writer,\n\t\tgroup: group.Consumer,\n\t\tfill: FillGroup,\n\t\ttimescale: Timescale,\n\t\tstamped: boolean,\n\t\tunsubscribed: Promise<void>,\n\t) {\n\t\tlet first = true;\n\t\tlet next = 0n;\n\n\t\t// The subscriber leaving has to end the fill too. An absolute filter ending below the\n\t\t// edge with no end object leaves `until` unset, so this reads until the group closes,\n\t\t// which a still-open past group may never do. Watching only the fetch stream would\n\t\t// then pin the group and the cache subscription behind it for the life of the track.\n\t\tlet left = false;\n\t\tconst cancelled = unsubscribed.then(() => {\n\t\t\tleft = true;\n\t\t\treturn undefined;\n\t\t});\n\n\t\tfor (;;) {\n\t\t\t// The group may keep growing, but everything at `until` and beyond belongs to the\n\t\t\t// subscription, so stop without waiting for the group's end.\n\t\t\tif (fill.until !== undefined && next >= fill.until) break;\n\n\t\t\t// Reading from the fill's start drops everything below it; see the same read in #runGroup.\n\t\t\tconst frame = await race([group.readFrameSequence({ from: Number(fill.skip) }), stream.closed, cancelled]);\n\t\t\tif (left) throw new Error(\"unsubscribed before the fill finished\");\n\t\t\tif (!frame) break;\n\t\t\tnext = BigInt(frame.sequence) + 1n;\n\t\t\tif (fill.until !== undefined && BigInt(frame.sequence) >= fill.until) break;\n\n\t\t\tconst obj = new FetchFrame({ payload: frame.payload, timestamp: stamped ? frame.timestamp : undefined });\n\t\t\tawait obj.encode(\n\t\t\t\tstream,\n\t\t\t\t{ group: Number(fill.sequence), object: frame.sequence, first },\n\t\t\t\ttimescale,\n\t\t\t\tthis.#session.version,\n\t\t\t);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE_NAMESPACE on a bidi stream.\n\t *\n\t * Draft-16+ fills the stream with every visible match, independently of unsolicited\n\t * discovery. Draft-14/15 use PUBLISH_NAMESPACE requests instead and suppress matches\n\t * already announced on the unsolicited path. Hidden visibility applies to both.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribeNamespace(msg: SubscribeNamespace, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst prefix = msg.namespace;\n\t\tconst legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;\n\n\t\t// Draft-14/15: the open PUBLISH_NAMESPACE request per advertised suffix.\n\t\tconst requests: Requests = new Map();\n\n\t\tconst ending = cancelled(stream, version);\n\t\ttry {\n\t\t\t// Send OK response\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceOk.id);\n\t\t\t\tconst ok = new SubscribeNamespaceOk({ requestId: msg.requestId });\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tconst ok = new RequestOk({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t});\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t}\n\n\t\t\t// Only legacy requests create another route; inline entries always fill the query.\n\t\t\t// Hidden namespaces still require opt-in unless the prefix names them directly.\n\t\t\tconst carries = (covered: Path.Valid) =>\n\t\t\t\t(!this.#hidden || msg.hidden || !hiddenBelow(prefix, covered)) &&\n\t\t\t\t(!legacy || this.#requiresSolicitation || (this.#hidden && hiddenBelow(Path.empty(), covered)));\n\n\t\t\t// Inline entries always land, and the receiver treats a repeated NAMESPACE as a\n\t\t\t// replacement, so repricing one is just sending it again, a new original\n\t\t\t// publisher included, as Rust does. Only a legacy PUBLISH_NAMESPACE request can\n\t\t\t// be declined.\n\t\t\tconst namespace = async (suffix: Path.Valid, snap: Advertised): Promise<Answer> => {\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntry.id);\n\t\t\t\tconst cluster = clusterFor(this.#advert, snap.route);\n\t\t\t\tawait new SubscribeNamespaceEntry({ suffix, cluster }).encode(stream.writer, version);\n\t\t\t\treturn \"held\";\n\t\t\t};\n\t\t\tconst target: Target = legacy\n\t\t\t\t? {\n\t\t\t\t\t\tadvertise: (suffix, snap) =>\n\t\t\t\t\t\t\tthis.#advertise(Path.join(prefix, suffix), requests, clusterFor(this.#advert, snap.route)),\n\t\t\t\t\t\tupdate: (suffix, _snap, reprice) => this.#update(Path.join(prefix, suffix), requests, reprice),\n\t\t\t\t\t\twithdraw: (suffix) => this.#withdraw(Path.join(prefix, suffix), requests),\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tadvertise: namespace,\n\t\t\t\t\t\tupdate: namespace,\n\t\t\t\t\t\twithdraw: async (suffix) => {\n\t\t\t\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntryDone.id);\n\t\t\t\t\t\t\tawait new SubscribeNamespaceEntryDone({ suffix }).encode(stream.writer, version);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\n\t\t\t// Keyed by suffix, as the entries name them.\n\t\t\tconst ns: Namespaces = { active: new Map(), refused: new Map(), offered: new Map() };\n\t\t\tlet retry = 0;\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling, for the same reason as\n\t\t\t\t// {@link runPublishNamespaces}: a publish landing while an advertisement\n\t\t\t\t// waits for its reply only notifies listeners already registered.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tlet dispose!: Dispose;\n\t\t\t\tconst changed = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst advertised = this.#advertised.peek();\n\t\t\t\tif (!advertised) {\n\t\t\t\t\tdispose();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst outstanding = await this.#reconcile(ns, presented(prefix, advertised, carries), target);\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, or for the peer to unsubscribe.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? race([changed, ending, retryAfter(retry).then(() => advertised)])\n\t\t\t\t\t: race([changed, ending]));\n\t\t\t\tdispose();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.debug(`subscribe_namespace stream error: ${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\t// This subscription's advertisements die with it.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advertise every published broadcast with an unsolicited PUBLISH_NAMESPACE, until\n\t * the publisher is closed.\n\t *\n\t * The peers that never send SUBSCRIBE_NAMESPACE are exactly the ones expecting a\n\t * publisher to announce itself, so announcing is the default. A peer that would\n\t * rather ask says so in its SETUP (MoQ Solicit) and this does nothing, leaving\n\t * {@link runSubscribeNamespace} to carry the advertisements instead. Modern peers\n\t * may also discover the namespace through an inline subscription fill.\n\t *\n\t * @internal\n\t */\n\tasync runPublishNamespaces() {\n\t\tif (this.#requiresSolicitation) {\n\t\t\t// The peer asked to be told on request; runSubscribeNamespace answers it.\n\t\t\treturn;\n\t\t}\n\n\t\t// The open PUBLISH_NAMESPACE request per advertised path.\n\t\tconst requests: Requests = new Map();\n\t\tconst target: Target = {\n\t\t\tadvertise: (path, snap) => this.#advertise(path, requests, clusterFor(this.#advert, snap.route)),\n\t\t\tupdate: (path, _snap, reprice) => this.#update(path, requests, reprice),\n\t\t\twithdraw: (path) => this.#withdraw(path, requests),\n\t\t};\n\n\t\t// The origin outlives the session and its signal never ends, so this loop needs the\n\t\t// session's own ending to stop: without it a closed connection leaves the loop parked\n\t\t// on a shared origin forever, waking on someone else's publish to fail on a dead\n\t\t// transport. `runSubscribeNamespace` gets this from the stream the peer asked on; an\n\t\t// unsolicited loop has no stream of its own, so the session is what it watches.\n\t\tconst closed = this.#quic.closed.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\n\t\tlet dispose: Dispose | undefined;\n\t\ttry {\n\t\t\t// Keyed by path.\n\t\t\tconst ns: Namespaces = { active: new Map(), refused: new Map(), offered: new Map() };\n\t\t\tlet retry = 0;\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling. Each advertisement below waits a round trip\n\t\t\t\t// for the peer's reply, and a publish that lands in that window notifies\n\t\t\t\t// only the listeners already registered; one created afterwards would sleep\n\t\t\t\t// through it and leave the namespace unadvertised until something unrelated\n\t\t\t\t// changed.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tconst changed = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst advertised = this.#advertised.peek();\n\t\t\t\tif (!advertised) {\n\t\t\t\t\tdispose?.();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst updated = new Map<Path.Valid, Advertised>();\n\t\t\t\tfor (const [covered, candidates] of advertised) {\n\t\t\t\t\t// Only peers that declared MoQ Hidden filter unsolicited discovery.\n\t\t\t\t\tif ((this.#hidden && hiddenBelow(Path.empty(), covered)) || candidates.length === 0) continue;\n\t\t\t\t\tupdated.set(covered, candidates[0]);\n\t\t\t\t}\n\n\t\t\t\tconst outstanding = await this.#reconcile(ns, updated, target);\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, which has already fired if one landed above.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? race([changed, closed, retryAfter(retry).then(() => advertised)])\n\t\t\t\t\t: race([changed, closed]));\n\t\t\t\tdispose?.();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\t// Nothing restarts this loop, so whatever got us here cost the session its\n\t\t\t// discovery. Not a debug-level event.\n\t\t\tconsole.warn(`publish_namespace loop failed: ${reason(error(err))}`);\n\t\t} finally {\n\t\t\tdispose?.();\n\t\t\t// Close out every open PUBLISH_NAMESPACE request.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Bring the peer's view in line with `updated`, one namespace at a time, and report\n\t * whether anything it should hold is still missing and worth coming back for.\n\t *\n\t * Nothing the peer cannot see is sent, a reprice updates the namespace in place, and\n\t * anything else is withdrawn first so a republish reads as withdraw-then-advertise.\n\t * `ns` records what the peer holds rather than what we attempted: a declined\n\t * advertisement or update stays out of it, so the next turn offers it fresh instead\n\t * of believing it is already up.\n\t */\n\tasync #reconcile(ns: Namespaces, updated: Map<Path.Valid, Advertised>, target: Target): Promise<boolean> {\n\t\t// A namespace that is gone, or that a republish replaced, takes its refusal with\n\t\t// it: the peer refused a broadcast, not a path forever, so a different one at the\n\t\t// same path is offered again. The origin swaps the front in one mutation, so the\n\t\t// path never leaves `updated` and only the front says they differ. Rust gets this\n\t\t// by rebuilding the watched entry.\n\t\tfor (const key of [...ns.refused.keys()]) {\n\t\t\tconst snap = updated.get(key);\n\t\t\tif (snap === undefined || ns.offered.get(key) !== snap.identity) {\n\t\t\t\tns.refused.delete(key);\n\t\t\t\tns.offered.delete(key);\n\t\t\t}\n\t\t}\n\n\t\tconst held = new Map(ns.active);\n\t\tfor (const [key, snap] of ns.active) {\n\t\t\tif (change(this.#advert, snap, updated.get(key)) !== \"restart\") continue;\n\t\t\tawait target.withdraw(key);\n\t\t\theld.delete(key);\n\t\t}\n\n\t\tfor (const [key, snap] of updated) {\n\t\t\tconst prev = held.get(key);\n\t\t\tconst diff = change(this.#advert, prev, snap);\n\t\t\tif (diff === \"same\") continue;\n\n\t\t\tlet answer: Answer;\n\t\t\tif (prev !== undefined && diff !== \"restart\") {\n\t\t\t\tanswer = await target.update(key, snap, diff);\n\t\t\t} else {\n\t\t\t\t// A fresh offer waits for what a refusal asked for, whatever brought us back.\n\t\t\t\tif (!this.#offerable(key, ns.refused)) continue;\n\t\t\t\tanswer = await target.advertise(key, snap);\n\t\t\t}\n\t\t\t// `offered` pairs with `refused`, so a held or withdrawn path leaves nothing behind.\n\t\t\tif (answer === \"held\") {\n\t\t\t\theld.set(key, snap);\n\t\t\t\tns.refused.delete(key);\n\t\t\t\tns.offered.delete(key);\n\t\t\t} else {\n\t\t\t\theld.delete(key);\n\t\t\t\tif (answer !== \"dropped\") {\n\t\t\t\t\tns.refused.set(key, answer);\n\t\t\t\t\tns.offered.set(key, snap.identity);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tns.active = held;\n\n\t\t// Whatever we wanted up and could not get up. Stream credit freeing, a transient\n\t\t// failure clearing, or the peer starting to answer raises no signal of its own, so\n\t\t// the only way back is to ask again on a timer.\n\t\treturn [...updated].some(\n\t\t\t([key, snap]) => change(this.#advert, held.get(key), snap) !== \"same\" && this.#pending(key, ns.refused),\n\t\t);\n\t}\n\n\t/**\n\t * Whether a namespace may be offered to the peer right now.\n\t *\n\t * A peer that asked never to be offered it again means it, whatever brought us back;\n\t * one that named a minimum wait gets it, even when our own backoff comes round sooner.\n\t */\n\t#offerable(key: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\tconst entry = refused.get(key);\n\t\tif (entry === undefined) return true;\n\t\treturn entry !== \"never\" && Date.now() >= entry;\n\t}\n\n\t/**\n\t * Whether the loop should keep coming back to a namespace the peer does not hold.\n\t *\n\t * Distinct from {@link offerable}, and the difference is what arms the retry: a\n\t * namespace waiting out a minimum is not offerable yet but is still pending, and\n\t * gating the timer on offerable instead would disarm it for exactly the wait it is\n\t * supposed to be counting. Only a refusal that forbids retrying ends it.\n\t */\n\t#pending(key: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\treturn refused.get(key) !== \"never\";\n\t}\n\n\t/**\n\t * What a REQUEST_ERROR's retry interval, in milliseconds, says about re-offering the\n\t * namespace.\n\t *\n\t * Draft-14/15 carry no such field, so a 0 there says nothing and our own backoff\n\t * stands; everywhere else 0 means the peer does not want this again.\n\t */\n\t#refusal(err: RequestError): Answer {\n\t\tconst version = this.#session.version;\n\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15) return \"dropped\";\n\t\treturn err.retryInterval === 0n ? \"never\" : Date.now() + Number(err.retryInterval);\n\t}\n\n\t/**\n\t * Advertise one namespace on its own PUBLISH_NAMESPACE request. A declined request\n\t * is logged and skipped: a peer that wants none of this rejects each one and stays\n\t * connected.\n\t */\n\tasync #advertise(\n\t\tpath: Path.Valid,\n\t\trequests: Requests,\n\t\tcluster: Cluster.Advert | undefined = this.#advert,\n\t): Promise<Answer> {\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) return \"dropped\";\n\n\t\t// Opening is inside the try because it fails like any other advertisement does:\n\t\t// a peer out of stream credit rejects here, and letting that escape would unwind\n\t\t// the announce loop and take discovery down for the whole session, rather than\n\t\t// costing this one namespace a turn.\n\t\tlet request: Stream | undefined;\n\t\ttry {\n\t\t\trequest = await this.#session.openBi();\n\t\t\tconst stream = request;\n\n\t\t\t// Bounded, like the subscriber's own request: the loop is single-threaded over\n\t\t\t// advertisements, so a peer that takes the stream and answers nothing strands\n\t\t\t// every publish and withdrawal behind it. Timing out costs this namespace a\n\t\t\t// turn and leaves it outstanding, which the retry above re-offers.\n\t\t\tconst answer = await withTimeout(\n\t\t\t\t(async (): Promise<Answer> => {\n\t\t\t\t\tawait stream.writer.u53(PublishNamespace.id);\n\t\t\t\t\tconst msg = new PublishNamespace({ requestId, trackNamespace: path, cluster });\n\t\t\t\t\tawait msg.encode(stream.writer, this.#session.version);\n\n\t\t\t\t\t// Read response (RequestOk and PublishNamespaceOk share 0x07)\n\t\t\t\t\tconst respTypeId = await stream.reader.u53();\n\t\t\t\t\tif (respTypeId === RequestError.id) {\n\t\t\t\t\t\tconst err = await RequestError.decode(stream.reader, this.#session.version);\n\t\t\t\t\t\tconst why = requestReason(\n\t\t\t\t\t\t\terr.errorCode,\n\t\t\t\t\t\t\terr.reasonPhrase,\n\t\t\t\t\t\t\t\"publish_namespace\",\n\t\t\t\t\t\t\tthis.#session.version,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconsole.warn(`announce refused: broadcast=${path} error=${why}`);\n\t\t\t\t\t\tstream.abort(new Error(`PublishNamespace rejected: ${why}`));\n\t\t\t\t\t\treturn this.#refusal(err);\n\t\t\t\t\t}\n\t\t\t\t\tif (respTypeId !== RequestOk.id) {\n\t\t\t\t\t\tthrow new Error(`PublishNamespace rejected: typeId=0x${respTypeId.toString(16)}`);\n\t\t\t\t\t}\n\t\t\t\t\t// Draft-14 sends PublishNamespaceOk (requestId only, no parameters)\n\t\t\t\t\tif (this.#session.version === Version.DRAFT_14) {\n\t\t\t\t\t\tawait PublishNamespaceOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait RequestOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t}\n\t\t\t\t\treturn \"held\";\n\t\t\t\t})(),\n\t\t\t\tADVERTISE_TIMEOUT_MS,\n\t\t\t\t`advertisement timed out after ${ADVERTISE_TIMEOUT_MS}ms waiting for the peer's answer`,\n\t\t\t);\n\n\t\t\tif (answer === \"held\") requests.set(path, { path, requestId, stream });\n\t\t\treturn answer;\n\t\t} catch (err: unknown) {\n\t\t\t// The peer never answered the advertisement: a control timeout, not late content.\n\t\t\tconst e = err instanceof TimeoutError ? controlTimeout(err) : error(err);\n\t\t\tconsole.warn(`announce failed: broadcast=${path} error=${reason(e)}`);\n\t\t\trequest?.abort(e);\n\t\t\treturn \"dropped\";\n\t\t}\n\t}\n\n\t/**\n\t * Update a namespace the peer holds: REQUEST_UPDATE on the request that carries it,\n\t * with only the parameters that changed, then its answer.\n\t *\n\t * Waiting for the answer keeps one update outstanding per stream, which satisfies any\n\t * MAX_REQUEST_UPDATES the peer set without reading it; a change landing meanwhile waits\n\t * for the next turn. The answer decides whether the peer still holds the namespace: a\n\t * REQUEST_ERROR closes the peer's side and withdraws the advertisement, so ours is\n\t * finished too, and an unanswered update is dropped abruptly, since a peer that ignored\n\t * it cannot be assumed to hold either price. Either way the retry re-offers it fresh.\n\t *\n\t * A different original publisher is an update like any other: the receiver drains what\n\t * it already serves from the old one and never splices the two.\n\t */\n\tasync #update(path: Path.Valid, requests: Requests, { from, to }: Reprice): Promise<Answer> {\n\t\tconst request = requests.get(path);\n\t\tif (!request) return \"dropped\";\n\n\t\tconst update: Cluster.Update = {\n\t\t\thops: sameHops(from.hops, to.hops) ? undefined : to.hops,\n\t\t\tcost: from.cost === to.cost ? undefined : to.cost,\n\t\t};\n\t\tconst version = this.#session.version;\n\t\tlet answer: Answer;\n\t\ttry {\n\t\t\tconst requestId = await this.#session.nextRequestId();\n\t\t\tif (requestId === undefined) throw new Error(\"no request ID for the update\");\n\n\t\t\tanswer = await withTimeout(\n\t\t\t\t(async (): Promise<Answer> => {\n\t\t\t\t\tconst { writer, reader } = request.stream;\n\t\t\t\t\tawait writer.u53(PublishNamespaceUpdate.id);\n\t\t\t\t\tawait new PublishNamespaceUpdate({ requestId, update }).encode(writer, version);\n\n\t\t\t\t\tconst typeId = await reader.u53();\n\t\t\t\t\tif (typeId === RequestError.id) {\n\t\t\t\t\t\tconst err = await RequestError.decode(reader, version);\n\t\t\t\t\t\tconst why = requestReason(err.errorCode, err.reasonPhrase, \"publish_namespace\", version);\n\t\t\t\t\t\tconsole.warn(`publish_namespace update refused: broadcast=${path} error=${why}`);\n\t\t\t\t\t\treturn this.#refusal(err);\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId !== RequestOk.id) {\n\t\t\t\t\t\tthrow new Error(`unexpected answer to the update: typeId=0x${typeId.toString(16)}`);\n\t\t\t\t\t}\n\t\t\t\t\tawait RequestOk.decode(reader, version);\n\t\t\t\t\treturn \"held\";\n\t\t\t\t})(),\n\t\t\t\tADVERTISE_TIMEOUT_MS,\n\t\t\t\t`update timed out after ${ADVERTISE_TIMEOUT_MS}ms waiting for the peer's answer`,\n\t\t\t);\n\t\t} catch (err: unknown) {\n\t\t\tconst e = err instanceof TimeoutError ? controlTimeout(err) : error(err);\n\t\t\tconsole.warn(`publish_namespace update failed: broadcast=${path} error=${reason(e)}`);\n\t\t\trequests.delete(path);\n\t\t\trequest.stream.abort(e);\n\t\t\treturn \"dropped\";\n\t\t}\n\n\t\t// The peer already closed out a refused request, and its STOP_SENDING can reject the\n\t\t// wait on our FIN. That is the withdrawal finishing, not a reason to end the loop.\n\t\tif (answer !== \"held\") await this.#withdraw(path, requests).catch(() => undefined);\n\t\treturn answer;\n\t}\n\n\t/**\n\t * Close out a namespace's PUBLISH_NAMESPACE request with PUBLISH_NAMESPACE_DONE.\n\t */\n\tasync #withdraw(path: Path.Valid, requests: Requests) {\n\t\tconst request = requests.get(path);\n\t\tif (!request) return;\n\t\trequests.delete(path);\n\n\t\t// Draft-17+ removed PUBLISH_NAMESPACE_DONE: the close below is the whole\n\t\t// withdrawal. Sending it anyway puts the type on the wire before the body throws,\n\t\t// and a receiver reading 0x09 there has no choice but to treat it as a protocol\n\t\t// violation.\n\t\tconst version = this.#session.version;\n\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) {\n\t\t\ttry {\n\t\t\t\tawait request.stream.writer.u53(PublishNamespaceDone.id);\n\t\t\t\tconst done = new PublishNamespaceDone({ trackNamespace: request.path, requestId: request.requestId });\n\t\t\t\tawait done.encode(request.stream.writer, version);\n\t\t\t} catch {\n\t\t\t\t// Stream might already be closed\n\t\t\t}\n\t\t\trequest.stream.close();\n\t\t\treturn;\n\t\t}\n\t\trequest.stream.close();\n\t\t// Wait for transport acknowledgment before opening a replacement request.\n\t\t// This assumes the peer processes the withdrawal by then; FIN acknowledgment\n\t\t// does not itself acknowledge application processing across streams.\n\t\tawait request.stream.writer.closed;\n\t}\n\n\t/**\n\t * Handles an incoming TRACK_STATUS_REQUEST on a bidi stream.\n\t *\n\t * @internal\n\t */\n\tasync runTrackStatusRequest(msg: TrackStatusRequest, stream: Stream) {\n\t\t// TRACK_STATUS_ERROR is 0x0f on draft-14.\n\t\tawait this.#refuseUnsupported(stream, msg.requestId, \"track_status\", 0x0f, \"TRACK_STATUS is not supported\");\n\t}\n\n\t/**\n\t * Refuses an incoming SUBSCRIBE_TRACKS (draft-18+): we never send the PUBLISH it asks for.\n\t * The reply carries no Request ID, so the message body is left unread.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribeTracks(stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tawait stream.writer.u53(RequestError.id);\n\t\tawait new RequestError({\n\t\t\terrorCode: toRequestCode(\"not_supported\", \"subscribe_namespace\", version),\n\t\t\treasonPhrase: \"SUBSCRIBE_TRACKS is not supported\",\n\t\t}).encode(stream.writer, version);\n\t\tstream.close();\n\t}\n\n\t/**\n\t * Handles an incoming FETCH on a bidi stream. We serve none.\n\t *\n\t * @internal\n\t */\n\tasync runFetch(msg: Fetch, stream: Stream) {\n\t\tawait this.#refuseUnsupported(stream, msg.requestId, \"fetch\", FetchError.id, \"FETCH is not supported\");\n\t}\n\n\t/**\n\t * Refuse a request NOT_SUPPORTED. Draft-14 gives each request its own error message,\n\t * `errorId14`, with the SUBSCRIBE_ERROR body; later drafts use REQUEST_ERROR.\n\t */\n\tasync #refuseUnsupported(\n\t\tstream: Stream,\n\t\trequestId: bigint,\n\t\tkind: RequestKind,\n\t\terrorId14: number,\n\t\treasonPhrase: string,\n\t) {\n\t\tconst version = this.#session.version;\n\t\tconst errorCode = toRequestCode(\"not_supported\", kind, version);\n\t\tif (version === Version.DRAFT_14) {\n\t\t\tawait stream.writer.u53(errorId14);\n\t\t\tawait new SubscribeError({ requestId, errorCode, reasonPhrase }).encode(stream.writer, version);\n\t\t} else {\n\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\tawait new RequestError({\n\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? requestId : undefined,\n\t\t\t\terrorCode,\n\t\t\t\treasonPhrase,\n\t\t\t}).encode(stream.writer, version);\n\t\t}\n\t\tstream.close();\n\t}\n}\n\n/** A `{group, object}` position, in the Location Filter's own units. */\ninterface Location {\n\t/** The group's sequence number. */\n\tgroup: bigint;\n\t/** The object's id within that group. */\n\tobject: bigint;\n}\n\n/** Where a range ends, inclusive. An absent `object` includes the whole end group. */\ninterface EndLocation {\n\t/** The last group to serve. */\n\tgroup: bigint;\n\t/** The last object within it, or the whole group when absent. */\n\tobject?: bigint;\n}\n\n/**\n * The live edge a SUBSCRIBE resolves against, snapshotted once so the subscription floor,\n * the fill cap, and the advertised LARGEST_OBJECT all agree on where it is.\n */\ninterface LiveEdge {\n\t/** The newest group sequence, absent before any group exists. */\n\tlatest?: bigint;\n\n\t/**\n\t * The precise Largest Object. Absent when the track has no readable frame, in which case\n\t * nothing is advertised and no fill is servable.\n\t */\n\tlargest?: Location;\n\n\t/**\n\t * One past the Largest Object, which is where a Next Object subscription begins. With no\n\t * readable object anywhere this falls back to the newest group's start, which excludes\n\t * nothing the cache can still name.\n\t */\n\tnext?: Location;\n}\n\n/** The Locations a SUBSCRIBE's Location Filter selects, resolved against the live edge. */\ninterface ServeRange {\n\t/** The first Location to serve, or the start of the latest group when absent. */\n\tstart?: Location;\n\n\t/**\n\t * Where the range ends, inclusive, or open ended when absent. The subscription stays open\n\t * once the range is exhausted; draft-20 removed the notion of a filter ending one.\n\t */\n\tend?: EndLocation;\n}\n\n/** The slice of one group a subscription's {@link ServeRange} selects. */\ninterface GroupSlice {\n\t/** Objects dropped from the front; also the first written object's absolute id. */\n\tskip: number;\n\n\t/** One past the last object to write, when the filter ends inside this group. */\n\tuntil?: number;\n}\n\n/** A fill resolved to a single group of the cache. */\ninterface FillGroup {\n\tkind: \"group\";\n\t/** The group to serve. */\n\tsequence: bigint;\n\t/** Objects dropped from the front. */\n\tskip: bigint;\n\t/** One past the last object to write, capping the fill at the Largest Object snapshot. */\n\tuntil?: bigint;\n}\n\n/** What a draft-20 fill request resolves to. */\ntype FillServe =\n\t/** The range is empty, so no fetch stream is opened at all. */\n\t| { kind: \"empty\" }\n\t| FillGroup\n\t/**\n\t * A range spanning several groups, which we do not serve: multi-group fetch\n\t * serialization depends on a negotiated group order we do not implement, so the stream is\n\t * reset instead, the draft's fill-failure signal.\n\t */\n\t| { kind: \"unsupported\" };\n\n/**\n * Take one group out of a cache view, without waiting.\n *\n * A fill's group is at or below the Largest Object snapshot, so it is either still in the\n * retained window or gone for good: nothing republishes an old sequence, and waiting for one\n * would park for the life of the track. Scanning past it, or running dry, is a cache miss,\n * which the caller turns into the draft's fill-failure reset.\n */\nfunction takeGroup(cache: TrackSubscriber, sequence: number): group.Consumer {\n\tfor (;;) {\n\t\tconst group = cache.tryRecvGroup();\n\t\tif (!group) throw new Error(`group not found: ${sequence}`);\n\t\tif (group.sequence === sequence) return group;\n\n\t\tgroup.close();\n\t\tif (group.sequence > sequence) throw new Error(`group not found: ${sequence}`);\n\t}\n}\n\n/** `a - b`, saturating at zero the way the draft's unsigned arithmetic does. */\nfunction saturatingSub(a: bigint, b: bigint): bigint {\n\treturn a > b ? a - b : 0n;\n}\n\n/** Snapshot the live edge of a track. */\nfunction liveEdge(track: TrackSubscriber): LiveEdge {\n\tconst latest = track.latest();\n\tif (latest === undefined) return {};\n\n\tconst largest = track.largest();\n\tif (!largest) return { latest: BigInt(latest), next: { group: BigInt(latest), object: 0n } };\n\n\tconst group = BigInt(largest.group);\n\tconst object = BigInt(largest.frame);\n\treturn { latest: BigInt(latest), largest: { group, object }, next: { group, object: object + 1n } };\n}\n\n/**\n * Resolve a SUBSCRIBE's Location Filter into the range to serve.\n *\n * Only draft-20 is honored. Earlier drafts have a Filter Type tag whose absolute forms we\n * never served, and starting to interpret them now would change what an existing peer\n * receives; draft-20 is also the first version whose relative forms can name a past group\n * without the subscriber knowing Largest Object.\n */\nfunction subscribeRange(msg: Subscribe, edge: LiveEdge, version: IetfVersion): ServeRange {\n\tif (!Filter.isDraft20(version)) {\n\t\tif (msg.filter.kind !== \"nextObject\" && msg.filter.kind !== \"unfiltered\") {\n\t\t\tconsole.warn(`filter not supported before draft-20, ignoring: ${msg.filter.kind}`);\n\t\t}\n\t\treturn {};\n\t}\n\n\treturn filterRange(msg.filter, edge);\n}\n\n/** The Locations a single Location Filter selects, resolved against the live edge. */\nfunction filterRange(filter: Filter.Filter, edge: LiveEdge): ServeRange {\n\tswitch (filter.kind) {\n\t\t// No restriction. moq-lite starts at the beginning of the latest group, which is the\n\t\t// join point it is built around; a subscription passes objects as they are published,\n\t\t// so an absent filter is not a request to replay history.\n\t\tcase \"unfiltered\":\n\t\t\treturn {};\n\t\t// `{Largest.Group, Largest.Object + 1}`. Everything below it, including the already\n\t\t// published head of the current group, is outside the requested range, so the join is\n\t\t// mid-group by construction. The draft pairs this with a fill when the subscriber\n\t\t// wants the head; see {@link Publisher.runFill}.\n\t\tcase \"nextObject\":\n\t\t\treturn { start: edge.next };\n\t\t// `{Largest.Group + 1 - groups, 0}`: 0 is the next group and 1 is the current one.\n\t\t// Counted from `Largest.Group`, which sits below the newest group while that group has\n\t\t// no objects yet; only with no largest at all does the newest group stand in for it.\n\t\tcase \"relative\": {\n\t\t\tconst base = edge.largest?.group ?? edge.latest;\n\t\t\tif (base === undefined) return {};\n\t\t\treturn { start: { group: saturatingSub(base + 1n, filter.groups), object: 0n } };\n\t\t}\n\t\tcase \"absolute\":\n\t\t\treturn {\n\t\t\t\tstart: { group: filter.startGroup, object: filter.startObject },\n\t\t\t\tend: filter.endGroup === undefined ? undefined : { group: filter.endGroup, object: filter.endObject },\n\t\t\t};\n\t}\n}\n\n/**\n * Trim a group to the filter's object bounds, so nothing outside the requested range is\n * sent. Interior groups are served whole.\n */\nfunction groupSlice(range: ServeRange, sequence: number): GroupSlice {\n\tconst at = BigInt(sequence);\n\treturn {\n\t\tskip: range.start?.group === at ? Number(range.start.object) : 0,\n\t\tuntil: range.end?.group === at && range.end.object !== undefined ? Number(range.end.object) + 1 : undefined,\n\t};\n}\n\n/**\n * Resolve a fill request using the Fetch rules: relative to Largest Object and never\n * extending beyond it. An omitted Location Filter inherits the subscription's.\n */\nfunction fillRange(fill: Filter.Fill, subscription: Filter.Filter, largest?: Location): FillServe {\n\t// A Range Filter narrows which objects pass, which we do not implement; serving the\n\t// unfiltered range instead would deliver objects the peer excluded, so refuse it.\n\tif (fill.rangeFilters) return { kind: \"unsupported\" };\n\tconst filter = fill.filter ?? subscription;\n\n\t// Nothing published (or no precise edge to cap at) means no fill is servable; an empty\n\t// range opens no stream.\n\tif (!largest) return { kind: \"empty\" };\n\n\tlet start: Location;\n\tswitch (filter.kind) {\n\t\t// A Fetch without a filter is the whole track up to Largest Object.\n\t\tcase \"unfiltered\":\n\t\t\tstart = { group: 0n, object: 0n };\n\t\t\tbreak;\n\t\t// One past the edge, which for a Fetch is always empty.\n\t\tcase \"nextObject\":\n\t\t\treturn { kind: \"empty\" };\n\t\tcase \"relative\":\n\t\t\tstart = { group: saturatingSub(largest.group + 1n, filter.groups), object: 0n };\n\t\t\tbreak;\n\t\tcase \"absolute\":\n\t\t\tstart = { group: filter.startGroup, object: filter.startObject };\n\t\t\tbreak;\n\t}\n\n\t// Cap the requested end at Largest Object.\n\tlet end: EndLocation = { group: largest.group, object: largest.object };\n\tif (filter.kind === \"absolute\" && filter.endGroup !== undefined) {\n\t\tconst below =\n\t\t\tfilter.endGroup < largest.group ||\n\t\t\t(filter.endGroup === largest.group && filter.endObject !== undefined && filter.endObject < largest.object);\n\t\tif (below) end = { group: filter.endGroup, object: filter.endObject };\n\t}\n\n\tif (\n\t\tstart.group > end.group ||\n\t\t(start.group === end.group && end.object !== undefined && end.object < start.object)\n\t) {\n\t\treturn { kind: \"empty\" };\n\t}\n\tif (start.group !== end.group) return { kind: \"unsupported\" };\n\n\treturn {\n\t\tkind: \"group\",\n\t\tsequence: start.group,\n\t\tskip: start.object,\n\t\tuntil: end.object === undefined ? undefined : end.object + 1n,\n\t};\n}\n\nclass UpdateFailed extends Error {\n\tconstructor() {\n\t\tsuper(\"subscription update failed\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/ietf/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,M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G,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,EACnF,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK;QAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;IAE9D,OAAO;QACN,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,KAAK,CAAC,KAAK;QACrB,IAAI,EAAE,KAAK,CAAC,MAAM;QAClB,KAAK,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE;KAC7D,CAAC;AACH,CAAC;AAED,MAAM,YAAa,SAAQ,KAAK;IAC/B;QACC,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACrC,CAAC;CACD","sourcesContent":["import { type Dispose, type Getter, race, Signal } from \"@moq/signals\";\nimport type * as broadcast from \"../broadcast.ts\";\nimport { controlTimeout, error, reason, StreamCode, StreamError } from \"../error.ts\";\nimport type * as group from \"../group.ts\";\nimport type { Hop, Route } from \"../hop.ts\";\nimport { hiddenBelow, hooks, presented } from \"../internal.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Stream, Writer } from \"../stream.ts\";\nimport { Milli, Timescale } from \"../time.ts\";\nimport type { Subscriber as TrackSubscriber } from \"../track.ts\";\nimport { TimeoutError, withTimeout } from \"../util/timeout.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { type Advertised, type Advertisements, wireOf } from \"../wire.ts\";\nimport type { Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { type RequestKind, requestReason, toRequestCode } from \"./error.ts\";\nimport { type Fetch, FetchError, FetchHeader } from \"./fetch.ts\";\nimport * as Filter from \"./filter.ts\";\nimport * as Message from \"./message.ts\";\nimport { FetchFrame, Frame, Group as GroupMessage } from \"./object.ts\";\nimport { Parameters } from \"./parameters.ts\";\nimport { fromWire, toWire } from \"./priority.ts\";\nimport * as Properties from \"./properties.ts\";\nimport { PublishDone, PublishDoneStatus } from \"./publish.ts\";\nimport {\n\tPublishNamespace,\n\tPublishNamespaceDone,\n\tPublishNamespaceOk,\n\tPublishNamespaceUpdate,\n} from \"./publish_namespace.ts\";\nimport { RequestError, RequestOk } from \"./request.ts\";\nimport { cancelled, finCancels } from \"./request_stream.ts\";\nimport { type Subscribe, SubscribeError, SubscribeOk } from \"./subscribe.ts\";\nimport {\n\ttype SubscribeNamespace,\n\tSubscribeNamespaceEntry,\n\tSubscribeNamespaceEntryDone,\n\tSubscribeNamespaceOk,\n} from \"./subscribe_namespace.ts\";\nimport type { TrackStatusRequest } from \"./track.ts\";\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/** First wait before re-offering a namespace the peer refused or we couldn't open for. */\nconst RETRY_BASE = 100;\n\n/** Ceiling on that wait. The loop retries for the life of the session, so it must not spin. */\nconst RETRY_MAX = 5000;\n\n/** Cluster parameters for one snapshot: the advertised hops, then our own id last. */\nfunction clusterFor(base: Cluster.Advert | undefined, route: Route): Cluster.Advert | undefined {\n\tif (!base) return undefined;\n\tconst self = base.hops.at(-1);\n\tif (self === undefined) return undefined;\n\tconst hops = route.hops.at(-1) === self ? [...route.hops] : [...route.hops, self];\n\treturn { hops, cost: route.cost.warm };\n}\n\n/**\n * What it takes to move the peer from `held` to `next`.\n *\n * - `\"same\"`: the peer would decode the same advertisement. The cold cost, and the whole\n * route without Cluster, never reach the wire, so a change there sends nothing.\n * - `\"restart\"`: nothing is held, nothing is wanted, or a different broadcast, which is\n * withdrawn and advertised again.\n * - Otherwise the same broadcast at a new hop chain or warm cost: the cluster parameters\n * the peer holds and the ones it should, for the target to update.\n */\nfunction change(\n\tbase: Cluster.Advert | undefined,\n\theld: Advertised | undefined,\n\tnext: Advertised | undefined,\n): \"same\" | \"restart\" | Reprice {\n\tif (held === undefined || next === undefined || held.identity !== next.identity) return \"restart\";\n\tconst from = clusterFor(base, held.route);\n\tconst to = clusterFor(base, next.route);\n\tif (from === undefined || to === undefined) return from === to ? \"same\" : \"restart\";\n\tif (from.cost === to.cost && sameHops(from.hops, to.hops)) return \"same\";\n\treturn { from, to };\n}\n\n/** A held advertisement's cluster parameters, and the ones the peer should hold instead. */\ninterface Reprice {\n\tfrom: Cluster.Advert;\n\tto: Cluster.Advert;\n}\n\n/** Whether two hop paths list the same hops in the same order. */\nfunction sameHops(a: Hop[], b: Hop[]): boolean {\n\treturn a.length === b.length && a.every((hop, i) => hop === b[i]);\n}\n\n/**\n * How long one advertisement may take to be answered. Matches the Rust publisher, and the\n * peer accepting the stream is only half the exchange: one it never answers on holds the\n * loop just as effectively as one it never grants.\n */\nconst ADVERTISE_TIMEOUT_MS = 5000;\n\n/** Sleep `delay`, jittered, so a relay's namespaces don't all retry on the same tick. */\nfunction retryAfter(delay: number): Promise<void> {\n\treturn new Promise((resolve) => setTimeout(resolve, delay * (0.5 + Math.random() / 2)));\n}\n\n/**\n * What a refusal said about re-offering the namespace.\n *\n * A peer answers a request it declines with a retry interval, and ignoring it is how a\n * permanent refusal (unauthorized, uninterested) turns into a request every few seconds\n * for the life of the session. `\"never\"` is an interval of 0; a number is the epoch\n * milliseconds before which we must not come back.\n */\ntype Refused = \"never\" | number;\n\n/**\n * How the peer answered an advertisement or an update: it holds the namespace, it does\n * not and said nothing about coming back (`\"dropped\"`), or it refused.\n */\ntype Answer = \"held\" | \"dropped\" | Refused;\n\n/** The open PUBLISH_NAMESPACE request per advertised path. */\ntype Requests = Map<Path.Valid, { path: Path.Valid; requestId: bigint; stream: Stream }>;\n\n/** What one announce loop knows about the peer, keyed the way that loop names namespaces. */\ninterface Namespaces {\n\t/** What the peer holds, by identity plus route. */\n\tactive: Map<Path.Valid, Advertised>;\n\n\t/** What the peer refused, and whether coming back is worth anything. */\n\trefused: Map<Path.Valid, Refused>;\n\n\t/** The identity each refusal was about, so a republish at the same path clears it. */\n\toffered: Map<Path.Valid, object>;\n}\n\n/** Where one announce loop sends its advertisements. */\ninterface Target {\n\t/** Advertise a namespace the peer does not hold. */\n\tadvertise(key: Path.Valid, next: Advertised): Promise<Answer>;\n\n\t/** Reprice a namespace the peer holds: the same broadcast at a new hop chain or cost. */\n\tupdate(key: Path.Valid, next: Advertised, reprice: Reprice): Promise<Answer>;\n\n\t/** Withdraw a namespace the peer holds. */\n\twithdraw(key: Path.Valid): Promise<void>;\n}\n\n/** What {@link Publisher.runGroup} needs to serve one group. */\ninterface RunGroup {\n\t/** The subscription's request ID, doubling as the track alias. */\n\trequestId: bigint;\n\n\t/** The group to serve. */\n\tgroup: group.Consumer;\n\n\t/** The track's advertised timescale, applied to every frame timestamp. */\n\ttimescale: Timescale;\n\n\t/** The publisher's tie-break priority, already converted to the IETF wire convention. */\n\tpublisherPriority: number;\n\n\t/**\n\t * Whether objects carry their presentation timestamp.\n\t *\n\t * False once the subscriber sends INCLUDE_PROPERTIES=0: that drops TIMESCALE from\n\t * SUBSCRIBE_OK, and a timestamp whose units were never declared is worse than none. Our\n\t * own reader discards it; another may read it as some default and time the media wrong.\n\t */\n\tstamped: boolean;\n\n\t/** The objects of this group the subscription's filter selects. */\n\tslice: GroupSlice;\n\n\t/** Settles when the subscriber leaves, dropping a group still queued for a stream slot. */\n\tunsubscribed: Promise<void>;\n\n\t/** The subscription's data stream count, which PUBLISH_DONE reports. */\n\tstreams: StreamCount;\n}\n\n/** How many data streams a subscription opened, fill streams included. */\ntype StreamCount = { opened: number };\n\n/** What {@link Publisher.runFill} needs to serve one subscription's backfill. */\ninterface RunFill {\n\t/** The subscription's request ID, which the fetch stream names. */\n\trequestId: bigint;\n\n\t/**\n\t * The subscriber's delivery priority, applied to the cache subscription the fill reads.\n\t *\n\t * Deliberately not the fetch stream's send order: this publisher leaves its group\n\t * streams at the transport's default, so ranking the fill alone would put backfill\n\t * ahead of the live groups it is catching up to.\n\t */\n\tpriority: number;\n\n\t/** The range the fill resolved to. */\n\tfill: FillServe;\n\n\t/**\n\t * An independent view of the same track, used to read the cached group without consuming\n\t * anything the subscription will deliver.\n\t */\n\tcache: TrackSubscriber;\n\n\t/** The track's advertised timescale, applied to every frame timestamp. */\n\ttimescale: Timescale;\n\n\t/** Whether objects carry their presentation timestamp; see {@link RunGroup.stamped}. */\n\tstamped: boolean;\n\n\t/** Settles when the subscriber leaves, releasing a fill still waiting on its group. */\n\tunsubscribed: Promise<void>;\n\n\t/** The subscription's data stream count, which PUBLISH_DONE reports. */\n\tstreams: StreamCount;\n}\n\n/**\n * Handles publishing broadcasts using moq-transport protocol.\n * Uses the stream-per-request pattern (real bidi streams for v17, virtual for v14-v16).\n *\n * @internal\n */\nexport class Publisher {\n\t#quic: WebTransport;\n\t#session: Session;\n\t#requiresSolicitation: boolean;\n\t#hidden: boolean;\n\n\t// The origin this session serves, borrowed: it outlives the session, and closing the\n\t// session leaves its broadcasts alone. The namespaces are advertised with an unsolicited\n\t// PUBLISH_NAMESPACE (see {@link runPublishNamespaces}), or on request if the peer asked\n\t// for that (see {@link runSubscribeNamespace}).\n\t#advertised: Getter<Advertisements | undefined>;\n\t#publish?: OriginConsumer;\n\n\t// What every advertisement carries on a session that negotiated the MoQ Cluster\n\t// extension: a hop path holding our own id, so the peer can tell that what it hears\n\t// back came from us. `undefined` when nothing negotiated it.\n\t#advert?: Cluster.Advert;\n\n\t/**\n\t * Creates a new Publisher instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\tquic,\n\t\tsession,\n\t\tpublish,\n\t\trequiresSolicitation,\n\t\thidden = false,\n\t\tcluster,\n\t}: {\n\t\t/** The WebTransport session, for uni streams. */\n\t\tquic: WebTransport;\n\t\t/** The session abstraction for bidi streams and request IDs. */\n\t\tsession: Session;\n\t\t/** The origin whose broadcasts this session serves; omit to publish nothing. */\n\t\tpublish?: OriginConsumer;\n\t\t/** Whether the peer's SETUP asked to be told on request (MoQ Solicit). */\n\t\trequiresSolicitation: boolean;\n\t\t/** Whether the peer declared MoQ Hidden. */\n\t\thidden?: boolean;\n\t\t/** The Hop IDs the SETUP exchange settled (MoQ Cluster). */\n\t\tcluster?: Cluster.Hops;\n\t}) {\n\t\tthis.#quic = quic;\n\t\tthis.#session = session;\n\t\tconst origin = publish && wireOf(publish);\n\t\tthis.#advertised = origin?.advertised ?? new Signal(new Map());\n\t\tthis.#publish = publish;\n\t\tthis.#requiresSolicitation = requiresSolicitation;\n\t\tthis.#hidden = hidden;\n\t\tthis.#advert = Cluster.advertise(cluster);\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE request on a bidi stream.\n\t * Owns the full lifecycle: sends response, serves track data, waits for close.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribe(msg: Subscribe, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst name = msg.trackNamespace;\n\t\tlet broadcast: broadcast.Consumer | undefined;\n\t\tlet refusal: { errorCode: number; reasonPhrase: string } | undefined;\n\n\t\t// Legal requests we can't honor are refused one at a time. A subscription that\n\t\t// forwards nothing is only useful to a subscriber that later turns forwarding on,\n\t\t// and serving a Range Filter unfiltered would deliver objects it excluded.\n\t\tconst unsupported = !msg.forward\n\t\t\t? \"FORWARD=0 not supported\"\n\t\t\t: msg.rangeFilters\n\t\t\t\t? \"range filters not supported\"\n\t\t\t\t: undefined;\n\n\t\tif (unsupported) {\n\t\t\trefusal = { errorCode: toRequestCode(\"not_supported\", \"subscribe\", version), reasonPhrase: unsupported };\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tbroadcast =\n\t\t\t\t\tthis.#publish && (wireOf(this.#publish).local(name) ?? (await wireOf(this.#publish).demand(name)));\n\t\t\t\tif (!broadcast) {\n\t\t\t\t\trefusal = {\n\t\t\t\t\t\terrorCode: toRequestCode(\"does_not_exist\", \"subscribe\", version),\n\t\t\t\t\t\treasonPhrase: \"broadcast not found\",\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t} catch (err: unknown) {\n\t\t\t\tconst e = error(err);\n\t\t\t\tconst condition =\n\t\t\t\t\te instanceof StreamError && e.code === StreamCode.NotFound ? \"does_not_exist\" : \"internal\";\n\t\t\t\trefusal = { errorCode: toRequestCode(condition, \"subscribe\", version), reasonPhrase: reason(e) };\n\t\t\t}\n\t\t}\n\n\t\tif (refusal) {\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeError.id);\n\t\t\t\tconst err = new SubscribeError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode: refusal.errorCode,\n\t\t\t\t\treasonPhrase: refusal.reasonPhrase,\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\tconst err = new RequestError({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t\terrorCode: refusal.errorCode,\n\t\t\t\t\treasonPhrase: refusal.reasonPhrase,\n\t\t\t\t});\n\t\t\t\tawait err.encode(stream.writer, version);\n\t\t\t}\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\t\tif (!broadcast) return;\n\n\t\tconst priority = fromWire(msg.subscriberPriority);\n\t\tconst track = wireOf(broadcast).subscribe(msg.trackName, {\n\t\t\tpriority,\n\t\t\t// moq-transport has no subscriber latency parameter. Keep everything the\n\t\t\t// producer retained and let the receiving subscriber enforce its own budget.\n\t\t\t// Keep the sentinel encodable if this demand crosses a Lite hop before the\n\t\t\t// producer's retention bound is known.\n\t\t\tmaxAge: Milli(Varint.MAX_U53),\n\t\t});\n\n\t\tlet cache: TrackSubscriber | undefined;\n\n\t\ttry {\n\t\t\t// Declaring the timescale is what opts the track into timestamps; every object\n\t\t\t// Timestamp below is in these units.\n\t\t\tconst info = await track.info();\n\t\t\tconst timescale = info.timescale;\n\t\t\t// The model ranks higher-first, the IETF wire lower-first. Every group this\n\t\t\t// subscription serves carries the same publisher priority, which is what lets a\n\t\t\t// relay prefer catalog and audio over video when it has no subscriber preference\n\t\t\t// to go on.\n\t\t\tconst publisherPriority = toWire(info.priority);\n\n\t\t\t// The filter and any fill are relative to the live edge, so snapshot it once: the\n\t\t\t// fill ends exactly where a Next Object subscription begins, which is what lets\n\t\t\t// the draft's current-group join (Next Object plus a StartGroup=1 fill) cover the\n\t\t\t// group with no gap and no overlap.\n\t\t\tconst edge = liveEdge(track);\n\t\t\tconst range = subscribeRange(msg, edge, version);\n\n\t\t\t// The wire request tells an upstream what we need; the cursor is what actually\n\t\t\t// trims this subscriber, since the producer fans every cached group out to every\n\t\t\t// sink regardless. An absent start joins at the latest group, which is what\n\t\t\t// moq-lite means by joining a live track. The range's end is the inclusive last\n\t\t\t// group; the model's `endGroup` is exclusive.\n\t\t\ttrack.update({\n\t\t\t\tpriority,\n\t\t\t\tmaxAge: Milli(Varint.MAX_U53),\n\t\t\t\tgroups: {\n\t\t\t\t\tstart: range.start ? { included: Number(range.start.group) } : undefined,\n\t\t\t\t\tend: range.end ? { included: Number(range.end.group) } : undefined,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst startGroup = range.start ? Number(range.start.group) : track.latest();\n\t\t\tif (startGroup !== undefined) track.setGroups({ start: { included: startGroup } });\n\n\t\t\t// A fill reads the group cache through its own consumer, independent of the\n\t\t\t// subscription's cursor. Forked from this subscriber rather than resolved through\n\t\t\t// the broadcast again: a dynamic serve is one request per peer subscription, so\n\t\t\t// asking the broadcast would mint a second producer nobody has accepted.\n\t\t\tconst fill =\n\t\t\t\tmsg.fill && Filter.isDraft20(version) ? fillRange(msg.fill, msg.filter, edge.largest) : undefined;\n\t\t\tcache = fill && fill.kind !== \"empty\" ? track.fork({ priority, maxAge: Milli(Varint.MAX_U53) }) : undefined;\n\n\t\t\t// Send SUBSCRIBE_OK\n\t\t\tawait stream.writer.u53(SubscribeOk.id);\n\t\t\tconst ok = new SubscribeOk({\n\t\t\t\trequestId:\n\t\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t\t? msg.requestId\n\t\t\t\t\t\t: undefined,\n\t\t\t\ttrackAlias: msg.requestId,\n\t\t\t\t// Required once the track has content; a fill-requesting subscriber sizes its\n\t\t\t\t// backfill against this. Below draft-20 round it down to the start of its\n\t\t\t\t// group, matching what the subscription serves there: a draft-20 subscriber\n\t\t\t\t// recovers a group's head with a FILL, which we serve, while older drafts\n\t\t\t\t// recover it with a joining FETCH, which we do not, so naming a mid-group\n\t\t\t\t// start would strand them.\n\t\t\t\tlargest:\n\t\t\t\t\tedge.largest &&\n\t\t\t\t\t(Filter.isDraft20(version)\n\t\t\t\t\t\t? { groupId: edge.largest.group, objectId: edge.largest.object }\n\t\t\t\t\t\t: { groupId: edge.largest.group, objectId: 0n }),\n\t\t\t\tproperties: msg.propertiesWanted\n\t\t\t\t\t? // Declaring the timescale is what opts the track into timestamps; every\n\t\t\t\t\t\t// object Timestamp below is in these units. We serve the newest group\n\t\t\t\t\t\t// first, matching moq-lite.\n\t\t\t\t\t\t{ timescale, priority: publisherPriority, groupOrder: Properties.DESCENDING }\n\t\t\t\t\t: // INCLUDE_PROPERTIES=0. The block stays present but empty, which also means\n\t\t\t\t\t\t// the track opts out of timestamps for this subscriber.\n\t\t\t\t\t\t{},\n\t\t\t});\n\t\t\tawait ok.encode(stream.writer, version);\n\t\t\tconsole.debug(`publish ok: broadcast=${name} track=${track.name}`);\n\n\t\t\t// Cancels groups still queued for a stream slot. Only the subscriber leaving counts:\n\t\t\t// a track that ran out of groups still has to flush the ones already queued, and we\n\t\t\t// close the stream ourselves below to say so.\n\t\t\tlet finished = false;\n\t\t\tlet unsubscribe!: () => void;\n\t\t\tconst unsubscribed = new Promise<void>((resolve) => {\n\t\t\t\tunsubscribe = resolve;\n\t\t\t});\n\n\t\t\t// Update replies and PUBLISH_DONE come from separate tasks but share this stream, and a\n\t\t\t// message is written in several pieces. Chain them so each goes out whole, in order,\n\t\t\t// and nothing follows PUBLISH_DONE.\n\t\t\tlet replies: Promise<void> = Promise.resolve();\n\t\t\tlet replied = false;\n\t\t\tconst reply = (write: () => Promise<void>): Promise<void> => {\n\t\t\t\tconst sent = replies.then(() => (replied ? undefined : write()));\n\t\t\t\treplies = sent.catch(() => undefined);\n\t\t\t\treturn sent;\n\t\t\t};\n\t\t\tlet publishError: Error | undefined;\n\n\t\t\tconst updates = (async () => {\n\t\t\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16)\n\t\t\t\t\treturn stream.reader.closed;\n\t\t\t\tfor (;;) {\n\t\t\t\t\tif (await stream.reader.done()) {\n\t\t\t\t\t\tif (finCancels(version)) return;\n\t\t\t\t\t\treturn stream.writer.closed;\n\t\t\t\t\t}\n\t\t\t\t\tif ((await stream.reader.u53()) !== 0x02) throw new Error(\"unexpected message on subscribe stream\");\n\t\t\t\t\tconst params = await Message.decode(stream.reader, async (r) => {\n\t\t\t\t\t\tawait r.u62();\n\t\t\t\t\t\tif (version === Version.DRAFT_17) await r.u62();\n\t\t\t\t\t\treturn Parameters.decode(r, version);\n\t\t\t\t\t});\n\t\t\t\t\tconst unsupported =\n\t\t\t\t\t\tparams.forward === false ||\n\t\t\t\t\t\tparams.bytes.size > 0 ||\n\t\t\t\t\t\tparams.subscriptionFilter !== undefined ||\n\t\t\t\t\t\tparams.largest !== undefined ||\n\t\t\t\t\t\tparams.rangeFilters ||\n\t\t\t\t\t\tparams.trackPropertyFilter ||\n\t\t\t\t\t\tparams.authorizationToken ||\n\t\t\t\t\t\t[...params.vars.keys()].some((key) => key !== 0x10n && key !== 0x20n);\n\t\t\t\t\tif (unsupported) {\n\t\t\t\t\t\t// Recorded before the reply, so a PUBLISH_DONE queued behind it reports the failure.\n\t\t\t\t\t\tconst failed = new UpdateFailed();\n\t\t\t\t\t\tpublishError = failed;\n\t\t\t\t\t\tawait reply(async () => {\n\t\t\t\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\t\t\t\tawait new RequestError({\n\t\t\t\t\t\t\t\trequestId: undefined,\n\t\t\t\t\t\t\t\terrorCode: toRequestCode(\"not_supported\", \"subscribe\", version),\n\t\t\t\t\t\t\t\treasonPhrase: \"REQUEST_UPDATE parameters not supported\",\n\t\t\t\t\t\t\t}).encode(stream.writer, version);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthrow failed;\n\t\t\t\t\t}\n\t\t\t\t\t// update() replaces every option, so carry the rest over as Rust does.\n\t\t\t\t\tif (params.subscriberPriority !== undefined)\n\t\t\t\t\t\ttrack.update({ ...track.subscription.peek(), priority: fromWire(params.subscriberPriority) });\n\t\t\t\t\tawait reply(async () => {\n\t\t\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\t\t\tawait new RequestOk({ requestId: undefined }).encode(stream.writer, version);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t\tconst requestEnded =\n\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t? updates\n\t\t\t\t\t: race([updates, stream.writer.closed]);\n\t\t\tvoid requestEnded.then(\n\t\t\t\t() => {\n\t\t\t\t\tif (!finished) unsubscribe();\n\t\t\t\t},\n\t\t\t\t// Updates can fail after the serving loop ends while its last groups drain.\n\t\t\t\t(err: unknown) => {\n\t\t\t\t\tpublishError = error(err);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t},\n\t\t\t);\n\n\t\t\t// Every group started, until its stream finishes or resets, and the data streams\n\t\t\t// opened for PUBLISH_DONE to report.\n\t\t\tconst groups = new Set<Promise<void>>();\n\t\t\tconst streams: StreamCount = { opened: 0 };\n\n\t\t\t// Serve groups until the track ends or the requester cancels.\n\t\t\tconst serving = (async () => {\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst group = await track.recvGroup();\n\t\t\t\t\tif (!group) return;\n\n\t\t\t\t\t// Past the filter's end. Dropped here rather than through `setGroups`, which\n\t\t\t\t\t// parks a capped group instead: this range is fixed for the life of the\n\t\t\t\t\t// subscription, so a group above it is never coming back in, and holding\n\t\t\t\t\t// one keeps the loop from ever ending. A producer that publishes beyond\n\t\t\t\t\t// the end and then closes would otherwise strand PUBLISH_DONE.\n\t\t\t\t\tif (range.end !== undefined && BigInt(group.sequence) > range.end.group) {\n\t\t\t\t\t\tgroup.close();\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst task = this.#runGroup({\n\t\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\t\tgroup,\n\t\t\t\t\t\ttimescale,\n\t\t\t\t\t\tpublisherPriority,\n\t\t\t\t\t\tstamped: msg.propertiesWanted,\n\t\t\t\t\t\tslice: groupSlice(range, group.sequence),\n\t\t\t\t\t\tunsubscribed,\n\t\t\t\t\t\tstreams,\n\t\t\t\t\t});\n\t\t\t\t\tgroups.add(task);\n\t\t\t\t\tvoid task.finally(() => groups.delete(task));\n\t\t\t\t}\n\t\t\t})();\n\n\t\t\t// The fill (when one was requested) runs alongside on its own fetch stream; its\n\t\t\t// failures reset that stream and never touch the subscription.\n\t\t\tconst filling =\n\t\t\t\tfill && cache\n\t\t\t\t\t? this.#runFill({\n\t\t\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\t\t\tpriority,\n\t\t\t\t\t\t\tfill,\n\t\t\t\t\t\t\tcache,\n\t\t\t\t\t\t\ttimescale,\n\t\t\t\t\t\t\tstamped: msg.propertiesWanted,\n\t\t\t\t\t\t\tunsubscribed,\n\t\t\t\t\t\t\tstreams,\n\t\t\t\t\t\t})\n\t\t\t\t\t: Promise.resolve();\n\n\t\t\tlet ended = false;\n\t\t\ttry {\n\t\t\t\tconst served = Symbol(\"served\");\n\t\t\t\tended = (await race([Promise.all([serving, filling]).then(() => served), requestEnded])) === served;\n\t\t\t} catch (err: unknown) {\n\t\t\t\tpublishError = error(err);\n\t\t\t}\n\n\t\t\t// PUBLISH_DONE waits until every stream this subscription will open is closed, as\n\t\t\t// the draft requires, so its count is final. The subscriber leaving cancels the\n\t\t\t// ones still queued instead.\n\t\t\tawait race([Promise.all(groups), unsubscribed]);\n\t\t\t// An error of our own (a refused or malformed update, a failed track) ends the\n\t\t\t// subscription while the requester may still listen, so its open streams reset\n\t\t\t// rather than finish as if complete, and PUBLISH_DONE still follows them. A stream\n\t\t\t// error is the requester cancelling, which the shortcut above already covers.\n\t\t\tif (publishError && !(publishError instanceof StreamError)) {\n\t\t\t\ttrack.close(publishError);\n\t\t\t\tawait Promise.all([...groups, filling]);\n\t\t\t}\n\n\t\t\t// Draft 14 on has no end location in PUBLISH_DONE: an END_OF_TRACK object is what\n\t\t\t// tells the subscriber where the track ended.\n\t\t\tconst final = track.final();\n\t\t\tif (ended && !publishError && final !== undefined) {\n\t\t\t\tawait this.#runEndOfTrack({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\tfinal,\n\t\t\t\t\tpublisherPriority,\n\t\t\t\t\tunsubscribed,\n\t\t\t\t\tstreams,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconsole.debug(`publish done: broadcast=${name} track=${track.name}`);\n\t\t\tif (publishError) {\n\t\t\t\tconsole.warn(`publish error: broadcast=${name} track=${track.name} error=${reason(publishError)}`);\n\t\t\t}\n\n\t\t\t// PUBLISH_DONE is required for every supported draft. The peer may have already\n\t\t\t// closed its side to unsubscribe, in which case there is nowhere to send it.\n\t\t\ttry {\n\t\t\t\tawait reply(async () => {\n\t\t\t\t\treplied = true;\n\t\t\t\t\tawait stream.writer.u53(PublishDone.id);\n\t\t\t\t\tconst done = new PublishDone({\n\t\t\t\t\t\trequestId:\n\t\t\t\t\t\t\tversion === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16\n\t\t\t\t\t\t\t\t? msg.requestId\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\tstatusCode:\n\t\t\t\t\t\t\tpublishError instanceof UpdateFailed\n\t\t\t\t\t\t\t\t? PublishDoneStatus.UPDATE_FAILED\n\t\t\t\t\t\t\t\t: publishError\n\t\t\t\t\t\t\t\t\t? PublishDoneStatus.INTERNAL_ERROR\n\t\t\t\t\t\t\t\t\t: PublishDoneStatus.TRACK_ENDED,\n\t\t\t\t\t\tstreamCount: BigInt(streams.opened),\n\t\t\t\t\t\treasonPhrase:\n\t\t\t\t\t\t\tpublishError instanceof UpdateFailed\n\t\t\t\t\t\t\t\t? \"update failed\"\n\t\t\t\t\t\t\t\t: publishError\n\t\t\t\t\t\t\t\t\t? \"internal error\"\n\t\t\t\t\t\t\t\t\t: \"track ended\",\n\t\t\t\t\t});\n\t\t\t\t\tawait done.encode(stream.writer, version);\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\t// Stream might already be closed by peer.\n\t\t\t}\n\n\t\t\t// Our close follows PUBLISH_DONE; it must not cancel data still queued for delivery.\n\t\t\tfinished = true;\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`publish error: broadcast=${name} track=${track.name} error=${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\ttrack.close();\n\t\t\t// Idempotent, and the backstop for a throw between the fork and the fill starting:\n\t\t\t// #runFill closes it itself on every path it reaches.\n\t\t\tcache?.close();\n\t\t}\n\t}\n\n\t/**\n\t * Runs a group and sends its frames using ObjectStream (Subgroup delivery mode).\n\t */\n\tasync #runGroup(options: RunGroup) {\n\t\tconst { requestId, group, timescale, publisherPriority, stamped, slice, unsubscribed, streams } = options;\n\t\ttry {\n\t\t\t// One stream per group is faster than a peer at its limit can retire them, so this\n\t\t\t// is the one path that doesn't wait for a slot: the transport would serve the opens\n\t\t\t// in the order we asked, which is oldest-first, exactly backwards for live media.\n\t\t\t// Failing here drops the group and lets the next one compete for the next slot.\n\t\t\tconst stream = await Writer.tryOpen(this.#quic, {\n\t\t\t\tcancel: unsubscribed,\n\t\t\t\tversion: this.#session.version,\n\t\t\t\twaitUntilAvailable: false,\n\t\t\t});\n\t\t\tif (!stream) {\n\t\t\t\tgroup.close(new Error(\"no stream slot\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstreams.opened += 1;\n\n\t\t\tconst header = new GroupMessage({\n\t\t\t\ttrackAlias: requestId,\n\t\t\t\tgroupId: group.sequence,\n\t\t\t\tsubGroupId: 0,\n\t\t\t\tpublisherPriority,\n\t\t\t\tflags: {\n\t\t\t\t\t// The object properties carry the timestamp, so there is nothing to write\n\t\t\t\t\t// when the track declared no units to read one in.\n\t\t\t\t\thasExtensions: stamped,\n\t\t\t\t\thasSubgroup: false,\n\t\t\t\t\thasSubgroupObject: false,\n\t\t\t\t\t// A stream capped by the range stops before the group may end, so its FIN\n\t\t\t\t\t// cannot claim END_OF_GROUP.\n\t\t\t\t\thasEnd: slice.until === undefined,\n\t\t\t\t\thasPriority: true,\n\t\t\t\t\t// Only honest when the stream really starts at the group's first object;\n\t\t\t\t\t// a trimmed head starts partway through.\n\t\t\t\t\tfirstObject: slice.skip === 0,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tawait hooks.guardGroup(group, () => header.encode(stream, this.#session.version));\n\t\t\t\t// The first written object goes on the wire as its absolute id, so a trimmed\n\t\t\t\t// head shows the true numbering rather than a silently renumbered group.\n\t\t\t\tlet first = true;\n\t\t\t\t// The next object id that could be written, which starts at the filter rather\n\t\t\t\t// than at zero. A backwards range (`startObject` above `endObject` in the same\n\t\t\t\t// group) is empty, and starting here is what lets the check below see that\n\t\t\t\t// before the read parks on an object the range already excludes.\n\t\t\t\tlet next = slice.skip;\n\n\t\t\t\tfor (;;) {\n\t\t\t\t\t// The filter ends inside this group: everything at `until` and beyond is\n\t\t\t\t\t// outside the requested range, so stop without waiting for the group's end.\n\t\t\t\t\tif (slice.until !== undefined && next >= slice.until) break;\n\n\t\t\t\t\t// Reading from the filter's start drops the objects below it: they are outside\n\t\t\t\t\t// the requested range, so skipping them is not a gap.\n\t\t\t\t\tconst read = await race([hooks.readGroupFrame(group, slice.skip), stream.closed]);\n\t\t\t\t\tif (!read) break;\n\t\t\t\t\tnext = read.sequence + 1;\n\t\t\t\t\tif (slice.until !== undefined && read.sequence >= slice.until) {\n\t\t\t\t\t\tread.complete();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst obj = new Frame({ payload: read.frame.payload, timestamp: read.frame.timestamp });\n\t\t\t\t\t\tconst delta = first ? read.sequence : 0;\n\t\t\t\t\t\tfirst = false;\n\t\t\t\t\t\tawait hooks.guardGroup(group, () =>\n\t\t\t\t\t\t\tobj.encode(stream, header.flags, timescale, this.#session.version, delta),\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tread.complete();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstream.close();\n\t\t\t} catch (err: unknown) {\n\t\t\t\tstream.reset(error(err));\n\t\t\t}\n\t\t} finally {\n\t\t\tgroup.close();\n\t\t}\n\t}\n\n\t/**\n\t * Mark the track's end with an END_OF_TRACK object on its own stream, at object 0 of the\n\t * group that will never exist.\n\t *\n\t * The last group's stream has usually finished before the track ends, so the marker cannot\n\t * ride on it. A failure only costs the subscriber the early boundary.\n\t */\n\tasync #runEndOfTrack(options: {\n\t\trequestId: bigint;\n\t\tfinal: number;\n\t\tpublisherPriority: number;\n\t\tunsubscribed: Promise<void>;\n\t\tstreams: StreamCount;\n\t}) {\n\t\tconst { requestId, final, publisherPriority, unsubscribed, streams } = options;\n\t\tconst version = this.#session.version;\n\t\tconst stream = await Writer.tryOpen(this.#quic, { cancel: unsubscribed, version }).catch(() => undefined);\n\t\tif (!stream) return;\n\t\tstreams.opened += 1;\n\n\t\ttry {\n\t\t\tconst header = new GroupMessage({\n\t\t\t\ttrackAlias: requestId,\n\t\t\t\tgroupId: final,\n\t\t\t\tsubGroupId: 0,\n\t\t\t\tpublisherPriority,\n\t\t\t\tflags: {\n\t\t\t\t\thasExtensions: false,\n\t\t\t\t\thasSubgroup: false,\n\t\t\t\t\thasSubgroupObject: false,\n\t\t\t\t\thasEnd: false,\n\t\t\t\t\thasPriority: true,\n\t\t\t\t\tfirstObject: true,\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait header.encode(stream, version);\n\t\t\tawait new Frame({ endOfTrack: true }).encode(stream, header.flags, Timescale.MILLI, version);\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tstream.reset(error(err));\n\t\t}\n\t}\n\n\t/**\n\t * Serve a draft-20 fill on its own fetch stream: the requested range, read from the\n\t * group cache, capped at the Largest Object snapshot.\n\t *\n\t * A fill is a promise once requested. An empty range opens no stream, but a range we\n\t * cannot serve still opens one and resets it right after the FETCH_HEADER, the draft's\n\t * fill-failure signal. Nothing here touches the subscription either way.\n\t */\n\tasync #runFill(options: RunFill) {\n\t\tconst { requestId, fill, cache, timescale, stamped, unsubscribed, streams } = options;\n\t\tconst version = this.#session.version;\n\n\t\t// Everything is inside the try so the cache fork is released on every path out,\n\t\t// including a transport failure while opening the stream.\n\t\tlet stream: Writer | undefined;\n\t\ttry {\n\t\t\tif (fill.kind === \"empty\") return;\n\n\t\t\tstream = await Writer.tryOpen(this.#quic, { cancel: unsubscribed, version });\n\t\t\tif (!stream) {\n\t\t\t\tconsole.debug(`fill stream failed to open: fill=${requestId}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstreams.opened += 1;\n\n\t\t\tawait stream.u53(FetchHeader.type);\n\t\t\tawait new FetchHeader({ requestId }).encode(stream, version);\n\n\t\t\tif (fill.kind !== \"group\") {\n\t\t\t\tthrow new Error(\"a fill spanning several groups is not supported\");\n\t\t\t}\n\n\t\t\tconst group = takeGroup(cache, Number(fill.sequence));\n\t\t\ttry {\n\t\t\t\tawait this.#writeFillGroup(stream, group, fill, timescale, stamped, unsubscribed);\n\t\t\t} finally {\n\t\t\t\tgroup.close();\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t\tconsole.debug(`fill complete: fill=${requestId}`);\n\t\t} catch (err: unknown) {\n\t\t\t// A fill never fails the subscription; its own stream carries the failure.\n\t\t\tconst e = error(err);\n\t\t\tconsole.debug(`fill failed, resetting its stream: fill=${requestId} error=${reason(e)}`);\n\t\t\tstream?.reset(e);\n\t\t} finally {\n\t\t\tcache.close();\n\t\t}\n\t}\n\n\t/**\n\t * Write one cached group's frames as draft-20 fetch objects.\n\t *\n\t * The cap is the Largest Object snapshot: the group may keep growing, but everything\n\t * past the snapshot belongs to the subscription, not the fill.\n\t */\n\tasync #writeFillGroup(\n\t\tstream: Writer,\n\t\tgroup: group.Consumer,\n\t\tfill: FillGroup,\n\t\ttimescale: Timescale,\n\t\tstamped: boolean,\n\t\tunsubscribed: Promise<void>,\n\t) {\n\t\tlet first = true;\n\t\tlet next = 0n;\n\n\t\t// The subscriber leaving has to end the fill too. An absolute filter ending below the\n\t\t// edge with no end object leaves `until` unset, so this reads until the group closes,\n\t\t// which a still-open past group may never do. Watching only the fetch stream would\n\t\t// then pin the group and the cache subscription behind it for the life of the track.\n\t\tlet left = false;\n\t\tconst cancelled = unsubscribed.then(() => {\n\t\t\tleft = true;\n\t\t\treturn undefined;\n\t\t});\n\n\t\tfor (;;) {\n\t\t\t// The group may keep growing, but everything at `until` and beyond belongs to the\n\t\t\t// subscription, so stop without waiting for the group's end.\n\t\t\tif (fill.until !== undefined && next >= fill.until) break;\n\n\t\t\t// Reading from the fill's start drops everything below it; see the same read in #runGroup.\n\t\t\tconst frame = await race([group.readFrameSequence({ from: Number(fill.skip) }), stream.closed, cancelled]);\n\t\t\tif (left) throw new Error(\"unsubscribed before the fill finished\");\n\t\t\tif (!frame) break;\n\t\t\tnext = BigInt(frame.sequence) + 1n;\n\t\t\tif (fill.until !== undefined && BigInt(frame.sequence) >= fill.until) break;\n\n\t\t\tconst obj = new FetchFrame({ payload: frame.payload, timestamp: stamped ? frame.timestamp : undefined });\n\t\t\tawait obj.encode(\n\t\t\t\tstream,\n\t\t\t\t{ group: Number(fill.sequence), object: frame.sequence, first },\n\t\t\t\ttimescale,\n\t\t\t\tthis.#session.version,\n\t\t\t);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\t/**\n\t * Handles an incoming SUBSCRIBE_NAMESPACE on a bidi stream.\n\t *\n\t * Draft-16+ fills the stream with every visible match, independently of unsolicited\n\t * discovery. Draft-14/15 use PUBLISH_NAMESPACE requests instead and suppress matches\n\t * already announced on the unsolicited path. Hidden visibility applies to both.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribeNamespace(msg: SubscribeNamespace, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst prefix = msg.namespace;\n\t\tconst legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;\n\n\t\t// Draft-14/15: the open PUBLISH_NAMESPACE request per advertised suffix.\n\t\tconst requests: Requests = new Map();\n\n\t\tconst ending = cancelled(stream, version);\n\t\ttry {\n\t\t\t// Send OK response\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceOk.id);\n\t\t\t\tconst ok = new SubscribeNamespaceOk({ requestId: msg.requestId });\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tconst ok = new RequestOk({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t});\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t}\n\n\t\t\t// Only legacy requests create another route; inline entries always fill the query.\n\t\t\t// Hidden namespaces still require opt-in unless the prefix names them directly.\n\t\t\tconst carries = (covered: Path.Valid) =>\n\t\t\t\t(!this.#hidden || msg.hidden || !hiddenBelow(prefix, covered)) &&\n\t\t\t\t(!legacy || this.#requiresSolicitation || (this.#hidden && hiddenBelow(Path.empty(), covered)));\n\n\t\t\t// Inline entries always land, and the receiver treats a repeated NAMESPACE as a\n\t\t\t// replacement, so repricing one is just sending it again, a new original\n\t\t\t// publisher included, as Rust does. Only a legacy PUBLISH_NAMESPACE request can\n\t\t\t// be declined.\n\t\t\tconst namespace = async (suffix: Path.Valid, snap: Advertised): Promise<Answer> => {\n\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntry.id);\n\t\t\t\tconst cluster = clusterFor(this.#advert, snap.route);\n\t\t\t\tawait new SubscribeNamespaceEntry({ suffix, cluster }).encode(stream.writer, version);\n\t\t\t\treturn \"held\";\n\t\t\t};\n\t\t\tconst target: Target = legacy\n\t\t\t\t? {\n\t\t\t\t\t\tadvertise: (suffix, snap) =>\n\t\t\t\t\t\t\tthis.#advertise(Path.join(prefix, suffix), requests, clusterFor(this.#advert, snap.route)),\n\t\t\t\t\t\tupdate: (suffix, _snap, reprice) => this.#update(Path.join(prefix, suffix), requests, reprice),\n\t\t\t\t\t\twithdraw: (suffix) => this.#withdraw(Path.join(prefix, suffix), requests),\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\tadvertise: namespace,\n\t\t\t\t\t\tupdate: namespace,\n\t\t\t\t\t\twithdraw: async (suffix) => {\n\t\t\t\t\t\t\tawait stream.writer.u53(SubscribeNamespaceEntryDone.id);\n\t\t\t\t\t\t\tawait new SubscribeNamespaceEntryDone({ suffix }).encode(stream.writer, version);\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\n\t\t\t// Keyed by suffix, as the entries name them.\n\t\t\tconst ns: Namespaces = { active: new Map(), refused: new Map(), offered: new Map() };\n\t\t\tlet retry = 0;\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling, for the same reason as\n\t\t\t\t// {@link runPublishNamespaces}: a publish landing while an advertisement\n\t\t\t\t// waits for its reply only notifies listeners already registered.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tlet dispose!: Dispose;\n\t\t\t\tconst changed = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst advertised = this.#advertised.peek();\n\t\t\t\tif (!advertised) {\n\t\t\t\t\tdispose();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst outstanding = await this.#reconcile(ns, presented(prefix, advertised, carries), target);\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, or for the peer to unsubscribe.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? race([changed, ending, retryAfter(retry).then(() => advertised)])\n\t\t\t\t\t: race([changed, ending]));\n\t\t\t\tdispose();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\n\t\t\tstream.close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.debug(`subscribe_namespace stream error: ${reason(e)}`);\n\t\t\tstream.abort(e);\n\t\t} finally {\n\t\t\t// This subscription's advertisements die with it.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Advertise every published broadcast with an unsolicited PUBLISH_NAMESPACE, until\n\t * the publisher is closed.\n\t *\n\t * The peers that never send SUBSCRIBE_NAMESPACE are exactly the ones expecting a\n\t * publisher to announce itself, so announcing is the default. A peer that would\n\t * rather ask says so in its SETUP (MoQ Solicit) and this does nothing, leaving\n\t * {@link runSubscribeNamespace} to carry the advertisements instead. Modern peers\n\t * may also discover the namespace through an inline subscription fill.\n\t *\n\t * @internal\n\t */\n\tasync runPublishNamespaces() {\n\t\tif (this.#requiresSolicitation) {\n\t\t\t// The peer asked to be told on request; runSubscribeNamespace answers it.\n\t\t\treturn;\n\t\t}\n\n\t\t// The open PUBLISH_NAMESPACE request per advertised path.\n\t\tconst requests: Requests = new Map();\n\t\tconst target: Target = {\n\t\t\tadvertise: (path, snap) => this.#advertise(path, requests, clusterFor(this.#advert, snap.route)),\n\t\t\tupdate: (path, _snap, reprice) => this.#update(path, requests, reprice),\n\t\t\twithdraw: (path) => this.#withdraw(path, requests),\n\t\t};\n\n\t\t// The origin outlives the session and its signal never ends, so this loop needs the\n\t\t// session's own ending to stop: without it a closed connection leaves the loop parked\n\t\t// on a shared origin forever, waking on someone else's publish to fail on a dead\n\t\t// transport. `runSubscribeNamespace` gets this from the stream the peer asked on; an\n\t\t// unsolicited loop has no stream of its own, so the session is what it watches.\n\t\tconst closed = this.#quic.closed.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\n\t\tlet dispose: Dispose | undefined;\n\t\ttry {\n\t\t\t// Keyed by path.\n\t\t\tconst ns: Namespaces = { active: new Map(), refused: new Map(), offered: new Map() };\n\t\t\tlet retry = 0;\n\n\t\t\tfor (;;) {\n\t\t\t\t// Subscribe BEFORE reconciling. Each advertisement below waits a round trip\n\t\t\t\t// for the peer's reply, and a publish that lands in that window notifies\n\t\t\t\t// only the listeners already registered; one created afterwards would sleep\n\t\t\t\t// through it and leave the namespace unadvertised until something unrelated\n\t\t\t\t// changed.\n\t\t\t\t// TODO Make a better helper within Signals.\n\t\t\t\tconst changed = new Promise<Advertisements | undefined>((resolve) => {\n\t\t\t\t\tdispose = this.#advertised.changed(resolve);\n\t\t\t\t});\n\n\t\t\t\tconst advertised = this.#advertised.peek();\n\t\t\t\tif (!advertised) {\n\t\t\t\t\tdispose?.();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst updated = new Map<Path.Valid, Advertised>();\n\t\t\t\tfor (const [covered, candidates] of advertised) {\n\t\t\t\t\t// Only peers that declared MoQ Hidden filter unsolicited discovery.\n\t\t\t\t\tif ((this.#hidden && hiddenBelow(Path.empty(), covered)) || candidates.length === 0) continue;\n\t\t\t\t\tupdated.set(covered, candidates[0]);\n\t\t\t\t}\n\n\t\t\t\tconst outstanding = await this.#reconcile(ns, updated, target);\n\t\t\t\tretry = outstanding ? Math.min(retry ? retry * 2 : RETRY_BASE, RETRY_MAX) : 0;\n\n\t\t\t\t// Wait for the next change, which has already fired if one landed above.\n\t\t\t\tconst next = await (retry\n\t\t\t\t\t? race([changed, closed, retryAfter(retry).then(() => advertised)])\n\t\t\t\t\t: race([changed, closed]));\n\t\t\t\tdispose?.();\n\t\t\t\tif (!next) break;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\t// Nothing restarts this loop, so whatever got us here cost the session its\n\t\t\t// discovery. Not a debug-level event.\n\t\t\tconsole.warn(`publish_namespace loop failed: ${reason(error(err))}`);\n\t\t} finally {\n\t\t\tdispose?.();\n\t\t\t// Close out every open PUBLISH_NAMESPACE request.\n\t\t\tfor (const path of [...requests.keys()]) {\n\t\t\t\tawait this.#withdraw(path, requests);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Bring the peer's view in line with `updated`, one namespace at a time, and report\n\t * whether anything it should hold is still missing and worth coming back for.\n\t *\n\t * Nothing the peer cannot see is sent, a reprice updates the namespace in place, and\n\t * anything else is withdrawn first so a republish reads as withdraw-then-advertise.\n\t * `ns` records what the peer holds rather than what we attempted: a declined\n\t * advertisement or update stays out of it, so the next turn offers it fresh instead\n\t * of believing it is already up.\n\t */\n\tasync #reconcile(ns: Namespaces, updated: Map<Path.Valid, Advertised>, target: Target): Promise<boolean> {\n\t\t// A namespace that is gone, or that a republish replaced, takes its refusal with\n\t\t// it: the peer refused a broadcast, not a path forever, so a different one at the\n\t\t// same path is offered again. The origin swaps the front in one mutation, so the\n\t\t// path never leaves `updated` and only the front says they differ. Rust gets this\n\t\t// by rebuilding the watched entry.\n\t\tfor (const key of [...ns.refused.keys()]) {\n\t\t\tconst snap = updated.get(key);\n\t\t\tif (snap === undefined || ns.offered.get(key) !== snap.identity) {\n\t\t\t\tns.refused.delete(key);\n\t\t\t\tns.offered.delete(key);\n\t\t\t}\n\t\t}\n\n\t\tconst held = new Map(ns.active);\n\t\tfor (const [key, snap] of ns.active) {\n\t\t\tif (change(this.#advert, snap, updated.get(key)) !== \"restart\") continue;\n\t\t\tawait target.withdraw(key);\n\t\t\theld.delete(key);\n\t\t}\n\n\t\tfor (const [key, snap] of updated) {\n\t\t\tconst prev = held.get(key);\n\t\t\tconst diff = change(this.#advert, prev, snap);\n\t\t\tif (diff === \"same\") continue;\n\n\t\t\tlet answer: Answer;\n\t\t\tif (prev !== undefined && diff !== \"restart\") {\n\t\t\t\tanswer = await target.update(key, snap, diff);\n\t\t\t} else {\n\t\t\t\t// A fresh offer waits for what a refusal asked for, whatever brought us back.\n\t\t\t\tif (!this.#offerable(key, ns.refused)) continue;\n\t\t\t\tanswer = await target.advertise(key, snap);\n\t\t\t}\n\t\t\t// `offered` pairs with `refused`, so a held or withdrawn path leaves nothing behind.\n\t\t\tif (answer === \"held\") {\n\t\t\t\theld.set(key, snap);\n\t\t\t\tns.refused.delete(key);\n\t\t\t\tns.offered.delete(key);\n\t\t\t} else {\n\t\t\t\theld.delete(key);\n\t\t\t\tif (answer !== \"dropped\") {\n\t\t\t\t\tns.refused.set(key, answer);\n\t\t\t\t\tns.offered.set(key, snap.identity);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tns.active = held;\n\n\t\t// Whatever we wanted up and could not get up. Stream credit freeing, a transient\n\t\t// failure clearing, or the peer starting to answer raises no signal of its own, so\n\t\t// the only way back is to ask again on a timer.\n\t\treturn [...updated].some(\n\t\t\t([key, snap]) => change(this.#advert, held.get(key), snap) !== \"same\" && this.#pending(key, ns.refused),\n\t\t);\n\t}\n\n\t/**\n\t * Whether a namespace may be offered to the peer right now.\n\t *\n\t * A peer that asked never to be offered it again means it, whatever brought us back;\n\t * one that named a minimum wait gets it, even when our own backoff comes round sooner.\n\t */\n\t#offerable(key: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\tconst entry = refused.get(key);\n\t\tif (entry === undefined) return true;\n\t\treturn entry !== \"never\" && Date.now() >= entry;\n\t}\n\n\t/**\n\t * Whether the loop should keep coming back to a namespace the peer does not hold.\n\t *\n\t * Distinct from {@link offerable}, and the difference is what arms the retry: a\n\t * namespace waiting out a minimum is not offerable yet but is still pending, and\n\t * gating the timer on offerable instead would disarm it for exactly the wait it is\n\t * supposed to be counting. Only a refusal that forbids retrying ends it.\n\t */\n\t#pending(key: Path.Valid, refused: Map<Path.Valid, Refused>): boolean {\n\t\treturn refused.get(key) !== \"never\";\n\t}\n\n\t/**\n\t * What a REQUEST_ERROR's retry interval, in milliseconds, says about re-offering the\n\t * namespace.\n\t *\n\t * Draft-14/15 carry no such field, so a 0 there says nothing and our own backoff\n\t * stands; everywhere else 0 means the peer does not want this again.\n\t */\n\t#refusal(err: RequestError): Answer {\n\t\tconst version = this.#session.version;\n\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15) return \"dropped\";\n\t\treturn err.retryInterval === 0n ? \"never\" : Date.now() + Number(err.retryInterval);\n\t}\n\n\t/**\n\t * Advertise one namespace on its own PUBLISH_NAMESPACE request. A declined request\n\t * is logged and skipped: a peer that wants none of this rejects each one and stays\n\t * connected.\n\t */\n\tasync #advertise(\n\t\tpath: Path.Valid,\n\t\trequests: Requests,\n\t\tcluster: Cluster.Advert | undefined = this.#advert,\n\t): Promise<Answer> {\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) return \"dropped\";\n\n\t\t// Opening is inside the try because it fails like any other advertisement does:\n\t\t// a peer out of stream credit rejects here, and letting that escape would unwind\n\t\t// the announce loop and take discovery down for the whole session, rather than\n\t\t// costing this one namespace a turn.\n\t\tlet request: Stream | undefined;\n\t\ttry {\n\t\t\trequest = await this.#session.openBi();\n\t\t\tconst stream = request;\n\n\t\t\t// Bounded, like the subscriber's own request: the loop is single-threaded over\n\t\t\t// advertisements, so a peer that takes the stream and answers nothing strands\n\t\t\t// every publish and withdrawal behind it. Timing out costs this namespace a\n\t\t\t// turn and leaves it outstanding, which the retry above re-offers.\n\t\t\tconst answer = await withTimeout(\n\t\t\t\t(async (): Promise<Answer> => {\n\t\t\t\t\tawait stream.writer.u53(PublishNamespace.id);\n\t\t\t\t\tconst msg = new PublishNamespace({ requestId, trackNamespace: path, cluster });\n\t\t\t\t\tawait msg.encode(stream.writer, this.#session.version);\n\n\t\t\t\t\t// Read response (RequestOk and PublishNamespaceOk share 0x07)\n\t\t\t\t\tconst respTypeId = await stream.reader.u53();\n\t\t\t\t\tif (respTypeId === RequestError.id) {\n\t\t\t\t\t\tconst err = await RequestError.decode(stream.reader, this.#session.version);\n\t\t\t\t\t\tconst why = requestReason(\n\t\t\t\t\t\t\terr.errorCode,\n\t\t\t\t\t\t\terr.reasonPhrase,\n\t\t\t\t\t\t\t\"publish_namespace\",\n\t\t\t\t\t\t\tthis.#session.version,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconsole.warn(`announce refused: broadcast=${path} error=${why}`);\n\t\t\t\t\t\tstream.abort(new Error(`PublishNamespace rejected: ${why}`));\n\t\t\t\t\t\treturn this.#refusal(err);\n\t\t\t\t\t}\n\t\t\t\t\tif (respTypeId !== RequestOk.id) {\n\t\t\t\t\t\tthrow new Error(`PublishNamespace rejected: typeId=0x${respTypeId.toString(16)}`);\n\t\t\t\t\t}\n\t\t\t\t\t// Draft-14 sends PublishNamespaceOk (requestId only, no parameters)\n\t\t\t\t\tif (this.#session.version === Version.DRAFT_14) {\n\t\t\t\t\t\tawait PublishNamespaceOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tawait RequestOk.decode(stream.reader, this.#session.version);\n\t\t\t\t\t}\n\t\t\t\t\treturn \"held\";\n\t\t\t\t})(),\n\t\t\t\tADVERTISE_TIMEOUT_MS,\n\t\t\t\t`advertisement timed out after ${ADVERTISE_TIMEOUT_MS}ms waiting for the peer's answer`,\n\t\t\t);\n\n\t\t\tif (answer === \"held\") requests.set(path, { path, requestId, stream });\n\t\t\treturn answer;\n\t\t} catch (err: unknown) {\n\t\t\t// The peer never answered the advertisement: a control timeout, not late content.\n\t\t\tconst e = err instanceof TimeoutError ? controlTimeout(err) : error(err);\n\t\t\tconsole.warn(`announce failed: broadcast=${path} error=${reason(e)}`);\n\t\t\trequest?.abort(e);\n\t\t\treturn \"dropped\";\n\t\t}\n\t}\n\n\t/**\n\t * Update a namespace the peer holds: REQUEST_UPDATE on the request that carries it,\n\t * with only the parameters that changed, then its answer.\n\t *\n\t * Waiting for the answer keeps one update outstanding per stream, which satisfies any\n\t * MAX_REQUEST_UPDATES the peer set without reading it; a change landing meanwhile waits\n\t * for the next turn. The answer decides whether the peer still holds the namespace: a\n\t * REQUEST_ERROR closes the peer's side and withdraws the advertisement, so ours is\n\t * finished too, and an unanswered update is dropped abruptly, since a peer that ignored\n\t * it cannot be assumed to hold either price. Either way the retry re-offers it fresh.\n\t *\n\t * A different original publisher is an update like any other: the receiver drains what\n\t * it already serves from the old one and never splices the two.\n\t */\n\tasync #update(path: Path.Valid, requests: Requests, { from, to }: Reprice): Promise<Answer> {\n\t\tconst request = requests.get(path);\n\t\tif (!request) return \"dropped\";\n\n\t\tconst update: Cluster.Update = {\n\t\t\thops: sameHops(from.hops, to.hops) ? undefined : to.hops,\n\t\t\tcost: from.cost === to.cost ? undefined : to.cost,\n\t\t};\n\t\tconst version = this.#session.version;\n\t\tlet answer: Answer;\n\t\ttry {\n\t\t\tconst requestId = await this.#session.nextRequestId();\n\t\t\tif (requestId === undefined) throw new Error(\"no request ID for the update\");\n\n\t\t\tanswer = await withTimeout(\n\t\t\t\t(async (): Promise<Answer> => {\n\t\t\t\t\tconst { writer, reader } = request.stream;\n\t\t\t\t\tawait writer.u53(PublishNamespaceUpdate.id);\n\t\t\t\t\tawait new PublishNamespaceUpdate({ requestId, update }).encode(writer, version);\n\n\t\t\t\t\tconst typeId = await reader.u53();\n\t\t\t\t\tif (typeId === RequestError.id) {\n\t\t\t\t\t\tconst err = await RequestError.decode(reader, version);\n\t\t\t\t\t\tconst why = requestReason(err.errorCode, err.reasonPhrase, \"publish_namespace\", version);\n\t\t\t\t\t\tconsole.warn(`publish_namespace update refused: broadcast=${path} error=${why}`);\n\t\t\t\t\t\treturn this.#refusal(err);\n\t\t\t\t\t}\n\t\t\t\t\tif (typeId !== RequestOk.id) {\n\t\t\t\t\t\tthrow new Error(`unexpected answer to the update: typeId=0x${typeId.toString(16)}`);\n\t\t\t\t\t}\n\t\t\t\t\tawait RequestOk.decode(reader, version);\n\t\t\t\t\treturn \"held\";\n\t\t\t\t})(),\n\t\t\t\tADVERTISE_TIMEOUT_MS,\n\t\t\t\t`update timed out after ${ADVERTISE_TIMEOUT_MS}ms waiting for the peer's answer`,\n\t\t\t);\n\t\t} catch (err: unknown) {\n\t\t\tconst e = err instanceof TimeoutError ? controlTimeout(err) : error(err);\n\t\t\tconsole.warn(`publish_namespace update failed: broadcast=${path} error=${reason(e)}`);\n\t\t\trequests.delete(path);\n\t\t\trequest.stream.abort(e);\n\t\t\treturn \"dropped\";\n\t\t}\n\n\t\t// The peer may already have closed out a refused request. Ending it again is the\n\t\t// withdrawal finishing, not a reason to end the loop.\n\t\tif (answer !== \"held\") await this.#withdraw(path, requests).catch(() => undefined);\n\t\treturn answer;\n\t}\n\n\t/**\n\t * End a namespace's PUBLISH_NAMESPACE request: PUBLISH_NAMESPACE_DONE then FIN before\n\t * draft-17, a cancel in both directions after. Neither waits on the peer.\n\t */\n\tasync #withdraw(path: Path.Valid, requests: Requests) {\n\t\tconst request = requests.get(path);\n\t\tif (!request) return;\n\t\trequests.delete(path);\n\n\t\t// Draft-17+ withdraws by cancelling the request in both directions; a FIN is only\n\t\t// allowed to end SUBSCRIBE_NAMESPACE and SUBSCRIBE_TRACKS.\n\t\tconst version = this.#session.version;\n\t\tif (version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16) {\n\t\t\trequest.stream.abort(new StreamError(StreamCode.Cancel, { message: \"withdrawn\" }));\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait request.stream.writer.u53(PublishNamespaceDone.id);\n\t\t\tconst done = new PublishNamespaceDone({ trackNamespace: request.path, requestId: request.requestId });\n\t\t\tawait done.encode(request.stream.writer, version);\n\t\t} catch {\n\t\t\t// Stream might already be closed\n\t\t}\n\t\trequest.stream.close();\n\t}\n\n\t/**\n\t * Handles an incoming TRACK_STATUS_REQUEST on a bidi stream.\n\t *\n\t * @internal\n\t */\n\tasync runTrackStatusRequest(msg: TrackStatusRequest, stream: Stream) {\n\t\t// TRACK_STATUS_ERROR is 0x0f on draft-14.\n\t\tawait this.#refuseUnsupported(stream, msg.requestId, \"track_status\", 0x0f, \"TRACK_STATUS is not supported\");\n\t}\n\n\t/**\n\t * Refuses an incoming SUBSCRIBE_TRACKS (draft-18+): we never send the PUBLISH it asks for.\n\t * The reply carries no Request ID, so the message body is left unread.\n\t *\n\t * @internal\n\t */\n\tasync runSubscribeTracks(stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tawait stream.writer.u53(RequestError.id);\n\t\tawait new RequestError({\n\t\t\terrorCode: toRequestCode(\"not_supported\", \"subscribe_namespace\", version),\n\t\t\treasonPhrase: \"SUBSCRIBE_TRACKS is not supported\",\n\t\t}).encode(stream.writer, version);\n\t\tstream.close();\n\t}\n\n\t/**\n\t * Handles an incoming FETCH on a bidi stream. We serve none.\n\t *\n\t * @internal\n\t */\n\tasync runFetch(msg: Fetch, stream: Stream) {\n\t\tawait this.#refuseUnsupported(stream, msg.requestId, \"fetch\", FetchError.id, \"FETCH is not supported\");\n\t}\n\n\t/**\n\t * Refuse a request NOT_SUPPORTED. Draft-14 gives each request its own error message,\n\t * `errorId14`, with the SUBSCRIBE_ERROR body; later drafts use REQUEST_ERROR.\n\t */\n\tasync #refuseUnsupported(\n\t\tstream: Stream,\n\t\trequestId: bigint,\n\t\tkind: RequestKind,\n\t\terrorId14: number,\n\t\treasonPhrase: string,\n\t) {\n\t\tconst version = this.#session.version;\n\t\tconst errorCode = toRequestCode(\"not_supported\", kind, version);\n\t\tif (version === Version.DRAFT_14) {\n\t\t\tawait stream.writer.u53(errorId14);\n\t\t\tawait new SubscribeError({ requestId, errorCode, reasonPhrase }).encode(stream.writer, version);\n\t\t} else {\n\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\tawait new RequestError({\n\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? requestId : undefined,\n\t\t\t\terrorCode,\n\t\t\t\treasonPhrase,\n\t\t\t}).encode(stream.writer, version);\n\t\t}\n\t\tstream.close();\n\t}\n}\n\n/** A `{group, object}` position, in the Location Filter's own units. */\ninterface Location {\n\t/** The group's sequence number. */\n\tgroup: bigint;\n\t/** The object's id within that group. */\n\tobject: bigint;\n}\n\n/** Where a range ends, inclusive. An absent `object` includes the whole end group. */\ninterface EndLocation {\n\t/** The last group to serve. */\n\tgroup: bigint;\n\t/** The last object within it, or the whole group when absent. */\n\tobject?: bigint;\n}\n\n/**\n * The live edge a SUBSCRIBE resolves against, snapshotted once so the subscription floor,\n * the fill cap, and the advertised LARGEST_OBJECT all agree on where it is.\n */\ninterface LiveEdge {\n\t/** The newest group sequence, absent before any group exists. */\n\tlatest?: bigint;\n\n\t/**\n\t * The precise Largest Object. Absent when the track has no readable frame, in which case\n\t * nothing is advertised and no fill is servable.\n\t */\n\tlargest?: Location;\n\n\t/**\n\t * One past the Largest Object, which is where a Next Object subscription begins. With no\n\t * readable object anywhere this falls back to the newest group's start, which excludes\n\t * nothing the cache can still name.\n\t */\n\tnext?: Location;\n}\n\n/** The Locations a SUBSCRIBE's Location Filter selects, resolved against the live edge. */\ninterface ServeRange {\n\t/** The first Location to serve, or the start of the latest group when absent. */\n\tstart?: Location;\n\n\t/**\n\t * Where the range ends, inclusive, or open ended when absent. The subscription stays open\n\t * once the range is exhausted; draft-20 removed the notion of a filter ending one.\n\t */\n\tend?: EndLocation;\n}\n\n/** The slice of one group a subscription's {@link ServeRange} selects. */\ninterface GroupSlice {\n\t/** Objects dropped from the front; also the first written object's absolute id. */\n\tskip: number;\n\n\t/** One past the last object to write, when the filter ends inside this group. */\n\tuntil?: number;\n}\n\n/** A fill resolved to a single group of the cache. */\ninterface FillGroup {\n\tkind: \"group\";\n\t/** The group to serve. */\n\tsequence: bigint;\n\t/** Objects dropped from the front. */\n\tskip: bigint;\n\t/** One past the last object to write, capping the fill at the Largest Object snapshot. */\n\tuntil?: bigint;\n}\n\n/** What a draft-20 fill request resolves to. */\ntype FillServe =\n\t/** The range is empty, so no fetch stream is opened at all. */\n\t| { kind: \"empty\" }\n\t| FillGroup\n\t/**\n\t * A range spanning several groups, which we do not serve: multi-group fetch\n\t * serialization depends on a negotiated group order we do not implement, so the stream is\n\t * reset instead, the draft's fill-failure signal.\n\t */\n\t| { kind: \"unsupported\" };\n\n/**\n * Take one group out of a cache view, without waiting.\n *\n * A fill's group is at or below the Largest Object snapshot, so it is either still in the\n * retained window or gone for good: nothing republishes an old sequence, and waiting for one\n * would park for the life of the track. Scanning past it, or running dry, is a cache miss,\n * which the caller turns into the draft's fill-failure reset.\n */\nfunction takeGroup(cache: TrackSubscriber, sequence: number): group.Consumer {\n\tfor (;;) {\n\t\tconst group = cache.tryRecvGroup();\n\t\tif (!group) throw new Error(`group not found: ${sequence}`);\n\t\tif (group.sequence === sequence) return group;\n\n\t\tgroup.close();\n\t\tif (group.sequence > sequence) throw new Error(`group not found: ${sequence}`);\n\t}\n}\n\n/** `a - b`, saturating at zero the way the draft's unsigned arithmetic does. */\nfunction saturatingSub(a: bigint, b: bigint): bigint {\n\treturn a > b ? a - b : 0n;\n}\n\n/** Snapshot the live edge of a track. */\nfunction liveEdge(track: TrackSubscriber): LiveEdge {\n\tconst latest = track.latest();\n\tif (latest === undefined) return {};\n\n\tconst largest = track.largest();\n\tif (!largest) return { latest: BigInt(latest), next: { group: BigInt(latest), object: 0n } };\n\n\tconst group = BigInt(largest.group);\n\tconst object = BigInt(largest.frame);\n\treturn { latest: BigInt(latest), largest: { group, object }, next: { group, object: object + 1n } };\n}\n\n/**\n * Resolve a SUBSCRIBE's Location Filter into the range to serve.\n *\n * Only draft-20 is honored. Earlier drafts have a Filter Type tag whose absolute forms we\n * never served, and starting to interpret them now would change what an existing peer\n * receives; draft-20 is also the first version whose relative forms can name a past group\n * without the subscriber knowing Largest Object.\n */\nfunction subscribeRange(msg: Subscribe, edge: LiveEdge, version: IetfVersion): ServeRange {\n\tif (!Filter.isDraft20(version)) {\n\t\tif (msg.filter.kind !== \"nextObject\" && msg.filter.kind !== \"unfiltered\") {\n\t\t\tconsole.warn(`filter not supported before draft-20, ignoring: ${msg.filter.kind}`);\n\t\t}\n\t\treturn {};\n\t}\n\n\treturn filterRange(msg.filter, edge);\n}\n\n/** The Locations a single Location Filter selects, resolved against the live edge. */\nfunction filterRange(filter: Filter.Filter, edge: LiveEdge): ServeRange {\n\tswitch (filter.kind) {\n\t\t// No restriction. moq-lite starts at the beginning of the latest group, which is the\n\t\t// join point it is built around; a subscription passes objects as they are published,\n\t\t// so an absent filter is not a request to replay history.\n\t\tcase \"unfiltered\":\n\t\t\treturn {};\n\t\t// `{Largest.Group, Largest.Object + 1}`. Everything below it, including the already\n\t\t// published head of the current group, is outside the requested range, so the join is\n\t\t// mid-group by construction. The draft pairs this with a fill when the subscriber\n\t\t// wants the head; see {@link Publisher.runFill}.\n\t\tcase \"nextObject\":\n\t\t\treturn { start: edge.next };\n\t\t// `{Largest.Group + 1 - groups, 0}`: 0 is the next group and 1 is the current one.\n\t\t// Counted from `Largest.Group`, which sits below the newest group while that group has\n\t\t// no objects yet; only with no largest at all does the newest group stand in for it.\n\t\tcase \"relative\": {\n\t\t\tconst base = edge.largest?.group ?? edge.latest;\n\t\t\tif (base === undefined) return {};\n\t\t\treturn { start: { group: saturatingSub(base + 1n, filter.groups), object: 0n } };\n\t\t}\n\t\tcase \"absolute\":\n\t\t\treturn {\n\t\t\t\tstart: { group: filter.startGroup, object: filter.startObject },\n\t\t\t\tend: filter.endGroup === undefined ? undefined : { group: filter.endGroup, object: filter.endObject },\n\t\t\t};\n\t}\n}\n\n/**\n * Trim a group to the filter's object bounds, so nothing outside the requested range is\n * sent. Interior groups are served whole.\n */\nfunction groupSlice(range: ServeRange, sequence: number): GroupSlice {\n\tconst at = BigInt(sequence);\n\treturn {\n\t\tskip: range.start?.group === at ? Number(range.start.object) : 0,\n\t\tuntil: range.end?.group === at && range.end.object !== undefined ? Number(range.end.object) + 1 : undefined,\n\t};\n}\n\n/**\n * Resolve a fill request using the Fetch rules: relative to Largest Object and never\n * extending beyond it. An omitted Location Filter inherits the subscription's.\n */\nfunction fillRange(fill: Filter.Fill, subscription: Filter.Filter, largest?: Location): FillServe {\n\t// A Range Filter narrows which objects pass, which we do not implement; serving the\n\t// unfiltered range instead would deliver objects the peer excluded, so refuse it.\n\tif (fill.rangeFilters) return { kind: \"unsupported\" };\n\tconst filter = fill.filter ?? subscription;\n\n\t// Nothing published (or no precise edge to cap at) means no fill is servable; an empty\n\t// range opens no stream.\n\tif (!largest) return { kind: \"empty\" };\n\n\tlet start: Location;\n\tswitch (filter.kind) {\n\t\t// A Fetch without a filter is the whole track up to Largest Object.\n\t\tcase \"unfiltered\":\n\t\t\tstart = { group: 0n, object: 0n };\n\t\t\tbreak;\n\t\t// One past the edge, which for a Fetch is always empty.\n\t\tcase \"nextObject\":\n\t\t\treturn { kind: \"empty\" };\n\t\tcase \"relative\":\n\t\t\tstart = { group: saturatingSub(largest.group + 1n, filter.groups), object: 0n };\n\t\t\tbreak;\n\t\tcase \"absolute\":\n\t\t\tstart = { group: filter.startGroup, object: filter.startObject };\n\t\t\tbreak;\n\t}\n\n\t// Cap the requested end at Largest Object.\n\tlet end: EndLocation = { group: largest.group, object: largest.object };\n\tif (filter.kind === \"absolute\" && filter.endGroup !== undefined) {\n\t\tconst below =\n\t\t\tfilter.endGroup < largest.group ||\n\t\t\t(filter.endGroup === largest.group && filter.endObject !== undefined && filter.endObject < largest.object);\n\t\tif (below) end = { group: filter.endGroup, object: filter.endObject };\n\t}\n\n\tif (\n\t\tstart.group > end.group ||\n\t\t(start.group === end.group && end.object !== undefined && end.object < start.object)\n\t) {\n\t\treturn { kind: \"empty\" };\n\t}\n\tif (start.group !== end.group) return { kind: \"unsupported\" };\n\n\treturn {\n\t\tkind: \"group\",\n\t\tsequence: start.group,\n\t\tskip: start.object,\n\t\tuntil: end.object === undefined ? undefined : end.object + 1n,\n\t};\n}\n\nclass UpdateFailed extends Error {\n\tconstructor() {\n\t\tsuper(\"subscription update failed\");\n\t}\n}\n"]}
@@ -3,7 +3,7 @@ import { race, 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 { closeError, controlTimeout, error, ProtocolViolation, reason, sessionCause } from "../error.js";
6
+ import { closeError, controlTimeout, error, ProtocolViolation, reason, StreamCode, StreamError, sessionCause, } from "../error.js";
7
7
  import * as netGroup from "../group.js";
8
8
  import { Cost, randomHop, routesEqual, stampHops, UNKNOWN_HOP } from "../hop.js";
9
9
  import { hiddenBelow, hooks, scopeCaptures, scopeHead, scopeOverlaps } from "../internal.js";
@@ -754,7 +754,14 @@ export class Subscriber {
754
754
  let held = msg.cluster;
755
755
  const done = version === Version.DRAFT_16 || legacy;
756
756
  for (;;) {
757
- if (await stream.reader.done())
757
+ // Drafts 17+ withdraw by resetting the request with CANCELLED, which ends it like a
758
+ // FIN. Any other reset is a failure.
759
+ const ended = await stream.reader.done().catch((err) => {
760
+ if (!done && err instanceof StreamError && err.code === StreamCode.Cancel)
761
+ return true;
762
+ throw err;
763
+ });
764
+ if (ended)
758
765
  break;
759
766
  const typeId = await stream.reader.u53();
760
767
  if (done && typeId === PublishNamespaceDone.id) {
@@ -1 +1 @@
1
- {"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../src/ietf/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CA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AC,CAAC;SAC7F,CAAC,CAAC;IACJ,CAAC;IAED,qFAAqF;IAC5E,KAAK;QACb,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { race, Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport * as broadcast from \"../broadcast.ts\";\nimport { BroadcastCache } from \"../consume.ts\";\nimport { closeError, controlTimeout, error, ProtocolViolation, reason, sessionCause } from \"../error.ts\";\nimport * as netGroup from \"../group.ts\";\nimport { Cost, type Route, randomHop, routesEqual, stampHops, UNKNOWN_HOP } from \"../hop.ts\";\nimport { hiddenBelow, hooks, scopeCaptures, scopeHead, scopeOverlaps } from \"../internal.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Cursor, type Reader, type Stream, UnexpectedEnd } from \"../stream.ts\";\nimport { Tail } from \"../tail.ts\";\nimport { type Timescale, Timestamp } from \"../time.ts\";\nimport type * as track from \"../track.ts\";\nimport { TimeoutError, withTimeout } from \"../util/timeout.ts\";\nimport { overrideBroadcastWire, wireOf } from \"../wire.ts\";\nimport type { Session } from \"./adapter.ts\";\nimport { DuplicateTrackAlias, RetiredTrackAlias, TrackAliases } from \"./aliases.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { requestReason, toRequestCode } from \"./error.ts\";\nimport { Frame, type Group as GroupMessage, hasFirstObjectBit } from \"./object.ts\";\nimport { fromWire, toWire } from \"./priority.ts\";\nimport { type Publish, PublishDone, PublishError, publishDoneClean } from \"./publish.ts\";\nimport {\n\ttype PublishNamespace,\n\tPublishNamespaceDone,\n\tPublishNamespaceError,\n\tPublishNamespaceOk,\n\tPublishNamespaceUpdate,\n} from \"./publish_namespace.ts\";\nimport { RequestError, RequestOk } from \"./request.ts\";\nimport { joinFilter, Subscribe, SubscribeError, SubscribeOk, Unsubscribe } from \"./subscribe.ts\";\nimport {\n\tPublishBlocked,\n\tSubscribeNamespace,\n\tSubscribeNamespaceEntry,\n\tSubscribeNamespaceEntryDone,\n\tSubscribeNamespaceLegacy,\n\tSubscribeNamespaceOk,\n\tUnsubscribeNamespace,\n} from \"./subscribe_namespace.ts\";\nimport { Version } from \"./version.ts\";\n\n// Bound on how long stream-open plus SUBSCRIBE_OK may take. Browsers cap\n// concurrent QUIC streams (Chrome ~100); past the cap openBi() silently\n// blocks. The timeout turns that into a clear error.\nconst SUBSCRIBE_OK_TIMEOUT_MS = 10_000;\n\n// A live subscription, as the track alias its data streams name resolves to.\ntype Subscription = {\n\t// The write side incoming group streams are routed into.\n\ttrack: track.Producer;\n\t// The group streams received, so the subscription can wait for the ones PUBLISH_DONE\n\t// says are still owed.\n\ttail: Tail;\n\t// The track's exclusive end, once an END_OF_TRACK declares it.\n\tend?: number;\n};\n\n// Out-parameter for #openSubscribe: lets the caller observe partial progress\n// (stream opened, trackAlias registered) so it can clean up on timeout even\n// before the setup promise settles.\ntype SubscribeSetupState = {\n\tstream?: Stream;\n\tregisteredAlias?: bigint;\n\t/**\n\t * Whether the caller has given up. Setup checks this once the stream exists so a request\n\t * opened after the timeout still unwinds: nothing else settles setup if the peer has\n\t * gone quiet, and the cleanup that fired first saw no stream to tear down.\n\t */\n\tcancelled?: boolean;\n\t/**\n\t * Whether the SUBSCRIBE reached the wire. From that moment the publisher may be serving,\n\t * even before it answers, so abandoning owes it a cancellation regardless of whether we\n\t * ever saw the SUBSCRIBE_OK.\n\t */\n\tsent?: boolean;\n\t/**\n\t * Whether the publisher answered with an error. It has torn the request down already, so\n\t * there is nothing left to cancel and naming the dead request id at it risks being read\n\t * as a protocol violation.\n\t */\n\trejected?: boolean;\n};\n\n/** A local announce reader's filter: its scope, the prefix it asked for, and its hidden opt-in. */\ntype Filter = { scope: Path.Pattern; prefix: Path.Valid; hidden: boolean };\n\n/** Whether a reader with `filter` sees an announcement at `path`. */\nfunction sees(filter: Filter, path: Path.Valid): boolean {\n\treturn scopeOverlaps(filter.scope, path) && (filter.hidden || !hiddenBelow(filter.prefix, path));\n}\n\n/**\n * Handles subscribing to broadcasts using moq-transport protocol.\n * Uses the stream-per-request pattern (real bidi streams for v17, virtual for v14-v16).\n *\n * @internal\n */\nexport class Subscriber {\n\t#session: Session;\n\t#localClose = false;\n\n\t// The transport, so a request cut off by the session's close ends with the session's\n\t// error. Optional for tests that drive a bare session.\n\t#quic?: WebTransport;\n\n\t// The Hop IDs this session declared; see {@link Cluster}. What the peer declared is what\n\t// says whether an advertisement carries a hop path, and ours is what a path looping back\n\t// to us contains.\n\t#cluster?: Cluster.Hops;\n\n\t// Publisher-chosen aliases used by incoming group streams.\n\t#aliases = new TrackAliases<Subscription>();\n\n\t// Units for each track's object Timestamps, from the TIMESCALE Track Property in\n\t// SUBSCRIBE_OK. A track missing from this map declared no timeline, so the publisher\n\t// opted out of timestamps and its frames are stamped on arrival instead.\n\t#timescales = new Map<bigint, Timescale>();\n\n\t// Dedup consumed broadcasts per path: repeat consume() calls share one subscription.\n\t#consumes = new BroadcastCache();\n\n\t// A random Hop ID of this connection's own, written as the first hop of any path that\n\t// names no publisher, so a publisher that reconnects reads as a new one.\n\t#stamp = randomHop();\n\n\t// Paths with a legacy PUBLISH_NAMESPACE request in flight, reserved synchronously.\n\t// The count below is only taken once the OK is written, and two requests that both\n\t// got past the duplicate check before either attached would both take one.\n\t#legacyRequests = new Set<Path.Valid>();\n\n\t// Every announced path, counted by how many live advertisements reference it.\n\t//\n\t// A peer may advertise one namespace twice on a session: an unsolicited\n\t// PUBLISH_NAMESPACE and an inline NAMESPACE answering our own SUBSCRIBE_NAMESPACE are\n\t// two messages about one source, which the MoQ Solicit draft requires us to tolerate.\n\t// Counting them is what keeps the second from duplicating the announce and the first\n\t// to end from retracting what the other still holds.\n\t#announced = new Map<Path.Valid, { count: number; route: Route }>();\n\n\t// Any consumers that want each new announcement, keyed by their local filter.\n\t#announcedConsumers = new Map<announce.Producer, Filter>();\n\n\t// Whether the peer understands the HIDDEN parameter (MoQ Hidden).\n\t#hidden: boolean;\n\n\t/** Marks this subscriber's deliberate local session close. @internal */\n\tclose() {\n\t\tthis.#localClose = true;\n\t}\n\n\t/**\n\t * Creates a new Subscriber instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\tsession,\n\t\tquic,\n\t\tcluster,\n\t\thidden = false,\n\t}: {\n\t\t/** The session abstraction for bidi streams and request IDs. */\n\t\tsession: Session;\n\t\t/** The transport the session runs on. */\n\t\tquic?: WebTransport;\n\t\t/** The Hop IDs the SETUP exchange settled (MoQ Cluster). */\n\t\tcluster?: Cluster.Hops;\n\t\t/** Whether the peer understands the HIDDEN parameter (MoQ Hidden). */\n\t\thidden?: boolean;\n\t}) {\n\t\tthis.#session = session;\n\t\tthis.#quic = quic;\n\t\tthis.#cluster = cluster;\n\t\tthis.#hidden = hidden;\n\t}\n\n\t/**\n\t * Whether an advertisement is ours coming back: its hop path already ran through us, so\n\t * subscribing via it would route us back to ourselves.\n\t *\n\t * A conforming peer withholds these (it knows our Hop ID), so this is the backstop that\n\t * keeps a mesh working when one member does not. A session that negotiated nothing\n\t * carries no path, and there is nothing to check.\n\t */\n\t#reflected(advert: Cluster.Advert | undefined): boolean {\n\t\treturn advert !== undefined && this.#cluster !== undefined && Cluster.loops(advert, this.#cluster.self);\n\t}\n\n\t/**\n\t * The route an advertisement carries; one without a path is free. A path that names no\n\t * publisher, or none at all, gets this connection's stamp in front of a 0.\n\t */\n\t#route(advert: Cluster.Advert | undefined): Route {\n\t\tif (advert === undefined) return { hops: [this.#stamp, UNKNOWN_HOP], cost: Cost.zero };\n\t\t// A full chain, or a stamp colliding with an entry (a 1-in-2^53 draw), keeps the\n\t\t// path as sent.\n\t\tconst hops = stampHops(advert.hops, this.#stamp) ?? [...advert.hops];\n\t\treturn { hops, cost: { warm: advert.cost, cold: advert.cost } };\n\t}\n\n\t/**\n\t * Gets an announced reader matching `scope`. Paths are relative to the session,\n\t * not the scope.\n\t *\n\t * The peer is asked with SUBSCRIBE_NAMESPACE regardless of what it declared, and an\n\t * unsolicited PUBLISH_NAMESPACE lands here too, so a peer that only tells and one\n\t * that only answers are both discovered.\n\t *\n\t * Hidden routes (a `.`-prefixed segment below the scope's head) are left out unless\n\t * `options.hidden` opts in. The opt-in rides the SUBSCRIBE_NAMESPACE when the peer\n\t * understands it (MoQ Hidden); the rule is also applied here, since an unsolicited\n\t * PUBLISH_NAMESPACE or a peer that never heard of it hides nothing.\n\t */\n\tannounced(scope: Path.Pattern = Path.Pattern.all(), options?: announce.Options): announce.Consumer {\n\t\t// The wire speaks announce interest by prefix.\n\t\tconst prefix = scopeHead(scope);\n\t\tconst filter = { scope, prefix, hidden: options?.hidden ?? false };\n\t\tconst announced = new announce.Producer();\n\t\tfor (const [active, info] of this.#announced) {\n\t\t\tif (!sees(filter, active)) continue;\n\t\t\tannounced.append({\n\t\t\t\tprefix: active,\n\t\t\t\tcaptures: scopeCaptures(scope, active),\n\t\t\t\tkind: \"announced\",\n\t\t\t\troute: info.route,\n\t\t\t});\n\t\t}\n\t\tthis.#announcedConsumers.set(announced, filter);\n\n\t\tvoid this.#runAnnounced(announced, prefix, filter.hidden && this.#hidden).finally(() => {\n\t\t\tthis.#announcedConsumers.delete(announced);\n\t\t\tannounced.close();\n\t\t});\n\n\t\treturn announced.consume();\n\t}\n\n\t/**\n\t * Record one more advertisement for a path, telling consumers only when it is the\n\t * first. A second one is the same namespace said twice, not news.\n\t */\n\t#attachAnnounce(path: Path.Valid, route: Route) {\n\t\tconst existing = this.#announced.get(path);\n\t\tif (existing) {\n\t\t\texisting.count += 1;\n\t\t\treturn;\n\t\t}\n\t\tthis.#announced.set(path, { count: 1, route });\n\n\t\tconsole.debug(`announced: broadcast=${path} active=true`);\n\t\tfor (const [consumer, filter] of this.#announcedConsumers) {\n\t\t\tif (!sees(filter, path)) continue;\n\t\t\tconst scope = filter.scope;\n\t\t\tconsumer.append({ prefix: path, captures: scopeCaptures(scope, path), kind: \"announced\", route });\n\t\t}\n\t}\n\n\t/**\n\t * Replace the stored route for a path that is already announced. A no-op when the\n\t * hops and cost did not change; otherwise consumers hear `updated` so a forwarder\n\t * can reprice without retracting.\n\t *\n\t * A new first hop is a new publisher: holders keep their broadcast to drain, but the\n\t * next consume starts fresh rather than reusing the old publisher's cached track info.\n\t */\n\t#updateAnnounce(path: Path.Valid, route: Route) {\n\t\tconst existing = this.#announced.get(path);\n\t\tif (existing === undefined || routesEqual(existing.route, route)) return;\n\t\tif (existing.route.hops[0] !== route.hops[0]) this.#consumes.evict(path);\n\t\texisting.route = route;\n\t\tconsole.debug(`announced: broadcast=${path} rerouted`);\n\t\tfor (const [consumer, filter] of this.#announcedConsumers) {\n\t\t\tif (!sees(filter, path)) continue;\n\t\t\tconst scope = filter.scope;\n\t\t\tconsumer.append({ prefix: path, captures: scopeCaptures(scope, path), kind: \"updated\", route });\n\t\t}\n\t}\n\n\t/**\n\t * Drop one advertisement for a path, retracting it only once the last one goes.\n\t */\n\t#detachAnnounce(path: Path.Valid) {\n\t\tconst existing = this.#announced.get(path);\n\t\tif (existing === undefined) return;\n\t\tif (existing.count > 1) {\n\t\t\texisting.count -= 1;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#announced.delete(path);\n\n\t\t// The path is gone, so stop sharing its broadcast: a holder outliving the publisher\n\t\t// would otherwise hand the dead generation to whoever consumes the path next.\n\t\tthis.#consumes.evict(path);\n\t\tconsole.debug(`announced: broadcast=${path} active=false`);\n\n\t\tfor (const [consumer, filter] of this.#announcedConsumers) {\n\t\t\tif (!sees(filter, path)) continue;\n\t\t\tconst scope = filter.scope;\n\t\t\ttry {\n\t\t\t\tconsumer.append({\n\t\t\t\t\tprefix: path,\n\t\t\t\t\tcaptures: scopeCaptures(scope, path),\n\t\t\t\t\tkind: \"retracted\",\n\t\t\t\t\troute: existing.route,\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\t// Consumer already closed, will be cleaned up\n\t\t\t}\n\t\t}\n\t}\n\n\tasync #runAnnounced(announced: announce.Producer, prefix: Path.Valid, hidden: boolean) {\n\t\tconst version = this.#session.version;\n\n\t\t// Suffixes live on this stream, so a repeat is recognized as an update to the\n\t\t// advertisement rather than a second one, which would leak the count.\n\t\tconst live = new Set<Path.Valid>();\n\n\t\t// Set once the teardown below has given back everything this stream held. The read\n\t\t// loop is not awaited when the local consumer closes first, and closing the stream\n\t\t// cancels the transport without discarding what the reader already buffered, so a\n\t\t// fully buffered entry can still decode afterwards. Attaching one then would take a\n\t\t// reference nobody is left to release, pinning the path for the session.\n\t\tlet released = false;\n\n\t\t// v14/v15: SubscribeNamespace on control stream (via adapter virtual stream)\n\t\t// v16+: SubscribeNamespace on its own real bidi stream\n\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) return;\n\n\t\ttry {\n\t\t\t// v16: use a real bidi stream (not virtual control stream)\n\t\t\tconst stream =\n\t\t\t\tversion === Version.DRAFT_16 && this.#session.openNativeBi\n\t\t\t\t\t? await this.#session.openNativeBi()\n\t\t\t\t\t: await this.#session.openBi();\n\n\t\t\ttry {\n\t\t\t\t// Draft-18+ uses SUBSCRIBE_NAMESPACE (0x50); earlier drafts use the\n\t\t\t\t// legacy 0x11 message with a Subscribe Options field.\n\t\t\t\tif (\n\t\t\t\t\tversion === Version.DRAFT_14 ||\n\t\t\t\t\tversion === Version.DRAFT_15 ||\n\t\t\t\t\tversion === Version.DRAFT_16 ||\n\t\t\t\t\tversion === Version.DRAFT_17\n\t\t\t\t) {\n\t\t\t\t\tawait stream.writer.u53(SubscribeNamespaceLegacy.id);\n\t\t\t\t\tawait new SubscribeNamespaceLegacy({ namespace: prefix, requestId, hidden }).encode(\n\t\t\t\t\t\tstream.writer,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tawait stream.writer.u53(SubscribeNamespace.id);\n\t\t\t\t\tawait new SubscribeNamespace({ namespace: prefix, requestId, hidden }).encode(\n\t\t\t\t\t\tstream.writer,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconsole.debug(`subscribe_namespace written: requestId=${requestId}`);\n\n\t\t\t\t// Read response\n\t\t\t\tconst respTypeId = await stream.reader.u53();\n\t\t\t\tif (respTypeId === RequestOk.id) {\n\t\t\t\t\tawait RequestOk.decode(stream.reader, version);\n\t\t\t\t} else if (respTypeId === SubscribeNamespaceOk.id) {\n\t\t\t\t\t// v14: SubscribeNamespaceOk\n\t\t\t\t\tconst size = await stream.reader.u16();\n\t\t\t\t\tawait stream.reader.read(size);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`SubscribeNamespace rejected: typeId=0x${respTypeId.toString(16)}`);\n\t\t\t\t}\n\n\t\t\t\t// Loop reading Namespace/NamespaceDone entries\n\t\t\t\tconst readLoop = (async () => {\n\t\t\t\t\tfor (;;) {\n\t\t\t\t\t\tconst done = await stream.reader.done();\n\t\t\t\t\t\tif (done) break;\n\n\t\t\t\t\t\tconst msgType = await stream.reader.u53();\n\t\t\t\t\t\tif (msgType === SubscribeNamespaceEntry.id) {\n\t\t\t\t\t\t\tconst entry = await SubscribeNamespaceEntry.decode(\n\t\t\t\t\t\t\t\tstream.reader,\n\t\t\t\t\t\t\t\tversion,\n\t\t\t\t\t\t\t\tCluster.negotiated(this.#cluster),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (released) break;\n\t\t\t\t\t\t\tconst path = Path.join(prefix, entry.suffix);\n\n\t\t\t\t\t\t\t// A repeat updates the advertisement in place, so one that now\n\t\t\t\t\t\t\t// loops back through us has taken a route we can't subscribe\n\t\t\t\t\t\t\t// over: the path is gone even though the message says active.\n\t\t\t\t\t\t\tif (this.#reflected(entry.cluster)) {\n\t\t\t\t\t\t\t\tconsole.debug(`dropping reflected namespace: broadcast=${path}`);\n\t\t\t\t\t\t\t\tif (live.delete(path)) this.#detachAnnounce(path);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// A repeat replaces the advertisement in place: HOP_PATH / ROUTE_COST\n\t\t\t\t\t\t\t// can change without a NAMESPACE_DONE. Only the first is a new path.\n\t\t\t\t\t\t\tconst route = this.#route(entry.cluster);\n\t\t\t\t\t\t\tif (live.has(path)) {\n\t\t\t\t\t\t\t\tthis.#updateAnnounce(path, route);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tlive.add(path);\n\t\t\t\t\t\t\t\tthis.#attachAnnounce(path, route);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (msgType === SubscribeNamespaceEntryDone.id) {\n\t\t\t\t\t\t\tconst entry = await SubscribeNamespaceEntryDone.decode(stream.reader, version);\n\t\t\t\t\t\t\tif (released) break;\n\t\t\t\t\t\t\tconst path = Path.join(prefix, entry.suffix);\n\n\t\t\t\t\t\t\tif (live.delete(path)) {\n\t\t\t\t\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (msgType === PublishBlocked.id && version === Version.DRAFT_17) {\n\t\t\t\t\t\t\tconst blocked = await PublishBlocked.decode(stream.reader, version);\n\t\t\t\t\t\t\tconsole.debug(`publish_blocked: suffix=${blocked.suffix} track=${blocked.trackName}`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`unexpected message on subscribe_namespace stream: 0x${msgType.toString(16)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})();\n\n\t\t\t\t// The race below can end through the consumer's close while a message that\n\t\t\t\t// already arrived is still decoding, which leaves the loop with nothing\n\t\t\t\t// awaiting it: a violation decoded after that would land nowhere, and its\n\t\t\t\t// rejection would go unhandled. Idempotent with the catch below, which is\n\t\t\t\t// what runs when the loop is the one that ends the race.\n\t\t\t\treadLoop.catch((err: unknown) => {\n\t\t\t\t\tif (err instanceof ProtocolViolation) this.#session.close();\n\t\t\t\t});\n\n\t\t\t\t// Wait for either the read loop or the announced to close\n\t\t\t\tawait race([readLoop, announced.closed]);\n\n\t\t\t\t// For v14/v15: send UnsubscribeNamespace before closing\n\t\t\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait stream.writer.u53(UnsubscribeNamespace.id);\n\t\t\t\t\t\tconst unsub = new UnsubscribeNamespace({ requestId });\n\t\t\t\t\t\tawait unsub.encode(stream.writer, version);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Stream might already be closed\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstream.close();\n\t\t\t} catch (err) {\n\t\t\t\tstream.abort(error(err));\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`subscribe_namespace error: ${reason(e)}`);\n\n\t\t\t// An advertisement is decoded here rather than in the session dispatch, so this\n\t\t\t// is the only place a malformed one surfaces. The cluster draft requires closing\n\t\t\t// the session over those, and the stream alone is not enough: the peer would\n\t\t\t// just repeat it on the next SUBSCRIBE_NAMESPACE.\n\t\t\tif (e instanceof ProtocolViolation) this.#session.close();\n\n\t\t\t// Abort the stream rather than letting the caller's `finally` close it cleanly.\n\t\t\t// A rejected namespace subscription is a failure, and a consumer that can't tell\n\t\t\t// it from \"nothing is published under this prefix\" waits forever on a broadcast\n\t\t\t// that will never be announced. Matches the lite subscriber.\n\t\t\tannounced.close(e);\n\t\t} finally {\n\t\t\t// The stream owns every advertisement it carried, so release them however it\n\t\t\t// ends: a clean close, a decode error, or the peer resetting it. Without this\n\t\t\t// each namespace keeps its count and the source never detaches, which would\n\t\t\t// pin the path for the session even after the other source withdrew.\n\t\t\treleased = true;\n\t\t\tfor (const path of live) {\n\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t}\n\t\t\tlive.clear();\n\t\t}\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * Deduplicated per path: repeat calls for the same still-live path share one reference-counted\n\t * broadcast (and one upstream subscription). The shared broadcast closes once every caller has\n\t * closed its handle, so callers close normally.\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#consumes.get(path) ?? this.#consumes.insert(path, this.#createConsume(path));\n\t}\n\n\t#createConsume(path: Path.Valid): broadcast.Consumer {\n\t\t// moq-transport has no one-shot group fetch; ConsumeBroadcast rejects it. Track info\n\t\t// is resolved by the subscribe path (the inherited resolveTrackInfo).\n\t\tconst consumer = new ConsumeBroadcast();\n\n\t\tvoid (async () => {\n\t\t\tfor (;;) {\n\t\t\t\tconst request = await wireOf(consumer).requested();\n\t\t\t\tif (!request) break;\n\t\t\t\tvoid this.#runSubscribe(path, request);\n\t\t\t}\n\t\t})();\n\n\t\treturn consumer;\n\t}\n\n\t// The adapter is gone. If the transport has already closed, that close is the\n\t// error. A still-open transport, such as a GOAWAY drain, has no peer code yet,\n\t// so this does not wait for it.\n\tasync #closedSession(): Promise<Error> {\n\t\tconst quic = this.#quic;\n\t\tif (!quic) return new Error(\"session closed\");\n\t\treturn Promise.race([\n\t\t\tcloseError(quic),\n\t\t\tnew Promise<Error>((resolve) => queueMicrotask(() => resolve(new Error(\"session closed\")))),\n\t\t]);\n\t}\n\n\tasync #runSubscribe(broadcast: Path.Valid, request: track.Request) {\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) {\n\t\t\trequest.reject(await this.#closedSession());\n\t\t\treturn;\n\t\t}\n\n\t\tconsole.debug(`subscribe start: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\n\t\t// Keep the request pending until SUBSCRIBE_OK supplies immutable track metadata.\n\t\t// Group streams already wait on the alias, so early data stays behind this response.\n\t\tconst producer = hooks.pendingTrackProducer(request);\n\t\tconst subscription: Subscription = { track: producer, tail: new Tail() };\n\n\t\t// Open the stream and wait for SUBSCRIBE_OK under a timeout. State\n\t\t// flows back via `state` so the timeout path can clean up the stream\n\t\t// and any registration if setup eventually finishes.\n\t\tconst state: SubscribeSetupState = {};\n\t\tconst setup = this.#openSubscribe(state, broadcast, request, subscription, requestId);\n\n\t\t// The publisher can be serving before it answers, so waiting only on the response\n\t\t// would miss the local side going away and leave it serving a track nobody reads.\n\t\t// Demand returning before we commit is not abandonment, matching the serving loop.\n\t\tconst waitAbandoned = async (): Promise<null> => {\n\t\t\t// An info-only lookup attaches no subscriber yet still waits on SUBSCRIBE_OK for\n\t\t\t// the track info, so only demand that arrived and then left is abandonment.\n\t\t\twhile (!producer.used.peek() && producer.closed.peek() === undefined) {\n\t\t\t\tawait Signal.race(producer.used, producer.closed);\n\t\t\t}\n\t\t\tfor (;;) {\n\t\t\t\tawait producer.unused();\n\t\t\t\tif (producer.closed.peek() !== undefined || !producer.used.peek()) return null;\n\t\t\t}\n\t\t};\n\n\t\tlet stream: Stream;\n\t\tlet trackAlias: bigint;\n\t\ttry {\n\t\t\tconst result = await race([\n\t\t\t\twithTimeout(\n\t\t\t\t\tsetup,\n\t\t\t\t\tSUBSCRIBE_OK_TIMEOUT_MS,\n\t\t\t\t\t`subscribe timed out after ${SUBSCRIBE_OK_TIMEOUT_MS}ms waiting for SUBSCRIBE_OK (browser stream limit reached?)`,\n\t\t\t\t),\n\t\t\t\twaitAbandoned(),\n\t\t\t]);\n\n\t\t\tif (result === null) throw new Error(\"subscribe abandoned before it was accepted\");\n\n\t\t\tstream = result.stream;\n\t\t\ttrackAlias = result.alias;\n\t\t\tconsole.debug(`subscribe ok: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\t// A control request that timed out is not late content, so it carries its own code.\n\t\t\tconst e = err instanceof TimeoutError ? controlTimeout(err) : await sessionCause(this.#quic, err);\n\t\t\trequest.reject(e);\n\t\t\tconsole.warn(\n\t\t\t\t`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`,\n\t\t\t);\n\t\t\t// Runs now for whatever is already open, and again if `setup` settles late.\n\t\t\t// Retirement is repeated because a late SUBSCRIBE_OK can register an alias after\n\t\t\t// the first pass; the stream is torn down once.\n\t\t\tlet torn = false;\n\t\t\tconst cleanup = async (afterSetup: boolean) => {\n\t\t\t\tstate.cancelled = true;\n\n\t\t\t\tif (state.registeredAlias !== undefined && this.#aliases.retire(state.registeredAlias, subscription)) {\n\t\t\t\t\tthis.#timescales.delete(state.registeredAlias);\n\t\t\t\t}\n\n\t\t\t\tif (!state.stream || torn) return;\n\n\t\t\t\t// A SUBSCRIBE still being written must not be torn down from here. Aborting a\n\t\t\t\t// Web Stream waits for the in-flight write, so the request can still reach the\n\t\t\t\t// peer while the abort destroys the stream we would have cancelled on. Setup\n\t\t\t\t// unwinds on the cancelled flag once that write lands, and its pass below has\n\t\t\t\t// the finished picture.\n\t\t\t\tif (!state.sent && !afterSetup) return;\n\t\t\t\ttorn = true;\n\n\t\t\t\t// Once the SUBSCRIBE is out the publisher may be serving, whether or not it has\n\t\t\t\t// answered yet: data streams are independent of the request stream. Aborting says\n\t\t\t\t// nothing on v14-16, where the request rides a virtual stream whose reset is\n\t\t\t\t// local, so the UNSUBSCRIBE has to go out explicitly.\n\t\t\t\tif (state.sent && !state.rejected) await this.#cancelSubscribe(state.stream, requestId);\n\t\t\t\tstate.stream.abort(e);\n\t\t\t};\n\n\t\t\t// Tear down what is already open rather than waiting on `setup`. A peer that\n\t\t\t// opened the stream and then went quiet never settles it, and deferring would\n\t\t\t// leave the request outstanding for the life of the session -- which is the\n\t\t\t// timeout case, not a rare one.\n\t\t\tvoid cleanup(false);\n\t\t\tsetup.then(\n\t\t\t\t() => cleanup(true),\n\t\t\t\t() => cleanup(true),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Which terminal fired decides whether we owe the publisher a cancellation, so\n\t\t\t// tag them rather than racing bare promises.\n\t\t\tconst publisherEnded = Symbol(\"publisher\");\n\t\t\tconst localEnded = Symbol(\"local\");\n\t\t\tconst idle = Symbol(\"idle\");\n\n\t\t\t// Terminal conditions settle at most once (PublishDone, track close = local\n\t\t\t// unsubscribe); race them once so the demand loop doesn't re-subscribe each pass.\n\t\t\tconst done = race([\n\t\t\t\tthis.#runPublishDone(stream, subscription).then(() => publisherEnded),\n\t\t\t\tproducer.closed.then(() => localEnded),\n\t\t\t]);\n\n\t\t\t// Serve until a terminal condition fires or the last local subscriber leaves. The unused\n\t\t\t// wake is level-triggered: re-check demand so a subscriber that returns before we tear\n\t\t\t// down resumes on the same stream.\n\t\t\tlet terminal = localEnded;\n\t\t\tfor (;;) {\n\t\t\t\tconst reason = await race([done, producer.unused().then(() => idle)]);\n\t\t\t\tif (reason === idle && producer.closed.peek() === undefined && producer.used.peek()) continue;\n\t\t\t\tterminal = reason;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Close before the cancellation is written, not after: awaiting the write first\n\t\t\t// reopens the window the demand re-check above just closed, and a subscriber that\n\t\t\t// returned during it would be closed by this line. The lite subscriber closes\n\t\t\t// straight out of its loop for the same reason.\n\t\t\tproducer.close();\n\n\t\t\t// The publisher already ended the request, so there is nothing to cancel. Sending\n\t\t\t// UNSUBSCRIBE here would name a request it has already torn down.\n\t\t\tif (terminal !== publisherEnded) await this.#cancelSubscribe(stream, requestId);\n\n\t\t\tstream.close();\n\t\t\tconsole.debug(`subscribe close: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = await sessionCause(this.#quic, err);\n\t\t\tproducer.close(this.#localClose ? undefined : e);\n\t\t\tstream.abort(e);\n\t\t\tconsole.warn(\n\t\t\t\t`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`,\n\t\t\t);\n\t\t} finally {\n\t\t\t// Only the owner tears down the alias metadata: a later subscription may have\n\t\t\t// reclaimed the alias and installed its own timescale.\n\t\t\tif (this.#aliases.retire(trackAlias, subscription)) this.#timescales.delete(trackAlias);\n\t\t}\n\t}\n\n\t/**\n\t * Read the PUBLISH_DONE that ends a subscription, then wait for the data streams it counts.\n\t *\n\t * An error status aborts the track with it. A clean one leaves streams in flight, since\n\t * QUIC does not order them, so wait until the Stream Count many have been read, or a\n\t * bounded grace for the ones that never arrive (the draft says to use a timeout). The count\n\t * is only a hint: a peer may send 0 regardless, so 0 waits out the grace. A request\n\t * stream that FINs without PUBLISH_DONE is a protocol violation.\n\t */\n\tasync #runPublishDone(stream: Stream, subscription: Subscription): Promise<void> {\n\t\tconst version = this.#session.version;\n\t\tif (await stream.reader.done()) throw new ProtocolViolation(\"subscribe stream ended without PUBLISH_DONE\");\n\t\tconst typeId = await stream.reader.u53();\n\t\tif (typeId !== PublishDone.id) {\n\t\t\tthrow new ProtocolViolation(`unexpected message on a subscription: 0x${typeId.toString(16)}`);\n\t\t}\n\t\tconst done = await PublishDone.decode(stream.reader, version);\n\t\tif (!publishDoneClean(done.statusCode, version)) {\n\t\t\tthrow new Error(`publish done: status=0x${done.statusCode.toString(16)} reason=${done.reasonPhrase}`);\n\t\t}\n\t\tconst count = done.streamCount;\n\n\t\tconst { tail, track } = subscription;\n\t\tconst complete = () => count > 0n && BigInt(tail.streams) >= count;\n\t\tawait tail.settle(complete, track.closed);\n\t}\n\n\t/**\n\t * Tell the publisher to stop serving a subscription we are walking away from.\n\t *\n\t * v14-16 cancel with UNSUBSCRIBE (draft-16 section 9.12), which is what lets the\n\t * publisher destroy the subscription (section 5.1.1); v17+ removed the message and\n\t * rely on the stream reset instead. Every path that abandons an Established\n\t * subscription goes through here, because those versions carry the request over a\n\t * virtual stream whose reset never reaches the peer.\n\t */\n\tasync #cancelSubscribe(stream: Stream, requestId: bigint) {\n\t\tconst version = this.#session.version;\n\t\tif (version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16) return;\n\n\t\ttry {\n\t\t\tawait stream.writer.u53(Unsubscribe.id);\n\t\t\tawait new Unsubscribe({ requestId }).encode(stream.writer, version);\n\t\t} catch {\n\t\t\t// The stream may already be gone; there is nothing further to tell the peer.\n\t\t}\n\t}\n\n\t// Opens the subscribe stream, sends SUBSCRIBE, and reads the response.\n\t// `state` is populated as soon as the stream opens and again when the\n\t// trackAlias is registered, so the caller can clean both up on timeout\n\t// even before this promise settles.\n\tasync #openSubscribe(\n\t\tstate: SubscribeSetupState,\n\t\tbroadcast: Path.Valid,\n\t\trequest: track.Request,\n\t\tsubscription: Subscription,\n\t\trequestId: bigint,\n\t): Promise<{ stream: Stream; alias: bigint }> {\n\t\tconst version = this.#session.version;\n\n\t\tstate.stream = await this.#session.openBi();\n\n\t\t// The timeout can fire while the open is still in flight, in which case cleanup ran\n\t\t// with nothing to release. Bail now that the stream is recorded, so settling this\n\t\t// promise hands it back to be torn down.\n\t\tif (state.cancelled) throw new Error(\"subscribe cancelled before it was sent\");\n\n\t\tawait state.stream.writer.u53(Subscribe.id);\n\t\tconst msg = new Subscribe({\n\t\t\trequestId,\n\t\t\ttrackNamespace: broadcast,\n\t\t\ttrackName: request.name,\n\t\t\tsubscriberPriority: toWire(request.priority),\n\t\t\t// No fill is requested: the fill's fetch stream and the live subscription split\n\t\t\t// the group across two streams, and this subscriber does not reassemble them into\n\t\t\t// one group yet. A lenient publisher (like ours) replays the whole in-range group\n\t\t\t// on the subscription instead; a strict one only delivers from the next published\n\t\t\t// object, and that mid-group stream is dropped, degrading the join to the next\n\t\t\t// group boundary.\n\t\t\tfilter: joinFilter(version),\n\t\t});\n\t\tawait msg.encode(state.stream.writer, version);\n\t\tstate.sent = true;\n\n\t\t// The caller may have given up while that write was in flight. It deliberately left\n\t\t// the stream alone, so unwind here and let its cleanup send the cancellation now that\n\t\t// the SUBSCRIBE has actually reached the peer.\n\t\tif (state.cancelled) throw new Error(\"subscribe cancelled while it was being sent\");\n\t\tconsole.debug(`subscribe written: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\n\t\tconst respTypeId = await state.stream.reader.u53();\n\t\tif (respTypeId !== SubscribeOk.id) {\n\t\t\tlet reasonPhrase = \"unknown error\";\n\t\t\ttry {\n\t\t\t\tif (respTypeId === RequestError.id) {\n\t\t\t\t\tconst err =\n\t\t\t\t\t\tversion === Version.DRAFT_14\n\t\t\t\t\t\t\t? await SubscribeError.decode(state.stream.reader, version)\n\t\t\t\t\t\t\t: await RequestError.decode(state.stream.reader, version);\n\t\t\t\t\treasonPhrase = requestReason(err.errorCode, err.reasonPhrase, \"subscribe\", version);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Decoding error response failed, use default message\n\t\t\t}\n\t\t\tstate.rejected = true;\n\t\t\tthrow new Error(`SUBSCRIBE error: ${reasonPhrase}`);\n\t\t}\n\n\t\tconst ok = await SubscribeOk.decode(state.stream.reader, version);\n\t\tif (state.cancelled) throw new Error(\"subscribe cancelled before acceptance\");\n\t\trequest.accept({ priority: fromWire(ok.properties.priority ?? 128) });\n\n\t\ttry {\n\t\t\tthis.#aliases.set(ok.trackAlias, subscription, { broadcast, name: request.name });\n\t\t\tconst timescale = ok.properties.timescale;\n\t\t\tif (timescale !== undefined) {\n\t\t\t\tthis.#timescales.set(ok.trackAlias, timescale);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\t// Only one alias naming two different tracks is the session's problem. A publisher\n\t\t\t// sharing an alias between subscriptions to one track is allowed to do that, and\n\t\t\t// disconnecting over it would drop every other broadcast on the session.\n\t\t\tif (err instanceof DuplicateTrackAlias) this.#session.close();\n\t\t\tthrow err;\n\t\t}\n\t\tstate.registeredAlias = ok.trackAlias;\n\t\treturn { stream: state.stream, alias: ok.trackAlias };\n\t}\n\n\t/**\n\t * Handles an incoming PUBLISH_NAMESPACE on a bidi stream.\n\t * Tracks announced broadcasts and notifies consumers.\n\t *\n\t * @internal\n\t */\n\tasync runPublishNamespace(msg: PublishNamespace, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst path = msg.trackNamespace;\n\n\t\t// A path that already ran through us looped back. Refuse it rather than holding an\n\t\t// advertisement we could never subscribe through. The peer knows our Hop ID, so a\n\t\t// conforming one never offers it; 0 as the retry interval says not to come back.\n\t\tif (this.#reflected(msg.cluster)) {\n\t\t\tconsole.debug(`dropping reflected publish_namespace: broadcast=${path}`);\n\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\tawait new RequestError({\n\t\t\t\trequestId: msg.requestId,\n\t\t\t\terrorCode: toRequestCode(\"uninterested\", \"publish_namespace\", version),\n\t\t\t\treasonPhrase: \"route loops back\",\n\t\t\t}).encode(stream.writer, version);\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\t// Draft-14/15 key their namespace-scoped messages by name, not request ID, so the\n\t\t// adapter can hold only one request per namespace: a second would overwrite the\n\t\t// first, and the withdrawals would then close the wrong stream and fail to find\n\t\t// the other. Nothing is lost by refusing it, because the case that makes a second\n\t\t// reference legitimate (an inline NAMESPACE for a path a PUBLISH_NAMESPACE already\n\t\t// carried) needs a message those drafts do not have.\n\t\tconst legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;\n\t\tif (legacy && (this.#announced.has(path) || this.#legacyRequests.has(path))) {\n\t\t\tconsole.warn(\"duplicate PublishNamespace\");\n\t\t\t// No draft registers a code for a duplicate, and this refusal is a draft-14/15\n\t\t\t// implementation limit, which is what INTERNAL_ERROR describes.\n\t\t\tconst errorCode = toRequestCode(\"internal\", \"publish_namespace\", version);\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(PublishNamespaceError.id);\n\t\t\t\tawait new PublishNamespaceError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode,\n\t\t\t\t\treasonPhrase: \"duplicate namespace\",\n\t\t\t\t}).encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\tawait new RequestError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode,\n\t\t\t\t\treasonPhrase: \"duplicate namespace\",\n\t\t\t\t}).encode(stream.writer, version);\n\t\t\t}\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\t// Everywhere else a path this session already knows is not refused: the same\n\t\t// namespace can reach us twice, and the count is what tells the second apart from\n\t\t// news. This request owns exactly one of those references and gives it back when\n\t\t// the stream ends.\n\t\tif (legacy) this.#legacyRequests.add(path);\n\t\tlet attached = false;\n\n\t\ttry {\n\t\t\t// Send OK first. This must complete before notifying consumers,\n\t\t\t// because consumers may trigger Subscribe writes that would\n\t\t\t// interleave with our OK on the control stream.\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(PublishNamespaceOk.id);\n\t\t\t\tconst ok = new PublishNamespaceOk({ requestId: msg.requestId });\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tconst ok = new RequestOk({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t});\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t}\n\n\t\t\t// Only now is the advertisement ours to announce, for the reason above: a\n\t\t\t// consumer reacting with a SUBSCRIBE must not interleave with that OK.\n\t\t\tattached = true;\n\t\t\tthis.#attachAnnounce(path, this.#route(msg.cluster));\n\n\t\t\t// An advertisement is updated in place with REQUEST_UPDATE on the stream that\n\t\t\t// already carries it, so read until the stream ends rather than waiting on the\n\t\t\t// close. Nothing else would deliver a re-parented route. What the peer holds\n\t\t\t// is kept current, since an update carries only what changed.\n\t\t\tlet held = msg.cluster;\n\t\t\tconst done = version === Version.DRAFT_16 || legacy;\n\t\t\tfor (;;) {\n\t\t\t\tif (await stream.reader.done()) break;\n\n\t\t\t\tconst typeId = await stream.reader.u53();\n\t\t\t\tif (done && typeId === PublishNamespaceDone.id) {\n\t\t\t\t\tawait PublishNamespaceDone.decode(stream.reader, version);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// A repeated PUBLISH_NAMESPACE lands here too: a second request on the\n\t\t\t\t// stream is the base draft's duplicate request ID.\n\t\t\t\tif (typeId !== PublishNamespaceUpdate.id) {\n\t\t\t\t\tthrow new ProtocolViolation(\n\t\t\t\t\t\t`unexpected message on publish_namespace stream: 0x${typeId.toString(16)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst update = await PublishNamespaceUpdate.decode(stream.reader, version);\n\n\t\t\t\t// The parameters exist only on a session that negotiated the extension;\n\t\t\t\t// anywhere else they are the peer's violation.\n\t\t\t\tif (held === undefined) {\n\t\t\t\t\tif (update.update.hops !== undefined || update.update.cost !== undefined) {\n\t\t\t\t\t\tthrow new ProtocolViolation(\"cluster parameters on a session that negotiated none\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// A different original publisher applies in place too, as it does inline.\n\t\t\t\t\theld = Cluster.apply(held, update.update);\n\t\t\t\t}\n\n\t\t\t\t// A path that now runs through us is unusable, so give it back. The update\n\t\t\t\t// itself is accepted, and reading continues: this stream is the\n\t\t\t\t// advertisement's only channel, so a later clean path arrives here or\n\t\t\t\t// nowhere.\n\t\t\t\tif (this.#reflected(held)) {\n\t\t\t\t\tif (attached) {\n\t\t\t\t\t\tattached = false;\n\t\t\t\t\t\tconsole.debug(`publish_namespace now loops back, detaching: broadcast=${path}`);\n\t\t\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t\t\t}\n\t\t\t\t} else if (!attached) {\n\t\t\t\t\t// Re-attach: a clean path replaced the reflected one we detached from.\n\t\t\t\t\tattached = true;\n\t\t\t\t\tthis.#attachAnnounce(path, this.#route(held));\n\t\t\t\t} else {\n\t\t\t\t\tthis.#updateAnnounce(path, this.#route(held));\n\t\t\t\t}\n\n\t\t\t\t// Nothing here can fail to apply, so every update is acknowledged. A leaf\n\t\t\t\t// routes nothing, so a repricing changes nothing it holds; consumers still\n\t\t\t\t// hear the new route so a forwarder can reprice.\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tawait new RequestOk({}).encode(stream.writer, version);\n\t\t\t}\n\t\t} finally {\n\t\t\tif (legacy) this.#legacyRequests.delete(path);\n\n\t\t\t// Give back exactly what was taken: a request that never got its OK out never\n\t\t\t// referenced the path, and retracting there would drop someone else's count.\n\t\t\tif (attached) {\n\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handles an incoming PUBLISH on a bidi stream.\n\t * We don't support reverse publish, so send error.\n\t *\n\t * @internal\n\t */\n\tasync runPublish(msg: Publish, stream: Stream) {\n\t\tconst version = this.#session.version;\n\n\t\t// We decline the method itself rather than this particular track, which would be\n\t\t// UNINTERESTED.\n\t\t//\n\t\t// The alias the message carries is deliberately not recorded. Nothing will ever bind\n\t\t// it, and a rejected request has no lifetime of ours to hang the cleanup on.\n\t\tconst errorCode = toRequestCode(\"not_supported\", \"publish\", version);\n\n\t\tif (version === Version.DRAFT_14) {\n\t\t\tawait stream.writer.u53(PublishError.id);\n\t\t\tconst err = new PublishError({\n\t\t\t\trequestId: msg.requestId,\n\t\t\t\terrorCode,\n\t\t\t\treasonPhrase: \"publish not supported\",\n\t\t\t});\n\t\t\tawait err.encode(stream.writer, version);\n\t\t} else {\n\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\tconst err = new RequestError({\n\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\terrorCode,\n\t\t\t\treasonPhrase: \"publish not supported\",\n\t\t\t});\n\t\t\tawait err.encode(stream.writer, version);\n\t\t}\n\t\tstream.close();\n\t}\n\n\t/**\n\t * Handles an ObjectStream message (group + frames on uni stream).\n\t *\n\t * @internal\n\t */\n\tasync handleGroup(group: GroupMessage, stream: Reader) {\n\t\tif (group.subGroupId !== 0) {\n\t\t\tthrow new Error(\"subgroups are not supported\");\n\t\t}\n\n\t\tlet subscription: Subscription;\n\t\ttry {\n\t\t\t// The control message establishing this alias can arrive after the data stream.\n\t\t\tsubscription = await this.#aliases.get(group.trackAlias);\n\t\t} catch (err: unknown) {\n\t\t\tconst e = await sessionCause(this.#quic, err);\n\t\t\t// Ours: we cancelled the subscription and the publisher has not stopped yet.\n\t\t\t// Anything else on this alias is the publisher sending data for a track it never\n\t\t\t// acknowledged, which is worth seeing.\n\t\t\tif (e instanceof RetiredTrackAlias) {\n\t\t\t\tconsole.debug(`dropping group for a cancelled subscription: alias=${group.trackAlias}`);\n\t\t\t}\n\t\t\tstream.stop(e);\n\t\t\treturn;\n\t\t}\n\n\t\tconst { track, tail } = subscription;\n\t\t// Every data stream counts toward PUBLISH_DONE's Stream Count, even one dropped below.\n\t\tconst read = tail.open(group.groupId);\n\n\t\t// Created on the first object rather than the header: an END_OF_TRACK at object 0\n\t\t// means the group does not exist at all.\n\t\tlet producer: netGroup.Producer | undefined;\n\t\tconst open = () => {\n\t\t\tif (!producer) {\n\t\t\t\t// The publisher contradicted its own end, which no later group can repair.\n\t\t\t\tif (subscription.end !== undefined && group.groupId >= subscription.end) {\n\t\t\t\t\tthrow new ProtocolViolation(\n\t\t\t\t\t\t`group ${group.groupId} is at or past the declared end ${subscription.end}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tproducer = new netGroup.Producer(group.groupId);\n\t\t\t\ttrack.writeGroup(producer);\n\t\t\t}\n\t\t\treturn producer;\n\t\t};\n\n\t\ttry {\n\t\t\t// FIRST_OBJECT clear is the publisher's claim that the stream starts partway\n\t\t\t// through the group. The first Object ID is absolute either way, and IDs start\n\t\t\t// at 0, so a clear bit on object 0 is still the whole group. Any other first ID,\n\t\t\t// or a stream with no object, has a hole at the front: drop it and pick up at\n\t\t\t// the next group.\n\t\t\t//\n\t\t\t// Drafts before the bit cannot say this in the header, so the first ID is the only\n\t\t\t// signal: a non-zero one is the same hole and is dropped the same way, but an empty\n\t\t\t// stream there is still a group. A later gap, or a header that claimed the group\n\t\t\t// starts at object 0, still fails it: `Frame.decode` refuses every non-zero delta.\n\t\t\tconst legacy = !hasFirstObjectBit(this.#session.version);\n\t\t\tif (!group.flags.firstObject || legacy) {\n\t\t\t\tlet id: bigint | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tid = await stream.peekU62();\n\t\t\t\t} catch (err: unknown) {\n\t\t\t\t\tif (!(err instanceof UnexpectedEnd)) throw err;\n\t\t\t\t}\n\t\t\t\tif (id !== 0n && !(legacy && id === undefined)) {\n\t\t\t\t\tconsole.debug(`dropping a group with no head: alias=${group.trackAlias} group=${group.groupId}`);\n\t\t\t\t\tstream.stop(new Error(\"a group must start at object 0\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The alias binds after SUBSCRIBE_OK commits the track property; an omitted\n\t\t\t// header priority inherits it (draft-21 section 10.4).\n\t\t\tif (!group.flags.hasPriority) group.publisherPriority = toWire((await track.info()).priority);\n\n\t\t\tconst decode = (c: Cursor) => Frame.decode(c, group.flags, this.#timescales.get(group.trackAlias));\n\t\t\tfor (;;) {\n\t\t\t\t// Every object already buffered is written without an await, so the reader wakes\n\t\t\t\t// once per batch rather than once per object. Only the group's own stream ends it:\n\t\t\t\t// a track that closes first has already closed (or aborted) this group through its\n\t\t\t\t// cache.\n\t\t\t\tconst frame =\n\t\t\t\t\tstream.tryDecode(decode) ??\n\t\t\t\t\t(await (producer\n\t\t\t\t\t\t? race([stream.decodeMaybe(decode), producer.closed])\n\t\t\t\t\t\t: stream.decodeMaybe(decode)));\n\t\t\t\tif (!frame || frame instanceof Error) break;\n\n\t\t\t\tif (frame.endOfTrack) {\n\t\t\t\t\t// No object at or past this location exists: after the group's last object\n\t\t\t\t\t// the track ends with it, and at object 0 it ends before it.\n\t\t\t\t\tconst end = producer ? group.groupId + 1 : group.groupId;\n\t\t\t\t\tproducer?.close();\n\t\t\t\t\ttry {\n\t\t\t\t\t\ttrack.finishAt(end);\n\t\t\t\t\t} catch (err: unknown) {\n\t\t\t\t\t\tthrow new ProtocolViolation(`invalid END_OF_TRACK: ${reason(error(err))}`);\n\t\t\t\t\t}\n\t\t\t\t\tsubscription.end ??= end;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (frame.payload === undefined) break;\n\n\t\t\t\topen().writeFrame({ payload: frame.payload, timestamp: frame.timestamp ?? Timestamp.now() });\n\t\t\t}\n\n\t\t\t// A group with no objects still exists.\n\t\t\topen().close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = await sessionCause(this.#quic, err);\n\t\t\tif (e instanceof ProtocolViolation) {\n\t\t\t\t// The publisher broke the track's end, which no later group can repair.\n\t\t\t\tproducer?.close(e);\n\t\t\t\ttrack.close(e);\n\t\t\t} else {\n\t\t\t\t// A stream that fails before its first object still names a group, which the\n\t\t\t\t// reader sees fail rather than silently go missing.\n\t\t\t\ttry {\n\t\t\t\t\topen().close(e);\n\t\t\t\t} catch {\n\t\t\t\t\t// The track has already closed or ended below this group.\n\t\t\t\t}\n\t\t\t}\n\t\t\tstream.stop(e);\n\t\t} finally {\n\t\t\tread();\n\t\t}\n\t}\n}\n\n/**\n * A broadcast consumed from a moq-transport session. Track info is resolved by the\n * subscribe path (the inherited `resolveTrackInfo`), but the protocol has no one-shot\n * group fetch, so `track.Consumer.fetchGroup()` is rejected.\n */\nclass ConsumeBroadcast extends broadcast.Consumer {\n\tconstructor(state?: never) {\n\t\tsuper(state);\n\t\toverrideBroadcastWire(this, {\n\t\t\tfetchGroup: () => Promise.reject(new Error(\"fetch group is not supported for moq-transport\")),\n\t\t});\n\t}\n\n\t// Preserve the subclass when the consume cache shares this broadcast across callers.\n\toverride clone(): ConsumeBroadcast {\n\t\treturn new ConsumeBroadcast(this.shareState());\n\t}\n}\n"]}
1
+ {"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../src/ietf/subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAC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AAE,CAAC;QACR,CAAC;IACF,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,gBAAiB,SAAQ,SAAS,CAAC,QAAQ;IAChD,YAAY,KAAa;QACxB,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,qBAAqB,CAAC,IAAI,EAAE;YAC3B,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;SAC7F,CAAC,CAAC;IACJ,CAAC;IAED,qFAAqF;IAC5E,KAAK;QACb,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { race, Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport * as broadcast from \"../broadcast.ts\";\nimport { BroadcastCache } from \"../consume.ts\";\nimport {\n\tcloseError,\n\tcontrolTimeout,\n\terror,\n\tProtocolViolation,\n\treason,\n\tStreamCode,\n\tStreamError,\n\tsessionCause,\n} from \"../error.ts\";\nimport * as netGroup from \"../group.ts\";\nimport { Cost, type Route, randomHop, routesEqual, stampHops, UNKNOWN_HOP } from \"../hop.ts\";\nimport { hiddenBelow, hooks, scopeCaptures, scopeHead, scopeOverlaps } from \"../internal.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Cursor, type Reader, type Stream, UnexpectedEnd } from \"../stream.ts\";\nimport { Tail } from \"../tail.ts\";\nimport { type Timescale, Timestamp } from \"../time.ts\";\nimport type * as track from \"../track.ts\";\nimport { TimeoutError, withTimeout } from \"../util/timeout.ts\";\nimport { overrideBroadcastWire, wireOf } from \"../wire.ts\";\nimport type { Session } from \"./adapter.ts\";\nimport { DuplicateTrackAlias, RetiredTrackAlias, TrackAliases } from \"./aliases.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { requestReason, toRequestCode } from \"./error.ts\";\nimport { Frame, type Group as GroupMessage, hasFirstObjectBit } from \"./object.ts\";\nimport { fromWire, toWire } from \"./priority.ts\";\nimport { type Publish, PublishDone, PublishError, publishDoneClean } from \"./publish.ts\";\nimport {\n\ttype PublishNamespace,\n\tPublishNamespaceDone,\n\tPublishNamespaceError,\n\tPublishNamespaceOk,\n\tPublishNamespaceUpdate,\n} from \"./publish_namespace.ts\";\nimport { RequestError, RequestOk } from \"./request.ts\";\nimport { joinFilter, Subscribe, SubscribeError, SubscribeOk, Unsubscribe } from \"./subscribe.ts\";\nimport {\n\tPublishBlocked,\n\tSubscribeNamespace,\n\tSubscribeNamespaceEntry,\n\tSubscribeNamespaceEntryDone,\n\tSubscribeNamespaceLegacy,\n\tSubscribeNamespaceOk,\n\tUnsubscribeNamespace,\n} from \"./subscribe_namespace.ts\";\nimport { Version } from \"./version.ts\";\n\n// Bound on how long stream-open plus SUBSCRIBE_OK may take. Browsers cap\n// concurrent QUIC streams (Chrome ~100); past the cap openBi() silently\n// blocks. The timeout turns that into a clear error.\nconst SUBSCRIBE_OK_TIMEOUT_MS = 10_000;\n\n// A live subscription, as the track alias its data streams name resolves to.\ntype Subscription = {\n\t// The write side incoming group streams are routed into.\n\ttrack: track.Producer;\n\t// The group streams received, so the subscription can wait for the ones PUBLISH_DONE\n\t// says are still owed.\n\ttail: Tail;\n\t// The track's exclusive end, once an END_OF_TRACK declares it.\n\tend?: number;\n};\n\n// Out-parameter for #openSubscribe: lets the caller observe partial progress\n// (stream opened, trackAlias registered) so it can clean up on timeout even\n// before the setup promise settles.\ntype SubscribeSetupState = {\n\tstream?: Stream;\n\tregisteredAlias?: bigint;\n\t/**\n\t * Whether the caller has given up. Setup checks this once the stream exists so a request\n\t * opened after the timeout still unwinds: nothing else settles setup if the peer has\n\t * gone quiet, and the cleanup that fired first saw no stream to tear down.\n\t */\n\tcancelled?: boolean;\n\t/**\n\t * Whether the SUBSCRIBE reached the wire. From that moment the publisher may be serving,\n\t * even before it answers, so abandoning owes it a cancellation regardless of whether we\n\t * ever saw the SUBSCRIBE_OK.\n\t */\n\tsent?: boolean;\n\t/**\n\t * Whether the publisher answered with an error. It has torn the request down already, so\n\t * there is nothing left to cancel and naming the dead request id at it risks being read\n\t * as a protocol violation.\n\t */\n\trejected?: boolean;\n};\n\n/** A local announce reader's filter: its scope, the prefix it asked for, and its hidden opt-in. */\ntype Filter = { scope: Path.Pattern; prefix: Path.Valid; hidden: boolean };\n\n/** Whether a reader with `filter` sees an announcement at `path`. */\nfunction sees(filter: Filter, path: Path.Valid): boolean {\n\treturn scopeOverlaps(filter.scope, path) && (filter.hidden || !hiddenBelow(filter.prefix, path));\n}\n\n/**\n * Handles subscribing to broadcasts using moq-transport protocol.\n * Uses the stream-per-request pattern (real bidi streams for v17, virtual for v14-v16).\n *\n * @internal\n */\nexport class Subscriber {\n\t#session: Session;\n\t#localClose = false;\n\n\t// The transport, so a request cut off by the session's close ends with the session's\n\t// error. Optional for tests that drive a bare session.\n\t#quic?: WebTransport;\n\n\t// The Hop IDs this session declared; see {@link Cluster}. What the peer declared is what\n\t// says whether an advertisement carries a hop path, and ours is what a path looping back\n\t// to us contains.\n\t#cluster?: Cluster.Hops;\n\n\t// Publisher-chosen aliases used by incoming group streams.\n\t#aliases = new TrackAliases<Subscription>();\n\n\t// Units for each track's object Timestamps, from the TIMESCALE Track Property in\n\t// SUBSCRIBE_OK. A track missing from this map declared no timeline, so the publisher\n\t// opted out of timestamps and its frames are stamped on arrival instead.\n\t#timescales = new Map<bigint, Timescale>();\n\n\t// Dedup consumed broadcasts per path: repeat consume() calls share one subscription.\n\t#consumes = new BroadcastCache();\n\n\t// A random Hop ID of this connection's own, written as the first hop of any path that\n\t// names no publisher, so a publisher that reconnects reads as a new one.\n\t#stamp = randomHop();\n\n\t// Paths with a legacy PUBLISH_NAMESPACE request in flight, reserved synchronously.\n\t// The count below is only taken once the OK is written, and two requests that both\n\t// got past the duplicate check before either attached would both take one.\n\t#legacyRequests = new Set<Path.Valid>();\n\n\t// Every announced path, counted by how many live advertisements reference it.\n\t//\n\t// A peer may advertise one namespace twice on a session: an unsolicited\n\t// PUBLISH_NAMESPACE and an inline NAMESPACE answering our own SUBSCRIBE_NAMESPACE are\n\t// two messages about one source, which the MoQ Solicit draft requires us to tolerate.\n\t// Counting them is what keeps the second from duplicating the announce and the first\n\t// to end from retracting what the other still holds.\n\t#announced = new Map<Path.Valid, { count: number; route: Route }>();\n\n\t// Any consumers that want each new announcement, keyed by their local filter.\n\t#announcedConsumers = new Map<announce.Producer, Filter>();\n\n\t// Whether the peer understands the HIDDEN parameter (MoQ Hidden).\n\t#hidden: boolean;\n\n\t/** Marks this subscriber's deliberate local session close. @internal */\n\tclose() {\n\t\tthis.#localClose = true;\n\t}\n\n\t/**\n\t * Creates a new Subscriber instance.\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\tsession,\n\t\tquic,\n\t\tcluster,\n\t\thidden = false,\n\t}: {\n\t\t/** The session abstraction for bidi streams and request IDs. */\n\t\tsession: Session;\n\t\t/** The transport the session runs on. */\n\t\tquic?: WebTransport;\n\t\t/** The Hop IDs the SETUP exchange settled (MoQ Cluster). */\n\t\tcluster?: Cluster.Hops;\n\t\t/** Whether the peer understands the HIDDEN parameter (MoQ Hidden). */\n\t\thidden?: boolean;\n\t}) {\n\t\tthis.#session = session;\n\t\tthis.#quic = quic;\n\t\tthis.#cluster = cluster;\n\t\tthis.#hidden = hidden;\n\t}\n\n\t/**\n\t * Whether an advertisement is ours coming back: its hop path already ran through us, so\n\t * subscribing via it would route us back to ourselves.\n\t *\n\t * A conforming peer withholds these (it knows our Hop ID), so this is the backstop that\n\t * keeps a mesh working when one member does not. A session that negotiated nothing\n\t * carries no path, and there is nothing to check.\n\t */\n\t#reflected(advert: Cluster.Advert | undefined): boolean {\n\t\treturn advert !== undefined && this.#cluster !== undefined && Cluster.loops(advert, this.#cluster.self);\n\t}\n\n\t/**\n\t * The route an advertisement carries; one without a path is free. A path that names no\n\t * publisher, or none at all, gets this connection's stamp in front of a 0.\n\t */\n\t#route(advert: Cluster.Advert | undefined): Route {\n\t\tif (advert === undefined) return { hops: [this.#stamp, UNKNOWN_HOP], cost: Cost.zero };\n\t\t// A full chain, or a stamp colliding with an entry (a 1-in-2^53 draw), keeps the\n\t\t// path as sent.\n\t\tconst hops = stampHops(advert.hops, this.#stamp) ?? [...advert.hops];\n\t\treturn { hops, cost: { warm: advert.cost, cold: advert.cost } };\n\t}\n\n\t/**\n\t * Gets an announced reader matching `scope`. Paths are relative to the session,\n\t * not the scope.\n\t *\n\t * The peer is asked with SUBSCRIBE_NAMESPACE regardless of what it declared, and an\n\t * unsolicited PUBLISH_NAMESPACE lands here too, so a peer that only tells and one\n\t * that only answers are both discovered.\n\t *\n\t * Hidden routes (a `.`-prefixed segment below the scope's head) are left out unless\n\t * `options.hidden` opts in. The opt-in rides the SUBSCRIBE_NAMESPACE when the peer\n\t * understands it (MoQ Hidden); the rule is also applied here, since an unsolicited\n\t * PUBLISH_NAMESPACE or a peer that never heard of it hides nothing.\n\t */\n\tannounced(scope: Path.Pattern = Path.Pattern.all(), options?: announce.Options): announce.Consumer {\n\t\t// The wire speaks announce interest by prefix.\n\t\tconst prefix = scopeHead(scope);\n\t\tconst filter = { scope, prefix, hidden: options?.hidden ?? false };\n\t\tconst announced = new announce.Producer();\n\t\tfor (const [active, info] of this.#announced) {\n\t\t\tif (!sees(filter, active)) continue;\n\t\t\tannounced.append({\n\t\t\t\tprefix: active,\n\t\t\t\tcaptures: scopeCaptures(scope, active),\n\t\t\t\tkind: \"announced\",\n\t\t\t\troute: info.route,\n\t\t\t});\n\t\t}\n\t\tthis.#announcedConsumers.set(announced, filter);\n\n\t\tvoid this.#runAnnounced(announced, prefix, filter.hidden && this.#hidden).finally(() => {\n\t\t\tthis.#announcedConsumers.delete(announced);\n\t\t\tannounced.close();\n\t\t});\n\n\t\treturn announced.consume();\n\t}\n\n\t/**\n\t * Record one more advertisement for a path, telling consumers only when it is the\n\t * first. A second one is the same namespace said twice, not news.\n\t */\n\t#attachAnnounce(path: Path.Valid, route: Route) {\n\t\tconst existing = this.#announced.get(path);\n\t\tif (existing) {\n\t\t\texisting.count += 1;\n\t\t\treturn;\n\t\t}\n\t\tthis.#announced.set(path, { count: 1, route });\n\n\t\tconsole.debug(`announced: broadcast=${path} active=true`);\n\t\tfor (const [consumer, filter] of this.#announcedConsumers) {\n\t\t\tif (!sees(filter, path)) continue;\n\t\t\tconst scope = filter.scope;\n\t\t\tconsumer.append({ prefix: path, captures: scopeCaptures(scope, path), kind: \"announced\", route });\n\t\t}\n\t}\n\n\t/**\n\t * Replace the stored route for a path that is already announced. A no-op when the\n\t * hops and cost did not change; otherwise consumers hear `updated` so a forwarder\n\t * can reprice without retracting.\n\t *\n\t * A new first hop is a new publisher: holders keep their broadcast to drain, but the\n\t * next consume starts fresh rather than reusing the old publisher's cached track info.\n\t */\n\t#updateAnnounce(path: Path.Valid, route: Route) {\n\t\tconst existing = this.#announced.get(path);\n\t\tif (existing === undefined || routesEqual(existing.route, route)) return;\n\t\tif (existing.route.hops[0] !== route.hops[0]) this.#consumes.evict(path);\n\t\texisting.route = route;\n\t\tconsole.debug(`announced: broadcast=${path} rerouted`);\n\t\tfor (const [consumer, filter] of this.#announcedConsumers) {\n\t\t\tif (!sees(filter, path)) continue;\n\t\t\tconst scope = filter.scope;\n\t\t\tconsumer.append({ prefix: path, captures: scopeCaptures(scope, path), kind: \"updated\", route });\n\t\t}\n\t}\n\n\t/**\n\t * Drop one advertisement for a path, retracting it only once the last one goes.\n\t */\n\t#detachAnnounce(path: Path.Valid) {\n\t\tconst existing = this.#announced.get(path);\n\t\tif (existing === undefined) return;\n\t\tif (existing.count > 1) {\n\t\t\texisting.count -= 1;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#announced.delete(path);\n\n\t\t// The path is gone, so stop sharing its broadcast: a holder outliving the publisher\n\t\t// would otherwise hand the dead generation to whoever consumes the path next.\n\t\tthis.#consumes.evict(path);\n\t\tconsole.debug(`announced: broadcast=${path} active=false`);\n\n\t\tfor (const [consumer, filter] of this.#announcedConsumers) {\n\t\t\tif (!sees(filter, path)) continue;\n\t\t\tconst scope = filter.scope;\n\t\t\ttry {\n\t\t\t\tconsumer.append({\n\t\t\t\t\tprefix: path,\n\t\t\t\t\tcaptures: scopeCaptures(scope, path),\n\t\t\t\t\tkind: \"retracted\",\n\t\t\t\t\troute: existing.route,\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\t// Consumer already closed, will be cleaned up\n\t\t\t}\n\t\t}\n\t}\n\n\tasync #runAnnounced(announced: announce.Producer, prefix: Path.Valid, hidden: boolean) {\n\t\tconst version = this.#session.version;\n\n\t\t// Suffixes live on this stream, so a repeat is recognized as an update to the\n\t\t// advertisement rather than a second one, which would leak the count.\n\t\tconst live = new Set<Path.Valid>();\n\n\t\t// Set once the teardown below has given back everything this stream held. The read\n\t\t// loop is not awaited when the local consumer closes first, and closing the stream\n\t\t// cancels the transport without discarding what the reader already buffered, so a\n\t\t// fully buffered entry can still decode afterwards. Attaching one then would take a\n\t\t// reference nobody is left to release, pinning the path for the session.\n\t\tlet released = false;\n\n\t\t// v14/v15: SubscribeNamespace on control stream (via adapter virtual stream)\n\t\t// v16+: SubscribeNamespace on its own real bidi stream\n\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) return;\n\n\t\ttry {\n\t\t\t// v16: use a real bidi stream (not virtual control stream)\n\t\t\tconst stream =\n\t\t\t\tversion === Version.DRAFT_16 && this.#session.openNativeBi\n\t\t\t\t\t? await this.#session.openNativeBi()\n\t\t\t\t\t: await this.#session.openBi();\n\n\t\t\ttry {\n\t\t\t\t// Draft-18+ uses SUBSCRIBE_NAMESPACE (0x50); earlier drafts use the\n\t\t\t\t// legacy 0x11 message with a Subscribe Options field.\n\t\t\t\tif (\n\t\t\t\t\tversion === Version.DRAFT_14 ||\n\t\t\t\t\tversion === Version.DRAFT_15 ||\n\t\t\t\t\tversion === Version.DRAFT_16 ||\n\t\t\t\t\tversion === Version.DRAFT_17\n\t\t\t\t) {\n\t\t\t\t\tawait stream.writer.u53(SubscribeNamespaceLegacy.id);\n\t\t\t\t\tawait new SubscribeNamespaceLegacy({ namespace: prefix, requestId, hidden }).encode(\n\t\t\t\t\t\tstream.writer,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tawait stream.writer.u53(SubscribeNamespace.id);\n\t\t\t\t\tawait new SubscribeNamespace({ namespace: prefix, requestId, hidden }).encode(\n\t\t\t\t\t\tstream.writer,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconsole.debug(`subscribe_namespace written: requestId=${requestId}`);\n\n\t\t\t\t// Read response\n\t\t\t\tconst respTypeId = await stream.reader.u53();\n\t\t\t\tif (respTypeId === RequestOk.id) {\n\t\t\t\t\tawait RequestOk.decode(stream.reader, version);\n\t\t\t\t} else if (respTypeId === SubscribeNamespaceOk.id) {\n\t\t\t\t\t// v14: SubscribeNamespaceOk\n\t\t\t\t\tconst size = await stream.reader.u16();\n\t\t\t\t\tawait stream.reader.read(size);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(`SubscribeNamespace rejected: typeId=0x${respTypeId.toString(16)}`);\n\t\t\t\t}\n\n\t\t\t\t// Loop reading Namespace/NamespaceDone entries\n\t\t\t\tconst readLoop = (async () => {\n\t\t\t\t\tfor (;;) {\n\t\t\t\t\t\tconst done = await stream.reader.done();\n\t\t\t\t\t\tif (done) break;\n\n\t\t\t\t\t\tconst msgType = await stream.reader.u53();\n\t\t\t\t\t\tif (msgType === SubscribeNamespaceEntry.id) {\n\t\t\t\t\t\t\tconst entry = await SubscribeNamespaceEntry.decode(\n\t\t\t\t\t\t\t\tstream.reader,\n\t\t\t\t\t\t\t\tversion,\n\t\t\t\t\t\t\t\tCluster.negotiated(this.#cluster),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (released) break;\n\t\t\t\t\t\t\tconst path = Path.join(prefix, entry.suffix);\n\n\t\t\t\t\t\t\t// A repeat updates the advertisement in place, so one that now\n\t\t\t\t\t\t\t// loops back through us has taken a route we can't subscribe\n\t\t\t\t\t\t\t// over: the path is gone even though the message says active.\n\t\t\t\t\t\t\tif (this.#reflected(entry.cluster)) {\n\t\t\t\t\t\t\t\tconsole.debug(`dropping reflected namespace: broadcast=${path}`);\n\t\t\t\t\t\t\t\tif (live.delete(path)) this.#detachAnnounce(path);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// A repeat replaces the advertisement in place: HOP_PATH / ROUTE_COST\n\t\t\t\t\t\t\t// can change without a NAMESPACE_DONE. Only the first is a new path.\n\t\t\t\t\t\t\tconst route = this.#route(entry.cluster);\n\t\t\t\t\t\t\tif (live.has(path)) {\n\t\t\t\t\t\t\t\tthis.#updateAnnounce(path, route);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tlive.add(path);\n\t\t\t\t\t\t\t\tthis.#attachAnnounce(path, route);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (msgType === SubscribeNamespaceEntryDone.id) {\n\t\t\t\t\t\t\tconst entry = await SubscribeNamespaceEntryDone.decode(stream.reader, version);\n\t\t\t\t\t\t\tif (released) break;\n\t\t\t\t\t\t\tconst path = Path.join(prefix, entry.suffix);\n\n\t\t\t\t\t\t\tif (live.delete(path)) {\n\t\t\t\t\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (msgType === PublishBlocked.id && version === Version.DRAFT_17) {\n\t\t\t\t\t\t\tconst blocked = await PublishBlocked.decode(stream.reader, version);\n\t\t\t\t\t\t\tconsole.debug(`publish_blocked: suffix=${blocked.suffix} track=${blocked.trackName}`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`unexpected message on subscribe_namespace stream: 0x${msgType.toString(16)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})();\n\n\t\t\t\t// The race below can end through the consumer's close while a message that\n\t\t\t\t// already arrived is still decoding, which leaves the loop with nothing\n\t\t\t\t// awaiting it: a violation decoded after that would land nowhere, and its\n\t\t\t\t// rejection would go unhandled. Idempotent with the catch below, which is\n\t\t\t\t// what runs when the loop is the one that ends the race.\n\t\t\t\treadLoop.catch((err: unknown) => {\n\t\t\t\t\tif (err instanceof ProtocolViolation) this.#session.close();\n\t\t\t\t});\n\n\t\t\t\t// Wait for either the read loop or the announced to close\n\t\t\t\tawait race([readLoop, announced.closed]);\n\n\t\t\t\t// For v14/v15: send UnsubscribeNamespace before closing\n\t\t\t\tif (version === Version.DRAFT_14 || version === Version.DRAFT_15) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait stream.writer.u53(UnsubscribeNamespace.id);\n\t\t\t\t\t\tconst unsub = new UnsubscribeNamespace({ requestId });\n\t\t\t\t\t\tawait unsub.encode(stream.writer, version);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Stream might already be closed\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstream.close();\n\t\t\t} catch (err) {\n\t\t\t\tstream.abort(error(err));\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tconst e = error(err);\n\t\t\tconsole.warn(`subscribe_namespace error: ${reason(e)}`);\n\n\t\t\t// An advertisement is decoded here rather than in the session dispatch, so this\n\t\t\t// is the only place a malformed one surfaces. The cluster draft requires closing\n\t\t\t// the session over those, and the stream alone is not enough: the peer would\n\t\t\t// just repeat it on the next SUBSCRIBE_NAMESPACE.\n\t\t\tif (e instanceof ProtocolViolation) this.#session.close();\n\n\t\t\t// Abort the stream rather than letting the caller's `finally` close it cleanly.\n\t\t\t// A rejected namespace subscription is a failure, and a consumer that can't tell\n\t\t\t// it from \"nothing is published under this prefix\" waits forever on a broadcast\n\t\t\t// that will never be announced. Matches the lite subscriber.\n\t\t\tannounced.close(e);\n\t\t} finally {\n\t\t\t// The stream owns every advertisement it carried, so release them however it\n\t\t\t// ends: a clean close, a decode error, or the peer resetting it. Without this\n\t\t\t// each namespace keeps its count and the source never detaches, which would\n\t\t\t// pin the path for the session even after the other source withdrew.\n\t\t\treleased = true;\n\t\t\tfor (const path of live) {\n\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t}\n\t\t\tlive.clear();\n\t\t}\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * Deduplicated per path: repeat calls for the same still-live path share one reference-counted\n\t * broadcast (and one upstream subscription). The shared broadcast closes once every caller has\n\t * closed its handle, so callers close normally.\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#consumes.get(path) ?? this.#consumes.insert(path, this.#createConsume(path));\n\t}\n\n\t#createConsume(path: Path.Valid): broadcast.Consumer {\n\t\t// moq-transport has no one-shot group fetch; ConsumeBroadcast rejects it. Track info\n\t\t// is resolved by the subscribe path (the inherited resolveTrackInfo).\n\t\tconst consumer = new ConsumeBroadcast();\n\n\t\tvoid (async () => {\n\t\t\tfor (;;) {\n\t\t\t\tconst request = await wireOf(consumer).requested();\n\t\t\t\tif (!request) break;\n\t\t\t\tvoid this.#runSubscribe(path, request);\n\t\t\t}\n\t\t})();\n\n\t\treturn consumer;\n\t}\n\n\t// The adapter is gone. If the transport has already closed, that close is the\n\t// error. A still-open transport, such as a GOAWAY drain, has no peer code yet,\n\t// so this does not wait for it.\n\tasync #closedSession(): Promise<Error> {\n\t\tconst quic = this.#quic;\n\t\tif (!quic) return new Error(\"session closed\");\n\t\treturn Promise.race([\n\t\t\tcloseError(quic),\n\t\t\tnew Promise<Error>((resolve) => queueMicrotask(() => resolve(new Error(\"session closed\")))),\n\t\t]);\n\t}\n\n\tasync #runSubscribe(broadcast: Path.Valid, request: track.Request) {\n\t\tconst requestId = await this.#session.nextRequestId();\n\t\tif (requestId === undefined) {\n\t\t\trequest.reject(await this.#closedSession());\n\t\t\treturn;\n\t\t}\n\n\t\tconsole.debug(`subscribe start: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\n\t\t// Keep the request pending until SUBSCRIBE_OK supplies immutable track metadata.\n\t\t// Group streams already wait on the alias, so early data stays behind this response.\n\t\tconst producer = hooks.pendingTrackProducer(request);\n\t\tconst subscription: Subscription = { track: producer, tail: new Tail() };\n\n\t\t// Open the stream and wait for SUBSCRIBE_OK under a timeout. State\n\t\t// flows back via `state` so the timeout path can clean up the stream\n\t\t// and any registration if setup eventually finishes.\n\t\tconst state: SubscribeSetupState = {};\n\t\tconst setup = this.#openSubscribe(state, broadcast, request, subscription, requestId);\n\n\t\t// The publisher can be serving before it answers, so waiting only on the response\n\t\t// would miss the local side going away and leave it serving a track nobody reads.\n\t\t// Demand returning before we commit is not abandonment, matching the serving loop.\n\t\tconst waitAbandoned = async (): Promise<null> => {\n\t\t\t// An info-only lookup attaches no subscriber yet still waits on SUBSCRIBE_OK for\n\t\t\t// the track info, so only demand that arrived and then left is abandonment.\n\t\t\twhile (!producer.used.peek() && producer.closed.peek() === undefined) {\n\t\t\t\tawait Signal.race(producer.used, producer.closed);\n\t\t\t}\n\t\t\tfor (;;) {\n\t\t\t\tawait producer.unused();\n\t\t\t\tif (producer.closed.peek() !== undefined || !producer.used.peek()) return null;\n\t\t\t}\n\t\t};\n\n\t\tlet stream: Stream;\n\t\tlet trackAlias: bigint;\n\t\ttry {\n\t\t\tconst result = await race([\n\t\t\t\twithTimeout(\n\t\t\t\t\tsetup,\n\t\t\t\t\tSUBSCRIBE_OK_TIMEOUT_MS,\n\t\t\t\t\t`subscribe timed out after ${SUBSCRIBE_OK_TIMEOUT_MS}ms waiting for SUBSCRIBE_OK (browser stream limit reached?)`,\n\t\t\t\t),\n\t\t\t\twaitAbandoned(),\n\t\t\t]);\n\n\t\t\tif (result === null) throw new Error(\"subscribe abandoned before it was accepted\");\n\n\t\t\tstream = result.stream;\n\t\t\ttrackAlias = result.alias;\n\t\t\tconsole.debug(`subscribe ok: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\t// A control request that timed out is not late content, so it carries its own code.\n\t\t\tconst e = err instanceof TimeoutError ? controlTimeout(err) : await sessionCause(this.#quic, err);\n\t\t\trequest.reject(e);\n\t\t\tconsole.warn(\n\t\t\t\t`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`,\n\t\t\t);\n\t\t\t// Runs now for whatever is already open, and again if `setup` settles late.\n\t\t\t// Retirement is repeated because a late SUBSCRIBE_OK can register an alias after\n\t\t\t// the first pass; the stream is torn down once.\n\t\t\tlet torn = false;\n\t\t\tconst cleanup = async (afterSetup: boolean) => {\n\t\t\t\tstate.cancelled = true;\n\n\t\t\t\tif (state.registeredAlias !== undefined && this.#aliases.retire(state.registeredAlias, subscription)) {\n\t\t\t\t\tthis.#timescales.delete(state.registeredAlias);\n\t\t\t\t}\n\n\t\t\t\tif (!state.stream || torn) return;\n\n\t\t\t\t// A SUBSCRIBE still being written must not be torn down from here. Aborting a\n\t\t\t\t// Web Stream waits for the in-flight write, so the request can still reach the\n\t\t\t\t// peer while the abort destroys the stream we would have cancelled on. Setup\n\t\t\t\t// unwinds on the cancelled flag once that write lands, and its pass below has\n\t\t\t\t// the finished picture.\n\t\t\t\tif (!state.sent && !afterSetup) return;\n\t\t\t\ttorn = true;\n\n\t\t\t\t// Once the SUBSCRIBE is out the publisher may be serving, whether or not it has\n\t\t\t\t// answered yet: data streams are independent of the request stream. Aborting says\n\t\t\t\t// nothing on v14-16, where the request rides a virtual stream whose reset is\n\t\t\t\t// local, so the UNSUBSCRIBE has to go out explicitly.\n\t\t\t\tif (state.sent && !state.rejected) await this.#cancelSubscribe(state.stream, requestId);\n\t\t\t\tstate.stream.abort(e);\n\t\t\t};\n\n\t\t\t// Tear down what is already open rather than waiting on `setup`. A peer that\n\t\t\t// opened the stream and then went quiet never settles it, and deferring would\n\t\t\t// leave the request outstanding for the life of the session -- which is the\n\t\t\t// timeout case, not a rare one.\n\t\t\tvoid cleanup(false);\n\t\t\tsetup.then(\n\t\t\t\t() => cleanup(true),\n\t\t\t\t() => cleanup(true),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Which terminal fired decides whether we owe the publisher a cancellation, so\n\t\t\t// tag them rather than racing bare promises.\n\t\t\tconst publisherEnded = Symbol(\"publisher\");\n\t\t\tconst localEnded = Symbol(\"local\");\n\t\t\tconst idle = Symbol(\"idle\");\n\n\t\t\t// Terminal conditions settle at most once (PublishDone, track close = local\n\t\t\t// unsubscribe); race them once so the demand loop doesn't re-subscribe each pass.\n\t\t\tconst done = race([\n\t\t\t\tthis.#runPublishDone(stream, subscription).then(() => publisherEnded),\n\t\t\t\tproducer.closed.then(() => localEnded),\n\t\t\t]);\n\n\t\t\t// Serve until a terminal condition fires or the last local subscriber leaves. The unused\n\t\t\t// wake is level-triggered: re-check demand so a subscriber that returns before we tear\n\t\t\t// down resumes on the same stream.\n\t\t\tlet terminal = localEnded;\n\t\t\tfor (;;) {\n\t\t\t\tconst reason = await race([done, producer.unused().then(() => idle)]);\n\t\t\t\tif (reason === idle && producer.closed.peek() === undefined && producer.used.peek()) continue;\n\t\t\t\tterminal = reason;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Close before the cancellation is written, not after: awaiting the write first\n\t\t\t// reopens the window the demand re-check above just closed, and a subscriber that\n\t\t\t// returned during it would be closed by this line. The lite subscriber closes\n\t\t\t// straight out of its loop for the same reason.\n\t\t\tproducer.close();\n\n\t\t\t// The publisher already ended the request, so there is nothing to cancel. Sending\n\t\t\t// UNSUBSCRIBE here would name a request it has already torn down.\n\t\t\tif (terminal !== publisherEnded) await this.#cancelSubscribe(stream, requestId);\n\n\t\t\tstream.close();\n\t\t\tconsole.debug(`subscribe close: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\t\t} catch (err) {\n\t\t\tconst e = await sessionCause(this.#quic, err);\n\t\t\tproducer.close(this.#localClose ? undefined : e);\n\t\t\tstream.abort(e);\n\t\t\tconsole.warn(\n\t\t\t\t`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`,\n\t\t\t);\n\t\t} finally {\n\t\t\t// Only the owner tears down the alias metadata: a later subscription may have\n\t\t\t// reclaimed the alias and installed its own timescale.\n\t\t\tif (this.#aliases.retire(trackAlias, subscription)) this.#timescales.delete(trackAlias);\n\t\t}\n\t}\n\n\t/**\n\t * Read the PUBLISH_DONE that ends a subscription, then wait for the data streams it counts.\n\t *\n\t * An error status aborts the track with it. A clean one leaves streams in flight, since\n\t * QUIC does not order them, so wait until the Stream Count many have been read, or a\n\t * bounded grace for the ones that never arrive (the draft says to use a timeout). The count\n\t * is only a hint: a peer may send 0 regardless, so 0 waits out the grace. A request\n\t * stream that FINs without PUBLISH_DONE is a protocol violation.\n\t */\n\tasync #runPublishDone(stream: Stream, subscription: Subscription): Promise<void> {\n\t\tconst version = this.#session.version;\n\t\tif (await stream.reader.done()) throw new ProtocolViolation(\"subscribe stream ended without PUBLISH_DONE\");\n\t\tconst typeId = await stream.reader.u53();\n\t\tif (typeId !== PublishDone.id) {\n\t\t\tthrow new ProtocolViolation(`unexpected message on a subscription: 0x${typeId.toString(16)}`);\n\t\t}\n\t\tconst done = await PublishDone.decode(stream.reader, version);\n\t\tif (!publishDoneClean(done.statusCode, version)) {\n\t\t\tthrow new Error(`publish done: status=0x${done.statusCode.toString(16)} reason=${done.reasonPhrase}`);\n\t\t}\n\t\tconst count = done.streamCount;\n\n\t\tconst { tail, track } = subscription;\n\t\tconst complete = () => count > 0n && BigInt(tail.streams) >= count;\n\t\tawait tail.settle(complete, track.closed);\n\t}\n\n\t/**\n\t * Tell the publisher to stop serving a subscription we are walking away from.\n\t *\n\t * v14-16 cancel with UNSUBSCRIBE (draft-16 section 9.12), which is what lets the\n\t * publisher destroy the subscription (section 5.1.1); v17+ removed the message and\n\t * rely on the stream reset instead. Every path that abandons an Established\n\t * subscription goes through here, because those versions carry the request over a\n\t * virtual stream whose reset never reaches the peer.\n\t */\n\tasync #cancelSubscribe(stream: Stream, requestId: bigint) {\n\t\tconst version = this.#session.version;\n\t\tif (version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16) return;\n\n\t\ttry {\n\t\t\tawait stream.writer.u53(Unsubscribe.id);\n\t\t\tawait new Unsubscribe({ requestId }).encode(stream.writer, version);\n\t\t} catch {\n\t\t\t// The stream may already be gone; there is nothing further to tell the peer.\n\t\t}\n\t}\n\n\t// Opens the subscribe stream, sends SUBSCRIBE, and reads the response.\n\t// `state` is populated as soon as the stream opens and again when the\n\t// trackAlias is registered, so the caller can clean both up on timeout\n\t// even before this promise settles.\n\tasync #openSubscribe(\n\t\tstate: SubscribeSetupState,\n\t\tbroadcast: Path.Valid,\n\t\trequest: track.Request,\n\t\tsubscription: Subscription,\n\t\trequestId: bigint,\n\t): Promise<{ stream: Stream; alias: bigint }> {\n\t\tconst version = this.#session.version;\n\n\t\tstate.stream = await this.#session.openBi();\n\n\t\t// The timeout can fire while the open is still in flight, in which case cleanup ran\n\t\t// with nothing to release. Bail now that the stream is recorded, so settling this\n\t\t// promise hands it back to be torn down.\n\t\tif (state.cancelled) throw new Error(\"subscribe cancelled before it was sent\");\n\n\t\tawait state.stream.writer.u53(Subscribe.id);\n\t\tconst msg = new Subscribe({\n\t\t\trequestId,\n\t\t\ttrackNamespace: broadcast,\n\t\t\ttrackName: request.name,\n\t\t\tsubscriberPriority: toWire(request.priority),\n\t\t\t// No fill is requested: the fill's fetch stream and the live subscription split\n\t\t\t// the group across two streams, and this subscriber does not reassemble them into\n\t\t\t// one group yet. A lenient publisher (like ours) replays the whole in-range group\n\t\t\t// on the subscription instead; a strict one only delivers from the next published\n\t\t\t// object, and that mid-group stream is dropped, degrading the join to the next\n\t\t\t// group boundary.\n\t\t\tfilter: joinFilter(version),\n\t\t});\n\t\tawait msg.encode(state.stream.writer, version);\n\t\tstate.sent = true;\n\n\t\t// The caller may have given up while that write was in flight. It deliberately left\n\t\t// the stream alone, so unwind here and let its cleanup send the cancellation now that\n\t\t// the SUBSCRIBE has actually reached the peer.\n\t\tif (state.cancelled) throw new Error(\"subscribe cancelled while it was being sent\");\n\t\tconsole.debug(`subscribe written: id=${requestId} broadcast=${broadcast} track=${request.name}`);\n\n\t\tconst respTypeId = await state.stream.reader.u53();\n\t\tif (respTypeId !== SubscribeOk.id) {\n\t\t\tlet reasonPhrase = \"unknown error\";\n\t\t\ttry {\n\t\t\t\tif (respTypeId === RequestError.id) {\n\t\t\t\t\tconst err =\n\t\t\t\t\t\tversion === Version.DRAFT_14\n\t\t\t\t\t\t\t? await SubscribeError.decode(state.stream.reader, version)\n\t\t\t\t\t\t\t: await RequestError.decode(state.stream.reader, version);\n\t\t\t\t\treasonPhrase = requestReason(err.errorCode, err.reasonPhrase, \"subscribe\", version);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Decoding error response failed, use default message\n\t\t\t}\n\t\t\tstate.rejected = true;\n\t\t\tthrow new Error(`SUBSCRIBE error: ${reasonPhrase}`);\n\t\t}\n\n\t\tconst ok = await SubscribeOk.decode(state.stream.reader, version);\n\t\tif (state.cancelled) throw new Error(\"subscribe cancelled before acceptance\");\n\t\trequest.accept({ priority: fromWire(ok.properties.priority ?? 128) });\n\n\t\ttry {\n\t\t\tthis.#aliases.set(ok.trackAlias, subscription, { broadcast, name: request.name });\n\t\t\tconst timescale = ok.properties.timescale;\n\t\t\tif (timescale !== undefined) {\n\t\t\t\tthis.#timescales.set(ok.trackAlias, timescale);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\t// Only one alias naming two different tracks is the session's problem. A publisher\n\t\t\t// sharing an alias between subscriptions to one track is allowed to do that, and\n\t\t\t// disconnecting over it would drop every other broadcast on the session.\n\t\t\tif (err instanceof DuplicateTrackAlias) this.#session.close();\n\t\t\tthrow err;\n\t\t}\n\t\tstate.registeredAlias = ok.trackAlias;\n\t\treturn { stream: state.stream, alias: ok.trackAlias };\n\t}\n\n\t/**\n\t * Handles an incoming PUBLISH_NAMESPACE on a bidi stream.\n\t * Tracks announced broadcasts and notifies consumers.\n\t *\n\t * @internal\n\t */\n\tasync runPublishNamespace(msg: PublishNamespace, stream: Stream) {\n\t\tconst version = this.#session.version;\n\t\tconst path = msg.trackNamespace;\n\n\t\t// A path that already ran through us looped back. Refuse it rather than holding an\n\t\t// advertisement we could never subscribe through. The peer knows our Hop ID, so a\n\t\t// conforming one never offers it; 0 as the retry interval says not to come back.\n\t\tif (this.#reflected(msg.cluster)) {\n\t\t\tconsole.debug(`dropping reflected publish_namespace: broadcast=${path}`);\n\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\tawait new RequestError({\n\t\t\t\trequestId: msg.requestId,\n\t\t\t\terrorCode: toRequestCode(\"uninterested\", \"publish_namespace\", version),\n\t\t\t\treasonPhrase: \"route loops back\",\n\t\t\t}).encode(stream.writer, version);\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\t// Draft-14/15 key their namespace-scoped messages by name, not request ID, so the\n\t\t// adapter can hold only one request per namespace: a second would overwrite the\n\t\t// first, and the withdrawals would then close the wrong stream and fail to find\n\t\t// the other. Nothing is lost by refusing it, because the case that makes a second\n\t\t// reference legitimate (an inline NAMESPACE for a path a PUBLISH_NAMESPACE already\n\t\t// carried) needs a message those drafts do not have.\n\t\tconst legacy = version === Version.DRAFT_14 || version === Version.DRAFT_15;\n\t\tif (legacy && (this.#announced.has(path) || this.#legacyRequests.has(path))) {\n\t\t\tconsole.warn(\"duplicate PublishNamespace\");\n\t\t\t// No draft registers a code for a duplicate, and this refusal is a draft-14/15\n\t\t\t// implementation limit, which is what INTERNAL_ERROR describes.\n\t\t\tconst errorCode = toRequestCode(\"internal\", \"publish_namespace\", version);\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(PublishNamespaceError.id);\n\t\t\t\tawait new PublishNamespaceError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode,\n\t\t\t\t\treasonPhrase: \"duplicate namespace\",\n\t\t\t\t}).encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\t\tawait new RequestError({\n\t\t\t\t\trequestId: msg.requestId,\n\t\t\t\t\terrorCode,\n\t\t\t\t\treasonPhrase: \"duplicate namespace\",\n\t\t\t\t}).encode(stream.writer, version);\n\t\t\t}\n\t\t\tstream.close();\n\t\t\treturn;\n\t\t}\n\n\t\t// Everywhere else a path this session already knows is not refused: the same\n\t\t// namespace can reach us twice, and the count is what tells the second apart from\n\t\t// news. This request owns exactly one of those references and gives it back when\n\t\t// the stream ends.\n\t\tif (legacy) this.#legacyRequests.add(path);\n\t\tlet attached = false;\n\n\t\ttry {\n\t\t\t// Send OK first. This must complete before notifying consumers,\n\t\t\t// because consumers may trigger Subscribe writes that would\n\t\t\t// interleave with our OK on the control stream.\n\t\t\tif (version === Version.DRAFT_14) {\n\t\t\t\tawait stream.writer.u53(PublishNamespaceOk.id);\n\t\t\t\tconst ok = new PublishNamespaceOk({ requestId: msg.requestId });\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t} else {\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tconst ok = new RequestOk({\n\t\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\t});\n\t\t\t\tawait ok.encode(stream.writer, version);\n\t\t\t}\n\n\t\t\t// Only now is the advertisement ours to announce, for the reason above: a\n\t\t\t// consumer reacting with a SUBSCRIBE must not interleave with that OK.\n\t\t\tattached = true;\n\t\t\tthis.#attachAnnounce(path, this.#route(msg.cluster));\n\n\t\t\t// An advertisement is updated in place with REQUEST_UPDATE on the stream that\n\t\t\t// already carries it, so read until the stream ends rather than waiting on the\n\t\t\t// close. Nothing else would deliver a re-parented route. What the peer holds\n\t\t\t// is kept current, since an update carries only what changed.\n\t\t\tlet held = msg.cluster;\n\t\t\tconst done = version === Version.DRAFT_16 || legacy;\n\t\t\tfor (;;) {\n\t\t\t\t// Drafts 17+ withdraw by resetting the request with CANCELLED, which ends it like a\n\t\t\t\t// FIN. Any other reset is a failure.\n\t\t\t\tconst ended = await stream.reader.done().catch((err: unknown) => {\n\t\t\t\t\tif (!done && err instanceof StreamError && err.code === StreamCode.Cancel) return true;\n\t\t\t\t\tthrow err;\n\t\t\t\t});\n\t\t\t\tif (ended) break;\n\n\t\t\t\tconst typeId = await stream.reader.u53();\n\t\t\t\tif (done && typeId === PublishNamespaceDone.id) {\n\t\t\t\t\tawait PublishNamespaceDone.decode(stream.reader, version);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// A repeated PUBLISH_NAMESPACE lands here too: a second request on the\n\t\t\t\t// stream is the base draft's duplicate request ID.\n\t\t\t\tif (typeId !== PublishNamespaceUpdate.id) {\n\t\t\t\t\tthrow new ProtocolViolation(\n\t\t\t\t\t\t`unexpected message on publish_namespace stream: 0x${typeId.toString(16)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst update = await PublishNamespaceUpdate.decode(stream.reader, version);\n\n\t\t\t\t// The parameters exist only on a session that negotiated the extension;\n\t\t\t\t// anywhere else they are the peer's violation.\n\t\t\t\tif (held === undefined) {\n\t\t\t\t\tif (update.update.hops !== undefined || update.update.cost !== undefined) {\n\t\t\t\t\t\tthrow new ProtocolViolation(\"cluster parameters on a session that negotiated none\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// A different original publisher applies in place too, as it does inline.\n\t\t\t\t\theld = Cluster.apply(held, update.update);\n\t\t\t\t}\n\n\t\t\t\t// A path that now runs through us is unusable, so give it back. The update\n\t\t\t\t// itself is accepted, and reading continues: this stream is the\n\t\t\t\t// advertisement's only channel, so a later clean path arrives here or\n\t\t\t\t// nowhere.\n\t\t\t\tif (this.#reflected(held)) {\n\t\t\t\t\tif (attached) {\n\t\t\t\t\t\tattached = false;\n\t\t\t\t\t\tconsole.debug(`publish_namespace now loops back, detaching: broadcast=${path}`);\n\t\t\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t\t\t}\n\t\t\t\t} else if (!attached) {\n\t\t\t\t\t// Re-attach: a clean path replaced the reflected one we detached from.\n\t\t\t\t\tattached = true;\n\t\t\t\t\tthis.#attachAnnounce(path, this.#route(held));\n\t\t\t\t} else {\n\t\t\t\t\tthis.#updateAnnounce(path, this.#route(held));\n\t\t\t\t}\n\n\t\t\t\t// Nothing here can fail to apply, so every update is acknowledged. A leaf\n\t\t\t\t// routes nothing, so a repricing changes nothing it holds; consumers still\n\t\t\t\t// hear the new route so a forwarder can reprice.\n\t\t\t\tawait stream.writer.u53(RequestOk.id);\n\t\t\t\tawait new RequestOk({}).encode(stream.writer, version);\n\t\t\t}\n\t\t} finally {\n\t\t\tif (legacy) this.#legacyRequests.delete(path);\n\n\t\t\t// Give back exactly what was taken: a request that never got its OK out never\n\t\t\t// referenced the path, and retracting there would drop someone else's count.\n\t\t\tif (attached) {\n\t\t\t\tthis.#detachAnnounce(path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handles an incoming PUBLISH on a bidi stream.\n\t * We don't support reverse publish, so send error.\n\t *\n\t * @internal\n\t */\n\tasync runPublish(msg: Publish, stream: Stream) {\n\t\tconst version = this.#session.version;\n\n\t\t// We decline the method itself rather than this particular track, which would be\n\t\t// UNINTERESTED.\n\t\t//\n\t\t// The alias the message carries is deliberately not recorded. Nothing will ever bind\n\t\t// it, and a rejected request has no lifetime of ours to hang the cleanup on.\n\t\tconst errorCode = toRequestCode(\"not_supported\", \"publish\", version);\n\n\t\tif (version === Version.DRAFT_14) {\n\t\t\tawait stream.writer.u53(PublishError.id);\n\t\t\tconst err = new PublishError({\n\t\t\t\trequestId: msg.requestId,\n\t\t\t\terrorCode,\n\t\t\t\treasonPhrase: \"publish not supported\",\n\t\t\t});\n\t\t\tawait err.encode(stream.writer, version);\n\t\t} else {\n\t\t\tawait stream.writer.u53(RequestError.id);\n\t\t\tconst err = new RequestError({\n\t\t\t\trequestId: version === Version.DRAFT_15 || version === Version.DRAFT_16 ? msg.requestId : undefined,\n\t\t\t\terrorCode,\n\t\t\t\treasonPhrase: \"publish not supported\",\n\t\t\t});\n\t\t\tawait err.encode(stream.writer, version);\n\t\t}\n\t\tstream.close();\n\t}\n\n\t/**\n\t * Handles an ObjectStream message (group + frames on uni stream).\n\t *\n\t * @internal\n\t */\n\tasync handleGroup(group: GroupMessage, stream: Reader) {\n\t\tif (group.subGroupId !== 0) {\n\t\t\tthrow new Error(\"subgroups are not supported\");\n\t\t}\n\n\t\tlet subscription: Subscription;\n\t\ttry {\n\t\t\t// The control message establishing this alias can arrive after the data stream.\n\t\t\tsubscription = await this.#aliases.get(group.trackAlias);\n\t\t} catch (err: unknown) {\n\t\t\tconst e = await sessionCause(this.#quic, err);\n\t\t\t// Ours: we cancelled the subscription and the publisher has not stopped yet.\n\t\t\t// Anything else on this alias is the publisher sending data for a track it never\n\t\t\t// acknowledged, which is worth seeing.\n\t\t\tif (e instanceof RetiredTrackAlias) {\n\t\t\t\tconsole.debug(`dropping group for a cancelled subscription: alias=${group.trackAlias}`);\n\t\t\t}\n\t\t\tstream.stop(e);\n\t\t\treturn;\n\t\t}\n\n\t\tconst { track, tail } = subscription;\n\t\t// Every data stream counts toward PUBLISH_DONE's Stream Count, even one dropped below.\n\t\tconst read = tail.open(group.groupId);\n\n\t\t// Created on the first object rather than the header: an END_OF_TRACK at object 0\n\t\t// means the group does not exist at all.\n\t\tlet producer: netGroup.Producer | undefined;\n\t\tconst open = () => {\n\t\t\tif (!producer) {\n\t\t\t\t// The publisher contradicted its own end, which no later group can repair.\n\t\t\t\tif (subscription.end !== undefined && group.groupId >= subscription.end) {\n\t\t\t\t\tthrow new ProtocolViolation(\n\t\t\t\t\t\t`group ${group.groupId} is at or past the declared end ${subscription.end}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tproducer = new netGroup.Producer(group.groupId);\n\t\t\t\ttrack.writeGroup(producer);\n\t\t\t}\n\t\t\treturn producer;\n\t\t};\n\n\t\ttry {\n\t\t\t// FIRST_OBJECT clear is the publisher's claim that the stream starts partway\n\t\t\t// through the group. The first Object ID is absolute either way, and IDs start\n\t\t\t// at 0, so a clear bit on object 0 is still the whole group. Any other first ID,\n\t\t\t// or a stream with no object, has a hole at the front: drop it and pick up at\n\t\t\t// the next group.\n\t\t\t//\n\t\t\t// Drafts before the bit cannot say this in the header, so the first ID is the only\n\t\t\t// signal: a non-zero one is the same hole and is dropped the same way, but an empty\n\t\t\t// stream there is still a group. A later gap, or a header that claimed the group\n\t\t\t// starts at object 0, still fails it: `Frame.decode` refuses every non-zero delta.\n\t\t\tconst legacy = !hasFirstObjectBit(this.#session.version);\n\t\t\tif (!group.flags.firstObject || legacy) {\n\t\t\t\tlet id: bigint | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tid = await stream.peekU62();\n\t\t\t\t} catch (err: unknown) {\n\t\t\t\t\tif (!(err instanceof UnexpectedEnd)) throw err;\n\t\t\t\t}\n\t\t\t\tif (id !== 0n && !(legacy && id === undefined)) {\n\t\t\t\t\tconsole.debug(`dropping a group with no head: alias=${group.trackAlias} group=${group.groupId}`);\n\t\t\t\t\tstream.stop(new Error(\"a group must start at object 0\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The alias binds after SUBSCRIBE_OK commits the track property; an omitted\n\t\t\t// header priority inherits it (draft-21 section 10.4).\n\t\t\tif (!group.flags.hasPriority) group.publisherPriority = toWire((await track.info()).priority);\n\n\t\t\tconst decode = (c: Cursor) => Frame.decode(c, group.flags, this.#timescales.get(group.trackAlias));\n\t\t\tfor (;;) {\n\t\t\t\t// Every object already buffered is written without an await, so the reader wakes\n\t\t\t\t// once per batch rather than once per object. Only the group's own stream ends it:\n\t\t\t\t// a track that closes first has already closed (or aborted) this group through its\n\t\t\t\t// cache.\n\t\t\t\tconst frame =\n\t\t\t\t\tstream.tryDecode(decode) ??\n\t\t\t\t\t(await (producer\n\t\t\t\t\t\t? race([stream.decodeMaybe(decode), producer.closed])\n\t\t\t\t\t\t: stream.decodeMaybe(decode)));\n\t\t\t\tif (!frame || frame instanceof Error) break;\n\n\t\t\t\tif (frame.endOfTrack) {\n\t\t\t\t\t// No object at or past this location exists: after the group's last object\n\t\t\t\t\t// the track ends with it, and at object 0 it ends before it.\n\t\t\t\t\tconst end = producer ? group.groupId + 1 : group.groupId;\n\t\t\t\t\tproducer?.close();\n\t\t\t\t\ttry {\n\t\t\t\t\t\ttrack.finishAt(end);\n\t\t\t\t\t} catch (err: unknown) {\n\t\t\t\t\t\tthrow new ProtocolViolation(`invalid END_OF_TRACK: ${reason(error(err))}`);\n\t\t\t\t\t}\n\t\t\t\t\tsubscription.end ??= end;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (frame.payload === undefined) break;\n\n\t\t\t\topen().writeFrame({ payload: frame.payload, timestamp: frame.timestamp ?? Timestamp.now() });\n\t\t\t}\n\n\t\t\t// A group with no objects still exists.\n\t\t\topen().close();\n\t\t} catch (err: unknown) {\n\t\t\tconst e = await sessionCause(this.#quic, err);\n\t\t\tif (e instanceof ProtocolViolation) {\n\t\t\t\t// The publisher broke the track's end, which no later group can repair.\n\t\t\t\tproducer?.close(e);\n\t\t\t\ttrack.close(e);\n\t\t\t} else {\n\t\t\t\t// A stream that fails before its first object still names a group, which the\n\t\t\t\t// reader sees fail rather than silently go missing.\n\t\t\t\ttry {\n\t\t\t\t\topen().close(e);\n\t\t\t\t} catch {\n\t\t\t\t\t// The track has already closed or ended below this group.\n\t\t\t\t}\n\t\t\t}\n\t\t\tstream.stop(e);\n\t\t} finally {\n\t\t\tread();\n\t\t}\n\t}\n}\n\n/**\n * A broadcast consumed from a moq-transport session. Track info is resolved by the\n * subscribe path (the inherited `resolveTrackInfo`), but the protocol has no one-shot\n * group fetch, so `track.Consumer.fetchGroup()` is rejected.\n */\nclass ConsumeBroadcast extends broadcast.Consumer {\n\tconstructor(state?: never) {\n\t\tsuper(state);\n\t\toverrideBroadcastWire(this, {\n\t\t\tfetchGroup: () => Promise.reject(new Error(\"fetch group is not supported for moq-transport\")),\n\t\t});\n\t}\n\n\t// Preserve the subclass when the consume cache shares this broadcast across callers.\n\toverride clone(): ConsumeBroadcast {\n\t\treturn new ConsumeBroadcast(this.shareState());\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moq/net",
3
3
  "type": "module",
4
- "version": "0.4.5",
4
+ "version": "0.4.6",
5
5
  "description": "The networking layer for Media over QUIC: real-time pub/sub with built-in caching, fan-out, and prioritization.",
6
6
  "license": "(MIT OR Apache-2.0)",
7
7
  "repository": {