diff --git a/dart/moq/lib/src/aliases.dart b/dart/moq/lib/src/aliases.dart index a6d38e1a683..503094fb577 100644 --- a/dart/moq/lib/src/aliases.dart +++ b/dart/moq/lib/src/aliases.dart @@ -89,9 +89,8 @@ typedef Instance = MoqInstance; /// A route over a prefix: its origin-relative path, required wildcard captures (empty without wildcards), and route metadata. typedef Announce = MoqAnnounce; -/// What an [AnnounceConsumer] yields: [AnnounceEventPresent], -/// [AnnounceEventUnavailable], [AnnounceEventAvailable], [AnnounceEventAbsent], -/// or [AnnounceEventOffline]. +/// What an [AnnounceConsumer] yields: [AnnounceEventPresent] or +/// [AnnounceEventAbsent]. /// /// Another publisher instance taking a path over keeps it present: hold a /// [Following] to see the broadcast change. @@ -100,21 +99,10 @@ typedef AnnounceEvent = MoqAnnounceEvent; /// A route now covers the path, which was absent; it may arrive unavailable. typedef AnnounceEventPresent = PresentMoqAnnounceEvent; -/// The present path lost every usable path to its origin but may recover one: -/// it stays present while requests for it may fail. -typedef AnnounceEventUnavailable = UnavailableMoqAnnounceEvent; - -/// The present path recovered a usable path: request it again. -typedef AnnounceEventAvailable = AvailableMoqAnnounceEvent; - -/// The origin withdrew the path; carries its last route. +/// No route covers the path any more, whether its origin withdrew it or this +/// side let go of it; carries its last route. typedef AnnounceEventAbsent = AbsentMoqAnnounceEvent; -/// This side let go of the path, which its origin may still serve: the session -/// it arrived on closed, or the network lost every path to it. Carries its last -/// route. -typedef AnnounceEventOffline = OfflineMoqAnnounceEvent; - /// The write side of a broadcast: publish tracks into it. typedef BroadcastProducer = MoqBroadcastProducer; diff --git a/dart/moq/lib/src/client.dart b/dart/moq/lib/src/client.dart index 36ee3f65a15..256d2107dee 100644 --- a/dart/moq/lib/src/client.dart +++ b/dart/moq/lib/src/client.dart @@ -222,7 +222,7 @@ final class Moq { MoqRoute route(String path, {RouteOptions? options}) => session.publish().route(path: path, options: options ?? RouteOptions()); - /// List the paths matching [options] as each becomes present, absent, or offline, or changes availability; + /// List the paths matching [options] as each becomes present or absent; /// prefixes stay relative to the origin. /// /// Listen to `announced(...).updates()` for a [Stream] of [AnnounceEvent] diff --git a/demo/boy/src/element.ts b/demo/boy/src/element.ts index 4238c85646b..08e67d311bb 100644 --- a/demo/boy/src/element.ts +++ b/demo/boy/src/element.ts @@ -222,7 +222,6 @@ export default class MoqBoy extends HTMLElement { if (!capture?.isLiteral) continue; const id = capture.text; - const gone = entry.kind === "absent" || entry.kind === "offline"; if (entry.kind === "present" && !this.#sessions.has(id)) { const config: GameConfig = { sessionId: id, @@ -235,7 +234,7 @@ export default class MoqBoy extends HTMLElement { const game = new Game(config); this.#sessions.set(id, game); this.games.set(new Map(this.#sessions)); - } else if (gone) { + } else if (entry.kind === "absent") { const game = this.#sessions.get(id); if (game) { game.close(); diff --git a/demo/carla/sim/moq_carla_sim/publish.py b/demo/carla/sim/moq_carla_sim/publish.py index f3eec270075..4ce1275e69b 100644 --- a/demo/carla/sim/moq_carla_sim/publish.py +++ b/demo/carla/sim/moq_carla_sim/publish.py @@ -364,11 +364,10 @@ async def run(self, client: moq.Client, prefix: str) -> None: async for event in announced: # Every variant carries `announce`; uniffi's stubs type only the enum. driver = event.announce.captures[0] # pyright: ignore[reportAttributeAccessIssue] - if isinstance(event, (moq.AnnounceEventAbsent, moq.AnnounceEventOffline)): + if isinstance(event, moq.AnnounceEventAbsent): task = drivers.pop(driver, None) if task is not None: task.cancel() - # Availability changes reach the follow, which waits them out. elif isinstance(event, moq.AnnounceEventPresent) and driver not in drivers: drivers[driver] = asyncio.create_task( self._follow(client, driver, f"{prefix}/{driver}"), name=f"driver:{driver}" diff --git a/demo/carla/sim/tests/conftest.py b/demo/carla/sim/tests/conftest.py index 4bc450ba493..4fa49b5e042 100644 --- a/demo/carla/sim/tests/conftest.py +++ b/demo/carla/sim/tests/conftest.py @@ -25,10 +25,6 @@ class AnnounceEventAbsent(AnnounceEvent): pass -class AnnounceEventOffline(AnnounceEvent): - pass - - class SnapshotProducer: """Records every published value; demand comes from the wrapped track.""" @@ -53,7 +49,6 @@ def update(self, value: object, timestamp: object) -> None: moq.is_shutdown = lambda err: False moq.AnnounceEventPresent = AnnounceEventPresent moq.AnnounceEventAbsent = AnnounceEventAbsent -moq.AnnounceEventOffline = AnnounceEventOffline moq.Timestamp = lambda value, scale: SimpleNamespace(value=value, scale=scale) moq.TrackInfo = lambda **kwargs: SimpleNamespace(**kwargs) diff --git a/demo/carla/sim/tests/test_publish.py b/demo/carla/sim/tests/test_publish.py index b441663ad4b..4a3f0e7960e 100644 --- a/demo/carla/sim/tests/test_publish.py +++ b/demo/carla/sim/tests/test_publish.py @@ -228,9 +228,6 @@ async def present(self, driver: str) -> None: async def absent(self, driver: str) -> None: await self.send(moq.AnnounceEventAbsent(SimpleNamespace(captures=[driver]))) - async def offline(self, driver: str) -> None: - await self.send(moq.AnnounceEventOffline(SimpleNamespace(captures=[driver]))) - class Run: """One driver run's broadcast: its `control` track hands out what `send` queues.""" @@ -359,13 +356,13 @@ async def scenario(relay: Relay, drivers, commands: asyncio.Queue, gate: Drive) asyncio.run(watching(scenario)) -def test_a_driver_this_side_lets_go_of_loses_the_lease() -> None: +def test_a_driver_that_returns_is_followed_afresh() -> None: async def scenario(relay: Relay, drivers, commands: asyncio.Queue, gate: Drive) -> None: await relay.announcements.present("abc") await relay.following("abc").run(DRIVE) await next_command(commands, gate) - await relay.announcements.offline("abc") + await relay.announcements.absent("abc") assert (await next_command(commands, gate)).kind == "driver_left" assert gate.driver is None diff --git a/doc/concept/identity.md b/doc/concept/identity.md index c1e958adf06..199a612d9ab 100644 --- a/doc/concept/identity.md +++ b/doc/concept/identity.md @@ -139,12 +139,9 @@ goes offline; JavaScript `origin.follow(path)`, whose `active` is undefined between instances; the moq-ffi bindings `follow(path)`, whose `available()` returns null once the path goes offline; and C `moq_origin_follow`, whose callback reports `MOQ_FOLLOW_EVENT_OFFLINE`. -An announcement listing (`announced()`) reports a path becoming present, -unavailable while the network holds its route without a path to it, available -again once it recovers one, and finally absent once the origin withdraws it or -offline once this side lets go of it, which says nothing of whether the origin -still serves it. An instance change keeps it present, so a reader that needs -one holds a follower. `@moq/watch`, `moq play`, and `moqsrc` follow this way, and +An announcement listing (`announced()`) only reports a path becoming present or +absent, whether the origin withdrew it or this side let go of it: an instance +change keeps it present, so a reader that needs one holds a follower. `@moq/watch`, `moq play`, and `moqsrc` follow this way, and `moq export ts --stitch` can splice a replacement as a marked program switch. A request failing is never the signal to restart; the follower handing out a new broadcast is. Nor is a track's error kind: a track withdrawn diff --git a/doc/lib/go/index.md b/doc/lib/go/index.md index 34b5e212a5a..ebc5d39d074 100644 --- a/doc/lib/go/index.md +++ b/doc/lib/go/index.md @@ -70,7 +70,7 @@ for event, err := range announced.All(ctx) { // handed each new run, with Available returning nil while the path is offline. present, ok := event.(moq.AnnounceEventPresent) if !ok { - continue // absent, offline, or a change in availability + continue // AnnounceEventAbsent } ann := present.Announce // Prefix stays origin-relative; Captures is a list, empty without wildcards. diff --git a/doc/lib/kt/index.md b/doc/lib/kt/index.md index bda75cf4e55..999ac115092 100644 --- a/doc/lib/kt/index.md +++ b/doc/lib/kt/index.md @@ -59,8 +59,7 @@ Moq.connect("https://relay.example.com", ClientConfig(tls = ClientTls(roots = li // each new run, or null once it goes offline. val announce = when (event) { is AnnounceEventPresent -> event.announce - // Absent, offline, or a change in availability. - else -> return@collect + is AnnounceEventAbsent -> return@collect } // Prefixes stay origin-relative; captures is a list of wildcard matches, empty without wildcards. println(announce.captures) diff --git a/doc/lib/py/index.md b/doc/lib/py/index.md index df94224b22d..b5ad14751c3 100644 --- a/doc/lib/py/index.md +++ b/doc/lib/py/index.md @@ -50,7 +50,7 @@ async def main(): # A path stays present across publisher restarts: hold client.follow(path) to # be handed each new run, or None once it goes offline. if not isinstance(event, moq.AnnounceEventPresent): - continue # absent, offline, or a change in availability + continue # AnnounceEventAbsent announcement = event.announce print(announcement.captures) # list of wildcard matches, empty without wildcards broadcast = await client.request(announcement.prefix) diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index 542557be0f9..3e36e0a09c4 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -19,7 +19,7 @@ What you use it for, beyond what the concept page already describes: - **Routes report what the mesh filled in.** An announcement's `route` gives its `instance()` and `cost()`; an application sets only `RouteOptions`. The hop chain a relay uses for loop detection stays internal. An origin's own Node ID is `origin::Config::node`, random unless a relay names one. - **Requests can pin an instance.** `consumer.request(path, Some(instance))` resolves only through a route announcing that [publisher instance](/concept/moq-lite#publisher-instances); `None` takes whichever route wins. The resolved consumer names its instance in `info().instance`, pinned or not. `origin.route(path, options)` serves a random instance minted when it is created and kept across `withdraw()` and `announce()`. Unless one is named, a claim moves to a fresh instance each time a job holding its current one ends, and a job takes the claim's. Set one with `RouteOptions::with_instance(instance, epoch)` only for a publisher that continues its timeline across restarts, so its group starts keep rising, and raises the epoch each time. `route.instance()` names it. - **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_priority(origin::Priority::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. After the earlier route keys, requests use the route with the highest priority, on moq-lite 07 the lowest of any link along its path, and fail over to the next; see [multiple CDNs](/concept/moq-lite#multiple-cdns). -- **Request one instance, or follow them all.** `consumer.request(path, None)` resolves the instance serving a path now, and fails `Unroutable` only once discovery has synced with no route for it. `consumer.follow(path, None)` hands out each publisher instance serving a path from `available()`: the first once announced, then each one that takes over, `None` once the path goes offline, and whatever serves it next, like JS `follow(path)`. `consumer.announced()` lists paths as present, then unavailable or available as a held route loses and recovers its path, and finally absent once the origin withdraws one or offline once this side lets go of it, which says nothing of whether the origin still serves it. A broadcast already resolved stays on the old instance until dropped or its route goes. See [identity and recovery](/concept/identity) to choose between following and holding one instance. +- **Request one instance, or follow them all.** `consumer.request(path, None)` resolves the instance serving a path now, and fails `Unroutable` only once discovery has synced with no route for it. `consumer.follow(path, None)` hands out each publisher instance serving a path from `available()`: the first once announced, then each one that takes over, `None` once the path goes offline, and whatever serves it next, like JS `follow(path)`. `consumer.announced()` lists paths as present, then absent once no route covers one, whether the origin withdrew it or this side let go of it. A path whose captures change is reported absent and then present again while a route still covers it. Read a held route's availability from `announce.route.available()` or a `follow`. A broadcast already resolved stays on the old instance until dropped or its route goes. See [identity and recovery](/concept/identity) to choose between following and holding one instance. - **Discovery follows what you watch.** A client session asks the relay for announcements only under the prefixes its subscribe origin's readers watch, with `announced()`, `request`, or `follow`, stops asking about a prefix 2s after nothing at or beneath it is watched, and asks again on reconnect. A broadcast resolved through a discovered route keeps its path watched until dropped. `request` owns discovery of its path, so no separate watch is needed. A server session, or a client fed into an origin handle marked `with_link(origin::Link::Peer)` or `Link::Upstream`, asks for everything it may, so a relay discovers everything. An HTTP gateway (the moq-hls `Server`, the moq-webrtc WHEP router) watches its whole scope while it lives, so the paths its callers name never open a request each. moq-lite-03/04 sessions, whose announcements mark no initial set, still ask for everything. - **Relay by opting into proxying.** On moq-lite-07 (`moq-lite-07-wip`, opt-in) a session sends its peer only the routes to its origin's own claims, so an application never becomes transit for anyone else. A relay built on the library marks the handle it publishes with `origin.clone().with_proxy(true)` to carry what it learned from other peers too; `moq-relay` does so for every session. Older versions advertise everything either way. - **One track per name.** Concurrent subscriptions share one request and producer. A group is keyed by its start, its first frame's timestamp in the track's timescale, and starts only rise. An untimed track has no timescale, so its frames carry `Timestamp::unscaled(key)`, the group's key, and a timestamp's `scale()` is `None`: conversions such as `as_millis()` fail on it, and it compares with no scaled timestamp. Every frame write takes a `Timestamp`, and one that doesn't match its track is refused with `TimestampMismatch`. `append_group(start)` opens the next one at a `Timestamp`, converted into the track's timescale as a frame's is (`Timestamp::unscaled(key)` on an untimed track), declaring the range below it skipped; `create_group` places one without declaring anything. The broadcast keeps nothing of an ended track, and a name always means the same content, so a producer that replaces it starts its groups past its predecessor's. Readers of an aborted track resume onto the replacement when they read through an origin request, whose route always names an instance; otherwise their subscription ends with the error. diff --git a/go/wrapper/README.md b/go/wrapper/README.md index 525a15c0421..f8841a0293b 100644 --- a/go/wrapper/README.md +++ b/go/wrapper/README.md @@ -56,8 +56,6 @@ for event, err := range announced.All(ctx) { fmt.Println("broadcast online", event.Announce.Prefix) case moq.AnnounceEventAbsent: fmt.Println("broadcast ended", event.Announce.Prefix) - case moq.AnnounceEventOffline: - fmt.Println("broadcast offline", event.Announce.Prefix) } } ``` diff --git a/go/wrapper/origin.go b/go/wrapper/origin.go index 1f9f36b642d..587c4a6befb 100644 --- a/go/wrapper/origin.go +++ b/go/wrapper/origin.go @@ -283,7 +283,7 @@ type AnnounceOptions struct { } // Announced lists the paths under a literal prefix matching an optional pattern filter, as each -// becomes present, absent, or offline, or changes availability. To see another publisher instance take a path over, use Follow. +// becomes present or absent. To see another publisher instance take a path over, use Follow. func (o *OriginConsumer) Announced(options AnnounceOptions) (*AnnounceConsumer, error) { inner, err := o.inner.Announced(ffi.MoqAnnounceConfig{ Prefix: options.Prefix, @@ -322,7 +322,7 @@ func (o *OriginConsumer) Request(ctx context.Context, path string, instance *Ins return &BroadcastConsumer{inner: inner}, nil } -// AnnounceConsumer is a listing of paths, each present, absent, or offline. +// AnnounceConsumer is a listing of paths, each present or absent. type AnnounceConsumer struct { inner *ffi.MoqAnnounceConsumer } diff --git a/go/wrapper/types.go b/go/wrapper/types.go index da344b60df8..e390cd00f50 100644 --- a/go/wrapper/types.go +++ b/go/wrapper/types.go @@ -41,22 +41,14 @@ type ( // resolve a path with [OriginConsumer.Request]. Captures is a required slice, // empty when the filter has no wildcards. Announce = ffi.MoqAnnounce - // AnnounceEvent is what an AnnounceConsumer yields: AnnounceEventPresent, AnnounceEventUnavailable, - // AnnounceEventAvailable, AnnounceEventAbsent, or AnnounceEventOffline. + // AnnounceEvent is what an AnnounceConsumer yields: AnnounceEventPresent or AnnounceEventAbsent. // Another publisher instance taking a path over keeps it present; see it with [OriginConsumer.Follow]. AnnounceEvent = ffi.MoqAnnounceEvent // AnnounceEventPresent reports a route now covering a path that was absent; it may arrive unavailable. AnnounceEventPresent = ffi.MoqAnnounceEventPresent - // AnnounceEventUnavailable reports that a present path lost every usable path to its origin but may - // recover one: it stays present while requests for it may fail. - AnnounceEventUnavailable = ffi.MoqAnnounceEventUnavailable - // AnnounceEventAvailable reports that a present path recovered a usable path: request it again. - AnnounceEventAvailable = ffi.MoqAnnounceEventAvailable - // AnnounceEventAbsent reports that the origin withdrew a path, carrying its last route. + // AnnounceEventAbsent reports that no route covers a path any more, whether its origin withdrew it + // or this side let go of it, carrying its last route. AnnounceEventAbsent = ffi.MoqAnnounceEventAbsent - // AnnounceEventOffline reports that this side let go of a path, carrying its last route: the session - // it arrived on closed, or the network lost every path to it, so its origin may still serve it. - AnnounceEventOffline = ffi.MoqAnnounceEventOffline // Range is a span of a track to deliver: from Start up to End, or onward when End is nil. // A relative start is the first frame of its group, a relative end includes its whole // group, and an absolute end is exclusive. diff --git a/js/net/api/index.api.md b/js/net/api/index.api.md index 2b726644379..386c31fc7a0 100644 --- a/js/net/api/index.api.md +++ b/js/net/api/index.api.md @@ -15,7 +15,7 @@ export namespace Announce { get synced(): Signals.Getter; } export type Event = { - kind: "present" | "unavailable" | "available" | "absent" | "offline"; + kind: "present" | "absent"; } & Announce.Announce; export interface Options { covering?: boolean; diff --git a/js/net/src/announced.test.ts b/js/net/src/announced.test.ts index 7315a1e32b8..6c413d0ca92 100644 --- a/js/net/src/announced.test.ts +++ b/js/net/src/announced.test.ts @@ -68,14 +68,14 @@ test("a listing shows a route's facts, never its epoch, hops, credential, or dra expect(Object.keys(event?.route ?? {}).sort()).toEqual(["available", "cost", "instance"]); }); -test("a listing reports availability flips and tells an offline path from an absent one", async () => { +test("a listing stays quiet as availability flips and reports a let-go path absent", async () => { const producer = new Announce.Producer(); const listing = Announce.list(producer.consume()); const route = WireRoute.normalize({ instance: Instance.random() }); const held = { ...route, available: false }; producer.append({ prefix: p("a"), captures: undefined, kind: "start", route: held }); - // A re-price that leaves availability as it was is not reported. + // Neither a re-price nor an availability flip is reported. producer.append({ prefix: p("a"), captures: undefined, kind: "update", route: { ...held, cost: 3n } }); producer.append({ prefix: p("a"), captures: undefined, kind: "update", route }); producer.append({ prefix: p("a"), captures: undefined, kind: "restart", route: held }); @@ -84,18 +84,11 @@ test("a listing reports availability flips and tells an offline path from an abs producer.append({ prefix: p("b"), captures: undefined, kind: "end", route }); const seen = []; - for (let i = 0; i < 6; i++) { + for (let i = 0; i < 4; i++) { const event = await listing.next(); seen.push(`${event?.kind} ${event?.prefix} ${event?.route.available}`); } - expect(seen).toEqual([ - "present a false", - "available a true", - "unavailable a false", - "offline a false", - "present b true", - "absent b true", - ]); + expect(seen).toEqual(["present a false", "absent a false", "present b true", "absent b true"]); }); test("the consumer is an async iterable of the same events", async () => { diff --git a/js/net/src/announced.ts b/js/net/src/announced.ts index 8a178607296..05c4bea0a95 100644 --- a/js/net/src/announced.ts +++ b/js/net/src/announced.ts @@ -37,23 +37,18 @@ export interface Announce { export type Routed = Omit & { route: WireRoute }; /** - * What an announcement listing yields: a path becoming present, absent, or offline, or its - * availability changing. + * What an announcement listing yields: a path becoming present or absent. * * `present`: a route now covers the path, which was absent; it may arrive unavailable (see - * {@link RouteInfo.available}). `unavailable`: the present path lost every usable path to its - * origin but may recover one, so it stays present while requests for it may fail. - * `available`: it recovered one: request it again. `absent`: the origin withdrew the path, and - * no route covers it any more. `offline`: this side let go of the path, and no route covers it - * any more: the session it arrived on closed, or the network lost every path to it, so its - * origin may still serve it. Both carry its last advertised route. + * {@link RouteInfo.available}). `absent`: no route covers the path any more, whether its origin + * withdrew it or this side let go of it; carries its last advertised route. * - * Another instance taking a path over keeps it present: follow it with the origin's - * `follow(path)` to see the broadcast change. + * Another instance taking a path over keeps it present, and a change in availability is not + * reported: follow it with the origin's `follow(path)` to see the broadcast change. * * @public */ -export type Event = { kind: "present" | "unavailable" | "available" | "absent" | "offline" } & Announce; +export type Event = { kind: "present" | "absent" } & Announce; /** * Every change to a route, for code that forwards or routes them. @@ -297,8 +292,7 @@ export class Routes { let makeConsumer: (routes: Routes) => Consumer; /** - * The paths announced under a scope, each reported as it becomes present, absent, or offline, - * and as its availability changes. + * The paths announced under a scope, each reported as it becomes present or absent. * * Created internally: obtain one from an origin or the connection's `announced(scope)`. * @@ -306,8 +300,6 @@ let makeConsumer: (routes: Routes) => Consumer; */ export class Consumer { #routes: Routes; - // The present paths last reported unavailable, bounded by the present set. - #unavailable = new Set(); private constructor(routes: Routes) { this.#routes = routes; @@ -350,24 +342,9 @@ export class Consumer { const event = await this.#routes.next(); if (!event) return undefined; const { kind, prefix, captures } = event; + if (kind === "update" || kind === "restart") continue; const route = routeInfo(event.route); - switch (kind) { - case "start": - if (!route.available) this.#unavailable.add(prefix); - return { kind: "present", prefix, captures, route }; - case "update": - case "restart": { - const was = !this.#unavailable.has(prefix); - if (was === route.available) continue; - if (route.available) this.#unavailable.delete(prefix); - else this.#unavailable.add(prefix); - return { kind: route.available ? "available" : "unavailable", prefix, captures, route }; - } - case "end": - case "offline": - this.#unavailable.delete(prefix); - return { kind: kind === "end" ? "absent" : "offline", prefix, captures, route }; - } + return { kind: kind === "start" ? "present" : "absent", prefix, captures, route }; } } @@ -381,8 +358,7 @@ export class Consumer { } /** - * The listing over a route stream: only paths becoming present, absent, or offline, and their - * availability changing. + * The listing over a route stream: only paths becoming present or absent. * * @internal */ diff --git a/js/room/src/room.ts b/js/room/src/room.ts index 8176805a5c3..a4a0387f2c2 100644 --- a/js/room/src/room.ts +++ b/js/room/src/room.ts @@ -95,10 +95,9 @@ export class Room { const local = this.identity.peek(); if (local && parsed.identity === local) continue; - // A held path keeps its participant; only presence changes membership. if (update.kind === "present") { this.#add(parsed.identity, parsed.kind, Moq.Path.from(covered)); - } else if (update.kind === "absent" || update.kind === "offline") { + } else { this.#remove(parsed.identity, parsed.kind); } } diff --git a/js/stats/src/node.ts b/js/stats/src/node.ts index f6dcf7b2eaa..151196297b5 100644 --- a/js/stats/src/node.ts +++ b/js/stats/src/node.ts @@ -31,7 +31,7 @@ export class Nodes { if (!event) return undefined; const node = parseNodePath(this.#prefix, event.prefix); if (node === undefined) continue; - const active = event.kind !== "absent" && event.kind !== "offline"; + const active = event.kind === "present"; return { node, path: event.prefix, active }; } } diff --git a/js/watch/src/broadcast.ts b/js/watch/src/broadcast.ts index 173b5560f0b..05b3672affe 100644 --- a/js/watch/src/broadcast.ts +++ b/js/watch/src/broadcast.ts @@ -61,8 +61,8 @@ function watchCovered( for (;;) { const entry = await announced.next(); if (!entry) break; - if (entry.kind === "absent" || entry.kind === "offline") active.delete(entry.prefix); - else if (entry.kind === "present") active.add(entry.prefix); + if (entry.kind === "absent") active.delete(entry.prefix); + else active.add(entry.prefix); covered.set([...active].some((prefix) => Path.hasPrefix(prefix, path))); } } catch { diff --git a/js/watch/src/echo.test.ts b/js/watch/src/echo.test.ts index dea7d1288d4..2448d7d9272 100644 --- a/js/watch/src/echo.test.ts +++ b/js/watch/src/echo.test.ts @@ -32,8 +32,8 @@ function announced(origin: Origin.Producer): Set { for (;;) { const entry = await listing.next(); if (!entry) break; - if (entry.kind === "absent" || entry.kind === "offline") paths.delete(entry.prefix); - else if (entry.kind === "present") paths.add(entry.prefix); + if (entry.kind === "absent") paths.delete(entry.prefix); + else paths.add(entry.prefix); } })(); return paths; diff --git a/kt/README.md b/kt/README.md index f15067e8d7f..8801272986b 100644 --- a/kt/README.md +++ b/kt/README.md @@ -35,7 +35,6 @@ Moq.connect("https://relay.example.com").use { moq -> // restarts; `moq.follow(path)` hands out each new run, or null once it goes offline. val announce = when (event) { is AnnounceEventPresent -> event.announce - // Absent, offline, or a change in availability. else -> return@collect } // Prefix stays origin-relative; captures reports what * matched. diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt index 9e8faa8ca48..83a3153180d 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt @@ -105,8 +105,7 @@ typealias Following = uniffi.moq.MoqFollowing typealias Announce = uniffi.moq.MoqAnnounce /** - * What an [AnnounceConsumer] yields: [AnnounceEventPresent], [AnnounceEventUnavailable], - * [AnnounceEventAvailable], [AnnounceEventAbsent], or [AnnounceEventOffline]. + * What an [AnnounceConsumer] yields: [AnnounceEventPresent] or [AnnounceEventAbsent]. * * Another publisher instance taking a path over keeps it present: hold a [Following] to see the * broadcast change. @@ -119,23 +118,11 @@ typealias AnnounceEvent = uniffi.moq.MoqAnnounceEvent typealias AnnounceEventPresent = uniffi.moq.MoqAnnounceEvent.Present /** - * The present path lost every usable path to its origin but may recover one: it stays present while - * requests for it may fail. + * No route covers the path any more, whether its origin withdrew it or this side let go of it; + * carries its last route. */ -typealias AnnounceEventUnavailable = uniffi.moq.MoqAnnounceEvent.Unavailable - -/** The present path recovered a usable path: request it again. */ -typealias AnnounceEventAvailable = uniffi.moq.MoqAnnounceEvent.Available - -/** The origin withdrew the path; carries its last route. */ typealias AnnounceEventAbsent = uniffi.moq.MoqAnnounceEvent.Absent -/** - * This side let go of the path, which its origin may still serve: the session it arrived on closed, - * or the network lost every path to it. Carries its last route. - */ -typealias AnnounceEventOffline = uniffi.moq.MoqAnnounceEvent.Offline - // Broadcast / track / group producers and consumers. /** The write side of a broadcast: publish tracks into it. */ typealias BroadcastProducer = uniffi.moq.MoqBroadcastProducer diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt index 77455164974..316df97a99d 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt @@ -27,10 +27,10 @@ internal constructor( session.publish().route(path, options) /** - * List the paths matching [config] as each becomes present, absent, or offline, or changes - * availability; prefixes stay relative to the origin. Collect `announced(config).updates()` for - * a [Flow] of [AnnounceEvent] that cancels the handle when collection ends. A new publisher - * instance keeps its path present, so use [follow] to see it. + * List the paths matching [config] as each becomes present or absent; prefixes stay relative to + * the origin. Collect `announced(config).updates()` for a [Flow] of [AnnounceEvent] that + * cancels the handle when collection ends. A new publisher instance keeps its path present, so + * use [follow] to see it. */ fun announced(config: AnnounceConfig = AnnounceConfig()): AnnounceConsumer = session.consume().announced(config) diff --git a/py/moq-rs/README.md b/py/moq-rs/README.md index c5008c0dc72..1a9bc041562 100644 --- a/py/moq-rs/README.md +++ b/py/moq-rs/README.md @@ -30,7 +30,7 @@ async def main(): async with moq.connect("https://cdn.moq.dev/anon") as client: async for event in client.announced(): if not isinstance(event, moq.AnnounceEventPresent): - continue # absent, offline, or a change in availability + continue # AnnounceEventAbsent # A route covers a prefix and carries no broadcast, so resolve the path. broadcast = await client.request(event.announce.prefix) catalog = await moq.media.catalog(broadcast) @@ -266,7 +266,7 @@ Every handle whose cleanup is `cancel()` is an async context manager, so exiting - `.announce()`, `.withdraw()`, `.set_cost(cost)`, `.set_auth(credential)`. Show, hide, re-price, or swap its request credential (`None` for the session's scope) in place. - `await .requested() → BroadcastRequest | None`, or async iteration. Call `.serve(consumer)` to answer with held content under the claim's continuous group starts, `.route(hidden=..., ...)` for the path's own route, which continues the claim's instance until the job ends and then moves the claim to a fresh one (unless either names an instance: a named claim lends none, and a named job keeps its own), or `.reject(code)` to fail the requester. - **`OriginConsumer`**. Discover broadcasts. - - `.announced(prefix, filter=None) → AnnounceConsumer` (async iterator of `AnnounceEvent`: `AnnounceEventPresent`, `AnnounceEventUnavailable`, `AnnounceEventAvailable`, `AnnounceEventAbsent`, or `AnnounceEventOffline`, each carrying an `Announce` whose `.route.instance` names the stream; another instance taking a path over keeps it present, so `follow` the path to see that); `filter` is a pattern relative to the literal prefix, while each `Announce.prefix` stays origin-relative and `.captures` is a required list of wildcard matches, empty without wildcards + - `.announced(prefix, filter=None) → AnnounceConsumer` (async iterator of `AnnounceEvent`: `AnnounceEventPresent` or `AnnounceEventAbsent`, each carrying an `Announce` whose `.route.instance` names the stream; another instance taking a path over keeps it present, so `follow` the path to see that); `filter` is a pattern relative to the literal prefix, while each `Announce.prefix` stays origin-relative and `.captures` is a required list of wildcard matches, empty without wildcards - `.follow(path, instance=None) → Following` (awaitable, waits until something serves the path, then returns each stream that takes over, or `None` once the path goes offline; an `instance` follows only that stream) - `.request(path, instance=None) → BroadcastConsumer` (awaitable; owns discovery and resolves one stream, or raises once synced without a route; an `instance` refuses any other stream) diff --git a/py/moq-rs/examples/announced.py b/py/moq-rs/examples/announced.py index 451cfef48af..77dc6617c28 100644 --- a/py/moq-rs/examples/announced.py +++ b/py/moq-rs/examples/announced.py @@ -16,7 +16,7 @@ async def run(url: str, prefix: str, insecure: bool) -> None: async for event in client.announced(prefix): if isinstance(event, moq.AnnounceEventPresent): print(f" + {event.announce.prefix}") - elif isinstance(event, (moq.AnnounceEventAbsent, moq.AnnounceEventOffline)): + elif isinstance(event, moq.AnnounceEventAbsent): print(f" - {event.announce.prefix}") diff --git a/py/moq-rs/moq/__init__.py b/py/moq-rs/moq/__init__.py index 867e9931c56..9b25931a568 100644 --- a/py/moq-rs/moq/__init__.py +++ b/py/moq-rs/moq/__init__.py @@ -19,10 +19,7 @@ AnnounceConsumer, AnnounceEvent, AnnounceEventAbsent, - AnnounceEventAvailable, - AnnounceEventOffline, AnnounceEventPresent, - AnnounceEventUnavailable, BroadcastRequest, Claim, Following, @@ -106,10 +103,7 @@ "AnnounceConsumer", "AnnounceEvent", "AnnounceEventAbsent", - "AnnounceEventAvailable", - "AnnounceEventOffline", "AnnounceEventPresent", - "AnnounceEventUnavailable", "AudioCodec", "AudioEncoderInput", "AudioSampleFormat", diff --git a/py/moq-rs/moq/origin.py b/py/moq-rs/moq/origin.py index 99b9bfa827b..917a55a6023 100644 --- a/py/moq-rs/moq/origin.py +++ b/py/moq-rs/moq/origin.py @@ -38,10 +38,8 @@ """ AnnounceEvent = MoqAnnounceEvent -"""What :class:`AnnounceConsumer` yields: :data:`AnnounceEventPresent`, -:data:`AnnounceEventUnavailable`, :data:`AnnounceEventAvailable`, -:data:`AnnounceEventAbsent`, or :data:`AnnounceEventOffline`, each carrying an -:data:`Announce` as ``announce``. +"""What :class:`AnnounceConsumer` yields: :data:`AnnounceEventPresent` or +:data:`AnnounceEventAbsent`, each carrying an :data:`Announce` as ``announce``. Another publisher instance taking a path over keeps it present; hold :meth:`OriginConsumer.follow` to see the broadcast change. @@ -50,19 +48,9 @@ AnnounceEventPresent = MoqAnnounceEvent.PRESENT """A route now covers the path, which was absent; it may arrive unavailable.""" -AnnounceEventUnavailable = MoqAnnounceEvent.UNAVAILABLE -"""The present path lost every usable path to its origin but may recover one: -it stays present while requests for it may fail.""" - -AnnounceEventAvailable = MoqAnnounceEvent.AVAILABLE -"""The present path recovered a usable path: request it again.""" - AnnounceEventAbsent = MoqAnnounceEvent.ABSENT -"""The origin withdrew the path; carries its last route.""" - -AnnounceEventOffline = MoqAnnounceEvent.OFFLINE -"""This side let go of the path, which its origin may still serve: the session it -arrived on closed, or the network lost every path to it. Carries its last route.""" +"""No route covers the path any more, whether its origin withdrew it or this side +let go of it; carries its last route.""" class AnnounceConsumer(_Stream[MoqAnnounceEvent]): diff --git a/quest/m2/outcome-enums/announce.md b/quest/m2/outcome-enums/announce.md deleted file mode 100644 index d633f4f6c99..00000000000 --- a/quest/m2/outcome-enums/announce.md +++ /dev/null @@ -1,34 +0,0 @@ -# [M] Announce listings report present or absent - -## Goal - -An announce listing reports two kinds in every language: a path became -present, or it became absent. `moq_net::announce::Event`, js/net -`Announced.next`, moq-ffi `MoqAnnounceEvent`, and libmoq `moq_announce_kind` -all shrink to those two. A let-go (`Offline`) is reported as absent, and a -route's availability is read from `announce.route.available()` or a -`follow()`, not from the listing. - -## Plan - -Decided 2026-11-18 (maintainer, /quest-plan): ✅ Present / Absent only -(rejected: Present / Absent / Changed, keeping one availability event; keeping -all five kinds with an added `present()` helper). -[moq-dev/moq#8375](https://github.com/moq-dev/moq/pull/8375) added -`Unavailable`, `Available`, and `Offline` on purpose, but no consumer acts on -them: moq-tokio's origin and server, moq-cli's `announced`, `report`, and -`archive`, moq-boy, moq-webrtc, js `room`, and js `watch` each fold -`Absent | Offline` into "gone" and skip the availability kinds. Only examples -and libmoq/moq-ffi forwarding read all five. - -Find the consumers with `rg 'announce::Event|AnnounceEvent|MoqAnnounceEvent|moq_announce_kind'` -and the JS `kind` checks on `Announced.next`. Recommended: in Rust keep a -two-variant enum carrying `Announce`; in moq-ffi, a record -`{ announce, present }` avoids an exhaustive switch in every binding. Check -that nothing on the relay side (origin internals, the lite announce stream) -reads `AnnounceEvent` rather than `RouteEvent`; the wire's let-go handling -from #8375 is not this listing and stays. - -Public API: breaking in moq-net, js/net, moq-ffi and its bindings, and -libmoq; migrate `Absent | Offline` to absent and drop availability arms. -Wire: none. diff --git a/rs/hang/examples/subscribe.rs b/rs/hang/examples/subscribe.rs index 382b7e14dae..38592cdd78d 100644 --- a/rs/hang/examples/subscribe.rs +++ b/rs/hang/examples/subscribe.rs @@ -63,19 +63,6 @@ async fn run_subscribe(consumer: moq_net::origin::Consumer) -> anyhow::Result<() old.abort(); } } - moq_net::announce::Event::Offline(announce) => { - tracing::info!(path = %announce.prefix, "broadcast offline"); - if let Some(old) = playing.take() { - old.abort(); - } - } - // The follow resumes on its own once the path is reachable again. - moq_net::announce::Event::Unavailable(announce) => { - tracing::info!(path = %announce.prefix, "broadcast unreachable"); - } - moq_net::announce::Event::Available(announce) => { - tracing::info!(path = %announce.prefix, "broadcast reachable again"); - } } } anyhow::bail!("origin closed") diff --git a/rs/libmoq/src/api.rs b/rs/libmoq/src/api.rs index d9c6b9b1908..169507c57c5 100644 --- a/rs/libmoq/src/api.rs +++ b/rs/libmoq/src/api.rs @@ -1174,20 +1174,12 @@ pub enum moq_announce_kind { /// A route now covers the path, which was absent. Another instance taking it over keeps it /// present: follow it with [moq_origin_follow] to see the broadcast change. MOQ_ANNOUNCE_KIND_PRESENT = 0, - /// The origin withdrew the path: no route covers it any more. + /// No route covers the path any more, whether its origin withdrew it or this origin let + /// go of it. MOQ_ANNOUNCE_KIND_ABSENT = 1, - /// This origin let go of the path, and no route covers it any more: the session it arrived - /// on closed, or the network lost every path to it. Its origin may still serve it. - MOQ_ANNOUNCE_KIND_OFFLINE = 2, - /// The present path lost every usable path to its origin but may recover one: it stays - /// present while requests for it may fail. - MOQ_ANNOUNCE_KIND_UNAVAILABLE = 3, - /// The present path recovered a usable path: request it again. - MOQ_ANNOUNCE_KIND_AVAILABLE = 4, -} - -/// An announce event from an origin: a path becoming present, absent, or offline, or its -/// availability changing. +} + +/// An announce event from an origin: a path becoming present or absent. #[repr(C)] pub struct moq_announce_event { /// The covered prefix, relative to the origin, NOT NULL terminated @@ -1204,8 +1196,8 @@ pub struct moq_announce_event { /// Which event this is. pub kind: moq_announce_kind, - /// The route serving the prefix. On `MOQ_ANNOUNCE_KIND_ABSENT` and - /// `MOQ_ANNOUNCE_KIND_OFFLINE` it carries the last advertised route. + /// The route serving the prefix. On `MOQ_ANNOUNCE_KIND_ABSENT` it carries the last + /// advertised route. pub route: moq_route_info, } diff --git a/rs/libmoq/src/origin.rs b/rs/libmoq/src/origin.rs index aeefa05c8b0..db2de2af36f 100644 --- a/rs/libmoq/src/origin.rs +++ b/rs/libmoq/src/origin.rs @@ -104,9 +104,6 @@ impl AnnouncedRecord { let (update, kind) = match event { Event::Present(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT), Event::Absent(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_ABSENT), - Event::Offline(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_OFFLINE), - Event::Unavailable(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_UNAVAILABLE), - Event::Available(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_AVAILABLE), }; let captures: Vec<_> = update .captures diff --git a/rs/moq-boy/src/input.rs b/rs/moq-boy/src/input.rs index a077b21028a..dd43966d200 100644 --- a/rs/moq-boy/src/input.rs +++ b/rs/moq-boy/src/input.rs @@ -97,7 +97,7 @@ pub async fn handle_viewers( let _ = cmd_tx.send(Command::Left { viewer }).await; } } - moq_net::announce::Event::Absent(announce) | moq_net::announce::Event::Offline(announce) => { + moq_net::announce::Event::Absent(announce) => { let viewer = announce.prefix.to_string(); // Dropping a join handle leaves its task running, so stop it here. if let Some(old) = readers.remove(&viewer) { @@ -106,8 +106,6 @@ pub async fn handle_viewers( tracing::info!(%viewer, "viewer went offline"); let _ = cmd_tx.send(Command::Left { viewer }).await; } - // The follower resumes on its own once the path is reachable again. - moq_net::announce::Event::Unavailable(_) | moq_net::announce::Event::Available(_) => {} } } anyhow::bail!("viewer origin closed") diff --git a/rs/moq-cli/src/announced.rs b/rs/moq-cli/src/announced.rs index 217d519241b..8ec9b04b934 100644 --- a/rs/moq-cli/src/announced.rs +++ b/rs/moq-cli/src/announced.rs @@ -92,9 +92,7 @@ async fn follow( let (announce, active) = match event { Event::Present(announce) => (announce, true), - Event::Absent(announce) | Event::Offline(announce) => (announce, false), - // The set lists presence; a held path stays listed. - Event::Available(_) | Event::Unavailable(_) => continue, + Event::Absent(announce) => (announce, false), }; let path = announce.prefix.as_str(); diff --git a/rs/moq-cli/src/archive.rs b/rs/moq-cli/src/archive.rs index d04b50d33f4..5268574fdb7 100644 --- a/rs/moq-cli/src/archive.rs +++ b/rs/moq-cli/src/archive.rs @@ -96,15 +96,12 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp old.abort(); } } - moq_net::announce::Event::Absent(announce) | moq_net::announce::Event::Offline(announce) => { + moq_net::announce::Event::Absent(announce) => { if let Some(follower) = followers.remove(&announce.prefix) { follower.abort(); } } - // A follower rides out its path being held. - moq_net::announce::Event::Present(_) - | moq_net::announce::Event::Available(_) - | moq_net::announce::Event::Unavailable(_) => {} + moq_net::announce::Event::Present(_) => {} } continue; } diff --git a/rs/moq-cli/src/report.rs b/rs/moq-cli/src/report.rs index d259e6890ba..87a7e67f6a9 100644 --- a/rs/moq-cli/src/report.rs +++ b/rs/moq-cli/src/report.rs @@ -496,9 +496,7 @@ async fn write_echo( let event = event.context("announcements ended")?; let (announce, active) = match event { moq_net::announce::Event::Present(announce) => (announce, true), - moq_net::announce::Event::Absent(announce) | moq_net::announce::Event::Offline(announce) => (announce, false), - // A reader rides out its path being held. - moq_net::announce::Event::Available(_) | moq_net::announce::Event::Unavailable(_) => continue, + moq_net::announce::Event::Absent(announce) => (announce, false), }; let path = announce.prefix; if !path.has_prefix(&prefix) || !hang::echo::is_echo(&path) { diff --git a/rs/moq-ffi/src/origin.rs b/rs/moq-ffi/src/origin.rs index be6a21a8e70..1333d0a3b3b 100644 --- a/rs/moq-ffi/src/origin.rs +++ b/rs/moq-ffi/src/origin.rs @@ -205,8 +205,7 @@ impl From for MoqAnnounce { } } -/// What a [`MoqAnnounceConsumer`] yields: a path becoming present, absent, or offline, or -/// its availability changing. +/// What a [`MoqAnnounceConsumer`] yields: a path becoming present or absent. /// /// Another publisher instance taking a path over keeps it present: follow it with /// `MoqOriginConsumer::follow` to see the broadcast change. @@ -217,30 +216,12 @@ pub enum MoqAnnounceEvent { /// The announcement that made the path present. announce: MoqAnnounce, }, - /// The present path lost every usable path to its origin but may recover one: it stays - /// present while requests for it may fail. - Unavailable { - /// The announcement, now unavailable. - announce: MoqAnnounce, - }, - /// The present path recovered a usable path: request it again. - Available { - /// The announcement, available again. - announce: MoqAnnounce, - }, - /// The origin withdrew the path: no route covers it any more. Carries its last - /// advertised route. + /// No route covers the path any more, whether its origin withdrew it or this side let go + /// of it. Carries its last advertised route. Absent { /// The announcement that went. announce: MoqAnnounce, }, - /// This origin let go of the path, and no route covers it any more: the session it - /// arrived on closed, or the network lost every path to it. Its origin may still serve - /// it. Carries its last advertised route. - Offline { - /// The announcement that went. - announce: MoqAnnounce, - }, } impl From for MoqAnnounceEvent { @@ -250,18 +231,9 @@ impl From for MoqAnnounceEvent { Event::Present(announce) => Self::Present { announce: announce.into(), }, - Event::Unavailable(announce) => Self::Unavailable { - announce: announce.into(), - }, - Event::Available(announce) => Self::Available { - announce: announce.into(), - }, Event::Absent(announce) => Self::Absent { announce: announce.into(), }, - Event::Offline(announce) => Self::Offline { - announce: announce.into(), - }, } } } diff --git a/rs/moq-net/src/model/announced.rs b/rs/moq-net/src/model/announced.rs index beb550c6253..0afd96bc298 100644 --- a/rs/moq-net/src/model/announced.rs +++ b/rs/moq-net/src/model/announced.rs @@ -1,6 +1,5 @@ //! The paths announced under a scope, each present or absent. -use std::collections::HashSet; use std::task::Poll; use super::origin_impl::{Announce, RouteEvent, RouteKind, Routes}; @@ -12,83 +11,33 @@ pub enum AnnounceEvent { /// A route now covers the path, which was absent. It may arrive unavailable; see /// [`RouteInfo::available`](crate::origin::RouteInfo::available). Present(Announce), - /// The present path's route lost every usable path to its origin but may recover - /// one, so the path stays present while requests for it may fail. - Unavailable(Announce), - /// The present path's route recovered a usable path: request it again. - Available(Announce), - /// The origin withdrew the path: no route covers it any more. Carries its last - /// advertised route. + /// No route covers the path any more, whether its origin withdrew it or this side let + /// go of it. Carries its last advertised route. Absent(Announce), - /// This origin let go of the path, and no route covers it any more: the session it - /// arrived on closed, or the network lost every path to it. Its origin may still - /// serve it. Carries its last advertised route. - Offline(Announce), } /// The paths announced in a scope, each reported as it becomes present or absent. /// -/// A path that another instance takes over stays present, and a route's metadata -/// changing is not reported, except its availability: hold a +/// A path that another instance takes over stays present, and a route's metadata, +/// availability included, changing is not reported: hold a /// [`follow`](crate::origin::Consumer::follow) to see the broadcast change. Created by /// [`Consumer::announced`](crate::origin::Consumer::announced). Drop to unregister. pub struct AnnounceConsumer { routes: Routes, - /// The present paths last reported unavailable, bounded by the present set. - unavailable: HashSet, } impl AnnounceConsumer { pub(super) fn new(routes: Routes) -> Self { - Self { - routes, - unavailable: HashSet::new(), - } + Self { routes } } /// What a route change means for the listing, if anything. - fn list(&mut self, event: RouteEvent) -> Option { - match event { - RouteEvent { - kind: RouteKind::Start, - announce, - } => { - if !announce.route.available() { - self.unavailable.insert(announce.prefix.clone()); - } - Some(AnnounceEvent::Present(announce)) - } - RouteEvent { - kind: RouteKind::Update | RouteKind::Restart, - announce, - } => { - let was = !self.unavailable.contains(&announce.prefix); - match (was, announce.route.available()) { - (true, false) => { - self.unavailable.insert(announce.prefix.clone()); - Some(AnnounceEvent::Unavailable(announce)) - } - (false, true) => { - self.unavailable.remove(&announce.prefix); - Some(AnnounceEvent::Available(announce)) - } - _ => None, - } - } - RouteEvent { - kind: RouteKind::End, - announce, - } => { - self.unavailable.remove(&announce.prefix); - Some(AnnounceEvent::Absent(announce)) - } - RouteEvent { - kind: RouteKind::Offline, - announce, - } => { - self.unavailable.remove(&announce.prefix); - Some(AnnounceEvent::Offline(announce)) - } + fn list(event: RouteEvent) -> Option { + let RouteEvent { kind, announce } = event; + match kind { + RouteKind::Start => Some(AnnounceEvent::Present(announce)), + RouteKind::Update | RouteKind::Restart => None, + RouteKind::End | RouteKind::Offline => Some(AnnounceEvent::Absent(announce)), } } @@ -109,7 +58,7 @@ impl AnnounceConsumer { let Some(event) = std::task::ready!(self.routes.poll_next(waiter)) else { return Poll::Ready(None); }; - if let Some(event) = self.list(event) { + if let Some(event) = Self::list(event) { return Poll::Ready(Some(event)); } } @@ -122,7 +71,7 @@ impl AnnounceConsumer { pub fn try_next(&mut self) -> Option { loop { let event = self.routes.try_next()?; - if let Some(event) = self.list(event) { + if let Some(event) = Self::list(event) { return Some(event); } } @@ -168,7 +117,7 @@ impl futures::Stream for AnnounceConsumer { else { return Poll::Ready(None); }; - if let Some(event) = this.list(event) { + if let Some(event) = Self::list(event) { return Poll::Ready(Some(event)); } } @@ -195,9 +144,6 @@ mod tests { match event { AnnounceEvent::Present(announce) => format!("present {}", announce.prefix), AnnounceEvent::Absent(announce) => format!("absent {}", announce.prefix), - AnnounceEvent::Offline(announce) => format!("offline {}", announce.prefix), - AnnounceEvent::Available(announce) => format!("available {}", announce.prefix), - AnnounceEvent::Unavailable(announce) => format!("unavailable {}", announce.prefix), } } @@ -255,10 +201,10 @@ mod tests { assert_eq!(listed(&mut announced).await, "absent live"); } - /// A held route keeps its path present, reported unavailable and available as it flips; a - /// session losing a route takes its path offline, while a peer's withdrawal ends it. + /// A held route keeps its path present and quiet as its availability flips; a session + /// letting go of a route and a peer withdrawing it both leave the path absent. #[kio::test] - async fn availability_flips_and_offline_is_not_absent() { + async fn availability_is_quiet_and_offline_is_absent() { let origin = Hop::new(1).unwrap().produce(); let mut announced = origin.consume().announced(); let instance = Instance::random(); @@ -271,11 +217,11 @@ mod tests { lost.update(held.clone().with_cost(Cost::new(3))).unwrap(); quiet(&mut announced).await; lost.update(held.clone().with_available(true)).unwrap(); - assert_eq!(listed(&mut announced).await, "available lost"); + quiet(&mut announced).await; lost.update(held.clone()).unwrap(); - assert_eq!(listed(&mut announced).await, "unavailable lost"); + quiet(&mut announced).await; drop(lost); - assert_eq!(listed(&mut announced).await, "offline lost"); + assert_eq!(listed(&mut announced).await, "absent lost"); let ended = origin.forward("ended", held.with_available(true)).unwrap(); assert_eq!(listed(&mut announced).await, "present ended"); diff --git a/rs/moq-tokio/examples/clock.rs b/rs/moq-tokio/examples/clock.rs index 09fc3c12152..f3ce2c3a4b5 100644 --- a/rs/moq-tokio/examples/clock.rs +++ b/rs/moq-tokio/examples/clock.rs @@ -120,12 +120,6 @@ async fn main() -> anyhow::Result<()> { announce::Event::Absent(update) => { tracing::warn!(broadcast = %update.prefix, "broadcast ended, waiting..."); } - announce::Event::Offline(update) | announce::Event::Unavailable(update) => { - tracing::warn!(broadcast = %update.prefix, "broadcast is offline, waiting..."); - } - announce::Event::Available(update) => { - tracing::info!(broadcast = %update.prefix, "broadcast is reachable again"); - } }, res = reconnect.closed() => return Ok(res?), // Drops the previous subscriber on each new announce. diff --git a/rs/moq-tokio/src/origin.rs b/rs/moq-tokio/src/origin.rs index 069028fdd7f..a690c55e3ed 100644 --- a/rs/moq-tokio/src/origin.rs +++ b/rs/moq-tokio/src/origin.rs @@ -42,14 +42,9 @@ mod tests { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { - loop { - return match announced.next().await? { - moq_net::announce::Event::Present(route) => Some((route, true)), - moq_net::announce::Event::Absent(route) | moq_net::announce::Event::Offline(route) => { - Some((route, false)) - } - moq_net::announce::Event::Available(_) | moq_net::announce::Event::Unavailable(_) => continue, - }; + match announced.next().await? { + moq_net::announce::Event::Present(route) => Some((route, true)), + moq_net::announce::Event::Absent(route) => Some((route, false)), } } diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 21100561e9b..32b5ab9b373 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -1849,14 +1849,9 @@ mod tests { /// The next route and whether it is active. #[cfg(unix)] async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { - loop { - return match announced.next().await? { - moq_net::announce::Event::Present(route) => Some((route, true)), - moq_net::announce::Event::Absent(route) | moq_net::announce::Event::Offline(route) => { - Some((route, false)) - } - moq_net::announce::Event::Available(_) | moq_net::announce::Event::Unavailable(_) => continue, - }; + match announced.next().await? { + moq_net::announce::Event::Present(route) => Some((route, true)), + moq_net::announce::Event::Absent(route) => Some((route, false)), } } diff --git a/rs/moq-tokio/tests/integration/backend.rs b/rs/moq-tokio/tests/integration/backend.rs index 36e0677de17..850ddd7aec4 100644 --- a/rs/moq-tokio/tests/integration/backend.rs +++ b/rs/moq-tokio/tests/integration/backend.rs @@ -1169,11 +1169,8 @@ async fn quic_windows() { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { - loop { - return match announced.next().await? { - moq_net::announce::Event::Present(route) => Some((route, true)), - moq_net::announce::Event::Absent(route) | moq_net::announce::Event::Offline(route) => Some((route, false)), - moq_net::announce::Event::Available(_) | moq_net::announce::Event::Unavailable(_) => continue, - }; + match announced.next().await? { + moq_net::announce::Event::Present(route) => Some((route, true)), + moq_net::announce::Event::Absent(route) => Some((route, false)), } } diff --git a/rs/moq-tokio/tests/integration/broadcast.rs b/rs/moq-tokio/tests/integration/broadcast.rs index 3a7be1066d8..053667dd007 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -3628,11 +3628,8 @@ async fn abort_carries_its_code_to_the_peer() { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { - loop { - return match announced.next().await? { - moq_net::announce::Event::Present(route) => Some((route, true)), - moq_net::announce::Event::Absent(route) | moq_net::announce::Event::Offline(route) => Some((route, false)), - moq_net::announce::Event::Available(_) | moq_net::announce::Event::Unavailable(_) => continue, - }; + match announced.next().await? { + moq_net::announce::Event::Present(route) => Some((route, true)), + moq_net::announce::Event::Absent(route) => Some((route, false)), } } diff --git a/rs/moq-webrtc/src/lib.rs b/rs/moq-webrtc/src/lib.rs index 1da2ab22d80..d60de649562 100644 --- a/rs/moq-webrtc/src/lib.rs +++ b/rs/moq-webrtc/src/lib.rs @@ -70,14 +70,9 @@ mod tests { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { - loop { - return match announced.next().await? { - moq_net::announce::Event::Present(route) => Some((route, true)), - moq_net::announce::Event::Absent(route) | moq_net::announce::Event::Offline(route) => { - Some((route, false)) - } - moq_net::announce::Event::Available(_) | moq_net::announce::Event::Unavailable(_) => continue, - }; + match announced.next().await? { + moq_net::announce::Event::Present(route) => Some((route, true)), + moq_net::announce::Event::Absent(route) => Some((route, false)), } } diff --git a/swift/Sources/Moq/Aliases.swift b/swift/Sources/Moq/Aliases.swift index b4bd79483e2..04dae30e246 100644 --- a/swift/Sources/Moq/Aliases.swift +++ b/swift/Sources/Moq/Aliases.swift @@ -63,10 +63,9 @@ public typealias RouteInfo = MoqFFI.MoqRouteInfo /// Resolve a path with `OriginConsumer.request`. public typealias Announce = MoqFFI.MoqAnnounce /// What an `AnnounceConsumer` yields, each carrying an `Announce`: `.present` once a route -/// covers the path, `.unavailable` and `.available` as a present path loses and recovers a -/// usable path to its origin, `.absent` once the origin withdraws it, and `.offline` once this -/// side lets go of it, which its origin may still serve. Another publisher instance taking a -/// path over keeps it present: hold a `Following` to see the broadcast change. +/// covers the path, and `.absent` once none does, whether its origin withdrew it or this side +/// let go of it. Another publisher instance taking a path over keeps it present: hold a +/// `Following` to see the broadcast change. public typealias AnnounceEvent = MoqFFI.MoqAnnounceEvent /// Per-subscription delivery preferences: priority, delay, the ranges of the track to /// deliver, and group ordering. diff --git a/swift/Sources/Moq/Origin.swift b/swift/Sources/Moq/Origin.swift index 5dbaf8fd9ae..9daf2428383 100644 --- a/swift/Sources/Moq/Origin.swift +++ b/swift/Sources/Moq/Origin.swift @@ -216,7 +216,7 @@ public final class OriginConsumer: Sendable { } /// List the paths under a literal prefix matching an optional pattern filter, as each - /// becomes present, absent, or offline, or changes availability. A new publisher instance keeps its path present, so use + /// becomes present or absent. A new publisher instance keeps its path present, so use /// `follow` to see it. Paths with a segment starting with `.` below the prefix are left /// out unless `hidden`. public func announced(prefix: String = "", filter: String? = nil, hidden: Bool = false) throws -> AnnounceConsumer { @@ -239,7 +239,7 @@ public final class OriginConsumer: Sendable { } } -/// A listing of paths as each becomes present, absent, or offline, or changes availability. +/// A listing of paths as each becomes present or absent. /// Iterate directly: /// `for try await event in announced { ... }`. /// The sequence ends when the origin closes; cancelling the consuming task