From 65b12b08190066ac5c3fbdead11cf43ddbb8cdae Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 22:47:42 -0800 Subject: [PATCH 01/21] chore(quest): claim quest/m1/api-audit/route/events.md Quest-Claim: 2e76cee834ff4e3a From 51095dd29a9e9e06e8ca5168e7d22249b7adad5f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 23:14:21 -0800 Subject: [PATCH 02/21] wip(net)!: announce listing, hidden routes(), and Following's end Co-Authored-By: Claude Opus 5.5 --- rs/hang/examples/subscribe.rs | 40 +- rs/moq-audio/src/decode/consumer.rs | 4 +- rs/moq-bench/src/connection.rs | 18 +- rs/moq-boy/src/input.rs | 92 ++-- rs/moq-c/src/api.rs | 35 +- rs/moq-c/src/origin.rs | 22 +- rs/moq-cli/src/announced.rs | 12 +- rs/moq-cli/src/archive.rs | 4 +- rs/moq-cli/src/main.rs | 4 +- rs/moq-cli/src/play/media.rs | 11 +- rs/moq-cli/src/publish.rs | 4 +- rs/moq-cli/src/report.rs | 4 +- rs/moq-cli/src/report/echo_test.rs | 2 +- rs/moq-cli/src/transcode.rs | 21 +- rs/moq-cli/tests/integration/export.rs | 14 +- rs/moq-cli/tests/integration/import.rs | 2 +- rs/moq-cli/tests/integration/instances.rs | 16 +- rs/moq-cli/tests/integration/rtsp.rs | 12 +- rs/moq-e2ee/tests/transport.rs | 2 +- rs/moq-gst/src/source/imp.rs | 76 ++- rs/moq-hls/src/export/mod.rs | 2 +- rs/moq-hls/src/server/mod.rs | 13 +- rs/moq-hls/tests/integration/server.rs | 6 +- rs/moq-mux/src/container/source.rs | 4 +- rs/moq-mux/src/container/ts/export_test.rs | 20 +- rs/moq-mux/src/container/ts/follower.rs | 19 +- rs/moq-mux/src/follow.rs | 112 +--- rs/moq-mux/src/source.rs | 2 +- rs/moq-net-tests/tests/announce_allocs.rs | 4 +- .../tests/integration/ietf_conformance.rs | 2 +- rs/moq-net-tests/tests/integration/refresh.rs | 4 +- rs/moq-net-tests/tests/integration/restart.rs | 54 +- rs/moq-net/benches/announce.rs | 14 +- rs/moq-net/benches/auth.rs | 10 +- rs/moq-net/benches/interests.rs | 10 +- rs/moq-net/benches/memory.rs | 2 +- rs/moq-net/benches/origin.rs | 44 +- rs/moq-net/benches/path.rs | 2 +- rs/moq-net/benches/session/mod.rs | 18 +- rs/moq-net/benches/stats.rs | 4 +- rs/moq-net/benches/synced.rs | 8 +- rs/moq-net/src/auth.rs | 6 +- rs/moq-net/src/fuzz.rs | 2 +- rs/moq-net/src/ietf/publisher.rs | 34 +- rs/moq-net/src/ietf/session.rs | 12 +- rs/moq-net/src/ietf/subscriber.rs | 30 +- rs/moq-net/src/lite/ietf.rs | 2 +- rs/moq-net/src/lite/publisher.rs | 88 ++-- rs/moq-net/src/lite/replay.rs | 14 +- rs/moq-net/src/lite/subscriber.rs | 34 +- rs/moq-net/src/model/announced.rs | 194 +++++++ rs/moq-net/src/model/follow.rs | 206 +++++--- rs/moq-net/src/model/mod.rs | 11 +- rs/moq-net/src/model/origin.rs | 482 +++++++++--------- .../integration/announce_covering_route.rs | 10 +- .../tests/integration/announce_takeover.rs | 28 +- .../tests/integration/announce_to_serve.rs | 6 +- rs/moq-net/tests/integration/auth.rs | 38 +- .../tests/integration/broadcast_close.rs | 2 +- .../tests/integration/catalog_acquisition.rs | 10 +- rs/moq-net/tests/integration/compress.rs | 6 +- rs/moq-net/tests/integration/control_stats.rs | 2 +- rs/moq-net/tests/integration/datagram.rs | 6 +- .../tests/integration/dial_split_horizon.rs | 16 +- rs/moq-net/tests/integration/empty_group.rs | 2 +- rs/moq-net/tests/integration/errored_end.rs | 2 +- rs/moq-net/tests/integration/extensions.rs | 12 +- .../tests/integration/fastest_reader.rs | 2 +- rs/moq-net/tests/integration/fetch_fanout.rs | 2 +- .../tests/integration/fetch_from_feed.rs | 2 +- rs/moq-net/tests/integration/fetch_only.rs | 2 +- .../tests/integration/fetch_pipeline.rs | 4 +- .../integration/finished_broadcast_mock.rs | 2 +- rs/moq-net/tests/integration/finite_relay.rs | 2 +- rs/moq-net/tests/integration/goaway.rs | 6 +- rs/moq-net/tests/integration/group_order.rs | 2 +- .../tests/integration/history_groups.rs | 6 +- .../tests/integration/idle_cancel_refetch.rs | 2 +- rs/moq-net/tests/integration/instance.rs | 12 +- .../tests/integration/late_lower_group.rs | 4 +- .../tests/integration/lazy_discovery.rs | 42 +- rs/moq-net/tests/integration/mesh_withdraw.rs | 32 +- rs/moq-net/tests/integration/model.rs | 2 +- rs/moq-net/tests/integration/multi_cdn.rs | 26 +- rs/moq-net/tests/integration/partial_group.rs | 2 +- rs/moq-net/tests/integration/quiet_catalog.rs | 2 +- rs/moq-net/tests/integration/range_anchors.rs | 2 +- rs/moq-net/tests/integration/range_read.rs | 2 +- .../tests/integration/received_rewind.rs | 4 +- rs/moq-net/tests/integration/rejoin.rs | 28 +- .../tests/integration/relay_upstream_close.rs | 2 +- rs/moq-net/tests/integration/replacement.rs | 14 +- rs/moq-net/tests/integration/request_caps.rs | 4 +- rs/moq-net/tests/integration/route_change.rs | 24 +- rs/moq-net/tests/integration/route_health.rs | 4 +- .../tests/integration/segmented_frame.rs | 2 +- rs/moq-net/tests/integration/session_close.rs | 4 +- rs/moq-net/tests/integration/session_idle.rs | 2 +- rs/moq-net/tests/integration/session_panic.rs | 16 +- rs/moq-net/tests/integration/source_errors.rs | 2 +- rs/moq-net/tests/integration/stream_credit.rs | 2 +- .../tests/integration/subscribe_priority.rs | 2 +- .../tests/integration/subscribe_ranges.rs | 8 +- .../tests/integration/subscribe_tracks.rs | 2 +- .../tests/integration/subscribe_with_track.rs | 2 +- .../tests/integration/subscriber_max_age.rs | 4 +- .../integration/subscription_end_integrity.rs | 6 +- .../tests/integration/support/harness.rs | 4 +- rs/moq-net/tests/integration/support/mod.rs | 10 +- rs/moq-net/tests/integration/synced.rs | 22 +- .../integration/track_abort_over_session.rs | 2 +- .../tests/integration/track_info_cancel.rs | 2 +- .../tests/integration/track_stream_demand.rs | 4 +- rs/moq-net/tests/integration/track_tail.rs | 2 +- rs/moq-net/tests/integration/tracks.rs | 2 +- rs/moq-net/tests/integration/tracks_ietf.rs | 2 +- .../tests/integration/unannounce_release.rs | 2 +- rs/moq-net/tests/integration/warm_backfill.rs | 2 +- rs/moq-net/tests/integration/wide_sequence.rs | 8 +- .../tests/integration/widened_max_age.rs | 4 +- rs/moq-net/tests/integration/zero_copy.rs | 2 +- rs/moq-net/tests/send.rs | 4 +- rs/moq-relay/benches/session.rs | 2 +- rs/moq-relay/src/cluster.rs | 38 +- rs/moq-relay/src/internal.rs | 14 +- rs/moq-relay/src/web.rs | 10 +- rs/moq-relay/tests/drills.rs | 24 +- .../tests/integration/auth_lifetime.rs | 30 +- .../tests/integration/cluster_idle.rs | 6 +- .../tests/integration/cluster_unknown.rs | 16 +- rs/moq-relay/tests/integration/connection.rs | 18 +- rs/moq-relay/tests/integration/embed.rs | 14 +- .../tests/integration/goaway_cluster.rs | 30 +- .../tests/integration/hidden_cluster.rs | 4 +- .../tests/integration/public_rules.rs | 4 +- rs/moq-relay/tests/integration/refusals.rs | 4 +- .../tests/integration/runtime_uring.rs | 20 +- .../tests/integration/runtime_workers.rs | 14 +- rs/moq-relay/tests/integration/smoke.rs | 30 +- .../tests/integration/tenant_matrix.rs | 4 +- .../tests/integration/upstream_links.rs | 6 +- rs/moq-room/src/chat.rs | 2 +- rs/moq-room/src/room.rs | 137 +++-- rs/moq-rtc/src/lib.rs | 18 +- rs/moq-rtmp/src/dial.rs | 13 +- rs/moq-rtmp/src/server.rs | 17 +- rs/moq-srt/src/ts.rs | 8 +- rs/moq-stats/benches/producer_tick.rs | 4 +- rs/moq-stats/src/aggregate.rs | 30 +- rs/moq-stats/src/consume.rs | 18 +- rs/moq-stats/src/produce.rs | 30 +- rs/moq-tokio/examples/clock.rs | 4 +- rs/moq-tokio/src/client.rs | 2 +- rs/moq-tokio/src/connection.rs | 6 +- rs/moq-tokio/src/origin.rs | 10 +- rs/moq-tokio/src/server.rs | 10 +- rs/moq-tokio/src/webrtc/tests.rs | 2 +- rs/moq-tokio/tests/integration/backend.rs | 10 +- rs/moq-tokio/tests/integration/broadcast.rs | 12 +- .../tests/integration/datagram_delivery.rs | 2 +- rs/moq-tokio/tests/integration/max_age.rs | 2 +- rs/moq-tokio/tests/integration/migrate.rs | 2 +- .../tests/integration/receive_credit.rs | 2 +- .../integration/subscription_end_integrity.rs | 2 +- rs/moq-uring/benches/session_lite.rs | 2 +- rs/moq-uring/tests/integration/session.rs | 4 +- rs/moq-uring/tests/integration/web.rs | 2 +- test/interop/clients/rust/finish.rs | 2 +- 168 files changed, 1594 insertions(+), 1413 deletions(-) create mode 100644 rs/moq-net/src/model/announced.rs diff --git a/rs/hang/examples/subscribe.rs b/rs/hang/examples/subscribe.rs index 9718326d08f..f5137fda861 100644 --- a/rs/hang/examples/subscribe.rs +++ b/rs/hang/examples/subscribe.rs @@ -37,34 +37,27 @@ async fn run_session(origin: moq_net::origin::Producer) -> anyhow::Result<()> { Ok(reconnect.closed().await?) } -// Follow the announced broadcast: play it once it starts, play it afresh when another -// publisher instance replaces it (a restart), keep playing when a route takes it over in -// place, and stop when it ends. +// List the announced broadcasts and play the first: follow it across publisher instances, +// playing afresh when another replaces it, until it goes offline. async fn run_subscribe(consumer: moq_net::origin::Consumer) -> anyhow::Result<()> { let mut announced = consumer.announced(); let mut playing: Option> = None; while let Some(event) = announced.next().await { match event { - // The same broadcast continued in place: nothing to do. - moq_net::announce::Event::Takeover { announce, predecessor } if predecessor == announce.prefix => {} // The convention is that a publisher announces each broadcast's exact path. - moq_net::announce::Event::Start(announce) - | moq_net::announce::Event::Restart(announce) - | moq_net::announce::Event::Takeover { announce, .. } => { + moq_net::announce::Event::Present(announce) => { tracing::info!(path = %announce.prefix, "broadcast announced"); if let Some(old) = playing.take() { old.abort(); } let consumer = consumer.clone(); playing = Some(tokio::spawn(async move { - if let Err(err) = play(consumer, announce).await { + if let Err(err) = follow(consumer, announce.prefix).await { tracing::warn!(%err, "playback failed"); } })); } - // The same broadcast over another route: nothing to do. - moq_net::announce::Event::Update(_) => {} - moq_net::announce::Event::End(announce) => { + moq_net::announce::Event::Absent(announce) => { tracing::info!(path = %announce.prefix, "broadcast ended"); if let Some(old) = playing.take() { old.abort(); @@ -75,10 +68,27 @@ async fn run_subscribe(consumer: moq_net::origin::Consumer) -> anyhow::Result<() anyhow::bail!("origin closed") } -// Resolve an announced broadcast and read media frames. -async fn play(consumer: moq_net::origin::Consumer, announce: moq_net::announce::Announce) -> anyhow::Result<()> { - let broadcast = consumer.request(&announce.prefix, announce.route.instance).await?; +// Play each publisher instance serving `path`, starting afresh when another replaces it. +async fn follow(consumer: moq_net::origin::Consumer, path: moq_net::Path) -> anyhow::Result<()> { + let mut following = consumer.follow(&path, None)?; + let mut next = following.available().await?; + while let Some(broadcast) = next { + tracing::info!(%path, instance = ?broadcast.info().instance, "broadcast online"); + next = tokio::select! { + played = play(broadcast) => { + if let Err(err) = played { + tracing::warn!(%err, "playback failed"); + } + following.available().await? + } + changed = following.available() => changed?, + }; + } + Ok(()) +} +// Read the catalog and media frames of one publisher instance. +async fn play(broadcast: moq_net::broadcast::Consumer) -> anyhow::Result<()> { // Read the catalog to discover available tracks. let catalog_track = broadcast .track(hang::Catalog::DEFAULT_NAME)? diff --git a/rs/moq-audio/src/decode/consumer.rs b/rs/moq-audio/src/decode/consumer.rs index 6ebd41e014e..8ac8bf325d3 100644 --- a/rs/moq-audio/src/decode/consumer.rs +++ b/rs/moq-audio/src/decode/consumer.rs @@ -994,7 +994,7 @@ mod tests { let relay = origin(2); let _link = link(&publisher, &relay).await; let consumer = relay.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); // A first reader warms the relay's copy with every group. { @@ -1066,7 +1066,7 @@ mod tests { let subscriber = origin(2); let _link = link(&publisher, &subscriber).await; let consumer = subscriber.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); let mut catalog = hang::catalog::AudioConfig::new(hang::catalog::AudioCodec::Pcm, 48_000, 1); catalog.warmup = Some(Duration::from_millis(80)); diff --git a/rs/moq-bench/src/connection.rs b/rs/moq-bench/src/connection.rs index 05ffb39a3f3..424ccd10b6f 100644 --- a/rs/moq-bench/src/connection.rs +++ b/rs/moq-bench/src/connection.rs @@ -357,11 +357,11 @@ async fn subscribe( update = announced.next() => { let update = match update { Some( - moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Restart(update) | moq_net::announce::Event::Takeover { announce: update, .. }, + moq_net::announce::Event::Present(update) + | moq_net::announce::Event::Present(update) + | moq_net::announce::Event::Present(update) | moq_net::announce::Event::Present(update), ) => update, - Some(moq_net::announce::Event::End(_)) => continue, + Some(moq_net::announce::Event::Absent(_)) => continue, None => break, }; let path = update.prefix.to_string(); @@ -387,12 +387,12 @@ async fn subscribe( while selected < want { let update = match announced.next().await { Some( - moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Restart(update) - | moq_net::announce::Event::Takeover { announce: update, .. }, + moq_net::announce::Event::Present(update) + | moq_net::announce::Event::Present(update) + | moq_net::announce::Event::Present(update) + | moq_net::announce::Event::Present(update), ) => update, - Some(moq_net::announce::Event::End(_)) => continue, + Some(moq_net::announce::Event::Absent(_)) => continue, None => break, }; let path = update.prefix.to_string(); diff --git a/rs/moq-boy/src/input.rs b/rs/moq-boy/src/input.rs index b7c954e7acc..3e5ab0137c9 100644 --- a/rs/moq-boy/src/input.rs +++ b/rs/moq-boy/src/input.rs @@ -65,63 +65,59 @@ pub async fn handle_viewers( cmd_tx: &tokio::sync::mpsc::Sender, ) -> anyhow::Result<()> { let mut announced = viewer_origin.announced(); - // The command reader per viewer, so a restarted viewer replaces the old one's. + // The follower per viewer, which reads each broadcast a restarted viewer replaces the old with. let mut readers: std::collections::HashMap = Default::default(); - loop { - let (update, active, restart) = match announced.next().await { - // A takeover continues what was read through its predecessor. - Some( - moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Takeover { announce: update, .. }, - ) => (update, true, false), - // The viewer restarted: read the new broadcast instead of the old one. - Some(moq_net::announce::Event::Restart(update)) => (update, true, true), - Some(moq_net::announce::Event::End(update)) => (update, false, false), - None => break, - }; - - let viewer_id = update.prefix.to_string(); - - if active { - if !restart && readers.get(&viewer_id).is_some_and(|reader| !reader.is_finished()) { - continue; - } - let Ok(broadcast) = viewer_origin.request(&update.prefix, None).await else { - continue; - }; - tracing::info!(%viewer_id, restart, "viewer connected"); - if let Some(old) = readers.remove(&viewer_id) { - old.abort(); + while let Some(event) = announced.next().await { + match event { + moq_net::announce::Event::Present(announce) => { + let viewer_id = announce.prefix.to_string(); + let reader = tokio::spawn(follow_viewer(viewer_origin.clone(), announce.prefix, cmd_tx.clone())); + if let Some(old) = readers.insert(viewer_id, reader.abort_handle()) { + old.abort(); + } } - let cmd_tx = cmd_tx.clone(); - let vid = viewer_id.clone(); - let reader = tokio::spawn(async move { - if let Err(e) = handle_viewer_commands(&vid, broadcast, &cmd_tx).await { - tracing::warn!(viewer_id = %vid, error = %e, "viewer command error"); + moq_net::announce::Event::Absent(announce) => { + let viewer_id = announce.prefix.to_string(); + // Dropping an abort handle leaves its task running, so stop it here. + if let Some(old) = readers.remove(&viewer_id) { + old.abort(); } - tracing::info!(viewer_id = %vid, "viewer disconnected"); - let _ = cmd_tx.send(Command::ViewerLeft { viewer_id: vid }).await; - }); - readers.insert(viewer_id, reader.abort_handle()); - } else { - // Dropping an abort handle leaves its task running. Older versions send a restart - // as END then START, and the old track keeps flowing meanwhile, so the old reader - // must stop here or it would race the replacement. - if let Some(old) = readers.remove(&viewer_id) { - old.abort(); + tracing::info!(%viewer_id, "viewer went offline"); + let _ = cmd_tx.send(Command::ViewerLeft { viewer_id }).await; } - tracing::info!(%viewer_id, "viewer went offline"); - let _ = cmd_tx - .send(Command::ViewerLeft { - viewer_id: viewer_id.clone(), - }) - .await; } } Ok(()) } +/// Read the commands of each broadcast a viewer publishes at `path`, switching to the new one +/// when the viewer restarts. +async fn follow_viewer( + origin: moq_net::origin::Consumer, + path: moq_net::Path, + cmd_tx: tokio::sync::mpsc::Sender, +) { + let viewer_id = path.to_string(); + let Ok(mut following) = origin.follow(&path, None) else { + return; + }; + let mut next = following.available().await; + while let Ok(Some(broadcast)) = next { + tracing::info!(%viewer_id, "viewer connected"); + next = tokio::select! { + read = handle_viewer_commands(&viewer_id, broadcast, &cmd_tx) => { + if let Err(e) = read { + tracing::warn!(%viewer_id, error = %e, "viewer command error"); + } + tracing::info!(%viewer_id, "viewer disconnected"); + let _ = cmd_tx.send(Command::ViewerLeft { viewer_id: viewer_id.clone() }).await; + following.available().await + } + changed = following.available() => changed, + }; + } +} + async fn handle_viewer_commands( viewer_id: &str, broadcast: moq_net::broadcast::Consumer, diff --git a/rs/moq-c/src/api.rs b/rs/moq-c/src/api.rs index 763b64a9d99..e4ae3686406 100644 --- a/rs/moq-c/src/api.rs +++ b/rs/moq-c/src/api.rs @@ -926,8 +926,8 @@ pub struct moq_announce_route { /// publisher is a new stream viewers restart onto. Set one only for a publisher that /// continues its group sequences across restarts and raises `epoch` on each: readers /// stitch every route of one instance together, so restarting the sequences under an - /// old instance splices unrelated groups into their tracks. Changing it is a - /// `MOQ_ANNOUNCE_KIND_RESTART`. + /// old instance splices unrelated groups into their tracks. Changing it hands followers + /// ([moq_origin_follow]) a new broadcast. pub instance: *const c_char, /// The length in bytes of `instance`. pub instance_len: usize, @@ -997,22 +997,14 @@ pub struct moq_announce_config { #[expect(non_camel_case_types, reason = "C ABI type names match moq.h")] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum moq_announce_kind { - /// A route now covers the prefix; the listener had none there. - MOQ_ANNOUNCE_KIND_START = 0, - /// The route covering the prefix changed hops or cost. - MOQ_ANNOUNCE_KIND_UPDATE = 1, - /// No route covers the prefix any more. - MOQ_ANNOUNCE_KIND_END = 2, - /// Another publisher instance now serves the prefix: drop what was resolved under - /// it and request afresh. - MOQ_ANNOUNCE_KIND_RESTART = 3, - /// A route now covers the prefix and continues what the route at - /// [moq_announce_event::predecessor] served beneath it: keep what was resolved through it. - MOQ_ANNOUNCE_KIND_TAKEOVER = 4, -} - -/// An announce event from an origin: a route starting, updating, ending, restarting, or -/// taking over. + /// 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, + /// No route covers the path any more. + MOQ_ANNOUNCE_KIND_ABSENT = 1, +} + +/// 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 @@ -1029,14 +1021,9 @@ pub struct moq_announce_event { /// Which event this is. pub kind: moq_announce_kind, - /// The route serving the prefix. On `MOQ_ANNOUNCE_KIND_END` it carries the last + /// The route serving the prefix. On `MOQ_ANNOUNCE_KIND_ABSENT` it carries the last /// advertised route. pub route: moq_route, - /// For [moq_announce_kind::MOQ_ANNOUNCE_KIND_TAKEOVER], the prefix of the route continued, - /// relative to the origin, NOT NULL terminated. Empty for every other kind. - pub predecessor: *const c_char, - /// The length in bytes of `predecessor`. - pub predecessor_len: usize, } /// Where a session is in its lifecycle, reported by [moq_connection_state]. diff --git a/rs/moq-c/src/origin.rs b/rs/moq-c/src/origin.rs index 2463579830a..fe16b7655e0 100644 --- a/rs/moq-c/src/origin.rs +++ b/rs/moq-c/src/origin.rs @@ -81,7 +81,6 @@ struct AnnouncedRecord { cost: u64, /// The route's instance. instance: String, - predecessor: String, } // The raw pointers only borrow immutable String allocations owned by this record. @@ -91,16 +90,9 @@ unsafe impl Send for AnnouncedRecord {} impl AnnouncedRecord { fn new(event: moq_net::announce::Event) -> Self { use moq_net::announce::Event; - let (update, kind, predecessor) = match event { - Event::Start(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_START, String::new()), - Event::Update(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_UPDATE, String::new()), - Event::End(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_END, String::new()), - Event::Restart(update) => (update, moq_announce_kind::MOQ_ANNOUNCE_KIND_RESTART, String::new()), - Event::Takeover { announce, predecessor } => ( - announce, - moq_announce_kind::MOQ_ANNOUNCE_KIND_TAKEOVER, - predecessor.to_string(), - ), + 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), }; let captures: Vec<_> = update .captures @@ -128,7 +120,6 @@ impl AnnouncedRecord { .instance .map(|instance| instance.to_string()) .unwrap_or_default(), - predecessor, } } } @@ -217,8 +208,6 @@ impl Origin { len: announced.instance.len(), }, }, - predecessor: announced.predecessor.as_ptr().cast::(), - predecessor_len: announced.predecessor.len(), }; Ok(()) } @@ -288,7 +277,10 @@ impl Origin { biased; _ = &mut close => return Ok(()), available = announced.available() => match available { - Ok(broadcast) => broadcast, + Ok(Some(broadcast)) => broadcast, + // The path went offline: the delivered handle's tracks end on their own, and the + // announce listing reports the absence. + Ok(None) => continue, // The origin closing ends the wait, cleanly once a handle was delivered. Err(moq_net::Error::Closed) if delivered => return Ok(()), Err(moq_net::Error::Closed) => return Err(Error::BroadcastNotFound), diff --git a/rs/moq-cli/src/announced.rs b/rs/moq-cli/src/announced.rs index 91cba68c204..4839fbb6c4d 100644 --- a/rs/moq-cli/src/announced.rs +++ b/rs/moq-cli/src/announced.rs @@ -91,14 +91,8 @@ async fn follow( }; let (announce, active) = match event { - Event::Start(announce) => (announce, true), - Event::End(announce) => (announce, false), - // A new route or a new instance for a path already announced, which changes - // nothing shown. - Event::Update(_) | Event::Restart(_) => continue, - // A route continuing another: new to the list unless it replaced that one in place. - Event::Takeover { announce, predecessor } if predecessor != announce.prefix => (announce, true), - Event::Takeover { .. } => continue, + Event::Present(announce) => (announce, true), + Event::Absent(announce) => (announce, false), }; let path = announce.prefix.as_str(); @@ -234,7 +228,7 @@ mod tests { kio::clock::timeout(TIMEOUT, relay.follow(*path, None).unwrap().available()) .await .expect("relay routes the broadcast") - .expect("broadcast"); + .expect("broadcast").unwrap(); } Self { diff --git a/rs/moq-cli/src/archive.rs b/rs/moq-cli/src/archive.rs index 1ad35dd9e32..496ecbb5125 100644 --- a/rs/moq-cli/src/archive.rs +++ b/rs/moq-cli/src/archive.rs @@ -82,7 +82,7 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp event = announced.next() => { let announce = match event.context("announcements ended")? { // Another instance, or the same one announced again. - moq_net::announce::Event::Start(announce) | moq_net::announce::Event::Restart(announce) | moq_net::announce::Event::Takeover { announce, .. } => announce, + moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) => announce, _ => continue, }; if !announce.prefix.has_prefix(&prefix) { @@ -444,7 +444,7 @@ mod tests { let mut announced = origin.consume().announced(); kio::clock::timeout(Duration::from_secs(10), async { loop { - if let Some(moq_net::announce::Event::Start(announce)) = announced.next().await { + if let Some(moq_net::announce::Event::Present(announce)) = announced.next().await { assert_eq!(announce.prefix.as_str(), "replay"); assert_eq!(announce.route.instance, Some(instance.clone())); break; diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 8ddb613410d..05a50fd36c0 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -1405,7 +1405,7 @@ mod tests { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut track = broadcast .track("status") .unwrap() @@ -1515,7 +1515,7 @@ mod tests { .unwrap() .available() .await - .unwrap() + .unwrap().unwrap() .track("live") .unwrap() .subscribe(None) diff --git a/rs/moq-cli/src/play/media.rs b/rs/moq-cli/src/play/media.rs index 83345dae129..15c3f3342ca 100644 --- a/rs/moq-cli/src/play/media.rs +++ b/rs/moq-cli/src/play/media.rs @@ -8,7 +8,6 @@ use std::time::Duration; use anyhow::Context; use hang::moq_net; use moq_mux::catalog::{self, Stream}; -use moq_mux::follow::{Event as FollowEvent, Instances}; // The ambient clock, which follows tokio's paused clock when a test drives the // playout clock itself. use kio::clock::Instant; @@ -76,7 +75,7 @@ impl Media { /// and an end lets what is playing finish while waiting for the next start. An /// update is the same instance, which its subscriptions already ride out. async fn play(self) -> anyhow::Result<()> { - let mut follow = Instances::new(&self.origin, &self.broadcast, None)?; + let mut follow = self.origin.follow(&self.broadcast, None)?; // The device belongs to the player, so replacing a broadcast never waits // for it to close and reopen. Each sink adapts its own rate and layout. let device = tokio::sync::OnceCell::new(); @@ -84,14 +83,14 @@ impl Media { loop { tokio::select! { - event = follow.next() => { + event = follow.available() => { let broadcast = match event { - Ok(FollowEvent::Start(broadcast)) => broadcast, - Ok(FollowEvent::End) => { + Ok(Some(broadcast)) => broadcast, + Ok(None) => { tracing::info!(broadcast = %self.broadcast, "offline, waiting for it to return"); continue; } - Err(moq_mux::Error::Moq(moq_net::Error::Closed)) => return Ok(()), + Err(moq_net::Error::Closed) => return Ok(()), Err(err) => return Err(err).context("failed to follow the broadcast"), }; tracing::info!( diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index 7d3fa239934..74ac57e9d7f 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -1711,7 +1711,7 @@ pub(crate) mod tests { let consumer = kio::clock::timeout(WAIT, remote.consume().follow("pt.hang", None).unwrap().available()) .await .unwrap() - .unwrap(); + .unwrap().unwrap(); let mut catalogs = hang::catalog::Catalog::<()>::subscribe(&consumer).await.unwrap(); let catalog = kio::clock::timeout(WAIT, catalogs.next()) .await @@ -2162,7 +2162,7 @@ pub(crate) mod tests { _ = kio::clock::sleep(Duration::from_secs(30)) => panic!("never announced"), resolved = async { let event = announced.next().await.expect("origin closed"); - assert!(matches!(event, moq_net::announce::Event::Start(_)), "{event:?}"); + assert!(matches!(event, moq_net::announce::Event::Present(_)), "{event:?}"); let broadcast = consumer.request("demo", None).await.unwrap(); let mut catalogs = hang::catalog::Catalog::<()>::subscribe(&broadcast).await.unwrap(); let catalog = catalogs.next().await.unwrap().expect("a catalog"); diff --git a/rs/moq-cli/src/report.rs b/rs/moq-cli/src/report.rs index f9ff59ff663..a727eb3ad69 100644 --- a/rs/moq-cli/src/report.rs +++ b/rs/moq-cli/src/report.rs @@ -489,10 +489,10 @@ async fn write_echo( let event = event.context("announcements ended")?; let (announce, active) = match event { // A restart is another publisher instance, which a reader still on the old one never sees. - moq_net::announce::Event::Start(announce) | moq_net::announce::Event::Restart(announce) | moq_net::announce::Event::Takeover { announce, .. } => { + moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) => { (announce, true) } - moq_net::announce::Event::End(announce) => (announce, false), + moq_net::announce::Event::Absent(announce) => (announce, false), _ => continue, }; let path = announce.prefix; diff --git a/rs/moq-cli/src/report/echo_test.rs b/rs/moq-cli/src/report/echo_test.rs index 7647229c890..fc9e413a6f6 100644 --- a/rs/moq-cli/src/report/echo_test.rs +++ b/rs/moq-cli/src/report/echo_test.rs @@ -30,7 +30,7 @@ async fn export_echo_reports_where_the_import_solicits() { import.decode(&CLIP[..HALF]).unwrap(); publication.announce(Default::default()).unwrap(); let consumer = origin.consume(); - let resolved = consumer.follow("demo", None).unwrap().available().await.unwrap(); + let resolved = consumer.follow("demo", None).unwrap().available().await.unwrap().unwrap(); let args = SubscribeArgs { format: SubscribeFormat::Ts, diff --git a/rs/moq-cli/src/transcode.rs b/rs/moq-cli/src/transcode.rs index 52ae7cdab40..fe499fafb87 100644 --- a/rs/moq-cli/src/transcode.rs +++ b/rs/moq-cli/src/transcode.rs @@ -168,14 +168,12 @@ struct Following { impl Following { async fn run(self) -> anyhow::Result<()> { - use moq_mux::follow::{Event, Instances}; - - let mut instances = Instances::new(&self.origin, &self.source_path, None)?; + let mut instances = self.origin.follow(&self.source_path, None)?; let mut running = None; loop { tokio::select! { - event = instances.next() => match event? { - Event::Start(source) => { + event = instances.available() => match event? { + Some(source) => { // Dropping the old ladder cancels its pending requests and rung tasks. drop(running.take()); let output = self.publish.create_broadcast(&self.output_path)?; @@ -184,7 +182,7 @@ impl Following { tracing::info!(source = %self.source_path, output = %self.output_path, "transcoding"); running = Some(Box::pin(transcoder.run())); } - Event::End => tracing::info!(source = %self.source_path, "offline, waiting for it to return"), + None => tracing::info!(source = %self.source_path, "offline, waiting for it to return"), }, result = async { running.as_mut().expect("guarded").await }, if running.is_some() => { running = None; @@ -233,7 +231,7 @@ mod tests { }; let old = origin.publish("source", route()).unwrap(); let _old_dynamic = old.requests(); - let mut derivatives = moq_mux::follow::Instances::new(&publish.consume(), "derived", None).unwrap(); + let mut derivatives = publish.consume().follow("derived", None).unwrap(); let following = Following { origin: origin.consume(), publish: publish.clone(), @@ -280,7 +278,7 @@ mod tests { let route = || moq_net::origin::Route::default(); let old = origin.publish("source", route()).unwrap(); let mut catalog = moq_mux::catalog::Producer::new(&mut old.broadcast().clone(), Default::default()).unwrap(); - let mut derivatives = moq_mux::follow::Instances::new(&publish.consume(), "derived", None).unwrap(); + let mut derivatives = publish.consume().follow("derived", None).unwrap(); let following = Following { origin: origin.consume(), publish: publish.clone(), @@ -306,12 +304,11 @@ mod tests { } /// The next derivative instance announced at the output path. - async fn next(instances: &mut moq_mux::follow::Instances) -> moq_net::broadcast::Consumer { + async fn next(instances: &mut moq_net::origin::Following) -> moq_net::broadcast::Consumer { let start = async { loop { - match instances.next().await.unwrap() { - moq_mux::follow::Event::Start(broadcast) => return broadcast, - moq_mux::follow::Event::End => continue, + if let Some(broadcast) = instances.available().await.unwrap() { + return broadcast; } } }; diff --git a/rs/moq-cli/tests/integration/export.rs b/rs/moq-cli/tests/integration/export.rs index e5c37658f3d..f9447306104 100644 --- a/rs/moq-cli/tests/integration/export.rs +++ b/rs/moq-cli/tests/integration/export.rs @@ -577,7 +577,7 @@ async fn the_same_instance_within_the_follow_continues() { let back = kio::clock::timeout(TIMEOUT, relay.origin.follow("demo", None).unwrap().available()) .await .expect("the relay observes the returning publication") - .unwrap(); + .unwrap().unwrap(); assert_eq!(back.info().instance.as_ref(), Some(&instance)); assert!(!back.is_clone(&old), "the old relay copy was replaced"); for chunk in chunks { @@ -1057,13 +1057,13 @@ async fn redundant_failover(bufferbloat: bool) { } /// The instance of the next route announced for the path. -async fn next_instance(announced: &mut moq_net::announce::Consumer) -> moq_net::Instance { +async fn next_instance(announced: &mut moq_net::origin::Routes) -> moq_net::Instance { kio::clock::timeout(TIMEOUT, async { loop { match announced.next().await.expect("the relay stays up") { - moq_net::announce::Event::Start(announce) - | moq_net::announce::Event::Restart(announce) - | moq_net::announce::Event::Takeover { announce, .. } => { + moq_net::origin::RouteEvent::Start(announce) + | moq_net::origin::RouteEvent::Restart(announce) + | moq_net::origin::RouteEvent::Takeover { announce, .. } => { return announce .route .instance @@ -1084,7 +1084,7 @@ async fn next_instance(announced: &mut moq_net::announce::Consumer) -> moq_net:: async fn a_passthrough_export_ends_with_its_redundant_importer() { let relay = relay().await; let demo = moq_net::Patterns::from(moq_net::Pattern::literal("demo").unwrap()); - let mut announced = relay.origin.scope("", &demo).unwrap().announced(); + let mut announced = relay.origin.scope("", &demo).unwrap().routes(); let (feed, feeding) = redundant_feed(); let mut first = redundant_import(&relay, &feed, &["--passthrough"]); let incumbent = next_instance(&mut announced).await; @@ -1196,7 +1196,7 @@ fn delivered(relay: &Relay) -> Arc { let counting = count.clone(); let origin = relay.origin.clone(); tokio::spawn(async move { - let broadcast = origin.follow("demo", None).unwrap().available().await.unwrap(); + let broadcast = origin.follow("demo", None).unwrap().available().await.unwrap().unwrap(); let mut catalogs = hang::catalog::Catalog::<()>::subscribe(&broadcast).await.unwrap(); let name = loop { let catalog = catalogs.next().await.unwrap().expect("the catalog ended"); diff --git a/rs/moq-cli/tests/integration/import.rs b/rs/moq-cli/tests/integration/import.rs index 11333ef629d..5df394b3681 100644 --- a/rs/moq-cli/tests/integration/import.rs +++ b/rs/moq-cli/tests/integration/import.rs @@ -88,7 +88,7 @@ async fn import_delivers_the_catalog_finish_at_eof() { let event = running(&mut child, "the announce", announced.next()) .await .expect("origin closed"); - let moq_tokio::moq_net::announce::Event::Start(announce) = event else { + let moq_tokio::moq_net::announce::Event::Present(announce) = event else { panic!("the first announce event is {event:?}, not a start"); }; assert_eq!(announce.prefix.as_str(), "demo"); diff --git a/rs/moq-cli/tests/integration/instances.rs b/rs/moq-cli/tests/integration/instances.rs index ae831c74eef..14a6040322a 100644 --- a/rs/moq-cli/tests/integration/instances.rs +++ b/rs/moq-cli/tests/integration/instances.rs @@ -119,15 +119,15 @@ async fn within(started: Instant, change: impl Future) -> T { } /// Ignore same-instance metadata updates, but keep the actual replacement representation. -async fn changed(follow: &mut announce::Consumer) -> bool { +async fn changed(follow: &mut origin::Routes) -> bool { loop { match follow.next().await.unwrap() { - announce::Event::Restart(_) => return true, - announce::Event::End(_) => { - assert!(matches!(follow.next().await, Some(announce::Event::Start(_)))); + origin::RouteEvent::Restart(_) => return true, + origin::RouteEvent::End(_) => { + assert!(matches!(follow.next().await, Some(origin::RouteEvent::Start(_)))); return false; } - announce::Event::Update(_) => {} + origin::RouteEvent::Update(_) => {} other => panic!("expected replacement, got {other:?}"), } } @@ -149,7 +149,7 @@ async fn replacement(version: &str) { let viewer = viewer_origin.consume(); let watch = |path| { let path = moq_net::Patterns::from(moq_net::Pattern::literal(path).unwrap()); - viewer.scope("", &path).unwrap().announced() + viewer.scope("", &path).unwrap().routes() }; let mut catalog_follow = watch("live/catalog.hang"); let mut media_follow = watch("live/media"); @@ -160,8 +160,8 @@ async fn replacement(version: &str) { .established() .await .unwrap(); - assert!(matches!(catalog_follow.next().await, Some(announce::Event::Start(_)))); - assert!(matches!(media_follow.next().await, Some(announce::Event::Start(_)))); + assert!(matches!(catalog_follow.next().await, Some(origin::RouteEvent::Start(_)))); + assert!(matches!(media_follow.next().await, Some(origin::RouteEvent::Start(_)))); let held = viewer.request("live/catalog.hang", None).await.unwrap(); let old = moq_mux::Source::new(viewer.clone(), held); diff --git a/rs/moq-cli/tests/integration/rtsp.rs b/rs/moq-cli/tests/integration/rtsp.rs index 5614767d01f..ecd776654ef 100644 --- a/rs/moq-cli/tests/integration/rtsp.rs +++ b/rs/moq-cli/tests/integration/rtsp.rs @@ -56,17 +56,17 @@ fn import(url: &str, fingerprint: &str, rtsp: &str) -> Child { async fn next_broadcast( child: &mut Child, consumer: &moq_net::origin::Consumer, - announced: &mut moq_net::announce::Consumer, + announced: &mut moq_net::origin::Routes, ) -> hang::catalog::Consumer { loop { match running(child, "the announce", announced.next()) .await .expect("origin closed") { - moq_net::announce::Event::Start(_) - | moq_net::announce::Event::Restart(_) - | moq_net::announce::Event::Takeover { .. } => break, - moq_net::announce::Event::End(_) | moq_net::announce::Event::Update(_) => {} + moq_net::origin::RouteEvent::Start(_) + | moq_net::origin::RouteEvent::Restart(_) + | moq_net::origin::RouteEvent::Takeover { .. } => break, + moq_net::origin::RouteEvent::End(_) | moq_net::origin::RouteEvent::Update(_) => {} } } let broadcast = running(child, "the broadcast", consumer.request("camera", None)) @@ -135,7 +135,7 @@ async fn every_rtsp_session_is_a_fresh_broadcast() { let origin = moq_tokio::origin::spawn(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let mut config = moq_tokio::connect::Config::default(); config.tls.insecure = Some(true); config.bind = Some("127.0.0.1:0".parse().unwrap()); diff --git a/rs/moq-e2ee/tests/transport.rs b/rs/moq-e2ee/tests/transport.rs index a79dce71f36..62a69434a40 100644 --- a/rs/moq-e2ee/tests/transport.rs +++ b/rs/moq-e2ee/tests/transport.rs @@ -57,7 +57,7 @@ async fn connect_protected(version: Version, track: &str) -> Fixture { // The subscriber knows the opaque path and takes the epoch from the announced route's // instance. A wire without instances leaves it to the application's own channel. let consumer = consumer_origin.consume(); - let remote = consumer.follow(&path, None).unwrap().available().await.unwrap(); + let remote = consumer.follow(&path, None).unwrap().available().await.unwrap().unwrap(); if version.to_string().starts_with("moq-lite-07") { assert_eq!( moq_e2ee::Epoch::of(&remote).as_ref(), diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index a05d8a9676f..add7eb64d8b 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -828,9 +828,7 @@ impl Session { path: &str, lost: impl Future, ) -> Result<()> { - use moq_mux::follow::{Event, Instances}; - - let mut follow = Instances::new(origin, path, None)?; + let mut follow = origin.follow(path, None)?; let mut shutdown = self.shutdown.clone(); let mut runs = tokio::task::JoinSet::new(); // Cancels the latest run. @@ -842,16 +840,16 @@ impl Session { let broadcast = tokio::select! { _ = shutdown.changed() => break Ok(()), err = &mut lost => break Err(err), - event = follow.next() => match event { - Ok(Event::Start(broadcast)) => { + event = follow.available() => match event { + Ok(Some(broadcast)) => { tracing::info!(%path, instance = ?broadcast.info().instance, "online"); Some(broadcast) } - Ok(Event::End) => { + Ok(None) => { tracing::info!(%path, "offline, holding pads until it returns"); None } - Err(moq_mux::Error::Moq(moq_net::Error::Closed)) => break Ok(()), + Err(moq_net::Error::Closed) => break Ok(()), Err(err) => break Err(anyhow::Error::from(err).context("broadcast refused")), }, joined = runs.join_next(), if !runs.is_empty() => match joined.expect("guarded by is_empty") { @@ -1302,7 +1300,7 @@ impl Follower { // The catalog's own broadcast is ready at once, so its renditions play even when the // catalog closed before this follower ran. match instances.poll_next(&moq_net::kio::Waiter::noop()) { - std::task::Poll::Ready(Ok(moq_mux::follow::Event::Start(instance))) => self.start(instance), + std::task::Poll::Ready(Ok(Some(instance))) => self.start(instance), std::task::Poll::Ready(Err(err)) => { gst::warning!(CAT, "lost {}: {err:?}", self.path); return; @@ -1362,11 +1360,11 @@ impl Follower { } } event = instances.next(), if following => match event { - Ok(moq_mux::follow::Event::Start(instance)) => { + Ok(Some(instance)) => { gst::info!(CAT, "{} is online, starting its renditions", self.path); self.start(instance); } - Ok(moq_mux::follow::Event::End) => { + Ok(None) => { gst::info!(CAT, "{} is offline, holding its pads", self.path); self.offline(); } @@ -3882,7 +3880,7 @@ mod session_tests { } /// Block until the path's announcements report an event `wanted` accepts. - fn await_event(follow: &mut moq_net::announce::Consumer, wanted: impl Fn(&moq_net::announce::Event) -> bool) { + fn await_event(follow: &mut moq_net::origin::Routes, wanted: impl Fn(&moq_net::origin::RouteEvent) -> bool) { let next = async { while let Some(event) = follow.next().await { if wanted(&event) { @@ -3906,15 +3904,15 @@ mod session_tests { } /// The announcements of the routes covering `path` on `origin`. - fn watch(origin: &moq_net::origin::Producer, path: &str) -> moq_net::announce::Consumer { + fn watch(origin: &moq_net::origin::Producer, path: &str) -> moq_net::origin::Routes { let path = moq_net::Patterns::from(moq_net::Pattern::literal(path).unwrap()); - origin.consume().scope("", &path).unwrap().announced() + origin.consume().scope("", &path).unwrap().routes() } /// Follow `room` on `origin` past its start. - fn announced(origin: &moq_net::origin::Producer) -> moq_net::announce::Consumer { + fn announced(origin: &moq_net::origin::Producer) -> moq_net::origin::Routes { let mut follow = watch(origin, "room"); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); follow } @@ -4035,9 +4033,9 @@ mod session_tests { let mut first = Publisher::sibling(&origin, Default::default()); let pad = recorder.written(&mut first, 1); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::End(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad"); @@ -4127,11 +4125,11 @@ mod session_tests { let pad = recorder.written(&mut first, 1); first.video.finish().unwrap(); await_finished(&first); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); first.publication.as_ref().unwrap().unannounce(); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::End(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); first.publication.as_ref().unwrap().announce(route).unwrap(); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!( @@ -4206,9 +4204,9 @@ mod session_tests { let pad = recorder.written(&mut first, 1); room.catalog.finish().unwrap(); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::End(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad"); @@ -4483,14 +4481,14 @@ mod session_tests { let unpinned = recorder.written(&mut second, 2); let pad = played.into_iter().find(|pad| *pad != unpinned).unwrap(); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); drop(second); await_event(&mut follow, |event| { matches!( event, - moq_net::announce::Event::Restart(_) - | moq_net::announce::Event::Takeover { .. } - | moq_net::announce::Event::Start(_) + moq_net::origin::RouteEvent::Restart(_) + | moq_net::origin::RouteEvent::Takeover { .. } + | moq_net::origin::RouteEvent::Start(_) ) }); @@ -4538,9 +4536,9 @@ mod session_tests { let mut first = Publisher::sibling(&origin, Default::default()); let pad = recorder.written(&mut first, 1); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::End(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); room.catalog.modify().unwrap().video.renditions.clear(); for _ in 0..200 { @@ -4555,7 +4553,7 @@ mod session_tests { ); let mut second = Publisher::sibling(&origin, Default::default()); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); for _ in 0..10 { second.write(2); block(Duration::from_millis(50)); @@ -4580,9 +4578,9 @@ mod session_tests { let mut first = Publisher::sibling(&origin, Default::default()); let pad = recorder.written(&mut first, 1); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::End(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); let listed = room.catalog.modify().unwrap().video.renditions.clone(); room.catalog.modify().unwrap().video.renditions.clear(); @@ -4656,16 +4654,16 @@ mod session_tests { // The reference lets the old instance go once another wins its path, and only then // does the new one leave, so the return is a resume rather than a missed restart. let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::announce::Event::Start(_))); + await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); let mut new = Publisher::sibling(&origin, Default::default()); await_event(&mut follow, |event| { - matches!(event, moq_net::announce::Event::Restart(_)) + matches!(event, moq_net::origin::RouteEvent::Restart(_)) }); await_demand(&old, false); new.write(2); drop(new); await_event(&mut follow, |event| { - matches!(event, moq_net::announce::Event::Restart(_)) + matches!(event, moq_net::origin::RouteEvent::Restart(_)) }); await_demand(&old, true); @@ -4772,7 +4770,7 @@ mod session_tests { .announce(route.with_cost(5)) .unwrap(); await_event(&mut announced, |event| { - matches!(event, moq_net::announce::Event::Update(_)) + matches!(event, moq_net::origin::RouteEvent::Update(_)) }); recorder.written(&mut publisher, 2); stop(session); @@ -4887,7 +4885,7 @@ mod session_tests { old.catalog.finish().unwrap(); drop(old); await_event(&mut announced, |event| { - matches!(event, moq_net::announce::Event::End(_)) + matches!(event, moq_net::origin::RouteEvent::End(_)) }); let mut new = Publisher::new(&origin, Default::default(), video_rendition()); @@ -4917,7 +4915,7 @@ mod session_tests { old.publication.as_ref().unwrap().unannounce(); await_event(&mut announced, |event| { - matches!(event, moq_net::announce::Event::End(_)) + matches!(event, moq_net::origin::RouteEvent::End(_)) }); drop(old); @@ -4970,7 +4968,7 @@ mod session_tests { let publication = next.publication.as_ref().unwrap(); publication.unannounce(); await_event(&mut announced, |event| { - matches!(event, moq_net::announce::Event::End(_)) + matches!(event, moq_net::origin::RouteEvent::End(_)) }); publication.announce(route).unwrap(); assert_eq!( @@ -5446,7 +5444,7 @@ mod session_tests { let mut announced = announced(&relay.origin); session.abort(moq_net::Error::App(1)); await_event(&mut announced, |event| { - matches!(event, moq_net::announce::Event::End(_)) + matches!(event, moq_net::origin::RouteEvent::End(_)) }); let mut new = Publisher::new(&relay.origin, Default::default(), video_rendition()); diff --git a/rs/moq-hls/src/export/mod.rs b/rs/moq-hls/src/export/mod.rs index c6fe3def8c3..89bc8942995 100644 --- a/rs/moq-hls/src/export/mod.rs +++ b/rs/moq-hls/src/export/mod.rs @@ -2345,7 +2345,7 @@ mod tests { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let source = crate::resolved(consuming, "live").await; let broadcaster = (!late).then(|| Broadcaster::spawned(source.clone(), Config::default())); for i in 0..20u64 { diff --git a/rs/moq-hls/src/server/mod.rs b/rs/moq-hls/src/server/mod.rs index 88b1bf9ede4..483153b7c42 100644 --- a/rs/moq-hls/src/server/mod.rs +++ b/rs/moq-hls/src/server/mod.rs @@ -69,7 +69,6 @@ use std::task::Poll; use std::time::Duration; use axum::Router; -use moq_mux::follow; use crate::export::{Broadcaster, Config}; @@ -228,7 +227,7 @@ impl Server { return Some(followed.clone()); } - let instances = follow::Instances::new(&self.inner.origin, name, None) + let instances = self.inner.origin.follow(name, None) .map_err(|err| tracing::warn!(%err, %name, "failed to follow broadcast")) .ok()?; // A request answers once the origin has synced with the relay, so a path with no route @@ -295,7 +294,7 @@ async fn run_follow( inner: Weak, name: String, followed: Weak, - mut instances: follow::Instances, + mut instances: moq_net::origin::Following, served: moq_net::broadcast::Consumer, ) { let mut served = Some(served); @@ -305,13 +304,13 @@ async fn run_follow( return Poll::Ready(None); }; followed.forget_closed(waiter); - if let Poll::Ready(next) = instances.poll_next(waiter) { + if let Poll::Ready(next) = instances.poll_available(waiter) { return Poll::Ready(Some(next)); } // The follower folds away an instance that started and ended before its first poll, // so the served instance closing before it is handed out means nothing serves the path. match &served { - Some(served) => served.poll_closed(waiter).map(|()| Some(Ok(follow::Event::End))), + Some(served) => served.poll_closed(waiter).map(|()| Some(Ok(None))), None => Poll::Pending, } }) @@ -320,12 +319,12 @@ async fn run_follow( return; }; match next { - Some(Ok(follow::Event::Start(broadcast))) => { + Some(Ok(Some(broadcast))) => { if !served.take().is_some_and(|served| served.is_clone(&broadcast)) { followed.start(inner.serve(broadcast)); } } - Some(Ok(follow::Event::End)) => break (inner, followed), + Some(Ok(None)) => break (inner, followed), Some(Err(err)) => { tracing::warn!(%err, %name, "stopped following broadcast"); break (inner, followed); diff --git a/rs/moq-hls/tests/integration/server.rs b/rs/moq-hls/tests/integration/server.rs index 86412a63d89..eb0a0d1bacf 100644 --- a/rs/moq-hls/tests/integration/server.rs +++ b/rs/moq-hls/tests/integration/server.rs @@ -53,7 +53,7 @@ async fn a_cursor_records_a_publisher_without_fetch() { let remote = kio::clock::timeout(TIMEOUT, origin.follow("live", None).unwrap().available()) .await .expect("request timed out") - .expect("remote broadcast"); + .expect("remote broadcast").unwrap(); let (broadcaster, driver) = Broadcaster::new(moq_mux::Source::new(origin, remote), Default::default()).unwrap(); tokio::spawn(driver.run()); // Recorded as soon as the catalog lists it with its records, as a recorder does. @@ -174,7 +174,7 @@ async fn a_sibling_resolves_through_a_client_session() { let broadcast = kio::clock::timeout(TIMEOUT, origin.follow("room/live", None).unwrap().available()) .await .expect("catalog resolve timed out") - .expect("catalog broadcast"); + .expect("catalog broadcast").unwrap(); let source = moq_mux::Source::new(origin, broadcast); let sibling = kio::clock::timeout( TIMEOUT, @@ -230,7 +230,7 @@ async fn a_disconnected_sibling_publisher_answers_404() { ) .await .expect("sibling resolve timed out") - .expect("sibling broadcast"); + .expect("sibling broadcast").unwrap(); // Only the sibling goes: the catalog keeps listing the rendition, so the request reaches the // media fetch rather than missing the rendition. media_broadcast.close(); diff --git a/rs/moq-mux/src/container/source.rs b/rs/moq-mux/src/container/source.rs index 60fd55b4b34..1ab31886fd2 100644 --- a/rs/moq-mux/src/container/source.rs +++ b/rs/moq-mux/src/container/source.rs @@ -1101,7 +1101,7 @@ mod tests { .unwrap(); broadcast.announce(Default::default()).unwrap(); let consumer = subscriber.consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); let source = crate::Source::new(consumer, remote); let mut export = ExportSource::for_audio(&source, "audio", &audio(None), Duration::from_secs(1)) .unwrap() @@ -1178,7 +1178,7 @@ mod tests { .unwrap(); broadcast.announce(Default::default()).unwrap(); let consumer = subscriber.consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); let source = crate::Source::new(consumer, remote); // MPEG-1 audio from TS: one 24 ms frame per group, a PES of five written at once. diff --git a/rs/moq-mux/src/container/ts/export_test.rs b/rs/moq-mux/src/container/ts/export_test.rs index d511e8587ca..c360cf81081 100644 --- a/rs/moq-mux/src/container/ts/export_test.rs +++ b/rs/moq-mux/src/container/ts/export_test.rs @@ -8812,7 +8812,7 @@ async fn same_instance_returns(finish: bool) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); let mut export = export.follow(back, stream).unwrap(); frames.extend(drain_frames(&mut export).await); @@ -8890,7 +8890,7 @@ async fn a_return_keeps_catalog_and_group_history() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); assert_eq!(back.info().instance.as_ref(), Some(&instance)); assert!(!back.is_clone(&old), "the withdrawn front is replaced"); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); @@ -9174,7 +9174,7 @@ async fn export_stats_count_only_returned_output() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); let mut export = export.follow(back, stream).unwrap(); for ms in (1_000..1_200).step_by(20) { @@ -11315,7 +11315,7 @@ async fn a_track_renamed_on_its_pid_across_returns_retires_the_one_before() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); export = export.follow(back, stream).unwrap(); drain_frames(&mut export).await; @@ -11381,7 +11381,7 @@ async fn a_track_renamed_on_its_pid_across_a_return_is_quiet_from_its_listing() .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); let mut export = export.follow(back, stream).unwrap(); drain_frames(&mut export).await; @@ -11787,7 +11787,7 @@ async fn an_expired_follow_stops_healthy_input_but_drains_its_buffered_tail() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); @@ -11944,7 +11944,7 @@ async fn a_replacement_leaving_before_it_commits_keeps_the_old_program() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); @@ -12074,7 +12074,7 @@ async fn an_empty_finished_replacement_drains_the_old_program() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&replacement, Default::default()) .await .unwrap(); @@ -12132,7 +12132,7 @@ async fn cold_same_instance_return(pending: bool) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); @@ -12162,7 +12162,7 @@ async fn cold_same_instance_return(pending: bool) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); diff --git a/rs/moq-mux/src/container/ts/follower.rs b/rs/moq-mux/src/container/ts/follower.rs index 1f3bdbf0beb..4ffe82c9cd2 100644 --- a/rs/moq-mux/src/container/ts/follower.rs +++ b/rs/moq-mux/src/container/ts/follower.rs @@ -9,7 +9,6 @@ use kio::clock::Instant; use super::{Export, catalog}; use crate::container::Frame; -use crate::follow::{Event, Instances}; type Subscribing = Pin>> + Send>>; @@ -60,7 +59,7 @@ enum State { } /// Carries an [`Export`] across its broadcast's returns, following the publisher instances -/// serving its path through [`Instances`]. +/// serving its path through [`Following`](moq_net::origin::Following). /// /// The same stream (the same instance) returning within the [follow](Self::with_follow) /// continues the export. Another instance taking the path fails with @@ -77,11 +76,11 @@ enum State { /// An instance that comes back is awaited until its catalog serves a first snapshot, with no /// deadline but its own end. A return that refuses its catalog waits for the next change, and /// the follow running out reports that refusal. A refusal to resolve the path at all fails at -/// once, as it does for every [`Instances`] reader. +/// once, as it does for every [`Following`](moq_net::origin::Following) reader. pub struct Follower { export: Export>, state: State, - instances: Instances, + instances: moq_net::origin::Following, path: moq_net::Path, serving: Serving, /// Taking the instances on hand when built, which replay the route the export resolved. @@ -103,7 +102,7 @@ impl Follower { /// Fails when the export's origin can never cover its path. pub fn new(export: Export>) -> crate::Result { let source = export.source(); - let instances = Instances::new(source.origin(), source.path(), None)?; + let instances = source.origin().follow(source.path(), None)?; let mut follower = Self { path: source.path().clone(), export, @@ -344,8 +343,8 @@ impl Follower { fn poll_instances(&mut self, waiter: &kio::Waiter) -> crate::Result { let mut any = false; while !self.closed { - match self.instances.poll_next(waiter) { - Poll::Ready(Ok(Event::Start(broadcast))) => { + match self.instances.poll_available(waiter) { + Poll::Ready(Ok(Some(broadcast))) => { self.serving = match self.export.instance() { // A broadcast not resolved through an origin has no instance to match, // so only the broadcast being exported is its own. @@ -359,9 +358,9 @@ impl Follower { _ => Serving::Other(broadcast), }; } - Poll::Ready(Ok(Event::End)) => self.serving = Serving::Gone, - Poll::Ready(Err(crate::Error::Moq(moq_net::Error::Closed))) => self.closed = true, - Poll::Ready(Err(err)) => return Err(err), + Poll::Ready(Ok(None)) => self.serving = Serving::Gone, + Poll::Ready(Err(moq_net::Error::Closed)) => self.closed = true, + Poll::Ready(Err(err)) => return Err(err.into()), Poll::Pending => break, } any = true; diff --git a/rs/moq-mux/src/follow.rs b/rs/moq-mux/src/follow.rs index 2e50b15cd17..da2ececdd5e 100644 --- a/rs/moq-mux/src/follow.rs +++ b/rs/moq-mux/src/follow.rs @@ -1,110 +1,52 @@ -//! Following a broadcast across the publisher instances that serve it. +//! Following a catalog rendition's broadcast across the publisher instances that serve it. //! //! An announcement is the online and offline signal, so a reader that restarts on each instance //! follows [`Instances`] rather than pinning one broadcast as a [`Binding`](crate::Binding) does. use std::task::Poll; -/// The publisher instances serving a broadcast, as each comes online, takes over, and goes. +/// The publisher instances serving a rendition's broadcast, as each comes online, takes over, +/// and goes. Created by [`Source::follow`](crate::Source::follow). /// -/// Built on [`follow`](moq_net::origin::Consumer::follow). Create one -/// with [`Source::follow`](crate::Source::follow) for a catalog reference, or [`Instances::new`] -/// for a path. -pub struct Instances { - feed: Feed, - /// The instance a reference named, if any. - instance: Option, - /// The instance handed out last, until it stops serving. - current: Option, -} +/// A sibling broadcast is followed through [`Following`](moq_net::origin::Following); the +/// catalog's own broadcast is handed out once and its end never reported, since a reader +/// follows its catalog's end itself. +pub struct Instances(Feed); enum Feed { /// Every instance announced at a path. - Announced(Box), + Following(Box), /// One instance, handed out once. Fixed(Option), } -/// A change to the instance [`Instances`] serves. -pub enum Event { - /// Start on this instance, dropping whatever was read from the one before. - Start(moq_net::broadcast::Consumer), - /// The instance handed out last stopped serving: idle until the next start. - End, -} - impl Instances { - /// Follow the broadcast at `path` through `origin`, handing out only `instance` when given. - /// - /// Unlike [`Source::follow`](crate::Source::follow), this needs no catalog broadcast, so a - /// reader can follow the broadcast whose catalog it reads and build a - /// [`Source`](crate::Source) for each instance. - pub fn new( - origin: &moq_net::origin::Consumer, - path: impl TryInto>, - instance: Option<&moq_net::Instance>, - ) -> crate::Result { - let announced = origin.follow(path, None)?; - Ok(Self::with(Feed::Announced(Box::new(announced)), instance)) + pub(crate) fn following(following: moq_net::origin::Following) -> Self { + Self(Feed::Following(Box::new(following))) } - /// Hand out `broadcast` once and never report its end, which its owner follows. pub(crate) fn fixed(broadcast: moq_net::broadcast::Consumer) -> Self { - Self::with(Feed::Fixed(Some(broadcast)), None) - } - - fn with(feed: Feed, instance: Option<&moq_net::Instance>) -> Self { - Self { - feed, - instance: instance.cloned(), - current: None, - } + Self(Feed::Fixed(Some(broadcast))) } /// Poll for the next change, registering `waiter` when there is none yet. /// - /// Each announcement that brings an instance hands it out, so the same one returns after an - /// end. Fails once the origin closes, and with any resolution failure, such as a handler - /// refusing the path. - pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll> { - loop { - let next = match &mut self.feed { - // Followed unpinned and checked here, so another instance taking over ends the - // rendition rather than waiting for the named one to come back. - Feed::Announced(announced) => announced.poll_available(waiter).map_err(crate::Error::from), - Feed::Fixed(broadcast) => match broadcast.take() { - Some(broadcast) => Poll::Ready(Ok(broadcast)), - None => Poll::Pending, - }, - }; - if let Poll::Ready(next) = next { - let broadcast = next?; - if crate::source::check_instance(self.instance.as_ref(), &broadcast).is_err() { - tracing::debug!(path = %broadcast.info().path, "skipping a broadcast of another instance"); - match self.current.take() { - Some(_) => return Poll::Ready(Ok(Event::End)), - None => continue, - } - } - // A fixed instance ends with its owner, which follows that itself. - if let Feed::Announced(_) = self.feed { - self.current = Some(broadcast.clone()); - } - return Poll::Ready(Ok(Event::Start(broadcast))); - } - - if let Some(current) = &self.current - && current.poll_closed(waiter).is_ready() - { - self.current = None; - return Poll::Ready(Ok(Event::End)); - } - return Poll::Pending; + /// Returns each instance as it comes online or takes over, and `None` once the path goes + /// offline; see [`Following::available`](moq_net::origin::Following::available). Fails + /// once the origin closes, and with any resolution failure, such as a handler refusing the + /// path. + pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll>> { + match &mut self.0 { + Feed::Following(following) => following.poll_available(waiter).map_err(crate::Error::from), + Feed::Fixed(broadcast) => match broadcast.take() { + Some(broadcast) => Poll::Ready(Ok(Some(broadcast))), + None => Poll::Pending, + }, } } /// The next change; see [`Self::poll_next`]. - pub async fn next(&mut self) -> crate::Result { + pub async fn next(&mut self) -> crate::Result> { kio::wait(|waiter| self.poll_next(waiter)).await } } @@ -128,14 +70,10 @@ mod tests { /// The next change a follower reports, which must arrive within the origin's update hold. async fn followed(follow: &mut Instances) -> Option { - let next = kio::clock::timeout(std::time::Duration::from_secs(1), follow.next()) + kio::clock::timeout(std::time::Duration::from_secs(1), follow.next()) .await .expect("no change") - .expect("the follow failed"); - match next { - Event::Start(broadcast) => Some(broadcast), - Event::End => None, - } + .expect("the follow failed") } /// The follower stays quiet past the origin's update hold. diff --git a/rs/moq-mux/src/source.rs b/rs/moq-mux/src/source.rs index f7673a46ee6..bfd3907f889 100644 --- a/rs/moq-mux/src/source.rs +++ b/rs/moq-mux/src/source.rs @@ -389,7 +389,7 @@ impl Source { check_instance(instance, &broadcast)?; crate::follow::Instances::fixed(broadcast) } - false => crate::follow::Instances::new(&self.origin, &path, instance)?, + false => crate::follow::Instances::following(self.origin.follow(&path, instance.cloned())?), }) } } diff --git a/rs/moq-net-tests/tests/announce_allocs.rs b/rs/moq-net-tests/tests/announce_allocs.rs index 77c0e0a80cb..5e04eeaa706 100644 --- a/rs/moq-net-tests/tests/announce_allocs.rs +++ b/rs/moq-net-tests/tests/announce_allocs.rs @@ -90,7 +90,7 @@ fn churn_allocs(root: &str, cursors: usize) -> usize { let _winner = producer.publish("room/a", peer_route(1, 1)).unwrap(); let all = Patterns::from(Pattern::all()); let mut cursors: Vec<_> = (0..cursors) - .map(|_| producer.consume().scope(root, &all).unwrap().announced()) + .map(|_| producer.consume().scope(root, &all).unwrap().routes()) .collect(); for cursor in &mut cursors { while cursor.try_next().is_some() {} @@ -281,7 +281,7 @@ async fn a_lite_request_keeps_one_copy_of_its_track_name() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); WATCH.with(|watch| watch.set(TRACK.len())); SIZED.with(|sized| sized.set((0, 0))); let subscriber = remote.track(TRACK).unwrap().subscribe(None).await.unwrap(); diff --git a/rs/moq-net-tests/tests/integration/ietf_conformance.rs b/rs/moq-net-tests/tests/integration/ietf_conformance.rs index 23e1064c41b..fef01dc6666 100644 --- a/rs/moq-net-tests/tests/integration/ietf_conformance.rs +++ b/rs/moq-net-tests/tests/integration/ietf_conformance.rs @@ -62,7 +62,7 @@ async fn routing(version: &str, cluster: bool) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut subscription = remote.track("test").unwrap().subscribe(None).await.unwrap(); crate::support::harness::subscribed(&track).await; let mut group = track.append_group().unwrap(); diff --git a/rs/moq-net-tests/tests/integration/refresh.rs b/rs/moq-net-tests/tests/integration/refresh.rs index 5b5df917977..ff0c7fb1192 100644 --- a/rs/moq-net-tests/tests/integration/refresh.rs +++ b/rs/moq-net-tests/tests/integration/refresh.rs @@ -48,7 +48,7 @@ async fn json_snapshot_refresh_crosses_a_two_relay_cluster() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let remote = remote.track("state").unwrap(); let mut baseline = remote.subscribe(None).await.unwrap(); assert_eq!(baseline.info().refresh, Some(ratio)); @@ -166,7 +166,7 @@ async fn ratio_joins_cross_two_relays() { options.client_subscribe = Some(downstream.clone()); links.push(connect_mock(options).await); } - let remote = b.consume().follow("room", None).unwrap().available().await.unwrap(); + let remote = b.consume().follow("room", None).unwrap().available().await.unwrap().unwrap(); let remote = remote.track("data").unwrap(); let mut baseline = remote.subscribe(None).await.unwrap(); assert_eq!(baseline.info().refresh, (name == "moq-lite-07-wip").then_some(1)); diff --git a/rs/moq-net-tests/tests/integration/restart.rs b/rs/moq-net-tests/tests/integration/restart.rs index 5dd592b221e..7a151f431cd 100644 --- a/rs/moq-net-tests/tests/integration/restart.rs +++ b/rs/moq-net-tests/tests/integration/restart.rs @@ -42,7 +42,7 @@ async fn settle() { } /// The next announce event, failing on a hang. -async fn next_event(announced: &mut announce::Consumer) -> announce::Event { +async fn next_event(announced: &mut origin::Routes) -> origin::RouteEvent { kio::clock::timeout(Duration::from_secs(10), announced.next()) .await .expect("announce hung") @@ -51,7 +51,7 @@ async fn next_event(announced: &mut announce::Consumer) -> announce::Event { /// Expect the restart of `prefix` onto another instance, as `version` carries it: one restart /// on lite-07, an end then a start elsewhere. -async fn expect_restart(version: Version, announced: &mut announce::Consumer, prefix: &str) { +async fn expect_restart(version: Version, announced: &mut origin::Routes, prefix: &str) { expect_replaced( version, announced, @@ -63,13 +63,13 @@ async fn expect_restart(version: Version, announced: &mut announce::Consumer, pr /// Expect the restart of `prefix` as one restart when the wire replaced the instance in /// place, so the path was never absent, or as an end then a start. -async fn expect_replaced(version: Version, announced: &mut announce::Consumer, prefix: &str, restarts: bool) { +async fn expect_replaced(version: Version, announced: &mut origin::Routes, prefix: &str, restarts: bool) { match next_event(announced).await { - announce::Event::Restart(announce) if restarts => assert_eq!(announce.prefix.as_str(), prefix), - announce::Event::End(announce) if !restarts => { + origin::RouteEvent::Restart(announce) if restarts => assert_eq!(announce.prefix.as_str(), prefix), + origin::RouteEvent::End(announce) if !restarts => { assert_eq!(announce.prefix.as_str(), prefix); match next_event(announced).await { - announce::Event::Start(announce) => assert_eq!(announce.prefix.as_str(), prefix), + origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), prefix), other => panic!("{version}: expected the start, got {other:?}"), } } @@ -78,7 +78,7 @@ async fn expect_replaced(version: Version, announced: &mut announce::Consumer, p } /// Nothing more arrives, past the update hold. -async fn quiet(version: Version, announced: &mut announce::Consumer) { +async fn quiet(version: Version, announced: &mut origin::Routes) { if let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { panic!("{version}: expected nothing more, got {event:?}"); } @@ -121,9 +121,9 @@ async fn relay_chain(version: &str) { let old = publisher.publish("live", origin::Route::default()).unwrap(); let old_track = old.create_track("video", timed()).unwrap(); - let mut announced = viewer.consume().announced(); + let mut announced = viewer.consume().routes(); match next_event(&mut announced).await { - announce::Event::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected the route, got {other:?}"), } @@ -245,9 +245,9 @@ async fn prefix_pool(version: &str) { let instance = announce.route.instance.expect("a delivered route has an instance"); instance.as_str().strip_prefix("worker-").expect("a worker").to_string() }; - let mut announced = downstream.consume().announced(); + let mut announced = downstream.consume().routes(); let mut prefix = match next_event(&mut announced).await { - announce::Event::Start(announce) => advertised(announce), + origin::RouteEvent::Start(announce) => advertised(announce), other => panic!("{version}: expected the pool, got {other:?}"), }; @@ -273,7 +273,7 @@ async fn prefix_pool(version: &str) { settle().await; while let Ok(Some(event)) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { match event { - announce::Event::Restart(announce) => prefix = advertised(announce), + origin::RouteEvent::Restart(announce) => prefix = advertised(announce), other => panic!("{version}: expected a restart at most, got {other:?}"), } } @@ -358,9 +358,9 @@ async fn dynamic_instance(version: &str, from: Option, to: Instance) { let _downstream = link(version, &relay, &viewer).await; let claim = Claim::new(&publisher, from.clone()); - let mut announced = viewer.consume().announced(); + let mut announced = viewer.consume().routes(); match next_event(&mut announced).await { - announce::Event::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected the claim, got {other:?}"), } @@ -372,7 +372,7 @@ async fn dynamic_instance(version: &str, from: Option, to: Instance) { claim.update_route(claim.dynamic.route().with_cost(5)); while let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { assert!( - matches!(event, Some(announce::Event::Update(_))), + matches!(event, Some(origin::RouteEvent::Update(_))), "{version}: a re-price delivered {event:?}" ); } @@ -462,8 +462,8 @@ async fn retired_fetch(version: &str, explicit: bool) { }; let old = publisher.publish("live", old_route).unwrap(); let old_track = old.create_track("video", timed()).unwrap(); - let mut announced = viewer.consume().announced(); - assert!(matches!(next_event(&mut announced).await, announce::Event::Start(_))); + let mut announced = viewer.consume().routes(); + assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); let (held, mut subscription) = subscribe(&viewer, "live").await; let track = held.track("video").unwrap(); write(&old_track, "old:0"); @@ -540,8 +540,8 @@ async fn unanswered_takeover(version: &str) { let old = publisher.publish("live", origin::Route::default()).unwrap(); // Quiet, so the publisher has nothing to answer the SUBSCRIBE with yet. let old_track = old.create_track("video", timed()).unwrap(); - let mut announced = viewer.consume().announced(); - assert!(matches!(next_event(&mut announced).await, announce::Event::Start(_))); + let mut announced = viewer.consume().routes(); + assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); let (_held, mut subscription) = subscribe(&viewer, "live").await; settle().await; assert!( @@ -599,14 +599,14 @@ async fn withdrawal_refuses_new_fetches_but_keeps_open_reads() { let _session = link(version, &publisher, &viewer).await; let source = publisher.publish("live", origin::Route::default()).unwrap(); let produced = source.create_track("video", timed()).unwrap(); - let mut announced = viewer.consume().announced(); - assert!(matches!(next_event(&mut announced).await, announce::Event::Start(_))); + let mut announced = viewer.consume().routes(); + assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); let (held, mut subscription) = subscribe(&viewer, "live").await; let track = held.track("video").unwrap(); write(&produced, "old:0"); assert_eq!(read(&mut subscription).await, "old:0"); source.unannounce(); - assert!(matches!(next_event(&mut announced).await, announce::Event::End(_))); + assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::End(_))); assert!(track.fetch_group(1, None).await.is_err(), "{version}"); write(&produced, "old:1"); assert_eq!(read(&mut subscription).await, "old:1"); @@ -621,8 +621,8 @@ async fn a_more_specific_source_cannot_fill_a_held_covering_track() { let viewer = produce_origin(2); let _session = link(version, &publisher, &viewer).await; let old = Claim::new(&publisher, None); - let mut announced = viewer.consume().announced(); - assert!(matches!(next_event(&mut announced).await, announce::Event::Start(_))); + let mut announced = viewer.consume().routes(); + assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); let (held, mut subscription) = subscribe(&viewer, "live/job").await; let track = held.track("video").unwrap(); old.write(0, "old:0"); @@ -631,7 +631,7 @@ async fn a_more_specific_source_cannot_fill_a_held_covering_track() { let replacement_track = replacement.create_track("video", timed()).unwrap(); write(&replacement_track, "new:0"); write(&replacement_track, "new:1"); - assert!(matches!(next_event(&mut announced).await, announce::Event::Start(_))); + assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); assert!( track.fetch_group(1, None).await.is_err(), "{version}: covering handle fetched replacement" @@ -778,9 +778,9 @@ async fn priority_update(version: &str, relayed: bool, switch: bool) { .publish("live", origin::Route::default().with_instance(a, 0)) .unwrap(); let old_track = old.create_track("video", timed()).unwrap(); - let mut announced = viewer.consume().announced(); + let mut announced = viewer.consume().routes(); assert!( - matches!(next_event(&mut announced).await, announce::Event::Start(_)), + matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_)), "{case}" ); diff --git a/rs/moq-net/benches/announce.rs b/rs/moq-net/benches/announce.rs index 898798cec81..61049c23176 100644 --- a/rs/moq-net/benches/announce.rs +++ b/rs/moq-net/benches/announce.rs @@ -27,15 +27,15 @@ use moq_net::{ mod replay; /// The previous replay, retained here as a scaling reference. -fn scanned(events: Vec) -> Vec { +fn scanned(events: Vec) -> Vec { let mut initial: Vec = Vec::new(); for event in events { let (update, active) = match event { - announce::Event::Start(update) - | announce::Event::Update(update) - | announce::Event::Restart(update) - | announce::Event::Takeover { announce: update, .. } => (update, true), - announce::Event::End(update) => (update, false), + origin::RouteEvent::Start(update) + | origin::RouteEvent::Update(update) + | origin::RouteEvent::Restart(update) + | origin::RouteEvent::Takeover { announce: update, .. } => (update, true), + origin::RouteEvent::End(update) => (update, false), }; initial.retain(|held| held.prefix != update.prefix); if active { @@ -52,7 +52,7 @@ fn initial(c: &mut Criterion) { let events: Vec<_> = (0..updates) .flat_map(|cost| { (0..routes).map(move |route| { - announce::Event::Update(announce::Announce { + origin::RouteEvent::Update(announce::Announce { prefix: moq_net::Path::new(&format!("route/{route}")).unwrap(), captures: None, route: moq_net::origin::Route::default().with_cost(cost), diff --git a/rs/moq-net/benches/auth.rs b/rs/moq-net/benches/auth.rs index 657bcafed9c..9b364f88646 100644 --- a/rs/moq-net/benches/auth.rs +++ b/rs/moq-net/benches/auth.rs @@ -283,14 +283,14 @@ fn waiting(c: &mut Criterion) { })); } let tokens: Vec<_> = presenting.await.into_iter().map(Result::unwrap).collect(); - let mut announced = receive.consume().announced(); + let mut announced = receive.consume().routes(); let mut seen = std::collections::HashSet::new(); while seen.len() < paths { match announced.next().await.unwrap() { - moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Restart(update) - | moq_net::announce::Event::Takeover { announce: update, .. } + moq_net::origin::RouteEvent::Start(update) + | moq_net::origin::RouteEvent::Update(update) + | moq_net::origin::RouteEvent::Restart(update) + | moq_net::origin::RouteEvent::Takeover { announce: update, .. } if update.prefix.as_str().starts_with(&prefix) => { seen.insert(update.prefix); diff --git a/rs/moq-net/benches/interests.rs b/rs/moq-net/benches/interests.rs index 505aecf666e..7598c3c4e3e 100644 --- a/rs/moq-net/benches/interests.rs +++ b/rs/moq-net/benches/interests.rs @@ -26,16 +26,16 @@ const SHAPES: [(usize, usize); 4] = [(10, 10), (1_000, 10), (10, 1_000), (1_000, struct Table { producer: origin::Producer, _driver: origin::Driver, - _watches: Vec, + _watches: Vec, sessions: Vec, } fn table(watches: usize, sessions: usize) -> Table { let (producer, driver) = origin::Producer::new(origin::Config::new(Hop::new(1).unwrap())); let mut held: Vec<_> = (0..watches) - .map(|i| scoped(&producer, &format!("other/{i}")).announced()) + .map(|i| scoped(&producer, &format!("other/{i}")).routes()) .collect(); - held.push(scoped(&producer, "room").announced()); + held.push(scoped(&producer, "room").routes()); let sessions: Vec<_> = (0..sessions).map(|_| fuzz::interests(&producer)).collect(); for session in &sessions { session.drain(); @@ -63,7 +63,7 @@ fn bench_uncovered(c: &mut Criterion) { let table = table(watches, sessions); let incoming = scoped(&table.producer, "incoming"); b.iter(|| { - drop(incoming.announced()); + drop(incoming.routes()); for session in &table.sessions { assert_eq!(session.drain(), 2); } @@ -81,7 +81,7 @@ fn bench_covered(c: &mut Criterion) { let table = table(watches, sessions); let incoming = scoped(&table.producer, "room/incoming"); b.iter(|| { - drop(incoming.announced()); + drop(incoming.routes()); }); for session in &table.sessions { assert_eq!(session.drain(), 0); diff --git a/rs/moq-net/benches/memory.rs b/rs/moq-net/benches/memory.rs index ab5f261b2b9..d06c96afb51 100644 --- a/rs/moq-net/benches/memory.rs +++ b/rs/moq-net/benches/memory.rs @@ -155,7 +155,7 @@ impl Link { broadcast.announce(Default::default()).unwrap(); let consumer = subscriber.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let mut subscribers = Vec::new(); for index in 0..streams { let track = remote.track(&format!("{index}")).unwrap(); diff --git a/rs/moq-net/benches/origin.rs b/rs/moq-net/benches/origin.rs index 0e0b3eb8935..6f31ddb5fce 100644 --- a/rs/moq-net/benches/origin.rs +++ b/rs/moq-net/benches/origin.rs @@ -75,7 +75,7 @@ struct Fanout { consumer: origin::Consumer, driver: origin::Driver, _publishers: Vec, - subscribers: Vec, + subscribers: Vec, } fn fanout(publishers: usize, subscribers: usize) -> Fanout { @@ -84,7 +84,7 @@ fn fanout(publishers: usize, subscribers: usize) -> Fanout { let publishers = (0..publishers) .map(|i| producer.publish(format!("room/{i}"), origin::Route::default()).unwrap()) .collect(); - let mut subscribers: Vec = (0..subscribers).map(|_| consumer.announced()).collect(); + let mut subscribers: Vec = (0..subscribers).map(|_| consumer.routes()).collect(); // Drain the replay so each iteration measures only what it adds. for cursor in &mut subscribers { while cursor.next().now_or_never().flatten().is_some() {} @@ -141,7 +141,7 @@ fn bench_announce_covering(c: &mut Criterion) { .scope("", &Patterns::from("**/*.chat".parse::().unwrap())) .unwrap(); let consumer = if covering { consumer.covering() } else { consumer }; - let mut cursors: Vec<_> = (0..readers).map(|_| consumer.announced()).collect(); + let mut cursors: Vec<_> = (0..readers).map(|_| consumer.routes()).collect(); for cursor in &mut cursors { while cursor.next().now_or_never().flatten().is_some() {} } @@ -174,7 +174,7 @@ fn bench_pending_churn(c: &mut Criterion) { let _routes: Vec<_> = (0..routes) .map(|i| producer.publish(format!("z/{i}"), origin::Route::default()).unwrap()) .collect(); - let mut cursors: Vec<_> = (0..readers).map(|_| producer.consume().announced()).collect(); + let mut cursors: Vec<_> = (0..readers).map(|_| producer.consume().routes()).collect(); let mut sequence = 0u64; b.iter(|| { sequence += 1; @@ -219,7 +219,7 @@ fn bench_withdraw(c: &mut Criterion) { .unwrap() }) .collect(); - let mut cursors: Vec<_> = (0..subscribers).map(|_| producer.consume().announced()).collect(); + let mut cursors: Vec<_> = (0..subscribers).map(|_| producer.consume().routes()).collect(); for cursor in &mut cursors { while cursor.next().now_or_never().flatten().is_some() {} } @@ -292,7 +292,7 @@ fn bench_withdraw_wave(c: &mut Criterion) { .unwrap() }) .collect(); - let mut cursors: Vec<_> = (0..subscribers).map(|_| producer.consume().announced()).collect(); + let mut cursors: Vec<_> = (0..subscribers).map(|_| producer.consume().routes()).collect(); for cursor in &mut cursors { while cursor.try_next().is_some() {} } @@ -343,7 +343,7 @@ fn bench_route_churn(c: &mut Criterion) { .unwrap() }) .collect(); - let mut cursors: Vec<_> = (0..subscribers).map(|_| producer.consume().announced()).collect(); + let mut cursors: Vec<_> = (0..subscribers).map(|_| producer.consume().routes()).collect(); for cursor in &mut cursors { while cursor.try_next().is_some() {} } @@ -384,7 +384,7 @@ fn bench_announce_mounted(c: &mut Criterion) { .unwrap() }) .collect(); - let mut cursors: Vec = (0..subscribers) + let mut cursors: Vec = (0..subscribers) .map(|project| { producer .mount(format!("p{project}/.svc"), ".svc/p0") @@ -393,7 +393,7 @@ fn bench_announce_mounted(c: &mut Criterion) { .unwrap() .consume() .with_hidden(true) - .announced() + .routes() }) .collect(); for cursor in &mut cursors { @@ -440,7 +440,7 @@ fn bench_announce_fleet(c: &mut Criterion) { let patterns: Patterns = [Pattern::subtree(&format!(".stats/p{}", peer % projects)).unwrap()] .into_iter() .collect(); - consumer.scope("", &patterns).unwrap().announced() + consumer.scope("", &patterns).unwrap().routes() }) .collect(); b.iter(|| { @@ -489,8 +489,8 @@ fn bench_announce_duplicate(c: &mut Criterion) { .unwrap() }) .collect(); - let mut cursors: Vec = (0..subscribers) - .map(|_| consumer.clone().with_hidden(true).announced()) + let mut cursors: Vec = (0..subscribers) + .map(|_| consumer.clone().with_hidden(true).routes()) .collect(); for cursor in &mut cursors { while cursor.next().now_or_never().flatten().is_some() {} @@ -552,7 +552,7 @@ fn bench_reprice_duplicate(c: &mut Criterion) { peer_route(challenger, incumbent_cost + 1), ) .unwrap(); - let mut cursors: Vec = (0..subscribers) + let mut cursors: Vec = (0..subscribers) .map(|peer| { producer .consume() @@ -562,7 +562,7 @@ fn bench_reprice_duplicate(c: &mut Criterion) { ) .unwrap() .with_hidden(true) - .announced() + .routes() }) .collect(); for cursor in &mut cursors { @@ -574,7 +574,7 @@ fn bench_reprice_duplicate(c: &mut Criterion) { for cursor in &mut cursors { // The winner switches between unnamed routes, which is another instance. let event = cursor.next().now_or_never().flatten().expect("winner changed"); - let moq_net::announce::Event::Restart(update) = event else { + let moq_net::origin::RouteEvent::Restart(update) = event else { panic!("expected a restart: got {event:?}"); }; assert_eq!(update.route.cost, moq_net::origin::Cost::new(cost.min(incumbent_cost))); @@ -664,7 +664,7 @@ fn bench_takeover(c: &mut Criterion) { (request, answer(&claim, path)) }; let _answered: Vec<_> = (0..publishers).map(|i| ask(&format!("room/{i}"))).collect(); - let mut cursors: Vec<_> = (0..subscribers).map(|_| consumer.announced()).collect(); + let mut cursors: Vec<_> = (0..subscribers).map(|_| consumer.routes()).collect(); for cursor in &mut cursors { while cursor.next().now_or_never().flatten().is_some() {} } @@ -674,7 +674,7 @@ fn bench_takeover(c: &mut Criterion) { let (request, output) = ask(&format!("room/incoming{n}")); for cursor in &mut cursors { let event = cursor.next().now_or_never().flatten(); - assert!(matches!(event, Some(announce::Event::Takeover { .. })), "{event:?}"); + assert!(matches!(event, Some(origin::RouteEvent::Takeover { .. })), "{event:?}"); } drop(request); drop(output); @@ -735,9 +735,9 @@ fn bench_subscribe(c: &mut Criterion) { group.bench_function(id, |b| { let fleet = fanout(publishers, subscribers); b.iter(|| { - let mut cursor = fleet.consumer.announced(); + let mut cursor = fleet.consumer.routes(); let mut replayed = 0; - while let Some(announce::Event::Start(_)) = cursor.next().now_or_never().flatten() { + while let Some(origin::RouteEvent::Start(_)) = cursor.next().now_or_never().flatten() { replayed += 1; } assert_eq!(replayed, publishers); @@ -842,7 +842,7 @@ struct Pool { _members: Vec, _producers: Vec, _consumers: Vec, - cursors: Vec, + cursors: Vec, } impl Pool { @@ -857,7 +857,7 @@ impl Pool { fn pool(members: usize, paths: usize, cursors: usize) -> Pool { let (producer, mut driver) = origin::Producer::new(origin::Config::new(Hop::new(1).unwrap())); let consumer = producer.consume(); - let cursors = (0..cursors).map(|_| consumer.announced()).collect(); + let cursors = (0..cursors).map(|_| consumer.routes()).collect(); let members: Vec<_> = (0..members) .map(|i| { moq_net::fuzz::requests_route( @@ -1166,7 +1166,7 @@ async fn watching(routes: usize, subscribers: usize) -> Watching { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let subscription = remote.track("video").unwrap().subscribe(None).await.unwrap(); subscriptions.push(subscription); } diff --git a/rs/moq-net/benches/path.rs b/rs/moq-net/benches/path.rs index 2b8f5bd2621..648f204f281 100644 --- a/rs/moq-net/benches/path.rs +++ b/rs/moq-net/benches/path.rs @@ -173,7 +173,7 @@ fn fanout() { let _pubs: Vec<_> = (0..100) .map(|i| producer.publish(format!("room/{i}"), origin::Route::default()).unwrap()) .collect(); - let mut cursors: Vec = (0..100).map(|_| consumer.announced()).collect(); + let mut cursors: Vec = (0..100).map(|_| consumer.routes()).collect(); for cursor in &mut cursors { while cursor.next().now_or_never().flatten().is_some() {} } diff --git a/rs/moq-net/benches/session/mod.rs b/rs/moq-net/benches/session/mod.rs index d8554982cdc..06247231cc3 100644 --- a/rs/moq-net/benches/session/mod.rs +++ b/rs/moq-net/benches/session/mod.rs @@ -541,7 +541,7 @@ pub(crate) struct Pair { pub client: moq_net::Session, pub server_transport: MockSession, pub server: Option, - pub discovery: Option, + pub discovery: Option, pub task: Option>, } @@ -688,7 +688,7 @@ impl Cluster { struct Viewer { /// Announcements watched without a subscription, one announce request each. - following: Vec, + following: Vec, subscribers: Vec, fetches: Vec<(usize, track::Consumer)>, blocked: usize, @@ -705,9 +705,9 @@ impl Viewer { .consume() .scope(path, &moq_net::Patterns::from(moq_net::Pattern::all())) .unwrap() - .announced(); + .routes(); let event = announced.next().await.expect("announced"); - assert!(matches!(event, moq_net::announce::Event::Start(_)), "{event:?}"); + assert!(matches!(event, moq_net::origin::RouteEvent::Start(_)), "{event:?}"); self.following.push(announced); } @@ -720,7 +720,7 @@ impl Viewer { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); for track in tracks { self.subscribers.push( broadcast @@ -790,7 +790,7 @@ impl Room { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); viewer.fetches.push((broadcast, source.track(TRACK).unwrap())); } else { viewer.watch(&path(broadcast), &[TRACK], shape.subscription()).await; @@ -1596,7 +1596,7 @@ impl ChurnRoom { .unwrap() .available() .await - .unwrap(), + .unwrap().unwrap(), ); viewers.push(viewer); } @@ -1778,7 +1778,7 @@ pub(crate) fn withdrawal(c: &mut Criterion) { ..Shape::BASE }; let cluster = Cluster::::new("moq-lite-06", shape).await; - let mut announced = B::origin(cluster.relays.last().unwrap()).consume().announced(); + let mut announced = B::origin(cluster.relays.last().unwrap()).consume().routes(); let live: Vec<_> = (0..broadcasts) .map(|i| { B::origin(&cluster.relays[i % (relays - 1)]) @@ -1796,7 +1796,7 @@ pub(crate) fn withdrawal(c: &mut Criterion) { while let Ok(Some(event)) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { - assert!(matches!(event, moq_net::announce::Event::End(_)), "{event:?}"); + assert!(matches!(event, moq_net::origin::RouteEvent::End(_)), "{event:?}"); retracted += 1; } let elapsed = start.elapsed(); diff --git a/rs/moq-net/benches/stats.rs b/rs/moq-net/benches/stats.rs index b35f04a31a8..846cffdbb61 100644 --- a/rs/moq-net/benches/stats.rs +++ b/rs/moq-net/benches/stats.rs @@ -17,7 +17,7 @@ struct Registry { registry: stats::Registry, _driver: origin::Driver, _publishers: Vec, - _cursors: Vec, + _cursors: Vec, } fn registry(broadcasts: usize, tiers: usize) -> Registry { @@ -31,7 +31,7 @@ fn registry(broadcasts: usize, tiers: usize) -> Registry { let session = registry .tier(stats::Tier::new(moq_net::Path::new(&format!("tier{t}")).unwrap())) .session(moq_net::Path::from_static("root")); - let mut cursor = producer.consume().with_stats(session).announced(); + let mut cursor = producer.consume().with_stats(session).routes(); // Each announce the cursor replays records under its tier. while cursor.next().now_or_never().flatten().is_some() {} cursor diff --git a/rs/moq-net/benches/synced.rs b/rs/moq-net/benches/synced.rs index 1716a716c37..cf4b92678f3 100644 --- a/rs/moq-net/benches/synced.rs +++ b/rs/moq-net/benches/synced.rs @@ -25,7 +25,7 @@ struct Table { producer: origin::Producer, _driver: origin::Driver, _streams: Vec, - _consumers: Vec, + _consumers: Vec, } fn table(streams: usize, consumers: usize) -> Table { @@ -34,7 +34,7 @@ fn table(streams: usize, consumers: usize) -> Table { .map(|i| fuzz::snapshot(&producer, &format!("room/{i}"))) .collect(); let consumers = (0..consumers) - .map(|i| scoped(&producer, &format!("other/{i}")).announced()) + .map(|i| scoped(&producer, &format!("other/{i}")).routes()) .collect(); Table { producer, @@ -57,7 +57,7 @@ fn bench_land(c: &mut Criterion) { let id = BenchmarkId::from_parameter(format!("{streams}st_{consumers}c")); group.bench_function(id, |b| { let table = table(streams, consumers); - let watcher = scoped(&table.producer, "room/incoming").announced(); + let watcher = scoped(&table.producer, "room/incoming").routes(); b.iter(|| { let snapshot = fuzz::snapshot(&table.producer, "room/incoming"); assert!(!watcher.poll_synced(&moq_net::kio::Waiter::noop()).is_ready()); @@ -78,7 +78,7 @@ fn bench_register(c: &mut Criterion) { let incoming = scoped(&table.producer, "room/incoming"); let _held = fuzz::snapshot(&table.producer, "room/incoming"); b.iter(|| { - let watcher = incoming.announced(); + let watcher = incoming.routes(); assert!(!watcher.poll_synced(&moq_net::kio::Waiter::noop()).is_ready()); }); }); diff --git a/rs/moq-net/src/auth.rs b/rs/moq-net/src/auth.rs index ee6eeff6d5a..37e2c6eed14 100644 --- a/rs/moq-net/src/auth.rs +++ b/rs/moq-net/src/auth.rs @@ -2476,7 +2476,7 @@ impl Enforce { pub(crate) fn poll( &mut self, handle: &Link, - announced: &mut crate::announce::Consumer, + announced: &mut crate::origin::Routes, waiter: &kio::Waiter, ) -> Poll> { if !self.setup { @@ -2498,7 +2498,7 @@ impl Enforce { return Poll::Ready(None); }; match event { - crate::announce::Event::Start(update) | crate::announce::Event::Update(update) + crate::origin::RouteEvent::Start(update) | crate::origin::RouteEvent::Update(update) if !self.live.contains(&update.prefix) => { if self.pending.iter().any(|gate| gate.path == update.prefix) { @@ -2514,7 +2514,7 @@ impl Enforce { } self.live.insert(gate.path); } - crate::announce::Event::End(update) => { + crate::origin::RouteEvent::End(update) => { self.live.remove(&update.prefix); self.pending.retain(|gate| gate.path != update.prefix); } diff --git a/rs/moq-net/src/fuzz.rs b/rs/moq-net/src/fuzz.rs index 41a27af2c79..bb5599f534d 100644 --- a/rs/moq-net/src/fuzz.rs +++ b/rs/moq-net/src/fuzz.rs @@ -1889,7 +1889,7 @@ mod tests { let tier = crate::stats::Tier::new(crate::Path::from_static("t")); let session = registry.tier(tier.clone()).session(crate::Path::from_static("root")); let _broadcast = origin.publish("room/1", crate::origin::Route::default()).unwrap(); - let mut cursor = origin.consume().with_stats(session).announced(); + let mut cursor = origin.consume().with_stats(session).routes(); while cursor.next().now_or_never().flatten().is_some() {} bump_publisher_bytes(®istry, crate::Path::from_static("room/1"), &tier, 5); diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index f42ce014e1e..806cc82f1ce 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -3998,7 +3998,7 @@ impl Publisher { .discovery(!self.peer_setup.get().await.hidden || self.origin.includes_hidden()); let ns = Namespaces::new(peer, Target::Requests); - self.run_namespaces(origin.announced(), crate::Path::empty(), ns, Vec::new()) + self.run_namespaces(origin.routes(), crate::Path::empty(), ns, Vec::new()) .await } @@ -4067,7 +4067,7 @@ impl Publisher { // A NAMESPACE is discovery, not a route, so a peer that also hears the unsolicited // PUBLISH_NAMESPACE still gets the match here. - let mut announced = origin.announced(); + let mut announced = origin.routes(); // MoQ Active Count: take what is advertised now, so the OK can say how many // NAMESPACE messages carry it. They go out first, ahead of any change, so with @@ -4122,17 +4122,17 @@ impl Publisher { /// /// A route announced and retracted within the snapshot is left out, and a repeat /// keeps its latest metadata, so each path appears once. - fn snapshot(announced: &mut crate::announce::Consumer) -> Vec { + fn snapshot(announced: &mut crate::origin::Routes) -> Vec { let mut initial = std::collections::BTreeMap::new(); while let Some(event) = announced.try_next() { match event { - crate::announce::Event::Start(update) - | crate::announce::Event::Update(update) - | crate::announce::Event::Restart(update) - | crate::announce::Event::Takeover { announce: update, .. } => { + crate::origin::RouteEvent::Start(update) + | crate::origin::RouteEvent::Update(update) + | crate::origin::RouteEvent::Restart(update) + | crate::origin::RouteEvent::Takeover { announce: update, .. } => { initial.insert(update.prefix.clone(), update); } - crate::announce::Event::End(update) => { + crate::origin::RouteEvent::End(update) => { initial.remove(&update.prefix); } } @@ -4147,7 +4147,7 @@ impl Publisher { /// for a subset). async fn run_namespaces( &self, - mut announced: crate::announce::Consumer, + mut announced: crate::origin::Routes, mut prefix: crate::Path, mut ns: Namespaces, initial: Vec, @@ -4237,16 +4237,16 @@ impl Publisher { } if let Poll::Ready(next) = announced.poll_next(waiter) { return Poll::Ready(NamespaceEvent::Update(next.map(|event| match event { - crate::announce::Event::Start(update) | crate::announce::Event::Update(update) => { + crate::origin::RouteEvent::Start(update) | crate::origin::RouteEvent::Update(update) => { (update, true, false) } - crate::announce::Event::Restart(update) => (update, true, true), + crate::origin::RouteEvent::Restart(update) => (update, true, true), // moq-transport has no takeover: another instance, in place or not. - crate::announce::Event::Takeover { announce, predecessor } => { + crate::origin::RouteEvent::Takeover { announce, predecessor } => { let restart = predecessor == announce.prefix; (announce, true, restart) } - crate::announce::Event::End(update) => (update, false, false), + crate::origin::RouteEvent::End(update) => (update, false, false), }))); } if retry.poll(waiter).is_ready() { @@ -4315,7 +4315,7 @@ impl Publisher { .origin .scope(&prefix, &scope) .unwrap_or_else(|_| self.origin.empty()); - announced = self.advertising(origin, &ns.peer).discovery(ns.hidden).announced(); + announced = self.advertising(origin, &ns.peer).discovery(ns.hidden).routes(); retry_at = None; retry_delay = RETRY_BASE; } @@ -14678,7 +14678,7 @@ mod tests { let peer = cluster::Peer::default(); // The cursor is what filters: an excluded consumer never sees the echoed route. - let mut announced = consumer.excluding(assigned).announced(); + let mut announced = consumer.excluding(assigned).routes(); let local = announced.assert_next_active("from/us"); announced.assert_next_wait(); @@ -14718,7 +14718,7 @@ mod tests { hop: Some(r1), cost: None, }; - let mut announced = consumer.excluding(publisher.exclude(&peer)).announced(); + let mut announced = consumer.excluding(publisher.exclude(&peer)).routes(); announced.assert_next_wait(); let forwarded = cluster::Advert::forward(&hops, 0, crate::Hop::new(1).unwrap()).unwrap(); @@ -14790,7 +14790,7 @@ mod tests { hop: Some(crate::Hop::UNKNOWN), cost: None, }; - let mut announced = consumer.excluding(publisher.exclude(&peer)).announced(); + let mut announced = consumer.excluding(publisher.exclude(&peer)).routes(); announced.assert_next_wait(); } diff --git a/rs/moq-net/src/ietf/session.rs b/rs/moq-net/src/ietf/session.rs index ebb3e128260..2b439958454 100644 --- a/rs/moq-net/src/ietf/session.rs +++ b/rs/moq-net/src/ietf/session.rs @@ -1362,7 +1362,7 @@ impl EnforceGrant { fn poll(&mut self, waiter: &kio::Waiter) -> std::task::Poll> { let origin: origin::Consumer = wait!(Origin => self.publisher.poll_serving_origin(waiter)); // Checking what we publish is not a local reader asking to discover anything. - let mut announced: crate::announce::Consumer = origin.clone().serving().announced(); + let mut announced: crate::origin::Routes = origin.clone().serving().routes(); let mut check: crate::auth::Enforce = crate::auth::Enforce::default(); let path = wait!(Check => check.poll(&self.auth, announced, waiter)); let Some(path) = path else { @@ -1407,7 +1407,7 @@ mod tests { use std::sync::atomic::Ordering; for version in [Version::Draft18] { let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); - let interest = origin.consume().announced(); + let interest = origin.consume().routes(); let session = crate::lite::test_transport::ScriptedSession::new(Vec::new()).without_credit(); let log = session.log.clone(); let session = crate::driver::Transport::new(session); @@ -1810,7 +1810,7 @@ mod tests { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); // A client asks only about what is watched. - let _watch = origin.consume().announced(); + let _watch = origin.consume().routes(); let session = crate::lite::test_transport::ScriptedSession::new(namespace_without_hop_path(VERSION).await); let log = session.log.clone(); @@ -1874,7 +1874,7 @@ mod tests { let scoped = origin .scope("rootns", &scope) .expect("scope the origin to two prefixes"); - let _watch = scoped.consume().announced(); + let _watch = scoped.consume().routes(); let gate = kio::Producer::new(true); let session = crate::lite::test_transport::SinkSession::gated_bi(gate.consume()); @@ -1937,12 +1937,12 @@ mod tests { } /// Watch everything under `prefix`. - fn watch(origin: &crate::origin::Producer, prefix: &str) -> crate::announce::Consumer { + fn watch(origin: &crate::origin::Producer, prefix: &str) -> crate::origin::Routes { origin .consume() .scope(prefix, &crate::Patterns::from(crate::Pattern::all())) .unwrap() - .announced() + .routes() } /// Start a client feeding `subscribe` against a peer that answers nothing and declared diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index e3b5e247c24..d07e188234c 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -7107,7 +7107,7 @@ mod tests { let session = crate::lite::test_transport::ScriptedSession::new(counted_response(VERSION, Some(2), entries).await); let (mut subscriber, consumer, snapshot) = counted_subscriber(VERSION, true, session.clone()); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); let (_live, live) = live(); let stream = Stream::open(&mut crate::driver::Transport::new(session.clone()), VERSION) .await @@ -7135,7 +7135,7 @@ mod tests { const VERSION: Version = Version::Draft18; let session = crate::lite::test_transport::ScriptedSession::new(counted_response(VERSION, None, &[]).await); let (mut subscriber, consumer, snapshot) = counted_subscriber(VERSION, false, session.clone()); - let cursor = consumer.announced(); + let cursor = consumer.routes(); assert!(!cursor.is_synced()); let (_live, live) = live(); let stream = Stream::open(&mut crate::driver::Transport::new(session.clone()), VERSION) @@ -8869,13 +8869,13 @@ mod tests { .start_announce(crate::Path::from_static("room/host"), advert, Admit::Session(None)) .unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let route = announced.expect_next_active("room/host").await; let hops: Vec<_> = route.hops.iter().copied().collect(); assert_eq!(hops, vec![crate::Hop::UNKNOWN]); assert!(route.is_anonymous()); - let mut hidden = consumer.excluding(assigned).announced(); + let mut hidden = consumer.excluding(assigned).routes(); hidden.assert_next_wait(); } @@ -8893,12 +8893,12 @@ mod tests { let origin = crate::origin::Config::new(self_origin).produce(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); // The publish direction: an origin handle scoped to the peer, which is what // `Client::with_peer_hop` hands the publisher. Holding its announce stream // is what records that the peer has been offered these paths. - let mut publishing = consumer.clone().excluding(peer).announced(); + let mut publishing = consumer.clone().excluding(peer).routes(); // What we are publishing to the peer: a real upstream route. let upstream = crate::Hops::try_from(vec![crate::Hop::new(7).unwrap()]).unwrap(); @@ -8946,7 +8946,7 @@ mod tests { let origin = crate::origin::Config::new(self_origin).produce(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let connect = || { let (tasks, task_set) = crate::util::TaskSet::new(); @@ -8983,7 +8983,7 @@ mod tests { announced.assert_next_wait(); // Neither route is offered back to the peer they both came from. - consumer.clone().excluding(peer).announced().assert_next_wait(); + consumer.clone().excluding(peer).routes().assert_next_wait(); // The stale session finally retracting leaves the fresh route standing. drop(first); @@ -9019,12 +9019,12 @@ mod tests { /// The current best route covering `path`, if any (synchronous peek). fn routed_now(consumer: &crate::origin::Consumer, path: &str) -> Option { use futures::FutureExt; - match consumer.routes(path).ok()?.next().now_or_never()?? { - crate::announce::Event::End(_) => None, - crate::announce::Event::Start(announce) - | crate::announce::Event::Update(announce) - | crate::announce::Event::Restart(announce) - | crate::announce::Event::Takeover { announce, .. } => Some(announce.route), + match consumer.path_routes(path).ok()?.next().now_or_never()?? { + crate::origin::RouteEvent::End(_) => None, + crate::origin::RouteEvent::Start(announce) + | crate::origin::RouteEvent::Update(announce) + | crate::origin::RouteEvent::Restart(announce) + | crate::origin::RouteEvent::Takeover { announce, .. } => Some(announce.route), } } @@ -10906,7 +10906,7 @@ mod tests { assert!(futures::poll!(run.as_mut()).is_pending(), "the announce ended early"); let _ = task_set.poll(&kio::Waiter::noop()); if let Poll::Ready(routed) = futures::poll!(routing.as_mut()) { - broadcast = Some(routed.expect("the announce routes the broadcast")); + broadcast = routed.expect("the announce routes the broadcast"); break; } settle().await; diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index 64d97ad40f5..deaefa697b5 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -991,7 +991,7 @@ pub(crate) async fn test_hop( ); downstream .consume() - .routes(broadcast) + .path_routes(broadcast) .unwrap() .next() .await diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 865488d068f..494c5996500 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -3,7 +3,7 @@ use crate::transport::poll::Session as _; #[cfg(test)] use std::sync::atomic::AtomicU64; -use crate::{SessionError, announce, frame, group, origin, track}; +use crate::{SessionError, frame, group, origin, track}; use rangemap::{RangeMap, RangeSet}; use std::{ borrow::Cow, @@ -269,7 +269,7 @@ impl Publisher { async fn run_announce( stream: &mut Stream, origin: &origin::Consumer, - announced: &mut announce::Consumer, + announced: &mut origin::Routes, self_origin: Hop, version: Version, auth: Option, @@ -611,7 +611,7 @@ impl AuthServe { #[derive(Default)] struct Enforce { check: crate::auth::Enforce, - announced: Option, + announced: Option, } impl Enforce { @@ -620,7 +620,7 @@ impl Enforce { Some(announced) => announced, None => { let origin = ready!(shared.poll_serving_origin(waiter)); - self.announced.insert(origin.announced()) + self.announced.insert(origin.routes()) } }; let Some(path) = ready!(self.check.poll(&shared.auth, announced, waiter)) else { @@ -889,7 +889,7 @@ impl AnnounceServe { Some(hop) => Poll::Ready(*hop), None => self.shared.peer_setup.poll_hop(waiter).map(|hop| hop.unwrap_or(*assigned)), }); - let (origin, announced, run): (origin::Consumer, announce::Consumer, AnnounceRun) = + let (origin, announced, run): (origin::Consumer, origin::Routes, AnnounceRun) = self.start(prefix, exclude_hop, hidden); // Streaming announce updates. @@ -924,7 +924,7 @@ impl AnnounceServe { prefix: crate::Path, exclude_hop: Hop, hidden: bool, - ) -> (origin::Consumer, announce::Consumer, AnnounceRun) { + ) -> (origin::Consumer, origin::Routes, AnnounceRun) { // If the requested prefix is outside our scope (an empty origin, or a token // that doesn't grant it), we simply have nothing to announce. Respond with an // empty set and keep the stream open (the subscriber treats a FIN here as a @@ -958,7 +958,7 @@ impl AnnounceServe { true => origin.with_hidden(true), false => origin, }; - let announced = origin.announced(); + let announced = origin.routes(); let mut run = AnnounceRun::new(prefix, self.shared.self_origin, self.shared.version); run.auth = Some(crate::auth::Gate::new( self.shared.auth.clone(), @@ -1092,17 +1092,17 @@ impl AnnounceRun { // state from a fresh one and start what the grant now covers. The cursor itself stays: // whatever it has pending for the routes the peer holds (an update, a restart, an end // still waiting out its hold) arrives through the loop as usual. - let mut snapshot = origin.announced(); + let mut snapshot = origin.routes(); let mut current: HashMap = HashMap::new(); while let Some(event) = snapshot.try_next() { match event { - announce::Event::Start(update) - | announce::Event::Update(update) - | announce::Event::Restart(update) - | announce::Event::Takeover { announce: update, .. } => { + origin::RouteEvent::Start(update) + | origin::RouteEvent::Update(update) + | origin::RouteEvent::Restart(update) + | origin::RouteEvent::Takeover { announce: update, .. } => { current.insert(update.prefix, update.route); } - announce::Event::End(update) => { + origin::RouteEvent::End(update) => { current.remove(&update.prefix); } } @@ -1346,7 +1346,7 @@ impl AnnounceRun { &mut self, stream: &mut Stream, origin: &origin::Consumer, - announced: &mut announce::Consumer, + announced: &mut origin::Routes, ) -> Result<(), Error> { if !matches!(self.version, Version::Lite01 | Version::Lite02) && !self.version.has_announce_ok() { return Ok(()); @@ -1408,7 +1408,7 @@ impl AnnounceRun { &mut self, stream: &mut Stream, origin: &origin::Consumer, - announced: &mut announce::Consumer, + announced: &mut origin::Routes, ) -> Result<(), Error> { match self.phase { AnnouncePhase::Withdrawing | AnnouncePhase::Closing => return Ok(()), @@ -1431,7 +1431,7 @@ impl AnnounceRun { &mut self, stream: &mut Stream, origin: &origin::Consumer, - announced: &mut announce::Consumer, + announced: &mut origin::Routes, waiter: &kio::Waiter, ) -> Poll> { if matches!(self.phase, AnnouncePhase::Init) { @@ -1498,10 +1498,10 @@ impl AnnounceRun { }; let (update, active, restart, predecessor) = match next { - Some(announce::Event::Start(update) | announce::Event::Update(update)) => (update, true, false, None), - Some(announce::Event::Restart(update)) => (update, true, true, None), - Some(announce::Event::Takeover { announce, predecessor }) => (announce, true, false, Some(predecessor)), - Some(announce::Event::End(update)) => (update, false, false, None), + Some(origin::RouteEvent::Start(update) | origin::RouteEvent::Update(update)) => (update, true, false, None), + Some(origin::RouteEvent::Restart(update)) => (update, true, true, None), + Some(origin::RouteEvent::Takeover { announce, predecessor }) => (announce, true, false, Some(predecessor)), + Some(origin::RouteEvent::End(update)) => (update, false, false, None), None => { if self.initial.take().is_some() { stream.writer.buffer(&lite::AnnounceBroadcast::Synced)?; @@ -2844,20 +2844,20 @@ mod announce_test { #[test] fn initial_replay_keeps_the_last_event_and_its_order() { - let update = |prefix: &'static str, cost| announce::Announce { + let update = |prefix: &'static str, cost| crate::announce::Announce { prefix: crate::Path::try_from(prefix).unwrap(), captures: None, route: origin::Route::default().with_cost(cost), }; let events = [ - announce::Event::Start(update("a", 1)), - announce::Event::Start(update("b", 2)), - announce::Event::Update(update("a", 3)), - announce::Event::Start(update("c", 4)), - announce::Event::End(update("b", 2)), - announce::Event::Restart(update("c", 5)), - announce::Event::End(update("c", 5)), - announce::Event::Start(update("b", 6)), + origin::RouteEvent::Start(update("a", 1)), + origin::RouteEvent::Start(update("b", 2)), + origin::RouteEvent::Update(update("a", 3)), + origin::RouteEvent::Start(update("c", 4)), + origin::RouteEvent::End(update("b", 2)), + origin::RouteEvent::Restart(update("c", 5)), + origin::RouteEvent::End(update("c", 5)), + origin::RouteEvent::Start(update("b", 6)), ]; let initial: Vec<_> = super::super::replay::initial(events) .into_iter() @@ -2878,7 +2878,7 @@ mod announce_test { let removed = origin.announce("z/removed", origin::Route::default()).unwrap(); let _initial = origin.announce("z/retained", origin::Route::default()).unwrap(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let budget = kio::Producer::new(0usize); let log = Log::default(); let mut wire = Wire { @@ -2920,7 +2920,7 @@ mod announce_test { let _a = origin.announce("a", origin::Route::default()).unwrap(); let _b = origin.announce("b", origin::Route::default()).unwrap(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let budget = kio::Producer::new(1usize); let log = Log::default(); let mut wire = Wire { @@ -2962,7 +2962,7 @@ mod announce_test { let _a = origin.announce("a", origin::Route::default()).unwrap(); let _b = origin.announce("b", origin::Route::default()).unwrap(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let budget = kio::Producer::new(0usize); let log = Log::default(); let mut wire = Wire { @@ -3018,7 +3018,7 @@ mod announce_test { let first = origin.announce("a", origin::Route::default()).unwrap(); let unseen = origin.announce("b", origin::Route::default()).unwrap(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let budget = kio::Producer::new(1usize); let log = Log::default(); let mut wire = Wire { @@ -3058,7 +3058,7 @@ mod announce_test { let origin = Hop::new(1).unwrap().produce(); let _upstream = origin.snapshot(""); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); assert!(!announced.is_synced()); let log = Log::default(); let mut wire = Wire { @@ -3178,13 +3178,13 @@ mod announce_test { let log = Log::default(); let writes = log.writes.clone(); let consumer = origin.consume(); - assert!(!consumer.announced().is_synced(), "the relay itself is still syncing"); + assert!(!consumer.routes().is_synced(), "the relay itself is still syncing"); let mut stream = Stream:: { writer: Writer::new(crate::transport::boxed::SendStream::new(SinkSend::new(log)), VERSION), reader: Reader::new(crate::transport::boxed::RecvStream::new(PendingRecv), VERSION), }; let _task = kio::clock::sim::spawn(async move { - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let self_origin = consumer.hop(); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, VERSION, None).await }); @@ -3217,7 +3217,7 @@ mod announce_test { reader: Reader::new(crate::transport::boxed::RecvStream::new(PendingRecv), version), }; let task = kio::clock::sim::spawn(async move { - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let self_origin = consumer.hop(); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, version, auth).await }); @@ -3474,7 +3474,7 @@ mod announce_test { reader: Reader::new(crate::transport::boxed::RecvStream::new(PendingRecv), VERSION), }; let task = kio::clock::sim::spawn(async move { - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let self_origin = consumer.hop(); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, VERSION, None).await }); @@ -7138,7 +7138,7 @@ mod serve_group_test { broadcast.announce(Default::default()).unwrap(); let relay = origin(2); let _upstream = connect(version, &publisher, &relay).await; - let remote = relay.consume().follow("room", None).unwrap().available().await.unwrap(); + let remote = relay.consume().follow("room", None).unwrap().available().await.unwrap().unwrap(); let mut keeper = match warm { true => Some( remote @@ -7169,7 +7169,7 @@ mod serve_group_test { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut live = remote .track("test") .unwrap() @@ -7983,7 +7983,7 @@ mod tests { .unwrap(); let consumer = origin.consume().excluding(assigned); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let mut run = std::pin::pin!(Publisher::run_announce( &mut stream, &consumer, @@ -8028,7 +8028,7 @@ mod tests { .await .unwrap(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let err = Publisher::run_announce( &mut stream, &consumer, @@ -8057,7 +8057,7 @@ mod tests { .await .unwrap(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let mut run = std::pin::pin!(Publisher::run_announce( &mut stream, &consumer, @@ -8093,7 +8093,7 @@ mod tests { .await .unwrap(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let mut run = AnnounceRun::new(crate::Path::default(), self_origin, Version::Lite01); run.withdraw(&mut stream, &consumer, &mut announced).unwrap(); diff --git a/rs/moq-net/src/lite/replay.rs b/rs/moq-net/src/lite/replay.rs index cef480f5663..1d5549d6689 100644 --- a/rs/moq-net/src/lite/replay.rs +++ b/rs/moq-net/src/lite/replay.rs @@ -2,19 +2,19 @@ use std::collections::HashMap; -use crate::announce; +use crate::{announce, origin}; /// Keep each prefix's last active event in its original event order. -pub(super) fn initial(events: impl IntoIterator) -> Vec { +pub(super) fn initial(events: impl IntoIterator) -> Vec { let mut pending: Vec> = Vec::new(); let mut positions = HashMap::new(); for event in events { let (update, active) = match event { - announce::Event::Start(update) - | announce::Event::Update(update) - | announce::Event::Restart(update) - | announce::Event::Takeover { announce: update, .. } => (update, true), - announce::Event::End(update) => (update, false), + origin::RouteEvent::Start(update) + | origin::RouteEvent::Update(update) + | origin::RouteEvent::Restart(update) + | origin::RouteEvent::Takeover { announce: update, .. } => (update, true), + origin::RouteEvent::End(update) => (update, false), }; if let Some(index) = positions.remove(&update.prefix) { pending[index] = None; diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 8a10609c858..52fc4d08fa7 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -4641,7 +4641,7 @@ mod tests { use std::sync::atomic::Ordering; for version in [Version::Lite04, Version::Lite07] { let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); - let interest = origin.consume().announced(); + let interest = origin.consume().routes(); let session = crate::lite::test_transport::ScriptedSession::new(Vec::new()).without_credit(); let log = session.log.clone(); let subscriber = Subscriber::new(SubscriberConfig { @@ -6622,13 +6622,13 @@ mod tests { assert!(accepted); // The route is announced synchronously: hop 0 on the wire, assigned id local. - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); let route = cursor.expect_next_active("room/host").await; let hops: Vec<_> = route.hops.iter().copied().collect(); assert_eq!(hops, vec![crate::Hop::UNKNOWN]); assert!(route.is_anonymous()); - let mut hidden = consumer.excluding(assigned).announced(); + let mut hidden = consumer.excluding(assigned).routes(); hidden.assert_next_wait(); } @@ -6668,7 +6668,7 @@ mod tests { .unwrap() ); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); let route = cursor.expect_next_active("room/host").await; let hops: Vec<_> = route.hops.iter().copied().collect(); assert_eq!(hops, vec![crate::Hop::UNKNOWN, crate::Hop::UNKNOWN]); @@ -6695,7 +6695,7 @@ mod tests { ) .unwrap(); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); kio::clock::sim::yield_now().await; let route = cursor.expect_next_active("room/host").await; let hops: Vec<_> = route.hops.iter().copied().collect(); @@ -6803,7 +6803,7 @@ mod tests { ) .unwrap(); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); kio::clock::sim::yield_now().await; cursor.expect_next_active("room/host").await; @@ -6843,7 +6843,7 @@ mod tests { &mut announced, ) .unwrap(); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); cursor.expect_next_active("room/host").await; auth.handle().authorize(&crate::auth::Grant { @@ -6904,7 +6904,7 @@ mod tests { &mut announced, ) .unwrap(); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); cursor.expect_next_active("room/host").await; // The stream ends without retracting anything: the map dies with it and the @@ -6979,7 +6979,7 @@ mod tests { Path::from_static(""), subscriber.origin.snapshot(""), ); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); let mut run = std::pin::pin!(kio::wait(|waiter| prefix.poll(waiter))); assert!(futures::poll!(run.as_mut()).is_pending()); @@ -7068,7 +7068,7 @@ mod tests { } script.extend(announce_script(VERSION, &[&announce_start(VERSION, "a")])); let (mut prefix, consumer) = root_prefix(VERSION, crate::lite::test_transport::ScriptedSession::new(script)); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); let mut polls = 0; kio::wait(|waiter| { @@ -7097,7 +7097,7 @@ mod tests { ], ); let (mut prefix, consumer) = root_prefix(VERSION, crate::lite::test_transport::ScriptedSession::new(script)); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); assert!(!cursor.is_synced(), "held from the request on"); let mut run = std::pin::pin!(kio::wait(|waiter| prefix.poll(waiter))); @@ -7108,7 +7108,7 @@ mod tests { cursor.assert_next_active("b"); assert!(cursor.is_synced()); // A consumer created after the boundary syncs on its replay. - let mut late = consumer.announced(); + let mut late = consumer.routes(); late.assert_next_active("a"); late.assert_next_active("b"); assert!(late.is_synced()); @@ -7120,7 +7120,7 @@ mod tests { const VERSION: Version = Version::Lite06; let script = announce_script(VERSION, &[&announce_ok(VERSION, 2), &announce_start(VERSION, "a")]); let (mut prefix, consumer) = root_prefix(VERSION, crate::lite::test_transport::ScriptedSession::new(script)); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); let mut run = std::pin::pin!(kio::wait(|waiter| prefix.poll(waiter))); assert!(futures::poll!(run.as_mut()).is_pending()); @@ -7135,7 +7135,7 @@ mod tests { let synced = |w: &mut crate::coding::Encoder<'_>| lite::AnnounceBroadcast::Synced.encode(w, VERSION).unwrap(); let script = announce_script(VERSION, &[&announce_ok(VERSION, 0), &synced]); let (mut prefix, consumer) = root_prefix(VERSION, crate::lite::test_transport::ScriptedSession::new(script)); - let cursor = consumer.announced(); + let cursor = consumer.routes(); let mut run = std::pin::pin!(kio::wait(|waiter| prefix.poll(waiter))); assert!(futures::poll!(run.as_mut()).is_pending()); assert!(cursor.is_synced()); @@ -7172,7 +7172,7 @@ mod tests { let session = crate::lite::test_transport::ScriptedSession::new(script); let log = session.log.clone(); let (mut prefix, consumer) = root_prefix(version, session.clone()); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); assert!(prefix.poll(&kio::Waiter::noop()).is_pending()); assert!(log.closes().is_empty()); session.push(&[last]); @@ -7225,7 +7225,7 @@ mod tests { const VERSION: Version = Version::Lite04; let (mut prefix, consumer) = root_prefix(VERSION, crate::lite::test_transport::ScriptedSession::new(Vec::new())); - let cursor = consumer.announced(); + let cursor = consumer.routes(); assert!(!cursor.is_synced()); let mut run = std::pin::pin!(kio::wait(|waiter| prefix.poll(waiter))); assert!(futures::poll!(run.as_mut()).is_pending()); @@ -7247,7 +7247,7 @@ mod tests { VERSION, crate::lite::test_transport::ScriptedSession::new(announce_script(VERSION, &[&init])), ); - let mut cursor = consumer.announced(); + let mut cursor = consumer.routes(); let mut run = std::pin::pin!(kio::wait(|waiter| prefix.poll(waiter))); assert!(futures::poll!(run.as_mut()).is_pending()); assert!(!cursor.is_synced()); diff --git a/rs/moq-net/src/model/announced.rs b/rs/moq-net/src/model/announced.rs new file mode 100644 index 00000000000..63a63980b78 --- /dev/null +++ b/rs/moq-net/src/model/announced.rs @@ -0,0 +1,194 @@ +//! The paths announced under a scope, each present or absent. + +use std::task::Poll; + +use super::origin_impl::{Announce, RouteEvent, Routes}; +use crate::{Error, Path}; + +/// What an announcement listing reports for a path. +#[derive(Clone, Debug)] +pub enum AnnounceEvent { + /// A route now covers the path, which was absent. + Present(Announce), + /// No route covers the path any more. Carries its last advertised route. + Absent(Announce), +} + +impl AnnounceEvent { + /// The announcement this event reports. + pub fn announce(&self) -> &Announce { + match self { + Self::Present(announce) | Self::Absent(announce) => 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: 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, +} + +impl AnnounceConsumer { + pub(super) fn new(routes: Routes) -> Self { + Self { routes } + } + + /// What a route change means for the listing, if anything. + fn list(event: RouteEvent) -> Option { + match event { + RouteEvent::Start(announce) => Some(AnnounceEvent::Present(announce)), + RouteEvent::End(announce) => Some(AnnounceEvent::Absent(announce)), + // A takeover elsewhere starts its own prefix; at its predecessor's it replaces it. + RouteEvent::Takeover { announce, predecessor } if predecessor != announce.prefix => { + Some(AnnounceEvent::Present(announce)) + } + RouteEvent::Update(_) | RouteEvent::Restart(_) | RouteEvent::Takeover { .. } => None, + } + } + + /// Returns the next path that became present or absent, relative to this listing's root. + /// + /// Returns None once the origin closes. The consumer is also a [`futures::Stream`] + /// of the same events. + #[cfg(feature = "async")] + pub async fn next(&mut self) -> Option { + kio::wait(|waiter| self.poll_next(waiter)).await + } + + /// Poll for the next event, registering `waiter` when there is none yet. + /// + /// Returns `Poll::Ready(None)` once the origin closes. + pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll> { + loop { + let Some(event) = std::task::ready!(self.routes.poll_next(waiter)) else { + return Poll::Ready(None); + }; + if let Some(event) = Self::list(event) { + return Poll::Ready(Some(event)); + } + } + } + + /// Returns the next event without blocking. + /// + /// Returns None if there is no event available; NOT because the listing is closed. + /// Use [`Self::is_closed`] to check if the listing is closed. + pub fn try_next(&mut self) -> Option { + loop { + if let Some(event) = Self::list(self.routes.try_next()?) { + return Some(event); + } + } + } + + /// Returns true if the listing is closed (no more events will arrive). + pub fn is_closed(&self) -> bool { + self.routes.is_closed() + } + + /// Wait until this listing has synced with what its sources announced. + /// + /// Synced means every session feeding this scope has delivered its peer's + /// announcements as of when it answered, and this listing has read every event + /// queued before then. A path not present by then is absent, rather than not heard + /// yet. A session joining the scope later, such as a reconnect, takes this back + /// until it syncs too; routes published on this origin itself never wait. + /// + /// Level-triggered: ready whenever synced, and once the listing is closed. + pub fn poll_synced(&self, waiter: &kio::Waiter) -> Poll<()> { + self.routes.poll_synced(waiter) + } + + /// Returns the root that is automatically stripped from reported paths. + pub fn root(&self) -> &Path { + self.routes.root() + } + + /// Converts a reported path back to one rooted at the origin. + pub fn absolute(&self, prefix: impl TryInto>) -> Result { + self.routes.absolute(prefix) + } +} + +#[cfg(feature = "async")] +impl futures::Stream for AnnounceConsumer { + type Item = AnnounceEvent; + + fn poll_next(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll> { + let this = self.get_mut(); + loop { + let Some(event) = std::task::ready!(futures::Stream::poll_next(std::pin::Pin::new(&mut this.routes), cx)) + else { + return Poll::Ready(None); + }; + if let Some(event) = Self::list(event) { + return Poll::Ready(Some(event)); + } + } + } +} + +#[cfg(all(test, feature = "async"))] +mod tests { + use std::time::Duration; + + use super::super::ProduceTest; + use super::*; + use crate::{ + Hop, Instance, + origin::{Cost, Route}, + }; + + /// The listing's next event as `present path` or `absent path`, within the update hold. + async fn listed(announced: &mut AnnounceConsumer) -> String { + let event = kio::clock::timeout(Duration::from_secs(1), announced.next()) + .await + .expect("no event") + .expect("the origin closed"); + match event { + AnnounceEvent::Present(announce) => format!("present {}", announce.prefix), + AnnounceEvent::Absent(announce) => format!("absent {}", announce.prefix), + } + } + + /// The listing stays quiet past the origin's update hold. + async fn quiet(announced: &mut AnnounceConsumer) { + if let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { + panic!("expected nothing, got {event:?}"); + } + } + + fn route(instance: &Instance) -> Route { + Route::default().with_instance(instance.clone(), 0) + } + + /// A path stays present while another instance takes it over or its route changes, and is + /// absent only once nothing covers it. + #[kio::test] + async fn a_path_stays_present_across_instances() { + let origin = Hop::new(1).unwrap().produce(); + let mut announced = origin.consume().announced(); + let mut routes = origin.consume().routes(); + + let first = origin.publish("live", route(&Instance::random())).unwrap(); + assert_eq!(listed(&mut announced).await, "present live"); + assert!(matches!(routes.next().await, Some(RouteEvent::Start(_)))); + + first.announce(route(&Instance::random()).with_cost(Cost::new(5))).unwrap(); + quiet(&mut announced).await; + // The relay-level stream still reports the replacement. + assert!(matches!(routes.next().await, Some(RouteEvent::Restart(_)))); + + let second = origin.publish("live", route(&Instance::random())).unwrap(); + drop(first); + quiet(&mut announced).await; + + drop(second); + assert_eq!(listed(&mut announced).await, "absent live"); + } +} diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index 249fa5a35d8..102a3894614 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -1,7 +1,7 @@ use std::task::{Poll, ready}; use super::WeakEntry; -use super::origin_impl::{Announce, AnnounceConsumer, AnnounceEvent, Consumer, Moved, Requesting}; +use super::origin_impl::{Announce, Routes, RouteEvent, Consumer, Moved, Requesting}; use crate::{Error, Instance, Path, broadcast}; /// The announcements covering one path, as one broadcast coming online, being replaced, and @@ -9,13 +9,13 @@ use crate::{Error, Instance, Path, broadcast}; /// /// Several routes can cover the path at once, such as the path itself and a prefix above it, /// and a request resolves through the most specific one, so only that route's events come -/// through. Another route taking over is a [`Restart`](AnnounceEvent::Restart), unless both +/// through. Another route taking over is a [`Restart`](RouteEvent::Restart), unless both /// carry the same instance: those serve one continuous stream, so it is an -/// [`Update`](AnnounceEvent::Update). One announced as a -/// [`Takeover`](AnnounceEvent::Takeover) of the serving route continues it, and comes through +/// [`Update`](RouteEvent::Update). One announced as a +/// [`Takeover`](RouteEvent::Takeover) of the serving route continues it, and comes through /// as one. Routes beneath the path serve other broadcasts and are ignored. pub(crate) struct Follow { - announced: AnnounceConsumer, + announced: Routes, path: Path, /// Every route standing over the path. covering: Vec, @@ -41,7 +41,7 @@ struct Standing { } impl Follow { - pub(super) fn new(announced: AnnounceConsumer, path: Path) -> Self { + pub(super) fn new(announced: Routes, path: Path) -> Self { Self { announced, path, @@ -54,7 +54,7 @@ impl Follow { /// The next change to the route serving the path, or `None` once the origin closes. #[cfg(all(test, feature = "async"))] - pub async fn next(&mut self) -> Option { + pub async fn next(&mut self) -> Option { kio::wait(|waiter| self.poll_next(waiter)).await } @@ -68,7 +68,7 @@ impl Follow { /// instance. A route whose start came after the serving route's last event, with the cursor /// never running dry in between, may have arrived after its end, so taking over from it is /// reported as that gap. - pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll> { + pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll> { if self.idle { let ended = loop { match self.poll_announced(waiter) { @@ -82,7 +82,7 @@ impl Follow { return match (self.serving().map(|standing| standing.announce.clone()), ended) { (Some(serving), _) => { self.idle = false; - Poll::Ready(Some(AnnounceEvent::Start(serving))) + Poll::Ready(Some(RouteEvent::Start(serving))) } (None, true) => Poll::Ready(None), (None, false) => Poll::Pending, @@ -94,7 +94,7 @@ impl Follow { return Poll::Ready(None); }; if let Some(event) = self.fold(event) { - self.idle = matches!(event, AnnounceEvent::End(_)); + self.idle = matches!(event, RouteEvent::End(_)); return Poll::Ready(Some(event)); } } @@ -102,13 +102,13 @@ impl Follow { /// Poll until every source feeding this follower has synced, registering `waiter` until /// then. A path [`poll_next`](Self::poll_next) has not started by then is not announced, - /// rather than not heard yet. See [`AnnounceConsumer::poll_synced`]. + /// rather than not heard yet. See [`Routes::poll_synced`]. pub fn poll_synced(&self, waiter: &kio::Waiter) -> Poll<()> { self.announced.poll_synced(waiter) } /// The cursor's next event, counting what it delivers and when it runs dry. - fn poll_announced(&mut self, waiter: &kio::Waiter) -> Poll> { + fn poll_announced(&mut self, waiter: &kio::Waiter) -> Poll> { let poll = self.announced.poll_next(waiter); match poll { Poll::Ready(Some(_)) => self.taken += 1, @@ -126,12 +126,12 @@ impl Follow { } /// Apply one route's event, returning what it means for the path, if anything. - fn fold(&mut self, event: AnnounceEvent) -> Option { - let (AnnounceEvent::Start(announce) - | AnnounceEvent::Update(announce) - | AnnounceEvent::Restart(announce) - | AnnounceEvent::Takeover { announce, .. } - | AnnounceEvent::End(announce)) = &event; + fn fold(&mut self, event: RouteEvent) -> Option { + let (RouteEvent::Start(announce) + | RouteEvent::Update(announce) + | RouteEvent::Restart(announce) + | RouteEvent::Takeover { announce, .. } + | RouteEvent::End(announce)) = &event; if !self.path.has_prefix(&announce.prefix) { return None; } @@ -146,11 +146,11 @@ impl Follow { .position(|standing| standing.announce.prefix == prefix) .map(|index| self.covering.swap_remove(index).since); let (announce, since, restart, predecessor) = match event { - AnnounceEvent::End(_) => (None, None, false, None), - AnnounceEvent::Start(announce) => (Some(announce), None, false, None), - AnnounceEvent::Update(announce) => (Some(announce), standing, false, None), - AnnounceEvent::Restart(announce) => (Some(announce), standing, true, None), - AnnounceEvent::Takeover { announce, predecessor } => (Some(announce), None, true, Some(predecessor)), + RouteEvent::End(_) => (None, None, false, None), + RouteEvent::Start(announce) => (Some(announce), None, false, None), + RouteEvent::Update(announce) => (Some(announce), standing, false, None), + RouteEvent::Restart(announce) => (Some(announce), standing, true, None), + RouteEvent::Takeover { announce, predecessor } => (Some(announce), None, true, Some(predecessor)), }; if let Some(announce) = announce { self.covering.push(Standing { @@ -165,19 +165,19 @@ impl Follow { .map(|standing| (standing.announce.clone(), standing.since)); match (before, after) { (None, None) => None, - (None, Some((after, _))) => Some(AnnounceEvent::Start(after)), - (Some((before, _)), None) => Some(AnnounceEvent::End(before)), + (None, Some((after, _))) => Some(RouteEvent::Start(after)), + (Some((before, _)), None) => Some(RouteEvent::End(before)), // The serving route ended, and the one left may have started after it did. (Some((before, seen)), Some((after, since))) if before.prefix == prefix && before.prefix != after.prefix && since > self.dry.max(seen) => { - Some(AnnounceEvent::End(before)) + Some(RouteEvent::End(before)) } // The serving route continues as this one. (Some((before, _)), Some((after, _))) if after.prefix == prefix && predecessor.as_ref() == Some(&before.prefix) => { - Some(AnnounceEvent::Takeover { + Some(RouteEvent::Takeover { announce: after, predecessor: before.prefix, }) @@ -185,14 +185,14 @@ impl Follow { (Some((before, _)), Some((after, _))) if before.prefix != after.prefix => { let same = before.route.instance == after.route.instance; Some(match same { - true => AnnounceEvent::Update(after), - false => AnnounceEvent::Restart(after), + true => RouteEvent::Update(after), + false => RouteEvent::Restart(after), }) } // A route less specific than the serving one changed, which no request sees. (Some(_), Some((after, _))) if after.prefix != prefix => None, - (Some(_), Some((after, _))) if restart => Some(AnnounceEvent::Restart(after)), - (Some(_), Some((after, _))) => Some(AnnounceEvent::Update(after)), + (Some(_), Some((after, _))) if restart => Some(RouteEvent::Restart(after)), + (Some(_), Some((after, _))) => Some(RouteEvent::Update(after)), } } } @@ -218,6 +218,10 @@ pub struct Following { /// A change resolved to the broadcast handed out last while it was still open, so it counts /// as delivered only until that broadcast closes. absorbed: bool, + /// A broadcast was handed out and its end not reported yet. + live: bool, + /// The broadcast handed out last stopped serving the path, and its end is owed. + ended: bool, } impl Following { @@ -232,22 +236,26 @@ impl Following { last: None, moved: None, absorbed: false, + live: false, + ended: false, } } - /// Wait for the next instance serving the path; see + /// Wait for the next change to the instance serving the path; see /// [`Consumer::follow`](crate::origin::Consumer::follow). /// - /// Returns [`Error::Closed`] once the origin closes, and any other resolution failure - /// as-is. Dropping the future keeps the wait's progress for the next call. + /// Returns the broadcast of each instance as it comes online or takes over, and `None` + /// once the path the one handed out last served goes offline, or, when pinned, another + /// instance takes it over. Returns [`Error::Closed`] once the origin closes, and any other resolution + /// failure as-is. Dropping the future keeps the wait's progress for the next call. #[cfg(feature = "async")] - pub async fn available(&mut self) -> Result { + pub async fn available(&mut self) -> Result, Error> { kio::wait(|waiter| self.poll_available(waiter)).await } - /// Poll for the next instance serving the path, registering `waiter` when there - /// is none yet. - pub fn poll_available(&mut self, waiter: &kio::Waiter) -> Poll> { + /// Poll for the next change to the instance serving the path, registering `waiter` when + /// there is none yet; see [`Self::available`]. + pub fn poll_available(&mut self, waiter: &kio::Waiter) -> Poll, Error>> { loop { // Apply every change on hand before reading an answer, so a burst of them hands out // only the instance serving the path now. A resolution in flight answers for the @@ -256,6 +264,12 @@ impl Following { if self.settle(waiter)? { self.resolving = None; } + // Report an end before whatever serves next, so a reader drops the old broadcast first. + if self.ended { + self.ended = false; + self.live = false; + return Poll::Ready(Ok(None)); + } // The broadcast handed out ended while the path is still served: its instance's // routes may have gone, and another instance's, beneath the same announcement, // taken the path over. It also ends once the caller lets go of it, so only its @@ -306,7 +320,8 @@ impl Following { self.last = Some(weak); self.moved = None; self.absorbed = false; - return Poll::Ready(Ok(broadcast)); + self.live = true; + return Poll::Ready(Ok(Some(broadcast))); } } @@ -319,31 +334,40 @@ impl Following { Ok(changed) } + /// The broadcast handed out last stopped serving the path: owe its end, and hand out + /// whatever serves next, even the same instance coming back. + fn end(&mut self) { + self.ended |= self.live; + self.last = None; + self.moved = None; + self.absorbed = false; + } + /// Apply one change to the path, returning whether it is one. - fn apply(&mut self, event: AnnounceEvent) -> bool { + fn apply(&mut self, event: RouteEvent) -> bool { match event { - // Another instance taking over leaves a pinned follower's own stream as it was. - AnnounceEvent::Restart(announce) + // Another instance taking over ends a pinned follower's own stream, which is handed + // out again once it serves the path again. + RouteEvent::Restart(announce) if self .instance .as_ref() .is_some_and(|pin| announce.route.instance.as_ref() != Some(pin)) => { + self.end(); return false; } // A pinned resolution refuses any other instance, waiting until its own serves again. - AnnounceEvent::Start(_) | AnnounceEvent::Restart(_) => self.unseen = true, + RouteEvent::Start(_) | RouteEvent::Restart(_) => self.unseen = true, // An end is a gap that ended every request on the old route, so whatever serves the // path next is handed out, even the same instance coming back. - AnnounceEvent::End(_) => { + RouteEvent::End(_) => { self.unseen = false; - self.last = None; - self.moved = None; - self.absorbed = false; + self.end(); } // The same instance over another route, which its subscriptions ride out, or one // continuing what was handed out. - AnnounceEvent::Update(_) | AnnounceEvent::Takeover { .. } => return false, + RouteEvent::Update(_) | RouteEvent::Takeover { .. } => return false, } true } @@ -367,11 +391,11 @@ mod tests { .expect("no event") .expect("the origin closed"); match event { - AnnounceEvent::Start(announce) => ("start", announce.prefix.to_string()), - AnnounceEvent::Update(announce) => ("update", announce.prefix.to_string()), - AnnounceEvent::Restart(announce) => ("restart", announce.prefix.to_string()), - AnnounceEvent::Takeover { announce, .. } => ("takeover", announce.prefix.to_string()), - AnnounceEvent::End(announce) => ("end", announce.prefix.to_string()), + RouteEvent::Start(announce) => ("start", announce.prefix.to_string()), + RouteEvent::Update(announce) => ("update", announce.prefix.to_string()), + RouteEvent::Restart(announce) => ("restart", announce.prefix.to_string()), + RouteEvent::Takeover { announce, .. } => ("takeover", announce.prefix.to_string()), + RouteEvent::End(announce) => ("end", announce.prefix.to_string()), } } @@ -389,7 +413,7 @@ mod tests { #[kio::test] async fn follow_reports_the_route_serving_the_path() { let origin = Hop::new(1).unwrap().produce(); - let mut follow = origin.consume().routes("pool/job").unwrap(); + let mut follow = origin.consume().path_routes("pool/job").unwrap(); let instance = Instance::random(); // A prefix above the path covers it. @@ -431,7 +455,7 @@ mod tests { let _pool = origin.requests_route("pool", Route::default(), None).unwrap(); let _exact = origin.publish("pool/job", Route::default()).unwrap(); - let mut follow = origin.consume().routes("pool/job").unwrap(); + let mut follow = origin.consume().path_routes("pool/job").unwrap(); assert_eq!(followed(&mut follow).await, ("start", "pool/job".into())); quiet(&mut follow).await; } @@ -443,7 +467,7 @@ mod tests { let origin = Hop::new(1).unwrap().produce(); let instance = Instance::random(); let exact = origin.publish("pool/job", route(&instance)).unwrap(); - let mut follow = origin.consume().routes("pool/job").unwrap(); + let mut follow = origin.consume().path_routes("pool/job").unwrap(); assert_eq!(followed(&mut follow).await, ("start", "pool/job".into())); // Both land before the follower reads again, and the cursor delivers the prefix's start @@ -466,7 +490,7 @@ mod tests { async fn follow_hands_over_to_a_prefix_that_started_before_the_last_change() { let origin = Hop::new(1).unwrap().produce(); let exact = origin.publish("pool/job", route(&Instance::random())).unwrap(); - let mut follow = origin.consume().routes("pool/job").unwrap(); + let mut follow = origin.consume().path_routes("pool/job").unwrap(); assert_eq!(followed(&mut follow).await, ("start", "pool/job".into())); let instance = Instance::random(); @@ -482,7 +506,7 @@ mod tests { #[kio::test] async fn follow_restarts_onto_a_more_specific_route_under_another_instance() { let origin = Hop::new(1).unwrap().produce(); - let mut follow = origin.consume().routes("pool/job").unwrap(); + let mut follow = origin.consume().path_routes("pool/job").unwrap(); let _pool = origin.requests_route("pool", Route::default(), None).unwrap(); assert_eq!(followed(&mut follow).await, ("start", "pool".into())); @@ -502,7 +526,7 @@ mod tests { .unwrap() .requests_route("room/alice", Route::default(), None) .unwrap(); - let mut follow = origin.consume().routes("room/alice").unwrap(); + let mut follow = origin.consume().path_routes("room/alice").unwrap(); let first = origin.publish("room/alice", Route::default().with_cost(5)).unwrap(); let event = kio::clock::timeout(Duration::from_secs(1), follow.next()) @@ -510,7 +534,7 @@ mod tests { .unwrap() .unwrap(); assert!( - matches!(&event, AnnounceEvent::Start(announce) if announce.route.cost == Cost::new(5)), + matches!(&event, RouteEvent::Start(announce) if announce.route.cost == Cost::new(5)), "{event:?}" ); @@ -522,26 +546,38 @@ mod tests { .unwrap() .unwrap(); assert!( - matches!(&event, AnnounceEvent::Restart(announce) if announce.route.cost == Cost::new(5)), + matches!(&event, RouteEvent::Restart(announce) if announce.route.cost == Cost::new(5)), "{event:?}" ); } - /// The next instance handed out, which must arrive within the origin's update hold. - async fn available(announced: &mut Following) -> broadcast::Consumer { + /// The next change handed out, which must arrive within the origin's update hold. + async fn changed(announced: &mut Following) -> Option { kio::clock::timeout(Duration::from_secs(1), announced.available()) .await - .expect("no instance") + .expect("no change") .expect("the wait failed") } + /// The next instance handed out, which must arrive within the origin's update hold. + async fn available(announced: &mut Following) -> broadcast::Consumer { + changed(announced).await.expect("an end, not an instance") + } + + /// The broadcast handed out last stops serving, with nothing in its place. + async fn ended(announced: &mut Following) { + if let Some(broadcast) = changed(announced).await { + panic!("expected an end, got {:?}", broadcast.info().instance); + } + } + /// Nothing more is handed out past the origin's update hold. async fn none(announced: &mut Following) { let hold = super::super::origin_impl::DEFAULT_UPDATE_HOLD * 2; if let Ok(result) = kio::clock::timeout(hold, announced.available()).await { panic!( "expected nothing, got {:?}", - result.map(|broadcast| broadcast.info().instance.clone()) + result.map(|broadcast| broadcast.map(|broadcast| broadcast.info().instance.clone())) ); } } @@ -601,6 +637,7 @@ mod tests { let dynamic = origin.requests_route("", route(&instance), None).unwrap(); exact.unannounce(); + ended(&mut announced).await; let served = broadcast::Info::new().produce(); let (again, ()) = futures::join!(available(&mut announced), async { requested(&dynamic).await.accept(&served); @@ -608,7 +645,7 @@ mod tests { assert!(again.is_clone(&first), "the route above did not carry the instance on"); } - /// An announced request that pins an instance refuses another instance taking over instead of + /// An announced request that pins an instance ends when another instance takes over instead of /// following it. #[kio::test] async fn announced_pinned_refuses_another_instance() { @@ -619,13 +656,43 @@ mod tests { let pinned = available(&mut announced).await; assert_eq!(pinned.info().instance.as_ref(), Some(&instance)); - let _second = origin.publish("live", route(&Instance::random())).unwrap(); + let second = origin.publish("live", route(&Instance::random())).unwrap(); + ended(&mut announced).await; none(&mut announced).await; // Unpinned, the same takeover is followed. let mut unpinned = origin.consume().follow("live", None).unwrap(); let current = available(&mut unpinned).await; assert_ne!(current.info().instance.as_ref(), Some(&instance)); + + // The pinned instance serves again once the other goes, and is handed out again. + drop(second); + assert_eq!( + available(&mut announced).await.info().instance.as_ref(), + Some(&instance) + ); + assert_eq!( + available(&mut unpinned).await.info().instance.as_ref(), + Some(&instance) + ); + } + + /// A follower started before anything serves the path waits for it, reports its end, and + /// hands out what serves it next. + #[kio::test] + async fn announced_reports_the_path_going_offline() { + let origin = Hop::new(1).unwrap().produce(); + let mut announced = origin.consume().follow("live", None).unwrap(); + none(&mut announced).await; + + let first = origin.publish("live", Route::default()).unwrap(); + let started = available(&mut announced).await; + drop(first); + ended(&mut announced).await; + none(&mut announced).await; + + let _second = origin.publish("live", Route::default()).unwrap(); + assert!(!available(&mut announced).await.is_clone(&started)); } #[kio::test] @@ -639,6 +706,7 @@ mod tests { Some(&instance) ); first.unannounce(); + ended(&mut announced).await; none(&mut announced).await; first.announce(route(&instance)).unwrap(); assert_eq!( @@ -671,7 +739,7 @@ mod tests { fn follow_refuses_a_path_no_pattern_can_spell() { let origin = Hop::new(1).unwrap().produce(); assert!(matches!( - origin.consume().routes("camera*main"), + origin.consume().path_routes("camera*main"), Err(Error::InvalidPath(_)) )); } @@ -682,6 +750,6 @@ mod tests { let origin = Hop::new(1).unwrap().produce(); let scope = Patterns::from(Pattern::subtree("pool/job/cam").unwrap()); let scoped = origin.consume().scope("", &scope).unwrap(); - assert!(matches!(scoped.routes("pool/job"), Err(Error::Unauthorized))); + assert!(matches!(scoped.path_routes("pool/job"), Err(Error::Unauthorized))); } } diff --git a/rs/moq-net/src/model/mod.rs b/rs/moq-net/src/model/mod.rs index e0a67cc3cb5..230397ea3a2 100644 --- a/rs/moq-net/src/model/mod.rs +++ b/rs/moq-net/src/model/mod.rs @@ -10,6 +10,8 @@ pub mod track; // modules so neither leaks the other's plumbing. #[path = "origin.rs"] mod origin_impl; +// The app-level announcement listing over a route stream. +mod announced; // Reduces the routes covering one path to the one serving it. mod follow; // The failover state machine origin fronts run; pure, so its transitions are @@ -58,11 +60,16 @@ pub mod origin { Config, Consumer, Cost, Driver, HopLimit, Link, Preference, Prepared, Producer, Publication, Request, Requesting, Requests, Route, Source, }; + // Relay-level: every route change, for forwarding and stats. Apps read + // `announce` and `follow` instead. + #[doc(hidden)] + pub use super::origin_impl::{RouteEvent, Routes}; } -/// Subscribing to route (un)announcements from an origin. +/// Listing the paths announced on an origin. pub mod announce { - pub use super::origin_impl::{Announce, AnnounceConsumer as Consumer, AnnounceEvent as Event}; + pub use super::announced::{AnnounceConsumer as Consumer, AnnounceEvent as Event}; + pub use super::origin_impl::Announce; } // Hop identity and the `Consume` conversion trait aren't part of a role diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index bbf3a98691c..ec80dbecd33 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -14,6 +14,7 @@ use rand::RngExt; use super::{ RequestQueue, WeakCache, WeakEntry, + announced::AnnounceConsumer, follow::{Follow, Following}, front::{Action, Candidate, Event, Front, Refusal}, }; @@ -475,7 +476,7 @@ impl From for Preference { pub struct Route { /// The stream the route serves: routes with one instance serve one continuous /// sequence space, so a subscription resumes from one to another. Changing it on a - /// standing advertisement is an [`AnnounceEvent::Restart`]. + /// standing advertisement is an [`RouteEvent::Restart`]. /// /// Always set on a route the origin delivers. Given to an announcing handle, `None` /// keeps the instance its route already has: a fresh random one, minted when the @@ -738,7 +739,7 @@ fn earliest(a: Option, b: Option) -> Option { } } -/// A retraction's quarantine, keyed by prefix in its [`AnnounceConsumer`]: the +/// A retraction's quarantine, keyed by prefix in its [`Routes`]: the /// retracted route's publisher (none for an anonymous route, which holds /// nothing), instance, epoch, and rank, and when the quarantine ends. #[derive(Clone)] @@ -761,7 +762,7 @@ impl Quarantine { } } -/// A pending update's hold, kept with it in its [`AnnounceConsumer`]'s queue. +/// A pending update's hold, kept with it in its [`Routes`]'s queue. /// /// A consumer reads the origin's clock outside the driver, where it holds the /// driver's last reading, not the time the update arrived. So a hold first waits @@ -773,7 +774,7 @@ enum Held { Until(Instant), } -/// One coalesced update queued for an `AnnounceConsumer`. +/// One coalesced update queued for an `Routes`. /// /// At most one entry exists per prefix, so a slow consumer's pending set is /// bounded by the number of distinct prefixes. A metadata change on a live route @@ -842,7 +843,7 @@ struct OriginConsumerState { /// the end instead of parking forever on a table that can never fire again. ended: bool, /// Snapshots in flight that can present on this consumer's cursors, counted - /// once per cursor they touch. See [`AnnounceConsumer::poll_synced`]. + /// once per cursor they touch. See [`Routes::poll_synced`]. /// /// Changed through a read guard, so a session joining wakes none of the cursors it /// holds back (nothing waits on losing sync), except the last landing, which @@ -1121,13 +1122,13 @@ impl OriginConsumerState { } /// Take the pending update at `prefix` for delivery. - fn take_prefix(&mut self, prefix: Path) -> AnnounceEvent { + fn take_prefix(&mut self, prefix: Path) -> RouteEvent { let (event, owed) = self.take_update(prefix); - let (AnnounceEvent::Start(announce) - | AnnounceEvent::Update(announce) - | AnnounceEvent::Restart(announce) - | AnnounceEvent::Takeover { announce, .. } - | AnnounceEvent::End(announce)) = &event; + let (RouteEvent::Start(announce) + | RouteEvent::Update(announce) + | RouteEvent::Restart(announce) + | RouteEvent::Takeover { announce, .. } + | RouteEvent::End(announce)) = &event; // A trailing announce left pending is still owed. if owed && !self.pending.contains_key(&announce.prefix) { self.owed -= 1; @@ -1135,7 +1136,7 @@ impl OriginConsumerState { event } - fn take_update(&mut self, prefix: Path) -> (AnnounceEvent, bool) { + fn take_update(&mut self, prefix: Path) -> (RouteEvent, bool) { /// What the consumer learns at the prefix. enum Kind { Start, @@ -1210,11 +1211,11 @@ impl OriginConsumerState { }, }; let event = match kind { - Kind::Start => AnnounceEvent::Start(announce), - Kind::Update => AnnounceEvent::Update(announce), - Kind::Restart => AnnounceEvent::Restart(announce), - Kind::Takeover(predecessor) => AnnounceEvent::Takeover { announce, predecessor }, - Kind::End => AnnounceEvent::End(announce), + Kind::Start => RouteEvent::Start(announce), + Kind::Update => RouteEvent::Update(announce), + Kind::Restart => RouteEvent::Restart(announce), + Kind::Takeover(predecessor) => RouteEvent::Takeover { announce, predecessor }, + Kind::End => RouteEvent::End(announce), }; (event, owed) } @@ -1984,9 +1985,9 @@ fn hides(heads: &[Path], prefix: &Path) -> bool { .any(|head| prefix.strip_prefix(head).is_some_and(|below| below.is_hidden())) } -/// What an [`AnnounceConsumer`] yields. +/// What a [`Routes`] yields. #[derive(Clone, Debug)] -pub enum AnnounceEvent { +pub enum RouteEvent { /// A route now covers the prefix; the cursor had none there. Start(Announce), /// The route covering the prefix changed hops, cost or epoch, with the same instance; @@ -2016,7 +2017,7 @@ pub enum AnnounceEvent { }, } -/// A route over a prefix, delivered by [`AnnounceConsumer`] inside an [`AnnounceEvent`]. +/// A route over a prefix, as an announcement listing or a [`Routes`] stream reports it. /// /// An announcement is always a prefix, never a broadcast: it advertises that /// [`prefix`](Self::prefix) and every path beneath it are servable. A broadcast @@ -2847,7 +2848,7 @@ impl Announcer { /// [`Pattern`] can be served. /// /// Held by a [`Requests`] and by a broadcast's [`Announcer`]; dropping it -/// retracts the route, which [`AnnounceConsumer`]s observe and sessions withdraw +/// retracts the route, which [`Routes`]s observe and sessions withdraw /// from their peers. #[must_use = "dropping an announcement retracts the route"] pub(crate) struct AnnounceProducer { @@ -3050,7 +3051,7 @@ impl Drop for AnnounceProducer { /// /// It holds no [`Producer`] clone, so it never keeps the origin alive. It /// finishes once every owner is gone: each [`Producer`] clone, published -/// broadcast, and [`Requests`]. Read handles ([`Consumer`], [`AnnounceConsumer`]) +/// broadcast, and [`Requests`]. Read handles ([`Consumer`], [`Routes`]) /// are not owners. Dropping it aborts active fronts, rejects pending requests, /// ends announcements, and makes subsequent producer mutations fail with /// [`Error::Closed`]. @@ -4516,7 +4517,7 @@ struct SnapshotEntry { /// A session still delivering its peer's initial announcements under a prefix. /// /// Every announce consumer whose scope the prefix overlaps is unsynced -/// (see [`AnnounceConsumer::poll_synced`]) until this drops: once the session +/// (see [`Routes::poll_synced`]) until this drops: once the session /// has inserted the announcements its peer counted, or it gave up on them. pub(crate) struct Snapshot { shared: Option>>, @@ -5737,7 +5738,7 @@ impl Requests { /// /// A route naming no [`Route::instance`], or the same one, re-prices: consumers observe /// an update and every handle survives. Another instance is another stream: consumers - /// see an [`AnnounceEvent::Restart`], and a re-request never joins what was resolved + /// see an [`RouteEvent::Restart`], and a re-request never joins what was resolved /// under the old one. Requests still waiting on this handle carry over: the handler is /// asked again under the new instance, and its answer to a request asked before the /// change is dropped, never served under the new one. A request pinned to the old @@ -6143,12 +6144,12 @@ impl Requesting { if let Some(discovery) = &mut self.discovery { loop { match discovery.poll_next(waiter) { - Poll::Ready(Some(AnnounceEvent::End(_))) => self.routed = false, + Poll::Ready(Some(RouteEvent::End(_))) => self.routed = false, Poll::Ready(Some( - AnnounceEvent::Start(announce) - | AnnounceEvent::Restart(announce) - | AnnounceEvent::Update(announce) - | AnnounceEvent::Takeover { announce, .. }, + RouteEvent::Start(announce) + | RouteEvent::Restart(announce) + | RouteEvent::Update(announce) + | RouteEvent::Takeover { announce, .. }, )) => { self.routed = self.instance.is_none() || announce.route.instance == self.instance; } @@ -6555,7 +6556,18 @@ impl Consumer { } } - /// Subscribe to route announcements for this consumer's scope. + /// List the paths announced in this consumer's scope, each present or absent. + /// + /// A path stays present while any route covers it, whichever instance serves it: + /// hold a [`follow`](Self::follow) to see the broadcast change. Scope, hiding and + /// sync behave as for [`routes`](Self::routes). Drop the returned + /// [`announce::Consumer`](crate::announce::Consumer) to unregister. + pub fn announced(&self) -> AnnounceConsumer { + AnnounceConsumer::new(self.routes()) + } + + /// Every change to the routes announced in this consumer's scope, for relays and + /// stats: route metadata, instance replacements and takeovers included. /// /// Allocates a per-cursor coalescing buffer and replays the currently /// announced routes as initial updates. Routes stay prefixes and are named @@ -6566,8 +6578,9 @@ impl Consumer { /// patterns are hidden unless [`with_hidden`](Self::with_hidden) opted in. /// The stream also watches its scope: a client session fed by this origin asks /// its peer about the scope while any stream watches it. - /// Drop the returned [`AnnounceConsumer`] to unregister. - pub fn announced(&self) -> AnnounceConsumer { + /// Drop the returned [`Routes`] to unregister. + #[doc(hidden)] + pub fn routes(&self) -> Routes { let state = kio::Producer::::default(); let cursor = |root: Path, allowed: Patterns, hidden: Hidden, mount: Option<&Mount>, under: Path, holes: Vec| { @@ -6593,7 +6606,7 @@ impl Consumer { // A root the mount resolves past the depth limit, or an excluded one, has // nothing to announce. let (Some(root), Some(holes)) = (mount.resolve(&self.root), self.scope.holes(Some(mount))) else { - return AnnounceConsumer::new( + return Routes::new( self.root.clone(), Vec::new(), state, @@ -6610,7 +6623,7 @@ impl Consumer { Path::default(), holes, )]; - return AnnounceConsumer::new( + return Routes::new( self.root.clone(), cursors, state, @@ -6664,7 +6677,7 @@ impl Consumer { holes, ), ); - AnnounceConsumer::new( + Routes::new( self.root.clone(), cursors, state, @@ -6703,7 +6716,7 @@ impl Consumer { /// absence from its sync. Fails with [`Error::Unauthorized`] when this consumer's scope can /// never cover the path, and with [`Error::InvalidPath`] when no pattern can spell it (a /// segment containing `*`). - pub(crate) fn routes(&self, path: impl TryInto>) -> Result { + pub(crate) fn path_routes(&self, path: impl TryInto>) -> Result { let path = path::convert(path)?; // Scope down to the path itself, which still sees every route whose claim covers it: @@ -6721,7 +6734,7 @@ impl Consumer { // Untagged: this is a lookup, not egress announce forwarding, so it must not drive // the announce guards. Hiding narrows discovery, not lookup, so a hidden path // follows like any other. - let announced = consumer.untagged().with_hidden(true).covering().announced(); + let announced = consumer.untagged().with_hidden(true).covering().routes(); Ok(Follow::new(announced, path)) } @@ -6767,23 +6780,24 @@ impl Consumer { /// Follow the broadcast at `path` across the instances that serve it. /// - /// The first [`available`](Following::poll_available) resolves the instance serving the - /// path once one is announced, retrying route churn but returning a selected handler's - /// refusal. Each later call waits for another instance to take over (an - /// [`AnnounceEvent::Restart`]), or for the path to be served again after an - /// [`AnnounceEvent::End`], even by the same instance. Drop what was read from the - /// previous broadcast then: its tracks end with an error once its routes go. + /// The first [`available`](Following::available) resolves the instance serving the path + /// once one is announced, retrying route churn but returning a selected handler's refusal. + /// Each later call returns another instance taking over, or `None` once the path goes + /// offline, then whatever serves it next, even the same instance. Drop what was read from the previous broadcast then: + /// its tracks end with an error once its routes go. Another route of the same instance, + /// or another epoch of it, is not a change. /// - /// Pass an owned [`Instance`] to follow only that stream: another one taking over is - /// never handed out, and the instance is handed out again if it returns after an end. Fails with [`Error::Unauthorized`] when this consumer's scope can never - /// cover the path, and with [`Error::InvalidPath`] when no pattern can spell it. + /// Pass an owned [`Instance`] to follow only that stream: another one taking over ends + /// it, and the instance is handed out again when it serves the path again. Fails with + /// [`Error::Unauthorized`] when this consumer's scope can never cover the path, and with + /// [`Error::InvalidPath`] when no pattern can spell it. pub fn follow( &self, path: impl TryInto>, instance: impl Into>, ) -> Result { let path = path::convert(path)?; - let routes = self.routes(&path)?; + let routes = self.path_routes(&path)?; Ok(Following::new(self.clone(), path, instance.into(), routes)) } @@ -6828,7 +6842,7 @@ impl Consumer { /// /// Another instance winning the path leaves the broadcast to its readers until its /// routes go, while the next request resolves the winner on a fresh broadcast. - /// [`Consumer::announced`] reports that as [`AnnounceEvent::Restart`], and + /// [`Consumer::announced`] reports that as [`RouteEvent::Restart`], and /// [`Self::follow`] yields the next broadcast. /// /// Pass an owned [`Instance`] to refuse a different stream, both when requesting @@ -6852,7 +6866,7 @@ impl Consumer { Err(err) => return kio::Pending::new(self.failed(err)), }; let mut routing = self.routing(path.clone(), instance.into()); - match self.routes(&path) { + match self.path_routes(&path) { Ok(discovery) => { routing.discovery = Some(discovery); if let Some(resolved) = self.root.join(&path).ok().and_then(|named| self.scope.resolve(&named)) { @@ -7043,11 +7057,11 @@ impl Consumer { } } -/// Receives route announcements for a scope. +/// Receives every route change for a scope, for relays and stats. /// -/// Created by [`Consumer::announced`]. +/// Created by [`Consumer::routes`]. /// Drop to unregister. -pub struct AnnounceConsumer { +pub struct Routes { // One registration per table cursor feeding `state`: more than one when the // consumer reads through a mount. ids: Vec, @@ -7084,9 +7098,9 @@ pub struct AnnounceConsumer { hold: crate::time::Deadline, } -impl AnnounceConsumer { +impl Routes { #[cfg(test)] - async fn expect_next(&mut self) -> AnnounceEvent { + async fn expect_next(&mut self) -> RouteEvent { #[cfg(feature = "async")] { return kio::wait(|waiter| self.poll_next(waiter)).await.expect("no next"); @@ -7112,7 +7126,7 @@ impl AnnounceConsumer { expected: impl TryInto, ) -> Route { match self.expect_next().await { - AnnounceEvent::Restart(announce) => { + RouteEvent::Restart(announce) => { assert_eq!( announce.prefix, expected.try_into().expect("expected path"), @@ -7127,7 +7141,7 @@ impl AnnounceConsumer { #[cfg(test)] pub(crate) async fn expect_next_ended(&mut self, expected: impl TryInto) { match self.expect_next().await { - AnnounceEvent::End(announce) => assert_eq!( + RouteEvent::End(announce) => assert_eq!( announce.prefix, expected.try_into().expect("expected path"), "wrong prefix" @@ -7189,8 +7203,8 @@ impl AnnounceConsumer { /// Start a retraction's quarantine. A delivered announcement leaves it to /// expire: later ones for the prefix are updates, which it never holds. - fn quarantine(&mut self, event: &AnnounceEvent, now: Instant) { - let AnnounceEvent::End(update) = event else { + fn quarantine(&mut self, event: &RouteEvent, now: Instant) { + let RouteEvent::End(update) = event else { return; }; if self.update_hold.is_zero() { @@ -7261,18 +7275,18 @@ impl AnnounceConsumer { } /// Drive the egress announce guards for one update. - fn hand_out(&mut self, event: AnnounceEvent) -> AnnounceEvent { + fn hand_out(&mut self, event: RouteEvent) -> RouteEvent { match &event { - AnnounceEvent::Start(announce) - | AnnounceEvent::Update(announce) - | AnnounceEvent::Restart(announce) - | AnnounceEvent::Takeover { announce, .. } => { + RouteEvent::Start(announce) + | RouteEvent::Update(announce) + | RouteEvent::Restart(announce) + | RouteEvent::Takeover { announce, .. } => { let scope = self.stats.egress(self.root.rejoin(&announce.prefix)); self.guards .entry(announce.prefix.clone()) .or_insert_with(|| scope.announce()); } - AnnounceEvent::End(announce) => { + RouteEvent::End(announce) => { self.guards.remove(&announce.prefix); } } @@ -7287,7 +7301,7 @@ impl AnnounceConsumer { /// None if the cursor is closed. The consumer is also a [`futures::Stream`] /// of the same events. #[cfg(feature = "async")] - pub async fn next(&mut self) -> Option { + pub async fn next(&mut self) -> Option { kio::wait(|waiter| self.poll_next(waiter)).await } @@ -7296,7 +7310,7 @@ impl AnnounceConsumer { /// Returns `Poll::Ready(Some(_))` for an event, `Poll::Ready(None)` if the /// cursor is closed, or `Poll::Pending` after registering `waiter` to be /// notified when the next event arrives. - pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll> { + pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll> { loop { let now = self.timers.now(); let settling = self.settle(now); @@ -7340,7 +7354,7 @@ impl AnnounceConsumer { /// /// Returns None if there is no event available; NOT because the cursor is closed. /// Use [`Self::is_closed`] to check if the cursor is closed. - pub fn try_next(&mut self) -> Option { + pub fn try_next(&mut self) -> Option { let now = self.timers.now(); let settling = self.settle(now); // Read first, so a call with nothing due writes nothing; see `poll_next`. @@ -7462,8 +7476,8 @@ impl AnnounceConsumer { } #[cfg(feature = "async")] -impl futures::Stream for AnnounceConsumer { - type Item = AnnounceEvent; +impl futures::Stream for Routes { + type Item = RouteEvent; fn poll_next(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll> { let this = self.get_mut(); @@ -7472,7 +7486,7 @@ impl futures::Stream for AnnounceConsumer { } } -impl Drop for AnnounceConsumer { +impl Drop for Routes { fn drop(&mut self) { let mut state = self.shared.lock(); for id in &self.ids { @@ -7493,11 +7507,11 @@ use futures::FutureExt; #[cfg(test)] #[expect(missing_docs, reason = "test-only assertion helpers")] -impl AnnounceConsumer { +impl Routes { /// The route of an active event at `expected`. - fn active(event: AnnounceEvent, expected: &Path) -> Route { + fn active(event: RouteEvent, expected: &Path) -> Route { match event { - AnnounceEvent::Start(announce) | AnnounceEvent::Update(announce) | AnnounceEvent::Restart(announce) => { + RouteEvent::Start(announce) | RouteEvent::Update(announce) | RouteEvent::Restart(announce) => { assert_eq!(announce.prefix, *expected, "wrong prefix"); announce.route } @@ -7527,7 +7541,7 @@ impl AnnounceConsumer { .expect("next blocked") .expect("no next") { - AnnounceEvent::Restart(announce) => { + RouteEvent::Restart(announce) => { assert_eq!( announce.prefix, expected.try_into().expect("expected path"), @@ -7546,7 +7560,7 @@ impl AnnounceConsumer { .expect("next blocked") .expect("no next") { - AnnounceEvent::End(announce) => assert_eq!( + RouteEvent::End(announce) => assert_eq!( announce.prefix, expected.try_into().expect("expected path"), "wrong prefix" @@ -7804,7 +7818,7 @@ mod tests { async fn announce_and_retract() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); announced.assert_next_wait(); let announcement = producer.announce("room/alice", Route::default()).unwrap(); @@ -7823,7 +7837,7 @@ mod tests { fn synced_after_the_snapshot_and_its_events() { let producer = origin(1).produce(); let snapshot = producer.snapshot("room"); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); assert!(!announced.is_synced(), "a snapshot in flight holds it"); let _alice = producer.announce("room/alice", Route::default()).unwrap(); @@ -7842,12 +7856,12 @@ mod tests { #[test] fn a_local_origin_catches_up_on_its_replay() { let producer = origin(1).produce(); - let mut empty = producer.consume().announced(); + let mut empty = producer.consume().routes(); assert!(empty.is_synced(), "nothing to wait on"); empty.assert_next_wait(); let _alice = producer.announce("room/alice", Route::default()).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); assert!(!announced.is_synced(), "the replay is owed"); announced.assert_next_active("room/alice"); assert!(announced.is_synced()); @@ -7857,7 +7871,7 @@ mod tests { fn initial_routes_precede_live_prefixes() { let producer = origin(1).produce(); let _initial = producer.announce("z/initial", Route::default()).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let _live = producer.announce("a/live", Route::default()).unwrap(); announced.assert_next_active("z/initial"); assert!(announced.is_synced()); @@ -7867,7 +7881,7 @@ mod tests { fn stalled_initial_replay_collapses_churn_without_a_backlog() { let producer = origin(1).produce(); let initial = producer.announce("z/initial", Route::default()).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); for i in 0..1_000 { let transient = producer.announce(format!("a/{i}"), Route::default()).unwrap(); initial.update(Route::default().with_cost(i)).unwrap(); @@ -7884,7 +7898,7 @@ mod tests { fn a_cancelled_start_still_catches_up() { let producer = origin(1).produce(); let snapshot = producer.snapshot(""); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let alice = producer.announce("room/alice", Route::default()).unwrap(); drop(snapshot); @@ -7898,7 +7912,7 @@ mod tests { #[test] fn an_update_is_not_owed() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let alice = producer.announce("room/alice", Route::default()).unwrap(); announced.assert_next_active("room/alice"); @@ -7912,7 +7926,7 @@ mod tests { #[test] fn a_new_snapshot_takes_sync_back() { let producer = origin(1).produce(); - let announced = producer.consume().announced(); + let announced = producer.consume().routes(); assert!(announced.is_synced()); let snapshot = producer.snapshot("room/alice"); @@ -7934,10 +7948,10 @@ mod tests { .unwrap(); let other = producer.snapshot("other"); - assert!(room.announced().is_synced(), "a disjoint prefix"); + assert!(room.routes().is_synced(), "a disjoint prefix"); let above = producer.snapshot(""); - let announced = room.announced(); + let announced = room.routes(); assert!(!announced.is_synced(), "a snapshot above the root covers it"); drop(above); assert!(announced.is_synced()); @@ -7946,8 +7960,8 @@ mod tests { // A local view never waits on a peer's routes. let _peer = producer.clone().with_link(Link::Peer).snapshot("room"); - assert!(producer.consume().local().announced().is_synced()); - assert!(!producer.consume().announced().is_synced()); + assert!(producer.consume().local().routes().is_synced()); + assert!(!producer.consume().routes().is_synced()); } /// A source shadowed by a mount can present nothing on the handle, so it never holds it. @@ -7955,12 +7969,12 @@ mod tests { fn a_shadowed_snapshot_never_holds() { let producer = origin(1).produce(); let project = mounted(&producer, "p1", &["**"]).with_hidden(true); - let announced = project.announced(); + let announced = project.routes(); assert!(announced.is_synced()); let shadowed = producer.snapshot("p1/.svc"); assert!(announced.is_synced(), "a snapshot in flight under the hole"); - assert!(project.announced().is_synced(), "a reader registering past one"); + assert!(project.routes().is_synced(), "a reader registering past one"); drop(shadowed); let _target = producer.snapshot(".svc/p1"); @@ -7971,14 +7985,14 @@ mod tests { #[test] fn a_hidden_snapshot_holds_only_hidden_readers() { let producer = origin(1).produce(); - let announced = producer.consume().announced(); + let announced = producer.consume().routes(); let _stats = producer.snapshot(".stats"); assert!(announced.is_synced(), "a snapshot in flight under a hidden segment"); assert!( - producer.consume().announced().is_synced(), + producer.consume().routes().is_synced(), "a reader registering past one" ); - assert!(!producer.consume().with_hidden(true).announced().is_synced()); + assert!(!producer.consume().with_hidden(true).routes().is_synced()); } /// A waiter parked on syncing is woken when it does. @@ -7993,7 +8007,7 @@ mod tests { let producer = origin(1).produce(); let snapshot = producer.snapshot(""); - let announced = producer.consume().announced(); + let announced = producer.consume().routes(); let woken = Arc::new(Woken(AtomicBool::new(false))); let waiter = kio::Waiter::new(std::task::Waker::from(woken.clone())); assert!(announced.poll_synced(&waiter).is_pending()); @@ -8014,7 +8028,7 @@ mod tests { } let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let woken = Arc::new(Woken(AtomicBool::new(false))); let waiter = kio::Waiter::new(std::task::Waker::from(woken.clone())); assert!(announced.poll_next(&waiter).is_pending()); @@ -8040,12 +8054,12 @@ mod tests { // Only a leading dot hides: a suffix is part of the name. let _suffix = producer.announce("room/catalog.pro", Route::default()).unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); announced.expect_next_active("room/alice").await; announced.expect_next_active("room/catalog.pro").await; announced.assert_next_wait(); - let mut announced = consumer.clone().with_hidden(true).announced(); + let mut announced = consumer.clone().with_hidden(true).routes(); announced.expect_next_active(".stats/node").await; announced.expect_next_active("room/.internal").await; announced.expect_next_active("room/alice").await; @@ -8056,10 +8070,10 @@ mod tests { let mut announced = consumer .scope(".stats", &Patterns::from(Pattern::all())) .unwrap() - .announced(); + .routes(); announced.expect_next_active("node").await; announced.assert_next_wait(); - let mut announced = consumer.scope("", &scopes(&["room/.internal"])).unwrap().announced(); + let mut announced = consumer.scope("", &scopes(&["room/.internal"])).unwrap().routes(); announced.expect_next_active("room/.internal").await; announced.assert_next_wait(); } @@ -8073,7 +8087,7 @@ mod tests { let broadcast = producer.create_broadcast(".stats/node").unwrap(); broadcast.announce(Route::default()).unwrap(); - consumer.announced().assert_next_wait(); + consumer.routes().assert_next_wait(); let resolved = consumer.request(".stats/node", None).await.expect("resolves"); assert_eq!(resolved.info().path.as_str(), ".stats/node"); } @@ -8096,7 +8110,7 @@ mod tests { .exclude(".pro") .unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); announced.expect_next_active("").await; announced.expect_next_active(".private/cam").await; announced.expect_next_active("cam").await; @@ -8126,12 +8140,12 @@ mod tests { let _cam = producer.publish("p1/cam", Route::default()).unwrap(); let project = mounted(&producer, "p1", &["**"]).with_hidden(true); - let mut announced = project.exclude(".svc/foo").unwrap().announced(); + let mut announced = project.exclude(".svc/foo").unwrap().routes(); announced.expect_next_active("cam").await; announced.expect_next_active(".svc/bar").await; announced.assert_next_wait(); - let mut announced = project.exclude(".svc").unwrap().announced(); + let mut announced = project.exclude(".svc").unwrap().routes(); announced.expect_next_active("cam").await; announced.assert_next_wait(); @@ -8141,7 +8155,7 @@ mod tests { .unwrap() .exclude("foo") .unwrap() - .announced(); + .routes(); inside.expect_next_active("bar").await; inside.assert_next_wait(); } @@ -8196,11 +8210,11 @@ mod tests { let project = mounted(&producer, "p1", &["**"]); // A dot segment hides the mount like any other. - let mut announced = project.announced(); + let mut announced = project.routes(); announced.expect_next_active("cam").await; announced.assert_next_wait(); - let mut announced = project.clone().with_hidden(true).covering().announced(); + let mut announced = project.clone().with_hidden(true).covering().routes(); announced.expect_next_active("cam").await; announced.expect_next_active(".svc").await; announced.expect_next_active(".svc/foo").await; @@ -8211,7 +8225,7 @@ mod tests { .scope(".svc", &Patterns::from(Pattern::all())) .unwrap() .covering() - .announced(); + .routes(); inside.expect_next_active("").await; inside.expect_next_active("foo").await; inside.assert_next_wait(); @@ -8242,7 +8256,7 @@ mod tests { .now_or_never() .expect("refused at once"); assert!(matches!(refused, Err(Error::Unauthorized))); - let mut announced = granted.clone().with_hidden(true).announced(); + let mut announced = granted.clone().with_hidden(true).routes(); announced.expect_next_active(".svc/foo").await; announced.assert_next_wait(); @@ -8252,11 +8266,11 @@ mod tests { .now_or_never() .expect("refused at once"); assert!(matches!(refused, Err(Error::Unauthorized))); - narrower.clone().with_hidden(true).announced().assert_next_wait(); + narrower.clone().with_hidden(true).routes().assert_next_wait(); // Another project's mount reaches its own target, never this one's. let other = mounted(&producer, "p2", &["**"]); - other.clone().with_hidden(true).announced().assert_next_wait(); + other.clone().with_hidden(true).routes().assert_next_wait(); let err = other.request(".svc/foo", None).await.err().unwrap(); assert!(matches!(err, Error::Unroutable)); } @@ -8269,14 +8283,14 @@ mod tests { let _foo = producer.publish(".svc/p1/foo", Route::default()).unwrap(); let project = mounted(&producer, "p1", &["**"]).with_hidden(true); - let Some(AnnounceEvent::Start(update)) = project.announced().try_next() else { + let Some(RouteEvent::Start(update)) = project.routes().try_next() else { panic!("expected foo to start"); }; assert_eq!(update.prefix.as_str(), ".svc/foo"); assert_eq!(update.captures, Some(vec![".svc/foo".parse::().unwrap()])); let inside = project.scope(".svc", &Patterns::from(Pattern::all())).unwrap(); - let Some(AnnounceEvent::Start(update)) = inside.announced().try_next() else { + let Some(RouteEvent::Start(update)) = inside.routes().try_next() else { panic!("expected foo to start"); }; assert_eq!(update.prefix.as_str(), "foo"); @@ -8299,7 +8313,7 @@ mod tests { .consume() .with_hidden(true); - let mut announced = project.announced(); + let mut announced = project.routes(); announced.expect_next_active(".svc").await; announced.assert_next_wait(); @@ -8307,7 +8321,7 @@ mod tests { let err = project.request(".svc/x", None).await.err().unwrap(); assert!(matches!(err, Error::BoundsExceeded(_)), "{err:?}"); let inside = project.scope(".svc/x", &Patterns::from(Pattern::all())).unwrap(); - inside.announced().assert_next_wait(); + inside.routes().assert_next_wait(); } /// A mount point deeper than its target never presents a route whose name @@ -8325,7 +8339,7 @@ mod tests { .unwrap() .consume(); - let mut announced = project.announced(); + let mut announced = project.routes(); announced.expect_next_active("a/b/x").await; announced.assert_next_wait(); @@ -8413,7 +8427,7 @@ mod tests { ) .with_hidden(true); - let mut announced = project.announced(); + let mut announced = project.routes(); announced.expect_next_active(".svc/foo").await; project.request(".svc/foo", None).await.expect("resolves"); @@ -8432,8 +8446,8 @@ mod tests { async fn hidden_route_announced_later_stays_hidden() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); - let mut opted = consumer.clone().with_hidden(true).announced(); + let mut announced = consumer.routes(); + let mut opted = consumer.clone().with_hidden(true).routes(); let hidden = producer.announce(".stats/node", Route::default()).unwrap(); announced.assert_next_wait(); @@ -8448,7 +8462,7 @@ mod tests { async fn a_replayed_route_retracted_before_delivery_cancels() { let producer = origin(1).produce(); let alice = producer.announce("alice", Route::default()).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); drop(alice); announced.assert_next_wait(); } @@ -8458,8 +8472,8 @@ mod tests { async fn broadcast_announces_its_own_path() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); - let mut peer = consumer.clone().excluding(Hop::UNKNOWN).announced(); + let mut announced = consumer.routes(); + let mut peer = consumer.clone().excluding(Hop::UNKNOWN).routes(); // Created but not announced: invisible to local and peer cursors alike. let broadcast = producer.create_broadcast("room/alice").unwrap(); @@ -8499,7 +8513,7 @@ mod tests { async fn broadcast_announcement_retracts_with_the_last_producer() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let broadcast = producer.create_broadcast("room/alice").unwrap(); let clone = broadcast.clone(); @@ -8516,7 +8530,7 @@ mod tests { #[kio::test] async fn publish_creates_and_announces_together() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let _broadcast = producer.publish("room/alice", Route::default()).unwrap(); announced.expect_next_active("room/alice").await; } @@ -8535,7 +8549,7 @@ mod tests { let _a = producer.announce("room/alice", Route::default()).unwrap(); let _b = producer.announce("room/bob", Route::default()).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); // Replay follows the table traversal order. announced.expect_next_active("room/alice").await; announced.expect_next_active("room/bob").await; @@ -8549,7 +8563,7 @@ mod tests { // Prefix advertisements stay prefixes. The scope filters requests locally. let _a = scoped.announce("", Route::default()).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); announced.expect_next_active("").await; // Disjoint prefixes cannot be claimed at all. @@ -8565,9 +8579,9 @@ mod tests { let _a = producer.announce("", Route::default()).unwrap(); let consumer = producer.consume().scope("", &scopes(&["room"])).unwrap(); - let mut announced = consumer.clone().covering().announced(); + let mut announced = consumer.clone().covering().routes(); announced.expect_next_active("").await; - consumer.announced().assert_next_wait(); + consumer.routes().assert_next_wait(); } #[kio::test] @@ -8579,14 +8593,14 @@ mod tests { .consume() .scope("room", &Patterns::from(Pattern::all())) .unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); announced.expect_next_active("alice").await; } #[kio::test] async fn best_route_wins_and_fails_over() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let expensive = producer .announce("room", Route::default().with_hops(hops(&[10])).with_cost(5)) @@ -8688,7 +8702,7 @@ mod tests { async fn identical_reannounce_restarts_under_another_instance() { for named in [None, Some(instance())] { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let mut route = Route::default().with_hops(hops(&[10])); route.instance = named.clone(); @@ -8712,7 +8726,7 @@ mod tests { #[cfg(feature = "async")] async fn a_reprice_is_an_update() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let route = producer .requests_route("room", Route::default().with_cost(3), None) .unwrap(); @@ -8720,7 +8734,7 @@ mod tests { route.update_route(Route::default().with_cost(5)).unwrap(); match announced.next().await.expect("no next") { - AnnounceEvent::Update(update) => assert_eq!(update.route.cost, Cost::new(5)), + RouteEvent::Update(update) => assert_eq!(update.route.cost, Cost::new(5)), other => panic!("should be an update: got {other:?}"), } } @@ -8734,7 +8748,7 @@ mod tests { let first = handle.present(bytes::Bytes::from_static(b"first"), false).unwrap(); let second = handle.present(bytes::Bytes::from_static(b"second"), false).unwrap(); let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let route = producer .requests_route("room", Route::default().with_auth(first.clone()), None) .unwrap(); @@ -8742,7 +8756,7 @@ mod tests { route.update_route(Route::default().with_auth(second.clone())).unwrap(); match announced.next().await.expect("no next") { - AnnounceEvent::Update(update) => assert_eq!(update.route.auth, Some(second)), + RouteEvent::Update(update) => assert_eq!(update.route.auth, Some(second)), other => panic!("should be an update: got {other:?}"), } } @@ -8762,7 +8776,7 @@ mod tests { } .produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let peer = producer.clone().with_link(Link::Peer); let old = peer .requests_route( @@ -8817,7 +8831,7 @@ mod tests { } .produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let _old = producer .requests_route("pool/job-0", Route::default().with_hops(hops(&[old_hop])), None) .unwrap(); @@ -8869,7 +8883,7 @@ mod tests { /// Let the fronts react, then expect nothing more on `announced`. #[cfg(feature = "async")] - async fn quiet(announced: &mut AnnounceConsumer) { + async fn quiet(announced: &mut Routes) { for _ in 0..20 { kio::clock::sim::yield_now().await; } @@ -8885,7 +8899,7 @@ mod tests { let consumer = producer.consume(); let a = claim("room", "room", 10, 5); let b = claim("room", "room", 11, 9); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); assert_eq!(announced.expect_next_active("room").await.cost, Cost::new(5)); let _sticky = hold(&consumer, "room/job", &a).await; @@ -8902,10 +8916,10 @@ mod tests { .announce("room", Route::default().with_hops(hops(&[7]))) .unwrap(); - let mut hidden = producer.consume().excluding(origin(7)).announced(); + let mut hidden = producer.consume().excluding(origin(7)).routes(); hidden.assert_next_wait(); - let mut visible = producer.consume().excluding(origin(8)).announced(); + let mut visible = producer.consume().excluding(origin(8)).routes(); visible.expect_next_active("room").await; } @@ -8920,7 +8934,7 @@ mod tests { .announce("local", Route::default().with_hops(hops(&[10]))) .unwrap(); - let mut hidden = producer.consume().excluding(assigned).announced(); + let mut hidden = producer.consume().excluding(assigned).routes(); hidden.expect_next_active("local").await; hidden.assert_next_wait(); } @@ -8928,7 +8942,7 @@ mod tests { #[kio::test] async fn anonymous_route_loses_to_identified_at_any_cost() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let _anonymous = producer .announce("room", Route::default().with_hops(hops(&[0])).with_cost(1)) @@ -8948,7 +8962,7 @@ mod tests { #[kio::test] async fn anonymous_routes_order_by_cost() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let expensive = producer .announce("room", Route::default().with_hops(hops(&[0])).with_cost(5)) @@ -8970,7 +8984,7 @@ mod tests { #[kio::test] async fn anonymous_chain_from_identified_peer_still_ranks_last() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let _anonymous = producer .announce( @@ -9040,7 +9054,7 @@ mod tests { #[kio::test] async fn update_reprices_in_place() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let announcement = producer.announce("room", Route::default()).unwrap(); announced.expect_next_active("room").await; @@ -9054,7 +9068,7 @@ mod tests { #[kio::test] async fn reprice_from_the_current_route_keeps_the_instance() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let dynamic = producer .requests_route("room", Route::default().with_instance(instance(), 0).with_cost(5), None) @@ -9081,7 +9095,7 @@ mod tests { #[kio::test] async fn retract_after_undelivered_reprice_still_delivered() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let announcement = producer.announce("room", Route::default()).unwrap(); announced.expect_next_active("room").await; @@ -9107,7 +9121,7 @@ mod tests { .consume() .scope("room/alice", &Patterns::from(Pattern::all())) .unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let route = announced.expect_next_active("").await; assert_eq!(route.cost, Cost::new(9)); announced.assert_next_wait(); @@ -9126,21 +9140,21 @@ mod tests { .scope("room/alice", &Patterns::from(Pattern::all())) .unwrap() .covering(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); - let Some(Some(AnnounceEvent::Start(first))) = announced.next().now_or_never() else { + let Some(Some(RouteEvent::Start(first))) = announced.next().now_or_never() else { panic!("expected the announcement"); }; assert_eq!(first.prefix.as_str(), ""); assert_eq!(first.captures, Some(Vec::new())); drop(exact); - let Some(Some(AnnounceEvent::End(retracted))) = announced.next().now_or_never() else { + let Some(Some(RouteEvent::End(retracted))) = announced.next().now_or_never() else { panic!("expected the retraction"); }; assert_eq!(retracted.prefix.as_str(), ""); assert_eq!(retracted.captures, Some(Vec::new())); - let Some(Some(AnnounceEvent::Start(replacement))) = announced.next().now_or_never() else { + let Some(Some(RouteEvent::Start(replacement))) = announced.next().now_or_never() else { panic!("expected the replacement"); }; assert_eq!(replacement.prefix.as_str(), ""); @@ -9174,7 +9188,7 @@ mod tests { assert!((&mut resolving).now_or_never().is_none()); broadcast.announce(Route::default()).unwrap(); - let resolved = resolving.await.expect("resolves once announced"); + let resolved = resolving.await.expect("resolves once announced").unwrap(); assert_eq!(resolved.info().path.as_str(), "room/alice"); drop(broadcast); } @@ -9186,7 +9200,7 @@ mod tests { async fn cheaper_remote_route_beats_a_local_broadcast() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let _local = producer .publish("room/alice", Route::default().with_instance(instance(), 0).with_cost(5)) @@ -9598,7 +9612,7 @@ mod tests { async fn local_broadcast_wins_a_cost_tie() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let server = producer .requests_route( @@ -10017,7 +10031,7 @@ mod tests { async fn a_hairpin_through_the_plain_front_is_withdrawn() { let producer = origin(1).produce(); let peer = producer.consume().excluding(origin(7)); - let mut view = peer.announced(); + let mut view = peer.routes(); let incumbent = producer .requests_route( "room", @@ -10376,8 +10390,8 @@ mod tests { .requests_route("live", Route::default().with_cost(1), None) .unwrap(); - let mut announced = producer.consume().announced(); - let Some(Some(AnnounceEvent::Start(update))) = announced.next().now_or_never() else { + let mut announced = producer.consume().routes(); + let Some(Some(RouteEvent::Start(update))) = announced.next().now_or_never() else { panic!("expected the announcement"); }; assert_eq!(update.prefix.as_str(), "live"); @@ -10423,14 +10437,14 @@ mod tests { .scope("", &scopes(&["room/chat"])) .unwrap() .covering() - .announced(); + .routes(); matching.expect_next_active("").await; let mut outside = producer .consume() .scope("", &scopes(&["room/video"])) .unwrap() .covering() - .announced(); + .routes(); outside.assert_next_wait(); let refused = producer @@ -10466,7 +10480,7 @@ mod tests { .scope("", &scopes(&["room/video"])) .unwrap() .covering() - .announced(); + .routes(); assert_eq!(video.expect_next_active("").await.cost, Cost::new(5)); } @@ -10475,18 +10489,18 @@ mod tests { async fn route_changes_preserve_each_cursors_visible_winner() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut all = consumer.clone().announced(); - let mut excluded = consumer.clone().excluding(origin(7)).announced(); + let mut all = consumer.clone().routes(); + let mut excluded = consumer.clone().excluding(origin(7)).routes(); let mut video = consumer .clone() .scope("", &scopes(&["room/live/video"])) .unwrap() .covering() - .announced(); + .routes(); let mut rooted = consumer .scope("room/live", &Patterns::from(Pattern::all())) .unwrap() - .announced(); + .routes(); let chat = producer .scope("", &scopes(&["room/live/chat"])) @@ -10537,7 +10551,7 @@ mod tests { .scope("room/live/video", &Patterns::from(Pattern::all())) .unwrap() .covering() - .announced(); + .routes(); assert_eq!(announced.expect_next_active("").await.cost, Cost::new(9)); broad.update_route(Route::default().with_cost(0)).unwrap(); @@ -10556,7 +10570,7 @@ mod tests { .map(|i| format!("s{i}")) .collect::>() .join("/"); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let dynamic = producer .requests_route(&path, Route::default(), None) @@ -10575,10 +10589,10 @@ mod tests { .requests_route("live", Route::default().with_hops(hops(&[7])), None) .unwrap(); - let mut excluded = producer.consume().excluding(origin(7)).announced(); + let mut excluded = producer.consume().excluding(origin(7)).routes(); excluded.assert_next_wait(); - let mut clean = producer.consume().excluding(origin(8)).announced(); + let mut clean = producer.consume().excluding(origin(8)).routes(); clean.expect_next_active("live").await; } @@ -10589,22 +10603,22 @@ mod tests { use futures::StreamExt; let producer = origin(1).produce(); let server = producer.requests_route("live", Route::default(), None).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let mut next = || StreamExt::next(&mut announced).now_or_never(); - let Some(Some(AnnounceEvent::Start(update))) = next() else { + let Some(Some(RouteEvent::Start(update))) = next() else { panic!("expected the replayed route"); }; assert_eq!(update.prefix.as_str(), "live"); assert!(next().is_none()); drop(server); - assert!(matches!(next(), Some(Some(AnnounceEvent::End(_))))); + assert!(matches!(next(), Some(Some(RouteEvent::End(_))))); } #[kio::test] async fn dynamic_retracts() { let producer = origin(1).produce(); let server = producer.requests_route("live", Route::default(), None).unwrap(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); announced.expect_next_active("live").await; drop(server); @@ -10614,8 +10628,8 @@ mod tests { #[kio::test] async fn local_broadcast_is_invisible_until_announced() { let producer = origin(1).produce(); - let mut local = producer.consume().announced(); - let mut peer = producer.consume().excluding(Hop::UNKNOWN).announced(); + let mut local = producer.consume().routes(); + let mut peer = producer.consume().excluding(Hop::UNKNOWN).routes(); let broadcast = producer.create_broadcast("room/alice").unwrap(); local.assert_next_wait(); peer.assert_next_wait(); @@ -10728,7 +10742,7 @@ mod tests { let source = broadcast::Info::new().produce(); request.accept(&source); - let resolved = resolving.await.expect("resolves via the standby"); + let resolved = resolving.await.expect("resolves via the standby").unwrap(); assert_eq!(resolved.info().path.as_str(), "room/alice"); } @@ -10759,7 +10773,7 @@ mod tests { async fn routes_report_where_they_entered() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let _ingest = producer .requests_route( @@ -10812,7 +10826,7 @@ mod tests { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); step(Duration::from_millis(1)).await; // One instance, so the winner moving between routes is an update, not a restart. @@ -10832,7 +10846,7 @@ mod tests { assert!(announced.try_next().is_none(), "the update is still held"); step(DEFAULT_UPDATE_HOLD).await; match announced.try_next().expect("the hold passed") { - AnnounceEvent::Update(update) => assert_eq!(update.route.hops, hops(&[9, 3, 4])), + RouteEvent::Update(update) => assert_eq!(update.route.hops, hops(&[9, 3, 4])), other => panic!("should be an update: got {other:?}"), } } @@ -10869,9 +10883,9 @@ mod tests { .unwrap(), ); } - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); for _ in 0..k { - assert!(matches!(announced.try_next(), Some(AnnounceEvent::Start(_)))); + assert!(matches!(announced.try_next(), Some(RouteEvent::Start(_)))); } let before = announced.state.read().steps; @@ -10882,7 +10896,7 @@ mod tests { for (i, route) in far.into_iter().enumerate().rev() { drop(route); match announced.try_next() { - Some(AnnounceEvent::End(end)) => assert_eq!(end.prefix, Path::new(&format!("room/{i}")).unwrap()), + Some(RouteEvent::End(end)) => assert_eq!(end.prefix, Path::new(&format!("room/{i}")).unwrap()), other => panic!("should be a retraction: got {other:?}"), } } @@ -10901,7 +10915,7 @@ mod tests { async fn a_changed_route_waits_out_the_hold() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); // Holds count on the driver's clock, which starts at its first poll. kio::clock::sleep(Duration::from_millis(1)).await; @@ -10922,7 +10936,7 @@ mod tests { drop(near); drop(far); match announced.next().await.unwrap() { - AnnounceEvent::Update(update) => assert_eq!(update.route.hops, hops(&[9, 5, 6, 7])), + RouteEvent::Update(update) => assert_eq!(update.route.hops, hops(&[9, 5, 6, 7])), other => panic!("should be an update: got {other:?}"), } assert_eq!(kio::clock::now() - start, DEFAULT_UPDATE_HOLD); @@ -10940,7 +10954,7 @@ mod tests { async fn a_retraction_quarantines_a_named_publisher() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); kio::clock::sleep(Duration::from_millis(1)).await; // Every path is to one publisher, so to one instance. @@ -10958,7 +10972,7 @@ mod tests { let start = kio::clock::now(); let _stale = peer.requests_route("named", route(&[9, 3, 4], 4), None).unwrap(); match announced.next().await.unwrap() { - AnnounceEvent::Start(announce) => assert_eq!(announce.route.hops, hops(&[9, 3, 4])), + RouteEvent::Start(announce) => assert_eq!(announce.route.hops, hops(&[9, 3, 4])), other => panic!("should be a start: got {other:?}"), } assert!(kio::clock::now() - start >= RETRACT_QUARANTINE); @@ -11003,7 +11017,7 @@ mod tests { async fn withdrawn_peer_hides_routes_through_it() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); // Publisher 9 ingests at relay 2; relay 3 relays 2's route. let direct = || Route::default().with_hops(hops(&[9, 2])).with_via(origin(2)); @@ -11042,7 +11056,7 @@ mod tests { for old_first in [false, true] { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let route = Route::default().with_instance(instance(), 0).with_hops(hops(&[9, 2])); let first = peer.requests_route("room", route.clone(), None).unwrap(); let second = peer.requests_route("room", route.clone(), None).unwrap(); @@ -11095,7 +11109,7 @@ mod tests { async fn source_change_is_an_update() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let route = Route::default() .with_instance(instance(), 0) @@ -11110,7 +11124,7 @@ mod tests { // The newest identical route wins, so the local twin takes over. let local = producer.requests_route("room", route, None).unwrap(); match announced.next().await.expect("no next") { - AnnounceEvent::Update(announce) => assert_eq!(announce.route.source(), Source::Local), + RouteEvent::Update(announce) => assert_eq!(announce.route.source(), Source::Local), other => panic!("should be an update: got {other:?}"), } @@ -11125,7 +11139,7 @@ mod tests { async fn local_view_hides_peer_routes() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); - let mut local = producer.consume().local().announced(); + let mut local = producer.consume().local().routes(); let _forwarded = peer .requests_route( @@ -11181,8 +11195,8 @@ mod tests { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); let core = producer.clone().with_link(Link::Upstream); - let mut toward_core = core.consume().announced(); - let mut everyone = producer.consume().announced(); + let mut toward_core = core.consume().routes(); + let mut everyone = producer.consume().routes(); let _core = core .requests_route("core", Route::default().with_hops(hops(&[7])).with_via(origin(7)), None) @@ -11294,7 +11308,7 @@ mod tests { #[cfg(feature = "async")] async fn a_prepared_answer_cannot_announce_itself() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let claim = producer.requests("room").unwrap(); announced.assert_next_active("room"); let pending = producer.consume().request("room/alice", None); @@ -11318,7 +11332,7 @@ mod tests { async fn publication_clones_share_control_and_fill_retention() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut events = consumer.announced(); + let mut events = consumer.routes(); let publication = producer.create_broadcast("room/alice").unwrap(); let fill = publication.broadcast().clone(); let control = publication.clone(); @@ -11402,7 +11416,7 @@ mod tests { #[cfg(feature = "async")] async fn a_prepared_answer_for_an_abandoned_claim_is_never_announced() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let claim = producer.requests("room").unwrap(); announced.assert_next_active("room"); let _pending = producer.consume().request("room/alice", None); @@ -11419,7 +11433,7 @@ mod tests { #[cfg(feature = "async")] async fn a_prepared_answer_for_a_released_request_is_never_announced() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let claim = producer.requests("room").unwrap(); announced.assert_next_active("room"); let _pending = producer.consume().request("room/alice", None); @@ -11441,7 +11455,7 @@ mod tests { async fn a_withdrawn_takeover_ends_the_claims_continuity() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let claim = producer.requests("room").unwrap(); announced.assert_next_active("room"); @@ -11454,7 +11468,7 @@ mod tests { let _alice = answer("room/alice").await; match announced.expect_next().await { - AnnounceEvent::Takeover { announce, predecessor } => { + RouteEvent::Takeover { announce, predecessor } => { assert_eq!(announce.prefix.as_str(), "room/alice"); assert_eq!(predecessor.as_str(), "room"); } @@ -11464,7 +11478,7 @@ mod tests { answer("room/bob").await.unannounce(); let _carol = answer("room/carol").await; match announced.expect_next().await { - AnnounceEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "room/carol"), + RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "room/carol"), other => panic!("should be a start: got {other:?}"), } announced.assert_next_wait(); @@ -11671,7 +11685,7 @@ mod tests { async fn root_dynamic_serves_any_path() { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let dynamic = producer.requests_route("", Route::default(), None).unwrap(); // The root claim is advertised like any other prefix. announced.expect_next_active("").await; @@ -11726,9 +11740,9 @@ mod tests { /// The route a follower's first event starts on. #[cfg(feature = "async")] - fn started(event: Option) -> Route { + fn started(event: Option) -> Route { match event.expect("routed") { - AnnounceEvent::Start(announce) => announce.route, + RouteEvent::Start(announce) => announce.route, other => panic!("should start: got {other:?}"), } } @@ -11739,7 +11753,7 @@ mod tests { let producer = origin(1).produce(); let consumer = producer.consume(); - let mut routes = consumer.routes("room/alice").unwrap(); + let mut routes = consumer.path_routes("room/alice").unwrap(); let mut fut = routes.next().boxed(); assert!((&mut fut).now_or_never().is_none()); @@ -11749,7 +11763,7 @@ mod tests { assert_eq!(route.cost, Cost::new(3)); // Already covered: resolves immediately. - let mut routes = consumer.routes("room/alice/cam").unwrap(); + let mut routes = consumer.path_routes("room/alice/cam").unwrap(); started(routes.next().now_or_never().expect("covered")); } @@ -11761,7 +11775,7 @@ mod tests { // A deeper route does not cover the shorter path. let _deep = producer.announce("room/alice/cam", Route::default()).unwrap(); - let mut routes = consumer.routes("room/alice").unwrap(); + let mut routes = consumer.path_routes("room/alice").unwrap(); let mut fut = routes.next().boxed(); assert!((&mut fut).now_or_never().is_none()); @@ -11782,7 +11796,7 @@ mod tests { assert!(consumer.allowed().matches(&path)); - let mut routes = consumer.routes(&path).unwrap(); + let mut routes = consumer.path_routes(&path).unwrap(); let mut fut = routes.next().boxed(); assert!((&mut fut).now_or_never().is_none()); @@ -11797,7 +11811,7 @@ mod tests { let (producer, driver) = Producer::new(Config::new(origin(1))); let consumer = producer.consume(); let _announcement = producer.announce("room", Route::default()).unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); announced.expect_next_active("room").await; let _server = producer.requests_route("served", Route::default(), None).unwrap(); @@ -11822,7 +11836,7 @@ mod tests { assert!(matches!(err, Error::Closed)); // A cursor born after the teardown is born ended. - let mut late = consumer.announced(); + let mut late = consumer.routes(); assert!(late.next().now_or_never().expect("ended").is_none()); } @@ -11832,7 +11846,7 @@ mod tests { fn teardown_owes_what_a_snapshot_held() { let (producer, driver) = Producer::new(Config::new(origin(1))); let snapshot = producer.snapshot("room"); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let _alice = producer.announce("room/alice", Route::default()).unwrap(); drop(driver); @@ -12068,14 +12082,14 @@ mod tests { let (first, ()) = futures::join!(follow.available(), async { queued(&a).await.accept(broadcast::Info::new().produce()); }); - let first = first.unwrap(); + let first = first.unwrap().unwrap(); assert_eq!(first.info().instance, Some("a".parse().unwrap())); drop(a); let (second, ()) = futures::join!(follow.available(), async { queued(&b).await.accept(broadcast::Info::new().produce()); }); - let second = second.unwrap(); + let second = second.unwrap().unwrap(); assert_eq!(second.info().instance, Some("b".parse().unwrap())); assert!(!second.is_clone(&first)); } @@ -12107,7 +12121,7 @@ mod tests { let (first, ()) = futures::join!(follow.available(), async { queued(&a).await.accept(broadcast::Info::new().produce()); }); - let first = first.unwrap(); + let first = first.unwrap().unwrap(); let weak = first.weak(); drop(first); settle(|| weak.consume().poll_closed(&kio::Waiter::noop()).is_ready()).await; @@ -12129,7 +12143,7 @@ mod tests { let (second, ()) = futures::join!(follow.available(), async { queued(&b).await.accept(broadcast::Info::new().produce()); }); - assert_eq!(second.unwrap().info().instance, Some("b".parse().unwrap())); + assert_eq!(second.unwrap().unwrap().info().instance, Some("b".parse().unwrap())); } /// Write one single-frame group and read it back through `subscription`. @@ -12437,7 +12451,7 @@ mod tests { #[cfg(feature = "async")] async fn the_newest_epoch_is_announced_in_place() { let producer = origin(1).produce(); - let mut announced = producer.consume().announced(); + let mut announced = producer.consume().routes(); let instance = crate::Instance::random(); let _old = producer .publish( @@ -13671,7 +13685,7 @@ mod tests { .scope("", &scopes(&["alpha", "beta"])) .unwrap() .covering(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); announced.expect_next_active("").await; announced.assert_next_wait(); } @@ -13722,7 +13736,7 @@ mod tests { let cursor = consumer .scope("", &scopes(&["room/a", "other/deep/head"])) .unwrap() - .announced(); + .routes(); let route = producer.announce("room/a/b/c", Route::default()).unwrap(); { let table = producer.shared.lock(); @@ -14128,12 +14142,12 @@ mod tests { .consume() .scope("", &Patterns::from("room/*/chat".parse::().unwrap())) .unwrap(); - let mut listed = consumer.announced(); - let mut announced = consumer.covering().announced(); + let mut listed = consumer.routes(); + let mut announced = consumer.covering().routes(); let alice = producer.create_broadcast("room/alice/chat").unwrap(); alice.announce(Route::default()).unwrap(); - let Some(AnnounceEvent::Start(update)) = announced.try_next() else { + let Some(RouteEvent::Start(update)) = announced.try_next() else { panic!("expected alice's chat"); }; assert_eq!(update.prefix.as_str(), "room/alice/chat"); @@ -14145,7 +14159,7 @@ mod tests { announced.assert_next_wait(); let broad = producer.announce("room", Route::default()).unwrap(); - let Some(AnnounceEvent::Start(update)) = announced.try_next() else { + let Some(RouteEvent::Start(update)) = announced.try_next() else { panic!("expected the overlapping broad route"); }; assert_eq!(update.prefix.as_str(), "room"); @@ -14168,11 +14182,11 @@ mod tests { let cam = producer.announce("project/cam.hang", Route::default()).unwrap(); let overlap = producer.announce("project/room/mic.hang", Route::default()).unwrap(); let chat = producer.announce("project/lobby.chat", Route::default()).unwrap(); - let mut routing = consumer.clone().covering().announced(); + let mut routing = consumer.clone().covering().routes(); routing.expect_next_active("cam.hang").await; routing.expect_next_active("lobby.chat").await; routing.expect_next_active("room/mic.hang").await; - let mut selected = consumer.announced(); + let mut selected = consumer.routes(); selected.expect_next_active("cam.hang").await; selected.expect_next_active("lobby.chat").await; selected.assert_next_wait(); @@ -14196,7 +14210,7 @@ mod tests { .scope("room/alice", &Patterns::from(Pattern::all())) .unwrap(); let broad = producer.announce("room", Route::default()).unwrap(); - let mut selected = consumer.announced(); + let mut selected = consumer.routes(); selected.assert_next_wait(); let first_instance = crate::Instance::random(); @@ -14204,21 +14218,21 @@ mod tests { .announce("room/alice", Route::default().with_instance(first_instance.clone(), 0)) .unwrap(); assert!( - matches!(selected.expect_next().await, AnnounceEvent::Start(a) if a.prefix.is_empty() && a.captures.is_some()) + matches!(selected.expect_next().await, RouteEvent::Start(a) if a.prefix.is_empty() && a.captures.is_some()) ); exact .update(Route::default().with_instance(first_instance, 0).with_cost(2)) .unwrap(); - assert!(matches!(selected.expect_next().await, AnnounceEvent::Update(a) if a.route.cost == Cost::new(2))); + assert!(matches!(selected.expect_next().await, RouteEvent::Update(a) if a.route.cost == Cost::new(2))); exact .update(Route::default().with_instance(crate::Instance::random(), 0)) .unwrap(); - assert!(matches!(selected.expect_next().await, AnnounceEvent::Restart(_))); + assert!(matches!(selected.expect_next().await, RouteEvent::Restart(_))); drop(exact); selected.expect_next_ended("").await; selected.assert_next_wait(); let _again = producer.announce("room/alice", Route::default()).unwrap(); - assert!(matches!(selected.expect_next().await, AnnounceEvent::Start(_))); + assert!(matches!(selected.expect_next().await, RouteEvent::Start(_))); drop(broad); selected.assert_next_wait(); drop(selected); @@ -14242,13 +14256,13 @@ mod tests { .with_hidden(true) .exclude(".svc/private") .unwrap(); - let mut selected = project.announced(); + let mut selected = project.routes(); selected.expect_next_active(".svc/.private/lobby.chat").await; selected.assert_next_wait(); let mut inside = project .scope(".svc", &Patterns::from(Pattern::all())) .unwrap() - .announced(); + .routes(); inside.expect_next_active(".private/lobby.chat").await; inside.assert_next_wait(); let live = producer.announce(".svc/p1/lobby.chat", Route::default()).unwrap(); @@ -14276,7 +14290,7 @@ mod tests { .tier(stats::Tier::default()) .session(Path::from_static("project")), ); - let mut selected = consumer.announced(); + let mut selected = consumer.routes(); selected.expect_next_active("cam.chat").await; selected.assert_next_wait(); let resolved = consumer.request("cam.chat", None).await.unwrap(); @@ -14309,7 +14323,7 @@ mod tests { assert_eq!(report.traffic[0].publisher.announces_ended, 1); // Discovery of a request still sees a covering route that enumeration omits. - let mut routes = consumer.routes("room/lobby.chat").unwrap(); + let mut routes = consumer.path_routes("room/lobby.chat").unwrap(); assert!(routes.next().await.is_some()); drop(routes); drop(overlap); @@ -14327,8 +14341,8 @@ mod tests { let local = producer.create_broadcast("room/alice").unwrap(); local.announce(Route::default()).unwrap(); - let mut announced = producer.consume().announced(); - let Some(AnnounceEvent::Start(update)) = announced.try_next() else { + let mut announced = producer.consume().routes(); + let Some(RouteEvent::Start(update)) = announced.try_next() else { panic!("expected one winning route"); }; assert_eq!(update.prefix.as_str(), "room/alice"); diff --git a/rs/moq-net/tests/integration/announce_covering_route.rs b/rs/moq-net/tests/integration/announce_covering_route.rs index 9b1db074a8b..c88a1524e01 100644 --- a/rs/moq-net/tests/integration/announce_covering_route.rs +++ b/rs/moq-net/tests/integration/announce_covering_route.rs @@ -27,8 +27,8 @@ fn produce_origin(hop: u64) -> origin::Producer { } /// Drain every event the cursor has pending, as `kind prefix` lines. -fn drain(announced: &mut moq_net::announce::Consumer) -> Vec { - use moq_net::announce::Event; +fn drain(announced: &mut moq_net::origin::Routes) -> Vec { + use moq_net::origin::RouteEvent as Event; let mut seen = Vec::new(); while let Some(event) = announced.try_next() { let (kind, announce) = match event { @@ -62,7 +62,7 @@ async fn covering(version: Option<&str>) -> Vec { (subscriber.consume(), Some(connect_mock(options).await)) } }; - let mut announced = observer.scope(REQUESTED, &everything).unwrap().covering().announced(); + let mut announced = observer.scope(REQUESTED, &everything).unwrap().covering().routes(); let mut log = Vec::new(); let served = publisher.create_broadcast(SERVED).unwrap(); @@ -146,8 +146,8 @@ async fn relays_route_a_covering_claim_that_listings_omit() { let _downstream = connect_mock(options).await; let scoped = client.consume().scope("", &chat).unwrap(); - let mut listed = scoped.announced(); - let mut covering = scoped.clone().covering().announced(); + let mut listed = scoped.routes(); + let mut covering = scoped.clone().covering().routes(); kio::clock::sleep(SETTLE).await; assert_eq!(drain(&mut listed), ["Start lobby.chat"], "{version}"); let mut routes = drain(&mut covering); diff --git a/rs/moq-net/tests/integration/announce_takeover.rs b/rs/moq-net/tests/integration/announce_takeover.rs index bf28bbf2ae3..f3c08ef14c0 100644 --- a/rs/moq-net/tests/integration/announce_takeover.rs +++ b/rs/moq-net/tests/integration/announce_takeover.rs @@ -9,7 +9,7 @@ use crate::support; use std::{cell::RefCell, rc::Rc, time::Duration}; -use moq_net::{Hop, Timestamp, Version, announce, origin, track}; +use moq_net::{Hop, Timestamp, Version, origin, track}; use support::harness::{MockConnectOptions, MockPair, connect_mock}; const TEST_TIMEOUT: Duration = Duration::from_secs(600); @@ -73,17 +73,17 @@ impl Worker { } /// Every announce event already delivered, as `(kind, prefix, predecessor)`. -async fn drain(announced: &mut announce::Consumer) -> Vec<(&'static str, String, Option)> { +async fn drain(announced: &mut origin::Routes) -> Vec<(&'static str, String, Option)> { let mut events = Vec::new(); while let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { events.push(match event.expect("announce ended") { - announce::Event::Start(a) => ("start", a.prefix.to_string(), None), - announce::Event::Update(a) => ("update", a.prefix.to_string(), None), - announce::Event::Restart(a) => ("restart", a.prefix.to_string(), None), - announce::Event::Takeover { announce, predecessor } => { + origin::RouteEvent::Start(a) => ("start", a.prefix.to_string(), None), + origin::RouteEvent::Update(a) => ("update", a.prefix.to_string(), None), + origin::RouteEvent::Restart(a) => ("restart", a.prefix.to_string(), None), + origin::RouteEvent::Takeover { announce, predecessor } => { ("takeover", announce.prefix.to_string(), Some(predecessor.to_string())) } - announce::Event::End(a) => ("end", a.prefix.to_string(), None), + origin::RouteEvent::End(a) => ("end", a.prefix.to_string(), None), }); } events @@ -117,8 +117,8 @@ async fn chain(version: &str, claim: &str) { let _downstream = link(version, &relay, &edge, 1).await; settle().await; - let mut at_relay = relay.consume().announced(); - let mut at_edge = edge.consume().announced(); + let mut at_relay = relay.consume().routes(); + let mut at_edge = edge.consume().routes(); let claimed = [("start", claim.to_string(), None)]; assert_eq!(drain(&mut at_relay).await, claimed, "{version}"); assert_eq!(drain(&mut at_edge).await, claimed, "{version}"); @@ -149,7 +149,7 @@ async fn chain(version: &str, claim: &str) { assert_eq!(drain(&mut at_edge).await, answered, "{version}: at the edge"); // A late snapshot starts what stands, replaying no takeover. - let mut late = edge.consume().announced(); + let mut late = edge.consume().routes(); let mut snapshot = vec![("start", "pool/p".to_string(), None)]; if claim != "pool/p" { snapshot.insert(0, ("start", claim.to_string(), None)); @@ -191,7 +191,7 @@ async fn two_workers_announce_a_start() { let _b = link(version, &b.origin, &relay, 10).await; settle().await; - let mut announced = relay.consume().announced(); + let mut announced = relay.consume().routes(); assert_eq!(drain(&mut announced).await, [("start", "pool".to_string(), None)]); assert_eq!(watch(&relay, "pool/p").await, "a"); @@ -217,7 +217,7 @@ async fn an_unrequested_publish_is_a_start() { let _link = link(version, &worker.origin, &relay, 1).await; settle().await; - let mut announced = relay.consume().announced(); + let mut announced = relay.consume().routes(); assert_eq!(drain(&mut announced).await, [("start", "pool".to_string(), None)]); let _direct = worker.origin.publish("pool/q", origin::Route::default()).unwrap(); @@ -240,8 +240,8 @@ async fn an_older_downstream_gets_a_start() { let _downstream = link("moq-lite-06".parse().unwrap(), &relay, &edge, 1).await; settle().await; - let mut at_relay = relay.consume().announced(); - let mut at_edge = edge.consume().announced(); + let mut at_relay = relay.consume().routes(); + let mut at_edge = edge.consume().routes(); drain(&mut at_relay).await; drain(&mut at_edge).await; diff --git a/rs/moq-net/tests/integration/announce_to_serve.rs b/rs/moq-net/tests/integration/announce_to_serve.rs index 35895427298..112ac37fba1 100644 --- a/rs/moq-net/tests/integration/announce_to_serve.rs +++ b/rs/moq-net/tests/integration/announce_to_serve.rs @@ -43,8 +43,8 @@ enum Observer { } /// Drain every route event the cursor has pending, as `kind prefix` lines. -fn drain(announced: &mut moq_net::announce::Consumer) -> Vec { - use moq_net::announce::Event; +fn drain(announced: &mut moq_net::origin::Routes) -> Vec { + use moq_net::origin::RouteEvent as Event; let mut seen = Vec::new(); while let Some(event) = announced.try_next() { @@ -141,7 +141,7 @@ async fn lifecycle(observer: Observer) -> Vec { (subscriber.consume(), Some(pair)) } }; - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let mut log = Vec::new(); // Created, not yet announced: nobody can see or reach it. diff --git a/rs/moq-net/tests/integration/auth.rs b/rs/moq-net/tests/integration/auth.rs index a5d6b2bb392..c9fe92e4d7b 100644 --- a/rs/moq-net/tests/integration/auth.rs +++ b/rs/moq-net/tests/integration/auth.rs @@ -396,16 +396,16 @@ async fn granted(session: &Session) -> Grant { /// Wait until `path` is announced (`true`) or retracted (`false`) in `origin`. async fn wait_announced(origin: &origin::Consumer, path: &str, active: bool) { - let mut announced = origin.announced(); + let mut announced = origin.routes(); let mut live = std::collections::HashSet::new(); - let apply = |live: &mut std::collections::HashSet, event: moq_net::announce::Event| match event { - moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Restart(update) - | moq_net::announce::Event::Takeover { announce: update, .. } => { + let apply = |live: &mut std::collections::HashSet, event: moq_net::origin::RouteEvent| match event { + moq_net::origin::RouteEvent::Start(update) + | moq_net::origin::RouteEvent::Update(update) + | moq_net::origin::RouteEvent::Restart(update) + | moq_net::origin::RouteEvent::Takeover { announce: update, .. } => { live.insert(update.prefix.to_string()); } - moq_net::announce::Event::End(update) => { + moq_net::origin::RouteEvent::End(update) => { live.remove(update.prefix.as_str()); } }; @@ -1104,7 +1104,7 @@ async fn exact_and_subtree_grants_admit_their_broadcast(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let prefs = moq_net::track::Subscription::default() .with_delay(moq_net::track::Delay::default().with_max(Duration::from_secs(10))); let mut sub = remote.track("video").unwrap().subscribe(prefs).await.unwrap(); @@ -1166,7 +1166,7 @@ async fn a_live_subscription_survives_union_renewal(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut group = published.append_group().unwrap(); group .write_frame(moq_net::Timestamp::from_millis(0).unwrap(), b"first".as_ref()) @@ -1246,7 +1246,7 @@ async fn a_revoked_grant_cancels_its_subscriptions(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut down_sub = remote.track("video").unwrap().subscribe(prefs()).await.unwrap(); down_sub.recv_group().await.unwrap().unwrap(); @@ -1256,7 +1256,7 @@ async fn a_revoked_grant_cancels_its_subscriptions(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut up_sub = remote.track("video").unwrap().subscribe(prefs()).await.unwrap(); up_sub.recv_group().await.unwrap().unwrap(); @@ -1638,7 +1638,7 @@ async fn a_narrowing_deafens_one_path(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut audio_sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); audio_sub.recv_group().await.unwrap().unwrap(); let remote = received @@ -1647,7 +1647,7 @@ async fn a_narrowing_deafens_one_path(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut video_sub = remote.track("h264").unwrap().subscribe(prefs()).await.unwrap(); video_sub.recv_group().await.unwrap().unwrap(); @@ -1726,7 +1726,7 @@ async fn a_narrowing_aborts_what_the_peer_published(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut mic_sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); mic_sub.recv_group().await.unwrap().unwrap(); let remote = relay @@ -1735,7 +1735,7 @@ async fn a_narrowing_aborts_what_the_peer_published(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut cam_sub = remote.track("h264").unwrap().subscribe(prefs()).await.unwrap(); cam_sub.recv_group().await.unwrap().unwrap(); @@ -1786,7 +1786,7 @@ async fn a_narrowing_resets_a_fetch_in_flight(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut fetched = remote.track("video").unwrap().fetch_group(0, None).await.unwrap(); let frame = fetched.read_frame().await.unwrap().expect("first frame"); assert_eq!(frame.payload.as_ref(), b"first"); @@ -1857,7 +1857,7 @@ async fn a_widening_brings_back_a_deafened_path(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); sub.recv_group().await.unwrap().unwrap(); @@ -1875,7 +1875,7 @@ async fn a_widening_brings_back_a_deafened_path(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); let mut group = audio_track.append_group().unwrap(); group.write_frame(ts(1), b"a".as_ref()).unwrap(); @@ -1933,7 +1933,7 @@ async fn a_widening_brings_back_what_the_peer_published(version: &'static str) { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); let mut group = mic_track.append_group().unwrap(); group.write_frame(ts(0), b"m".as_ref()).unwrap(); diff --git a/rs/moq-net/tests/integration/broadcast_close.rs b/rs/moq-net/tests/integration/broadcast_close.rs index cd65a8ca432..6a7fe549632 100644 --- a/rs/moq-net/tests/integration/broadcast_close.rs +++ b/rs/moq-net/tests/integration/broadcast_close.rs @@ -30,7 +30,7 @@ async fn close_then_lookup(publisher: moq_net::origin::Producer, reader: moq_net let handle = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); handle.track("video").expect("a live broadcast serves its track"); broadcast.close(); diff --git a/rs/moq-net/tests/integration/catalog_acquisition.rs b/rs/moq-net/tests/integration/catalog_acquisition.rs index 2f694bb89ed..944ba91f8f0 100644 --- a/rs/moq-net/tests/integration/catalog_acquisition.rs +++ b/rs/moq-net/tests/integration/catalog_acquisition.rs @@ -38,10 +38,10 @@ async fn acquisition(version: &str, carries_instance: bool) { .unwrap() .available() .await - .unwrap(); - let mut announced = subscriber.consume().announced(); + .unwrap().unwrap(); + let mut announced = subscriber.consume().routes(); let old_cost = match announced.next().await { - Some(moq_net::announce::Event::Start(announce)) => announce.route.cost, + Some(moq_net::origin::RouteEvent::Start(announce)) => announce.route.cost, other => panic!("expected the first route, got {other:?}"), }; let mut pending = Box::pin(remote.track("catalog.json").unwrap().subscribe(None)); @@ -55,8 +55,8 @@ async fn acquisition(version: &str, carries_instance: bool) { // A replacement under a minted instance restarts the advertisement; a carried one only // updates it. let new_cost = match announced.next().await { - Some(moq_net::announce::Event::Update(announce)) if carries_instance => announce.route.cost, - Some(moq_net::announce::Event::Restart(announce)) if !carries_instance => announce.route.cost, + Some(moq_net::origin::RouteEvent::Update(announce)) if carries_instance => announce.route.cost, + Some(moq_net::origin::RouteEvent::Restart(announce)) if !carries_instance => announce.route.cost, other => panic!("{version}: unexpected route change {other:?}"), }; assert!(new_cost < old_cost, "the cheaper session wins the route"); diff --git a/rs/moq-net/tests/integration/compress.rs b/rs/moq-net/tests/integration/compress.rs index b1e33fc8a80..c23dab56eef 100644 --- a/rs/moq-net/tests/integration/compress.rs +++ b/rs/moq-net/tests/integration/compress.rs @@ -101,7 +101,7 @@ async fn relay(published: Published, hops: [&str; 2], subscription: moq_net::tra let downstream = connect_mock(options).await; let consumer = origin.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); let subscriber = remote.track("data").unwrap().subscribe(subscription).await.unwrap(); support::harness::subscribed(&track).await; @@ -292,7 +292,7 @@ async fn datagrams_meter_the_bytes_on_the_wire() { let downstream = connect_mock(options).await; let consumer = origin.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); let mut subscriber = remote.track("data").unwrap().subscribe(None).await.unwrap(); support::harness::subscribed(&track).await; @@ -396,7 +396,7 @@ async fn ietf_fetch_keeps_the_stored_form() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let consumer = remote.track("data").unwrap(); assert!(consumer.info().await.unwrap().compress, "{version}"); let mut fetched = consumer.fetch_group(0, moq_net::group::Fetch::default()).await.unwrap(); diff --git a/rs/moq-net/tests/integration/control_stats.rs b/rs/moq-net/tests/integration/control_stats.rs index 4ad814fdbd9..10df93a6b06 100644 --- a/rs/moq-net/tests/integration/control_stats.rs +++ b/rs/moq-net/tests/integration/control_stats.rs @@ -43,7 +43,7 @@ async fn control_classes_cross_lite_and_ietf_sessions_without_counting_payload() .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); subscribed(&track).await; let mut group = track.append_group().unwrap(); diff --git a/rs/moq-net/tests/integration/datagram.rs b/rs/moq-net/tests/integration/datagram.rs index 0e8087bd623..f8a41470a91 100644 --- a/rs/moq-net/tests/integration/datagram.rs +++ b/rs/moq-net/tests/integration/datagram.rs @@ -54,7 +54,7 @@ async fn connect_datagram_track() -> Fixture { let pair = connect_mock(options).await; let consumer = consumer_origin.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let subscriber = remote.track("datagrams").unwrap().subscribe(None).await.unwrap(); // The subscriber is handed over once TRACK_INFO answers, before its SUBSCRIBE reaches // the publisher, and a datagram only goes to a subscription already there. @@ -143,7 +143,7 @@ async fn ietf_delivers_datagrams_on(version: &str) { let _pair = connect_mock(options).await; let consumer = consumer_origin.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let mut subscriber = remote.track("datagrams").unwrap().subscribe(None).await.unwrap(); // A group first, so the subscription's alias is bound before any datagram lands. @@ -246,7 +246,7 @@ async fn a_fetched_datagram_is_refused_per_version() { let sequence = producer.append_datagram(Timestamp::ZERO, &b"x"[..]).unwrap(); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); let err = match remote.track("datagrams").unwrap().fetch_group(sequence, None).await { Ok(_) => panic!("{versions:?}: a datagram was fetched"), Err(err) => err, diff --git a/rs/moq-net/tests/integration/dial_split_horizon.rs b/rs/moq-net/tests/integration/dial_split_horizon.rs index d017fcbe397..6b3ebf74f1d 100644 --- a/rs/moq-net/tests/integration/dial_split_horizon.rs +++ b/rs/moq-net/tests/integration/dial_split_horizon.rs @@ -94,16 +94,16 @@ fn traffic(registry: &stats::Registry, role: stats::Role) -> stats::Traffic { /// The hop the dialer attributed `path` to, once that announce has arrived. async fn learned_hop(dialer: &origin::Producer, path: &str) -> Hop { - let mut announced = dialer.consume().announced(); + let mut announced = dialer.consume().routes(); let event = kio::clock::timeout(SETTLE, async { loop { let event = announced.next().await.expect("announce cursor closed"); let announce = match event { - moq_net::announce::Event::Start(announce) - | moq_net::announce::Event::Update(announce) - | moq_net::announce::Event::Restart(announce) - | moq_net::announce::Event::Takeover { announce, .. } => announce, - moq_net::announce::Event::End(_) => continue, + moq_net::origin::RouteEvent::Start(announce) + | moq_net::origin::RouteEvent::Update(announce) + | moq_net::origin::RouteEvent::Restart(announce) + | moq_net::origin::RouteEvent::Takeover { announce, .. } => announce, + moq_net::origin::RouteEvent::End(_) => continue, }; if announce.prefix.as_str() == path { return announce; @@ -160,12 +160,12 @@ async fn split_horizon(version: &str, [publisher_hop, subscriber_hop]: [Hop; 2]) // The other edge learns the namespace, attributed to a different hop, so the // two dials are not one endpoint. - let mut subscriber_announced = subscriber.consume().announced(); + let mut subscriber_announced = subscriber.consume().routes(); let subscriber_saw = kio::clock::timeout(SETTLE, subscriber_announced.next()) .await .expect("the other edge never learned the namespace") .expect("announce cursor closed"); - let moq_net::announce::Event::Start(subscriber_saw) = subscriber_saw else { + let moq_net::origin::RouteEvent::Start(subscriber_saw) = subscriber_saw else { panic!("the other edge's first event was not the namespace: {subscriber_saw:?}"); }; assert_eq!(subscriber_saw.prefix.as_str(), "room"); diff --git a/rs/moq-net/tests/integration/empty_group.rs b/rs/moq-net/tests/integration/empty_group.rs index 4fd5e61799f..acd8375fee5 100644 --- a/rs/moq-net/tests/integration/empty_group.rs +++ b/rs/moq-net/tests/integration/empty_group.rs @@ -39,7 +39,7 @@ async fn an_empty_group_arrives_empty() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut sub = kio::clock::timeout(TIMEOUT, remote.track("data").unwrap().subscribe(None)) .await .expect("subscribe timeout") diff --git a/rs/moq-net/tests/integration/errored_end.rs b/rs/moq-net/tests/integration/errored_end.rs index a8f8fc5caf2..6387b307e7c 100644 --- a/rs/moq-net/tests/integration/errored_end.rs +++ b/rs/moq-net/tests/integration/errored_end.rs @@ -99,7 +99,7 @@ async fn an_errored_end_keeps_its_history_across_a_hop() { let remote = kio::clock::timeout(TIMEOUT, subscriber.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); session.server_transport.split_unis(); if subscribe_first { diff --git a/rs/moq-net/tests/integration/extensions.rs b/rs/moq-net/tests/integration/extensions.rs index a477925cf59..ecadc6b76a2 100644 --- a/rs/moq-net/tests/integration/extensions.rs +++ b/rs/moq-net/tests/integration/extensions.rs @@ -40,17 +40,17 @@ fn assert_open(pair: &MockPair, context: &str) { /// Whether `path` is announced in `origin` right now. fn announced(origin: &origin::Producer, path: &str) -> bool { - let mut announced = origin.consume().announced(); + let mut announced = origin.consume().routes(); let mut live = false; while let Some(event) = announced.try_next() { match event { - moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Restart(update) - | moq_net::announce::Event::Takeover { announce: update, .. } => { + moq_net::origin::RouteEvent::Start(update) + | moq_net::origin::RouteEvent::Update(update) + | moq_net::origin::RouteEvent::Restart(update) + | moq_net::origin::RouteEvent::Takeover { announce: update, .. } => { live |= update.prefix.as_str() == path; } - moq_net::announce::Event::End(update) => { + moq_net::origin::RouteEvent::End(update) => { live &= update.prefix.as_str() != path; } } diff --git a/rs/moq-net/tests/integration/fastest_reader.rs b/rs/moq-net/tests/integration/fastest_reader.rs index df0dce3b030..08bf9ea61fd 100644 --- a/rs/moq-net/tests/integration/fastest_reader.rs +++ b/rs/moq-net/tests/integration/fastest_reader.rs @@ -46,7 +46,7 @@ async fn relay(version: &str) -> Relay { let remote = kio::clock::timeout(TIMEOUT, relay.consume().follow("live", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let subscriber = kio::clock::timeout( TIMEOUT, remote.track("data").unwrap().subscribe( diff --git a/rs/moq-net/tests/integration/fetch_fanout.rs b/rs/moq-net/tests/integration/fetch_fanout.rs index e35e461eb49..8f1eb318557 100644 --- a/rs/moq-net/tests/integration/fetch_fanout.rs +++ b/rs/moq-net/tests/integration/fetch_fanout.rs @@ -44,7 +44,7 @@ async fn sequential_viewers_share_the_relays_fetched_groups() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); viewers.push((viewer, pair, remote)); } for round in 0..3 { diff --git a/rs/moq-net/tests/integration/fetch_from_feed.rs b/rs/moq-net/tests/integration/fetch_from_feed.rs index abfc3f3ab52..66659fbb5cf 100644 --- a/rs/moq-net/tests/integration/fetch_from_feed.rs +++ b/rs/moq-net/tests/integration/fetch_from_feed.rs @@ -49,7 +49,7 @@ async fn relay(version: &str) -> Relay { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); Relay { track, remote, diff --git a/rs/moq-net/tests/integration/fetch_only.rs b/rs/moq-net/tests/integration/fetch_only.rs index 3e38135fae9..84e7842d64c 100644 --- a/rs/moq-net/tests/integration/fetch_only.rs +++ b/rs/moq-net/tests/integration/fetch_only.rs @@ -33,7 +33,7 @@ async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Cons kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() } /// Publish a finished track of three groups, and flag any subscription it ever gets. diff --git a/rs/moq-net/tests/integration/fetch_pipeline.rs b/rs/moq-net/tests/integration/fetch_pipeline.rs index 5cb165927ab..9c32040f15e 100644 --- a/rs/moq-net/tests/integration/fetch_pipeline.rs +++ b/rs/moq-net/tests/integration/fetch_pipeline.rs @@ -68,7 +68,7 @@ async fn fetch_ahead( let remote = kio::clock::timeout(TIMEOUT, upstream.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let fetching = kio::clock::sim::spawn(async move { remote.track("video").unwrap().fetch_group(0, None).await }); let request = kio::clock::timeout(TIMEOUT, dynamic.requested_track()) @@ -156,7 +156,7 @@ async fn first_fetch(version: &str, relays: u64, rtt: Duration) -> Duration { let remote = kio::clock::timeout(TIMEOUT, upstream.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let start = kio::clock::now(); let mut fetched = kio::clock::timeout(TIMEOUT, remote.track("video").unwrap().fetch_group(0, None)) .await diff --git a/rs/moq-net/tests/integration/finished_broadcast_mock.rs b/rs/moq-net/tests/integration/finished_broadcast_mock.rs index 7b963360410..f761ab4fd2f 100644 --- a/rs/moq-net/tests/integration/finished_broadcast_mock.rs +++ b/rs/moq-net/tests/integration/finished_broadcast_mock.rs @@ -53,7 +53,7 @@ async fn round(finish_broadcast: bool) -> (Vec>, Option) let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); // Resolved before the ending starts: a SUBSCRIBE sent alongside its TRACK reaches the // publisher before the subscriber has the TRACK_INFO it accepts the track with. diff --git a/rs/moq-net/tests/integration/finite_relay.rs b/rs/moq-net/tests/integration/finite_relay.rs index 2a0cb226c33..d5213164248 100644 --- a/rs/moq-net/tests/integration/finite_relay.rs +++ b/rs/moq-net/tests/integration/finite_relay.rs @@ -80,7 +80,7 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let (mut heads, mut opened) = futures::channel::mpsc::unbounded(); let reader = kio::clock::sim::spawn(async move { diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index 4be7c5e2239..1c373f5244a 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -395,7 +395,7 @@ async fn goaway_keeps_new_subscribes(version: Version) { .unwrap() .available() .await - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut existing = bc.track("video").unwrap().subscribe(None).await.expect("subscribe"); let mut group = track.append_group().expect("append group"); @@ -507,9 +507,9 @@ async fn goaway_drains_routes(version: Version) { // Nothing else is sent on the announce stream, so this only resolves if the // subscriber acted on the GOAWAY rather than on another message. The drain // re-prices the route in place, which arrives as another active update. - let mut announced = sub.announced(); + let mut announced = sub.routes(); loop { - let (moq_net::announce::Event::Start(update) | moq_net::announce::Event::Update(update)) = + let (moq_net::origin::RouteEvent::Start(update) | moq_net::origin::RouteEvent::Update(update)) = announced.next().await.expect("update") else { continue; diff --git a/rs/moq-net/tests/integration/group_order.rs b/rs/moq-net/tests/integration/group_order.rs index 44ab3e2aa5d..3ff9a1a938d 100644 --- a/rs/moq-net/tests/integration/group_order.rs +++ b/rs/moq-net/tests/integration/group_order.rs @@ -53,7 +53,7 @@ fn read_arrivals(origin: moq_net::origin::Producer, order: Order) -> kio::clock: .unwrap() .available() .await - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(FOREVER)) .with_range(0..) diff --git a/rs/moq-net/tests/integration/history_groups.rs b/rs/moq-net/tests/integration/history_groups.rs index 78c7ac48ab6..c046e835d9f 100644 --- a/rs/moq-net/tests/integration/history_groups.rs +++ b/rs/moq-net/tests/integration/history_groups.rs @@ -75,7 +75,7 @@ async fn round(version: &str, relay: bool, newest_first: bool) -> Vec<(u64, usiz let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let reader = kio::clock::sim::spawn(async move { let subscription = Subscription::default() @@ -219,7 +219,7 @@ async fn a_late_subscriber_receives_the_relays_cached_history() { options.client_subscribe = Some(first.clone()); let first_pair = connect_mock(options).await; let consumer = first.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(FOREVER)) .with_range(0..); @@ -258,7 +258,7 @@ async fn a_late_subscriber_receives_the_relays_cached_history() { options.client_subscribe = Some(late.clone()); let late_pair = connect_mock(options).await; let consumer = late.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); let mut late_sub = remote.track("history").unwrap().subscribe(subscription).await.unwrap(); kio::clock::timeout(TIMEOUT, read_history(&mut late_sub)) .await diff --git a/rs/moq-net/tests/integration/idle_cancel_refetch.rs b/rs/moq-net/tests/integration/idle_cancel_refetch.rs index 7ca37c81c5a..f84eb0a15d1 100644 --- a/rs/moq-net/tests/integration/idle_cancel_refetch.rs +++ b/rs/moq-net/tests/integration/idle_cancel_refetch.rs @@ -43,7 +43,7 @@ async fn a_group_cut_by_an_idle_cancel_is_refetched_whole() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .unwrap() - .unwrap(); + .unwrap().unwrap(); { let mut subscriber = kio::clock::timeout(TIMEOUT, remote.track("audio").unwrap().subscribe(None)) diff --git a/rs/moq-net/tests/integration/instance.rs b/rs/moq-net/tests/integration/instance.rs index d1b3bb6ff7d..1210936a07d 100644 --- a/rs/moq-net/tests/integration/instance.rs +++ b/rs/moq-net/tests/integration/instance.rs @@ -7,7 +7,7 @@ use crate::support; use std::time::Duration; -use moq_net::{Hop, Instance, Version, announce, origin}; +use moq_net::{Hop, Instance, Version, origin}; use support::harness::{MockConnectOptions, MockPair, connect_mock}; fn produce_origin(hop: u64) -> origin::Producer { @@ -24,24 +24,24 @@ async fn link(version: Version, from: &origin::Producer, to: &origin::Producer) } /// The instance of the next route `announced` starts, failing on any other event. -async fn started(announced: &mut announce::Consumer) -> Instance { +async fn started(announced: &mut origin::Routes) -> Instance { match kio::clock::timeout(Duration::from_secs(10), announced.next()) .await .expect("announce hung") .expect("announce ended") { - announce::Event::Start(announce) => announce.route.instance.expect("a delivered route has an instance"), + origin::RouteEvent::Start(announce) => announce.route.instance.expect("a delivered route has an instance"), other => panic!("expected a start, got {other:?}"), } } -async fn ended(announced: &mut announce::Consumer) { +async fn ended(announced: &mut origin::Routes) { match kio::clock::timeout(Duration::from_secs(10), announced.next()) .await .expect("announce hung") .expect("announce ended") { - announce::Event::End(_) => {} + origin::RouteEvent::End(_) => {} other => panic!("expected an end, got {other:?}"), } } @@ -59,7 +59,7 @@ async fn job_reannounced(version: &str) { .publish("job", origin::Route::default().with_instance(instance.clone(), 0)) .unwrap(); let _session = link(version, &publisher, &relay).await; - let mut announced = relay.consume().announced(); + let mut announced = relay.consume().routes(); let first = started(&mut announced).await; job.unannounce(); diff --git a/rs/moq-net/tests/integration/late_lower_group.rs b/rs/moq-net/tests/integration/late_lower_group.rs index 34fb1058b88..d58fad8e92f 100644 --- a/rs/moq-net/tests/integration/late_lower_group.rs +++ b/rs/moq-net/tests/integration/late_lower_group.rs @@ -118,7 +118,7 @@ async fn session(version: &str, relay: bool, start: Option) -> Vec<(u64, us let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(BUDGET)) @@ -235,7 +235,7 @@ async fn merged(version: &str) -> (Vec<(u64, usize)>, Vec<(u64, usize)>) { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let subscribe = |range: Range| { let track = remote.track("late").unwrap(); diff --git a/rs/moq-net/tests/integration/lazy_discovery.rs b/rs/moq-net/tests/integration/lazy_discovery.rs index 811f89b2f31..e6f01ceb0c1 100644 --- a/rs/moq-net/tests/integration/lazy_discovery.rs +++ b/rs/moq-net/tests/integration/lazy_discovery.rs @@ -6,7 +6,7 @@ use std::time::Duration; -use moq_net::{Error, Hop, Pattern, Patterns, Version, announce, origin}; +use moq_net::{Error, Hop, Pattern, Patterns, Version, origin}; use crate::support; use support::harness::{MockConnectOptions, MockPair, connect_mock}; @@ -77,12 +77,12 @@ impl Lazy { } /// Watch everything under `prefix`. - fn watch(&self, prefix: &str) -> announce::Consumer { + fn watch(&self, prefix: &str) -> origin::Routes { self.subscriber .consume() .scope(prefix, &Patterns::from(Pattern::all())) .unwrap() - .announced() + .routes() } /// Inspect the current table without running discovery for the observation itself. @@ -92,16 +92,16 @@ impl Lazy { .consume() .scope("", &Patterns::from(Pattern::literal(path).unwrap())) .unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); matches!( announced.poll_next(&kio::Waiter::noop()), - std::task::Poll::Ready(Some(announce::Event::Start(_))) + std::task::Poll::Ready(Some(origin::RouteEvent::Start(_))) ) } } /// Read until the stream syncs, returning the prefixes it then holds. -async fn synced(announced: &mut announce::Consumer) -> Vec { +async fn synced(announced: &mut origin::Routes) -> Vec { let mut seen = Vec::new(); while !announced.poll_synced(&moq_net::kio::Waiter::noop()).is_ready() { let event = kio::clock::timeout(SETTLE, announced.next()) @@ -109,11 +109,11 @@ async fn synced(announced: &mut announce::Consumer) -> Vec { .expect("synced in time") .expect("the stream stays open"); match event { - announce::Event::Start(announce) - | announce::Event::Restart(announce) - | announce::Event::Takeover { announce, .. } => seen.push(announce.prefix.to_string()), - announce::Event::End(announce) => seen.retain(|prefix| *prefix != announce.prefix.as_str()), - announce::Event::Update(_) => {} + origin::RouteEvent::Start(announce) + | origin::RouteEvent::Restart(announce) + | origin::RouteEvent::Takeover { announce, .. } => seen.push(announce.prefix.to_string()), + origin::RouteEvent::End(announce) => seen.retain(|prefix| *prefix != announce.prefix.as_str()), + origin::RouteEvent::Update(_) => {} } } seen.sort(); @@ -151,7 +151,7 @@ async fn a_new_session_asks_about_existing_watches() { .consume() .scope("b", &Patterns::from(Pattern::all())) .unwrap() - .announced(); + .routes(); let lazy = Lazy::with("moq-lite-07-wip", subscriber).await; assert_eq!(synced(&mut watch).await, ["y"]); assert_eq!(lazy.requests(), 1); @@ -283,12 +283,12 @@ async fn waiting_on_a_path_asks_about_it() { kio::clock::timeout(SETTLE, consumer.follow("a/x", None).unwrap().available()) .await .expect("routed in time") - .unwrap(); + .unwrap().unwrap(); let mut followed = consumer.follow("b/y", None).unwrap(); kio::clock::timeout(SETTLE, followed.available()) .await .expect("announced in time") - .unwrap(); + .unwrap().unwrap(); assert_eq!(lazy.requests(), 2, "{version}"); } } @@ -416,19 +416,19 @@ const IETF: &[&str] = &["moq-transport-18", "moq-transport-22"]; /// Apply what `announced` reports once everything in flight has arrived to `held`, and /// say whether any of it ended a prefix. -async fn settled(announced: &mut announce::Consumer, held: &mut Vec) -> bool { +async fn settled(announced: &mut origin::Routes, held: &mut Vec) -> bool { kio::clock::sleep(SETTLE).await; let mut ended = false; while let Some(event) = announced.try_next() { match event { - announce::Event::Start(announce) - | announce::Event::Restart(announce) - | announce::Event::Takeover { announce, .. } => held.push(announce.prefix.to_string()), - announce::Event::End(announce) => { + origin::RouteEvent::Start(announce) + | origin::RouteEvent::Restart(announce) + | origin::RouteEvent::Takeover { announce, .. } => held.push(announce.prefix.to_string()), + origin::RouteEvent::End(announce) => { ended = true; held.retain(|prefix| *prefix != announce.prefix.as_str()) } - announce::Event::Update(_) => {} + origin::RouteEvent::Update(_) => {} } } held.sort(); @@ -526,7 +526,7 @@ async fn ietf_waiting_on_a_path_asks_about_it() { kio::clock::timeout(SETTLE, consumer.follow("a/x", None).unwrap().available()) .await .expect("routed in time") - .unwrap(); + .unwrap().unwrap(); assert!(!lazy.routes("b/y").await, "{version}"); } } diff --git a/rs/moq-net/tests/integration/mesh_withdraw.rs b/rs/moq-net/tests/integration/mesh_withdraw.rs index e80b8654bdf..03abc03bc84 100644 --- a/rs/moq-net/tests/integration/mesh_withdraw.rs +++ b/rs/moq-net/tests/integration/mesh_withdraw.rs @@ -13,7 +13,7 @@ use std::{collections::HashMap, time::Duration}; use futures::channel::mpsc; -use moq_net::{Hop, Version, announce, cache, origin}; +use moq_net::{Hop, Version, cache, origin}; use support::harness::{MockConnectOptions, MockPair, connect_mock, peer, peer_with_latency}; fn produce_origin(hop: u64) -> origin::Producer { @@ -32,7 +32,7 @@ fn produce(hop: u64, hold: Duration) -> origin::Producer { producer } -/// The kind of an [`announce::Event`] for a prefix. +/// The kind of an [`origin::RouteEvent`] for a prefix. #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Kind { Start, @@ -55,16 +55,16 @@ fn drain(watched: &mut mpsc::UnboundedReceiver<(String, Kind)>) -> HashMap mpsc::UnboundedReceiver<(String, Kind)> { +fn watch(mut announced: origin::Routes) -> mpsc::UnboundedReceiver<(String, Kind)> { let (tx, rx) = mpsc::unbounded(); kio::clock::sim::spawn(async move { while let Some(event) = announced.next().await { let (kind, announce) = match event { - announce::Event::Start(announce) => (Kind::Start, announce), - announce::Event::Update(announce) => (Kind::Update, announce), - announce::Event::Restart(announce) => (Kind::Restart, announce), - announce::Event::Takeover { announce, .. } => (Kind::Takeover, announce), - announce::Event::End(announce) => (Kind::End, announce), + origin::RouteEvent::Start(announce) => (Kind::Start, announce), + origin::RouteEvent::Update(announce) => (Kind::Update, announce), + origin::RouteEvent::Restart(announce) => (Kind::Restart, announce), + origin::RouteEvent::Takeover { announce, .. } => (Kind::Takeover, announce), + origin::RouteEvent::End(announce) => (Kind::End, announce), }; if tx.unbounded_send((announce.prefix.to_string(), kind)).is_err() { break; @@ -89,7 +89,7 @@ impl Mesh { for &(a, b) in edges { pairs.push(peer(version, &nodes[a], &nodes[b]).await); } - let watched = watch(nodes.last().unwrap().consume().announced()); + let watched = watch(nodes.last().unwrap().consume().routes()); Self { nodes, _pairs: pairs, @@ -223,7 +223,7 @@ async fn partial_mesh_withdraw_retracts_once() { for (&(a, b), &ms) in PRODUCTION.iter().zip(PRODUCTION_LATENCY_MS) { pairs.push(peer_with_latency(version, &nodes[a], &nodes[b], Duration::from_millis(ms)).await); } - let mut watched: Vec<_> = nodes.iter().map(|node| watch(node.consume().announced())).collect(); + let mut watched: Vec<_> = nodes.iter().map(|node| watch(node.consume().routes())).collect(); for publisher in [5, 13, 22, 26, 32] { let broadcast = nodes[publisher].create_broadcast(format!("room/{publisher}")).unwrap(); @@ -278,7 +278,7 @@ async fn retracted_relay_ignores_a_stale_path() { for &((a, b), latency) in STALE_PATHS { pairs.push(peer_with_latency(version, &nodes[a], &nodes[b], latency).await); } - let mut watched: Vec<_> = nodes.iter().map(|node| watch(node.consume().announced())).collect(); + let mut watched: Vec<_> = nodes.iter().map(|node| watch(node.consume().routes())).collect(); let broadcast = nodes[7].create_broadcast("room/7").unwrap(); broadcast.announce(Default::default()).unwrap(); @@ -351,8 +351,8 @@ impl Cluster { let mut cluster = Self { _pairs: pairs, publisher: publishing, - client: watch(watching.consume().announced()), - relays: relays.iter().map(|relay| watch(relay.consume().announced())).collect(), + client: watch(watching.consume().routes()), + relays: relays.iter().map(|relay| watch(relay.consume().routes())).collect(), }; // Let every session's announce interest land before anything is published. kio::clock::sim::idle().await; @@ -641,8 +641,8 @@ async fn hop_limit_bounds_receive_and_send() { let sink = produce_origin(3); let _upstream = peer(version, &source, &relay).await; let _downstream = peer(version, &relay, &sink).await; - let mut received = watch(relay.consume().announced()); - let mut sent = watch(sink.consume().announced()); + let mut received = watch(relay.consume().routes()); + let mut sent = watch(sink.consume().routes()); kio::clock::sim::idle().await; let route = |count: u64| { origin::Route::default().with_hops( @@ -706,7 +706,7 @@ async fn hop_limit_falls_back_to_a_forwardable_route() { let _near = peer(version, &near, &relay).await; let _far = peer(version, &far, &relay).await; let _downstream = peer(version, &relay, &sink).await; - let mut sent = watch(sink.consume().announced()); + let mut sent = watch(sink.consume().routes()); kio::clock::sim::idle().await; let route = |first: u64, count: u64, cost: u64| { diff --git a/rs/moq-net/tests/integration/model.rs b/rs/moq-net/tests/integration/model.rs index c4b1050a23e..d77efb0e9a0 100644 --- a/rs/moq-net/tests/integration/model.rs +++ b/rs/moq-net/tests/integration/model.rs @@ -64,7 +64,7 @@ fn follow_resolves_with_only_explicit_polls() { broadcast.announce(origin::Route::default()).unwrap(); assert!(following.poll_available(&waiter).is_pending()); driver.poll(now, &waiter).unwrap(); - let resolved = ready(following.poll_available(&waiter)).unwrap(); + let resolved = ready(following.poll_available(&waiter)).unwrap().unwrap(); assert_eq!(resolved.info().path.as_str(), "room/live"); // A closed origin ends a parked follower. diff --git a/rs/moq-net/tests/integration/multi_cdn.rs b/rs/moq-net/tests/integration/multi_cdn.rs index f2fa393dd3a..9dceb213ee0 100644 --- a/rs/moq-net/tests/integration/multi_cdn.rs +++ b/rs/moq-net/tests/integration/multi_cdn.rs @@ -15,7 +15,7 @@ use crate::support; use std::time::Duration; use futures::{StreamExt, channel::mpsc}; -use moq_net::{Error, Hop, Timestamp, Version, announce, origin, track}; +use moq_net::{Error, Hop, Timestamp, Version, origin, track}; use support::harness::{MockConnectOptions, MockPair, connect_mock}; /// A millisecond track: the frames written here carry timestamps. @@ -127,13 +127,13 @@ async fn next(rx: &mut mpsc::UnboundedReceiver) -> (u64, Option bool { +fn via_a(announce: &origin::RouteEvent) -> bool { let route = match announce { - announce::Event::Start(a) - | announce::Event::Update(a) - | announce::Event::Restart(a) - | announce::Event::Takeover { announce: a, .. } => &a.route, - announce::Event::End(_) => return false, + origin::RouteEvent::Start(a) + | origin::RouteEvent::Update(a) + | origin::RouteEvent::Restart(a) + | origin::RouteEvent::Takeover { announce: a, .. } => &a.route, + origin::RouteEvent::End(_) => return false, }; route.hops.iter().any(|hop| *hop == Hop::new(A).unwrap()) } @@ -275,10 +275,10 @@ fn assert_continuous(seen: &[(u64, Vec, Option)], groups: u64) { async fn fails_over_and_back(secondary: &str) { kio::clock::timeout(TEST_TIMEOUT, async { let mut topology = Topology::new(secondary.parse().unwrap()).await; - let mut announced = topology.subscriber.consume().announced(); + let mut announced = topology.subscriber.consume().routes(); let start = announced.next().await.expect("announced"); assert!( - matches!(start, announce::Event::Start(_)) && via_a(&start), + matches!(start, origin::RouteEvent::Start(_)) && via_a(&start), "the preferred CDN wins over the cheaper one: {start:?}" ); @@ -288,7 +288,7 @@ async fn fails_over_and_back(secondary: &str) { topology.lose_a().await; let update = announced.next().await.expect("announced"); assert!( - matches!(update, announce::Event::Update(_)) && !via_a(&update), + matches!(update, origin::RouteEvent::Update(_)) && !via_a(&update), "same instance over B: {update:?}" ); seen.extend(topology.group_anywhere(&mut rx).await); @@ -296,7 +296,7 @@ async fn fails_over_and_back(secondary: &str) { topology.restore_a().await; let update = announced.next().await.expect("announced"); assert!( - matches!(update, announce::Event::Update(_)) && via_a(&update), + matches!(update, origin::RouteEvent::Update(_)) && via_a(&update), "back on A: {update:?}" ); seen.extend(topology.group_through_a(&mut rx).await); @@ -320,7 +320,7 @@ async fn preferred_cdn_fails_over_and_back() { async fn restarts_across_protocols(secondary: &str) { kio::clock::timeout(TEST_TIMEOUT, async { let mut topology = Topology::new(secondary.parse().unwrap()).await; - let mut announced = topology.subscriber.consume().announced(); + let mut announced = topology.subscriber.consume().routes(); let start = announced.next().await.expect("announced"); assert!(via_a(&start), "{start:?}"); @@ -331,7 +331,7 @@ async fn restarts_across_protocols(secondary: &str) { topology.lose_a().await; let update = announced.next().await.expect("announced"); assert!( - matches!(update, announce::Event::Restart(_)) && !via_a(&update), + matches!(update, origin::RouteEvent::Restart(_)) && !via_a(&update), "another instance over B: {update:?}" ); topology.group(); diff --git a/rs/moq-net/tests/integration/partial_group.rs b/rs/moq-net/tests/integration/partial_group.rs index db8c6266368..4b5ace8c4f3 100644 --- a/rs/moq-net/tests/integration/partial_group.rs +++ b/rs/moq-net/tests/integration/partial_group.rs @@ -44,7 +44,7 @@ async fn round(version: &str) -> Option, moq_net::Error>> { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut live = kio::clock::timeout( TIMEOUT, remote diff --git a/rs/moq-net/tests/integration/quiet_catalog.rs b/rs/moq-net/tests/integration/quiet_catalog.rs index 9855715de07..4ce989b8d5e 100644 --- a/rs/moq-net/tests/integration/quiet_catalog.rs +++ b/rs/moq-net/tests/integration/quiet_catalog.rs @@ -59,7 +59,7 @@ fn publish(origin: &origin::Producer) -> (moq_net::origin::Publication, track::P async fn request(origin: &origin::Producer) -> broadcast::Consumer { let consumer = origin.consume(); - consumer.follow("live", None).unwrap().available().await.unwrap() + consumer.follow("live", None).unwrap().available().await.unwrap().unwrap() } /// Subscribe without a floor and expect the snapshot as group 0. diff --git a/rs/moq-net/tests/integration/range_anchors.rs b/rs/moq-net/tests/integration/range_anchors.rs index 8f3ead08c41..bf3a2c37f6a 100644 --- a/rs/moq-net/tests/integration/range_anchors.rs +++ b/rs/moq-net/tests/integration/range_anchors.rs @@ -73,7 +73,7 @@ async fn read(version: Option<&str>, range: Range) -> Result, Error> { kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() } }; diff --git a/rs/moq-net/tests/integration/range_read.rs b/rs/moq-net/tests/integration/range_read.rs index c1253847722..94eb53749e8 100644 --- a/rs/moq-net/tests/integration/range_read.rs +++ b/rs/moq-net/tests/integration/range_read.rs @@ -95,7 +95,7 @@ async fn fixture( let remote = kio::clock::timeout(TIMEOUT, client.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); (remote, track, (sessions, broadcast, publisher, middle, client)) } diff --git a/rs/moq-net/tests/integration/received_rewind.rs b/rs/moq-net/tests/integration/received_rewind.rs index 4a8002c79b5..4c78b1718f9 100644 --- a/rs/moq-net/tests/integration/received_rewind.rs +++ b/rs/moq-net/tests/integration/received_rewind.rs @@ -75,7 +75,7 @@ async fn relay( let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(BUDGET)) @@ -193,7 +193,7 @@ async fn fetch_only(version: &str) -> Vec, moq let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut got = Vec::new(); for sequence in [1, 0] { diff --git a/rs/moq-net/tests/integration/rejoin.rs b/rs/moq-net/tests/integration/rejoin.rs index 3489d8d98aa..d8bc6ed24d8 100644 --- a/rs/moq-net/tests/integration/rejoin.rs +++ b/rs/moq-net/tests/integration/rejoin.rs @@ -6,7 +6,7 @@ use crate::support; use std::time::Duration; -use moq_net::{Hop, Timestamp, Version, announce, group, track}; +use moq_net::{Hop, Timestamp, Version, group, origin, track}; use support::harness::{MockConnectOptions, connect_mock}; /// A millisecond track: the frames written here carry timestamps. @@ -55,7 +55,7 @@ async fn rejoin_recovers_the_group_reset_on_leave() { let _pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); let prefs = || { @@ -149,7 +149,7 @@ async fn rejoin_skips_a_cache_kept_by_another_handle() { let _pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); // Held for fetches only: it keeps the relay's copy without subscribing. @@ -207,7 +207,7 @@ async fn rejoin_keeps_the_cache_when_the_backlog_lands_newest_first() { let pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); let prefs = || track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(10))); @@ -289,7 +289,7 @@ async fn rejoin_mid_group_keeps_the_head_for_later_readers() { let _downstream = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = sub.recv_group().await.unwrap().unwrap(); assert_eq!(group.read_frame().await.unwrap().unwrap().payload, b"a0".as_ref()); @@ -360,7 +360,7 @@ async fn rejoin_goes_live_without_the_join_head() { let _downstream = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = sub.recv_group().await.unwrap().unwrap(); assert_eq!(group.read_frame().await.unwrap().unwrap().payload, b"a0".as_ref()); @@ -423,7 +423,7 @@ async fn rejoin_during_the_cancel_skips_the_cache() { let _pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); let mut group = track.append_group().unwrap(); @@ -485,7 +485,7 @@ async fn rejoin_waits_for_the_answers_first_frame() { let pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); // Held for fetches only: it keeps the relay's copy without subscribing. @@ -569,7 +569,7 @@ async fn leaving_after_the_cache_window_keeps_the_latest_group() { options.client_subscribe = Some(client.clone()); let pair = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); (remote, pair) } }; @@ -631,7 +631,7 @@ async fn rejoin_keeps_source_timestamps() { let _pair = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); // Far from any arrival time, so a frame stamped on arrival cannot pass. let ts = |ms| Timestamp::from_millis(ms).unwrap(); @@ -733,7 +733,7 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { options.client_subscribe = Some(client.clone()); let pair = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let sub = remote.track("catalog").unwrap().subscribe(None).await.unwrap(); (sub, remote, pair) } @@ -745,9 +745,9 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { let (mut holder, remote, pair) = session(3).await; assert_eq!(holder.recv_group().await.unwrap().unwrap().sequence, 0, "{version}"); // The new connection is cheaper, so the relay reports its route taking over. - let mut follow = relay.consume().announced(); + let mut follow = relay.consume().routes(); assert!( - matches!(follow.next().await, Some(announce::Event::Start(_))), + matches!(follow.next().await, Some(origin::RouteEvent::Start(_))), "{version}" ); let replacement = upstream(1).await; @@ -755,7 +755,7 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { assert!( matches!( event, - Some(announce::Event::Update(_) | announce::Event::Restart(_) | announce::Event::Takeover { .. }) + Some(origin::RouteEvent::Update(_) | origin::RouteEvent::Restart(_) | origin::RouteEvent::Takeover { .. }) ), "{version}: {event:?}" ); diff --git a/rs/moq-net/tests/integration/relay_upstream_close.rs b/rs/moq-net/tests/integration/relay_upstream_close.rs index 2a31afcf065..4adf8886d11 100644 --- a/rs/moq-net/tests/integration/relay_upstream_close.rs +++ b/rs/moq-net/tests/integration/relay_upstream_close.rs @@ -117,7 +117,7 @@ async fn round(name: &str, end: End) -> Vec { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut readers = Vec::new(); for (index, track) in tracks.iter().enumerate() { diff --git a/rs/moq-net/tests/integration/replacement.rs b/rs/moq-net/tests/integration/replacement.rs index 601628ee9b7..15006530fe8 100644 --- a/rs/moq-net/tests/integration/replacement.rs +++ b/rs/moq-net/tests/integration/replacement.rs @@ -14,7 +14,7 @@ use crate::support; use std::time::Duration; -use moq_net::{Error, Hop, Instance, Timestamp, Version, announce, broadcast, origin, track}; +use moq_net::{Error, Hop, Instance, Timestamp, Version, broadcast, origin, track}; use support::harness::{MockConnectOptions, MockPair, connect_mock}; /// A millisecond track: the frames written here carry timestamps. @@ -39,7 +39,7 @@ async fn link(version: Version, from: &origin::Producer, to: &origin::Producer) } /// The next announce event, failing on a hang. -async fn next_event(announced: &mut announce::Consumer) -> announce::Event { +async fn next_event(announced: &mut origin::Routes) -> origin::RouteEvent { kio::clock::timeout(Duration::from_secs(10), announced.next()) .await .expect("announce hung") @@ -90,9 +90,9 @@ async fn replace(version: &str, instance: Option) { let meta = cam.create_track("meta", timed()).unwrap(); let _first = link(version, &publisher, &viewer).await; - let mut announced = viewer.consume().announced(); + let mut announced = viewer.consume().routes(); match next_event(&mut announced).await { - announce::Event::Start(announce) => { + origin::RouteEvent::Start(announce) => { assert_eq!(announce.prefix.as_str(), "cam"); let carried = announce.route.instance.as_ref().expect("every route has an instance"); assert_eq!(carried.is_minted(), !carries, "{version}: minted {carried}"); @@ -131,7 +131,7 @@ async fn replace(version: &str, instance: Option) { // A minted instance makes the replacement a restart, delivered at once, and the old // handle refuses new requests from then on. match announced.try_next() { - Some(announce::Event::Restart(announce)) => assert_eq!(announce.prefix.as_str(), "cam"), + Some(origin::RouteEvent::Restart(announce)) => assert_eq!(announce.prefix.as_str(), "cam"), other => panic!("{version}: expected the restart, got {other:?}"), } let Err(err) = subscribe(&old, "meta").await else { @@ -199,7 +199,7 @@ async fn route_death(version: &str, relayed: bool, wait: Duration) { true => Some(link(version, &relay, &viewer).await), false => None, }; - let mut announced = viewer.consume().announced(); + let mut announced = viewer.consume().routes(); next_event(&mut announced).await; let old = viewer.consume().request("cam", None).await.unwrap(); @@ -276,7 +276,7 @@ async fn restart_while_the_old_session_lingers(version: &str, old_hop: u64, new_ let old_cam = old.publish("cam", origin::Route::default()).unwrap(); let _old_video = old_cam.create_track("video", timed()).unwrap(); let old_session = link(version, &old, &viewer).await; - let mut announced = viewer.consume().announced(); + let mut announced = viewer.consume().routes(); next_event(&mut announced).await; // The old process dies without a close: its session falls silent. diff --git a/rs/moq-net/tests/integration/request_caps.rs b/rs/moq-net/tests/integration/request_caps.rs index 165552593fa..52b98e96210 100644 --- a/rs/moq-net/tests/integration/request_caps.rs +++ b/rs/moq-net/tests/integration/request_caps.rs @@ -78,7 +78,7 @@ async fn closed_requests_are_granted_back() { ) .await .expect("announce timeout") - .unwrap(); + .unwrap().unwrap(); for round in 0..ROUNDS { let track = broadcast.track(&format!("t{round}")).unwrap(); @@ -128,7 +128,7 @@ async fn flow_control_bounds_the_subscriptions_a_peer_holds() { let remote = kio::clock::timeout(TIMEOUT, client.consume().follow("bcast", None).unwrap().available()) .await .expect("announce timeout") - .unwrap(); + .unwrap().unwrap(); let subscribing: Vec<_> = (0..TRACKS) .map(|i| { let track = remote.track(&format!("t{i}")).unwrap(); diff --git a/rs/moq-net/tests/integration/route_change.rs b/rs/moq-net/tests/integration/route_change.rs index 8b60195802b..5b0b3ae8b21 100644 --- a/rs/moq-net/tests/integration/route_change.rs +++ b/rs/moq-net/tests/integration/route_change.rs @@ -22,7 +22,7 @@ use std::collections::BTreeMap; use std::time::Duration; use futures::{StreamExt, channel::mpsc}; -use moq_net::{Error, Hop, Timestamp, Version, announce, origin, track}; +use moq_net::{Error, Hop, Timestamp, Version, origin, track}; use support::harness::{MockConnectOptions, MockPair, connect_mock}; /// A millisecond track: the frames written here carry timestamps. @@ -129,7 +129,7 @@ impl Topology { let a_to_r = link(version, &relay_a, &subscriber).await; let consumer = subscriber.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let sub = remote.track("video").unwrap().subscribe(prefs).await.unwrap(); @@ -382,9 +382,9 @@ async fn better_route_restarts(version: &str) { let mut rx = read(sub); topology.standby().await; let consumer = topology.subscriber.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); match announced.next().await.expect("announced") { - announce::Event::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected the route, got {other:?}"), } @@ -395,7 +395,7 @@ async fn better_route_restarts(version: &str) { topology.trigger(Trigger::BetterRoute).await; match announced.next().await.expect("announced") { - announce::Event::Restart(announce) => { + origin::RouteEvent::Restart(announce) => { assert_eq!(announce.prefix.as_str(), "live"); assert_eq!(announce.route.hops.len(), 1, "{version}: the direct route"); } @@ -530,7 +530,7 @@ async fn lagging_route_dies(version: Version) { } async fn subscribe(origin: &origin::Producer) -> track::Subscriber { let consumer = origin.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let preferences = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); remote.track("video").unwrap().subscribe(preferences).await.unwrap() @@ -647,7 +647,7 @@ async fn undetected_outage(budget: Duration) -> BTreeMap> { let m1_e = link(version, &m1, &e).await; let consumer = e.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(budget)); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); let m2_e = priced_link(version, &m2, &e, Some(1_000)).await; @@ -789,7 +789,7 @@ async fn redundant_pair_follows_the_next_instance(version: &str, loss: Loss) { settle().await; let mut follow = subscriber.consume().follow("live", None).unwrap(); - let first = follow.available().await.unwrap(); + let first = follow.available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let mut rx = read(first.track("video").unwrap().subscribe(prefs.clone()).await.unwrap()); let write = |replicas: &mut Vec, sequence: u64| { @@ -826,7 +826,7 @@ async fn redundant_pair_follows_the_next_instance(version: &str, loss: Loss) { drop(broadcast); settle().await; - let second = follow.available().await.unwrap(); + let second = follow.available().await.unwrap().unwrap(); assert!( !second.is_clone(&first), "{version} {loss:?}: handed out the old broadcast" @@ -902,7 +902,7 @@ async fn replaced_behind_a_relay(version: &str) { let _r_to_d = link(version, &relay, &downstream).await; let consumer = downstream.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); @@ -999,7 +999,7 @@ async fn compression_changes_behind_a_relay(compress: bool) { let _r_to_d = link(version, &relay, &downstream).await; let consumer = downstream.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); @@ -1093,7 +1093,7 @@ async fn producer_replaced(version: &str) { let _a_to_r = link(version, &relay, &subscriber).await; let consumer = subscriber.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let sub = remote.track("video").unwrap().subscribe(prefs).await.unwrap(); let mut rx = read(sub); diff --git a/rs/moq-net/tests/integration/route_health.rs b/rs/moq-net/tests/integration/route_health.rs index 38c0cb976f7..d4a11d010c6 100644 --- a/rs/moq-net/tests/integration/route_health.rs +++ b/rs/moq-net/tests/integration/route_health.rs @@ -65,7 +65,7 @@ async fn silent_kill(budget: Duration, detect: Duration) -> Vec { let m1_e = link(version, &m1, &e).await; let consumer = e.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(budget)); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); let m2_e = priced_link(version, &m2, &e, Some(1_000)).await; @@ -204,7 +204,7 @@ async fn payload_stall(stall: Stall, span: Duration) -> (Observed, Observed) { async fn subscribe(origin: &origin::Producer) -> track::Subscriber { let consumer = origin.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(2))); remote.track("video").unwrap().subscribe(prefs).await.unwrap() } diff --git a/rs/moq-net/tests/integration/segmented_frame.rs b/rs/moq-net/tests/integration/segmented_frame.rs index c87d4c7db06..10fbe48354a 100644 --- a/rs/moq-net/tests/integration/segmented_frame.rs +++ b/rs/moq-net/tests/integration/segmented_frame.rs @@ -43,7 +43,7 @@ async fn a_segmented_frame_crosses_whole() { let remote = kio::clock::timeout(TIMEOUT, viewer.consume().follow("room", None).unwrap().available()) .await .expect("broadcast timeout") - .unwrap(); + .unwrap().unwrap(); let mut sub = remote.track("file").unwrap().subscribe(None).await.unwrap(); subscribed(&track).await; diff --git a/rs/moq-net/tests/integration/session_close.rs b/rs/moq-net/tests/integration/session_close.rs index 087dbe604b2..bc385d80007 100644 --- a/rs/moq-net/tests/integration/session_close.rs +++ b/rs/moq-net/tests/integration/session_close.rs @@ -57,7 +57,7 @@ async fn setup_with_gate(version: &str, gate: Option>) -> Se let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); // The publisher only learns of a subscription once the subscriber polls it. let (ready, active) = futures::channel::oneshot::channel(); @@ -113,7 +113,7 @@ async fn track_info_interest_precedes_a_subscription() { options.client_subscribe = Some(subscriber.clone()); let _pair = connect_mock(options).await; let consumer = subscriber.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); let copy = remote.track("video").unwrap(); copy.info().await.expect("TRACK_INFO"); crate::support::wanted(track.demand()) diff --git a/rs/moq-net/tests/integration/session_idle.rs b/rs/moq-net/tests/integration/session_idle.rs index 542d7bde485..252e73331ea 100644 --- a/rs/moq-net/tests/integration/session_idle.rs +++ b/rs/moq-net/tests/integration/session_idle.rs @@ -52,7 +52,7 @@ async fn setup(version: &str) -> Setup { let remote = kio::clock::timeout(TIMEOUT, subscriber.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); Setup { pair, diff --git a/rs/moq-net/tests/integration/session_panic.rs b/rs/moq-net/tests/integration/session_panic.rs index 9f0f34dbec5..ecd374fb214 100644 --- a/rs/moq-net/tests/integration/session_panic.rs +++ b/rs/moq-net/tests/integration/session_panic.rs @@ -13,7 +13,7 @@ use crate::support; use std::time::Duration; -use moq_net::{Client, Hop, Server, Session, Version, announce, origin}; +use moq_net::{Client, Hop, Server, Session, Version, origin}; use support::harness::{now, spawn}; use support::mock::{MockSession, create_mock_session_pair}; @@ -77,15 +77,15 @@ async fn publish(version: Version, relay: &origin::Producer, hop: u64, name: &st } /// Wait until `path` is announced (`true`) or withdrawn (`false`) on `announced`. -async fn until(announced: &mut announce::Consumer, path: &str, active: bool) { +async fn until(announced: &mut origin::Routes, path: &str, active: bool) { let wait = async { loop { let (announce, now_active) = match announced.next().await.expect("origin closed") { - announce::Event::Start(announce) - | announce::Event::Update(announce) - | announce::Event::Restart(announce) - | announce::Event::Takeover { announce, .. } => (announce, true), - announce::Event::End(announce) => (announce, false), + origin::RouteEvent::Start(announce) + | origin::RouteEvent::Update(announce) + | origin::RouteEvent::Restart(announce) + | origin::RouteEvent::Takeover { announce, .. } => (announce, true), + origin::RouteEvent::End(announce) => (announce, false), }; if announce.prefix.as_str() == path && now_active == active { return; @@ -102,7 +102,7 @@ async fn a_panicking_session_leaves_the_others_serving() { for version in ["moq-lite-07-wip", "moq-transport-22"] { let version: Version = version.parse().unwrap(); let relay = produce_origin(100); - let mut announced = relay.consume().announced(); + let mut announced = relay.consume().routes(); let broken = publish(version, &relay, 1, "broken").await; until(&mut announced, "broken", true).await; diff --git a/rs/moq-net/tests/integration/source_errors.rs b/rs/moq-net/tests/integration/source_errors.rs index 5aecf07e94d..abcda3025dc 100644 --- a/rs/moq-net/tests/integration/source_errors.rs +++ b/rs/moq-net/tests/integration/source_errors.rs @@ -43,7 +43,7 @@ async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Cons kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() } async fn relayed(version: &str) -> Relayed { diff --git a/rs/moq-net/tests/integration/stream_credit.rs b/rs/moq-net/tests/integration/stream_credit.rs index 4e6443fad9f..7623ca23c82 100644 --- a/rs/moq-net/tests/integration/stream_credit.rs +++ b/rs/moq-net/tests/integration/stream_credit.rs @@ -40,7 +40,7 @@ async fn one_stream_credit_serves_every_backlogged_group() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(30))); let mut subscribers = Vec::new(); diff --git a/rs/moq-net/tests/integration/subscribe_priority.rs b/rs/moq-net/tests/integration/subscribe_priority.rs index e71b5e77ade..cd070b75d40 100644 --- a/rs/moq-net/tests/integration/subscribe_priority.rs +++ b/rs/moq-net/tests/integration/subscribe_priority.rs @@ -68,7 +68,7 @@ async fn follows(version: Version, relay: bool) -> Result<(), String> { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let subscribe = |priority: i8| { let track = remote.track("video").unwrap(); async move { diff --git a/rs/moq-net/tests/integration/subscribe_ranges.rs b/rs/moq-net/tests/integration/subscribe_ranges.rs index ed5b2d73e9c..1330c6d6aae 100644 --- a/rs/moq-net/tests/integration/subscribe_ranges.rs +++ b/rs/moq-net/tests/integration/subscribe_ranges.rs @@ -95,7 +95,7 @@ async fn ahead_then_live(version: Option<&str>, relay: bool) -> (Vec, Vec Rang options.client_subscribe = Some(subscriber.clone()); sessions.push(connect_mock(options).await); let consumer = subscriber.consume(); - let remote = consumer.follow("ranges", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("ranges", None).unwrap().available().await.unwrap().unwrap(); RangeFixture { track, remote, @@ -763,7 +763,7 @@ async fn a_covered_bounded_subscription_ends_on_lite07() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let bounded = |range: std::ops::Range| { Subscription::default() diff --git a/rs/moq-net/tests/integration/subscribe_tracks.rs b/rs/moq-net/tests/integration/subscribe_tracks.rs index 821c21b6f10..4065f8e513c 100644 --- a/rs/moq-net/tests/integration/subscribe_tracks.rs +++ b/rs/moq-net/tests/integration/subscribe_tracks.rs @@ -63,7 +63,7 @@ async fn setup(version: Version) -> Setup { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let (tx, frames) = futures::channel::mpsc::unbounded(); kio::clock::sim::spawn(async move { diff --git a/rs/moq-net/tests/integration/subscribe_with_track.rs b/rs/moq-net/tests/integration/subscribe_with_track.rs index 8e1eeea42c5..30fc1207066 100644 --- a/rs/moq-net/tests/integration/subscribe_with_track.rs +++ b/rs/moq-net/tests/integration/subscribe_with_track.rs @@ -79,7 +79,7 @@ async fn first_frame(version: &str, relays: usize, arrival: Arrival) -> Duration broadcast.announce(Default::default()).unwrap(); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); if !matches!(arrival, Arrival::Together) { reader.hold_bidis(); diff --git a/rs/moq-net/tests/integration/subscriber_max_age.rs b/rs/moq-net/tests/integration/subscriber_max_age.rs index 35b83a339f0..9bd9680b88d 100644 --- a/rs/moq-net/tests/integration/subscriber_max_age.rs +++ b/rs/moq-net/tests/integration/subscriber_max_age.rs @@ -51,7 +51,7 @@ async fn relay_forwards_the_most_tolerant_subscriber_max_age() { group.finish().unwrap(); broadcast.announce(Default::default()).unwrap(); let consumer = viewer.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let cache = remote.track("catalog").unwrap(); let prefs = |millis| { track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_millis(millis))) @@ -126,7 +126,7 @@ async fn relay_forwards_the_smallest_stated_min_delay() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); remote.track("catalog").unwrap() } }; diff --git a/rs/moq-net/tests/integration/subscription_end_integrity.rs b/rs/moq-net/tests/integration/subscription_end_integrity.rs index dcf562285b4..f1e80dd950c 100644 --- a/rs/moq-net/tests/integration/subscription_end_integrity.rs +++ b/rs/moq-net/tests/integration/subscription_end_integrity.rs @@ -70,7 +70,7 @@ async fn round(drop_session: bool) -> (Vec>, Option) { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); // The publisher only learns of a subscription once the subscriber polls it, so the // reader runs concurrently. It reports the head group drained, then waits to be told @@ -229,7 +229,7 @@ async fn killed(version: &str, kill: Kill) -> (Option, Option moq_net::Error { .unwrap() .available() .await - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut fetching = kio::clock::sim::spawn(async move { remote.track("video").unwrap().fetch_group(0, None).await }); let request = dynamic.requested_track().await.expect("the track request arrives"); diff --git a/rs/moq-net/tests/integration/support/harness.rs b/rs/moq-net/tests/integration/support/harness.rs index bcfb15d6d45..8d51ff64a37 100644 --- a/rs/moq-net/tests/integration/support/harness.rs +++ b/rs/moq-net/tests/integration/support/harness.rs @@ -145,7 +145,7 @@ pub struct MockPair { /// The server's end of the mock transport, for steering delivery. pub server_transport: MockSession, /// See [`MockConnectOptions::client_discovers_all`]. - pub client_discovery: Option, + pub client_discovery: Option, } /// Run the MoQ handshake over the mock transport, returning connected sessions. @@ -183,7 +183,7 @@ pub async fn connect_mock(opts: MockConnectOptions) -> MockPair { .client_subscribe .as_ref() .filter(|_| opts.client_discovers_all) - .map(|subscribe| subscribe.consume().announced()); + .map(|subscribe| subscribe.consume().routes()); if let Some(subscribe) = opts.client_subscribe { client = client.with_subscriber(subscribe); } diff --git a/rs/moq-net/tests/integration/support/mod.rs b/rs/moq-net/tests/integration/support/mod.rs index 0bd52c80366..4685a685580 100644 --- a/rs/moq-net/tests/integration/support/mod.rs +++ b/rs/moq-net/tests/integration/support/mod.rs @@ -3,7 +3,7 @@ pub mod harness; pub mod mock; -use moq_net::{announce, goaway, origin, track}; +use moq_net::{goaway, origin, track}; /// Wait until anyone wants the track, returning the group they want. #[allow(dead_code, reason = "shared by several test binaries, each using only part of it")] @@ -25,12 +25,12 @@ pub async fn unwanted(mut demand: track::Demand) -> moq_net::Result<()> { /// Wait until `consumer` sees a route announced at exactly `path`, and return it. #[allow(dead_code, reason = "shared by several test binaries, each using only part of it")] pub async fn announced(consumer: &origin::Consumer, path: &str) -> origin::Route { - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); loop { match announced.next().await.expect("the origin closed") { - announce::Event::Start(announce) - | announce::Event::Update(announce) - | announce::Event::Restart(announce) + origin::RouteEvent::Start(announce) + | origin::RouteEvent::Update(announce) + | origin::RouteEvent::Restart(announce) if announce.prefix.as_str() == path => { return announce.route; diff --git a/rs/moq-net/tests/integration/synced.rs b/rs/moq-net/tests/integration/synced.rs index e623627de9c..2394a2de908 100644 --- a/rs/moq-net/tests/integration/synced.rs +++ b/rs/moq-net/tests/integration/synced.rs @@ -7,7 +7,7 @@ use std::collections::BTreeSet; use std::time::Duration; -use moq_net::{Hop, Version, announce, origin}; +use moq_net::{Hop, Version, origin}; use crate::support; use support::harness::{MockConnectOptions, connect_mock}; @@ -22,7 +22,7 @@ fn produce_origin(hop: u64) -> origin::Producer { } /// Read events until the consumer syncs, returning the prefixes then announced. -async fn read_until_synced(announced: &mut announce::Consumer) -> BTreeSet { +async fn read_until_synced(announced: &mut origin::Routes) -> BTreeSet { let mut seen = BTreeSet::new(); while !announced.poll_synced(&moq_net::kio::Waiter::noop()).is_ready() { let event = kio::clock::timeout(SETTLE, announced.next()) @@ -30,15 +30,15 @@ async fn read_until_synced(announced: &mut announce::Consumer) -> BTreeSet { + origin::RouteEvent::Start(announce) + | origin::RouteEvent::Restart(announce) + | origin::RouteEvent::Takeover { announce, .. } => { seen.insert(announce.prefix.to_string()); } - announce::Event::End(announce) => { + origin::RouteEvent::End(announce) => { seen.remove(announce.prefix.as_str()); } - announce::Event::Update(_) => {} + origin::RouteEvent::Update(_) => {} } } seen @@ -59,7 +59,7 @@ async fn synced(version: &str) -> BTreeSet { options.client_subscribe = Some(subscriber.clone()); let _pair = connect_mock(options).await; - let mut announced = subscriber.consume().announced(); + let mut announced = subscriber.consume().routes(); read_until_synced(&mut announced).await } @@ -105,7 +105,7 @@ async fn a_second_session_catches_up() { connect_mock(options) }; let first = connect().await; - let mut announced = subscriber.consume().announced(); + let mut announced = subscriber.consume().routes(); assert_eq!( read_until_synced(&mut announced).await, ["a"].into_iter().map(String::from).collect() @@ -128,7 +128,7 @@ async fn a_cold_relay_syncs_then_forwards_upstream_routes_as_live() { downstream.server_publish = Some(relay.consume()); downstream.client_subscribe = Some(subscriber.clone()); let _downstream = connect_mock(downstream).await; - let mut announced = subscriber.consume().announced(); + let mut announced = subscriber.consume().routes(); moq_net::kio::wait(|waiter| announced.poll_synced(waiter)).await; assert!(announced.try_next().is_none()); @@ -140,6 +140,6 @@ async fn a_cold_relay_syncs_then_forwards_upstream_routes_as_live() { options.client_subscribe = Some(relay.clone()); let _upstream = connect_mock(options).await; let event = announced.next().await.unwrap(); - assert!(matches!(event, announce::Event::Start(route) if route.prefix.as_str() == "room/cam")); + assert!(matches!(event, origin::RouteEvent::Start(route) if route.prefix.as_str() == "room/cam")); assert!(announced.poll_synced(&moq_net::kio::Waiter::noop()).is_ready()); } diff --git a/rs/moq-net/tests/integration/track_abort_over_session.rs b/rs/moq-net/tests/integration/track_abort_over_session.rs index 538a9afa8fc..511cb79ce31 100644 --- a/rs/moq-net/tests/integration/track_abort_over_session.rs +++ b/rs/moq-net/tests/integration/track_abort_over_session.rs @@ -38,7 +38,7 @@ async fn after_abort(version: &str, hops: u32) { options.client_subscribe = Some(far.clone()); let _pair2 = connect_mock(options).await; let consumer = if hops == 2 { far.consume() } else { relay.consume() }; - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); let mut open = track.append_group().unwrap(); open.write_frame(Timestamp::ZERO, b"head".as_ref()).unwrap(); diff --git a/rs/moq-net/tests/integration/track_info_cancel.rs b/rs/moq-net/tests/integration/track_info_cancel.rs index 250c8fa4cf9..d8453416680 100644 --- a/rs/moq-net/tests/integration/track_info_cancel.rs +++ b/rs/moq-net/tests/integration/track_info_cancel.rs @@ -87,7 +87,7 @@ async fn withdrawn_broadcast_releases_track_info(version: &str, answered: bool, .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut query = remote.track("video").unwrap().info(); let request = match futures::future::select(std::pin::pin!(dynamic.requested_track()), &mut query).await { futures::future::Either::Left((request, _)) => request.expect("TRACK reaches the publisher"), diff --git a/rs/moq-net/tests/integration/track_stream_demand.rs b/rs/moq-net/tests/integration/track_stream_demand.rs index 4af2c4c0143..733f2a23af7 100644 --- a/rs/moq-net/tests/integration/track_stream_demand.rs +++ b/rs/moq-net/tests/integration/track_stream_demand.rs @@ -103,7 +103,7 @@ async fn one_used_edge(version: &str, relays: usize, reorder: bool) { }); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); let subscribing = remote.track("video").unwrap().subscribe(None); if reorder { @@ -190,7 +190,7 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { }); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); let handle = remote.track("video").unwrap(); kio::clock::sleep(Duration::from_secs(1)).await; diff --git a/rs/moq-net/tests/integration/track_tail.rs b/rs/moq-net/tests/integration/track_tail.rs index 1cc939befb3..d7835182cda 100644 --- a/rs/moq-net/tests/integration/track_tail.rs +++ b/rs/moq-net/tests/integration/track_tail.rs @@ -94,7 +94,7 @@ async fn connect(version: &str) -> Pair { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); Pair { pair, diff --git a/rs/moq-net/tests/integration/tracks.rs b/rs/moq-net/tests/integration/tracks.rs index 1f1b34fa060..f7a92d02459 100644 --- a/rs/moq-net/tests/integration/tracks.rs +++ b/rs/moq-net/tests/integration/tracks.rs @@ -56,7 +56,7 @@ async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Cons kio::clock::timeout(TIMEOUT, origin.consume().follow("bcast", None).unwrap().available()) .await .expect("announce timeout") - .expect("routed") + .expect("routed").unwrap() } /// A session syncs at once, then lists the peer's tracks and their changes until the diff --git a/rs/moq-net/tests/integration/tracks_ietf.rs b/rs/moq-net/tests/integration/tracks_ietf.rs index 6d437b3f8e8..22b99a1db5d 100644 --- a/rs/moq-net/tests/integration/tracks_ietf.rs +++ b/rs/moq-net/tests/integration/tracks_ietf.rs @@ -61,7 +61,7 @@ async fn resolve(origin: &moq_net::origin::Producer, path: &str) -> moq_net::bro kio::clock::timeout(TIMEOUT, origin.consume().follow(path, None).unwrap().available()) .await .expect("announce timeout") - .expect("routed") + .expect("routed").unwrap() } /// How many request streams of `kind` the client has opened. diff --git a/rs/moq-net/tests/integration/unannounce_release.rs b/rs/moq-net/tests/integration/unannounce_release.rs index bd660de8e49..d64e539d61e 100644 --- a/rs/moq-net/tests/integration/unannounce_release.rs +++ b/rs/moq-net/tests/integration/unannounce_release.rs @@ -33,7 +33,7 @@ async fn release(version: Version) { .unwrap() .available() .await - .expect("resolves"); + .expect("resolves").unwrap(); let sub = remote.track("t").unwrap().subscribe(None).await.expect("subscribes"); crate::support::wanted(track.demand()).await.unwrap(); diff --git a/rs/moq-net/tests/integration/warm_backfill.rs b/rs/moq-net/tests/integration/warm_backfill.rs index 2c5f2c7251e..6d2a8b67424 100644 --- a/rs/moq-net/tests/integration/warm_backfill.rs +++ b/rs/moq-net/tests/integration/warm_backfill.rs @@ -36,7 +36,7 @@ fn origin(hop: u64) -> origin::Producer { async fn subscribe(relay: &origin::Producer) -> track::Subscriber { let consumer = relay.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); remote .track("video") .unwrap() diff --git a/rs/moq-net/tests/integration/wide_sequence.rs b/rs/moq-net/tests/integration/wide_sequence.rs index 3dfb14cd918..860aaab6736 100644 --- a/rs/moq-net/tests/integration/wide_sequence.rs +++ b/rs/moq-net/tests/integration/wide_sequence.rs @@ -41,7 +41,7 @@ async fn largest_quic_sequence_reaches_the_subscriber() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut sub = remote.track("data").unwrap().subscribe(None).await.unwrap(); for sequence in [5, 1 << 32, (1 << 53) - 1, (1 << 53) + 1, (1 << 62) - 1] { // Timestamps stop at 2^61 - 1, the most lite-05/06 can zigzag as a first frame. @@ -111,12 +111,12 @@ async fn wide_sequence_fails_only_its_subscription() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut sub = cached.track("wide").unwrap().subscribe(None).await.unwrap(); assert_eq!(sub.recv_group().await.unwrap().unwrap().sequence, WIDE); let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let result = kio::clock::timeout(Duration::from_secs(5), async { let mut sub = remote.track("wide").unwrap().subscribe(None).await?; @@ -165,7 +165,7 @@ async fn a_later_wide_group_fails_only_that_subscription() { let _downstream = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); let mut sub = remote.track("wide").unwrap().subscribe(None).await.unwrap(); let mut group = sub.recv_group().await.unwrap().unwrap(); diff --git a/rs/moq-net/tests/integration/widened_max_age.rs b/rs/moq-net/tests/integration/widened_max_age.rs index 243ac580130..e37c37de68d 100644 --- a/rs/moq-net/tests/integration/widened_max_age.rs +++ b/rs/moq-net/tests/integration/widened_max_age.rs @@ -110,7 +110,7 @@ impl Chain { /// Subscribe from the viewer with `budget`, reading from the oldest group still around. async fn subscribe(&self, budget: Duration) -> track::Subscriber { let consumer = self.viewer.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(budget)) .with_ranges([Range::oldest()]); @@ -318,7 +318,7 @@ async fn wider_newcomers_after_the_first_pull_nothing_upstream() { let viewer = origin(3); links.push(peer(version, &relay, &viewer).await); let consumer = viewer.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(budget)) .with_ranges([Range::oldest()]); diff --git a/rs/moq-net/tests/integration/zero_copy.rs b/rs/moq-net/tests/integration/zero_copy.rs index b8888660444..310c0c06d54 100644 --- a/rs/moq-net/tests/integration/zero_copy.rs +++ b/rs/moq-net/tests/integration/zero_copy.rs @@ -63,7 +63,7 @@ async fn frames_cross_without_a_copy() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.expect("subscribe"); subscribed(&track).await; diff --git a/rs/moq-net/tests/send.rs b/rs/moq-net/tests/send.rs index b96177ff106..f0fa6daae6f 100644 --- a/rs/moq-net/tests/send.rs +++ b/rs/moq-net/tests/send.rs @@ -3,7 +3,7 @@ fn require_send(_: impl Send) {} -async fn watch_announcements(mut consumer: moq_net::announce::Consumer) { +async fn watch_announcements(mut consumer: moq_net::origin::Routes) { while let Some(event) = consumer.next().await { drop(event); } @@ -23,7 +23,7 @@ async fn read_frames(mut consumer: moq_net::group::Consumer) { #[test] fn announcement_next_is_send() { - let _: fn(moq_net::announce::Consumer) = |consumer| { + let _: fn(moq_net::origin::Routes) = |consumer| { require_send(watch_announcements(consumer)); }; } diff --git a/rs/moq-relay/benches/session.rs b/rs/moq-relay/benches/session.rs index 7e3a9ed4220..8ec8bc61c32 100644 --- a/rs/moq-relay/benches/session.rs +++ b/rs/moq-relay/benches/session.rs @@ -95,7 +95,7 @@ impl Backend for Relay { .client_subscribe .as_ref() .filter(|_| options.client_discovers_all) - .map(|origin| origin.consume().announced()); + .map(|origin| origin.consume().routes()); let mut client = moq_net::Client::new() .with_versions(version.into()) .with_extensions(options.client_extensions); diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 69212a577eb..e0f3c6cb764 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -2505,7 +2505,7 @@ mod tests { false => cluster.scope(lease, &request), } .expect("admitted"); - let mut announced = admitted.subscriber.expect("subscribe grant").announced(); + let mut announced = admitted.subscriber.expect("subscribe grant").routes(); let mut seen = Vec::new(); while let Some(route) = try_next_announced(&mut announced) { seen.push(route.prefix.to_string()); @@ -2523,20 +2523,20 @@ mod tests { /// The next route and whether it is active. #[cfg(feature = "cluster-lan")] - async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { + async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } /// The next announcement without blocking. - fn try_next_announced(announced: &mut moq_net::announce::Consumer) -> Option { + fn try_next_announced(announced: &mut moq_net::origin::Routes) -> Option { match announced.try_next()? { - moq_net::announce::Event::Start(route) => Some(route), + moq_net::origin::RouteEvent::Start(route) => Some(route), other => panic!("expected an announcement: got {other:?}"), } } @@ -2627,7 +2627,7 @@ mod tests { ) .await .expect("stats broadcast announced within 5s") - .expect("stats broadcast resolves"); + .expect("stats broadcast resolves").unwrap(); assert!(broadcast.info().instance.is_some(), "stats announce under an instance"); // Several publish intervals (1s each by default) after the handle went out @@ -3282,7 +3282,7 @@ mod tests { ) .await .expect("stats announced") - .expect("stats present"); + .expect("stats present").unwrap(); } /// The reserved `cluster.id` 0 is rejected, since it cannot be excluded for loop @@ -3774,7 +3774,7 @@ mod tests { }; let _dial = fingerprint.dial_lan_target(&target).expect("dial"); - let mut announced = fingerprint.origin.consume().announced(); + let mut announced = fingerprint.origin.consume().routes(); let (update, _) = kio::clock::timeout(TIMEOUT, next_update(&mut announced)) .await .expect("timed out waiting for from-node") @@ -3785,7 +3785,7 @@ mod tests { let _from_fp = fingerprint.origin.create_broadcast("from-fingerprint").expect("create"); _from_fp.announce(Default::default()).expect("announce"); - let mut announced = node.origin.consume().announced(); + let mut announced = node.origin.consume().routes(); loop { let (update, _) = kio::clock::timeout(TIMEOUT, next_update(&mut announced)) .await @@ -3799,7 +3799,7 @@ mod tests { } // Each relay's local view holds only what it ingested itself. - let mut local = node.origin.consume().local().announced(); + let mut local = node.origin.consume().local().routes(); let update = try_next_announced(&mut local).expect("from-node is local"); assert_eq!(update.prefix.as_str(), "from-node"); assert_eq!(update.route.source(), origin::Source::Local); @@ -4091,7 +4091,7 @@ mod tests { .await .expect("dialer task"); - let mut announced = node.origin.consume().announced(); + let mut announced = node.origin.consume().routes(); loop { let (update, active) = kio::clock::timeout(TIMEOUT, next_update(&mut announced)) .await @@ -4139,14 +4139,14 @@ mod tests { .expect("peer") .publish("forwarded", Default::default()); - let mut announced = cluster.origin.consume().announced(); + let mut announced = cluster.origin.consume().routes(); let forwarded = try_next_announced(&mut announced).expect("forwarded"); assert_eq!(forwarded.prefix.as_str(), "forwarded"); assert!(matches!(forwarded.route.source(), origin::Source::Peer(_))); let ingest = try_next_announced(&mut announced).expect("ingest"); assert_eq!(ingest.route.source(), origin::Source::Local); - let mut local = cluster.origin.consume().local().announced(); + let mut local = cluster.origin.consume().local().routes(); assert_eq!( try_next_announced(&mut local).expect("ingest").prefix.as_str(), "ingest" @@ -4181,14 +4181,14 @@ mod tests { .expect("core") .publish("core", Default::default()); - let mut everyone = cluster.subscriber(&client).expect("client").consume().announced(); + let mut everyone = cluster.subscriber(&client).expect("client").consume().routes(); let mut prefixes = std::iter::from_fn(|| try_next_announced(&mut everyone)) .map(|announce| announce.prefix.to_string()) .collect::>(); prefixes.sort(); assert_eq!(prefixes, ["core", "ingest", "mesh"]); - let mut toward_core = cluster.subscriber(&core).expect("core").consume().announced(); + let mut toward_core = cluster.subscriber(&core).expect("core").consume().routes(); let mut prefixes = std::iter::from_fn(|| try_next_announced(&mut toward_core)) .map(|announce| announce.prefix.to_string()) .collect::>(); diff --git a/rs/moq-relay/src/internal.rs b/rs/moq-relay/src/internal.rs index ec881d8173e..0a1299741f5 100644 --- a/rs/moq-relay/src/internal.rs +++ b/rs/moq-relay/src/internal.rs @@ -1354,13 +1354,13 @@ 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)> { + async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } @@ -1836,7 +1836,7 @@ mod tests { let default_ctx = stats.tier(Tier::default()).session(moq_net::Path::from_static("acme")); let pub_origin = moq_tokio::origin::spawn(); let egress = pub_origin.consume().with_stats(default_ctx.clone()); - let mut announced = egress.announced(); + let mut announced = egress.routes(); let pub_source = pub_origin.create_broadcast("demo/x").unwrap(); pub_source.announce(Default::default()).unwrap(); let pub_track = pub_source.create_track("video", timed()).unwrap(); diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 512e82dd05d..36d2d0bd239 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -1079,14 +1079,14 @@ async fn serve_announced( }; let (lease, origin) = admit_http(&state, prefix, query, &uri, server_name, remote, mtls).await?; - let mut announced = origin.announced(); + let mut announced = origin.routes(); let mut broadcasts = Vec::new(); while let Some(event) = announced.try_next() { - if let moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Restart(update) - | moq_net::announce::Event::Takeover { announce: update, .. } = event + if let moq_net::origin::RouteEvent::Start(update) + | moq_net::origin::RouteEvent::Update(update) + | moq_net::origin::RouteEvent::Restart(update) + | moq_net::origin::RouteEvent::Takeover { announce: update, .. } = event { broadcasts.push(update.prefix); } diff --git a/rs/moq-relay/tests/drills.rs b/rs/moq-relay/tests/drills.rs index a053d755c77..d6697e300eb 100644 --- a/rs/moq-relay/tests/drills.rs +++ b/rs/moq-relay/tests/drills.rs @@ -414,7 +414,7 @@ async fn subscribe(origin: &moq_net::origin::Consumer, path: &str) -> Reader { let broadcast = kio::clock::timeout(TIMEOUT, origin.follow(path, None).unwrap().available()) .await .expect("announcement timed out") - .expect("origin closed before announcing"); + .expect("origin closed before announcing").unwrap(); let track = broadcast.track(TRACK).expect("track"); let groups = kio::clock::timeout(TIMEOUT, track.subscribe(None)) @@ -700,7 +700,7 @@ async fn interrupted_publisher_republishes_new_content(lane: Lane) { .await .expect("subscriber connect timed out") .expect("subscriber connect failed"); - let mut announced = subscribed.announced(); + let mut announced = subscribed.routes(); let first = moq_tokio::origin::spawn(); let broadcast = first.create_broadcast("live").expect("create broadcast"); @@ -777,7 +777,7 @@ async fn interrupted_publisher_republishes_new_content(lane: Lane) { lanes!(interrupted_publisher_republishes_new_content); /// Wait for `path` to be announced (`want`) or unannounced (`!want`). -async fn expect_announce(announced: &mut moq_net::announce::Consumer, path: &str, want: bool, who: &str) { +async fn expect_announce(announced: &mut moq_net::origin::Routes, path: &str, want: bool, who: &str) { loop { let (update, active) = kio::clock::timeout(TIMEOUT, next_update(announced)) .await @@ -1039,7 +1039,7 @@ async fn cross_cluster(lane: Lane, link: PeerLink) { let subscriber = moq_tokio::origin::spawn(); let subscribed = subscriber.consume(); - let mut announced = subscribed.announced(); + let mut announced = subscribed.routes(); let url = subscribe_path.url.clone(); let subscribe_session = kio::clock::timeout( TIMEOUT, @@ -1353,7 +1353,7 @@ async fn no_publisher_never_delivers(lane: Lane) { Lane::Impaired => Duration::from_secs(2), }; - let mut announced = subscribed.announced(); + let mut announced = subscribed.routes(); let mut following = subscribed.follow("live", None).unwrap(); let (update, resolved) = tokio::join!( kio::clock::timeout(quiet, next_update(&mut announced)), @@ -1373,13 +1373,13 @@ async fn no_publisher_never_delivers(lane: Lane) { lanes!(no_publisher_never_delivers); /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } @@ -1447,7 +1447,7 @@ async fn subscriber_max_age_skips_bufferbloat(version: &str) { let remote = kio::clock::timeout(TIMEOUT, consumed.follow("live", None).unwrap().available()) .await .unwrap() - .unwrap(); + .unwrap().unwrap(); let mut groups = remote .track(TRACK) .unwrap() diff --git a/rs/moq-relay/tests/integration/auth_lifetime.rs b/rs/moq-relay/tests/integration/auth_lifetime.rs index 06ad9a296d1..5e0b4c124fb 100644 --- a/rs/moq-relay/tests/integration/auth_lifetime.rs +++ b/rs/moq-relay/tests/integration/auth_lifetime.rs @@ -288,7 +288,7 @@ async fn connect_and_round_trip(url: &url::Url) -> (moq_tokio::Connection, moq_t let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + let mut announcements = sub_consumer.routes(); let sub_session = kio::clock::timeout( TIMEOUT, client() @@ -655,7 +655,7 @@ async fn a_moved_tier_retags_the_live_session() { let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + let mut announcements = sub_consumer.routes(); let sub_session = kio::clock::timeout( TIMEOUT, client() @@ -816,7 +816,7 @@ async fn a_rechecked_grant_resizes_live_sessions() { let broadcast = kio::clock::timeout(TIMEOUT, sub_consumer.follow(path, None).unwrap().available()) .await .expect("announcement timeout") - .expect("announced broadcast resolves"); + .expect("announced broadcast resolves").unwrap(); subs.push( broadcast .track("media") @@ -879,7 +879,7 @@ async fn a_rechecked_grant_resizes_live_sessions() { let broadcast = kio::clock::timeout(TIMEOUT, sub_consumer.follow("alice/audio", None).unwrap().available()) .await .expect("the undeafened path was never announced again") - .expect("announced broadcast resolves"); + .expect("announced broadcast resolves").unwrap(); let mut audio = broadcast .track("media") .unwrap() @@ -997,7 +997,7 @@ async fn http_routes_hold_a_lease() { // Wait until the announcement reaches the relay before asking over HTTP: // the /announced handler only reports what has arrived so far. let sub_origin = moq_tokio::origin::spawn(); - let mut announcements = sub_origin.consume().announced(); + let mut announcements = sub_origin.consume().routes(); let _sub_session = kio::clock::timeout( TIMEOUT, client() @@ -1337,7 +1337,7 @@ async fn mtls_route_source(mtls_peer: bool) -> moq_net::origin::Source { .expect("connect timeout") .expect("the peer is admitted"); - let mut announced = cluster.origin.consume().announced(); + let mut announced = cluster.origin.consume().routes(); let (update, _) = kio::clock::timeout(TIMEOUT, next_update(&mut announced)) .await .expect("timed out waiting for forwarded") @@ -1690,13 +1690,13 @@ async fn a_late_decision_within_the_deadline_admits() { } /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } @@ -1780,7 +1780,7 @@ async fn in_band_tokens_widen_and_withdraw_live_prefixes() { let a_read = kio::clock::timeout(TIMEOUT, read.follow("a/cam", None).unwrap().available()) .await .unwrap() - .unwrap(); + .unwrap().unwrap(); let mut a_sub = a_read.track("video").unwrap().subscribe(None).await.unwrap(); let mut replacement = Grant::new(all(), "b/**".parse::().unwrap()); replacement.expires = Some(kio::clock::wall() + Duration::from_secs(3600)); @@ -1792,7 +1792,7 @@ async fn in_band_tokens_widen_and_withdraw_live_prefixes() { let b_read = kio::clock::timeout(TIMEOUT, read.follow("b/cam", None).unwrap().available()) .await .expect("new prefix not announced") - .unwrap(); + .unwrap().unwrap(); let mut b_sub = b_read.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = b_track.append_group().unwrap(); group @@ -1851,7 +1851,7 @@ async fn relay_request_limits_distinguish_clients_and_peers() { options.peer.announces = 2; let cluster = crate::spawn_cluster(options); let consumer = cluster.origin.consume(); - let mut observed = consumer.announced(); + let mut observed = consumer.routes(); let (port, relay) = match scheme { "tcp" => spawn_relay_with(auth, cluster).await, _ => spawn_ws_relay_with(auth, cluster).await, diff --git a/rs/moq-relay/tests/integration/cluster_idle.rs b/rs/moq-relay/tests/integration/cluster_idle.rs index 9841f4a75c4..71c07f1c431 100644 --- a/rs/moq-relay/tests/integration/cluster_idle.rs +++ b/rs/moq-relay/tests/integration/cluster_idle.rs @@ -108,13 +108,13 @@ async fn silent_peer_detected() { let mut quic = moq_tokio::quic::Config::default(); quic.idle_timeout = Some((IDLE).into()); let cluster = crate::spawn_cluster(cluster::Options::new(config)).with_connect(connect, quic); - let mut announced = cluster.origin.consume().announced(); + let mut announced = cluster.origin.consume().routes(); let run = tokio::spawn(cluster.clone().start().await.expect("cluster start").run()); kio::clock::timeout(DETECT, async { loop { let event = announced.next().await.expect("origin closed"); - if let moq_net::announce::Event::Start(update) | moq_net::announce::Event::Update(update) = event + if let moq_net::origin::RouteEvent::Start(update) | moq_net::origin::RouteEvent::Update(update) = event && update.prefix.as_str() == "peer" { break; @@ -132,7 +132,7 @@ async fn silent_peer_detected() { kio::clock::timeout(DETECT, async { loop { let event = announced.next().await.expect("origin closed"); - if let moq_net::announce::Event::End(update) = event + if let moq_net::origin::RouteEvent::End(update) = event && update.prefix.as_str() == "peer" { break; diff --git a/rs/moq-relay/tests/integration/cluster_unknown.rs b/rs/moq-relay/tests/integration/cluster_unknown.rs index 68dffcdfe91..daf968c1209 100644 --- a/rs/moq-relay/tests/integration/cluster_unknown.rs +++ b/rs/moq-relay/tests/integration/cluster_unknown.rs @@ -259,7 +259,7 @@ async fn watch_announces( ) -> tokio::task::JoinHandle> { let url: Url = format!("tcp://127.0.0.1:{port}").parse().expect("parse url"); let origin = moq_tokio::origin::spawn(); - let mut announced = origin.consume().announced(); + let mut announced = origin.consume().routes(); let session = kio::clock::timeout(TIMEOUT, client(None).with_subscriber(origin).connect(url).established()) .await .expect("viewer connect timeout") @@ -346,7 +346,7 @@ async fn unknown_publisher_republish_stays_routable() { let url: Url = format!("tcp://127.0.0.1:{}", mesh.d()).parse().expect("parse url"); let origin = moq_tokio::origin::spawn(); - let mut announced = origin.consume().announced(); + let mut announced = origin.consume().routes(); let _session = kio::clock::timeout(TIMEOUT, client(None).with_subscriber(origin).connect(url).established()) .await .expect("viewer connect timeout") @@ -401,12 +401,12 @@ async fn unknown_publisher_does_not_flap_across_a_lite04_cluster_triangle() { } /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/connection.rs b/rs/moq-relay/tests/integration/connection.rs index 77973741ec9..f1fdb72fabe 100644 --- a/rs/moq-relay/tests/integration/connection.rs +++ b/rs/moq-relay/tests/integration/connection.rs @@ -46,7 +46,7 @@ async fn largest_quic_sequence_reaches_the_subscriber() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let mut sub = remote.track("data").unwrap().subscribe(None).await.unwrap(); for sequence in [5, 1 << 32, (1 << 53) - 1, (1 << 53) + 1, (1 << 62) - 1] { // Timestamps stop at 2^61 - 1, the most lite-05/06 can zigzag as a first frame. @@ -91,18 +91,18 @@ fn publish( } /// The next active route's prefix. -async fn next_active(announced: &mut moq_net::announce::Consumer) -> String { +async fn next_active(announced: &mut moq_net::origin::Routes) -> String { loop { match kio::clock::timeout(TIMEOUT, announced.next()) .await .expect("announcement timeout") .expect("origin closed") { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => return route.prefix.to_string(), - moq_net::announce::Event::End(_) => {} + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => return route.prefix.to_string(), + moq_net::origin::RouteEvent::End(_) => {} } } } @@ -179,7 +179,7 @@ async fn two_publish_only_clients_coexist() { .expect("beta connects"); let origin = moq_tokio::origin::spawn(); - let mut announced = origin.consume().announced(); + let mut announced = origin.consume().routes(); let _subscriber = connect( moq_net::Client::new().with_subscriber(origin), newest(), @@ -224,7 +224,7 @@ async fn the_setup_path_reaches_the_decider_and_roots_the_grant() { let origin = moq_tokio::origin::spawn(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let _subscriber = connect( moq_net::Client::new().with_subscriber(origin), newest(), diff --git a/rs/moq-relay/tests/integration/embed.rs b/rs/moq-relay/tests/integration/embed.rs index 3ff968e2a8c..5da348e59d5 100644 --- a/rs/moq-relay/tests/integration/embed.rs +++ b/rs/moq-relay/tests/integration/embed.rs @@ -274,7 +274,7 @@ async fn embed_and_stop(mut config: Config) { let url: url::Url = format!("https://{quic}/").parse().expect("parse url"); let subscriber_origin = moq_tokio::origin::spawn(); let consumer = subscriber_origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let subscriber = kio::clock::timeout( TIMEOUT, client() @@ -577,12 +577,12 @@ fn embedded_loader_refuses_obsolete_file_settings() { } /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/goaway_cluster.rs b/rs/moq-relay/tests/integration/goaway_cluster.rs index e9a067be4ef..15efa890f51 100644 --- a/rs/moq-relay/tests/integration/goaway_cluster.rs +++ b/rs/moq-relay/tests/integration/goaway_cluster.rs @@ -175,7 +175,7 @@ async fn cluster_continues_a_group_split_by_goaway_inner() { .unwrap() .available() .await - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut sub = within("subscribe", bc.track("video").expect("track").subscribe(None)) .await .expect("subscribe"); @@ -202,7 +202,7 @@ async fn cluster_continues_a_group_split_by_goaway_inner() { // The cursor replays A's route first. After the GOAWAY, A's re-prices to DRAIN, so // the next route at any other cost is B's. - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); within("A's route", announced.next()).await.expect("announce update"); session_a .drain() @@ -213,10 +213,10 @@ async fn cluster_continues_a_group_split_by_goaway_inner() { loop { let event = announced.next().await.expect("announce update"); // Under another instance, B's route is another source: a restart. - if let moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Restart(update) - | moq_net::announce::Event::Takeover { announce: update, .. } = event + if let moq_net::origin::RouteEvent::Start(update) + | moq_net::origin::RouteEvent::Update(update) + | moq_net::origin::RouteEvent::Restart(update) + | moq_net::origin::RouteEvent::Takeover { announce: update, .. } = event && update.route.cost != moq_net::origin::Cost::DRAIN { break; @@ -319,7 +319,7 @@ async fn cluster_migrates_on_upstream_goaway_inner() { .unwrap() .available() .await - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut sub = bc .track("video") .expect("track handle") @@ -342,7 +342,7 @@ async fn cluster_migrates_on_upstream_goaway_inner() { // Watch for retraction during the swap: the migration must never // unannounce the path (metadata updates are expected: the drain // re-prices the old route and the sibling announces its own). - let mut announcements = cluster.origin.consume().announced(); + let mut announcements = cluster.origin.consume().routes(); let (first, _) = next_update(&mut announcements).await.expect("initial announce"); assert_eq!(first.prefix.as_str(), "cam"); @@ -549,7 +549,7 @@ async fn cluster_diamond_goaway_seamless_failover_inner() { // Watch announcements for the whole test: the failover must never // unannounce the broadcast under the subscriber. - let mut announcements = sub_origin.consume().announced(); + let mut announcements = sub_origin.consume().routes(); let (first, _) = within( "broadcast announced through the MID-A leg", next_update(&mut announcements), @@ -848,12 +848,12 @@ async fn goaway_handover_is_enforced_while_the_replacement_dial_hangs_inner() { } /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/hidden_cluster.rs b/rs/moq-relay/tests/integration/hidden_cluster.rs index 91e6ef17893..8a78b692f00 100644 --- a/rs/moq-relay/tests/integration/hidden_cluster.rs +++ b/rs/moq-relay/tests/integration/hidden_cluster.rs @@ -54,7 +54,7 @@ async fn old_peer_keeps_hidden_paths(version: moq_net::Version) { kio::clock::timeout(TEST_TIMEOUT, async { let (port, mut server) = listen_tcp(version).await; let peer_origin = moq_tokio::origin::spawn(); - let mut discovered = peer_origin.consume().with_hidden(true).announced(); + let mut discovered = peer_origin.consume().with_hidden(true).routes(); let accept = tokio::spawn(async move { let request = server.accept().await.expect("cluster dial"); let session = request.with_subscriber(peer_origin).ok().await.expect("accept"); @@ -72,7 +72,7 @@ async fn old_peer_keeps_hidden_paths(version: moq_net::Version) { let cluster_run = tokio::spawn(cluster.clone().start().await.expect("cluster start").run()); loop { - if let moq_net::announce::Event::Start(announce) | moq_net::announce::Event::Update(announce) = + if let moq_net::origin::RouteEvent::Start(announce) | moq_net::origin::RouteEvent::Update(announce) = discovered.next().await.expect("peer origin closed") && announce.prefix.as_str() == ".hidden/test" { diff --git a/rs/moq-relay/tests/integration/public_rules.rs b/rs/moq-relay/tests/integration/public_rules.rs index 7b58ac99172..cd8a74190be 100644 --- a/rs/moq-relay/tests/integration/public_rules.rs +++ b/rs/moq-relay/tests/integration/public_rules.rs @@ -96,7 +96,7 @@ async fn publish(url: url::Url, name: &str) -> Box { async fn first_broadcast(url: url::Url) -> String { let origin = moq_tokio::origin::spawn(); let consumer = origin.consume(); - let mut announcements = consumer.announced(); + let mut announcements = consumer.routes(); let _session = kio::clock::timeout( TIMEOUT, client() @@ -111,7 +111,7 @@ async fn first_broadcast(url: url::Url) -> String { let update = kio::clock::timeout(TIMEOUT, async { match announcements.next().await.expect("origin closed") { - moq_net::announce::Event::Start(update) => update, + moq_net::origin::RouteEvent::Start(update) => update, other => panic!("expected announce, got {other:?}"), } }) diff --git a/rs/moq-relay/tests/integration/refusals.rs b/rs/moq-relay/tests/integration/refusals.rs index 83e66e392a6..3867db25c6f 100644 --- a/rs/moq-relay/tests/integration/refusals.rs +++ b/rs/moq-relay/tests/integration/refusals.rs @@ -250,7 +250,7 @@ async fn refused_only_stats_depth_one_has_root_totals_and_shared_embedder_metric ) .await .unwrap() - .unwrap(); + .unwrap().unwrap(); let consumer = moq_stats::Consumer::new(broadcast, Default::default()); let mut totals = consumer.totals().await.unwrap(); kio::clock::timeout(TIMEOUT, async { @@ -306,7 +306,7 @@ async fn peer_zero_close_is_clean_and_application_close_counts_once() { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); let consumer = moq_stats::Consumer::new(broadcast, Default::default()); let mut totals = consumer.totals().await.unwrap(); for (index, error) in [moq_net::Error::Cancel, moq_net::Error::App(42)] diff --git a/rs/moq-relay/tests/integration/runtime_uring.rs b/rs/moq-relay/tests/integration/runtime_uring.rs index baa79df6865..31b21d4ae94 100644 --- a/rs/moq-relay/tests/integration/runtime_uring.rs +++ b/rs/moq-relay/tests/integration/runtime_uring.rs @@ -158,7 +158,7 @@ async fn uring_workers_serve_webtransport_and_raw_quic() { for url in [&wt_url, &raw_url, &wt_url, &raw_url] { let origin = moq_tokio::origin::spawn(); let consumer = origin.consume(); - let announced = consumer.announced(); + let announced = consumer.routes(); let connection = connect(client().with_subscriber(origin), url.clone()).await; subscribers.push((connection, consumer, announced)); } @@ -256,7 +256,7 @@ async fn uring_workers_serve_every_configured_version() { let (version, client) = pinned(name); let origin = moq_tokio::origin::spawn(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let connection = connect(client.with_subscriber(origin), url).await; assert_eq!(connection.version(), Some(version), "{scheme} {name}"); @@ -675,7 +675,7 @@ async fn an_mtls_client_authenticates_without_a_token() { let subscriber_origin = moq_tokio::origin::spawn(); let consumer = subscriber_origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let subscriber = connect(client().with_subscriber(subscriber_origin), url).await; let (update, active) = kio::clock::timeout(TIMEOUT, next_update(&mut announced)) @@ -756,7 +756,7 @@ async fn uring_workers_write_qlog_traces() { let subscriber_origin = moq_tokio::origin::spawn(); let consumer = subscriber_origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let subscriber = connect(client().with_subscriber(subscriber_origin), url).await; let (_, active) = kio::clock::timeout(TIMEOUT, next_update(&mut announced)) .await @@ -887,13 +887,13 @@ async fn spawn_auth_server(policy: moq_auth::serve::Policy) -> url::Url { } /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/runtime_workers.rs b/rs/moq-relay/tests/integration/runtime_workers.rs index d37757ac5f8..41d331ac1ed 100644 --- a/rs/moq-relay/tests/integration/runtime_workers.rs +++ b/rs/moq-relay/tests/integration/runtime_workers.rs @@ -105,7 +105,7 @@ async fn workers_serve_quic_and_share_one_origin() { for _ in 0..WORKERS { let origin = moq_tokio::origin::spawn(); let consumer = origin.consume(); - let announced = consumer.announced(); + let announced = consumer.routes(); let connection = connect(client().with_subscriber(origin), url.clone()).await; subscribers.push((connection, consumer, announced)); } @@ -152,12 +152,12 @@ async fn workers_serve_quic_and_share_one_origin() { } /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/smoke.rs b/rs/moq-relay/tests/integration/smoke.rs index 76527c4e647..21abd596168 100644 --- a/rs/moq-relay/tests/integration/smoke.rs +++ b/rs/moq-relay/tests/integration/smoke.rs @@ -171,7 +171,7 @@ async fn relay_websocket_round_trip_uses_newest_version() { // ── subscriber ────────────────────────────────────────────────── let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + let mut announcements = sub_consumer.routes(); let (_client, sub_connection) = kio::clock::timeout(TIMEOUT, connect_once(client().with_subscriber(sub_origin), url)) @@ -261,14 +261,14 @@ async fn relay_websocket_logs_its_close_under_a_cluster_id() { } /// Read announcements until `until` shows up, returning every active prefix seen. -async fn announced_until(announcements: &mut moq_net::announce::Consumer, until: &str) -> Vec { +async fn announced_until(announcements: &mut moq_net::origin::Routes, until: &str) -> Vec { let mut seen = Vec::new(); while !seen.iter().any(|prefix| prefix == until) { let event = kio::clock::timeout(TIMEOUT, announcements.next()) .await .expect("announcement timeout") .expect("origin closed"); - if let moq_net::announce::Event::Start(announce) | moq_net::announce::Event::Update(announce) = event { + if let moq_net::origin::RouteEvent::Start(announce) | moq_net::origin::RouteEvent::Update(announce) = event { seen.push(announce.prefix.as_str().to_owned()); } } @@ -307,7 +307,7 @@ async fn hidden_broadcasts_need_a_lite07_opt_in() { // An opted-in lite-07 client discovers the hidden broadcast. let opted_origin = moq_tokio::origin::spawn(); - let mut opted = opted_origin.consume().with_hidden(true).announced(); + let mut opted = opted_origin.consume().with_hidden(true).routes(); let (_opted_client, opted_connection) = kio::clock::timeout( TIMEOUT, connect_once(client_version(Some(lite07)).with_subscriber(opted_origin), url.clone()), @@ -328,7 +328,7 @@ async fn hidden_broadcasts_need_a_lite07_opt_in() { for (version, local_hidden) in [(lite07, false), (lite06, true)] { let origin = moq_tokio::origin::spawn(); let consumer = origin.consume().with_hidden(local_hidden); - let mut announcements = consumer.announced(); + let mut announcements = consumer.routes(); let (_client, connection) = kio::clock::timeout( TIMEOUT, connect_once(client_version(Some(version)).with_subscriber(origin), url.clone()), @@ -505,7 +505,7 @@ async fn relay_websocket_root_path_upgrades() { // ── subscriber ────────────────────────────────────────────────── let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + let mut announcements = sub_consumer.routes(); let (_client, sub_connection) = kio::clock::timeout(TIMEOUT, connect_once(client().with_subscriber(sub_origin), url)) .await @@ -643,7 +643,7 @@ async fn internal_tcp_round_trip() { // ── subscriber ────────────────────────────────────────────────── let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + let mut announcements = sub_consumer.routes(); let (_client, sub_connection) = kio::clock::timeout(TIMEOUT, connect_once(client().with_subscriber(sub_origin), url)) .await @@ -746,7 +746,7 @@ async fn internal_unix_round_trip() { // ── subscriber ────────────────────────────────────────────────── let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + let mut announcements = sub_consumer.routes(); let (_client, sub_connection) = kio::clock::timeout(TIMEOUT, connect_once(client().with_subscriber(sub_origin), url)) .await @@ -822,7 +822,7 @@ async fn path_round_trip(version: moq_net::Version, pub_url: url::Url, sub_url: let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + let mut announcements = sub_consumer.routes(); let sub_client = client_version(Some(version)).with_subscriber(sub_origin); let (_client, sub_connection) = kio::clock::timeout(TIMEOUT, connect_once(sub_client, sub_url)) .await @@ -961,12 +961,12 @@ async fn connect_once( } /// The next route and whether it is active. -async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { +async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/tenant_matrix.rs b/rs/moq-relay/tests/integration/tenant_matrix.rs index 665a81661e2..faf278142be 100644 --- a/rs/moq-relay/tests/integration/tenant_matrix.rs +++ b/rs/moq-relay/tests/integration/tenant_matrix.rs @@ -236,7 +236,7 @@ impl Watcher { async fn connect(url: url::Url) -> Self { let origin = moq_tokio::origin::spawn(); let consumer = origin.consume(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let session = kio::clock::timeout( TIMEOUT, client() @@ -256,7 +256,7 @@ impl Watcher { let changed = changed.clone(); async move { while let Some(event) = announced.next().await { - if let moq_net::announce::Event::Start(route) = event { + if let moq_net::origin::RouteEvent::Start(route) = event { seen.lock().unwrap().push(route.prefix.to_string()); changed.notify_waiters(); } diff --git a/rs/moq-relay/tests/integration/upstream_links.rs b/rs/moq-relay/tests/integration/upstream_links.rs index e7c4ca43cd7..2ff5f388f02 100644 --- a/rs/moq-relay/tests/integration/upstream_links.rs +++ b/rs/moq-relay/tests/integration/upstream_links.rs @@ -207,10 +207,10 @@ async fn read_frame(origin: &origin::Producer, path: &str) { /// cursor replays that set when it registers, all starts and none held, so it /// drains without waiting. fn routes(origin: &origin::Producer) -> BTreeMap> { - let mut announced = origin.consume().announced(); + let mut announced = origin.consume().routes(); let mut routes = BTreeMap::new(); while let Some(event) = announced.try_next() { - let announce::Event::Start(announce) = event else { + let origin::RouteEvent::Start(announce) = event else { panic!("an initial set is only starts: got {event:?}"); }; let hops = announce.route.hops.iter().map(|hop| hop.id()).collect(); @@ -227,7 +227,7 @@ async fn routes_when( ) -> BTreeMap> { within(step, async { // Created first, so a change landing between two reads still wakes us. - let mut changes = origin.consume().announced(); + let mut changes = origin.consume().routes(); loop { let routes = routes(origin); if ready(&routes) { diff --git a/rs/moq-room/src/chat.rs b/rs/moq-room/src/chat.rs index 6868d5e14cb..bab7a56025e 100644 --- a/rs/moq-room/src/chat.rs +++ b/rs/moq-room/src/chat.rs @@ -294,7 +294,7 @@ mod tests { let relay = origin(2); let _link = link(&publisher, &relay).await; let consumer = relay.consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap(); + let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); // A first reader warms the relay's copy with the first window. { diff --git a/rs/moq-room/src/room.rs b/rs/moq-room/src/room.rs index af2c046a317..eaa1e4a7cb4 100644 --- a/rs/moq-room/src/room.rs +++ b/rs/moq-room/src/room.rs @@ -1,11 +1,8 @@ //! A room is a path prefix. Participants are discovered from the announce stream. -use std::task::{Poll, ready}; +use std::task::Poll; -use moq_net::{ - Path, announce, broadcast, - origin::{self, Requesting}, -}; +use moq_net::{Path, announce, broadcast, origin}; use crate::path::{Kind, parse}; @@ -33,23 +30,24 @@ impl std::fmt::Debug for Event { } } -/// An in-flight request for the broadcast an active announcement named. -struct Inflight { +/// A listed participant broadcast, followed across the instances that serve it. +struct Participant { identity: Path, kind: Kind, path: Path, - request: Requesting, + following: origin::Following, } /// Runs the announce loop and yields remote participant broadcasts. /// /// Skips paths that are not `{identity}/camera.hang` or `{identity}/screen.hang`, and -/// skips the local identity so a publisher does not see itself as a remote. +/// skips the local identity so a publisher does not see itself as a remote. A participant +/// that restarts is yielded again with its new broadcast. pub struct Room { origin: origin::Consumer, announced: announce::Consumer, local: Option, - inflight: Option, + participants: Vec, } impl std::fmt::Debug for Room { @@ -67,87 +65,76 @@ impl Room { announced: origin.announced(), origin: origin.clone(), local, - inflight: None, + participants: Vec::new(), } } /// Poll for the next remote camera/screen (un)announce. pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll> { loop { - if let Some(event) = ready!(self.poll_inflight(waiter)) { - return Poll::Ready(Some(event)); - } - - let (update, active) = match ready!(self.announced.poll_next(waiter)) { - // A restart resolves the new instance, replacing the one handed out before. - Some( - announce::Event::Start(update) - | announce::Event::Update(update) - | announce::Event::Restart(update) - | announce::Event::Takeover { announce: update, .. }, - ) => (update, true), - Some(announce::Event::End(update)) => (update, false), - None => return Poll::Ready(None), - }; - let path = update.prefix; - let Some(parsed) = parse(&path) else { - continue; - }; - if self.local.as_ref().is_some_and(|id| *id == parsed.identity) { - continue; - } - if !active { - return Poll::Ready(Some(Event { - identity: parsed.identity, - kind: parsed.kind, - path, - broadcast: None, - })); - } - - let mut request = self.origin.request(&path, None).into_inner(); - match kio::Task::poll(&mut request, waiter) { - Poll::Ready(Ok(broadcast)) => { + match self.announced.poll_next(waiter) { + Poll::Ready(Some(announce::Event::Present(announce))) => self.listed(announce.prefix), + Poll::Ready(Some(announce::Event::Absent(announce))) => { + let Some(index) = self.participants.iter().position(|p| p.path == announce.prefix) else { + continue; + }; + let gone = self.participants.swap_remove(index); return Poll::Ready(Some(Event { - identity: parsed.identity, - kind: parsed.kind, - path, - broadcast: Some(broadcast), + identity: gone.identity, + kind: gone.kind, + path: gone.path, + broadcast: None, })); } - Poll::Ready(Err(_)) => continue, - Poll::Pending => { - self.inflight = Some(Inflight { - identity: parsed.identity, - kind: parsed.kind, - path, - request, - }); - return Poll::Pending; - } + Poll::Ready(None) => return Poll::Ready(None), + Poll::Pending => break, } } + self.poll_participants(waiter).map(Some) } - fn poll_inflight(&mut self, waiter: &kio::Waiter) -> Poll> { - let Some(inflight) = self.inflight.as_mut() else { - return Poll::Ready(None); + /// Follow a listed path, unless it is not a remote participant broadcast. + fn listed(&mut self, path: Path) { + let Some(parsed) = parse(&path) else { + return; }; - match ready!(kio::Task::poll(&mut inflight.request, waiter)) { - Ok(broadcast) => { - let inflight = self.inflight.take().expect("inflight still set"); - Poll::Ready(Some(Event { - identity: inflight.identity, - kind: inflight.kind, - path: inflight.path, - broadcast: Some(broadcast), - })) - } - Err(_) => { - self.inflight = None; - Poll::Ready(None) + if self.local.as_ref().is_some_and(|id| *id == parsed.identity) { + return; + } + let Ok(following) = self.origin.follow(&path, None) else { + return; + }; + self.participants.push(Participant { + identity: parsed.identity, + kind: parsed.kind, + path, + following, + }); + } + + /// The next broadcast a participant's follower hands out. A follower that fails, such as a + /// handler refusing its path, is dropped until the path is listed again; its end comes + /// from the listing. + fn poll_participants(&mut self, waiter: &kio::Waiter) -> Poll { + let mut index = 0; + while let Some(participant) = self.participants.get_mut(index) { + match participant.following.poll_available(waiter) { + Poll::Ready(Ok(Some(broadcast))) => { + return Poll::Ready(Event { + identity: participant.identity.clone(), + kind: participant.kind, + path: participant.path.clone(), + broadcast: Some(broadcast), + }); + } + Poll::Ready(Ok(None)) => continue, + Poll::Ready(Err(_)) => { + self.participants.swap_remove(index); + } + Poll::Pending => index += 1, } } + Poll::Pending } /// Wait for the next remote camera/screen (un)announce. diff --git a/rs/moq-rtc/src/lib.rs b/rs/moq-rtc/src/lib.rs index 19895f301d6..876b23eb9b6 100644 --- a/rs/moq-rtc/src/lib.rs +++ b/rs/moq-rtc/src/lib.rs @@ -77,11 +77,11 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) => Some((route, true)), + moq_net::announce::Event::Absent(route) => Some((route, false)), } } @@ -169,14 +169,14 @@ mod tests { /// Publish a replacement instance of `source`, returning once the origin serves it. async fn take_over(origin: &moq_net::origin::Producer) -> (Box, moq_mux::catalog::Producer) { let instance = moq_net::Instance::random(); - let mut instances = moq_mux::follow::Instances::new(&origin.consume(), "source", Some(&instance)).unwrap(); + let mut instances = origin.consume().follow("source", instance.clone()).unwrap(); let (mut new, catalog) = publish_opus(origin, instance); push(&mut *new, 20_000, NEW_PACKET); - let started = kio::clock::timeout(TIMEOUT, instances.next()) + let started = kio::clock::timeout(TIMEOUT, instances.available()) .await .expect("the replacement never took over") .unwrap(); - assert!(matches!(started, moq_mux::follow::Event::Start(_))); + assert!(started.is_some()); (new, catalog) } @@ -289,7 +289,7 @@ mod tests { let source = moq_mux::Source::new(source, broadcast); let pushed = tokio::spawn(async move { client.publish(url, source).await }); let ingested = ingest_origin.consume(); - let ingested = ingested.follow("ingested", None).unwrap().available().await.unwrap(); + let ingested = ingested.follow("ingested", None).unwrap().available().await.unwrap().unwrap(); let mut played = opus_output(&ingested).await; assert_eq!(next_payload(&mut played).await, OPUS_PACKET); diff --git a/rs/moq-rtmp/src/dial.rs b/rs/moq-rtmp/src/dial.rs index 6bff0f758f0..308ea842acb 100644 --- a/rs/moq-rtmp/src/dial.rs +++ b/rs/moq-rtmp/src/dial.rs @@ -822,7 +822,7 @@ mod tests { }); let consumer = downstream.consume(); - let copy = consumer.follow("live/cam0", None).unwrap().available().await.unwrap(); + let copy = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); // The catalog goes out once the keyframe landed, so the copy holds media to linger with. let mut listed = copy.track("catalog.json").unwrap().subscribe(None).await.unwrap(); assert!(listed.recv_group().await.unwrap().is_some()); @@ -938,7 +938,7 @@ mod tests { // Read what reaches the remote back out as FLV. let consumer = downstream.consume(); - let copy = consumer.follow("live/cam0", None).unwrap().available().await.unwrap(); + let copy = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); let source = moq_mux::Source::new(consumer, copy); let catalog = source .catalog::<()>(moq_mux::catalog::CatalogFormat::default()) @@ -955,12 +955,13 @@ mod tests { until(OLD_IDR).await; let instance = moq_net::Instance::random(); - let mut instances = moq_mux::follow::Instances::new(&upstream.consume(), "live/cam0", Some(&instance)).unwrap(); + let mut instances = upstream.consume().follow("live/cam0", instance.clone()).unwrap(); let (_new, _new_catalog) = publish(&upstream, &instance, NEW_IDR); - kio::clock::timeout(Duration::from_secs(5), instances.next()) + kio::clock::timeout(Duration::from_secs(5), instances.available()) .await .expect("the new publisher takes over") - .unwrap(); + .unwrap() + .expect("the new publisher serves"); let mut delta = vec![0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, OLD_DELTA.len() as u8]; delta.extend_from_slice(OLD_DELTA); @@ -1037,7 +1038,7 @@ mod tests { .unwrap() .available() .await - .unwrap(); + .unwrap().unwrap(); // It should carry a hang catalog track (proof the FLV demux produced real // media on the far side): subscribe to it and read one catalog frame. diff --git a/rs/moq-rtmp/src/server.rs b/rs/moq-rtmp/src/server.rs index 1accebad879..c7c76c43c2b 100644 --- a/rs/moq-rtmp/src/server.rs +++ b/rs/moq-rtmp/src/server.rs @@ -1900,7 +1900,7 @@ mod tests { let (mut client, server) = tokio::io::duplex(64 * 1024); let accept = tokio::spawn(accept_publish(server, origin.clone(), Duration::ZERO)); let catalog = async { - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap(); + let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); let track = broadcast.track(hang::Catalog::DEFAULT_NAME).unwrap(); track.subscribe(None).await.unwrap() }; @@ -2210,7 +2210,7 @@ mod tests { publisher.push(flv::TAG_VIDEO, 0, &vseq).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap(); + let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); let info = broadcast.track("0.flv-v").unwrap().info().await.unwrap(); assert_eq!(info.max_age, Some(Duration::from_secs(3))); } @@ -2343,12 +2343,13 @@ mod tests { assert_eq!(next().await.1[..2], [0x17, 0x01]); let instance = moq_net::Instance::random(); - let mut instances = moq_mux::follow::Instances::new(&consumer, "live/cam0", Some(&instance)).unwrap(); + let mut instances = consumer.follow("live/cam0", instance.clone()).unwrap(); let (_new, _new_catalog) = publish_avc(&origin, instance, &[0x65, 0x99, 0x99, 0x99, 0x99]); - kio::clock::timeout(Duration::from_secs(5), instances.next()) + kio::clock::timeout(Duration::from_secs(5), instances.available()) .await .expect("the new publisher takes over") - .unwrap(); + .unwrap() + .expect("the new publisher serves"); let mut delta = vec![0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, OLD_DELTA.len() as u8]; delta.extend_from_slice(OLD_DELTA); @@ -2802,7 +2803,7 @@ mod tests { let stale_client = tokio::spawn(async move { run_client(TcpStream::connect(addr).await.unwrap(), ClientMode::Publish).await; }); - let stale = consumer.follow("live/cam0", None).unwrap().available().await.unwrap(); + let stale = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); let mut catalog = stale .track(hang::Catalog::DEFAULT_NAME) .unwrap() @@ -2810,12 +2811,12 @@ mod tests { .await .unwrap(); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let fresh_client = tokio::spawn(async move { run_client(TcpStream::connect(addr).await.unwrap(), ClientMode::Publish).await; }); kio::clock::timeout(Duration::from_secs(5), async { - while !matches!(announced.next().await, Some(moq_net::announce::Event::Restart(_))) {} + while !matches!(announced.next().await, Some(moq_net::origin::RouteEvent::Restart(_))) {} }) .await .expect("the reconnect restarts the broadcast"); diff --git a/rs/moq-srt/src/ts.rs b/rs/moq-srt/src/ts.rs index ed32d8eafe5..1495ae5f4cf 100644 --- a/rs/moq-srt/src/ts.rs +++ b/rs/moq-srt/src/ts.rs @@ -631,7 +631,7 @@ mod tests { /// announced. async fn program(origin: &moq_net::origin::Producer, path: &str) -> (u16, Vec) { let consumer = origin.consume(); - let broadcast = consumer.follow(path, None).unwrap().available().await.unwrap(); + let broadcast = consumer.follow(path, None).unwrap().available().await.unwrap().unwrap(); let mut catalog = moq_mux::catalog::Consumer::::new(&broadcast, CatalogFormat::Hang) .await .unwrap(); @@ -727,7 +727,7 @@ mod tests { publisher.feed(Bytes::from_static(BBB5S)).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap(); + let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); let start = kio::clock::now(); let wait = tokio::spawn(publisher.finish(linger).unwrap().wait()); kio::clock::sleep(linger / 2).await; @@ -760,7 +760,7 @@ mod tests { publisher.feed(Bytes::from(ts)).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap(); + let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); let info = broadcast.track("0.avc3").unwrap().info().await.unwrap(); assert_eq!(info.max_age, Some(Duration::from_secs(3))); } @@ -831,7 +831,7 @@ mod tests { let mut publisher = Publisher::new(&origin, "ingest", Default::default(), None).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("ingest", None).unwrap().available().await.unwrap(); + let broadcast = consumer.follow("ingest", None).unwrap().available().await.unwrap().unwrap(); publisher.feed(bytes::Bytes::from_static(BBB5S)).unwrap(); diff --git a/rs/moq-stats/benches/producer_tick.rs b/rs/moq-stats/benches/producer_tick.rs index 17d46eb2079..a956d2d35bb 100644 --- a/rs/moq-stats/benches/producer_tick.rs +++ b/rs/moq-stats/benches/producer_tick.rs @@ -96,7 +96,7 @@ struct Relay { _origin: origin::Producer, _origin_driver: origin::Driver, _publishers: Vec, - _cursors: Vec, + _cursors: Vec, _sessions: Vec, _held: Vec, } @@ -131,7 +131,7 @@ impl Relay { .map(|tier| { let tier = stats::Tier::new(moq_net::Path::new(&format!("t{tier}")).unwrap()); let session = registry.tier(tier.clone()).session(moq_net::Path::from_static("root")); - let mut cursor = origin.consume().with_stats(session.clone()).announced(); + let mut cursor = origin.consume().with_stats(session.clone()).routes(); while cursor.next().now_or_never().flatten().is_some() {} cursors.push(cursor); sessions.push(session); diff --git a/rs/moq-stats/src/aggregate.rs b/rs/moq-stats/src/aggregate.rs index 290c807b91b..35099fadeae 100644 --- a/rs/moq-stats/src/aggregate.rs +++ b/rs/moq-stats/src/aggregate.rs @@ -763,7 +763,7 @@ impl Node { struct Merged { /// Resolves announced node paths into broadcasts. origin: origin::Consumer, - announce: moq_net::announce::Consumer, + announce: moq_net::origin::Routes, prefix: Path, /// Track name subscribed on each node broadcast. name: String, @@ -783,7 +783,7 @@ impl Merged { fn new(origin: origin::Consumer, config: &Config, name: String) -> Self { Self { // Stats live under a `.`-named prefix, which discovery hides by default. - announce: origin.clone().with_hidden(true).announced(), + announce: origin.clone().with_hidden(true).routes(), origin, prefix: config.prefix.clone(), name, @@ -808,16 +808,16 @@ impl Merged { match self.announce.poll_next(waiter) { // A takeover continues what was read through its predecessor, like an update. Poll::Ready(Some( - moq_net::announce::Event::Start(update) - | moq_net::announce::Event::Update(update) - | moq_net::announce::Event::Takeover { announce: update, .. }, + moq_net::origin::RouteEvent::Start(update) + | moq_net::origin::RouteEvent::Update(update) + | moq_net::origin::RouteEvent::Takeover { announce: update, .. }, )) => changed |= self.apply_announce(update, true), - Poll::Ready(Some(moq_net::announce::Event::End(update))) => { + Poll::Ready(Some(moq_net::origin::RouteEvent::End(update))) => { changed |= self.apply_announce(update, false) } // Another instance: the one tracked at the path ends, then the new one // starts, so its reader resolves afresh. - Poll::Ready(Some(moq_net::announce::Event::Restart(update))) => { + Poll::Ready(Some(moq_net::origin::RouteEvent::Restart(update))) => { // An announced prefix is a path beneath the root, so rooting it fits. let absolute = self.announce.absolute(&update.prefix).ok(); if let Some(previous) = absolute.and_then(|absolute| self.last_announced.get(&absolute).cloned()) { @@ -1121,13 +1121,13 @@ 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)> { + async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } @@ -1232,7 +1232,7 @@ mod tests { /// announce, bumping the `_closed` counters. #[allow(dead_code, reason = "held for their drop, never read")] struct Feed { - announced: announce::Consumer, + announced: origin::Routes, source: origin::Publication, consumer: broadcast::Consumer, sub: track::Subscriber, @@ -1250,7 +1250,7 @@ mod tests { let feed_origin = produce_origin(); let egress = feed_origin.consume().with_stats(ctx.clone()); - let mut announced = egress.announced(); + let mut announced = egress.routes(); let source = feed_origin.create_broadcast(path).expect("create_broadcast"); source.announce(origin::Route::default()).expect("announce"); let track = source.create_track("video", timed()).expect("create_track"); diff --git a/rs/moq-stats/src/consume.rs b/rs/moq-stats/src/consume.rs index 4b22bb8f1fc..ecf45033cd5 100644 --- a/rs/moq-stats/src/consume.rs +++ b/rs/moq-stats/src/consume.rs @@ -160,13 +160,13 @@ 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)> { + async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } @@ -193,7 +193,7 @@ mod tests { struct Feed { track: track::Producer, sub: track::Subscriber, - _announced: announce::Consumer, + _announced: origin::Routes, _source: origin::Publication, _ctx: moq_net::stats::Session, } @@ -218,7 +218,7 @@ mod tests { let feed_origin = produce_origin(); let egress = feed_origin.consume().with_stats(ctx.clone()); - let mut announced = egress.announced(); + let mut announced = egress.routes(); let source = feed_origin.create_broadcast(path).unwrap(); source.announce(origin::Route::default()).unwrap(); let track = source.clone().create_track("video", timed()).unwrap(); @@ -238,7 +238,7 @@ mod tests { } async fn announced(origin: &origin::Producer) -> moq_net::broadcast::Consumer { - let mut consumer = origin.consume().with_hidden(true).announced(); + let mut consumer = origin.consume().with_hidden(true).routes(); tokio::time::advance(Duration::from_millis(1)).await; let (update, active) = next_update(&mut consumer).await.expect("expected announce"); assert!(active); diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 955d1ddc6e1..7d2fbca4e62 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -1479,7 +1479,7 @@ mod tests { drain.collect(); drain.publish(Instant::now()); let consumer = edge.consume().with_hidden(true); - let mut events = consumer.announced(); + let mut events = consumer.routes(); let (route, active) = next_update(&mut events).await.unwrap(); assert!(active); assert_eq!(route.prefix.as_str(), ".stats/node"); @@ -1625,13 +1625,13 @@ 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)> { + async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::origin::RouteEvent::Start(route) + | moq_net::origin::RouteEvent::Update(route) + | moq_net::origin::RouteEvent::Restart(route) + | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), + moq_net::origin::RouteEvent::End(route) => Some((route, false)), } } @@ -1657,7 +1657,7 @@ mod tests { /// announce (bumping the `_closed` counters). #[allow(dead_code, reason = "held for their drop, never read")] struct Feed { - announced: announce::Consumer, + announced: origin::Routes, source: origin::Publication, consumer: broadcast::Consumer, sub: Option, @@ -1682,7 +1682,7 @@ mod tests { // Egress (publisher side) is tagged; the local publisher stays untagged. let egress = origin.consume().with_stats(ctx); - let mut announced = egress.announced(); + let mut announced = egress.routes(); let source = origin.create_broadcast(path).expect("create_broadcast"); source.announce(origin::Route::default()).expect("announce"); let producer = source.create_track("video", timed()).expect("create_track"); @@ -1726,7 +1726,7 @@ mod tests { /// Awaits the stats announce and returns its broadcast. async fn announced(origin: &origin::Producer) -> (String, moq_net::broadcast::Consumer) { - let mut consumer = origin.consume().with_hidden(true).announced(); + let mut consumer = origin.consume().with_hidden(true).routes(); tokio::time::advance(Duration::from_millis(1)).await; let (update, active) = next_update(&mut consumer).await.expect("expected announce"); assert!(active); @@ -1946,7 +1946,7 @@ mod tests { #[tokio::test(start_paused = true)] async fn restarted_producer_announces_a_new_instance() { let origin = produce_origin(); - let mut events = origin.consume().with_hidden(true).announced(); + let mut events = origin.consume().with_hidden(true).routes(); let first = node_producer(&origin); drive_tick().await; @@ -1975,7 +1975,7 @@ mod tests { #[tokio::test(start_paused = true)] async fn restart_replaces_a_still_announced_instance() { let origin = produce_origin(); - let mut events = origin.consume().with_hidden(true).announced(); + let mut events = origin.consume().with_hidden(true).routes(); let first = node_producer(&origin); let _f1 = feed(first.registry(), Tier::default(), "foo/bar", true, 1, 100).await; @@ -2006,7 +2006,7 @@ mod tests { #[tokio::test(start_paused = true)] async fn a_publisher_run_after_its_producer_dropped_announces_nothing() { let origin = produce_origin(); - let mut events = origin.consume().with_hidden(true).announced(); + let mut events = origin.consume().with_hidden(true).routes(); let (stale, publisher) = Producer::new( Config::new() @@ -2229,7 +2229,7 @@ mod tests { /// The announce events buffered so far in delivery order, as /// `(path, active, epoch)`. Every stats route carries an epoch. - fn take_epochs(events: &mut announce::Consumer) -> Vec<(String, bool, Instance)> { + fn take_epochs(events: &mut origin::Routes) -> Vec<(String, bool, Instance)> { use futures::FutureExt; let mut out = Vec::new(); while let Some(Some((update, active))) = next_update(events).now_or_never() { @@ -3015,7 +3015,7 @@ mod tests { drain.collect(); drain.publish(start); let consumer = edge.consume().with_hidden(true); - let mut announced = consumer.announced(); + let mut announced = consumer.routes(); let (route, active) = next_update(&mut announced).await.unwrap(); assert!(active); assert_eq!(route.prefix.as_str(), ".stats/node"); diff --git a/rs/moq-tokio/examples/clock.rs b/rs/moq-tokio/examples/clock.rs index 8ef3b628925..16bf6b2c404 100644 --- a/rs/moq-tokio/examples/clock.rs +++ b/rs/moq-tokio/examples/clock.rs @@ -112,14 +112,14 @@ async fn main() -> anyhow::Result<()> { tokio::select! { Some(event) = announced.next() => match event { // A restart is a new broadcast: subscribe to it afresh. - announce::Event::Start(update) | announce::Event::Update(update) | announce::Event::Restart(update) | announce::Event::Takeover { announce: update, .. } => { + announce::Event::Present(update) | announce::Event::Present(update) | announce::Event::Present(update) | announce::Event::Present(update) => { tracing::info!(broadcast = %update.prefix, "broadcast is online, subscribing to track"); let broadcast = consumer.request(&update.prefix, None).await?; let track = broadcast .track(&track)?.subscribe(None).await?; clock = Some(Subscriber::new(track)); } - announce::Event::End(update) => { + announce::Event::Absent(update) => { tracing::warn!(broadcast = %update.prefix, "broadcast is offline, waiting..."); } }, diff --git a/rs/moq-tokio/src/client.rs b/rs/moq-tokio/src/client.rs index 1b9b5b23c09..bbb8234f8c8 100644 --- a/rs/moq-tokio/src/client.rs +++ b/rs/moq-tokio/src/client.rs @@ -1243,7 +1243,7 @@ mod tests { let _ = websocket_handle.await; let update = match announcements.next().await.expect("origin closed") { - moq_net::announce::Event::Start(update) => update, + moq_net::announce::Event::Present(update) => update, event => panic!("expected announcement, got {event:?}"), }; assert_eq!(update.prefix.as_str(), "test"); diff --git a/rs/moq-tokio/src/connection.rs b/rs/moq-tokio/src/connection.rs index 1411b1a3c5c..d207dfd0b38 100644 --- a/rs/moq-tokio/src/connection.rs +++ b/rs/moq-tokio/src/connection.rs @@ -3377,7 +3377,7 @@ mod tests { let cam = kio::clock::timeout(WAIT, consumer.follow("cam", None).unwrap().available()) .await .unwrap() - .unwrap(); + .unwrap().unwrap(); let mut sub = cam.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = track.append_group().unwrap(); @@ -3460,7 +3460,7 @@ mod tests { kio::clock::timeout(WAIT, subscriber.consume().follow("late", None).unwrap().available()) .await .expect("the drained session stopped serving") - .unwrap(); + .unwrap().unwrap(); assert!( connection .draining() @@ -3698,7 +3698,7 @@ mod tests { .await .expect("the broadcast never reached the server") .expect("the server's origin closed"); - assert!(matches!(arrived, moq_net::announce::Event::Start(update) if update.prefix.as_str() == "room")); + assert!(matches!(arrived, moq_net::announce::Event::Present(update) if update.prefix.as_str() == "room")); assert!( futures::FutureExt::now_or_never(dialed.session.closed()).is_none(), "the session closed before the configured token was answered" diff --git a/rs/moq-tokio/src/origin.rs b/rs/moq-tokio/src/origin.rs index cb47828da7b..dca85558425 100644 --- a/rs/moq-tokio/src/origin.rs +++ b/rs/moq-tokio/src/origin.rs @@ -42,11 +42,11 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | 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 184c1dbd0a5..56d05a503be 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -2156,11 +2156,11 @@ mod tests { #[cfg(all(feature = "uds", unix))] async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | 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/webrtc/tests.rs b/rs/moq-tokio/src/webrtc/tests.rs index 8446cc3e598..f008f3ee033 100644 --- a/rs/moq-tokio/src/webrtc/tests.rs +++ b/rs/moq-tokio/src/webrtc/tests.rs @@ -60,7 +60,7 @@ async fn transfer(offerer: &Offerer, answerer: &Answerer, payload: &[u8]) { .expect("handshake timed out"); let read = async { - let Some(moq_net::announce::Event::Start(route)) = announced.next().await else { + let Some(moq_net::announce::Event::Present(route)) = announced.next().await else { panic!("expected the broadcast to be announced"); }; assert_eq!(route.prefix.as_str(), "test"); diff --git a/rs/moq-tokio/tests/integration/backend.rs b/rs/moq-tokio/tests/integration/backend.rs index f9c2507a832..f066a6e7136 100644 --- a/rs/moq-tokio/tests/integration/backend.rs +++ b/rs/moq-tokio/tests/integration/backend.rs @@ -1372,10 +1372,10 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | 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 624d68976e9..cc7d289b8c3 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -1105,7 +1105,7 @@ async fn broadcast_route_migration() { // active metadata updates (the standby's chain taking over). while let Some(event) = announcements.try_next() { assert!( - !matches!(event, moq_net::announce::Event::End(_)), + !matches!(event, moq_net::announce::Event::Absent(_)), "failover must not retract the route" ); } @@ -3479,10 +3479,10 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Start(route) - | moq_net::announce::Event::Update(route) - | moq_net::announce::Event::Restart(route) - | moq_net::announce::Event::Takeover { announce: route, .. } => Some((route, true)), - moq_net::announce::Event::End(route) => Some((route, false)), + moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | moq_net::announce::Event::Present(route) + | 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/datagram_delivery.rs b/rs/moq-tokio/tests/integration/datagram_delivery.rs index 164aa1d1aee..ecc8d3bc993 100644 --- a/rs/moq-tokio/tests/integration/datagram_delivery.rs +++ b/rs/moq-tokio/tests/integration/datagram_delivery.rs @@ -104,7 +104,7 @@ impl Viewer { let broadcast = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let track = kio::clock::timeout(TIMEOUT, broadcast.track("audio").unwrap().subscribe(None)) .await .expect("subscribe timeout") diff --git a/rs/moq-tokio/tests/integration/max_age.rs b/rs/moq-tokio/tests/integration/max_age.rs index f47a3c08582..c1d89af853e 100644 --- a/rs/moq-tokio/tests/integration/max_age.rs +++ b/rs/moq-tokio/tests/integration/max_age.rs @@ -100,7 +100,7 @@ async fn relay(version: moq_net::Version, javascript: Option) -> anyhow::R .next() .await .ok_or_else(|| anyhow::anyhow!("announcements closed"))?, - moq_net::announce::Event::Start(_) + moq_net::announce::Event::Present(_) ) {} let front = consumer.request("age", None).await?; for (i, age) in AGES.into_iter().enumerate() { diff --git a/rs/moq-tokio/tests/integration/migrate.rs b/rs/moq-tokio/tests/integration/migrate.rs index 85ea7208174..ccbdf1612dc 100644 --- a/rs/moq-tokio/tests/integration/migrate.rs +++ b/rs/moq-tokio/tests/integration/migrate.rs @@ -106,7 +106,7 @@ fn view(origin: &moq_net::origin::Producer, name: &str) -> tokio::sync::mpsc::Un .expect("follow") .available() .await - .expect("the broadcast resolves"); + .expect("the broadcast resolves").unwrap(); // A budget, so a group the move delays is late rather than skipped. let subscription = moq_net::track::Subscription::default() .with_delay(moq_net::track::Delay::default().with_max(Duration::from_secs(5))); diff --git a/rs/moq-tokio/tests/integration/receive_credit.rs b/rs/moq-tokio/tests/integration/receive_credit.rs index 475dd3650ee..417eaf15c1e 100644 --- a/rs/moq-tokio/tests/integration/receive_credit.rs +++ b/rs/moq-tokio/tests/integration/receive_credit.rs @@ -183,7 +183,7 @@ async fn room(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Consume kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() } /// Subscribe to track `name` of `remote` at `priority`. diff --git a/rs/moq-tokio/tests/integration/subscription_end_integrity.rs b/rs/moq-tokio/tests/integration/subscription_end_integrity.rs index 342ad178f4c..f7ee7163b87 100644 --- a/rs/moq-tokio/tests/integration/subscription_end_integrity.rs +++ b/rs/moq-tokio/tests/integration/subscription_end_integrity.rs @@ -89,7 +89,7 @@ async fn round(drop_session: bool) -> (usize, Option) { .unwrap() .available() .await - .expect("broadcast resolves"); + .expect("broadcast resolves").unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.expect("subscribe"); let mut got = 0; diff --git a/rs/moq-uring/benches/session_lite.rs b/rs/moq-uring/benches/session_lite.rs index bb7384f70d0..03ecc20d09e 100644 --- a/rs/moq-uring/benches/session_lite.rs +++ b/rs/moq-uring/benches/session_lite.rs @@ -184,7 +184,7 @@ mod linux { .unwrap() .available() .await - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() }; let sub = bc .track("data") diff --git a/rs/moq-uring/tests/integration/session.rs b/rs/moq-uring/tests/integration/session.rs index fd61aaf3f3d..d3728cd1e65 100644 --- a/rs/moq-uring/tests/integration/session.rs +++ b/rs/moq-uring/tests/integration/session.rs @@ -138,7 +138,7 @@ fn lite_session_over_the_worker() { .unwrap() .available() .await - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() }; let mut track = bc .track("data") @@ -282,7 +282,7 @@ fn two_lite_sessions_share_the_server_socket() { .unwrap() .available() .await - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() }; let mut track = bc .track("data") diff --git a/rs/moq-uring/tests/integration/web.rs b/rs/moq-uring/tests/integration/web.rs index 57db4c7687f..b78b26279af 100644 --- a/rs/moq-uring/tests/integration/web.rs +++ b/rs/moq-uring/tests/integration/web.rs @@ -346,7 +346,7 @@ fn lite_session_over_webtransport() { .unwrap() .available() .await - .expect("broadcast resolves") + .expect("broadcast resolves").unwrap() }; let mut track = bc .track("data") diff --git a/test/interop/clients/rust/finish.rs b/test/interop/clients/rust/finish.rs index 2e98d093d29..6cb59c7e2cf 100644 --- a/test/interop/clients/rust/finish.rs +++ b/test/interop/clients/rust/finish.rs @@ -156,7 +156,7 @@ async fn main() -> anyhow::Result<()> { .next() .await .context("origin ended before broadcast withdrawal")?; - if let moq_net::announce::Event::End(announce) = event + if let moq_net::announce::Event::Absent(announce) = event && announce.prefix.as_str() == args.broadcast { break; From 51792211c3b87449b915d2faae38573b45c35372 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 23:33:39 -0800 Subject: [PATCH 03/21] wip: migrate callers to the listing and Following's end Co-Authored-By: Claude Opus 5.5 --- rs/moq-audio/src/decode/consumer.rs | 16 +++- rs/moq-bench/src/connection.rs | 17 ++-- rs/moq-c/src/test.rs | 53 ++++++++---- rs/moq-cli/src/announced.rs | 3 +- rs/moq-cli/src/archive.rs | 53 +++++++++--- rs/moq-cli/src/fetch.rs | 3 +- rs/moq-cli/src/main.rs | 10 ++- rs/moq-cli/src/publish.rs | 5 +- rs/moq-cli/src/report.rs | 74 ++++++++++------ rs/moq-cli/src/report/echo_test.rs | 8 +- rs/moq-cli/src/rtc.rs | 3 +- rs/moq-cli/src/rtmp.rs | 3 +- rs/moq-cli/tests/integration/export.rs | 3 +- rs/moq-cli/tests/integration/instances.rs | 7 +- rs/moq-e2ee/tests/transport.rs | 8 +- rs/moq-ffi/src/origin.rs | 67 ++++++--------- rs/moq-ffi/src/test.rs | 41 +++++---- rs/moq-gst/src/source/imp.rs | 60 +++++++++---- rs/moq-hls/src/export/mod.rs | 3 +- rs/moq-hls/src/server/mod.rs | 5 +- rs/moq-hls/tests/integration/server.rs | 9 +- rs/moq-mux/src/container/source.rs | 16 +++- rs/moq-mux/src/container/ts/export_test.rs | 30 ++++--- rs/moq-mux/src/source.rs | 10 ++- rs/moq-net-tests/tests/announce_allocs.rs | 3 +- .../tests/integration/ietf_conformance.rs | 3 +- rs/moq-net-tests/tests/integration/refresh.rs | 12 ++- rs/moq-net/benches/announce.rs | 1 + rs/moq-net/benches/interests.rs | 2 +- rs/moq-net/benches/memory.rs | 8 +- rs/moq-net/benches/origin.rs | 5 +- rs/moq-net/benches/path.rs | 2 +- rs/moq-net/benches/session/mod.rs | 9 +- rs/moq-net/benches/stats.rs | 2 +- rs/moq-net/benches/synced.rs | 2 +- rs/moq-net/src/lite/publisher.rs | 20 ++++- rs/moq-net/src/model/announced.rs | 4 +- rs/moq-net/src/model/follow.rs | 7 +- rs/moq-net/src/model/origin.rs | 10 +-- rs/moq-net/tests/integration/auth.rs | 36 +++++--- .../tests/integration/broadcast_close.rs | 3 +- .../tests/integration/catalog_acquisition.rs | 3 +- rs/moq-net/tests/integration/compress.rs | 19 +++- rs/moq-net/tests/integration/control_stats.rs | 3 +- rs/moq-net/tests/integration/datagram.rs | 24 +++++- rs/moq-net/tests/integration/empty_group.rs | 3 +- rs/moq-net/tests/integration/errored_end.rs | 3 +- .../tests/integration/fastest_reader.rs | 3 +- rs/moq-net/tests/integration/fetch_fanout.rs | 3 +- .../tests/integration/fetch_from_feed.rs | 3 +- rs/moq-net/tests/integration/fetch_only.rs | 3 +- .../tests/integration/fetch_pipeline.rs | 6 +- .../integration/finished_broadcast_mock.rs | 3 +- rs/moq-net/tests/integration/finite_relay.rs | 3 +- rs/moq-net/tests/integration/goaway.rs | 3 +- rs/moq-net/tests/integration/group_order.rs | 3 +- .../tests/integration/history_groups.rs | 19 +++- .../tests/integration/idle_cancel_refetch.rs | 3 +- .../tests/integration/late_lower_group.rs | 6 +- .../tests/integration/lazy_discovery.rs | 9 +- rs/moq-net/tests/integration/partial_group.rs | 3 +- rs/moq-net/tests/integration/quiet_catalog.rs | 8 +- rs/moq-net/tests/integration/range_anchors.rs | 3 +- rs/moq-net/tests/integration/range_read.rs | 3 +- .../tests/integration/received_rewind.rs | 6 +- rs/moq-net/tests/integration/rejoin.rs | 86 ++++++++++++++++--- .../tests/integration/relay_upstream_close.rs | 3 +- rs/moq-net/tests/integration/request_caps.rs | 6 +- rs/moq-net/tests/integration/route_change.rs | 48 +++++++++-- rs/moq-net/tests/integration/route_health.rs | 16 +++- .../tests/integration/segmented_frame.rs | 3 +- rs/moq-net/tests/integration/session_close.rs | 11 ++- rs/moq-net/tests/integration/session_idle.rs | 3 +- rs/moq-net/tests/integration/source_errors.rs | 3 +- rs/moq-net/tests/integration/stream_credit.rs | 3 +- .../tests/integration/subscribe_priority.rs | 3 +- .../tests/integration/subscribe_ranges.rs | 17 +++- .../tests/integration/subscribe_tracks.rs | 3 +- .../tests/integration/subscribe_with_track.rs | 8 +- .../tests/integration/subscriber_max_age.rs | 11 ++- .../integration/subscription_end_integrity.rs | 9 +- .../integration/track_abort_over_session.rs | 8 +- .../tests/integration/track_info_cancel.rs | 3 +- .../tests/integration/track_stream_demand.rs | 16 +++- rs/moq-net/tests/integration/track_tail.rs | 3 +- rs/moq-net/tests/integration/tracks.rs | 3 +- rs/moq-net/tests/integration/tracks_ietf.rs | 3 +- .../tests/integration/unannounce_release.rs | 3 +- rs/moq-net/tests/integration/warm_backfill.rs | 8 +- rs/moq-net/tests/integration/wide_sequence.rs | 22 ++++- .../tests/integration/widened_max_age.rs | 16 +++- rs/moq-net/tests/integration/zero_copy.rs | 3 +- rs/moq-relay/src/cluster.rs | 6 +- rs/moq-relay/src/web.rs | 7 +- rs/moq-relay/tests/drills.rs | 6 +- .../tests/integration/auth_lifetime.rs | 12 ++- .../tests/integration/cluster_unknown.rs | 3 +- rs/moq-relay/tests/integration/connection.rs | 3 +- .../tests/integration/goaway_cluster.rs | 14 ++- rs/moq-relay/tests/integration/refusals.rs | 6 +- .../tests/integration/upstream_links.rs | 5 +- rs/moq-room/src/chat.rs | 8 +- rs/moq-rtc/src/lib.rs | 13 +-- rs/moq-rtc/src/server/whep.rs | 3 +- rs/moq-rtmp/src/dial.rs | 19 +++- rs/moq-rtmp/src/server.rs | 26 +++++- rs/moq-srt/src/ts.rs | 28 +++++- rs/moq-stats/benches/producer_tick.rs | 2 +- rs/moq-stats/src/aggregate.rs | 2 +- rs/moq-stats/src/consume.rs | 2 +- rs/moq-stats/src/produce.rs | 2 +- rs/moq-tokio/examples/clock.rs | 2 +- rs/moq-tokio/src/connection.rs | 6 +- rs/moq-tokio/src/origin.rs | 5 +- rs/moq-tokio/src/server.rs | 5 +- rs/moq-tokio/tests/integration/backend.rs | 5 +- rs/moq-tokio/tests/integration/broadcast.rs | 5 +- .../tests/integration/datagram_delivery.rs | 3 +- rs/moq-tokio/tests/integration/migrate.rs | 3 +- .../tests/integration/receive_credit.rs | 3 +- .../integration/subscription_end_integrity.rs | 3 +- rs/moq-transcode/examples/transcode.rs | 2 +- rs/moq-uring/benches/session_lite.rs | 3 +- .../tests/integration/receive_credit.rs | 6 +- rs/moq-uring/tests/integration/session.rs | 6 +- rs/moq-uring/tests/integration/web.rs | 3 +- test/interop/clients/rust/audio.rs | 6 +- test/interop/clients/rust/finish.rs | 9 +- test/interop/clients/rust/goaway-client.rs | 10 ++- test/interop/clients/rust/hls.rs | 7 +- test/interop/clients/rust/tail.rs | 6 +- 131 files changed, 980 insertions(+), 387 deletions(-) diff --git a/rs/moq-audio/src/decode/consumer.rs b/rs/moq-audio/src/decode/consumer.rs index 8ac8bf325d3..6e937588a26 100644 --- a/rs/moq-audio/src/decode/consumer.rs +++ b/rs/moq-audio/src/decode/consumer.rs @@ -994,7 +994,13 @@ mod tests { let relay = origin(2); let _link = link(&publisher, &relay).await; let consumer = relay.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); // A first reader warms the relay's copy with every group. { @@ -1066,7 +1072,13 @@ mod tests { let subscriber = origin(2); let _link = link(&publisher, &subscriber).await; let consumer = subscriber.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut catalog = hang::catalog::AudioConfig::new(hang::catalog::AudioCodec::Pcm, 48_000, 1); catalog.warmup = Some(Duration::from_millis(80)); diff --git a/rs/moq-bench/src/connection.rs b/rs/moq-bench/src/connection.rs index 424ccd10b6f..3dd1856b30c 100644 --- a/rs/moq-bench/src/connection.rs +++ b/rs/moq-bench/src/connection.rs @@ -315,7 +315,11 @@ async fn subscribe_named( max_delay: Duration, stats: Arc, ) -> anyhow::Result<()> { - let broadcast = consume.follow(path.as_str(), None)?.available().await?; + let broadcast = consume + .follow(path.as_str(), None)? + .available() + .await? + .ok_or_else(|| anyhow::anyhow!("the first change is an instance"))?; drain(broadcast, max_delay, &stats).await } @@ -357,9 +361,7 @@ async fn subscribe( update = announced.next() => { let update = match update { Some( - moq_net::announce::Event::Present(update) - | moq_net::announce::Event::Present(update) - | moq_net::announce::Event::Present(update) | moq_net::announce::Event::Present(update), + moq_net::announce::Event::Present(update), ) => update, Some(moq_net::announce::Event::Absent(_)) => continue, None => break, @@ -386,12 +388,7 @@ async fn subscribe( // there is nothing to spread over. while selected < want { let update = match announced.next().await { - Some( - moq_net::announce::Event::Present(update) - | moq_net::announce::Event::Present(update) - | moq_net::announce::Event::Present(update) - | moq_net::announce::Event::Present(update), - ) => update, + Some(moq_net::announce::Event::Present(update)) => update, Some(moq_net::announce::Event::Absent(_)) => continue, None => break, }; diff --git a/rs/moq-c/src/test.rs b/rs/moq-c/src/test.rs index 13ea2cf8c3c..b93935e75e7 100644 --- a/rs/moq-c/src/test.rs +++ b/rs/moq-c/src/test.rs @@ -184,7 +184,7 @@ fn announce_info(announced: u32) -> moq_announce_event { prefix_len: 0, captures: std::ptr::null(), captures_len: 0, - kind: moq_announce_kind::MOQ_ANNOUNCE_KIND_START, + kind: moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT, route: moq_route { hops: std::ptr::null(), hops_len: 0, @@ -194,8 +194,6 @@ fn announce_info(announced: u32) -> moq_announce_event { len: 0, }, }, - predecessor: std::ptr::null(), - predecessor_len: 0, }; assert_eq!(unsafe { moq_origin_announced_info(announced, &mut info) }, 0); info @@ -3304,7 +3302,7 @@ fn announced_free_lifecycle() { // The first callback is the announcement for our broadcast. let (announced, mut info) = ann_cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); let got = unsafe { std::slice::from_raw_parts(info.prefix.cast::(), info.prefix_len) }; assert_eq!(got, path, "announced prefix should match"); @@ -3454,7 +3452,7 @@ fn local_announce() { let broadcast = publish_broadcast(origin, path); let (announced_id, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); let announced_prefix = unsafe { std::str::from_utf8(std::slice::from_raw_parts(info.prefix.cast::(), info.prefix_len)).unwrap() }; @@ -3556,7 +3554,7 @@ fn announced_deactivation() { assert_eq!(unsafe { moq_publication_announce(publication, std::ptr::null()) }, 0); let (announced_id, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); assert_eq!(moq_origin_announced_free(announced_id), 0); // Going non-live unannounces the broadcast without tearing it down: local @@ -3564,13 +3562,13 @@ fn announced_deactivation() { assert_eq!(moq_publication_unannounce(publication), 0); let (deactivated_id, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_END); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_ABSENT); assert_eq!(moq_origin_announced_free(deactivated_id), 0); assert!(request_once(origin, path) < 0, "an unannounced broadcast is unroutable"); assert_eq!(unsafe { moq_publication_announce(publication, std::ptr::null()) }, 0); let (reannounced_id, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); assert_eq!(moq_origin_announced_free(reannounced_id), 0); let _ = request_broadcast(origin, path); @@ -3623,7 +3621,7 @@ fn create_broadcast_is_unroutable_until_announced() { assert_eq!(moq_publication_free(publication), 0); let _ = request_broadcast(origin, path); let (announced_id, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); assert_eq!(moq_origin_announced_free(announced_id), 0); assert_eq!(moq_origin_announced_cancel(announced_task), 0); @@ -3646,7 +3644,7 @@ fn announce_route_carries_cost_and_instance_without_hops() { assert_eq!(unsafe { moq_publication_announce(publication, &route) }, 0); let (announced, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); assert_eq!(info.route.hops_len, 0, "a local route claims no hops"); assert_eq!(info.route.cost, 7); assert_eq!(route_instance(&info.route).as_ref(), Some(&instance)); @@ -3675,14 +3673,27 @@ fn announce_route_carries_cost_and_instance_without_hops() { assert_eq!(moq_origin_close(origin), 0); } -/// Announcing under another instance is another stream: subscribers see a restart rather -/// than a stalled broadcast. +/// Announcing under another instance is another stream: the path stays listed, and a follower +/// is handed the new instance's broadcast. #[test] fn announce_under_a_new_instance_restarts() { let origin = id(moq_origin_create()); let cb = Callback::new(); let announced_task = id(unsafe { moq_origin_announced(origin, std::ptr::null(), Some(channel_callback), cb.ptr) }); let (publication, broadcast) = create_broadcast(origin, b"restarted"); + let follow_cb = Callback::new(); + let path = b"restarted"; + let follow = id(unsafe { + moq_origin_follow( + origin, + path.as_ptr() as *const c_char, + path.len(), + std::ptr::null(), + 0, + Some(channel_callback), + follow_cb.ptr, + ) + }); let first = fresh_instance(); assert_eq!( @@ -3690,22 +3701,26 @@ fn announce_under_a_new_instance_restarts() { 0 ); let (announced, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); assert_eq!(route_instance(&info.route), Some(first)); assert_eq!(moq_origin_announced_free(announced), 0); + let old = id(follow_cb.recv()); let second = fresh_instance(); assert_eq!( unsafe { moq_publication_announce(publication, &announce_route(0, &second)) }, 0 ); - let (announced, info) = cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_RESTART); - assert_eq!(route_instance(&info.route), Some(second)); - assert_eq!(moq_origin_announced_free(announced), 0); + let new = id(follow_cb.recv()); + assert_ne!(old, new); + assert_eq!(moq_origin_follow_cancel(follow), 0); + assert_eq!(follow_cb.recv_terminal(), 0); + assert_eq!(moq_consume_close(old), 0); + assert_eq!(moq_consume_close(new), 0); + // The path stayed present throughout: the cancel's terminal is the next callback. assert_eq!(moq_origin_announced_cancel(announced_task), 0); - assert_eq!(cb.recv_announce_terminal(), 0); + assert_eq!(cb.recv(), 0, "a restart is not listed"); assert_eq!(moq_publication_free(publication), 0); assert_eq!(moq_publish_close(broadcast), 0); assert_eq!(moq_origin_close(origin), 0); @@ -7242,7 +7257,7 @@ fn announce_route_hops_cross_a_relay_session() { }; assert_eq!(unsafe { moq_publication_announce(publication, &route) }, 0); let (announced, info) = announced_cb.recv_route(); - assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_START); + assert_eq!(info.kind, moq_announce_kind::MOQ_ANNOUNCE_KIND_PRESENT); assert_eq!( borrowed_string(info.prefix, info.prefix_len).as_deref(), Some("relayed") diff --git a/rs/moq-cli/src/announced.rs b/rs/moq-cli/src/announced.rs index 4839fbb6c4d..444c32bf5b7 100644 --- a/rs/moq-cli/src/announced.rs +++ b/rs/moq-cli/src/announced.rs @@ -228,7 +228,8 @@ mod tests { kio::clock::timeout(TIMEOUT, relay.follow(*path, None).unwrap().available()) .await .expect("relay routes the broadcast") - .expect("broadcast").unwrap(); + .expect("broadcast") + .unwrap(); } Self { diff --git a/rs/moq-cli/src/archive.rs b/rs/moq-cli/src/archive.rs index 496ecbb5125..59549918cda 100644 --- a/rs/moq-cli/src/archive.rs +++ b/rs/moq-cli/src/archive.rs @@ -70,6 +70,10 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp let hidden = prefix.split('/').any(|segment| segment.starts_with('.')); let prefix = moq_net::Path::new(&prefix)?; let mut announced = origin.clone().with_hidden(hidden).announced(); + // A follower per listed path, reporting each instance that serves it, stopped with the export. + let mut following = tokio::task::JoinSet::new(); + let mut followers: HashMap = HashMap::new(); + let (served, mut instances) = tokio::sync::mpsc::unbounded_channel::(); let mut recordings = tokio::task::JoinSet::new(); let mut running = Running::default(); let claims = Claims::default(); @@ -80,18 +84,25 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp loop { let instance = tokio::select! { event = announced.next() => { - let announce = match event.context("announcements ended")? { - // Another instance, or the same one announced again. - moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) => announce, - _ => continue, - }; - if !announce.prefix.has_prefix(&prefix) { - continue; + match event.context("announcements ended")? { + moq_net::announce::Event::Present(announce) if announce.prefix.has_prefix(&prefix) => { + let path = announce.prefix; + let follower = following.spawn(follow(origin.clone(), path.clone(), served.clone())); + if let Some(old) = followers.insert(path, follower) { + old.abort(); + } + } + moq_net::announce::Event::Absent(announce) => { + if let Some(follower) = followers.remove(&announce.prefix) { + follower.abort(); + } + } + moq_net::announce::Event::Present(_) => {} } - let Some(instance) = announce.route.instance else { - continue; - }; - let instance: Instance = (announce.prefix, instance); + continue; + } + Some(_) = following.join_next() => continue, + Some(instance) = instances.recv() => { if !running.start(&instance) { continue; } @@ -115,6 +126,26 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp } } +/// Report each instance serving `path` as it comes online or takes over. An instance comes +/// again after the path went offline, since a return is announced anew. +async fn follow( + origin: moq_net::origin::Consumer, + path: moq_net::Path, + served: tokio::sync::mpsc::UnboundedSender, +) { + let Ok(mut following) = origin.follow(&path, None) else { + return; + }; + while let Ok(change) = following.available().await { + let Some(instance) = change.and_then(|broadcast| broadcast.info().instance.clone()) else { + continue; + }; + if served.send((path.clone(), instance)).is_err() { + return; + } + } +} + /// The broadcasts being recorded. Announcements read after another instance took over all /// resolve that one, so it is recorded once. #[derive(Clone, Default)] diff --git a/rs/moq-cli/src/fetch.rs b/rs/moq-cli/src/fetch.rs index 97993ed4aa7..fcb2a56b140 100644 --- a/rs/moq-cli/src/fetch.rs +++ b/rs/moq-cli/src/fetch.rs @@ -122,7 +122,8 @@ async fn fetch_from( .follow(path, None)? .available() .await - .with_context(|| format!("broadcast `{}` not found", crate::display_name(path)))?; + .with_context(|| format!("broadcast `{}` not found", crate::display_name(path)))? + .context("went offline before serving")?; let track = broadcast.track(&args.track)?; let mut group = moq_relay::fetch_group(&track, args.group) .await diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 05a50fd36c0..f37ff0794de 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -982,7 +982,9 @@ async fn run_container( // rendition's `broadcast` field references (e.g. "./source") through the same origin. let mut follow = consumer.follow(name.as_str(), None)?; let broadcast = tokio::select! { - broadcast = follow.available() => broadcast.with_context(|| format!("failed to resolve broadcast `{name}`"))?, + broadcast = follow.available() => broadcast + .with_context(|| format!("failed to resolve broadcast `{name}`"))? + .context("went offline before serving")?, () = finish.cancelled() => return Ok(()), }; @@ -1405,7 +1407,8 @@ mod tests { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut track = broadcast .track("status") .unwrap() @@ -1515,7 +1518,8 @@ mod tests { .unwrap() .available() .await - .unwrap().unwrap() + .unwrap() + .unwrap() .track("live") .unwrap() .subscribe(None) diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index 74ac57e9d7f..ce5996d3474 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -1711,7 +1711,8 @@ pub(crate) mod tests { let consumer = kio::clock::timeout(WAIT, remote.consume().follow("pt.hang", None).unwrap().available()) .await .unwrap() - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut catalogs = hang::catalog::Catalog::<()>::subscribe(&consumer).await.unwrap(); let catalog = kio::clock::timeout(WAIT, catalogs.next()) .await @@ -2283,7 +2284,7 @@ pub(crate) mod tests { instance = async { loop { use moq_net::announce::Event; - if let Event::Start(announce) | Event::Restart(announce) = announced.next().await.unwrap() { + if let Event::Present(announce) = announced.next().await.unwrap() { break announce.route.instance.unwrap(); } } diff --git a/rs/moq-cli/src/report.rs b/rs/moq-cli/src/report.rs index a727eb3ad69..72dba5c8cab 100644 --- a/rs/moq-cli/src/report.rs +++ b/rs/moq-cli/src/report.rs @@ -417,7 +417,8 @@ pub async fn print_report(origin: moq_net::origin::Consumer, path: String) -> an .follow(path.as_str(), None)? .available() .await - .with_context(|| format!("failed to resolve broadcast `{path}`"))?; + .with_context(|| format!("failed to resolve broadcast `{path}`"))? + .context("went offline before serving")?; let source = moq_mux::Source::new(origin, broadcast.clone()); let mut catalog = Some(source.catalog::<()>(CatalogFormat::Hang).await?); @@ -488,12 +489,8 @@ async fn write_echo( event = announced.next() => { let event = event.context("announcements ended")?; let (announce, active) = match event { - // A restart is another publisher instance, which a reader still on the old one never sees. - moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) | moq_net::announce::Event::Present(announce) => { - (announce, true) - } + moq_net::announce::Event::Present(announce) => (announce, true), moq_net::announce::Event::Absent(announce) => (announce, false), - _ => continue, }; let path = announce.prefix; if !path.has_prefix(&prefix) || !hang::echo::is_echo(&path) { @@ -565,30 +562,57 @@ impl Readers { /// Send a line for each feedback snapshot the broadcast at `path` publishes, until it ends. async fn read_echo(origin: moq_net::origin::Consumer, path: moq_net::Path, lines: tokio::sync::mpsc::Sender) { - let read = async { - let broadcast = origin.request(&path, None).await?; - let subscriber = broadcast.track(hang::echo::TRACK)?.subscribe(None).await?; - let mut track = reader(subscriber); - while let Some(moq_net::Timed { value: feedback, .. }) = track.latest().await? { - let line = EchoLine { - broadcast: path.as_str(), - feedback, - }; - if lines - .send(format!("{}\n", serde_json::to_string(&line)?)) - .await - .is_err() - { - break; + let mut following = match origin.follow(&path, None) { + Ok(following) => following, + Err(err) => return tracing::debug!(%err, path = %path.as_str(), "stopped reading feedback"), + }; + // The instance being read; a restarted publisher replaces it, and going offline keeps it + // draining its final snapshot. + let mut reading = None; + loop { + tokio::select! { + change = following.available() => match change { + Ok(Some(broadcast)) => reading = Some(Box::pin(read_feedback(broadcast, path.clone(), lines.clone()))), + Ok(None) => {} + Err(err) => return tracing::debug!(%err, path = %path.as_str(), "stopped reading feedback"), + }, + read = async { reading.as_mut().expect("guarded").await }, if reading.is_some() => { + reading = None; + if let Err(err) = read { + tracing::debug!(%err, path = %path.as_str(), "stopped reading feedback"); + } + if lines.is_closed() { + return; + } } } - anyhow::Ok(()) - }; - if let Err(err) = read.await { - tracing::debug!(%err, path = %path.as_str(), "stopped reading feedback"); } } +/// Write one publisher instance's feedback to `lines` until its track ends or `lines` closes. +async fn read_feedback( + broadcast: moq_net::broadcast::Consumer, + path: moq_net::Path, + lines: tokio::sync::mpsc::Sender, +) -> anyhow::Result<()> { + let subscriber = broadcast.track(hang::echo::TRACK)?.subscribe(None).await?; + let mut track = reader(subscriber); + while let Some(moq_net::Timed { value: feedback, .. }) = track.latest().await? { + let line = EchoLine { + broadcast: path.as_str(), + feedback, + }; + if lines + .send(format!("{}\n", serde_json::to_string(&line)?)) + .await + .is_err() + { + break; + } + } + Ok(()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/rs/moq-cli/src/report/echo_test.rs b/rs/moq-cli/src/report/echo_test.rs index fc9e413a6f6..5d803d26135 100644 --- a/rs/moq-cli/src/report/echo_test.rs +++ b/rs/moq-cli/src/report/echo_test.rs @@ -30,7 +30,13 @@ async fn export_echo_reports_where_the_import_solicits() { import.decode(&CLIP[..HALF]).unwrap(); publication.announce(Default::default()).unwrap(); let consumer = origin.consume(); - let resolved = consumer.follow("demo", None).unwrap().available().await.unwrap().unwrap(); + let resolved = consumer + .follow("demo", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let args = SubscribeArgs { format: SubscribeFormat::Ts, diff --git a/rs/moq-cli/src/rtc.rs b/rs/moq-cli/src/rtc.rs index a91fccd9073..27e7055e016 100644 --- a/rs/moq-cli/src/rtc.rs +++ b/rs/moq-cli/src/rtc.rs @@ -121,7 +121,8 @@ pub async fn connect_export(origin: moq_net::origin::Consumer, url: Url, name: S .follow(name.as_str(), None)? .available() .await - .with_context(|| format!("failed to resolve broadcast `{name}`"))?; + .with_context(|| format!("failed to resolve broadcast `{name}`"))? + .context("went offline before serving")?; let source = moq_mux::Source::new(origin, broadcast); tracing::info!(url = %RedactedUrl::new(&url), %name, "WHIP client pushing"); diff --git a/rs/moq-cli/src/rtmp.rs b/rs/moq-cli/src/rtmp.rs index 180d190f7b4..f7975d7c0d7 100644 --- a/rs/moq-cli/src/rtmp.rs +++ b/rs/moq-cli/src/rtmp.rs @@ -176,7 +176,8 @@ pub async fn connect_export( .follow(&name, None)? .available() .await - .with_context(|| format!("failed to resolve broadcast `{name}`"))?; + .with_context(|| format!("failed to resolve broadcast `{name}`"))? + .context("went offline before serving")?; let source = moq_mux::Source::new(origin, broadcast); // The stream key is the ingest credential, so log the dial target and app instead. diff --git a/rs/moq-cli/tests/integration/export.rs b/rs/moq-cli/tests/integration/export.rs index f9447306104..af2c6a9a7e4 100644 --- a/rs/moq-cli/tests/integration/export.rs +++ b/rs/moq-cli/tests/integration/export.rs @@ -577,7 +577,8 @@ async fn the_same_instance_within_the_follow_continues() { let back = kio::clock::timeout(TIMEOUT, relay.origin.follow("demo", None).unwrap().available()) .await .expect("the relay observes the returning publication") - .unwrap().unwrap(); + .unwrap() + .unwrap(); assert_eq!(back.info().instance.as_ref(), Some(&instance)); assert!(!back.is_clone(&old), "the old relay copy was replaced"); for chunk in chunks { diff --git a/rs/moq-cli/tests/integration/instances.rs b/rs/moq-cli/tests/integration/instances.rs index 14a6040322a..d69d4125266 100644 --- a/rs/moq-cli/tests/integration/instances.rs +++ b/rs/moq-cli/tests/integration/instances.rs @@ -4,7 +4,7 @@ use std::time::Duration; use kio::clock::Instant; -use hang::moq_net::{self, Instance, Timestamp, announce, origin, track}; +use hang::moq_net::{self, Instance, Timestamp, origin, track}; use moq_mux::catalog::Stream; const LITE_07: &str = "moq-lite-07-wip"; @@ -160,7 +160,10 @@ async fn replacement(version: &str) { .established() .await .unwrap(); - assert!(matches!(catalog_follow.next().await, Some(origin::RouteEvent::Start(_)))); + assert!(matches!( + catalog_follow.next().await, + Some(origin::RouteEvent::Start(_)) + )); assert!(matches!(media_follow.next().await, Some(origin::RouteEvent::Start(_)))); let held = viewer.request("live/catalog.hang", None).await.unwrap(); diff --git a/rs/moq-e2ee/tests/transport.rs b/rs/moq-e2ee/tests/transport.rs index 62a69434a40..78fe7dfeb9a 100644 --- a/rs/moq-e2ee/tests/transport.rs +++ b/rs/moq-e2ee/tests/transport.rs @@ -57,7 +57,13 @@ async fn connect_protected(version: Version, track: &str) -> Fixture { // The subscriber knows the opaque path and takes the epoch from the announced route's // instance. A wire without instances leaves it to the application's own channel. let consumer = consumer_origin.consume(); - let remote = consumer.follow(&path, None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow(&path, None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); if version.to_string().starts_with("moq-lite-07") { assert_eq!( moq_e2ee::Epoch::of(&remote).as_ref(), diff --git a/rs/moq-ffi/src/origin.rs b/rs/moq-ffi/src/origin.rs index 040c3847f2a..f946f1c5b63 100644 --- a/rs/moq-ffi/src/origin.rs +++ b/rs/moq-ffi/src/origin.rs @@ -46,8 +46,8 @@ pub struct MoqAnnounceRoute { /// publisher is a new stream viewers restart onto. Set one only for a publisher that /// continues its group sequences across restarts and raises `epoch` on each: readers /// stitch every route of one instance together, so restarting the sequences under an - /// old instance splices unrelated groups into their tracks. Changing it is a - /// `MoqAnnounceEvent::Restart`. + /// old instance splices unrelated groups into their tracks. Changing it hands + /// `MoqFollowing` a new broadcast. #[uniffi(default = None)] pub instance: Option, /// Which run of a stable `instance` this is: only its highest epoch is eligible, cheaper @@ -218,7 +218,18 @@ struct Following { impl Following { async fn available(&mut self) -> Result, MoqError> { - let broadcast = self.driver.watch(async { Ok(self.inner.available().await?) }).await?; + // An end only precedes the next instance here: the old one's tracks end on their own, and + // the announcement stream reports the path's absence. + let broadcast = self + .driver + .watch(async { + loop { + if let Some(broadcast) = self.inner.available().await? { + return Ok(broadcast); + } + } + }) + .await?; Ok(Arc::new(MoqBroadcastConsumer::routed( broadcast, self.origin.clone(), @@ -257,37 +268,21 @@ impl From for MoqAnnounce { } } -/// What a [`MoqAnnounceConsumer`] yields. +/// 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. #[derive(Clone, Debug, PartialEq, Eq, uniffi::Enum)] pub enum MoqAnnounceEvent { - /// A route now covers the prefix; the stream had none there. - Start { - /// The broadcast announcement affected by this event. - announce: MoqAnnounce, - }, - /// The route covering the prefix changed hops or cost. - Update { - /// The broadcast announcement affected by this event. - announce: MoqAnnounce, - }, - /// No route covers the prefix any more. Carries its last advertised route. - End { - /// The broadcast announcement affected by this event. - announce: MoqAnnounce, - }, - /// Another publisher instance now serves the prefix: drop what was resolved under - /// it and request afresh. - Restart { - /// The broadcast announcement affected by this event. + /// A route now covers the path, which was absent. + Present { + /// The announcement that made the path present. announce: MoqAnnounce, }, - /// A route now covers the prefix and continues what the route at `predecessor` - /// served beneath it: keep what was resolved through that one. - Takeover { - /// The broadcast announcement affected by this event. + /// No route covers the path any more. Carries its last advertised route. + Absent { + /// The announcement that went. announce: MoqAnnounce, - /// The prefix of the route it continues, at or above `announce`'s. - predecessor: String, }, } @@ -295,21 +290,11 @@ impl From for MoqAnnounceEvent { fn from(event: moq_net::announce::Event) -> Self { use moq_net::announce::Event; match event { - Event::Start(announce) => Self::Start { - announce: announce.into(), - }, - Event::Update(announce) => Self::Update { - announce: announce.into(), - }, - Event::End(announce) => Self::End { - announce: announce.into(), - }, - Event::Restart(announce) => Self::Restart { + Event::Present(announce) => Self::Present { announce: announce.into(), }, - Event::Takeover { announce, predecessor } => Self::Takeover { + Event::Absent(announce) => Self::Absent { announce: announce.into(), - predecessor: predecessor.to_string(), }, } } diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index 39cb5a24998..d260138858c 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -263,7 +263,7 @@ async fn next_event(announced: &MoqAnnounceConsumer) -> MoqAnnounceEvent { /// The next newly announced route. async fn next_announced(announced: &MoqAnnounceConsumer) -> MoqAnnounce { match next_event(announced).await { - MoqAnnounceEvent::Start { announce } => announce, + MoqAnnounceEvent::Present { announce } => announce, other => panic!("expected an announcement, got {other:?}"), } } @@ -412,8 +412,7 @@ async fn announced_route_keeps_static_cost_on_reannounce() { // Reading an advertisement preserves its static production price. let announced = consumer.announced(MoqAnnounceConfig::default()).unwrap(); let route = loop { - if let MoqAnnounceEvent::Start { announce } | MoqAnnounceEvent::Update { announce } = - next_event(&announced).await + if let MoqAnnounceEvent::Present { announce } = next_event(&announced).await && announce.prefix == "priced-route" { break announce.route; @@ -457,10 +456,11 @@ fn instance_routes_parse_and_refuse() { } #[tokio::test] -async fn announced_restarts_on_a_new_instance() { +async fn following_restarts_on_a_new_instance() { let origin = MoqOriginProducer::new(MoqOriginConfig::default()); let consumer = origin.consume(); let announced = consumer.announced(MoqAnnounceConfig::default()).unwrap(); + let following = consumer.follow("instance-route".into(), None).unwrap(); let publication = origin.create_broadcast("instance-route".into()).unwrap(); let first = moq_net::Instance::random().to_string(); @@ -472,8 +472,10 @@ async fn announced_restarts_on_a_new_instance() { .unwrap(); let announce = next_announced(&announced).await; assert_eq!(announce.route.instance, first); + following.available().await.unwrap(); - // A new run of the same publisher is another instance: consumers restart onto it. + // A new run of the same publisher is another instance: followers restart onto it, while + // the path stays listed. let second = moq_net::Instance::random().to_string(); publication .announce(MoqAnnounceRoute { @@ -481,13 +483,16 @@ async fn announced_restarts_on_a_new_instance() { ..Default::default() }) .unwrap(); - match next_event(&announced).await { - MoqAnnounceEvent::Restart { announce } => { - assert_eq!(announce.prefix, "instance-route"); - assert_eq!(announce.route.instance, second); - } - other => panic!("expected a restart, got {other:?}"), - } + tokio::time::timeout(std::time::Duration::from_secs(1), following.available()) + .await + .expect("the new instance is handed out") + .unwrap(); + assert!( + tokio::time::timeout(std::time::Duration::from_millis(100), announced.next()) + .await + .is_err(), + "a restart is not listed" + ); publication.broadcast().close().unwrap(); } @@ -3253,7 +3258,7 @@ async fn create_broadcast_is_invisible_until_announced() { .expect("announce reaches the cursor") .expect("the cursor is still open"); assert!( - matches!(&update, MoqAnnounceEvent::Start { announce } if announce.prefix == "live"), + matches!(&update, MoqAnnounceEvent::Present { announce } if announce.prefix == "live"), "{update:?}" ); publication.broadcast().close().unwrap(); @@ -3679,8 +3684,8 @@ async fn announce_and_unannounce_toggles_discovery() { async fn wait_live(announced: &MoqAnnounceConsumer, active: bool) { loop { match next_event(announced).await { - MoqAnnounceEvent::Start { announce } if active && announce.prefix == "live" => return, - MoqAnnounceEvent::End { announce } if !active && announce.prefix == "live" => return, + MoqAnnounceEvent::Present { announce } if active && announce.prefix == "live" => return, + MoqAnnounceEvent::Absent { announce } if !active && announce.prefix == "live" => return, _ => {} } } @@ -4626,7 +4631,7 @@ fn close_twice_is_a_noop() { /// Wait for the announcement of `path` to end, failing the test if it doesn't. async fn await_unannounced(announced: &MoqAnnounceConsumer) { match next_event(announced).await { - MoqAnnounceEvent::End { .. } => {} + MoqAnnounceEvent::Absent { .. } => {} other => panic!("expected the announcement to end, got {other:?}"), } } @@ -5873,7 +5878,7 @@ fn without_runtime() { let announced = consumer.announced(MoqAnnounceConfig::default()).unwrap(); let announcement = match pollster::block_on(announced.next()).unwrap().unwrap() { - MoqAnnounceEvent::Start { announce } => announce, + MoqAnnounceEvent::Present { announce } => announce, other => panic!("expected an announcement, got {other:?}"), }; assert_eq!(announcement.prefix, "test"); @@ -6085,7 +6090,7 @@ async fn server_client_run_end(version: &str) { // The announcement, not the track's error, ends the run. match next_event(&announced).await { - MoqAnnounceEvent::End { announce } => assert_eq!(announce.prefix, "hello"), + MoqAnnounceEvent::Absent { announce } => assert_eq!(announce.prefix, "hello"), other => panic!("{version}: expected the run's end, got {other:?}"), } diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index add7eb64d8b..11decaaf04e 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -3912,7 +3912,9 @@ mod session_tests { /// Follow `room` on `origin` past its start. fn announced(origin: &moq_net::origin::Producer) -> moq_net::origin::Routes { let mut follow = watch(origin, "room"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); follow } @@ -4033,9 +4035,13 @@ mod session_tests { let mut first = Publisher::sibling(&origin, Default::default()); let pad = recorder.written(&mut first, 1); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::End(_)) + }); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad"); @@ -4125,11 +4131,17 @@ mod session_tests { let pad = recorder.written(&mut first, 1); first.video.finish().unwrap(); await_finished(&first); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); first.publication.as_ref().unwrap().unannounce(); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::End(_)) + }); first.publication.as_ref().unwrap().announce(route).unwrap(); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!( @@ -4204,9 +4216,13 @@ mod session_tests { let pad = recorder.written(&mut first, 1); room.catalog.finish().unwrap(); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::End(_)) + }); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad"); @@ -4481,7 +4497,9 @@ mod session_tests { let unpinned = recorder.written(&mut second, 2); let pad = played.into_iter().find(|pad| *pad != unpinned).unwrap(); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); drop(second); await_event(&mut follow, |event| { matches!( @@ -4536,9 +4554,13 @@ mod session_tests { let mut first = Publisher::sibling(&origin, Default::default()); let pad = recorder.written(&mut first, 1); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::End(_)) + }); room.catalog.modify().unwrap().video.renditions.clear(); for _ in 0..200 { @@ -4553,7 +4575,9 @@ mod session_tests { ); let mut second = Publisher::sibling(&origin, Default::default()); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); for _ in 0..10 { second.write(2); block(Duration::from_millis(50)); @@ -4578,9 +4602,13 @@ mod session_tests { let mut first = Publisher::sibling(&origin, Default::default()); let pad = recorder.written(&mut first, 1); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::End(_)) + }); let listed = room.catalog.modify().unwrap().video.renditions.clone(); room.catalog.modify().unwrap().video.renditions.clear(); @@ -4654,7 +4682,9 @@ mod session_tests { // The reference lets the old instance go once another wins its path, and only then // does the new one leave, so the return is a resume rather than a missed restart. let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); let mut new = Publisher::sibling(&origin, Default::default()); await_event(&mut follow, |event| { matches!(event, moq_net::origin::RouteEvent::Restart(_)) diff --git a/rs/moq-hls/src/export/mod.rs b/rs/moq-hls/src/export/mod.rs index 89bc8942995..1bc835d35bf 100644 --- a/rs/moq-hls/src/export/mod.rs +++ b/rs/moq-hls/src/export/mod.rs @@ -2345,7 +2345,8 @@ mod tests { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let source = crate::resolved(consuming, "live").await; let broadcaster = (!late).then(|| Broadcaster::spawned(source.clone(), Config::default())); for i in 0..20u64 { diff --git a/rs/moq-hls/src/server/mod.rs b/rs/moq-hls/src/server/mod.rs index 483153b7c42..41c9b039557 100644 --- a/rs/moq-hls/src/server/mod.rs +++ b/rs/moq-hls/src/server/mod.rs @@ -227,7 +227,10 @@ impl Server { return Some(followed.clone()); } - let instances = self.inner.origin.follow(name, None) + let instances = self + .inner + .origin + .follow(name, None) .map_err(|err| tracing::warn!(%err, %name, "failed to follow broadcast")) .ok()?; // A request answers once the origin has synced with the relay, so a path with no route diff --git a/rs/moq-hls/tests/integration/server.rs b/rs/moq-hls/tests/integration/server.rs index eb0a0d1bacf..bc87bd6322a 100644 --- a/rs/moq-hls/tests/integration/server.rs +++ b/rs/moq-hls/tests/integration/server.rs @@ -53,7 +53,8 @@ async fn a_cursor_records_a_publisher_without_fetch() { let remote = kio::clock::timeout(TIMEOUT, origin.follow("live", None).unwrap().available()) .await .expect("request timed out") - .expect("remote broadcast").unwrap(); + .expect("remote broadcast") + .unwrap(); let (broadcaster, driver) = Broadcaster::new(moq_mux::Source::new(origin, remote), Default::default()).unwrap(); tokio::spawn(driver.run()); // Recorded as soon as the catalog lists it with its records, as a recorder does. @@ -174,7 +175,8 @@ async fn a_sibling_resolves_through_a_client_session() { let broadcast = kio::clock::timeout(TIMEOUT, origin.follow("room/live", None).unwrap().available()) .await .expect("catalog resolve timed out") - .expect("catalog broadcast").unwrap(); + .expect("catalog broadcast") + .unwrap(); let source = moq_mux::Source::new(origin, broadcast); let sibling = kio::clock::timeout( TIMEOUT, @@ -230,7 +232,8 @@ async fn a_disconnected_sibling_publisher_answers_404() { ) .await .expect("sibling resolve timed out") - .expect("sibling broadcast").unwrap(); + .expect("sibling broadcast") + .unwrap(); // Only the sibling goes: the catalog keeps listing the rendition, so the request reaches the // media fetch rather than missing the rendition. media_broadcast.close(); diff --git a/rs/moq-mux/src/container/source.rs b/rs/moq-mux/src/container/source.rs index 1ab31886fd2..fb19e6a38b3 100644 --- a/rs/moq-mux/src/container/source.rs +++ b/rs/moq-mux/src/container/source.rs @@ -1101,7 +1101,13 @@ mod tests { .unwrap(); broadcast.announce(Default::default()).unwrap(); let consumer = subscriber.consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let source = crate::Source::new(consumer, remote); let mut export = ExportSource::for_audio(&source, "audio", &audio(None), Duration::from_secs(1)) .unwrap() @@ -1178,7 +1184,13 @@ mod tests { .unwrap(); broadcast.announce(Default::default()).unwrap(); let consumer = subscriber.consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let source = crate::Source::new(consumer, remote); // MPEG-1 audio from TS: one 24 ms frame per group, a PES of five written at once. diff --git a/rs/moq-mux/src/container/ts/export_test.rs b/rs/moq-mux/src/container/ts/export_test.rs index c360cf81081..3ae8f46cb36 100644 --- a/rs/moq-mux/src/container/ts/export_test.rs +++ b/rs/moq-mux/src/container/ts/export_test.rs @@ -8812,7 +8812,8 @@ async fn same_instance_returns(finish: bool) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); let mut export = export.follow(back, stream).unwrap(); frames.extend(drain_frames(&mut export).await); @@ -8890,7 +8891,8 @@ async fn a_return_keeps_catalog_and_group_history() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); assert_eq!(back.info().instance.as_ref(), Some(&instance)); assert!(!back.is_clone(&old), "the withdrawn front is replaced"); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); @@ -9174,7 +9176,8 @@ async fn export_stats_count_only_returned_output() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); let mut export = export.follow(back, stream).unwrap(); for ms in (1_000..1_200).step_by(20) { @@ -11315,7 +11318,8 @@ async fn a_track_renamed_on_its_pid_across_returns_retires_the_one_before() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); export = export.follow(back, stream).unwrap(); drain_frames(&mut export).await; @@ -11381,7 +11385,8 @@ async fn a_track_renamed_on_its_pid_across_a_return_is_quiet_from_its_listing() .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&back, Default::default()).await.unwrap(); let mut export = export.follow(back, stream).unwrap(); drain_frames(&mut export).await; @@ -11787,7 +11792,8 @@ async fn an_expired_follow_stops_healthy_input_but_drains_its_buffered_tail() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); @@ -11944,7 +11950,8 @@ async fn a_replacement_leaving_before_it_commits_keeps_the_old_program() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); @@ -12074,7 +12081,8 @@ async fn an_empty_finished_replacement_drains_the_old_program() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&replacement, Default::default()) .await .unwrap(); @@ -12132,7 +12140,8 @@ async fn cold_same_instance_return(pending: bool) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); @@ -12162,7 +12171,8 @@ async fn cold_same_instance_return(pending: bool) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let stream = crate::catalog::Consumer::new(&target, Default::default()) .await .unwrap(); diff --git a/rs/moq-mux/src/source.rs b/rs/moq-mux/src/source.rs index bfd3907f889..b1f0f126c5f 100644 --- a/rs/moq-mux/src/source.rs +++ b/rs/moq-mux/src/source.rs @@ -506,7 +506,14 @@ fn poll_first( waiter: &kio::Waiter, ) -> Poll> { let result = match following { - Ok(following) => ready!(following.poll_available(waiter)), + // The first change is always an instance: an end follows only one handed out. + Ok(following) => loop { + match ready!(following.poll_available(waiter)) { + Ok(Some(broadcast)) => break Ok(broadcast), + Ok(None) => continue, + Err(err) => break Err(err), + } + }, Err(err) => Err(err.clone()), }; if let Err(err) = &result { @@ -708,6 +715,7 @@ mod tests { let catalog = kio::clock::timeout(timeout, consumer.follow("a/pub", None).unwrap().available()) .await .expect("the catalog resolves") + .unwrap() .unwrap(); let source = Source::new(consumer, catalog); let sibling = kio::clock::timeout(timeout, source.resolve(Some(&Relative::new("./source").unwrap()), None)) diff --git a/rs/moq-net-tests/tests/announce_allocs.rs b/rs/moq-net-tests/tests/announce_allocs.rs index 5e04eeaa706..643ff25699b 100644 --- a/rs/moq-net-tests/tests/announce_allocs.rs +++ b/rs/moq-net-tests/tests/announce_allocs.rs @@ -281,7 +281,8 @@ async fn a_lite_request_keeps_one_copy_of_its_track_name() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); WATCH.with(|watch| watch.set(TRACK.len())); SIZED.with(|sized| sized.set((0, 0))); let subscriber = remote.track(TRACK).unwrap().subscribe(None).await.unwrap(); diff --git a/rs/moq-net-tests/tests/integration/ietf_conformance.rs b/rs/moq-net-tests/tests/integration/ietf_conformance.rs index fef01dc6666..212f968b719 100644 --- a/rs/moq-net-tests/tests/integration/ietf_conformance.rs +++ b/rs/moq-net-tests/tests/integration/ietf_conformance.rs @@ -62,7 +62,8 @@ async fn routing(version: &str, cluster: bool) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut subscription = remote.track("test").unwrap().subscribe(None).await.unwrap(); crate::support::harness::subscribed(&track).await; let mut group = track.append_group().unwrap(); diff --git a/rs/moq-net-tests/tests/integration/refresh.rs b/rs/moq-net-tests/tests/integration/refresh.rs index ff0c7fb1192..00ca38f7f3e 100644 --- a/rs/moq-net-tests/tests/integration/refresh.rs +++ b/rs/moq-net-tests/tests/integration/refresh.rs @@ -48,7 +48,8 @@ async fn json_snapshot_refresh_crosses_a_two_relay_cluster() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let remote = remote.track("state").unwrap(); let mut baseline = remote.subscribe(None).await.unwrap(); assert_eq!(baseline.info().refresh, Some(ratio)); @@ -166,7 +167,14 @@ async fn ratio_joins_cross_two_relays() { options.client_subscribe = Some(downstream.clone()); links.push(connect_mock(options).await); } - let remote = b.consume().follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = b + .consume() + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let remote = remote.track("data").unwrap(); let mut baseline = remote.subscribe(None).await.unwrap(); assert_eq!(baseline.info().refresh, (name == "moq-lite-07-wip").then_some(1)); diff --git a/rs/moq-net/benches/announce.rs b/rs/moq-net/benches/announce.rs index 61049c23176..ca59f4e4080 100644 --- a/rs/moq-net/benches/announce.rs +++ b/rs/moq-net/benches/announce.rs @@ -20,6 +20,7 @@ use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, use moq_net::{ Hop, Hops, Path, announce, fuzz::{AnnounceWriter, Announced, decode_announces, encode_announces}, + origin, }; // Compile the actual private replay code, as the priority bench does for its queue. diff --git a/rs/moq-net/benches/interests.rs b/rs/moq-net/benches/interests.rs index 7598c3c4e3e..bd88a09630a 100644 --- a/rs/moq-net/benches/interests.rs +++ b/rs/moq-net/benches/interests.rs @@ -15,7 +15,7 @@ //! Run with `cargo bench -p moq-net --features fuzz --bench interests`. use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use moq_net::{Hop, Pattern, Patterns, announce, fuzz, origin}; +use moq_net::{Hop, Pattern, Patterns, fuzz, origin}; /// `(watches, sessions)` shapes. const SHAPES: [(usize, usize); 4] = [(10, 10), (1_000, 10), (10, 1_000), (1_000, 1_000)]; diff --git a/rs/moq-net/benches/memory.rs b/rs/moq-net/benches/memory.rs index d06c96afb51..e57868835ac 100644 --- a/rs/moq-net/benches/memory.rs +++ b/rs/moq-net/benches/memory.rs @@ -155,7 +155,13 @@ impl Link { broadcast.announce(Default::default()).unwrap(); let consumer = subscriber.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut subscribers = Vec::new(); for index in 0..streams { let track = remote.track(&format!("{index}")).unwrap(); diff --git a/rs/moq-net/benches/origin.rs b/rs/moq-net/benches/origin.rs index 6f31ddb5fce..898e1ffe734 100644 --- a/rs/moq-net/benches/origin.rs +++ b/rs/moq-net/benches/origin.rs @@ -51,7 +51,7 @@ use std::time::Duration; use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; use futures::FutureExt; -use moq_net::{Hop, Hops, Instance, Pattern, Patterns, Timestamp, announce, auth, broadcast, kio, origin, track}; +use moq_net::{Hop, Hops, Instance, Pattern, Patterns, Timestamp, auth, broadcast, kio, origin, track}; use support::harness::{MockConnectOptions, MockPair, connect_mock}; /// A millisecond track: the frames written here carry timestamps. @@ -1166,7 +1166,8 @@ async fn watching(routes: usize, subscribers: usize) -> Watching { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let subscription = remote.track("video").unwrap().subscribe(None).await.unwrap(); subscriptions.push(subscription); } diff --git a/rs/moq-net/benches/path.rs b/rs/moq-net/benches/path.rs index 648f204f281..26d8665e784 100644 --- a/rs/moq-net/benches/path.rs +++ b/rs/moq-net/benches/path.rs @@ -14,7 +14,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use futures::FutureExt; use moq_net::{ - Hop, Hops, Path, Pattern, Patterns, announce, + Hop, Hops, Path, Pattern, Patterns, fuzz::{Announced, Messages, decode_announces, decode_namespaces, encode_announces, encode_namespaces}, kio, origin, }; diff --git a/rs/moq-net/benches/session/mod.rs b/rs/moq-net/benches/session/mod.rs index 06247231cc3..dafaebf8f60 100644 --- a/rs/moq-net/benches/session/mod.rs +++ b/rs/moq-net/benches/session/mod.rs @@ -720,7 +720,8 @@ impl Viewer { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); for track in tracks { self.subscribers.push( broadcast @@ -790,7 +791,8 @@ impl Room { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); viewer.fetches.push((broadcast, source.track(TRACK).unwrap())); } else { viewer.watch(&path(broadcast), &[TRACK], shape.subscription()).await; @@ -1596,7 +1598,8 @@ impl ChurnRoom { .unwrap() .available() .await - .unwrap().unwrap(), + .unwrap() + .unwrap(), ); viewers.push(viewer); } diff --git a/rs/moq-net/benches/stats.rs b/rs/moq-net/benches/stats.rs index 846cffdbb61..e04d3e28b30 100644 --- a/rs/moq-net/benches/stats.rs +++ b/rs/moq-net/benches/stats.rs @@ -6,7 +6,7 @@ use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; use futures::FutureExt; -use moq_net::{announce, fuzz, origin, stats, transport}; +use moq_net::{fuzz, origin, stats, transport}; /// `(broadcasts, tiers)` shapes; every broadcast records under every tier. const SHAPES: [(usize, usize); 4] = [(100, 1), (1_000, 1), (100, 10), (1_000, 10)]; diff --git a/rs/moq-net/benches/synced.rs b/rs/moq-net/benches/synced.rs index cf4b92678f3..e30640b2fa2 100644 --- a/rs/moq-net/benches/synced.rs +++ b/rs/moq-net/benches/synced.rs @@ -14,7 +14,7 @@ //! Run with `cargo bench -p moq-net --features fuzz --bench synced`. use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use moq_net::{Hop, Pattern, Patterns, announce, fuzz, origin}; +use moq_net::{Hop, Pattern, Patterns, fuzz, origin}; /// `(streams, consumers)` shapes. const SHAPES: [(usize, usize); 4] = [(10, 10), (1_000, 10), (10, 1_000), (1_000, 1_000)]; diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 494c5996500..39e8ae976a5 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -1498,9 +1498,13 @@ impl AnnounceRun { }; let (update, active, restart, predecessor) = match next { - Some(origin::RouteEvent::Start(update) | origin::RouteEvent::Update(update)) => (update, true, false, None), + Some(origin::RouteEvent::Start(update) | origin::RouteEvent::Update(update)) => { + (update, true, false, None) + } Some(origin::RouteEvent::Restart(update)) => (update, true, true, None), - Some(origin::RouteEvent::Takeover { announce, predecessor }) => (announce, true, false, Some(predecessor)), + Some(origin::RouteEvent::Takeover { announce, predecessor }) => { + (announce, true, false, Some(predecessor)) + } Some(origin::RouteEvent::End(update)) => (update, false, false, None), None => { if self.initial.take().is_some() { @@ -7138,7 +7142,14 @@ mod serve_group_test { broadcast.announce(Default::default()).unwrap(); let relay = origin(2); let _upstream = connect(version, &publisher, &relay).await; - let remote = relay.consume().follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = relay + .consume() + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut keeper = match warm { true => Some( remote @@ -7169,7 +7180,8 @@ mod serve_group_test { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut live = remote .track("test") .unwrap() diff --git a/rs/moq-net/src/model/announced.rs b/rs/moq-net/src/model/announced.rs index 63a63980b78..e1499eb283d 100644 --- a/rs/moq-net/src/model/announced.rs +++ b/rs/moq-net/src/model/announced.rs @@ -179,7 +179,9 @@ mod tests { assert_eq!(listed(&mut announced).await, "present live"); assert!(matches!(routes.next().await, Some(RouteEvent::Start(_)))); - first.announce(route(&Instance::random()).with_cost(Cost::new(5))).unwrap(); + first + .announce(route(&Instance::random()).with_cost(Cost::new(5))) + .unwrap(); quiet(&mut announced).await; // The relay-level stream still reports the replacement. assert!(matches!(routes.next().await, Some(RouteEvent::Restart(_)))); diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index 102a3894614..998aaa8d1fa 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -1,7 +1,7 @@ use std::task::{Poll, ready}; use super::WeakEntry; -use super::origin_impl::{Announce, Routes, RouteEvent, Consumer, Moved, Requesting}; +use super::origin_impl::{Announce, Consumer, Moved, Requesting, RouteEvent, Routes}; use crate::{Error, Instance, Path, broadcast}; /// The announcements covering one path, as one broadcast coming online, being replaced, and @@ -671,10 +671,7 @@ mod tests { available(&mut announced).await.info().instance.as_ref(), Some(&instance) ); - assert_eq!( - available(&mut unpinned).await.info().instance.as_ref(), - Some(&instance) - ); + assert_eq!(available(&mut unpinned).await.info().instance.as_ref(), Some(&instance)); } /// A follower started before anything serves the path waits for it, reports its end, and diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index ec80dbecd33..93e76492fac 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -7988,10 +7988,7 @@ mod tests { let announced = producer.consume().routes(); let _stats = producer.snapshot(".stats"); assert!(announced.is_synced(), "a snapshot in flight under a hidden segment"); - assert!( - producer.consume().routes().is_synced(), - "a reader registering past one" - ); + assert!(producer.consume().routes().is_synced(), "a reader registering past one"); assert!(!producer.consume().with_hidden(true).routes().is_synced()); } @@ -14259,10 +14256,7 @@ mod tests { let mut selected = project.routes(); selected.expect_next_active(".svc/.private/lobby.chat").await; selected.assert_next_wait(); - let mut inside = project - .scope(".svc", &Patterns::from(Pattern::all())) - .unwrap() - .routes(); + let mut inside = project.scope(".svc", &Patterns::from(Pattern::all())).unwrap().routes(); inside.expect_next_active(".private/lobby.chat").await; inside.assert_next_wait(); let live = producer.announce(".svc/p1/lobby.chat", Route::default()).unwrap(); diff --git a/rs/moq-net/tests/integration/auth.rs b/rs/moq-net/tests/integration/auth.rs index c9fe92e4d7b..c81c89fcf10 100644 --- a/rs/moq-net/tests/integration/auth.rs +++ b/rs/moq-net/tests/integration/auth.rs @@ -1104,7 +1104,8 @@ async fn exact_and_subtree_grants_admit_their_broadcast(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let prefs = moq_net::track::Subscription::default() .with_delay(moq_net::track::Delay::default().with_max(Duration::from_secs(10))); let mut sub = remote.track("video").unwrap().subscribe(prefs).await.unwrap(); @@ -1166,7 +1167,8 @@ async fn a_live_subscription_survives_union_renewal(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut group = published.append_group().unwrap(); group .write_frame(moq_net::Timestamp::from_millis(0).unwrap(), b"first".as_ref()) @@ -1246,7 +1248,8 @@ async fn a_revoked_grant_cancels_its_subscriptions(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut down_sub = remote.track("video").unwrap().subscribe(prefs()).await.unwrap(); down_sub.recv_group().await.unwrap().unwrap(); @@ -1256,7 +1259,8 @@ async fn a_revoked_grant_cancels_its_subscriptions(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut up_sub = remote.track("video").unwrap().subscribe(prefs()).await.unwrap(); up_sub.recv_group().await.unwrap().unwrap(); @@ -1638,7 +1642,8 @@ async fn a_narrowing_deafens_one_path(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut audio_sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); audio_sub.recv_group().await.unwrap().unwrap(); let remote = received @@ -1647,7 +1652,8 @@ async fn a_narrowing_deafens_one_path(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut video_sub = remote.track("h264").unwrap().subscribe(prefs()).await.unwrap(); video_sub.recv_group().await.unwrap().unwrap(); @@ -1726,7 +1732,8 @@ async fn a_narrowing_aborts_what_the_peer_published(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut mic_sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); mic_sub.recv_group().await.unwrap().unwrap(); let remote = relay @@ -1735,7 +1742,8 @@ async fn a_narrowing_aborts_what_the_peer_published(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut cam_sub = remote.track("h264").unwrap().subscribe(prefs()).await.unwrap(); cam_sub.recv_group().await.unwrap().unwrap(); @@ -1786,7 +1794,8 @@ async fn a_narrowing_resets_a_fetch_in_flight(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut fetched = remote.track("video").unwrap().fetch_group(0, None).await.unwrap(); let frame = fetched.read_frame().await.unwrap().expect("first frame"); assert_eq!(frame.payload.as_ref(), b"first"); @@ -1857,7 +1866,8 @@ async fn a_widening_brings_back_a_deafened_path(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); sub.recv_group().await.unwrap().unwrap(); @@ -1875,7 +1885,8 @@ async fn a_widening_brings_back_a_deafened_path(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); let mut group = audio_track.append_group().unwrap(); group.write_frame(ts(1), b"a".as_ref()).unwrap(); @@ -1933,7 +1944,8 @@ async fn a_widening_brings_back_what_the_peer_published(version: &'static str) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = remote.track("opus").unwrap().subscribe(prefs()).await.unwrap(); let mut group = mic_track.append_group().unwrap(); group.write_frame(ts(0), b"m".as_ref()).unwrap(); diff --git a/rs/moq-net/tests/integration/broadcast_close.rs b/rs/moq-net/tests/integration/broadcast_close.rs index 6a7fe549632..12b8087d2f1 100644 --- a/rs/moq-net/tests/integration/broadcast_close.rs +++ b/rs/moq-net/tests/integration/broadcast_close.rs @@ -30,7 +30,8 @@ async fn close_then_lookup(publisher: moq_net::origin::Producer, reader: moq_net let handle = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); handle.track("video").expect("a live broadcast serves its track"); broadcast.close(); diff --git a/rs/moq-net/tests/integration/catalog_acquisition.rs b/rs/moq-net/tests/integration/catalog_acquisition.rs index 944ba91f8f0..413282e2b71 100644 --- a/rs/moq-net/tests/integration/catalog_acquisition.rs +++ b/rs/moq-net/tests/integration/catalog_acquisition.rs @@ -38,7 +38,8 @@ async fn acquisition(version: &str, carries_instance: bool) { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut announced = subscriber.consume().routes(); let old_cost = match announced.next().await { Some(moq_net::origin::RouteEvent::Start(announce)) => announce.route.cost, diff --git a/rs/moq-net/tests/integration/compress.rs b/rs/moq-net/tests/integration/compress.rs index c23dab56eef..0617c80f830 100644 --- a/rs/moq-net/tests/integration/compress.rs +++ b/rs/moq-net/tests/integration/compress.rs @@ -101,7 +101,13 @@ async fn relay(published: Published, hops: [&str; 2], subscription: moq_net::tra let downstream = connect_mock(options).await; let consumer = origin.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let subscriber = remote.track("data").unwrap().subscribe(subscription).await.unwrap(); support::harness::subscribed(&track).await; @@ -292,7 +298,13 @@ async fn datagrams_meter_the_bytes_on_the_wire() { let downstream = connect_mock(options).await; let consumer = origin.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut subscriber = remote.track("data").unwrap().subscribe(None).await.unwrap(); support::harness::subscribed(&track).await; @@ -396,7 +408,8 @@ async fn ietf_fetch_keeps_the_stored_form() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let consumer = remote.track("data").unwrap(); assert!(consumer.info().await.unwrap().compress, "{version}"); let mut fetched = consumer.fetch_group(0, moq_net::group::Fetch::default()).await.unwrap(); diff --git a/rs/moq-net/tests/integration/control_stats.rs b/rs/moq-net/tests/integration/control_stats.rs index 10df93a6b06..fcf0ea05e5b 100644 --- a/rs/moq-net/tests/integration/control_stats.rs +++ b/rs/moq-net/tests/integration/control_stats.rs @@ -43,7 +43,8 @@ async fn control_classes_cross_lite_and_ietf_sessions_without_counting_payload() .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); subscribed(&track).await; let mut group = track.append_group().unwrap(); diff --git a/rs/moq-net/tests/integration/datagram.rs b/rs/moq-net/tests/integration/datagram.rs index f8a41470a91..bd95b520246 100644 --- a/rs/moq-net/tests/integration/datagram.rs +++ b/rs/moq-net/tests/integration/datagram.rs @@ -54,7 +54,13 @@ async fn connect_datagram_track() -> Fixture { let pair = connect_mock(options).await; let consumer = consumer_origin.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let subscriber = remote.track("datagrams").unwrap().subscribe(None).await.unwrap(); // The subscriber is handed over once TRACK_INFO answers, before its SUBSCRIBE reaches // the publisher, and a datagram only goes to a subscription already there. @@ -143,7 +149,13 @@ async fn ietf_delivers_datagrams_on(version: &str) { let _pair = connect_mock(options).await; let consumer = consumer_origin.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut subscriber = remote.track("datagrams").unwrap().subscribe(None).await.unwrap(); // A group first, so the subscription's alias is bound before any datagram lands. @@ -246,7 +258,13 @@ async fn a_fetched_datagram_is_refused_per_version() { let sequence = producer.append_datagram(Timestamp::ZERO, &b"x"[..]).unwrap(); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let err = match remote.track("datagrams").unwrap().fetch_group(sequence, None).await { Ok(_) => panic!("{versions:?}: a datagram was fetched"), Err(err) => err, diff --git a/rs/moq-net/tests/integration/empty_group.rs b/rs/moq-net/tests/integration/empty_group.rs index acd8375fee5..e8939361e74 100644 --- a/rs/moq-net/tests/integration/empty_group.rs +++ b/rs/moq-net/tests/integration/empty_group.rs @@ -39,7 +39,8 @@ async fn an_empty_group_arrives_empty() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut sub = kio::clock::timeout(TIMEOUT, remote.track("data").unwrap().subscribe(None)) .await .expect("subscribe timeout") diff --git a/rs/moq-net/tests/integration/errored_end.rs b/rs/moq-net/tests/integration/errored_end.rs index 6387b307e7c..ab6f46ef6e7 100644 --- a/rs/moq-net/tests/integration/errored_end.rs +++ b/rs/moq-net/tests/integration/errored_end.rs @@ -99,7 +99,8 @@ async fn an_errored_end_keeps_its_history_across_a_hop() { let remote = kio::clock::timeout(TIMEOUT, subscriber.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); session.server_transport.split_unis(); if subscribe_first { diff --git a/rs/moq-net/tests/integration/fastest_reader.rs b/rs/moq-net/tests/integration/fastest_reader.rs index 08bf9ea61fd..858963dc0f6 100644 --- a/rs/moq-net/tests/integration/fastest_reader.rs +++ b/rs/moq-net/tests/integration/fastest_reader.rs @@ -46,7 +46,8 @@ async fn relay(version: &str) -> Relay { let remote = kio::clock::timeout(TIMEOUT, relay.consume().follow("live", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let subscriber = kio::clock::timeout( TIMEOUT, remote.track("data").unwrap().subscribe( diff --git a/rs/moq-net/tests/integration/fetch_fanout.rs b/rs/moq-net/tests/integration/fetch_fanout.rs index 8f1eb318557..0288444bf41 100644 --- a/rs/moq-net/tests/integration/fetch_fanout.rs +++ b/rs/moq-net/tests/integration/fetch_fanout.rs @@ -44,7 +44,8 @@ async fn sequential_viewers_share_the_relays_fetched_groups() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); viewers.push((viewer, pair, remote)); } for round in 0..3 { diff --git a/rs/moq-net/tests/integration/fetch_from_feed.rs b/rs/moq-net/tests/integration/fetch_from_feed.rs index 66659fbb5cf..e912b320558 100644 --- a/rs/moq-net/tests/integration/fetch_from_feed.rs +++ b/rs/moq-net/tests/integration/fetch_from_feed.rs @@ -49,7 +49,8 @@ async fn relay(version: &str) -> Relay { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); Relay { track, remote, diff --git a/rs/moq-net/tests/integration/fetch_only.rs b/rs/moq-net/tests/integration/fetch_only.rs index 84e7842d64c..c5f2fe9c9ea 100644 --- a/rs/moq-net/tests/integration/fetch_only.rs +++ b/rs/moq-net/tests/integration/fetch_only.rs @@ -33,7 +33,8 @@ async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Cons kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() } /// Publish a finished track of three groups, and flag any subscription it ever gets. diff --git a/rs/moq-net/tests/integration/fetch_pipeline.rs b/rs/moq-net/tests/integration/fetch_pipeline.rs index 9c32040f15e..cc792354fb7 100644 --- a/rs/moq-net/tests/integration/fetch_pipeline.rs +++ b/rs/moq-net/tests/integration/fetch_pipeline.rs @@ -68,7 +68,8 @@ async fn fetch_ahead( let remote = kio::clock::timeout(TIMEOUT, upstream.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let fetching = kio::clock::sim::spawn(async move { remote.track("video").unwrap().fetch_group(0, None).await }); let request = kio::clock::timeout(TIMEOUT, dynamic.requested_track()) @@ -156,7 +157,8 @@ async fn first_fetch(version: &str, relays: u64, rtt: Duration) -> Duration { let remote = kio::clock::timeout(TIMEOUT, upstream.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let start = kio::clock::now(); let mut fetched = kio::clock::timeout(TIMEOUT, remote.track("video").unwrap().fetch_group(0, None)) .await diff --git a/rs/moq-net/tests/integration/finished_broadcast_mock.rs b/rs/moq-net/tests/integration/finished_broadcast_mock.rs index f761ab4fd2f..3f75a00dca3 100644 --- a/rs/moq-net/tests/integration/finished_broadcast_mock.rs +++ b/rs/moq-net/tests/integration/finished_broadcast_mock.rs @@ -53,7 +53,8 @@ async fn round(finish_broadcast: bool) -> (Vec>, Option) let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); // Resolved before the ending starts: a SUBSCRIBE sent alongside its TRACK reaches the // publisher before the subscriber has the TRACK_INFO it accepts the track with. diff --git a/rs/moq-net/tests/integration/finite_relay.rs b/rs/moq-net/tests/integration/finite_relay.rs index d5213164248..a996f586cc0 100644 --- a/rs/moq-net/tests/integration/finite_relay.rs +++ b/rs/moq-net/tests/integration/finite_relay.rs @@ -80,7 +80,8 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let (mut heads, mut opened) = futures::channel::mpsc::unbounded(); let reader = kio::clock::sim::spawn(async move { diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index 1c373f5244a..a8484e96229 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -395,7 +395,8 @@ async fn goaway_keeps_new_subscribes(version: Version) { .unwrap() .available() .await - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut existing = bc.track("video").unwrap().subscribe(None).await.expect("subscribe"); let mut group = track.append_group().expect("append group"); diff --git a/rs/moq-net/tests/integration/group_order.rs b/rs/moq-net/tests/integration/group_order.rs index 3ff9a1a938d..dc372896fd3 100644 --- a/rs/moq-net/tests/integration/group_order.rs +++ b/rs/moq-net/tests/integration/group_order.rs @@ -53,7 +53,8 @@ fn read_arrivals(origin: moq_net::origin::Producer, order: Order) -> kio::clock: .unwrap() .available() .await - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(FOREVER)) .with_range(0..) diff --git a/rs/moq-net/tests/integration/history_groups.rs b/rs/moq-net/tests/integration/history_groups.rs index c046e835d9f..be77e0f69c1 100644 --- a/rs/moq-net/tests/integration/history_groups.rs +++ b/rs/moq-net/tests/integration/history_groups.rs @@ -75,7 +75,8 @@ async fn round(version: &str, relay: bool, newest_first: bool) -> Vec<(u64, usiz let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let reader = kio::clock::sim::spawn(async move { let subscription = Subscription::default() @@ -219,7 +220,13 @@ async fn a_late_subscriber_receives_the_relays_cached_history() { options.client_subscribe = Some(first.clone()); let first_pair = connect_mock(options).await; let consumer = first.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(FOREVER)) .with_range(0..); @@ -258,7 +265,13 @@ async fn a_late_subscriber_receives_the_relays_cached_history() { options.client_subscribe = Some(late.clone()); let late_pair = connect_mock(options).await; let consumer = late.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut late_sub = remote.track("history").unwrap().subscribe(subscription).await.unwrap(); kio::clock::timeout(TIMEOUT, read_history(&mut late_sub)) .await diff --git a/rs/moq-net/tests/integration/idle_cancel_refetch.rs b/rs/moq-net/tests/integration/idle_cancel_refetch.rs index f84eb0a15d1..e2bd95ccdcf 100644 --- a/rs/moq-net/tests/integration/idle_cancel_refetch.rs +++ b/rs/moq-net/tests/integration/idle_cancel_refetch.rs @@ -43,7 +43,8 @@ async fn a_group_cut_by_an_idle_cancel_is_refetched_whole() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .unwrap() - .unwrap().unwrap(); + .unwrap() + .unwrap(); { let mut subscriber = kio::clock::timeout(TIMEOUT, remote.track("audio").unwrap().subscribe(None)) diff --git a/rs/moq-net/tests/integration/late_lower_group.rs b/rs/moq-net/tests/integration/late_lower_group.rs index d58fad8e92f..5973d5bd659 100644 --- a/rs/moq-net/tests/integration/late_lower_group.rs +++ b/rs/moq-net/tests/integration/late_lower_group.rs @@ -118,7 +118,8 @@ async fn session(version: &str, relay: bool, start: Option) -> Vec<(u64, us let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(BUDGET)) @@ -235,7 +236,8 @@ async fn merged(version: &str) -> (Vec<(u64, usize)>, Vec<(u64, usize)>) { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let subscribe = |range: Range| { let track = remote.track("late").unwrap(); diff --git a/rs/moq-net/tests/integration/lazy_discovery.rs b/rs/moq-net/tests/integration/lazy_discovery.rs index e6f01ceb0c1..e5d65118542 100644 --- a/rs/moq-net/tests/integration/lazy_discovery.rs +++ b/rs/moq-net/tests/integration/lazy_discovery.rs @@ -283,12 +283,14 @@ async fn waiting_on_a_path_asks_about_it() { kio::clock::timeout(SETTLE, consumer.follow("a/x", None).unwrap().available()) .await .expect("routed in time") - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut followed = consumer.follow("b/y", None).unwrap(); kio::clock::timeout(SETTLE, followed.available()) .await .expect("announced in time") - .unwrap().unwrap(); + .unwrap() + .unwrap(); assert_eq!(lazy.requests(), 2, "{version}"); } } @@ -526,7 +528,8 @@ async fn ietf_waiting_on_a_path_asks_about_it() { kio::clock::timeout(SETTLE, consumer.follow("a/x", None).unwrap().available()) .await .expect("routed in time") - .unwrap().unwrap(); + .unwrap() + .unwrap(); assert!(!lazy.routes("b/y").await, "{version}"); } } diff --git a/rs/moq-net/tests/integration/partial_group.rs b/rs/moq-net/tests/integration/partial_group.rs index 4b5ace8c4f3..05c35951762 100644 --- a/rs/moq-net/tests/integration/partial_group.rs +++ b/rs/moq-net/tests/integration/partial_group.rs @@ -44,7 +44,8 @@ async fn round(version: &str) -> Option, moq_net::Error>> { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut live = kio::clock::timeout( TIMEOUT, remote diff --git a/rs/moq-net/tests/integration/quiet_catalog.rs b/rs/moq-net/tests/integration/quiet_catalog.rs index 4ce989b8d5e..3ea0b0a0801 100644 --- a/rs/moq-net/tests/integration/quiet_catalog.rs +++ b/rs/moq-net/tests/integration/quiet_catalog.rs @@ -59,7 +59,13 @@ fn publish(origin: &origin::Producer) -> (moq_net::origin::Publication, track::P async fn request(origin: &origin::Producer) -> broadcast::Consumer { let consumer = origin.consume(); - consumer.follow("live", None).unwrap().available().await.unwrap().unwrap() + consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap() } /// Subscribe without a floor and expect the snapshot as group 0. diff --git a/rs/moq-net/tests/integration/range_anchors.rs b/rs/moq-net/tests/integration/range_anchors.rs index bf3a2c37f6a..1034de14399 100644 --- a/rs/moq-net/tests/integration/range_anchors.rs +++ b/rs/moq-net/tests/integration/range_anchors.rs @@ -73,7 +73,8 @@ async fn read(version: Option<&str>, range: Range) -> Result, Error> { kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() } }; diff --git a/rs/moq-net/tests/integration/range_read.rs b/rs/moq-net/tests/integration/range_read.rs index 94eb53749e8..c20de85558d 100644 --- a/rs/moq-net/tests/integration/range_read.rs +++ b/rs/moq-net/tests/integration/range_read.rs @@ -95,7 +95,8 @@ async fn fixture( let remote = kio::clock::timeout(TIMEOUT, client.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); (remote, track, (sessions, broadcast, publisher, middle, client)) } diff --git a/rs/moq-net/tests/integration/received_rewind.rs b/rs/moq-net/tests/integration/received_rewind.rs index 4c78b1718f9..5c154b80f0b 100644 --- a/rs/moq-net/tests/integration/received_rewind.rs +++ b/rs/moq-net/tests/integration/received_rewind.rs @@ -75,7 +75,8 @@ async fn relay( let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(BUDGET)) @@ -193,7 +194,8 @@ async fn fetch_only(version: &str) -> Vec, moq let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut got = Vec::new(); for sequence in [1, 0] { diff --git a/rs/moq-net/tests/integration/rejoin.rs b/rs/moq-net/tests/integration/rejoin.rs index d8bc6ed24d8..eab4f576095 100644 --- a/rs/moq-net/tests/integration/rejoin.rs +++ b/rs/moq-net/tests/integration/rejoin.rs @@ -55,7 +55,13 @@ async fn rejoin_recovers_the_group_reset_on_leave() { let _pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); let prefs = || { @@ -149,7 +155,13 @@ async fn rejoin_skips_a_cache_kept_by_another_handle() { let _pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); // Held for fetches only: it keeps the relay's copy without subscribing. @@ -207,7 +219,13 @@ async fn rejoin_keeps_the_cache_when_the_backlog_lands_newest_first() { let pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); let prefs = || track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(10))); @@ -289,7 +307,13 @@ async fn rejoin_mid_group_keeps_the_head_for_later_readers() { let _downstream = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = sub.recv_group().await.unwrap().unwrap(); assert_eq!(group.read_frame().await.unwrap().unwrap().payload, b"a0".as_ref()); @@ -360,7 +384,13 @@ async fn rejoin_goes_live_without_the_join_head() { let _downstream = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = sub.recv_group().await.unwrap().unwrap(); assert_eq!(group.read_frame().await.unwrap().unwrap().payload, b"a0".as_ref()); @@ -423,7 +453,13 @@ async fn rejoin_during_the_cancel_skips_the_cache() { let _pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); let mut group = track.append_group().unwrap(); @@ -485,7 +521,13 @@ async fn rejoin_waits_for_the_answers_first_frame() { let pair = connect_mock(options).await; let consumer = relay.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let ts = |ms| Timestamp::from_millis(ms).unwrap(); // Held for fetches only: it keeps the relay's copy without subscribing. @@ -569,7 +611,13 @@ async fn leaving_after_the_cache_window_keeps_the_latest_group() { options.client_subscribe = Some(client.clone()); let pair = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); (remote, pair) } }; @@ -631,7 +679,13 @@ async fn rejoin_keeps_source_timestamps() { let _pair = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); // Far from any arrival time, so a frame stamped on arrival cannot pass. let ts = |ms| Timestamp::from_millis(ms).unwrap(); @@ -733,7 +787,13 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { options.client_subscribe = Some(client.clone()); let pair = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let sub = remote.track("catalog").unwrap().subscribe(None).await.unwrap(); (sub, remote, pair) } @@ -755,7 +815,11 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { assert!( matches!( event, - Some(origin::RouteEvent::Update(_) | origin::RouteEvent::Restart(_) | origin::RouteEvent::Takeover { .. }) + Some( + origin::RouteEvent::Update(_) + | origin::RouteEvent::Restart(_) + | origin::RouteEvent::Takeover { .. } + ) ), "{version}: {event:?}" ); diff --git a/rs/moq-net/tests/integration/relay_upstream_close.rs b/rs/moq-net/tests/integration/relay_upstream_close.rs index 4adf8886d11..fdd11e96c32 100644 --- a/rs/moq-net/tests/integration/relay_upstream_close.rs +++ b/rs/moq-net/tests/integration/relay_upstream_close.rs @@ -117,7 +117,8 @@ async fn round(name: &str, end: End) -> Vec { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut readers = Vec::new(); for (index, track) in tracks.iter().enumerate() { diff --git a/rs/moq-net/tests/integration/request_caps.rs b/rs/moq-net/tests/integration/request_caps.rs index 52b98e96210..03ff43f92e4 100644 --- a/rs/moq-net/tests/integration/request_caps.rs +++ b/rs/moq-net/tests/integration/request_caps.rs @@ -78,7 +78,8 @@ async fn closed_requests_are_granted_back() { ) .await .expect("announce timeout") - .unwrap().unwrap(); + .unwrap() + .unwrap(); for round in 0..ROUNDS { let track = broadcast.track(&format!("t{round}")).unwrap(); @@ -128,7 +129,8 @@ async fn flow_control_bounds_the_subscriptions_a_peer_holds() { let remote = kio::clock::timeout(TIMEOUT, client.consume().follow("bcast", None).unwrap().available()) .await .expect("announce timeout") - .unwrap().unwrap(); + .unwrap() + .unwrap(); let subscribing: Vec<_> = (0..TRACKS) .map(|i| { let track = remote.track(&format!("t{i}")).unwrap(); diff --git a/rs/moq-net/tests/integration/route_change.rs b/rs/moq-net/tests/integration/route_change.rs index 5b0b3ae8b21..d0b0f519172 100644 --- a/rs/moq-net/tests/integration/route_change.rs +++ b/rs/moq-net/tests/integration/route_change.rs @@ -129,7 +129,13 @@ impl Topology { let a_to_r = link(version, &relay_a, &subscriber).await; let consumer = subscriber.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let sub = remote.track("video").unwrap().subscribe(prefs).await.unwrap(); @@ -530,7 +536,13 @@ async fn lagging_route_dies(version: Version) { } async fn subscribe(origin: &origin::Producer) -> track::Subscriber { let consumer = origin.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let preferences = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); remote.track("video").unwrap().subscribe(preferences).await.unwrap() @@ -647,7 +659,13 @@ async fn undetected_outage(budget: Duration) -> BTreeMap> { let m1_e = link(version, &m1, &e).await; let consumer = e.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(budget)); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); let m2_e = priced_link(version, &m2, &e, Some(1_000)).await; @@ -902,7 +920,13 @@ async fn replaced_behind_a_relay(version: &str) { let _r_to_d = link(version, &relay, &downstream).await; let consumer = downstream.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); @@ -999,7 +1023,13 @@ async fn compression_changes_behind_a_relay(compress: bool) { let _r_to_d = link(version, &relay, &downstream).await; let consumer = downstream.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); @@ -1093,7 +1123,13 @@ async fn producer_replaced(version: &str) { let _a_to_r = link(version, &relay, &subscriber).await; let consumer = subscriber.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(60))); let sub = remote.track("video").unwrap().subscribe(prefs).await.unwrap(); let mut rx = read(sub); diff --git a/rs/moq-net/tests/integration/route_health.rs b/rs/moq-net/tests/integration/route_health.rs index d4a11d010c6..bd9ba49a735 100644 --- a/rs/moq-net/tests/integration/route_health.rs +++ b/rs/moq-net/tests/integration/route_health.rs @@ -65,7 +65,13 @@ async fn silent_kill(budget: Duration, detect: Duration) -> Vec { let m1_e = link(version, &m1, &e).await; let consumer = e.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(budget)); let mut rx = read(remote.track("video").unwrap().subscribe(prefs).await.unwrap()); let m2_e = priced_link(version, &m2, &e, Some(1_000)).await; @@ -204,7 +210,13 @@ async fn payload_stall(stall: Stall, span: Duration) -> (Observed, Observed) { async fn subscribe(origin: &origin::Producer) -> track::Subscriber { let consumer = origin.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(2))); remote.track("video").unwrap().subscribe(prefs).await.unwrap() } diff --git a/rs/moq-net/tests/integration/segmented_frame.rs b/rs/moq-net/tests/integration/segmented_frame.rs index 10fbe48354a..a5a8e993db6 100644 --- a/rs/moq-net/tests/integration/segmented_frame.rs +++ b/rs/moq-net/tests/integration/segmented_frame.rs @@ -43,7 +43,8 @@ async fn a_segmented_frame_crosses_whole() { let remote = kio::clock::timeout(TIMEOUT, viewer.consume().follow("room", None).unwrap().available()) .await .expect("broadcast timeout") - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = remote.track("file").unwrap().subscribe(None).await.unwrap(); subscribed(&track).await; diff --git a/rs/moq-net/tests/integration/session_close.rs b/rs/moq-net/tests/integration/session_close.rs index bc385d80007..b31a4d65a8e 100644 --- a/rs/moq-net/tests/integration/session_close.rs +++ b/rs/moq-net/tests/integration/session_close.rs @@ -57,7 +57,8 @@ async fn setup_with_gate(version: &str, gate: Option>) -> Se let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); // The publisher only learns of a subscription once the subscriber polls it. let (ready, active) = futures::channel::oneshot::channel(); @@ -113,7 +114,13 @@ async fn track_info_interest_precedes_a_subscription() { options.client_subscribe = Some(subscriber.clone()); let _pair = connect_mock(options).await; let consumer = subscriber.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let copy = remote.track("video").unwrap(); copy.info().await.expect("TRACK_INFO"); crate::support::wanted(track.demand()) diff --git a/rs/moq-net/tests/integration/session_idle.rs b/rs/moq-net/tests/integration/session_idle.rs index 252e73331ea..0d200234a21 100644 --- a/rs/moq-net/tests/integration/session_idle.rs +++ b/rs/moq-net/tests/integration/session_idle.rs @@ -52,7 +52,8 @@ async fn setup(version: &str) -> Setup { let remote = kio::clock::timeout(TIMEOUT, subscriber.consume().follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); Setup { pair, diff --git a/rs/moq-net/tests/integration/source_errors.rs b/rs/moq-net/tests/integration/source_errors.rs index abcda3025dc..c85b21983a2 100644 --- a/rs/moq-net/tests/integration/source_errors.rs +++ b/rs/moq-net/tests/integration/source_errors.rs @@ -43,7 +43,8 @@ async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Cons kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() } async fn relayed(version: &str) -> Relayed { diff --git a/rs/moq-net/tests/integration/stream_credit.rs b/rs/moq-net/tests/integration/stream_credit.rs index 7623ca23c82..7afc6eded33 100644 --- a/rs/moq-net/tests/integration/stream_credit.rs +++ b/rs/moq-net/tests/integration/stream_credit.rs @@ -40,7 +40,8 @@ async fn one_stream_credit_serves_every_backlogged_group() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let prefs = track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_secs(30))); let mut subscribers = Vec::new(); diff --git a/rs/moq-net/tests/integration/subscribe_priority.rs b/rs/moq-net/tests/integration/subscribe_priority.rs index cd070b75d40..65ba7482252 100644 --- a/rs/moq-net/tests/integration/subscribe_priority.rs +++ b/rs/moq-net/tests/integration/subscribe_priority.rs @@ -68,7 +68,8 @@ async fn follows(version: Version, relay: bool) -> Result<(), String> { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let subscribe = |priority: i8| { let track = remote.track("video").unwrap(); async move { diff --git a/rs/moq-net/tests/integration/subscribe_ranges.rs b/rs/moq-net/tests/integration/subscribe_ranges.rs index 1330c6d6aae..7b5036b1e7b 100644 --- a/rs/moq-net/tests/integration/subscribe_ranges.rs +++ b/rs/moq-net/tests/integration/subscribe_ranges.rs @@ -95,7 +95,8 @@ async fn ahead_then_live(version: Option<&str>, relay: bool) -> (Vec, Vec Rang options.client_subscribe = Some(subscriber.clone()); sessions.push(connect_mock(options).await); let consumer = subscriber.consume(); - let remote = consumer.follow("ranges", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("ranges", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); RangeFixture { track, remote, @@ -763,7 +771,8 @@ async fn a_covered_bounded_subscription_ends_on_lite07() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let bounded = |range: std::ops::Range| { Subscription::default() diff --git a/rs/moq-net/tests/integration/subscribe_tracks.rs b/rs/moq-net/tests/integration/subscribe_tracks.rs index 4065f8e513c..9425c44b6db 100644 --- a/rs/moq-net/tests/integration/subscribe_tracks.rs +++ b/rs/moq-net/tests/integration/subscribe_tracks.rs @@ -63,7 +63,8 @@ async fn setup(version: Version) -> Setup { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let (tx, frames) = futures::channel::mpsc::unbounded(); kio::clock::sim::spawn(async move { diff --git a/rs/moq-net/tests/integration/subscribe_with_track.rs b/rs/moq-net/tests/integration/subscribe_with_track.rs index 30fc1207066..7f5e945a173 100644 --- a/rs/moq-net/tests/integration/subscribe_with_track.rs +++ b/rs/moq-net/tests/integration/subscribe_with_track.rs @@ -79,7 +79,13 @@ async fn first_frame(version: &str, relays: usize, arrival: Arrival) -> Duration broadcast.announce(Default::default()).unwrap(); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); if !matches!(arrival, Arrival::Together) { reader.hold_bidis(); diff --git a/rs/moq-net/tests/integration/subscriber_max_age.rs b/rs/moq-net/tests/integration/subscriber_max_age.rs index 9bd9680b88d..ee474e46162 100644 --- a/rs/moq-net/tests/integration/subscriber_max_age.rs +++ b/rs/moq-net/tests/integration/subscriber_max_age.rs @@ -51,7 +51,13 @@ async fn relay_forwards_the_most_tolerant_subscriber_max_age() { group.finish().unwrap(); broadcast.announce(Default::default()).unwrap(); let consumer = viewer.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let cache = remote.track("catalog").unwrap(); let prefs = |millis| { track::Subscription::default().with_delay(track::Delay::default().with_max(Duration::from_millis(millis))) @@ -126,7 +132,8 @@ async fn relay_forwards_the_smallest_stated_min_delay() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); remote.track("catalog").unwrap() } }; diff --git a/rs/moq-net/tests/integration/subscription_end_integrity.rs b/rs/moq-net/tests/integration/subscription_end_integrity.rs index f1e80dd950c..3ef37836678 100644 --- a/rs/moq-net/tests/integration/subscription_end_integrity.rs +++ b/rs/moq-net/tests/integration/subscription_end_integrity.rs @@ -70,7 +70,8 @@ async fn round(drop_session: bool) -> (Vec>, Option) { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); // The publisher only learns of a subscription once the subscriber polls it, so the // reader runs concurrently. It reports the head group drained, then waits to be told @@ -229,7 +230,8 @@ async fn killed(version: &str, kill: Kill) -> (Option, Option moq_net::Error { .unwrap() .available() .await - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut fetching = kio::clock::sim::spawn(async move { remote.track("video").unwrap().fetch_group(0, None).await }); let request = dynamic.requested_track().await.expect("the track request arrives"); diff --git a/rs/moq-net/tests/integration/track_abort_over_session.rs b/rs/moq-net/tests/integration/track_abort_over_session.rs index 511cb79ce31..c2475a7b26c 100644 --- a/rs/moq-net/tests/integration/track_abort_over_session.rs +++ b/rs/moq-net/tests/integration/track_abort_over_session.rs @@ -38,7 +38,13 @@ async fn after_abort(version: &str, hops: u32) { options.client_subscribe = Some(far.clone()); let _pair2 = connect_mock(options).await; let consumer = if hops == 2 { far.consume() } else { relay.consume() }; - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); let mut open = track.append_group().unwrap(); open.write_frame(Timestamp::ZERO, b"head".as_ref()).unwrap(); diff --git a/rs/moq-net/tests/integration/track_info_cancel.rs b/rs/moq-net/tests/integration/track_info_cancel.rs index d8453416680..bf9fe31178a 100644 --- a/rs/moq-net/tests/integration/track_info_cancel.rs +++ b/rs/moq-net/tests/integration/track_info_cancel.rs @@ -87,7 +87,8 @@ async fn withdrawn_broadcast_releases_track_info(version: &str, answered: bool, .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut query = remote.track("video").unwrap().info(); let request = match futures::future::select(std::pin::pin!(dynamic.requested_track()), &mut query).await { futures::future::Either::Left((request, _)) => request.expect("TRACK reaches the publisher"), diff --git a/rs/moq-net/tests/integration/track_stream_demand.rs b/rs/moq-net/tests/integration/track_stream_demand.rs index 733f2a23af7..1aaf88560b4 100644 --- a/rs/moq-net/tests/integration/track_stream_demand.rs +++ b/rs/moq-net/tests/integration/track_stream_demand.rs @@ -103,7 +103,13 @@ async fn one_used_edge(version: &str, relays: usize, reorder: bool) { }); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let subscribing = remote.track("video").unwrap().subscribe(None); if reorder { @@ -190,7 +196,13 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { }); let consumer = nodes.last().unwrap().consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let handle = remote.track("video").unwrap(); kio::clock::sleep(Duration::from_secs(1)).await; diff --git a/rs/moq-net/tests/integration/track_tail.rs b/rs/moq-net/tests/integration/track_tail.rs index d7835182cda..4a0841debdf 100644 --- a/rs/moq-net/tests/integration/track_tail.rs +++ b/rs/moq-net/tests/integration/track_tail.rs @@ -94,7 +94,8 @@ async fn connect(version: &str) -> Pair { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("bcast", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); Pair { pair, diff --git a/rs/moq-net/tests/integration/tracks.rs b/rs/moq-net/tests/integration/tracks.rs index f7a92d02459..e394273b83c 100644 --- a/rs/moq-net/tests/integration/tracks.rs +++ b/rs/moq-net/tests/integration/tracks.rs @@ -56,7 +56,8 @@ async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Cons kio::clock::timeout(TIMEOUT, origin.consume().follow("bcast", None).unwrap().available()) .await .expect("announce timeout") - .expect("routed").unwrap() + .expect("routed") + .unwrap() } /// A session syncs at once, then lists the peer's tracks and their changes until the diff --git a/rs/moq-net/tests/integration/tracks_ietf.rs b/rs/moq-net/tests/integration/tracks_ietf.rs index 22b99a1db5d..4693717ffd1 100644 --- a/rs/moq-net/tests/integration/tracks_ietf.rs +++ b/rs/moq-net/tests/integration/tracks_ietf.rs @@ -61,7 +61,8 @@ async fn resolve(origin: &moq_net::origin::Producer, path: &str) -> moq_net::bro kio::clock::timeout(TIMEOUT, origin.consume().follow(path, None).unwrap().available()) .await .expect("announce timeout") - .expect("routed").unwrap() + .expect("routed") + .unwrap() } /// How many request streams of `kind` the client has opened. diff --git a/rs/moq-net/tests/integration/unannounce_release.rs b/rs/moq-net/tests/integration/unannounce_release.rs index d64e539d61e..e86543f5af1 100644 --- a/rs/moq-net/tests/integration/unannounce_release.rs +++ b/rs/moq-net/tests/integration/unannounce_release.rs @@ -33,7 +33,8 @@ async fn release(version: Version) { .unwrap() .available() .await - .expect("resolves").unwrap(); + .expect("resolves") + .unwrap(); let sub = remote.track("t").unwrap().subscribe(None).await.expect("subscribes"); crate::support::wanted(track.demand()).await.unwrap(); diff --git a/rs/moq-net/tests/integration/warm_backfill.rs b/rs/moq-net/tests/integration/warm_backfill.rs index 6d2a8b67424..daba5f7110b 100644 --- a/rs/moq-net/tests/integration/warm_backfill.rs +++ b/rs/moq-net/tests/integration/warm_backfill.rs @@ -36,7 +36,13 @@ fn origin(hop: u64) -> origin::Producer { async fn subscribe(relay: &origin::Producer) -> track::Subscriber { let consumer = relay.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); remote .track("video") .unwrap() diff --git a/rs/moq-net/tests/integration/wide_sequence.rs b/rs/moq-net/tests/integration/wide_sequence.rs index 860aaab6736..f17fb410fb4 100644 --- a/rs/moq-net/tests/integration/wide_sequence.rs +++ b/rs/moq-net/tests/integration/wide_sequence.rs @@ -41,7 +41,8 @@ async fn largest_quic_sequence_reaches_the_subscriber() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = remote.track("data").unwrap().subscribe(None).await.unwrap(); for sequence in [5, 1 << 32, (1 << 53) - 1, (1 << 53) + 1, (1 << 62) - 1] { // Timestamps stop at 2^61 - 1, the most lite-05/06 can zigzag as a first frame. @@ -111,12 +112,19 @@ async fn wide_sequence_fails_only_its_subscription() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = cached.track("wide").unwrap().subscribe(None).await.unwrap(); assert_eq!(sub.recv_group().await.unwrap().unwrap().sequence, WIDE); let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let result = kio::clock::timeout(Duration::from_secs(5), async { let mut sub = remote.track("wide").unwrap().subscribe(None).await?; @@ -165,7 +173,13 @@ async fn a_later_wide_group_fails_only_that_subscription() { let _downstream = connect_mock(options).await; let consumer = client.consume(); - let remote = consumer.follow("bench", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bench", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut sub = remote.track("wide").unwrap().subscribe(None).await.unwrap(); let mut group = sub.recv_group().await.unwrap().unwrap(); diff --git a/rs/moq-net/tests/integration/widened_max_age.rs b/rs/moq-net/tests/integration/widened_max_age.rs index e37c37de68d..3fe706c806d 100644 --- a/rs/moq-net/tests/integration/widened_max_age.rs +++ b/rs/moq-net/tests/integration/widened_max_age.rs @@ -110,7 +110,13 @@ impl Chain { /// Subscribe from the viewer with `budget`, reading from the oldest group still around. async fn subscribe(&self, budget: Duration) -> track::Subscriber { let consumer = self.viewer.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(budget)) .with_ranges([Range::oldest()]); @@ -318,7 +324,13 @@ async fn wider_newcomers_after_the_first_pull_nothing_upstream() { let viewer = origin(3); links.push(peer(version, &relay, &viewer).await); let consumer = viewer.consume(); - let remote = consumer.follow("live", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("live", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let subscription = Subscription::default() .with_delay(Delay::default().with_max(budget)) .with_ranges([Range::oldest()]); diff --git a/rs/moq-net/tests/integration/zero_copy.rs b/rs/moq-net/tests/integration/zero_copy.rs index 310c0c06d54..3779106d2eb 100644 --- a/rs/moq-net/tests/integration/zero_copy.rs +++ b/rs/moq-net/tests/integration/zero_copy.rs @@ -63,7 +63,8 @@ async fn frames_cross_without_a_copy() { let remote = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.expect("subscribe"); subscribed(&track).await; diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index e0f3c6cb764..b9ab95f3de8 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -2627,7 +2627,8 @@ mod tests { ) .await .expect("stats broadcast announced within 5s") - .expect("stats broadcast resolves").unwrap(); + .expect("stats broadcast resolves") + .unwrap(); assert!(broadcast.info().instance.is_some(), "stats announce under an instance"); // Several publish intervals (1s each by default) after the handle went out @@ -3282,7 +3283,8 @@ mod tests { ) .await .expect("stats announced") - .expect("stats present").unwrap(); + .expect("stats present") + .unwrap(); } /// The reserved `cluster.id` 0 is rejected, since it cannot be excluded for loop diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 36d2d0bd239..d366d459f72 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -1136,7 +1136,12 @@ async fn serve_fetch( // Block until a route covers the broadcast (within the fetch deadline) so // freshly-connected subscribers don't get a spurious 404 before the announce arrives. let mut following = origin.follow("", None).map_err(|_| StatusCode::NOT_FOUND)?; - let broadcast = following.available().await.map_err(|_| StatusCode::NOT_FOUND)?; + let broadcast = following + .available() + .await + .ok() + .flatten() + .ok_or(StatusCode::NOT_FOUND)?; let sequence = match params.group { FetchGroup::Num(sequence) => Some(sequence), FetchGroup::Latest => None, diff --git a/rs/moq-relay/tests/drills.rs b/rs/moq-relay/tests/drills.rs index d6697e300eb..57f6289739c 100644 --- a/rs/moq-relay/tests/drills.rs +++ b/rs/moq-relay/tests/drills.rs @@ -414,7 +414,8 @@ async fn subscribe(origin: &moq_net::origin::Consumer, path: &str) -> Reader { let broadcast = kio::clock::timeout(TIMEOUT, origin.follow(path, None).unwrap().available()) .await .expect("announcement timed out") - .expect("origin closed before announcing").unwrap(); + .expect("origin closed before announcing") + .unwrap(); let track = broadcast.track(TRACK).expect("track"); let groups = kio::clock::timeout(TIMEOUT, track.subscribe(None)) @@ -1447,7 +1448,8 @@ async fn subscriber_max_age_skips_bufferbloat(version: &str) { let remote = kio::clock::timeout(TIMEOUT, consumed.follow("live", None).unwrap().available()) .await .unwrap() - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut groups = remote .track(TRACK) .unwrap() diff --git a/rs/moq-relay/tests/integration/auth_lifetime.rs b/rs/moq-relay/tests/integration/auth_lifetime.rs index 5e0b4c124fb..af573d235c8 100644 --- a/rs/moq-relay/tests/integration/auth_lifetime.rs +++ b/rs/moq-relay/tests/integration/auth_lifetime.rs @@ -816,7 +816,8 @@ async fn a_rechecked_grant_resizes_live_sessions() { let broadcast = kio::clock::timeout(TIMEOUT, sub_consumer.follow(path, None).unwrap().available()) .await .expect("announcement timeout") - .expect("announced broadcast resolves").unwrap(); + .expect("announced broadcast resolves") + .unwrap(); subs.push( broadcast .track("media") @@ -879,7 +880,8 @@ async fn a_rechecked_grant_resizes_live_sessions() { let broadcast = kio::clock::timeout(TIMEOUT, sub_consumer.follow("alice/audio", None).unwrap().available()) .await .expect("the undeafened path was never announced again") - .expect("announced broadcast resolves").unwrap(); + .expect("announced broadcast resolves") + .unwrap(); let mut audio = broadcast .track("media") .unwrap() @@ -1780,7 +1782,8 @@ async fn in_band_tokens_widen_and_withdraw_live_prefixes() { let a_read = kio::clock::timeout(TIMEOUT, read.follow("a/cam", None).unwrap().available()) .await .unwrap() - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut a_sub = a_read.track("video").unwrap().subscribe(None).await.unwrap(); let mut replacement = Grant::new(all(), "b/**".parse::().unwrap()); replacement.expires = Some(kio::clock::wall() + Duration::from_secs(3600)); @@ -1792,7 +1795,8 @@ async fn in_band_tokens_widen_and_withdraw_live_prefixes() { let b_read = kio::clock::timeout(TIMEOUT, read.follow("b/cam", None).unwrap().available()) .await .expect("new prefix not announced") - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut b_sub = b_read.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = b_track.append_group().unwrap(); group diff --git a/rs/moq-relay/tests/integration/cluster_unknown.rs b/rs/moq-relay/tests/integration/cluster_unknown.rs index daf968c1209..6e4edd1c9f2 100644 --- a/rs/moq-relay/tests/integration/cluster_unknown.rs +++ b/rs/moq-relay/tests/integration/cluster_unknown.rs @@ -218,7 +218,8 @@ async fn read_first_frame(port: u16) -> Result, String> { .unwrap() .available() .await - .map_err(|err| format!("broadcast unroutable: {err}"))?; + .map_err(|err| format!("broadcast unroutable: {err}"))? + .ok_or("the first change is an instance")?; // This verifies route propagation rather than real-time backlog skipping. Give // every hop enough tolerance for the next 100ms group to arrive while the diff --git a/rs/moq-relay/tests/integration/connection.rs b/rs/moq-relay/tests/integration/connection.rs index f1fdb72fabe..52bae1ce5e3 100644 --- a/rs/moq-relay/tests/integration/connection.rs +++ b/rs/moq-relay/tests/integration/connection.rs @@ -46,7 +46,8 @@ async fn largest_quic_sequence_reaches_the_subscriber() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = remote.track("data").unwrap().subscribe(None).await.unwrap(); for sequence in [5, 1 << 32, (1 << 53) - 1, (1 << 53) + 1, (1 << 62) - 1] { // Timestamps stop at 2^61 - 1, the most lite-05/06 can zigzag as a first frame. diff --git a/rs/moq-relay/tests/integration/goaway_cluster.rs b/rs/moq-relay/tests/integration/goaway_cluster.rs index 15efa890f51..dd637f3d103 100644 --- a/rs/moq-relay/tests/integration/goaway_cluster.rs +++ b/rs/moq-relay/tests/integration/goaway_cluster.rs @@ -175,7 +175,8 @@ async fn cluster_continues_a_group_split_by_goaway_inner() { .unwrap() .available() .await - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut sub = within("subscribe", bc.track("video").expect("track").subscribe(None)) .await .expect("subscribe"); @@ -319,7 +320,8 @@ async fn cluster_migrates_on_upstream_goaway_inner() { .unwrap() .available() .await - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut sub = bc .track("video") .expect("track handle") @@ -560,7 +562,13 @@ async fn cluster_diamond_goaway_seamless_failover_inner() { let bc = within("broadcast resolves on the subscriber origin", async { let consumer = sub_origin.consume(); - consumer.follow("diamond", None).unwrap().available().await.ok() + consumer + .follow("diamond", None) + .unwrap() + .available() + .await + .ok() + .flatten() }) .await .expect("broadcast announced"); diff --git a/rs/moq-relay/tests/integration/refusals.rs b/rs/moq-relay/tests/integration/refusals.rs index 3867db25c6f..177c25f0935 100644 --- a/rs/moq-relay/tests/integration/refusals.rs +++ b/rs/moq-relay/tests/integration/refusals.rs @@ -250,7 +250,8 @@ async fn refused_only_stats_depth_one_has_root_totals_and_shared_embedder_metric ) .await .unwrap() - .unwrap().unwrap(); + .unwrap() + .unwrap(); let consumer = moq_stats::Consumer::new(broadcast, Default::default()); let mut totals = consumer.totals().await.unwrap(); kio::clock::timeout(TIMEOUT, async { @@ -306,7 +307,8 @@ async fn peer_zero_close_is_clean_and_application_close_counts_once() { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); let consumer = moq_stats::Consumer::new(broadcast, Default::default()); let mut totals = consumer.totals().await.unwrap(); for (index, error) in [moq_net::Error::Cancel, moq_net::Error::App(42)] diff --git a/rs/moq-relay/tests/integration/upstream_links.rs b/rs/moq-relay/tests/integration/upstream_links.rs index 2ff5f388f02..3f337141e1c 100644 --- a/rs/moq-relay/tests/integration/upstream_links.rs +++ b/rs/moq-relay/tests/integration/upstream_links.rs @@ -11,7 +11,7 @@ use std::collections::BTreeMap; use std::time::Duration; use moq_auth::{Grant, Pattern, lease}; -use moq_net::{announce, origin}; +use moq_net::origin; use moq_relay::{ Connection, auth, cluster::{self, Peer}, @@ -181,7 +181,8 @@ async fn read_frame(origin: &origin::Producer, path: &str) { consumer.follow(path, None).unwrap().available(), ) .await - .unwrap_or_else(|err| panic!("{path} unroutable: {err}")); + .unwrap_or_else(|err| panic!("{path} unroutable: {err}")) + .expect("the first change is an instance"); let subscription = moq_net::track::Subscription::default() .with_delay(moq_net::track::Delay::default().with_max(Duration::from_secs(1))); let mut track = within( diff --git a/rs/moq-room/src/chat.rs b/rs/moq-room/src/chat.rs index bab7a56025e..55e018f3080 100644 --- a/rs/moq-room/src/chat.rs +++ b/rs/moq-room/src/chat.rs @@ -294,7 +294,13 @@ mod tests { let relay = origin(2); let _link = link(&publisher, &relay).await; let consumer = relay.consume(); - let remote = consumer.follow("room", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("room", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); // A first reader warms the relay's copy with the first window. { diff --git a/rs/moq-rtc/src/lib.rs b/rs/moq-rtc/src/lib.rs index 876b23eb9b6..d8ecb5f80e3 100644 --- a/rs/moq-rtc/src/lib.rs +++ b/rs/moq-rtc/src/lib.rs @@ -77,10 +77,7 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) => Some((route, true)), + moq_net::announce::Event::Present(route) => Some((route, true)), moq_net::announce::Event::Absent(route) => Some((route, false)), } } @@ -289,7 +286,13 @@ mod tests { let source = moq_mux::Source::new(source, broadcast); let pushed = tokio::spawn(async move { client.publish(url, source).await }); let ingested = ingest_origin.consume(); - let ingested = ingested.follow("ingested", None).unwrap().available().await.unwrap().unwrap(); + let ingested = ingested + .follow("ingested", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut played = opus_output(&ingested).await; assert_eq!(next_payload(&mut played).await, OPUS_PACKET); diff --git a/rs/moq-rtc/src/server/whep.rs b/rs/moq-rtc/src/server/whep.rs index 94214641072..5f0cdc9a224 100644 --- a/rs/moq-rtc/src/server/whep.rs +++ b/rs/moq-rtc/src/server/whep.rs @@ -210,7 +210,8 @@ async fn resolve(subscriber: &moq_net::origin::Consumer, path: moq_net::Path) -> let mut following = subscriber.follow(path, None)?; let broadcast = kio::clock::timeout_at(deadline, following.available()) .await - .map_err(|_| Error::Moq(moq_net::Error::Unroutable))??; + .map_err(|_| Error::Moq(moq_net::Error::Unroutable))?? + .ok_or(Error::Moq(moq_net::Error::Unroutable))?; kio::clock::timeout_at( deadline, EgressSource::new(moq_mux::Source::new(subscriber.clone(), broadcast)), diff --git a/rs/moq-rtmp/src/dial.rs b/rs/moq-rtmp/src/dial.rs index 308ea842acb..abd037a5c29 100644 --- a/rs/moq-rtmp/src/dial.rs +++ b/rs/moq-rtmp/src/dial.rs @@ -822,7 +822,13 @@ mod tests { }); let consumer = downstream.consume(); - let copy = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); + let copy = consumer + .follow("live/cam0", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); // The catalog goes out once the keyframe landed, so the copy holds media to linger with. let mut listed = copy.track("catalog.json").unwrap().subscribe(None).await.unwrap(); assert!(listed.recv_group().await.unwrap().is_some()); @@ -938,7 +944,13 @@ mod tests { // Read what reaches the remote back out as FLV. let consumer = downstream.consume(); - let copy = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); + let copy = consumer + .follow("live/cam0", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let source = moq_mux::Source::new(consumer, copy); let catalog = source .catalog::<()>(moq_mux::catalog::CatalogFormat::default()) @@ -1038,7 +1050,8 @@ mod tests { .unwrap() .available() .await - .unwrap().unwrap(); + .unwrap() + .unwrap(); // It should carry a hang catalog track (proof the FLV demux produced real // media on the far side): subscribe to it and read one catalog frame. diff --git a/rs/moq-rtmp/src/server.rs b/rs/moq-rtmp/src/server.rs index c7c76c43c2b..5c192ecbf74 100644 --- a/rs/moq-rtmp/src/server.rs +++ b/rs/moq-rtmp/src/server.rs @@ -836,7 +836,7 @@ impl Play { } } }; - let Ok(broadcast) = broadcast else { + let Ok(Some(broadcast)) = broadcast else { tracing::debug!(peer = %self.peer, %path, "play broadcast unavailable"); return self.reject("stream not found").await; }; @@ -1900,7 +1900,13 @@ mod tests { let (mut client, server) = tokio::io::duplex(64 * 1024); let accept = tokio::spawn(accept_publish(server, origin.clone(), Duration::ZERO)); let catalog = async { - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); + let broadcast = consumer + .follow("live/cam0", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let track = broadcast.track(hang::Catalog::DEFAULT_NAME).unwrap(); track.subscribe(None).await.unwrap() }; @@ -2210,7 +2216,13 @@ mod tests { publisher.push(flv::TAG_VIDEO, 0, &vseq).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); + let broadcast = consumer + .follow("live/cam0", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let info = broadcast.track("0.flv-v").unwrap().info().await.unwrap(); assert_eq!(info.max_age, Some(Duration::from_secs(3))); } @@ -2803,7 +2815,13 @@ mod tests { let stale_client = tokio::spawn(async move { run_client(TcpStream::connect(addr).await.unwrap(), ClientMode::Publish).await; }); - let stale = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); + let stale = consumer + .follow("live/cam0", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let mut catalog = stale .track(hang::Catalog::DEFAULT_NAME) .unwrap() diff --git a/rs/moq-srt/src/ts.rs b/rs/moq-srt/src/ts.rs index 1495ae5f4cf..91ee24765b6 100644 --- a/rs/moq-srt/src/ts.rs +++ b/rs/moq-srt/src/ts.rs @@ -292,7 +292,9 @@ impl Subscriber { // Join the broadcast once announced. The export resolves any referenced sibling // broadcast (the catalog `broadcast` field) through the same origin. let broadcast = match following.available().await { - Ok(broadcast) => broadcast, + Ok(Some(broadcast)) => broadcast, + // The first change is always an instance. + Ok(None) => return Ok(None), Err(moq_net::Error::Closed) => return Ok(None), Err(err) => return Err(err.into()), }; @@ -727,7 +729,13 @@ mod tests { publisher.feed(Bytes::from_static(BBB5S)).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); + let broadcast = consumer + .follow("live/cam0", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let start = kio::clock::now(); let wait = tokio::spawn(publisher.finish(linger).unwrap().wait()); kio::clock::sleep(linger / 2).await; @@ -760,7 +768,13 @@ mod tests { publisher.feed(Bytes::from(ts)).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("live/cam0", None).unwrap().available().await.unwrap().unwrap(); + let broadcast = consumer + .follow("live/cam0", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let info = broadcast.track("0.avc3").unwrap().info().await.unwrap(); assert_eq!(info.max_age, Some(Duration::from_secs(3))); } @@ -831,7 +845,13 @@ mod tests { let mut publisher = Publisher::new(&origin, "ingest", Default::default(), None).unwrap(); let consumer = origin.consume(); - let broadcast = consumer.follow("ingest", None).unwrap().available().await.unwrap().unwrap(); + let broadcast = consumer + .follow("ingest", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); publisher.feed(bytes::Bytes::from_static(BBB5S)).unwrap(); diff --git a/rs/moq-stats/benches/producer_tick.rs b/rs/moq-stats/benches/producer_tick.rs index a956d2d35bb..d582c25e36d 100644 --- a/rs/moq-stats/benches/producer_tick.rs +++ b/rs/moq-stats/benches/producer_tick.rs @@ -36,7 +36,7 @@ use std::time::{Duration, Instant}; use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; use futures::FutureExt; -use moq_net::{announce, origin, stats}; +use moq_net::{origin, stats}; use moq_stats::produce::bench::{Driver, FrameBytes}; struct Counter; diff --git a/rs/moq-stats/src/aggregate.rs b/rs/moq-stats/src/aggregate.rs index 35099fadeae..7e51057e21c 100644 --- a/rs/moq-stats/src/aggregate.rs +++ b/rs/moq-stats/src/aggregate.rs @@ -1133,7 +1133,7 @@ mod tests { use std::time::Duration; - use moq_net::{Path, Timestamp, announce, broadcast, origin, track}; + use moq_net::{Path, Timestamp, broadcast, origin, track}; use moq_net::stats::Tier; diff --git a/rs/moq-stats/src/consume.rs b/rs/moq-stats/src/consume.rs index ecf45033cd5..802431e092d 100644 --- a/rs/moq-stats/src/consume.rs +++ b/rs/moq-stats/src/consume.rs @@ -172,7 +172,7 @@ mod tests { use std::time::Duration; - use moq_net::{Consume, Path, Timestamp, announce, origin, track}; + use moq_net::{Consume, Path, Timestamp, origin, track}; use crate::{Producer, Tier, produce}; diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 7d2fbca4e62..881d551057a 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -1638,7 +1638,7 @@ mod tests { use std::collections::BTreeMap; use moq_net::stats::{Registry, Tier}; - use moq_net::{Timestamp, announce, broadcast, track}; + use moq_net::{Timestamp, broadcast, track}; use super::*; use crate::{PrefixFrame, PresenceFrame, TotalsFrame}; diff --git a/rs/moq-tokio/examples/clock.rs b/rs/moq-tokio/examples/clock.rs index 16bf6b2c404..dc2307b5b26 100644 --- a/rs/moq-tokio/examples/clock.rs +++ b/rs/moq-tokio/examples/clock.rs @@ -112,7 +112,7 @@ async fn main() -> anyhow::Result<()> { tokio::select! { Some(event) = announced.next() => match event { // A restart is a new broadcast: subscribe to it afresh. - announce::Event::Present(update) | announce::Event::Present(update) | announce::Event::Present(update) | announce::Event::Present(update) => { + announce::Event::Present(update) => { tracing::info!(broadcast = %update.prefix, "broadcast is online, subscribing to track"); let broadcast = consumer.request(&update.prefix, None).await?; let track = broadcast diff --git a/rs/moq-tokio/src/connection.rs b/rs/moq-tokio/src/connection.rs index d207dfd0b38..b901504ef87 100644 --- a/rs/moq-tokio/src/connection.rs +++ b/rs/moq-tokio/src/connection.rs @@ -3377,7 +3377,8 @@ mod tests { let cam = kio::clock::timeout(WAIT, consumer.follow("cam", None).unwrap().available()) .await .unwrap() - .unwrap().unwrap(); + .unwrap() + .unwrap(); let mut sub = cam.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = track.append_group().unwrap(); @@ -3460,7 +3461,8 @@ mod tests { kio::clock::timeout(WAIT, subscriber.consume().follow("late", None).unwrap().available()) .await .expect("the drained session stopped serving") - .unwrap().unwrap(); + .unwrap() + .unwrap(); assert!( connection .draining() diff --git a/rs/moq-tokio/src/origin.rs b/rs/moq-tokio/src/origin.rs index dca85558425..16e25f9b0c9 100644 --- a/rs/moq-tokio/src/origin.rs +++ b/rs/moq-tokio/src/origin.rs @@ -42,10 +42,7 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) => Some((route, true)), + 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 56d05a503be..98eaf588fdb 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -2156,10 +2156,7 @@ mod tests { #[cfg(all(feature = "uds", unix))] async fn next_update(announced: &mut moq_net::announce::Consumer) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) => Some((route, true)), + 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 f066a6e7136..e01c6164f34 100644 --- a/rs/moq-tokio/tests/integration/backend.rs +++ b/rs/moq-tokio/tests/integration/backend.rs @@ -1372,10 +1372,7 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) => Some((route, true)), + 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 cc7d289b8c3..2eb4f5dea15 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -3479,10 +3479,7 @@ 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)> { match announced.next().await? { - moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) - | moq_net::announce::Event::Present(route) => Some((route, true)), + 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/datagram_delivery.rs b/rs/moq-tokio/tests/integration/datagram_delivery.rs index ecc8d3bc993..0536973fd24 100644 --- a/rs/moq-tokio/tests/integration/datagram_delivery.rs +++ b/rs/moq-tokio/tests/integration/datagram_delivery.rs @@ -104,7 +104,8 @@ impl Viewer { let broadcast = kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let track = kio::clock::timeout(TIMEOUT, broadcast.track("audio").unwrap().subscribe(None)) .await .expect("subscribe timeout") diff --git a/rs/moq-tokio/tests/integration/migrate.rs b/rs/moq-tokio/tests/integration/migrate.rs index ccbdf1612dc..3e3adedc620 100644 --- a/rs/moq-tokio/tests/integration/migrate.rs +++ b/rs/moq-tokio/tests/integration/migrate.rs @@ -106,7 +106,8 @@ fn view(origin: &moq_net::origin::Producer, name: &str) -> tokio::sync::mpsc::Un .expect("follow") .available() .await - .expect("the broadcast resolves").unwrap(); + .expect("the broadcast resolves") + .unwrap(); // A budget, so a group the move delays is late rather than skipped. let subscription = moq_net::track::Subscription::default() .with_delay(moq_net::track::Delay::default().with_max(Duration::from_secs(5))); diff --git a/rs/moq-tokio/tests/integration/receive_credit.rs b/rs/moq-tokio/tests/integration/receive_credit.rs index 417eaf15c1e..b3c2522c78a 100644 --- a/rs/moq-tokio/tests/integration/receive_credit.rs +++ b/rs/moq-tokio/tests/integration/receive_credit.rs @@ -183,7 +183,8 @@ async fn room(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Consume kio::clock::timeout(TIMEOUT, consumer.follow("room", None).unwrap().available()) .await .expect("resolve timeout") - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() } /// Subscribe to track `name` of `remote` at `priority`. diff --git a/rs/moq-tokio/tests/integration/subscription_end_integrity.rs b/rs/moq-tokio/tests/integration/subscription_end_integrity.rs index f7ee7163b87..cd7c084ce27 100644 --- a/rs/moq-tokio/tests/integration/subscription_end_integrity.rs +++ b/rs/moq-tokio/tests/integration/subscription_end_integrity.rs @@ -89,7 +89,8 @@ async fn round(drop_session: bool) -> (usize, Option) { .unwrap() .available() .await - .expect("broadcast resolves").unwrap(); + .expect("broadcast resolves") + .unwrap(); let mut sub = remote.track("video").unwrap().subscribe(None).await.expect("subscribe"); let mut got = 0; diff --git a/rs/moq-transcode/examples/transcode.rs b/rs/moq-transcode/examples/transcode.rs index 2e06b578bf8..cfbf624f60d 100644 --- a/rs/moq-transcode/examples/transcode.rs +++ b/rs/moq-transcode/examples/transcode.rs @@ -59,7 +59,7 @@ async fn main() -> anyhow::Result<()> { // subscribes upstream on demand. let mut following = remote.consume().follow(&source_path, None)?; let source = tokio::select! { - resolved = following.available() => resolved.context("source broadcast unavailable")?, + resolved = following.available() => resolved.context("source broadcast unavailable")?.context("went offline before serving")?, closed = session.closed() => { closed.context("session failed before the source broadcast was announced")?; anyhow::bail!("session closed before the source broadcast was announced"); diff --git a/rs/moq-uring/benches/session_lite.rs b/rs/moq-uring/benches/session_lite.rs index 03ecc20d09e..ffc77c8787f 100644 --- a/rs/moq-uring/benches/session_lite.rs +++ b/rs/moq-uring/benches/session_lite.rs @@ -184,7 +184,8 @@ mod linux { .unwrap() .available() .await - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() }; let sub = bc .track("data") diff --git a/rs/moq-uring/tests/integration/receive_credit.rs b/rs/moq-uring/tests/integration/receive_credit.rs index 7c4d7f17428..d69ddead02c 100644 --- a/rs/moq-uring/tests/integration/receive_credit.rs +++ b/rs/moq-uring/tests/integration/receive_credit.rs @@ -163,7 +163,8 @@ fn partial_frame_gives_way() { consumer.follow("room", None).unwrap().available(), ) .await - .expect("broadcast resolves"); + .expect("broadcast resolves") + .expect("the first change is an instance"); let subscribe = |name: &str, priority: i8| { let track = remote.track(name).expect("track"); async move { @@ -320,7 +321,8 @@ fn javascript_partial_frame_gives_way() { consumer.follow("room", None).unwrap().available(), ) .await - .expect("broadcast resolves"); + .expect("broadcast resolves") + .expect("the first change is an instance"); let subscribe = |name: &str, priority: i8| { let track = remote.track(name).expect("track"); async move { diff --git a/rs/moq-uring/tests/integration/session.rs b/rs/moq-uring/tests/integration/session.rs index d3728cd1e65..bf5ddb25789 100644 --- a/rs/moq-uring/tests/integration/session.rs +++ b/rs/moq-uring/tests/integration/session.rs @@ -138,7 +138,8 @@ fn lite_session_over_the_worker() { .unwrap() .available() .await - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() }; let mut track = bc .track("data") @@ -282,7 +283,8 @@ fn two_lite_sessions_share_the_server_socket() { .unwrap() .available() .await - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() }; let mut track = bc .track("data") diff --git a/rs/moq-uring/tests/integration/web.rs b/rs/moq-uring/tests/integration/web.rs index b78b26279af..72dcd67fc52 100644 --- a/rs/moq-uring/tests/integration/web.rs +++ b/rs/moq-uring/tests/integration/web.rs @@ -346,7 +346,8 @@ fn lite_session_over_webtransport() { .unwrap() .available() .await - .expect("broadcast resolves").unwrap() + .expect("broadcast resolves") + .unwrap() }; let mut track = bc .track("data") diff --git a/test/interop/clients/rust/audio.rs b/test/interop/clients/rust/audio.rs index c7be847447c..9ada6204099 100644 --- a/test/interop/clients/rust/audio.rs +++ b/test/interop/clients/rust/audio.rs @@ -41,7 +41,11 @@ async fn main() -> anyhow::Result<()> { .established() .await?; - let broadcast = consumer.follow(&args[2], None)?.available().await?; + let broadcast = consumer + .follow(&args[2], None)? + .available() + .await? + .context("went offline before serving")?; let source = moq_mux::Source::new(consumer, broadcast.clone()); let mut catalogs = moq_mux::catalog::Consumer::<()>::new(&broadcast, CatalogFormat::Hang).await?; // A lazy publisher (the browser) may add audio in a later catalog update. diff --git a/test/interop/clients/rust/finish.rs b/test/interop/clients/rust/finish.rs index 6cb59c7e2cf..576fc541059 100644 --- a/test/interop/clients/rust/finish.rs +++ b/test/interop/clients/rust/finish.rs @@ -117,7 +117,11 @@ async fn main() -> anyhow::Result<()> { ensure!(command == "read\n", "finish read phase was not released"); kio::clock::timeout(args.timeout, async { let mut routes = consumer.announced(); - let broadcast = consumer.follow(&args.broadcast, None)?.available().await?; + let broadcast = consumer + .follow(&args.broadcast, None)? + .available() + .await? + .context("went offline before serving")?; let mut catalogs = moq_mux::catalog::Consumer::<()>::new(&broadcast, moq_mux::catalog::CatalogFormat::Hang).await?; let catalog = loop { @@ -165,7 +169,8 @@ async fn main() -> anyhow::Result<()> { let health = consumer .follow(format!("{}.health", args.broadcast), None)? .available() - .await?; + .await? + .context("went offline before serving")?; let mut track = health.track("live")?.subscribe(None).await?; let mut group = track.recv_group().await?.context("no health group")?; let frame = group.read_frame().await?.context("no health frame")?; diff --git a/test/interop/clients/rust/goaway-client.rs b/test/interop/clients/rust/goaway-client.rs index ce9963804a9..9767b441381 100644 --- a/test/interop/clients/rust/goaway-client.rs +++ b/test/interop/clients/rust/goaway-client.rs @@ -41,7 +41,7 @@ async fn main() -> anyhow::Result<()> { "wrong negotiated version" ); let mut following = consumer.follow("handover", None)?; - let broadcast = following.available().await?; + let broadcast = following.available().await?.context("went offline before serving")?; let mut track = broadcast.track("video")?.subscribe(None).await?; let input = child.stdin.as_mut().context("stdin")?; for sequence in 0..2 { @@ -56,14 +56,18 @@ async fn main() -> anyhow::Result<()> { input.write_all(b"first group\n").await?; // The first endpoint's publisher scope excludes this broadcast, so its bytes // prove that the replacement session is serving beyond its SETUP handshake. - let ready = consumer.follow("replacement", None)?.available().await?; + let ready = consumer + .follow("replacement", None)? + .available() + .await? + .context("went offline before serving")?; let mut marker = ready.track("ready")?.subscribe(None).await?; let mut marker = marker.recv_group().await?.context("replacement marker")?; ensure!( marker.read_frame().await?.context("marker frame")?.payload.as_ref() == [42], "wrong marker" ); - let restarted = following.available().await?; + let restarted = following.available().await?.context("went offline before serving")?; ensure!(!restarted.is_clone(&broadcast), "redirect did not restart the instance"); track = restarted.track("video")?.subscribe(None).await?.with_range(1..); input.write_all(b"replacement ready\n").await?; diff --git a/test/interop/clients/rust/hls.rs b/test/interop/clients/rust/hls.rs index a8908bf3be4..a3262c5b7ae 100644 --- a/test/interop/clients/rust/hls.rs +++ b/test/interop/clients/rust/hls.rs @@ -114,7 +114,12 @@ async fn main() -> anyhow::Result<()> { .established() .await?; kio::clock::timeout(Duration::from_secs(30), async { - let broadcast = origin.consume().follow(path, None)?.available().await?; + let broadcast = origin + .consume() + .follow(path, None)? + .available() + .await? + .context("went offline before serving")?; let mut catalogs = moq_mux::catalog::Consumer::<()>::new(&broadcast, moq_mux::catalog::CatalogFormat::Hang).await?; // Both renditions, each advertising its records. diff --git a/test/interop/clients/rust/tail.rs b/test/interop/clients/rust/tail.rs index db1e2fb6307..8c68a358435 100644 --- a/test/interop/clients/rust/tail.rs +++ b/test/interop/clients/rust/tail.rs @@ -186,7 +186,11 @@ async fn main() -> anyhow::Result<()> { .connect(url) .established() .await?; - let broadcast = consumer.follow(&args[3], None)?.available().await?; + let broadcast = consumer + .follow(&args[3], None)? + .available() + .await? + .context("went offline before serving")?; let remote = broadcast.track("tail")?; if status { // Query before subscribing so draft-18+ must use TRACK_STATUS, From 814a11149f72d1e8155ba7ed8169d8065429bebc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 2 Nov 2026 23:47:39 -0800 Subject: [PATCH 04/21] wip(js)!: announce listing and internal routes() Co-Authored-By: Claude Opus 5.5 --- demo/carla/web/src/player.ts | 8 +- demo/web/src/index.ts | 2 +- demo/web/src/stats.ts | 66 ++++++------ js/moq-boy/src/element.tsx | 4 +- js/net/api/index.api.md | 2 +- js/net/bench/broadcasts.ts | 4 +- js/net/bench/forward.ts | 2 +- js/net/bench/refresh.ts | 2 +- js/net/examples/discovery.ts | 2 +- js/net/src/announced.test-util.ts | 11 +- js/net/src/announced.test.ts | 28 +++-- js/net/src/announced.ts | 132 +++++++++++++++++++---- js/net/src/auth.test.ts | 2 +- js/net/src/connection/close.test.ts | 2 +- js/net/src/connection/established.ts | 4 + js/net/src/connection/forward.test.ts | 64 +++++------ js/net/src/connection/forward.ts | 6 +- js/net/src/connection/pool.test.ts | 6 +- js/net/src/connection/pool.ts | 13 ++- js/net/src/connection/reload.test.ts | 8 +- js/net/src/connection/reload.ts | 2 +- js/net/src/connection/scope.test.ts | 2 +- js/net/src/goaway-requests.test.ts | 16 +-- js/net/src/ietf/connection.ts | 11 +- js/net/src/ietf/goaway.test.ts | 2 +- js/net/src/ietf/peer-violations.test.ts | 8 +- js/net/src/ietf/subscriber.test.ts | 66 ++++++------ js/net/src/ietf/subscriber.ts | 2 +- js/net/src/integration.test.ts | 38 +++---- js/net/src/lite/compression.test.ts | 2 +- js/net/src/lite/connection.test.ts | 2 +- js/net/src/lite/connection.ts | 10 +- js/net/src/lite/refresh.test.ts | 2 +- js/net/src/lite/subscriber.test.ts | 72 ++++++------- js/net/src/lite/subscriber.ts | 2 +- js/net/src/lite/tracks.test.ts | 2 +- js/net/src/origin.test.ts | 44 ++++---- js/net/src/origin.ts | 21 +++- js/net/src/request-deadline.test.ts | 2 +- js/net/src/session-limits.test.ts | 2 +- js/room/src/room.test.ts | 2 +- js/room/src/room.ts | 2 +- js/watch/src/broadcast.ts | 2 +- js/watch/src/echo.test.ts | 2 +- test/interop/clients/js-native/finish.ts | 2 +- test/interop/clients/js-native/goaway.ts | 2 +- 46 files changed, 415 insertions(+), 273 deletions(-) diff --git a/demo/carla/web/src/player.ts b/demo/carla/web/src/player.ts index b8425a4237e..331fe1b8aab 100644 --- a/demo/carla/web/src/player.ts +++ b/demo/carla/web/src/player.ts @@ -121,14 +121,14 @@ export function mount(root: ShadowRoot, connection: Moq.Connection): () => void // A broad route can cover the scope without naming one camera. if (!parseCamera(entry.prefix)) continue; - // A restart is a new simulator instance on the same path; the watch - // broadcast follows it, so only an end removes the tile. - if (entry.kind !== "end" && !tiles.has(entry.prefix)) { + // A restarted simulator keeps its path present, and the watch broadcast + // follows it, so only an absence removes the tile. + if (entry.kind !== "absent" && !tiles.has(entry.prefix)) { const truck = new Truck({ broadcastId: entry.prefix, connection, driving, focused, hovered }); tiles.set(entry.prefix, new TruckTile(truck)); vehicles.set(tiles.size); refreshFocusLayout(); - } else if (entry.kind === "end") { + } else if (entry.kind === "absent") { const tile = tiles.get(entry.prefix); tile?.dispose(); tiles.delete(entry.prefix); diff --git a/demo/web/src/index.ts b/demo/web/src/index.ts index 55958c73391..7785c466c9a 100644 --- a/demo/web/src/index.ts +++ b/demo/web/src/index.ts @@ -199,7 +199,7 @@ discovery.run((effect) => { // Only catalog-backed broadcasts are watchable streams; this skips the relay's // `.stats` broadcast (see the stats dashboard demo for that one). if (!path.endsWith(".hang") && !path.endsWith(".msf")) continue; - if (entry.kind === "end") live.delete(path); + if (entry.kind === "absent") live.delete(path); else live.add(path); broadcasts.set([...live].sort()); } diff --git a/demo/web/src/stats.ts b/demo/web/src/stats.ts index 95f981a762f..75ae1c0dc32 100644 --- a/demo/web/src/stats.ts +++ b/demo/web/src/stats.ts @@ -6,7 +6,7 @@ * auto-discover all of those nodes (announcements under `.stats/node`), so this * works for a single relay and for a cluster alike, then aggregate each node and * let you drill into one. A restarted relay announces a new instance at the same - * path, which arrives as an end then a start, so its history starts over. + * path, which each node's follower hands out afresh, so its history starts over. * * Per node we read `group.json`, the whole node's group at the relay's default * `depth = 0`: `{ epoch, tiers: { : { paths, labels } } }`, a JSON snapshot @@ -161,13 +161,7 @@ discovery.run((effect) => { const node = Net.Path.stripPrefix(prefix, path); if (!node) continue; - // The same node re-priced or failed over: its counters carry on. - if (entry.kind === "update") continue; - if (entry.kind === "start" && subs.has(node)) continue; - - // An end, or a restart: another instance at the path counts from zero, so neither - // series may splice across it. - if (entry.kind !== "start") { + if (entry.kind === "absent") { subs.get(node)?.close(); subs.delete(node); nodeStats.mutate((s) => { @@ -175,8 +169,9 @@ discovery.run((effect) => { }); history.delete(node); clusterMembership = ""; + continue; } - if (entry.kind === "end") continue; + if (subs.has(node)) continue; const ne = new Signals.Effect(); subs.set(node, ne); @@ -186,31 +181,34 @@ discovery.run((effect) => { }); function subscribeNode(effect: Signals.Effect, origin: Net.Origin.Reader, path: Net.Path.Valid, node: string) { - nodeStats.mutate((s) => { - s[node] = { - egress: {}, - ingress: {}, - sessions: {}, - }; - }); - - // The path was just announced, so the request resolves from the table immediately. - const request = origin.request(path); - effect.cleanup(() => request.close()); - const consumer = request.active.peek(); - if (!consumer) return; - - const track = consumer.track("group.json").subscribe(); - effect.cleanup(() => track.close()); - const group = new Json.Snapshot.Consumer({ track }); - effect.spawn(async () => { - for (;;) { - const state = await effect.race(group.latest()); - if (state === undefined) break; - nodeStats.mutate((s) => { - if (s[node]) s[node] = nodeStatsOf(state.value ?? {}); - }); - } + // Follow the node across instances: a restarted one counts from zero, so its series starts + // afresh rather than splicing onto the old one's. + const following = origin.follow(path); + effect.cleanup(() => following.close()); + effect.run((instance) => { + const consumer = instance.get(following.active); + nodeStats.mutate((s) => { + s[node] = { + egress: {}, + ingress: {}, + sessions: {}, + }; + }); + history.delete(node); + if (!consumer) return; + + const track = consumer.track("group.json").subscribe(); + instance.cleanup(() => track.close()); + const group = new Json.Snapshot.Consumer({ track }); + instance.spawn(async () => { + for (;;) { + const state = await instance.race(group.latest()); + if (state === undefined) break; + nodeStats.mutate((s) => { + if (s[node]) s[node] = nodeStatsOf(state.value ?? {}); + }); + } + }); }); } diff --git a/js/moq-boy/src/element.tsx b/js/moq-boy/src/element.tsx index 5e12f823236..ce2704ba25d 100644 --- a/js/moq-boy/src/element.tsx +++ b/js/moq-boy/src/element.tsx @@ -183,7 +183,7 @@ export default class MoqBoy extends HTMLElement { if (!capture?.isLiteral) continue; const id = capture.text; - if (entry.kind !== "end" && !this.#sessions.has(id)) { + if (entry.kind !== "absent" && !this.#sessions.has(id)) { const config: GameConfig = { sessionId: id, connection: this.connection, @@ -195,7 +195,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 (entry.kind === "end") { + } else if (entry.kind === "absent") { const game = this.#sessions.get(id); if (game) { game.close(); diff --git a/js/net/api/index.api.md b/js/net/api/index.api.md index e009f823516..6ff678c48a7 100644 --- a/js/net/api/index.api.md +++ b/js/net/api/index.api.md @@ -21,7 +21,7 @@ export namespace Announce { get synced(): Signals.Getter; } export type Event = { - kind: "start" | "update" | "restart" | "end"; + kind: "present" | "absent"; } & Announce.Announce; export interface Options { covering?: boolean; diff --git a/js/net/bench/broadcasts.ts b/js/net/bench/broadcasts.ts index 80895efe551..7f89626a04f 100644 --- a/js/net/bench/broadcasts.ts +++ b/js/net/bench/broadcasts.ts @@ -46,7 +46,7 @@ for (const scope of [ let notifications = 0; const streams = Array.from({ length: observerCount }, (_, index) => scope === "full-name" || scope === "overlap-only" - ? origin.consume().announced(Path.Pattern.parse("**/*.chat")) + ? origin.consume().routes(Path.Pattern.parse("**/*.chat")) : (scope === "producer-scopes" ? origin.scope( Path.empty(), @@ -58,7 +58,7 @@ for (const scope of [ new Path.Patterns([Path.Pattern.parse(`**/tag-${index}`)]), ) : origin - ).announced( + ).routes( scope === "distinct-scopes" ? Path.Pattern.parse(`room/**/tag-${index}`) : undefined, // These scopes only overlap `room/`, so they measure the covering view. { covering: scope !== "unscoped" }, diff --git a/js/net/bench/forward.ts b/js/net/bench/forward.ts index c0aaa6f030f..42edb11c682 100644 --- a/js/net/bench/forward.ts +++ b/js/net/bench/forward.ts @@ -42,7 +42,7 @@ class FakeSession { }); } - announced(): Announce.Consumer { + routes(): Announce.Routes { const stream = new Announce.Producer(); this.streams.push(stream); // This peer has no initial routes; later announcements are live updates. diff --git a/js/net/bench/refresh.ts b/js/net/bench/refresh.ts index 3dd5b5322e4..a14650164da 100644 --- a/js/net/bench/refresh.ts +++ b/js/net/bench/refresh.ts @@ -30,7 +30,7 @@ for (const retained of [1, 64, 1024]) ]); try { const announcements = destination.announced(); - while ((await announcements.next())?.kind !== "start") {} + while ((await announcements.next())?.kind !== "present") {} const request = destination.request(Path.from("room")); while (!request.active.peek()) await request.active.changed(); const remote = request.active.peek(); diff --git a/js/net/examples/discovery.ts b/js/net/examples/discovery.ts index b361e02e7ab..eb070025ff1 100644 --- a/js/net/examples/discovery.ts +++ b/js/net/examples/discovery.ts @@ -11,7 +11,7 @@ async function main() { // Discover broadcasts announced by the server for await (const announcement of announced) { - if (announcement.kind === "end" || requests.has(announcement.prefix)) continue; + if (announcement.kind === "absent" || requests.has(announcement.prefix)) continue; console.log("New stream available:", announcement.prefix); // One request per path follows its publisher restarts until closed. diff --git a/js/net/src/announced.test-util.ts b/js/net/src/announced.test-util.ts index daee64e6ad2..6f2b2732d87 100644 --- a/js/net/src/announced.test-util.ts +++ b/js/net/src/announced.test-util.ts @@ -1,12 +1,15 @@ import { Signal } from "@moq/signals"; -import type { Options } from "./announced"; +import type { Options, Routes } from "./announced"; import type { Route } from "./hop"; -import type { Table } from "./origin"; import type * as Path from "./path"; /** A closeable announcement snapshot for tests and benchmarks. @internal */ -export async function announcedView(origin: Pick, scope?: Path.Pattern, options?: Options) { - const stream = origin.announced(scope, options); +export async function announcedView( + origin: { routes(scope?: Path.Pattern, options?: Options): Routes }, + scope?: Path.Pattern, + options?: Options, +) { + const stream = origin.routes(scope, options); const value = new Signal>(new Map()); const done = (async () => { for await (const event of stream) diff --git a/js/net/src/announced.test.ts b/js/net/src/announced.test.ts index f9da2f5b217..eb2ce44fe0e 100644 --- a/js/net/src/announced.test.ts +++ b/js/net/src/announced.test.ts @@ -28,6 +28,20 @@ test("next streams every appended event in order", async () => { expect(await consumer.next()).toEqual({ prefix: p("a"), captures: undefined, kind: "end", route }); }); +test("a listing reports only a path becoming present or absent", async () => { + const producer = new Announce.Producer(); + const listing = Announce.list(producer.consume()); + + const route = Route.default; + producer.append({ prefix: p("a"), captures: undefined, kind: "start", route }); + producer.append({ prefix: p("a"), captures: undefined, kind: "update", route }); + producer.append({ prefix: p("a"), captures: undefined, kind: "restart", route }); + producer.append({ prefix: p("a"), captures: undefined, kind: "end", route }); + + expect((await listing.next())?.kind).toBe("present"); + expect((await listing.next())?.kind).toBe("absent"); +}); + test("the consumer is an async iterable of the same events", async () => { const producer = new Announce.Producer(); const consumer = producer.consume(); @@ -161,7 +175,7 @@ test("the local route wins over a blind request on a no-discovery origin", async }); const tick = () => yieldNow(); -const start = (prefix: string): Announce.Event => ({ +const start = (prefix: string): Announce.RouteEvent => ({ prefix: p(prefix), captures: undefined, kind: "start", @@ -217,7 +231,7 @@ test("behind takes sync back, and closing hands it back for good", () => { test("an origin with no session delivering syncs on its own replay", async () => { const origin = new OriginProducer(); const room = publish(origin, p("room")); - const announced = origin.consume().announced(); + const announced = origin.consume().routes(); expect(await announced.next()).toMatchObject({ prefix: p("room"), kind: "start" }); void announced.next(); await tick(); @@ -232,8 +246,8 @@ test("an origin stream waits on every overlapping initial set in flight", async const room = wire.snapshot(p("room")); const other = wire.snapshot(p("other")); - const scoped = origin.consume().announced(Path.Pattern.subtree(p("room"))); - const all = origin.consume().announced(); + const scoped = origin.consume().routes(Path.Pattern.subtree(p("room"))); + const all = origin.consume().routes(); await tick(); expect(scoped.synced.peek()).toBe(false); expect(all.synced.peek()).toBe(false); @@ -268,7 +282,7 @@ test("an origin stream waits on every overlapping initial set in flight", async test("a snapshot elsewhere never holds a scoped stream", async () => { const origin = new OriginProducer(); const other = wireOf(origin).snapshot(p("other")); - const scoped = origin.consume().announced(Path.Pattern.subtree(p("room"))); + const scoped = origin.consume().routes(Path.Pattern.subtree(p("room"))); await tick(); expect(scoped.synced.peek()).toBe(true); other(); @@ -278,8 +292,8 @@ test("a snapshot elsewhere never holds a scoped stream", async () => { test("a snapshot under a hidden segment holds only a reader that opts in", async () => { const origin = new OriginProducer(); const stats = wireOf(origin).snapshot(p(".stats")); - const all = origin.consume().announced(); - const hidden = origin.consume().announced(Path.Pattern.all(), { hidden: true }); + const all = origin.consume().routes(); + const hidden = origin.consume().routes(Path.Pattern.all(), { hidden: true }); await tick(); expect(all.synced.peek()).toBe(true); expect(hidden.synced.peek()).toBe(false); diff --git a/js/net/src/announced.ts b/js/net/src/announced.ts index 64dca8800b3..20db6927bfc 100644 --- a/js/net/src/announced.ts +++ b/js/net/src/announced.ts @@ -30,16 +30,26 @@ export interface Announce { } /** - * What an announcement stream yields. + * What an announcement listing yields: a path becoming present or absent. * - * `start`: a route now covers the prefix. `update`: the route covering it changed - * hops or cost, in place. `restart`: another instance now serves the prefix, so request it - * afresh; what was already resolved stays on the old one until dropped or its route goes. - * `end`: no route covers it any more. + * `present`: a route now covers the path, which was absent. `absent`: no route covers it any + * more, carrying 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. * * @public */ -export type Event = { kind: "start" | "update" | "restart" | "end" } & Announce; +export type Event = { kind: "present" | "absent" } & Announce; + +/** + * Every change to a route, for code that forwards or routes them. + * + * `start`: a route now covers the prefix. `update`: the route covering it changed hops or cost, + * in place. `restart`: another instance now serves the prefix. `end`: no route covers it any + * more. + * + * @internal + */ +export type RouteEvent = { kind: "start" | "update" | "restart" | "end" } & Announce; /** * Options for an announcement stream. @@ -67,7 +77,7 @@ export interface Options { /** Reactive backing state shared by announcement producers and consumers. */ class AnnounceState { - queue = new Signal([]); + queue = new Signal([]); closed = new Once(); synced = new Signal(false); // The queued events still to read before the stream counts as synced, or undefined @@ -100,9 +110,9 @@ function closeState(state: AnnounceState, abort?: Error) { } /** - * The write side of an announcement stream. + * The write side of a route stream. * - * @public + * @internal */ export class Producer { #state = new AnnounceState(); @@ -116,20 +126,20 @@ export class Producer { } /** A read handle for this announcement stream. */ - consume(): Consumer { - return makeConsumer(this.#state); + consume(): Routes { + return makeRoutes(this.#state); } /** * Whether any consumer still holds the stream: false before the first {@link consume} and - * once the last one {@link Consumer.close}s, which is how a reader cancels it. + * once the last one {@link Routes.close}s, which is how a reader cancels it. */ get wanted(): Getter { return this.#state.wanted; } /** Writes an event to the queue. */ - append(event: Event) { + append(event: RouteEvent) { if (this.#state.closed.peek() !== undefined) throw new Error("announcements are closed"); this.#state.queue.mutate((queue) => { queue.push(event); @@ -167,18 +177,16 @@ export class Producer { } } -// Constructs a Consumer from within this module without exposing a public constructor +// Constructs a Routes from within this module without exposing a public constructor // that would leak the unexported AnnounceState. Assigned in the class's static block. -let makeConsumer: (state: AnnounceState) => Consumer; +let makeRoutes: (state: AnnounceState) => Routes; /** - * The read side of an announcement stream. - * - * Created internally: obtain one from an origin or the connection's `announced(scope)`. + * The read side of a route stream: every change, for code that forwards or routes them. * - * @public + * @internal */ -export class Consumer { +export class Routes { #state: AnnounceState; // Set once this handle closes, ending its own reads and guarding the consumer count. #released = new Signal(false); @@ -195,7 +203,7 @@ export class Consumer { } static { - makeConsumer = (state) => new Consumer(state); + makeRoutes = (state) => new Routes(state); } /** @@ -212,7 +220,7 @@ export class Consumer { } /** The events as they arrive, until the stream closes. */ - async *[Symbol.asyncIterator](): AsyncGenerator { + async *[Symbol.asyncIterator](): AsyncGenerator { for (;;) { const event = await this.next(); if (!event) return; @@ -221,7 +229,7 @@ export class Consumer { } /** Returns the next event, or undefined once the stream or this handle closes. */ - async next(): Promise { + async next(): Promise { const state = this.#state; state.reading = false; settle(state); @@ -253,3 +261,81 @@ export class Consumer { if (--this.#state.consumers === 0) this.#state.wanted.set(false); } } + +// Constructs a listing over a route stream without a public constructor. Declared before the +// class, whose static block assigns it. +let makeConsumer: (routes: Routes) => Consumer; + +/** + * 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)`. + * + * @public + */ +export class Consumer { + #routes: Routes; + + private constructor(routes: Routes) { + this.#routes = routes; + } + + static { + makeConsumer = (routes) => new Consumer(routes); + } + + /** Settles once the stream closes: `null` on a clean close, or the abort {@link Error}. */ + get closed(): GetPromise { + return this.#routes.closed; + } + + /** + * Whether the listing has delivered its source's initial announcements and the reader has + * taken them, so a path not present by now is absent rather than not yet heard of. + * + * Flips once the reader asks for the event after the last of them, and is true once + * closed. Through a session, the initial set is the peer's view when it answered: exact + * on versions that count it, best-effort on the rest. Reading an origin, it is every + * attached session's initial set, so a reconnect takes it back until the new one lands. + */ + get synced(): Getter { + return this.#routes.synced; + } + + /** The events as they arrive, until the listing closes. */ + async *[Symbol.asyncIterator](): AsyncGenerator { + for (;;) { + const event = await this.next(); + if (!event) return; + yield event; + } + } + + /** Returns the next path that became present or absent, or undefined once the listing or this handle closes. */ + async next(): Promise { + for (;;) { + const event = await this.#routes.next(); + if (!event) return undefined; + const { kind, ...announce } = event; + if (kind === "start") return { kind: "present", ...announce }; + if (kind === "end") return { kind: "absent", ...announce }; + } + } + + /** + * Release this handle, like dropping a Rust handle: the source sees the listing as no + * longer wanted. Idempotent. + */ + close() { + this.#routes.close(); + } +} + +/** + * The listing over a route stream: only paths becoming present or absent. + * + * @internal + */ +export function list(routes: Routes): Consumer { + return makeConsumer(routes); +} diff --git a/js/net/src/auth.test.ts b/js/net/src/auth.test.ts index 14feb5ca266..7d45fb71617 100644 --- a/js/net/src/auth.test.ts +++ b/js/net/src/auth.test.ts @@ -369,7 +369,7 @@ describe.each([Lite.ALPN_07_WIP, Ietf.ALPN.DRAFT_22])("%s", (protocol) => { await waitFor(client.auth.grant, (g) => g !== undefined); origin.createBroadcast(Path.from("a/x")).announce(); - const announced = server.announced(); + const announced = server.routes(); const first = await nextRoute(announced); expect(first?.prefix).toBe(Path.from("a/x")); expect(first?.kind).toBe("start"); diff --git a/js/net/src/connection/close.test.ts b/js/net/src/connection/close.test.ts index fc4dbb53761..2111a17e097 100644 --- a/js/net/src/connection/close.test.ts +++ b/js/net/src/connection/close.test.ts @@ -65,7 +65,7 @@ for (const protocol of [Lite.ALPN_07_WIP, Ietf.ALPN.DRAFT_18]) { connect({ url, transport: pair.client, consume: destination }), accept({ url, transport: pair.server, publish: source.consume() }), ]); - const announced = destination.announced(); + const announced = destination.routes(); let installed: Installed | undefined; try { expect((await announced.next())?.kind).toBe("start"); diff --git a/js/net/src/connection/established.ts b/js/net/src/connection/established.ts index c4920e6d4ce..9e55e067e25 100644 --- a/js/net/src/connection/established.ts +++ b/js/net/src/connection/established.ts @@ -1,5 +1,6 @@ import type { GetPromise, Getter } from "@moq/signals"; import type * as announce from "../announce.ts"; +import type { Routes } from "../announced.ts"; import type * as Auth from "../auth.ts"; import type * as Path from "../path.ts"; import type { Drain } from "./goaway.ts"; @@ -59,6 +60,9 @@ export interface Established { */ announced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer; + /** Every route change matching `scope`, for code that forwards routes. @internal */ + routes(scope?: Path.Pattern, options?: announce.Options): Routes; + /** * Snapshot the transport's counters, querying it fresh on each call. * diff --git a/js/net/src/connection/forward.test.ts b/js/net/src/connection/forward.test.ts index e53f77a50cd..79a9df2030a 100644 --- a/js/net/src/connection/forward.test.ts +++ b/js/net/src/connection/forward.test.ts @@ -79,7 +79,7 @@ class FakeSession { }); } - announced(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Announce.Consumer { + routes(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Announce.Routes { const stream = new Announce.Producer(); this.requests.push({ scope: scope.text, hidden: options?.hidden, covering: options?.covering, stream }); if (this.syncedAtOnce) stream.synced(); @@ -137,7 +137,7 @@ function start(stream: Announce.Producer, prefix: string, route: Route = Route.d } /** Every event an origin announcement stream yields, as `kind prefix`. */ -function record(stream: Announce.Consumer): string[] { +function record(stream: Announce.Routes): string[] { const events: string[] = []; void (async () => { for await (const event of stream) events.push(`${event.kind} ${event.prefix}`); @@ -172,7 +172,7 @@ test("a watch opens its request, and the request closes once the linger expires" const session = new FakeSession(); forwardAnnounced(session.session, origin); - const watch = origin.announced(Path.Pattern.subtree(Path.from("room"))); + const watch = origin.routes(Path.Pattern.subtree(Path.from("room"))); await settle(); expect(session.requests.map(({ scope, hidden }) => ({ scope, hidden }))).toEqual([ { scope: "room/**", hidden: true }, @@ -183,7 +183,7 @@ test("a watch opens its request, and the request closes once the linger expires" await advance(LINGER - 1); expect(session.open()).toEqual(["room/**"]); - const again = origin.announced(Path.Pattern.subtree(Path.from("room"))); + const again = origin.routes(Path.Pattern.subtree(Path.from("room"))); await advance(LINGER); expect(session.open()).toEqual(["room/**"]); expect(session.requests.length).toBe(1); @@ -203,15 +203,15 @@ test("a watch arriving as the linger expires opens a fresh request", async () => const session = new FakeSession(); forwardAnnounced(session.session, origin); - const watch = origin.announced(Path.Pattern.subtree(Path.from("room"))); + const watch = origin.routes(Path.Pattern.subtree(Path.from("room"))); await settle(); watch.close(); await settle(); // The expiry closes the old request, and the next watch lands before its stream winds down. - let again: Announce.Consumer | undefined; + let again: Announce.Routes | undefined; session.onClose = () => { - again ??= origin.announced(Path.Pattern.subtree(Path.from("room"))); + again ??= origin.routes(Path.Pattern.subtree(Path.from("room"))); }; await advance(LINGER); expect(again).toBeDefined(); @@ -285,7 +285,7 @@ test("a pattern watches its literal head", async () => { const session = new FakeSession(); forwardAnnounced(session.session, origin); - const chat = origin.announced(Path.Pattern.parse("room/*/chat")); + const chat = origin.routes(Path.Pattern.parse("room/*/chat")); await settle(); expect(session.open()).toEqual(["room/**"]); @@ -299,8 +299,8 @@ test("a narrower watch rides an open broader request and keeps it open", async ( const session = new FakeSession(); forwardAnnounced(session.session, origin); - const broad = origin.announced(Path.Pattern.subtree(Path.from("a"))); - const narrow = origin.announced(Path.Pattern.subtree(Path.from("a/b"))); + const broad = origin.routes(Path.Pattern.subtree(Path.from("a"))); + const narrow = origin.routes(Path.Pattern.subtree(Path.from("a/b"))); const events = record(narrow); await settle(); expect(session.open()).toEqual(["a/**"]); @@ -333,14 +333,14 @@ test("a narrower request stays open until the broader one covering it goes", asy const session = new FakeSession(); forwardAnnounced(session.session, origin); - const narrow = origin.announced(Path.Pattern.subtree(Path.from("a/b"))); + const narrow = origin.routes(Path.Pattern.subtree(Path.from("a/b"))); await settle(); start(session.stream("a/b/**"), "a/b/x"); await settle(); // A broader watch opens its own request, which has yet to answer when the narrower watch // leaves. The narrower request stays open, so the route never retracts. - const broad = origin.announced(Path.Pattern.subtree(Path.from("a"))); + const broad = origin.routes(Path.Pattern.subtree(Path.from("a"))); const events = record(broad); await settle(); narrow.close(); @@ -365,8 +365,8 @@ test("an exclusive session closes every request beneath a broader one before it const session = new FakeSession({ exclusive: true }); forwardAnnounced(session.session, origin); - const narrow = origin.announced(Path.Pattern.subtree(Path.from("a/b"))); - const lingering = origin.announced(Path.Pattern.subtree(Path.from("a/c"))); + const narrow = origin.routes(Path.Pattern.subtree(Path.from("a/b"))); + const lingering = origin.routes(Path.Pattern.subtree(Path.from("a/c"))); await settle(); start(session.stream("a/b/**"), "a/b/x"); lingering.close(); @@ -375,7 +375,7 @@ test("an exclusive session closes every request beneath a broader one before it // Watched or lingering, each narrower request closes for the broader one, on purpose: the // session stays discovering, and the route returns once the broader request reports it. - const broad = origin.announced(Path.Pattern.subtree(Path.from("a"))); + const broad = origin.routes(Path.Pattern.subtree(Path.from("a"))); const events = record(broad); await settle(); expect(session.open()).toEqual(["a/**"]); @@ -409,11 +409,11 @@ for (const [name, instances] of [ const session = new FakeSession(); forwardAnnounced(session.session, origin); - const narrow = origin.announced(Path.Pattern.subtree(Path.from("a/b"))); + const narrow = origin.routes(Path.Pattern.subtree(Path.from("a/b"))); await settle(); start(session.stream("a/b/**"), "a/b/x", { ...Route.default, instance: instances[0] }); await settle(); - const broad = origin.announced(Path.Pattern.subtree(Path.from("a"))); + const broad = origin.routes(Path.Pattern.subtree(Path.from("a"))); const events = record(broad); await settle(); start(session.stream("a/**"), "a/b/x", { ...Route.default, instance: instances[1] }); @@ -438,8 +438,8 @@ test("a reconnect re-opens every live watch and skips a lingering one", async () const first = new FakeSession(); forwardAnnounced(first.session, origin); - const kept = origin.announced(Path.Pattern.subtree(Path.from("kept"))); - const dropped = origin.announced(Path.Pattern.subtree(Path.from("dropped"))); + const kept = origin.routes(Path.Pattern.subtree(Path.from("kept"))); + const dropped = origin.routes(Path.Pattern.subtree(Path.from("dropped"))); await settle(); expect(first.open()).toEqual(["kept/**", "dropped/**"]); @@ -483,7 +483,7 @@ test("a refused announce request downgrades the session once, and later watches expect(plain.active.peek()).toBeDefined(); expect(session.consumes(path)).toBe(1); - const later = origin.announced(Path.Pattern.subtree(Path.from("other"))); + const later = origin.routes(Path.Pattern.subtree(Path.from("other"))); await settle(); expect(session.requests.length).toBe(1); @@ -536,7 +536,7 @@ test("a session dying does not downgrade discovery for the next one", async () = const origin = new OriginProducer(); const first = new FakeSession(); forwardAnnounced(first.session, origin); - const watch = origin.announced(); + const watch = origin.routes(); await settle(); expect(origin.discovery.peek()).toBe(true); @@ -563,7 +563,7 @@ test("a request replaced across one coalesced wakeup still gets answered", async forwardAnnounced(session.session, origin); // Refusing discovery downgrades the session, so plain requests take its blind answers. - const listing = origin.announced(Path.Pattern.subtree(path)); + const listing = origin.routes(Path.Pattern.subtree(path)); await settle(); session.stream("wanted/**").close(new Error("namespace rejected")); await settle(); @@ -600,15 +600,15 @@ test("a scoped origin narrows a root watch to its disjoint literal heads", async const session = new FakeSession(); forwardAnnounced(session.session, scoped); - const all = origin.announced(); + const all = origin.routes(); await settle(); expect(session.open()).toEqual(["other/**", "room/**"]); all.close(); // A watch inside a head rides the head's open request, and one outside the scope asks for // nothing. - let inside = origin.announced(Path.Pattern.subtree(Path.from("room/alice/chat"))); - const outside = origin.announced(Path.Pattern.subtree(Path.from("elsewhere"))); + let inside = origin.routes(Path.Pattern.subtree(Path.from("room/alice/chat"))); + const outside = origin.routes(Path.Pattern.subtree(Path.from("elsewhere"))); await advance(LINGER); expect(session.open()).toEqual(["room/**"]); @@ -616,7 +616,7 @@ test("a scoped origin narrows a root watch to its disjoint literal heads", async inside.close(); await advance(LINGER); expect(session.open()).toEqual([]); - inside = origin.announced(Path.Pattern.subtree(Path.from("room/alice/chat"))); + inside = origin.routes(Path.Pattern.subtree(Path.from("room/alice/chat"))); await settle(); expect(session.open()).toEqual(["room/alice/chat/**"]); @@ -632,7 +632,7 @@ test("a scoped session filters discovered routes and requests under its root", a const session = new FakeSession(); forwardAnnounced(session.session, scoped); - const all = origin.announced(); + const all = origin.routes(); const events = record(all); await settle(); // Session-relative: the scope's root is the session's. @@ -665,8 +665,8 @@ test("one failed request leaves the other routes live until the session ends", a const session = new FakeSession(); forwardAnnounced(session.session, origin); - const a = origin.announced(Path.Pattern.subtree(Path.from("a"))); - const b = origin.announced(Path.Pattern.subtree(Path.from("b"))); + const a = origin.routes(Path.Pattern.subtree(Path.from("a"))); + const b = origin.routes(Path.Pattern.subtree(Path.from("b"))); await settle(); start(session.stream("a/**"), "a"); start(session.stream("b/**"), "b"); @@ -694,7 +694,7 @@ test("an origin watcher syncs with the session's initial set, not before", async const session = new FakeSession(); forwardAnnounced(session.session, origin); - const watch = origin.announced(Path.Pattern.subtree(Path.from("room"))); + const watch = origin.routes(Path.Pattern.subtree(Path.from("room"))); const events = record(watch); await settle(); expect(watch.synced.peek()).toBe(false); @@ -720,7 +720,7 @@ test("a session ending before its initial set lands stops holding the watcher", const session = new FakeSession(); forwardAnnounced(session.session, origin); - const watch = origin.announced(); + const watch = origin.routes(); record(watch); await settle(); expect(watch.synced.peek()).toBe(false); @@ -739,7 +739,7 @@ test("a request synced as it opens releases the watcher", async () => { session.syncedAtOnce = true; forwardAnnounced(session.session, origin); - const watch = origin.announced(); + const watch = origin.routes(); record(watch); await settle(); expect(session.requests).toHaveLength(1); diff --git a/js/net/src/connection/forward.ts b/js/net/src/connection/forward.ts index fa1ab2f6ebd..f1792248e1f 100644 --- a/js/net/src/connection/forward.ts +++ b/js/net/src/connection/forward.ts @@ -24,7 +24,7 @@ const LINGER = Milli(2000); /** One announce request open on the session, and the routes it currently reports. */ interface Interest { - readonly announced: Announce.Consumer; + readonly announced: Announce.Routes; readonly reported: Set; /** The pending close, set while nothing at or beneath the prefix is watched. */ linger?: () => void; @@ -89,7 +89,7 @@ export function forwardAnnounced(conn: Established, origin: OriginProducer): voi void serveRequests(conn, origin); - const report = (interest: Interest, event: Announce.Event) => { + const report = (interest: Interest, event: Announce.RouteEvent) => { const { prefix, route } = event; if (event.kind === "end") { unreport(interest, prefix); @@ -173,7 +173,7 @@ export function forwardAnnounced(conn: Established, origin: OriginProducer): voi // Hidden and covering routes are mirrored too; each local reader opts in on its own. const interest: Interest = { - announced: conn.announced(Path.Pattern.subtree(prefix), { hidden: true, covering: true }), + announced: conn.routes(Path.Pattern.subtree(prefix), { hidden: true, covering: true }), reported: new Set(), closing: false, held: new Map(), diff --git a/js/net/src/connection/pool.test.ts b/js/net/src/connection/pool.test.ts index f849baf5145..d62e72772e2 100644 --- a/js/net/src/connection/pool.test.ts +++ b/js/net/src/connection/pool.test.ts @@ -264,14 +264,14 @@ test("a borrowed connection origin exposes live routes and dynamic serving", asy const prefix = Path.from("on-demand"); const route = table.requestsRoute(prefix); await advance(); - expect(announcement).toMatchObject({ kind: "start", prefix }); + expect(announcement).toMatchObject({ kind: "present", prefix }); let withdrawal: unknown; void live.next().then((event) => { withdrawal = event; }); route.close(); await advance(); - expect(withdrawal).toMatchObject({ kind: "end", prefix }); + expect(withdrawal).toMatchObject({ kind: "absent", prefix }); live.close(); } finally { handle.close(); @@ -605,7 +605,7 @@ test("a handle's announcements sync with the shared origin", async () => { stubTransports(); const handle = new Connection({ url }); - const watch = handle.announced(); + const watch = handle.routes(); expect(watch.synced.peek()).toBe(false); await advance(); diff --git a/js/net/src/connection/pool.ts b/js/net/src/connection/pool.ts index 6e0d499a16d..42a89b2faad 100644 --- a/js/net/src/connection/pool.ts +++ b/js/net/src/connection/pool.ts @@ -7,7 +7,7 @@ import { Milli, Nano } from "@moq/clock"; import { Effect, type GetPromise, type Getter, Once, Signal } from "@moq/signals"; import type * as Announce from "../announce.ts"; -import { Producer as AnnounceProducer } from "../announced.ts"; +import { Producer as AnnounceProducer, list, type Routes } from "../announced.ts"; import type * as Auth from "../auth.ts"; import type { Handle } from "../bandwidth.ts"; import * as Origin from "../origin.ts"; @@ -348,6 +348,15 @@ export class Connection { * the old relay's origin, then the new one's arrivals stream in. */ announced(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Announce.Consumer { + return list(this.routes(scope, options)); + } + + /** + * Every route change matching `scope`, spanning reconnects like {@link announced}. + * + * @internal + */ + routes(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Routes { const producer = new AnnounceProducer(); const consumer = producer.consume(); @@ -364,7 +373,7 @@ export class Connection { return; } // A URL switch retracts what the old origin announced. - pumpAnnounced(effect, origin.announced(scope, options), producer); + pumpAnnounced(effect, origin.routes(scope, options), producer); }); closeUnwanted(producer); diff --git a/js/net/src/connection/reload.test.ts b/js/net/src/connection/reload.test.ts index 5adcd6e91c8..6cc4ebaa371 100644 --- a/js/net/src/connection/reload.test.ts +++ b/js/net/src/connection/reload.test.ts @@ -583,7 +583,7 @@ test("origins span reconnects: local re-announces, remote re-populates", async ( const pair = createMockTransportPair(Lite.ALPN_05); const saw = new OriginProducer(); // The server watches everything, so it asks the client for announcements. - const watching = saw.announced(); + const watching = saw.routes(); const serverOrigin = new OriginProducer(); void accept(pair.server, url, { publish: serverOrigin.consume(), consume: saw }).then((session) => { publish(serverOrigin, Path.from("remote")); @@ -603,7 +603,7 @@ test("origins span reconnects: local re-announces, remote re-populates", async ( }); const reader = subscribeOrigin.consume(); // A watch held across the reconnect: each session re-opens its announce request. - const watching = reader.announced(); + const watching = reader.routes(); try { // First session: the server's broadcast lands in the client origin, and the client's @@ -1046,7 +1046,7 @@ test("closing an announce consumer during upstream teardown does not append retr test("announced accepts a non-prefix scope before any session exists", () => { const connection = new Connection({ enabled: false }); try { - const announced = connection.announced(Path.Pattern.parse("room/*")); + const announced = connection.routes(Path.Pattern.parse("room/*")); announced.close(); } finally { connection.close(); @@ -1090,7 +1090,7 @@ test("a watcher syncs with the server's initial set, and again after a reconnect }; const reload = viaOrigin ? new Reload({ ...props, consume: clientOrigin }) : undefined; const connection = viaOrigin ? undefined : new Connection({ ...props, share: false }); - const watching = connection ? connection.announced() : clientOrigin.announced(); + const watching = connection ? connection.routes() : clientOrigin.routes(); const seen = new Set(); void (async () => { for await (const event of watching) { diff --git a/js/net/src/connection/reload.ts b/js/net/src/connection/reload.ts index 243fb0b7862..43b53f72ff3 100644 --- a/js/net/src/connection/reload.ts +++ b/js/net/src/connection/reload.ts @@ -847,7 +847,7 @@ export class Reload { * * @internal */ -export function pumpAnnounced(effect: Effect, upstream: Announce.Consumer, producer: Announce.Producer) { +export function pumpAnnounced(effect: Effect, upstream: Announce.Routes, producer: Announce.Producer) { // The last event per active route rides along for its retraction. const active = new Map(); let live = true; diff --git a/js/net/src/connection/scope.test.ts b/js/net/src/connection/scope.test.ts index c4d8e4fe784..c59a729acf1 100644 --- a/js/net/src/connection/scope.test.ts +++ b/js/net/src/connection/scope.test.ts @@ -31,7 +31,7 @@ for (const protocol of [Lite.ALPN_07_WIP, Ietf.ALPN.DRAFT_18]) { connect({ url, transport: pair.client, consume }), accept({ url, transport: pair.server, publish: publish.consume() }), ]); - const announced = destination.announced(undefined, { hidden: true }); + const announced = destination.routes(undefined, { hidden: true }); try { const received: string[] = []; for (let index = 0; index < 3; index++) { diff --git a/js/net/src/goaway-requests.test.ts b/js/net/src/goaway-requests.test.ts index d041f145f49..52636fccdc5 100644 --- a/js/net/src/goaway-requests.test.ts +++ b/js/net/src/goaway-requests.test.ts @@ -130,10 +130,10 @@ async function handover(kind: "lite" | "ietf"): Promise { accept({ transport: pair.server, url, publish: publish.consume() }), ]); - const announced = client.announced(); + const announced = client.routes(); // Watching the origin has the session discover routes into it. Request once the route // lands, so the request resolves through the table rather than blind. - const watching = consume.announced(); + const watching = consume.routes(); expect((await watching.next())?.kind).toBe("start"); const request = consume.request(Path.from("room")); let replacement: Awaited> | undefined; @@ -185,7 +185,7 @@ async function handover(kind: "lite" | "ietf"): Promise { else await expect(fetched).rejects.toThrow(/not supported/); // A new announce-interest opens too, and sees the route at the drain cost. - const interest = client.announced(); + const interest = client.routes(); const drained = await interest.next(); expect(drained?.route.cost).toBe(DRAIN); interest.close(); @@ -193,7 +193,7 @@ async function handover(kind: "lite" | "ietf"): Promise { expect(pair.client.sendStreams.bidi.length).toBeGreaterThan(opened); const drainingOpened = pair.client.sendStreams.bidi.length; - const routes = consume.consume().announced(); + const routes = consume.consume().routes(); expect((await routes.next())?.kind).toBe("start"); const pair2 = createMockTransportPair(protocol); @@ -274,7 +274,7 @@ test("announcing and subscribing after GOAWAY still open streams", async () => { expect(opened).toBe(true); opened = false; - const announced = subscriber.announced(); + const announced = subscriber.routes(); await waitUntil(() => opened); announced.close(); } @@ -317,9 +317,9 @@ async function routeDeath(kind: "lite" | "ietf", after: boolean): Promise accept({ transport: pair.server, url, publish: publish.consume() }), ]); - const watching = consume.announced(); + const watching = consume.routes(); const request = consume.request(Path.from("room")); - let routes: ReturnType | undefined; + let routes: ReturnType | undefined; let replacement: Awaited> | undefined; let replacementServer: Awaited> | undefined; @@ -335,7 +335,7 @@ async function routeDeath(kind: "lite" | "ietf", after: boolean): Promise else await sendLiteGoaway(pair.server); await client.draining; - routes = consume.announced(); + routes = consume.routes(); expect((await routes.next())?.kind).toBe("start"); const pair2 = createMockTransportPair(protocol); [replacement, replacementServer] = await Promise.all([ diff --git a/js/net/src/ietf/connection.ts b/js/net/src/ietf/connection.ts index f21f6e3dc76..1f47b6a9498 100644 --- a/js/net/src/ietf/connection.ts +++ b/js/net/src/ietf/connection.ts @@ -1,6 +1,6 @@ import { Nano, Second } from "@moq/clock"; import { type GetPromise, type Getter, Once, race, Signal } from "@moq/signals"; -import type * as announce from "../announced.ts"; +import * as announce from "../announced.ts"; import type * as Auth from "../auth.ts"; import { AuthSession } from "../auth_session.ts"; import type { Established } from "../connection/established.ts"; @@ -312,9 +312,14 @@ export class Connection implements Established { } } - /** Gets an announced reader for `scope`; see {@link Established.announced}. */ + /** The paths announced matching `scope`, each present or absent; see {@link Established.announced}. */ announced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer { - return this.#subscriber.announced(scope, options); + return announce.list(this.#subscriber.routes(scope, options)); + } + + /** Every route change matching `scope`, for code that forwards routes. @internal */ + routes(scope?: Path.Pattern, options?: announce.Options): announce.Routes { + return this.#subscriber.routes(scope, options); } /** Accepts request streams and dispatches them. */ diff --git a/js/net/src/ietf/goaway.test.ts b/js/net/src/ietf/goaway.test.ts index c93c19eb45d..7ceb767ae72 100644 --- a/js/net/src/ietf/goaway.test.ts +++ b/js/net/src/ietf/goaway.test.ts @@ -209,7 +209,7 @@ for (const [version, alpn] of [ version, client: true, }); - const announced = connection.announced(); + const announced = connection.routes(); try { const request = await Stream.accept(pair.server, version); if (!request) throw new Error("no namespace subscription"); diff --git a/js/net/src/ietf/peer-violations.test.ts b/js/net/src/ietf/peer-violations.test.ts index e2e770d4498..27b4e41a37a 100644 --- a/js/net/src/ietf/peer-violations.test.ts +++ b/js/net/src/ietf/peer-violations.test.ts @@ -146,7 +146,7 @@ for (const [version, alpn] of versions) { }); const acquiring = spyOn(Slots.prototype, "tryAcquire"); try { - const announced = subscriber.announced(); + const announced = subscriber.routes(); await announced.closed; expect(acquiring).toHaveBeenCalledTimes(3); // a, b, c; neither DONE nor the repeat takes another slot. expect((await pair.client.closed).closeCode).toBe(SessionCode.TooManyRequests); @@ -169,7 +169,7 @@ for (const [version, alpn] of versions) { cluster: { self, peer }, limits: { announces: 1 }, }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const stream = await Stream.accept(pair.client, version); if (!stream) throw new Error("missing namespace stream"); const answer = async (stream: Stream) => { @@ -200,7 +200,7 @@ for (const [version, alpn] of versions) { } else { stream.abort(new StreamError(StreamCode.Cancel)); await announced.closed; - const next = subscriber.announced(); + const next = subscriber.routes(); const replacement = await Stream.accept(pair.client, version); if (!replacement) throw new Error("missing replacement namespace stream"); await answer(replacement); @@ -223,7 +223,7 @@ for (const [version, alpn] of versions) { quic: pair.server, limits: { announces: 1 }, }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); try { const inline = await Stream.accept(pair.client, version); if (!inline) throw new Error("missing namespace stream"); diff --git a/js/net/src/ietf/subscriber.test.ts b/js/net/src/ietf/subscriber.test.ts index 2cfaee4e23e..de5ccc3c153 100644 --- a/js/net/src/ietf/subscriber.test.ts +++ b/js/net/src/ietf/subscriber.test.ts @@ -64,7 +64,7 @@ test("every peer is asked", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session }); - subscriber.announced(); + subscriber.routes(); expect(await nextStream(pair.client)).toBeDefined(); }); @@ -79,7 +79,7 @@ test("an unsolicited announcement lands", async () => { const session = new NativeSession(pair.server, version, true); const subscriber = new Subscriber({ session }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); // The question we asked, which this peer never answers. expect(await nextStream(pair.client)).toBeDefined(); @@ -127,7 +127,7 @@ test("an unsolicited announcement lands", async () => { test("an advertisement with no path is anonymous", async () => { const pair = createMockTransportPair(ALPN.DRAFT_18); const subscriber = new Subscriber({ session: new NativeSession(pair.server, VERSION, true) }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); expect(await nextStream(pair.client)).toBeDefined(); const stream = await Stream.open(pair.server, { version: VERSION }); @@ -171,7 +171,7 @@ async function inlineNamespace( * before it on the same stream have been read. Announcing an already-announced path is * silent by design, so it cannot be waited on directly. */ -async function syncInline(stream: Stream, announced: announce.Consumer, cluster?: Cluster.Advert): Promise { +async function syncInline(stream: Stream, announced: announce.Routes, cluster?: Cluster.Advert): Promise { await inlineNamespace(stream, Path.from("sentinel"), cluster); expect(await announced.next()).toMatchObject({ prefix: Path.from("sentinel"), @@ -192,7 +192,7 @@ test("an announcement survives the first of its two sources ending", async () => const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); // Unsolicited first, then the same path inline on the subscription. @@ -224,8 +224,8 @@ test("announced lists literal matches unless covering asks for overlapping route const pair = createMockTransportPair(ALPN.DRAFT_18); const subscriber = new Subscriber({ session: new NativeSession(pair.server, VERSION, true) }); const scope = Path.Pattern.parse("**/*.chat"); - const listed = subscriber.announced(scope); - const covering = subscriber.announced(scope, { covering: true }); + const listed = subscriber.routes(scope); + const covering = subscriber.routes(scope, { covering: true }); // `room` could serve `room/lobby.chat`, but its own name is no match. for (const [requestId, path] of [ @@ -255,7 +255,7 @@ test("an announcement ends once its last source does", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); const request = await Stream.open(pair.server, { version: VERSION }); @@ -292,9 +292,9 @@ test("a subscription that dies releases what it advertised", async () => { const subscriber = new Subscriber({ session }); // Two feeds, so one outlives the stream that carries the advertisement. - const doomed = subscriber.announced(); + const doomed = subscriber.routes(); const streamA = await acceptSubscribeNamespace(pair.client); - const survivor = subscriber.announced(); + const survivor = subscriber.routes(); await acceptSubscribeNamespace(pair.client); await inlineNamespace(streamA, Path.from("orphan")); @@ -318,7 +318,7 @@ test("an entry buffered past a consumer close does not pin the path", async () = const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); // Both entries land in one chunk, so the second is buffered while the first is being @@ -333,7 +333,7 @@ test("an entry buffered past a consumer close does not pin the path", async () = // Whatever the loop managed to attach, the stream gave back on its way out. await sleep(Nano.fromMilli(Milli(50))); - const fresh = subscriber.announced(); + const fresh = subscriber.routes(); await acceptSubscribeNamespace(pair.client); const seeded = await Promise.race([fresh.next(), sleep(Nano.fromMilli(Milli(250))).then(() => "nothing" as const)]); expect(seeded).toBe("nothing"); @@ -353,7 +353,7 @@ test("an inline NAMESPACE that looped back through us is dropped", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); // Ours coming back, then someone else's. Only the second is news. @@ -371,7 +371,7 @@ test("an inline NAMESPACE that starts looping back is retracted", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); await inlineNamespace(subscription, Path.from("theirs"), { hops: [PEER], cost: 0n }); @@ -391,7 +391,7 @@ test("a repeated NAMESPACE reprices in place", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); await inlineNamespace(subscription, Path.from("theirs"), { hops: [PEER], cost: 4n }); @@ -415,7 +415,7 @@ test("a PUBLISH_NAMESPACE that looped back through us is refused", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); const request = await Stream.open(pair.server, { version: VERSION }); @@ -449,7 +449,7 @@ test("a NAMESPACE missing its hop path closes the session", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - subscriber.announced(); + subscriber.routes(); const subscription = await acceptSubscribeNamespace(pair.client); // The base form, which a negotiated session must never send. @@ -517,7 +517,7 @@ test("a PUBLISH_NAMESPACE update that starts looping back is detached", async () const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await acceptSubscribeNamespace(pair.client); // Published by 11, relayed by the peer. Every update keeps that publisher. @@ -573,7 +573,7 @@ test("a PUBLISH_NAMESPACE repricing is acknowledged in place", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await acceptSubscribeNamespace(pair.client); const request = await Stream.open(pair.server, { version: VERSION }); @@ -622,7 +622,7 @@ test("a PUBLISH_NAMESPACE update that changes the publisher applies in place", a const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await acceptSubscribeNamespace(pair.client); const request = await Stream.open(pair.server, { version: VERSION }); @@ -684,7 +684,7 @@ test("a repeated PUBLISH_NAMESPACE is a protocol violation", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, quic: pair.server, cluster: { self: SELF, peer: PEER } }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await acceptSubscribeNamespace(pair.client); const advert = new PublishNamespace({ @@ -793,7 +793,7 @@ test("a refused SUBSCRIBE or SUBSCRIBE_NAMESPACE ends its stream cleanly", async peer.writer.close(); }; - const announced = subscriber.announced(); + const announced = subscriber.routes(); const namespace = await nextStream(pair.client); if (!namespace) throw new Error("no SUBSCRIBE_NAMESPACE was sent"); expect(await namespace.reader.u53()).toBe(SubscribeNamespace.id); @@ -1362,8 +1362,8 @@ test("every object in a chunk reaches the reader before it wakes", async () => { test("local readers filter hidden unsolicited namespaces from a legacy peer", async () => { const pair = createMockTransportPair(ALPN.DRAFT_18); const subscriber = new Subscriber({ session: new NativeSession(pair.server, VERSION, true) }); - const plain = subscriber.announced(); - const opted = subscriber.announced(undefined, { hidden: true }); + const plain = subscriber.routes(); + const opted = subscriber.routes(undefined, { hidden: true }); const handlers: Promise[] = []; const streams: Stream[] = []; for (const path of [".stats/node", "visible"]) { @@ -1485,7 +1485,7 @@ test("an object datagram is a datagram group", async () => { test("a more specific unnamed announcement replaces the consumed source", async () => { const pair = createMockTransportPair(ALPN.DRAFT_18); const subscriber = new Subscriber({ session: new NativeSession(pair.server, VERSION, true) }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await acceptSubscribeNamespace(pair.client); const pool = Path.from("pool"); const job = Path.from("pool/job"); @@ -1558,17 +1558,17 @@ test("a request overlapping one on its way out waits for the peer to end it", as const session = new NativeSession(pair.server, version, true); const subscriber = new Subscriber({ session }); - const narrow = subscriber.announced(Path.Pattern.subtree(Path.from("a/b"))); + const narrow = subscriber.routes(Path.Pattern.subtree(Path.from("a/b"))); const stream = await acceptSubscribeNamespace(pair.client, version); await inlineNamespace(stream, Path.from("x"), undefined, version); expect(await narrow.next()).toMatchObject({ prefix: Path.from("a/b/x"), kind: "start" }); // A request still open is no blocker, and hears the narrower one's route go at once. - const watcher = subscriber.announced(Path.Pattern.subtree(Path.from("a/b"))); + const watcher = subscriber.routes(Path.Pattern.subtree(Path.from("a/b"))); const watching = await acceptSubscribeNamespace(pair.client, version); expect(await watcher.next()).toMatchObject({ prefix: Path.from("a/b/x"), kind: "start" }); narrow.close(); - const broad = subscriber.announced(Path.Pattern.subtree(Path.from("a"))); + const broad = subscriber.routes(Path.Pattern.subtree(Path.from("a"))); expect(await watcher.next()).toMatchObject({ prefix: Path.from("a/b/x"), kind: "end" }); // Draft 22 cancels with a reset, and the broader request waits on the peer's half. @@ -1632,7 +1632,7 @@ test("counted NAMESPACEs sync", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session, activeCount: true }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); const subscription = await answerCounted(pair.client, 2); await inlineNamespace(subscription, Path.from("a")); expect(await announced.next()).toMatchObject({ prefix: Path.from("a"), kind: "start" }); @@ -1657,7 +1657,7 @@ test("an uncounted answer syncs on the OK", async () => { const session = new NativeSession(pair.server, VERSION, true); const subscriber = new Subscriber({ session }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await yieldTask(); expect(announced.synced.peek()).toBe(false); await acceptSubscribeNamespace(pair.client); @@ -1678,7 +1678,7 @@ test("an ACTIVE_COUNT that does not match the negotiation closes the session", a const warn = spyOn(console, "warn").mockImplementation(() => void 0); onTestFinished(() => warn.mockRestore()); - subscriber.announced(); + subscriber.routes(); await answerCounted(pair.client, count); await violationClosed(pair); } @@ -1693,7 +1693,7 @@ test("a namespace subscription closes the session once over a violation", async onTestFinished(() => warn.mockRestore()); const close = spyOn(pair.server, "close"); - subscriber.announced(); + subscriber.routes(); await answerCounted(pair.client, undefined); await violationClosed(pair); await yieldTask(); @@ -1709,7 +1709,7 @@ test.each(["done", "fin"] as const)("a counted set cut short by %s closes the se const warn = spyOn(console, "warn").mockImplementation(() => void 0); onTestFinished(() => warn.mockRestore()); - subscriber.announced(); + subscriber.routes(); const subscription = await answerCounted(pair.client, 2); await inlineNamespace(subscription, Path.from("a")); if (cut === "done") { diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index 352f6da0483..9880c0bcab5 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -329,7 +329,7 @@ export class Subscriber { * The request goes out once every overlapping request already closed here is off the * wire, so a peer that refuses overlapping requests never sees this one beside them. */ - announced(scope: Path.Pattern = Path.Pattern.all(), options?: announce.Options): announce.Consumer { + routes(scope: Path.Pattern = Path.Pattern.all(), options?: announce.Options): announce.Routes { // The wire speaks announce interest by prefix. const prefix = scopeHead(scope); const filter: Asking = { diff --git a/js/net/src/integration.test.ts b/js/net/src/integration.test.ts index a7fa963a5f6..dc18016786f 100644 --- a/js/net/src/integration.test.ts +++ b/js/net/src/integration.test.ts @@ -1,7 +1,7 @@ import { afterEach, expect, mock, onTestFinished, spyOn, test } from "bun:test"; import { Instant, Manual, Milli, Nano, now, sleep, yieldNow } from "@moq/clock"; import type { Getter } from "@moq/signals"; -import type * as Announce from "./announce.ts"; +import type * as Announce from "./announced.ts"; import { type Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts"; import { type AcceptProps, @@ -124,14 +124,14 @@ async function runPublishSubscribeFlow(protocol: string, version?: number) { })(); // Client discovers announced broadcast - const announced = client.announced(); + const announced = client.routes(); const entry = await announced.next(); if (!entry) throw new Error("expected entry"); expect(entry.prefix).toBe("test" as Path.Valid); expect(entry.kind).toBe("start"); // Scoped discovery only echoes the suffix on the wire, but presents the whole path. - const prefixed = client.announced(Path.Pattern.subtree(Path.from("root"))); + const prefixed = client.routes(Path.Pattern.subtree(Path.from("root"))); const prefixedEntry = await prefixed.next(); if (!prefixedEntry) throw new Error("expected prefixed entry"); expect(prefixedEntry.prefix).toBe("root/child" as Path.Valid); @@ -518,7 +518,7 @@ test("integration: lite draft-06 announce lifecycle", async () => { // Announced before the client asks, so it can ride the initial set. const first = publish(origin, Path.from("first")); - const announced = client.announced(); + const announced = client.routes(); let entry = await announced.next(); if (!entry) throw new Error("expected announce"); expect(entry.prefix).toBe("first" as Path.Valid); @@ -554,7 +554,7 @@ test("integration: lite draft-06 announce lifecycle", async () => { }); /** Collect announced prefixes until `until` arrives. */ -async function announcedUntil(announced: Announce.Consumer, until: string) { +async function announcedUntil(announced: Announce.Routes, until: string) { const seen: string[] = []; while (!seen.includes(until)) { const entry = await withTimeout(announced.next(), Nano.fromMilli(Milli(1000)), `waiting for ${until}`); @@ -583,17 +583,17 @@ for (const [protocol, carriesOptIn] of [ const hidden = publish(origin, Path.from(".x/y")); const visible = publish(origin, Path.from("visible")); - const plain = client.announced(); + const plain = client.routes(); expect(await announcedUntil(plain, "visible")).toEqual(["visible"]); // An IETF reader shares the session's table, so `visible` may land before the // opted-in request's own answer; wait on the hidden path itself where it is due. - const opted = client.announced(undefined, { hidden: true }); + const opted = client.routes(undefined, { hidden: true }); if (carriesOptIn) await announcedUntil(opted, ".x/y"); else expect(await announcedUntil(opted, "visible")).toEqual(["visible"]); if (carriesOptIn) { - const named = client.announced(Path.Pattern.parse(".x/**")); + const named = client.routes(Path.Pattern.parse(".x/**")); expect(await announcedUntil(named, ".x/y")).toEqual([".x/y"]); named.close(); } @@ -2073,7 +2073,7 @@ async function runOriginFlow(protocol: string, version?: number) { // The announcement lands in the client's origin. const reader = clientOrigin.consume(); - const announced = reader.announced(); + const announced = reader.routes(); expect(await announced.next()).toMatchObject({ prefix: Path.from("test"), kind: "start" }); // Consuming through the origin reaches the wire. @@ -2116,7 +2116,7 @@ test("origin: remote entries retract when the session dies, local ones survive", const reader = clientOrigin.consume(); // Watching is what has the session discover the peer's routes. - const watching = reader.announced(); + const watching = reader.routes(); await until(() => wireOf(reader).routes(Path.from("remote"))); client.abort(); @@ -2150,8 +2150,8 @@ test("origin: one origin on both directions consumes locally and never echoes", ]); // Both sides watch everything, so each session asks the other for announcements. - const watchingShared = shared.announced(); - const watchingServer = serverSees.announced(); + const watchingShared = shared.routes(); + const watchingServer = serverSees.routes(); // The server announces a broadcast; it lands in the shared origin as a remote entry. { @@ -2254,7 +2254,7 @@ test.each([Lite.ALPN_03, Lite.ALPN_05, Lite.ALPN_06, Lite.ALPN_07_WIP])( // Repeated watch cycles must each give their stream back, not pile up on the peer. for (let i = 1; i <= 3; i++) { - const announced = client.announced(Path.Pattern.subtree(Path.from("room"))); + const announced = client.routes(Path.Pattern.subtree(Path.from("room"))); expect((await announced.next())?.kind).toBe("start"); announced.close(); await until(() => ended === i); @@ -2284,7 +2284,7 @@ test.each([Lite.ALPN_05, Lite.ALPN_06, Lite.ALPN_07_WIP])( accept(pair.server, url, { publish: new OriginProducer().consume() }), ]); - const announced = client.announced(Path.Pattern.subtree(Path.from("room"))); + const announced = client.routes(Path.Pattern.subtree(Path.from("room"))); await until(() => started === 1); announced.close(); await until(() => ended === 1); @@ -2330,7 +2330,7 @@ for (const alpn of [Lite.ALPN_06, Lite.ALPN_07_WIP]) { // Browse, then play what the listing found. const reader = clientOrigin.consume(); - const listing = reader.announced(Path.Pattern.subtree(Path.from("room"))); + const listing = reader.routes(Path.Pattern.subtree(Path.from("room"))); expect((await listing.next())?.kind).toBe("start"); const request = reader[method](Path.from("room/cam")); await until(() => request.active.peek() !== undefined); @@ -2379,7 +2379,7 @@ test.each([Ietf.ALPN.DRAFT_18])( accept(pair.server, url, { publish: new OriginProducer().consume() }), ]); - const announced = client.announced(Path.Pattern.subtree(Path.from("room"))); + const announced = client.routes(Path.Pattern.subtree(Path.from("room"))); await until(() => started === 1); announced.close(); await until(() => ended === 1); @@ -2501,7 +2501,7 @@ test("origin: overlapping sessions carrying one path fail over", async () => { return { client, server, serverOrigin, broadcast, serving }; }; - const watching = clientOrigin.announced(); + const watching = clientOrigin.routes(); const first = await setup(); const second = await setup(); @@ -2594,7 +2594,7 @@ test("create then announce is discoverable on the wire", async () => { accept(pair.server, url, { publish: origin.consume() }), ]); - const announced = client.announced(); + const announced = client.routes(); const broadcastPublication = origin.createBroadcast(Path.from("later")); const broadcast = broadcastPublication.broadcast; broadcast.createTrack("chat", { timescale: Timescale.MILLI }); @@ -2630,7 +2630,7 @@ test("a handle serves a request under live/** over the wire", async () => { accept(pair.server, url, { publish: origin.consume() }), ]); - const announced = client.announced(); + const announced = client.routes(); const entry = await announced.next(); expect(entry?.prefix).toBe("live" as Path.Valid); expect(entry?.kind).toBe("start"); diff --git a/js/net/src/lite/compression.test.ts b/js/net/src/lite/compression.test.ts index 21ee318c979..294ebfc5731 100644 --- a/js/net/src/lite/compression.test.ts +++ b/js/net/src/lite/compression.test.ts @@ -27,7 +27,7 @@ for (const downstream of [ALPN_06, ALPN_07_WIP]) { accept({ url, transport: pair.server, publish: publish.consume() }), ])), ); - const announcements = consume.announced(); + const announcements = consume.routes(); try { while ((await announcements.next())?.kind !== "start") {} } finally { diff --git a/js/net/src/lite/connection.test.ts b/js/net/src/lite/connection.test.ts index 8d3c77f56dc..f1b60e94564 100644 --- a/js/net/src/lite/connection.test.ts +++ b/js/net/src/lite/connection.test.ts @@ -685,7 +685,7 @@ test("close waits for a request served while withdrawals are in flight", async ( connect({ url, transport: pair.client, consume: destination }), accept({ url, transport: pair.server, publish: source.consume() }), ]); - const announced = destination.announced(); + const announced = destination.routes(); let closed = false; void pair.server.closed.then(() => { closed = true; diff --git a/js/net/src/lite/connection.ts b/js/net/src/lite/connection.ts index 9214bddf444..af5fc42b6c0 100644 --- a/js/net/src/lite/connection.ts +++ b/js/net/src/lite/connection.ts @@ -1,6 +1,6 @@ import { Milli, Nano } from "@moq/clock"; import { Effect, type GetPromise, type Getter, Once, Signal } from "@moq/signals"; -import type * as announce from "../announced.ts"; +import * as announce from "../announced.ts"; import type * as Auth from "../auth.ts"; import { AuthSession } from "../auth_session.ts"; import type { Established } from "../connection/established.ts"; @@ -337,8 +337,14 @@ export class Connection implements Established { } } + /** The paths announced matching `scope`, each present or absent; see {@link Established.announced}. */ announced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer { - return this.#subscriber.announced(scope, options); + return announce.list(this.#subscriber.routes(scope, options)); + } + + /** Every route change matching `scope`, for code that forwards routes. @internal */ + routes(scope?: Path.Pattern, options?: announce.Options): announce.Routes { + return this.#subscriber.routes(scope, options); } async #runSession() { diff --git a/js/net/src/lite/refresh.test.ts b/js/net/src/lite/refresh.test.ts index 4a1cc2e0524..3e403d553ab 100644 --- a/js/net/src/lite/refresh.test.ts +++ b/js/net/src/lite/refresh.test.ts @@ -37,7 +37,7 @@ test.each([ALPN_06, ALPN_07_WIP])("refresh joins reach a browser publisher on %s accept({ url, transport: pair.server, publish: source.consume() }), ])), ); - const announcements = b.announced(); + const announcements = b.routes(); while ((await announcements.next())?.kind !== "start") {} const request = b.request(Path.from("room")); while (request.active.peek() === undefined) await request.active.changed(); diff --git a/js/net/src/lite/subscriber.test.ts b/js/net/src/lite/subscriber.test.ts index c1c0acba951..51fbdfc26e6 100644 --- a/js/net/src/lite/subscriber.test.ts +++ b/js/net/src/lite/subscriber.test.ts @@ -176,7 +176,7 @@ test("an announce consumer closed while its stream opens sends nothing on it", a } as unknown as WebTransport; const subscriber = new Subscriber(quic, Version.DRAFT_06, HopSchema.parse(1n)); - const announced = subscriber.announced(Path.Pattern.subtree(Path.from("room"))); + const announced = subscriber.routes(Path.Pattern.subtree(Path.from("room"))); announced.close(); // The slot frees up only after the consumer left. opening.resolve(); @@ -192,7 +192,7 @@ test("a local empty hop chain is not anonymous", () => { test("a max-length chain plus withheld responder is dropped", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const hops = Array.from({ length: MAX_HOPS }, (_, i) => HopSchema.parse(BigInt(i + 1))); @@ -219,7 +219,7 @@ test("a max-length chain plus withheld responder is dropped", async () => { test("an unidentified responder keeps hop 0 on a nonempty chain", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(UNKNOWN_HOP, 0).encode(w, Version.DRAFT_06)); @@ -242,7 +242,7 @@ test("an unidentified responder keeps hop 0 on a nonempty chain", async () => { test("a received hop list naming no publisher stays anonymous", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(UNKNOWN_HOP, 0).encode(w, Version.DRAFT_06)); @@ -259,7 +259,7 @@ test("a received hop list naming no publisher stays anonymous", async () => { test("a received chain starting with hop 0 is forwarded unchanged", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06)); @@ -280,7 +280,7 @@ test("a received chain starting with hop 0 is forwarded unchanged", async () => test("an update moves the route in place, even from another publisher", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const room = Path.from("room"); @@ -333,7 +333,7 @@ test("an update moves the route in place, even from another publisher", async () test("a lite-07 restart replaces the instance, and the next consume subscribes fresh", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_07); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const room = Path.from("room"); @@ -373,7 +373,7 @@ test("a lite-07 restart replaces the instance, and the next consume subscribes f test("a lite-07 takeover surfaces as a start beneath its predecessor, or a restart of it", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_07); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const pool = Path.from("pool"); const job = Path.from("pool/job"); @@ -425,7 +425,7 @@ test.each([ ["a predecessor not covering it", 0n, "other"], ] as const)("a lite-07 takeover of %s ends the stream", async (_, predecessor, suffix) => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_07); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_07)); @@ -462,7 +462,7 @@ test.each([ ["an end then a start", Version.DRAFT_06], ] as const)("%s of a prefix stops sharing what was consumed beneath it", async (_, version) => { const { subscriber, send, settle } = announceHarness(version); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const pool = Path.from("pool"); const job = Path.from("pool/job"); @@ -506,7 +506,7 @@ test.each([ test("an update that re-prices the same publisher emits the new route", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06)); @@ -538,7 +538,7 @@ test("an update that re-prices the same publisher emits the new route", async () test("a lite-05 duplicate announce follows the same update rule", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_05); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_05)); @@ -562,7 +562,7 @@ test("a lite-05 duplicate announce follows the same update rule", async () => { // that updates in place and keeps the shared broadcast, as does one that names a publisher. test("an update from an unidentified publisher updates in place", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const room = Path.from("room"); @@ -669,7 +669,7 @@ test("an announce skipped as a reflected loop still holds its path", async () => // The subscriber's own origin, so a chain naming it reflects back through us. const SELF = 1n; const { subscriber, send, abortReason, sessionEnded, settle } = announceHarness(Version.DRAFT_06, SELF); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06)); @@ -711,7 +711,7 @@ test("an announce skipped as a reflected loop still holds its path", async () => test("an update replaces an announce that was skipped as a reflected loop", async () => { const SELF = 1n; const { subscriber, send, settle } = announceHarness(Version.DRAFT_06, SELF); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06)); @@ -741,7 +741,7 @@ test("an update replaces an announce that was skipped as a reflected loop", asyn test("an update keeps the instance of an announce skipped as a reflected loop", async () => { const SELF = 1n; const { subscriber, send, settle } = announceHarness(Version.DRAFT_07, SELF); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_07)); @@ -770,7 +770,7 @@ test("an update keeps the instance of an announce skipped as a reflected loop", test("retiring an id whose announce was skipped ends nothing", async () => { const SELF = 1n; const { subscriber, send, settle } = announceHarness(Version.DRAFT_06, SELF); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06)); @@ -805,7 +805,7 @@ test("retiring an id whose announce was skipped ends nothing", async () => { test("a draft-02 initial announcement can still be retracted", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_02); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); // ANNOUNCE_INIT carries the initial set. These are advertisements like any other, so @@ -823,7 +823,7 @@ test("a draft-02 initial announcement can still be retracted", async () => { test("a duplicate start is reported even when its own route reflects", async () => { const SELF = 1n; const { subscriber, send, settle } = announceHarness(Version.DRAFT_06, SELF); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06)); @@ -857,7 +857,7 @@ test("a duplicate start is reported even when its own route reflects", async () test("a draft-02 initial set naming a path twice is refused", async () => { const { subscriber, send, abortReason, sessionEnded, settle } = announceHarness(Version.DRAFT_02); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); // One advertisement per path, and the initial set is advertisements. Two entries for @@ -881,7 +881,7 @@ test("a draft-02 initial set naming a path twice is refused", async () => { test("a violation on a very long path still ends the session", async () => { const SELF = 1n; const { subscriber, send, sessionEnded, settle } = announceHarness(Version.DRAFT_06, SELF); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_06)); @@ -908,7 +908,7 @@ test.each([Version.DRAFT_02, Version.DRAFT_06])( const { subscriber, send, sessionEnded, settle } = announceHarness(version); // Each half fits on the wire alone; the joined path is one byte over. const half = Path.from("x".repeat(Path.MAX_BYTES / 2)); - const announced = subscriber.announced(Path.Pattern.subtree(half)); + const announced = subscriber.routes(Path.Pattern.subtree(half)); await settle(); if (version === Version.DRAFT_02) { @@ -933,7 +933,7 @@ test("a draft-04 duplicate start is a violation, not an update", async () => { // update, is exempt. The Rust loop routes every other version through `start_announce`, // which rejects it. const { subscriber, send, sessionEnded, settle } = announceHarness(Version.DRAFT_04); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const active: AnnounceBroadcast = { status: "active", suffix: Path.from("room"), hops: [PUBLISHER_A] }; @@ -950,7 +950,7 @@ test("a draft-04 duplicate start is a violation, not an update", async () => { test("a draft-05 duplicate start is still an update", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_05); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, Version.DRAFT_05)); @@ -974,7 +974,7 @@ test("a draft-05 duplicate start is still an update", async () => { // Mirrors the Rust `an_unknown_announce_type_keeps_the_stream`. test("an unknown announce type between starts keeps the stream", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); const start = (suffix: string) => (w: Writer) => @@ -1717,7 +1717,7 @@ test.each([Version.DRAFT_05, Version.DRAFT_06])( async (version) => { const { quic, streams, opened } = fakeSession(); const subscriber = new Subscriber(quic, version, HopSchema.parse(1n)); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await opened(0); const send = async (encode: (writer: Writer) => Promise) => { const writer = new Writer( @@ -1837,7 +1837,7 @@ test.each([ const warn = spyOn(console, "warn").mockImplementation(() => {}); const { quic, streams, opened } = fakeSession(); const subscriber = new Subscriber(quic, version, HopSchema.parse(1n)); - const announced = subscriber.announced(); + const announced = subscriber.routes(); try { await opened(0); const pool = await unpinnedPool(version, streams, announced); @@ -1883,7 +1883,7 @@ test("a withdrawal while the subscribe opens closes the answered track", async ( const warn = spyOn(console, "warn").mockImplementation(() => {}); const { quic, streams, opened } = fakeSession([2]); const subscriber = new Subscriber(quic, version, HopSchema.parse(1n)); - const announced = subscriber.announced(); + const announced = subscriber.routes(); try { await opened(0); const pool = await unpinnedPool(version, streams, announced); @@ -2001,7 +2001,7 @@ test("consumes resolve the serving prefix and pin its instance", async () => { const version = Version.DRAFT_07; const { quic, streams, opened } = fakeSession(); const subscriber = new Subscriber(quic, version, HopSchema.parse(1n)); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await opened(0); const peer = new Writer( new WritableStream({ @@ -2064,7 +2064,7 @@ test.each([Version.DRAFT_06, Version.DRAFT_07])( "a more specific start replaces an existing consume on %s", async (version) => { const { subscriber, send, settle } = announceHarness(version); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 0).encode(w, version)); const pool = Path.from("pool"); @@ -2103,7 +2103,7 @@ test.each([Version.DRAFT_05, Version.DRAFT_06])( async (version) => { const { quic, streams, opened } = fakeSession(); const subscriber = new Subscriber(quic, version, HopSchema.parse(1n)); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await opened(0); const peer = new Writer( new WritableStream({ @@ -2806,7 +2806,7 @@ const announceStart = (suffix: string) => (w: Writer) => test("a counted initial set syncs once the reader is past its last announce", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 2).encode(w, Version.DRAFT_06)); @@ -2830,7 +2830,7 @@ test("a counted initial set syncs once the reader is past its last announce", as test("an empty initial set syncs on the answer", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); expect(announced.synced.peek()).toBe(false); @@ -2845,7 +2845,7 @@ test("an empty initial set syncs on the answer", async () => { test("a counted initial set cut short is a protocol violation", async () => { for (const cut of ["ended", "fin"] as const) { const { subscriber, send, finish, sessionEnded, settle } = announceHarness(Version.DRAFT_06); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceOk(PEER, 2).encode(w, Version.DRAFT_06)); @@ -2865,7 +2865,7 @@ test("a counted initial set cut short is a protocol violation", async () => { test("a version without a boundary syncs once the request is out", async () => { const { subscriber, settle } = announceHarness(Version.DRAFT_03); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); expect(announced.synced.peek()).toBe(true); @@ -2875,7 +2875,7 @@ test("a version without a boundary syncs once the request is out", async () => { test("announce init is the initial set", async () => { const { subscriber, send, settle } = announceHarness(Version.DRAFT_02); - const announced = subscriber.announced(); + const announced = subscriber.routes(); await settle(); await send((w) => new AnnounceInit([Path.from("room")]).encode(w, Version.DRAFT_02)); diff --git a/js/net/src/lite/subscriber.ts b/js/net/src/lite/subscriber.ts index 77a699ffb6a..092232cb320 100644 --- a/js/net/src/lite/subscriber.ts +++ b/js/net/src/lite/subscriber.ts @@ -323,7 +323,7 @@ export class Subscriber { * Only routes whose literal name matches `scope` are reported, unless `options.covering` * also asks for those whose subtree overlaps it. */ - announced(scope: Path.Pattern = Path.Pattern.all(), options?: announce.Options): announce.Consumer { + routes(scope: Path.Pattern = Path.Pattern.all(), options?: announce.Options): announce.Routes { const announced = new announce.Producer(); // The wire speaks announce interest by prefix, and echoes suffixes beneath it. const consumer = announced.consume(); diff --git a/js/net/src/lite/tracks.test.ts b/js/net/src/lite/tracks.test.ts index ea5061fd47d..24c83fa01e9 100644 --- a/js/net/src/lite/tracks.test.ts +++ b/js/net/src/lite/tracks.test.ts @@ -504,7 +504,7 @@ test("an instance-pinned front lists its serving route's tracks", async () => { broadcastPublication.announce({ instance: Instance.parse("01900000-0000-7000-8000-000000000001") }); const reader = clientOrigin.consume(); - const announced = reader.announced(); + const announced = reader.routes(); expect(await announced.next()).toMatchObject({ prefix: Path.from("room"), kind: "start" }); const request = reader.request(Path.from("room")); await settle(); diff --git a/js/net/src/origin.test.ts b/js/net/src/origin.test.ts index dfe0e590188..7ba16c0075e 100644 --- a/js/net/src/origin.test.ts +++ b/js/net/src/origin.test.ts @@ -71,7 +71,7 @@ test("a borrowed table exposes dynamic serving and a live scoped broadcast map", const origin = new Producer(); const table: Table = origin; const scope = Path.Pattern.parse("room/**"); - const live = await announcedView(table, scope); + const live = await announcedView(origin, scope); const changes: ReadonlyMap[] = []; const stop = live.subscribe((value) => changes.push(value)); await new Promise((resolve) => setImmediate(resolve)); @@ -321,7 +321,7 @@ test("announced streams the table under a scope with origin-relative paths", asy const a = publish(origin, Path.from("room/a")); - const announced = consumer.announced(Path.Pattern.subtree(Path.from("room"))); + const announced = consumer.routes(Path.Pattern.subtree(Path.from("room"))); // The initial state arrives first, named from the origin rather than the scope. expect(await announced.next()).toMatchObject({ prefix: Path.from("room/a"), kind: "start" }); @@ -359,10 +359,10 @@ test("hidden paths need an opt-in or a scope naming the dot segment", async () = Path.from(".stats/node"), ]); - const plain = consumer.announced(); + const plain = consumer.routes(); await new Promise((resolve) => setImmediate(resolve)); expect(await plain.next()).toMatchObject({ prefix: Path.from("room/catalog.pro") }); - const opted = consumer.announced(Path.Pattern.parse("room/**"), { hidden: true }); + const opted = consumer.routes(Path.Pattern.parse("room/**"), { hidden: true }); const seen = [(await opted.next())?.prefix, (await opted.next())?.prefix].sort(); await new Promise((resolve) => setImmediate(resolve)); expect(seen).toEqual([Path.from("room/.internal"), Path.from("room/catalog.pro")]); @@ -389,7 +389,7 @@ test("a remote entry resolves by path and retracts on dispose", async () => { handle?.close(); // Announced streams include remote entries. - const announced = consumer.announced(); + const announced = consumer.routes(); expect(await announced.next()).toMatchObject({ prefix: path, kind: "start", route: Route.default }); dispose(); @@ -410,7 +410,7 @@ test("announced keeps a broader covering route at its prefix", async () => { // The scope filters the route without changing the prefix it claims. const scope = Path.Pattern.subtree(Path.from("room/alice")); - const announced = consumer.announced(scope, { covering: true }); + const announced = consumer.routes(scope, { covering: true }); expect(await announced.next()).toMatchObject({ prefix: Path.from("room"), kind: "start" }); dispose(); @@ -441,7 +441,7 @@ test("a local publish shadows a remote entry", async () => { handle?.close(); // One path, one announcement, even though both tables route it. - const announced = consumer.announced(); + const announced = consumer.routes(); expect(await announced.next()).toMatchObject({ prefix: path, kind: "start", route: Route.default }); // Dropping the local publish falls back to the remote entry without a retraction. @@ -565,7 +565,7 @@ test("disposing the newest remote route promotes the fallback", async () => { const keepNewer = newer.consume(); const disposeNewer = serve(origin, path, provider(newer)); - const announced = consumer.announced(); + const announced = consumer.routes(); expect(await announced.next()).toMatchObject({ prefix: path, kind: "start" }); // The newer session dies: without an instance the promoted fallback is another source. @@ -639,7 +639,7 @@ test("requests never appear in announced or the table", async () => { expect(request.active.peek()).toBeDefined(); expect(wireOf(origin).routes(path)).toBe(false); - const announced = consumer.announced(); + const announced = consumer.routes(); publish(origin, Path.from("real")); expect(await announced.next()).toMatchObject({ prefix: Path.from("real"), kind: "start" }); @@ -654,7 +654,7 @@ test("a republish restarts the path", async () => { const path = Path.from("room"); publish(origin, path); - const announced = consumer.announced(); + const announced = consumer.routes(); expect(await announced.next()).toMatchObject({ prefix: path, kind: "start" }); // A new broadcast takes the path: consumers must let go of the replaced one. @@ -670,7 +670,7 @@ test("an identical reconnect restarts without an instance and is quiet with one" const origin = new Producer(); const consumer = origin.consume(); const path = Path.from("room"); - const announced = consumer.announced(); + const announced = consumer.routes(); const route = Route.normalize({ instance, hops: [PEER] }); const old = wireOf(origin).receive(path, route); @@ -988,7 +988,7 @@ test("createBroadcast is invisible to everyone until announce", async () => { const request = consumer.request(path); expect(request.active.peek()).toBeUndefined(); - const announced = consumer.announced(); + const announced = consumer.routes(); broadcastPublication.announce({ cost: 4n }); expect(wireOf(consumer).routes(path)).toBe(true); expect(wireOf(consumer).advertised.peek()?.has(path)).toBe(true); @@ -1045,7 +1045,7 @@ test("a request prefers a cheaper received route over an announced local broadca await settle(); const remote = request.active.peek(); expect(remote).toBeDefined(); - const announced = consumer.announced(); + const announced = consumer.routes(); expect(await announced.next()).toMatchObject({ prefix: path, route: { hops: [PEER] } }); // Re-priced below it, the local broadcast of the same instance wins at once: the request's @@ -1108,7 +1108,7 @@ test("a handle serves a request under live", async () => { const consumer = origin.consume(); const handle = origin.requestsRoute(Path.from("live")); - expect(await consumer.announced().next()).toMatchObject({ prefix: Path.from("live"), kind: "start" }); + expect(await consumer.routes().next()).toMatchObject({ prefix: Path.from("live"), kind: "start" }); const waiting = handle.requested().next(); const request = consumer.request(Path.from("live/cam")); @@ -1177,7 +1177,7 @@ test("a received route still serves a broadcast a session delivered", async () = test("a re-priced route is delivered as an update", async () => { const origin = new Producer(); const handle = origin.requestsRoute(Path.from("live")); - const announced = origin.consume().announced(); + const announced = origin.consume().routes(); expect(await announced.next()).toMatchObject({ prefix: Path.from("live"), kind: "start" }); handle.updateRoute({ cost: 5n }); expect(await announced.next()).toMatchObject({ prefix: Path.from("live"), kind: "update" }); @@ -1800,7 +1800,7 @@ test("announced filters by arbitrary patterns and reports captures", async () => const origin = new Producer(); const consumer = origin.consume(); const broadcast = publish(origin, Path.from("room/alice")); - const announced = consumer.announced(Path.Pattern.parse("room/*")); + const announced = consumer.routes(Path.Pattern.parse("room/*")); const update = await announced.next(); expect(update?.prefix).toBe(Path.from("room/alice")); @@ -1849,7 +1849,7 @@ test("announced filters before rooting and retains lifecycle, routing and watch const unlisten = wireOf(origin).interests((prefix, wanted) => interests.push(`${wanted ? "+" : "-"}${prefix}`)); const source = new BroadcastProducer(); const broad = origin.requestsRoute(Path.from("room")); - const stream = reader.announced(); + const stream = reader.routes(); const events = stream[Symbol.asyncIterator](); const covering = await announcedView(reader, undefined, { covering: true }); expect([...covering.peek().keys()]).toEqual([Path.empty()]); @@ -2028,7 +2028,7 @@ test("a rooted producer shares the table and enforces its pattern union", async expect([...(await announcedView(nested)).peek().keys()]).toEqual([Path.from("alice")]); await new Promise((resolve) => setImmediate(resolve)); expect(() => nested.createBroadcast(Path.from("alice/deep")).broadcast).toThrow("outside the origin scope"); - const announced = nested.announced(); + const announced = nested.routes(); await new Promise((resolve) => setImmediate(resolve)); expect(await announced.next()).toMatchObject({ kind: "start", prefix: Path.from("alice") }); announced.close(); @@ -2107,7 +2107,7 @@ test("closing a derived handle withdraws the sessions and answers attached throu const snapshot = wireOf(scoped).snapshot(Path.empty()); const interests: string[] = []; const unlisten = wireOf(scoped).interests((prefix, wanted) => interests.push(`${wanted ? "+" : "-"}${prefix}`)); - const announced = consumer.announced(); + const announced = consumer.routes(); const upstream = new BroadcastProducer(); const withdraw = wireOf(scoped).answer(path, upstream.consume()); expect(withdraw).toBeDefined(); @@ -2249,7 +2249,7 @@ test("a scoped reader picks the best route its scope can see at a prefix", async (await announcedView(origin, Path.Pattern.parse("room/video"), { covering: true })).peek().get(Path.empty()) ?.cost, ).toBe(5n); - const announced = reader.announced(undefined, { covering: true }); + const announced = reader.routes(undefined, { covering: true }); await new Promise((resolve) => setImmediate(resolve)); expect((await announced.next())?.route.cost).toBe(5n); announced.close(); @@ -2424,7 +2424,7 @@ test("the newest epoch of an instance is announced in place over a cheaper one", const origin = new Producer(); const consumer = origin.consume(); const path = Path.from("room/alice"); - const announced = consumer.announced(); + const announced = consumer.routes(); const instance = Instance.random(); const oldPublication = origin.createBroadcast(path); @@ -2639,7 +2639,7 @@ test.each([ if (named !== undefined) expect(from).toBe(named); const to = NEWER; const requests = dynamic.requested(); - const announced = origin.consume().announced(); + const announced = origin.consume().routes(); expect(await announced.next()).toMatchObject({ prefix, kind: "start" }); const held = origin.consume().request(path); diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index cbabea6b1bd..c9981466f7f 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -1671,6 +1671,11 @@ export class Producer implements Table { return this.#reader.announced(scope, options); } + /** Every route change under `scope`; see {@link Consumer.routes}. @internal */ + routes(scope?: Path.Pattern, options?: Announce.Options): announce.Routes { + return this.#reader.routes(scope, options); + } + /** * Close the origin, every broadcast it still routes, and its announcement streams. Idempotent. * @@ -2251,8 +2256,9 @@ export class Consumer implements Reader { } /** - * The announced routes matching `scope`, as a live stream: every currently advertised - * route arrives first as `start`, then changes as they happen. + * The paths announced matching `scope`, each reported as it becomes present or absent: + * every currently advertised one arrives first as `present`. Another instance taking a + * path over keeps it present; {@link follow} it to see the broadcast change. * Any pattern is accepted. A local broadcast appears once it announces, exactly as a * peer sees it. Only routes whose literal name matches the scope are listed, unless * `options.covering` also asks for every dynamic or received route whose subtree @@ -2262,6 +2268,17 @@ export class Consumer implements Reader { * announcements there. */ announced(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): Announce.Consumer { + return announce.list(this.routes(scope, options)); + } + + /** + * Every change to the routes matching `scope`, for code that forwards routes: a re-price + * is an `update`, and another instance serving a path a `restart`. Scope, options and the + * watch are as for {@link announced}. + * + * @internal + */ + routes(scope: Path.Pattern = Path.Pattern.all(), options?: Announce.Options): announce.Routes { const producer = new announce.Producer(); const patterns = this.#scope.patterns(scope); void producer.closed.then(this.#state.watch([...patterns].map(scopeHead))); diff --git a/js/net/src/request-deadline.test.ts b/js/net/src/request-deadline.test.ts index 9636f4d47d7..93bc49ff167 100644 --- a/js/net/src/request-deadline.test.ts +++ b/js/net/src/request-deadline.test.ts @@ -153,7 +153,7 @@ for (const protocol of ["lite", "ietf"] as const) { protocol === "lite" ? new LiteSubscriber(transport.quic, Lite.DRAFT_07, HopSchema.parse(1n)) : new IetfSubscriber({ session: new NativeSession(transport.quic, Ietf.DRAFT_18, true) }); - const announced = subscriber.announced(); + const announced = subscriber.routes(); try { await transport.created; await clock.advance(Nano.zero); diff --git a/js/net/src/session-limits.test.ts b/js/net/src/session-limits.test.ts index 345bd84d04d..af296baf1e1 100644 --- a/js/net/src/session-limits.test.ts +++ b/js/net/src/session-limits.test.ts @@ -87,7 +87,7 @@ test.each(["lite", "ietf"] as const)("%s closes on the first advertisement beyon limits, }); try { - const announced = subscriber.announced(); + const announced = subscriber.routes(); const ended = await announced.closed; expect(ended).toBeInstanceOf(SessionError); expect((ended as SessionError).code).toBe(SessionCode.TooManyRequests); diff --git a/js/room/src/room.test.ts b/js/room/src/room.test.ts index 8b8260cea0c..16beb40dcf4 100644 --- a/js/room/src/room.test.ts +++ b/js/room/src/room.test.ts @@ -20,7 +20,7 @@ test("room restores the announce prefix and reconciles local identity changes", let update: Net.Announce.Event | undefined = { prefix: Net.Path.from("room-a/bob/camera.hang"), captures: [Net.Path.Pattern.literal(Net.Path.from("bob/camera.hang"))], - kind: "start", + kind: "present", route: { hops: [], cost: 0n }, }; const stream = { diff --git a/js/room/src/room.ts b/js/room/src/room.ts index c9e038438a4..700d4df4cd3 100644 --- a/js/room/src/room.ts +++ b/js/room/src/room.ts @@ -95,7 +95,7 @@ export class Room { const local = this.identity.peek(); if (local && parsed.identity === local) continue; - if (update.kind !== "end") { + if (update.kind !== "absent") { this.#add(parsed.identity, parsed.kind, Moq.Path.from(covered)); } else { this.#remove(parsed.identity, parsed.kind); diff --git a/js/watch/src/broadcast.ts b/js/watch/src/broadcast.ts index 7afc89bd87e..cc322e1cd31 100644 --- a/js/watch/src/broadcast.ts +++ b/js/watch/src/broadcast.ts @@ -60,7 +60,7 @@ function watchCovered( for (;;) { const entry = await announced.next(); if (!entry) break; - if (entry.kind === "end") active.delete(entry.prefix); + if (entry.kind === "absent") active.delete(entry.prefix); else active.add(entry.prefix); covered.set([...active].some((prefix) => Path.hasPrefix(prefix, path))); } diff --git a/js/watch/src/echo.test.ts b/js/watch/src/echo.test.ts index dfb6af5bdb7..af9ac4e6ac7 100644 --- a/js/watch/src/echo.test.ts +++ b/js/watch/src/echo.test.ts @@ -31,7 +31,7 @@ function announced(origin: Origin.Producer): Set { for (;;) { const entry = await listing.next(); if (!entry) break; - if (entry.kind === "end") paths.delete(entry.prefix); + if (entry.kind === "absent") paths.delete(entry.prefix); else paths.add(entry.prefix); } })(); diff --git a/test/interop/clients/js-native/finish.ts b/test/interop/clients/js-native/finish.ts index b943dae595e..c1a2c4cd594 100644 --- a/test/interop/clients/js-native/finish.ts +++ b/test/interop/clients/js-native/finish.ts @@ -56,7 +56,7 @@ export async function readFinish( for (;;) { const event = await routes.next(); if (!event) throw new Error("origin ended before broadcast withdrawal"); - if (event.kind === "end" && event.prefix === path) break; + if (event.kind === "absent" && event.prefix === path) break; } let health = healthRequest.active.peek(); while (!health) { diff --git a/test/interop/clients/js-native/goaway.ts b/test/interop/clients/js-native/goaway.ts index 52af4e03c22..1253356a7c7 100644 --- a/test/interop/clients/js-native/goaway.ts +++ b/test/interop/clients/js-native/goaway.ts @@ -57,7 +57,7 @@ try { for (;;) { const event = await announcements.next(); assert(event, "replacement announcements ended"); - if (event.kind === "start" && event.prefix === "handover") break; + if (event.kind === "present" && event.prefix === "handover") break; } } finally { announcements.close(); From d79d568bc638cfc90557e26d41b803c43cd6d364 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 00:15:27 -0800 Subject: [PATCH 05/21] wip: bindings, docs and migration notes for the announce listing Co-Authored-By: Claude Opus 5.5 --- c/moq/MIGRATE.md | 6 + dart/moq/MIGRATE.md | 14 ++ dart/moq/README.md | 10 +- dart/moq/lib/src/aliases.dart | 27 +-- dart/moq/lib/src/client.dart | 6 +- dart/moq/test/moq_test.dart | 43 +++-- dart/moq_ffi/lib/src/moq.dart | 177 ++---------------- dart/moq_ffi/test/future_test.dart | 2 +- demo/carla/README.md | 2 +- demo/carla/sim/moq_carla_sim/drive.py | 12 +- demo/carla/sim/moq_carla_sim/publish.py | 88 +++++---- demo/carla/sim/tests/conftest.py | 18 +- demo/carla/sim/tests/test_publish.py | 154 ++++++++------- doc/concept/identity.md | 34 ++-- doc/lib/c/index.md | 4 +- doc/lib/dart/index.md | 10 +- doc/lib/go/index.md | 16 +- doc/lib/kt/index.md | 10 +- doc/lib/py/index.md | 8 +- doc/lib/rs/index.md | 5 +- doc/lib/swift/index.md | 10 +- doc/setup/redundancy.md | 6 +- go/wrapper/MIGRATE.md | 22 +++ go/wrapper/README.md | 14 +- go/wrapper/client.go | 2 +- go/wrapper/example_test.go | 2 +- go/wrapper/moq_test.go | 44 +++-- go/wrapper/origin.go | 11 +- go/wrapper/reconnect_test.go | 4 +- go/wrapper/types.go | 20 +- js/net/MIGRATE.md | 5 + kt/README.md | 10 +- kt/moq/MIGRATE.md | 12 ++ .../kotlin/dev/moq/Aliases.kt | 29 +-- .../jvmAndAndroidMain/kotlin/dev/moq/Moq.kt | 7 +- .../kotlin/dev/moq/SmokeTest.kt | 32 ++-- py/moq-rs/MIGRATE.md | 6 + py/moq-rs/README.md | 8 +- py/moq-rs/docs/index.md | 9 +- py/moq-rs/examples/announced.py | 4 +- py/moq-rs/moq/__init__.py | 14 +- py/moq-rs/moq/origin.py | 27 +-- py/moq-rs/tests/test_local.py | 42 +++-- py/moq-rs/tests/test_server.py | 53 +----- quest/m1/announce-takeover.md | 12 +- quest/m1/api-audit/route/README.md | 1 - quest/m1/api-audit/route/events.md | 54 ------ quest/m1/api-audit/route/handle.md | 3 +- quest/m2/room-bench.md | 11 +- rs/moq-c/MIGRATE.md | 7 + rs/moq-ffi/MIGRATE.md | 5 + rs/moq-mux/MIGRATE.md | 6 + rs/moq-net/MIGRATE.md | 29 +++ rs/moq-net/src/model/announced.rs | 9 - swift/MIGRATE.md | 14 ++ swift/README.md | 11 +- swift/Sources/Moq/Aliases.swift | 5 +- swift/Sources/Moq/Origin.swift | 10 +- swift/Tests/MoqTests/SmokeTests.swift | 30 +-- test/interop/clients/c/subscribe.c | 2 +- test/interop/clients/go/main.go | 21 +-- test/interop/clients/python/interop.py | 16 +- 62 files changed, 570 insertions(+), 715 deletions(-) delete mode 100644 quest/m1/api-audit/route/events.md diff --git a/c/moq/MIGRATE.md b/c/moq/MIGRATE.md index e2a9d73e5cd..3b902f18212 100644 --- a/c/moq/MIGRATE.md +++ b/c/moq/MIGRATE.md @@ -6,6 +6,12 @@ How to update your code for each breaking change, newest first. The hand-written crate never published as moq-c: a libmoq 0.6 user applies these entries before moving to the generated API. +### Announcements are a listing ([#7678](https://github.com/moq-dev/moq/pull/7678)) + +`moq_announce_kind` is `MOQ_ANNOUNCE_KIND_PRESENT` (0) or `MOQ_ANNOUNCE_KIND_ABSENT` (1), and `moq_announce_event` loses `predecessor` and `predecessor_len`, changing the C ABI. +Another instance taking a path over keeps it present, and a route's cost changing is not reported. +Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `moq_announce_event.has_captures` is removed, changing the C ABI. Read `captures_len` directly: zero means the filter has no wildcards. Rebuild consumers against the regenerated header and matching native library. diff --git a/dart/moq/MIGRATE.md b/dart/moq/MIGRATE.md index 38f4d5f1f5b..8262fcb0825 100644 --- a/dart/moq/MIGRATE.md +++ b/dart/moq/MIGRATE.md @@ -4,6 +4,20 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing + +`announced(...).updates()` yields `AnnounceEventPresent` when a path becomes present and `AnnounceEventAbsent` when it goes, each carrying an `Announce`. +`AnnounceEventStart` is `AnnounceEventPresent` and `AnnounceEventEnd` is `AnnounceEventAbsent`. +`AnnounceEventUpdate`, `AnnounceEventRestart`, and `AnnounceEventTakeover` are gone: a path whose route or publisher instance changes stays present and is not reported again. +Where you requested the path again on a restart, hold `follow(path)` instead; each `available()` returns the next instance's broadcast. + +```dart +final following = moq.follow('live/camera'); +while (true) { + play(await following.available()); +} +``` + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `Announce.captures` is `List` instead of `List?`. Remove null checks and pass `captures: []` when constructing an announcement for a filter without wildcards. Regenerate bindings and rebuild with the matching native library. diff --git a/dart/moq/README.md b/dart/moq/README.md index cff7d70ce40..8dbec24e263 100644 --- a/dart/moq/README.md +++ b/dart/moq/README.md @@ -10,16 +10,14 @@ final announced = connection.announced( options: const AnnounceOptions(prefix: 'live/', filter: '*/camera'), ); await for (final event in announced.updates()) { - // A restart is a new publisher run at the same path: request it again. A takeover - // continues what an earlier route served, like a start. + // The listing reports each path once while it stays present, even as its + // publisher restarts; `connection.follow(path)` hands out each new run. switch (event) { - case AnnounceEventStart(:final announce) || - AnnounceEventRestart(:final announce) || - AnnounceEventTakeover(:final announce): + case AnnounceEventPresent(:final announce): // Prefix stays origin-relative; captures reports wildcard matches. print(announce.prefix); print(announce.captures); - default: + case AnnounceEventAbsent(): } } ``` diff --git a/dart/moq/lib/src/aliases.dart b/dart/moq/lib/src/aliases.dart index a9c38dde51b..bd14407101e 100644 --- a/dart/moq/lib/src/aliases.dart +++ b/dart/moq/lib/src/aliases.dart @@ -70,27 +70,18 @@ typedef AnnounceRoute = MoqAnnounceRoute; /// 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: [AnnounceEventStart], -/// [AnnounceEventUpdate], [AnnounceEventEnd], [AnnounceEventRestart], or -/// [AnnounceEventTakeover]. +/// 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. typedef AnnounceEvent = MoqAnnounceEvent; -/// A route now covers the prefix; the stream had none there. -typedef AnnounceEventStart = StartMoqAnnounceEvent; - -/// The route covering the prefix changed hops or cost. -typedef AnnounceEventUpdate = UpdateMoqAnnounceEvent; - -/// No route covers the prefix any more; carries its last route. -typedef AnnounceEventEnd = EndMoqAnnounceEvent; - -/// Another publisher instance now serves the prefix: drop what was resolved -/// under it and request afresh. -typedef AnnounceEventRestart = RestartMoqAnnounceEvent; +/// A route now covers the path, which was absent. +typedef AnnounceEventPresent = PresentMoqAnnounceEvent; -/// A route now covers the prefix and continues what the route at `predecessor` -/// served beneath it: keep what was resolved through that one. -typedef AnnounceEventTakeover = TakeoverMoqAnnounceEvent; +/// No route covers the path any more; carries its last route. +typedef AnnounceEventAbsent = AbsentMoqAnnounceEvent; /// 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 267834ddf62..9e374bdd0e1 100644 --- a/dart/moq/lib/src/client.dart +++ b/dart/moq/lib/src/client.dart @@ -221,10 +221,12 @@ final class Moq { Publication createBroadcast(String path) => session.publish().createBroadcast(path: path); - /// Discover routes matching [options]; prefixes stay relative to the origin. + /// 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] - /// that releases the cursor when the subscription ends. + /// that releases the cursor when the subscription ends. A new publisher + /// instance keeps its path present, so use [follow] to see it. AnnounceConsumer announced({ AnnounceOptions options = const AnnounceOptions(), }) => session.consume().announced(config: options._ffi); diff --git a/dart/moq/test/moq_test.dart b/dart/moq/test/moq_test.dart index e2cafbde1e4..47569ca045c 100644 --- a/dart/moq/test/moq_test.dart +++ b/dart/moq/test/moq_test.dart @@ -215,7 +215,7 @@ void main() { expect(client.allocator(), isA()); final announcement = client.announced().updates().firstWhere( - (event) => event is AnnounceEventStart, + (event) => event is AnnounceEventPresent, ); final publication = relay.createBroadcast(path: 'live'); final track = publication.broadcast().publishTrack( @@ -224,7 +224,7 @@ void main() { ); publication.announce(route: AnnounceRoute()); final announced = - (await announcement.timeout(timeout) as AnnounceEventStart).announce; + (await announcement.timeout(timeout) as AnnounceEventPresent).announce; expect(announced.prefix, 'live'); final requested = await client.request(announced.prefix).timeout(timeout); @@ -304,14 +304,14 @@ void main() { final serverSession = await accepted; final announcement = client.announced().updates().firstWhere( - (event) => event is AnnounceEventStart, + (event) => event is AnnounceEventPresent, ); final publication = server.createBroadcast('live'); final broadcast = publication.broadcast(); final track = broadcast.publishTrack(name: 'events', info: null); publication.announce(route: AnnounceRoute()); final announced = - (await announcement.timeout(timeout) as AnnounceEventStart).announce; + (await announcement.timeout(timeout) as AnnounceEventPresent).announce; expect(announced.prefix, 'live'); await client.close(); @@ -474,27 +474,27 @@ void main() { publication.announce(route: AnnounceRoute()); final announced = consumer.announced(config: MoqAnnounceConfig()); final first = await nextRoute(announced); - expect(first, isA()); - expect((first as AnnounceEventStart).announce.prefix, 'live'); + expect(first, isA()); + expect((first as AnnounceEventPresent).announce.prefix, 'live'); publication.unannounce(); final retracted = await nextRoute(announced); - expect(retracted, isA()); - expect((retracted as AnnounceEventEnd).announce.prefix, 'live'); + expect(retracted, isA()); + expect((retracted as AnnounceEventAbsent).announce.prefix, 'live'); await expectLater( consumer.request(path: 'live').timeout(timeout), throwsA(anything), ); publication.announce(route: AnnounceRoute()); - expect(await nextRoute(announced), isA()); + expect(await nextRoute(announced), isA()); await consumer.request(path: 'live').timeout(timeout); // Disposing the publication keeps the route; closing the broadcast ends it. publication.dispose(); await consumer.request(path: 'live').timeout(timeout); broadcast.close(); - expect(await nextRoute(announced), isA()); + expect(await nextRoute(announced), isA()); announced.cancel(); announced.dispose(); }); @@ -516,23 +516,32 @@ void main() { replacement.broadcast().close(); }); - test('a new instance restarts announce consumers', () async { + test('a new instance restarts followers but stays listed', () async { final origin = MoqOriginProducer(config: MoqOriginConfig()); - final announced = origin.consume().announced(config: MoqAnnounceConfig()); + final consumer = origin.consume(); + final announced = consumer.announced(config: MoqAnnounceConfig()); + final following = consumer.follow(path: 'instance'); final publication = origin.createBroadcast(path: 'instance'); publication.announce(route: AnnounceRoute()); - final start = await nextRoute(announced) as AnnounceEventStart; - expect(start.announce.route.instance, isNotEmpty); + final present = await nextRoute(announced) as AnnounceEventPresent; + expect(present.announce.route.instance, isNotEmpty); + (await following.available().timeout(timeout)).dispose(); publication.announce(route: AnnounceRoute(instance: 'camera', epoch: 1)); - final restart = await nextRoute(announced) as AnnounceEventRestart; - expect(restart.announce.route.instance, 'camera'); + (await following.available().timeout(timeout)).dispose(); + + // The takeover was not listed, so the next event is the path going absent. + publication.unannounce(); + final absent = await nextRoute(announced) as AnnounceEventAbsent; + expect(absent.announce.route.instance, 'camera'); expect( () => publication.announce(route: AnnounceRoute(instance: '')), throwsA(isA()), ); + following.cancel(); + following.dispose(); announced.cancel(); announced.dispose(); }); @@ -545,7 +554,7 @@ void main() { final publication = origin.createBroadcast(path: 'room/alice/chat'); publication.announce(route: AnnounceRoute()); - final update = await nextRoute(announced) as AnnounceEventStart; + final update = await nextRoute(announced) as AnnounceEventPresent; expect(update.announce.prefix, 'room/alice/chat'); expect(update.announce.captures, ['alice']); }); diff --git a/dart/moq_ffi/lib/src/moq.dart b/dart/moq_ffi/lib/src/moq.dart index 469ee931747..44c95caf870 100644 --- a/dart/moq_ffi/lib/src/moq.dart +++ b/dart/moq_ffi/lib/src/moq.dart @@ -8085,31 +8085,13 @@ class FfiConverterMoqAnnounceEvent { final subview = Uint8List.view(buf.buffer, buf.offsetInBytes + 4); switch (index) { case 1: - final lifted = StartMoqAnnounceEvent.read(subview); + final lifted = PresentMoqAnnounceEvent.read(subview); return LiftRetVal( lifted.value, lifted.bytesRead - subview.offsetInBytes + 4, ); case 2: - final lifted = UpdateMoqAnnounceEvent.read(subview); - return LiftRetVal( - lifted.value, - lifted.bytesRead - subview.offsetInBytes + 4, - ); - case 3: - final lifted = EndMoqAnnounceEvent.read(subview); - return LiftRetVal( - lifted.value, - lifted.bytesRead - subview.offsetInBytes + 4, - ); - case 4: - final lifted = RestartMoqAnnounceEvent.read(subview); - return LiftRetVal( - lifted.value, - lifted.bytesRead - subview.offsetInBytes + 4, - ); - case 5: - final lifted = TakeoverMoqAnnounceEvent.read(subview); + final lifted = AbsentMoqAnnounceEvent.read(subview); return LiftRetVal( lifted.value, lifted.bytesRead - subview.offsetInBytes + 4, @@ -8135,18 +8117,18 @@ class FfiConverterMoqAnnounceEvent { } } -class StartMoqAnnounceEvent extends MoqAnnounceEvent { +class PresentMoqAnnounceEvent extends MoqAnnounceEvent { final MoqAnnounce announce; - StartMoqAnnounceEvent(MoqAnnounce this.announce); - StartMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { + PresentMoqAnnounceEvent(MoqAnnounce this.announce); + PresentMoqAnnounceEvent._(MoqAnnounce this.announce); + static LiftRetVal read(Uint8List buf) { int new_offset = buf.offsetInBytes; final announce_lifted = FfiConverterMoqAnnounce.read( Uint8List.view(buf.buffer, new_offset), ); final announce = announce_lifted.value; new_offset += announce_lifted.bytesRead; - return LiftRetVal(StartMoqAnnounceEvent._(announce), new_offset); + return LiftRetVal(PresentMoqAnnounceEvent._(announce), new_offset); } @override @@ -8173,18 +8155,18 @@ class StartMoqAnnounceEvent extends MoqAnnounceEvent { } } -class UpdateMoqAnnounceEvent extends MoqAnnounceEvent { +class AbsentMoqAnnounceEvent extends MoqAnnounceEvent { final MoqAnnounce announce; - UpdateMoqAnnounceEvent(MoqAnnounce this.announce); - UpdateMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { + AbsentMoqAnnounceEvent(MoqAnnounce this.announce); + AbsentMoqAnnounceEvent._(MoqAnnounce this.announce); + static LiftRetVal read(Uint8List buf) { int new_offset = buf.offsetInBytes; final announce_lifted = FfiConverterMoqAnnounce.read( Uint8List.view(buf.buffer, new_offset), ); final announce = announce_lifted.value; new_offset += announce_lifted.bytesRead; - return LiftRetVal(UpdateMoqAnnounceEvent._(announce), new_offset); + return LiftRetVal(AbsentMoqAnnounceEvent._(announce), new_offset); } @override @@ -8211,141 +8193,6 @@ class UpdateMoqAnnounceEvent extends MoqAnnounceEvent { } } -class EndMoqAnnounceEvent extends MoqAnnounceEvent { - final MoqAnnounce announce; - EndMoqAnnounceEvent(MoqAnnounce this.announce); - EndMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { - int new_offset = buf.offsetInBytes; - final announce_lifted = FfiConverterMoqAnnounce.read( - Uint8List.view(buf.buffer, new_offset), - ); - final announce = announce_lifted.value; - new_offset += announce_lifted.bytesRead; - return LiftRetVal(EndMoqAnnounceEvent._(announce), new_offset); - } - - @override - RustBuffer lower() { - final buf = Uint8List(allocationSize()); - write(buf); - return toRustBuffer(buf); - } - - @override - int allocationSize() { - return FfiConverterMoqAnnounce.allocationSize(announce) + 4; - } - - @override - int write(Uint8List buf) { - buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 3); - int new_offset = buf.offsetInBytes + 4; - new_offset += FfiConverterMoqAnnounce.write( - announce, - Uint8List.view(buf.buffer, new_offset), - ); - return new_offset; - } -} - -class RestartMoqAnnounceEvent extends MoqAnnounceEvent { - final MoqAnnounce announce; - RestartMoqAnnounceEvent(MoqAnnounce this.announce); - RestartMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { - int new_offset = buf.offsetInBytes; - final announce_lifted = FfiConverterMoqAnnounce.read( - Uint8List.view(buf.buffer, new_offset), - ); - final announce = announce_lifted.value; - new_offset += announce_lifted.bytesRead; - return LiftRetVal(RestartMoqAnnounceEvent._(announce), new_offset); - } - - @override - RustBuffer lower() { - final buf = Uint8List(allocationSize()); - write(buf); - return toRustBuffer(buf); - } - - @override - int allocationSize() { - return FfiConverterMoqAnnounce.allocationSize(announce) + 4; - } - - @override - int write(Uint8List buf) { - buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 4); - int new_offset = buf.offsetInBytes + 4; - new_offset += FfiConverterMoqAnnounce.write( - announce, - Uint8List.view(buf.buffer, new_offset), - ); - return new_offset; - } -} - -class TakeoverMoqAnnounceEvent extends MoqAnnounceEvent { - final MoqAnnounce announce; - final String predecessor; - TakeoverMoqAnnounceEvent({ - required MoqAnnounce this.announce, - required String this.predecessor, - }); - TakeoverMoqAnnounceEvent._( - MoqAnnounce this.announce, - String this.predecessor, - ); - static LiftRetVal read(Uint8List buf) { - int new_offset = buf.offsetInBytes; - final announce_lifted = FfiConverterMoqAnnounce.read( - Uint8List.view(buf.buffer, new_offset), - ); - final announce = announce_lifted.value; - new_offset += announce_lifted.bytesRead; - final predecessor_lifted = FfiConverterString.read( - Uint8List.view(buf.buffer, new_offset), - ); - final predecessor = predecessor_lifted.value; - new_offset += predecessor_lifted.bytesRead; - return LiftRetVal( - TakeoverMoqAnnounceEvent._(announce, predecessor), - new_offset, - ); - } - - @override - RustBuffer lower() { - final buf = Uint8List(allocationSize()); - write(buf); - return toRustBuffer(buf); - } - - @override - int allocationSize() { - return FfiConverterMoqAnnounce.allocationSize(announce) + - FfiConverterString.allocationSize(predecessor) + - 4; - } - - @override - int write(Uint8List buf) { - buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 5); - int new_offset = buf.offsetInBytes + 4; - new_offset += FfiConverterMoqAnnounce.write( - announce, - Uint8List.view(buf.buffer, new_offset), - ); - new_offset += FfiConverterString.write( - predecessor, - Uint8List.view(buf.buffer, new_offset), - ); - return new_offset; - } -} - enum MoqTransport { quic, iroh, webSocket, tcp, unix, webTransport } class FfiConverterMoqTransport { diff --git a/dart/moq_ffi/test/future_test.dart b/dart/moq_ffi/test/future_test.dart index f671129d350..92d8d311bdb 100644 --- a/dart/moq_ffi/test/future_test.dart +++ b/dart/moq_ffi/test/future_test.dart @@ -140,7 +140,7 @@ void main() { final publication = origin.createBroadcast(path: 'still-listening'); try { publication.announce(route: MoqAnnounceRoute()); - expect(await next, isA()); + expect(await next, isA()); } finally { publication.broadcast().close(); } diff --git a/demo/carla/README.md b/demo/carla/README.md index 07567b95cc6..3ecfd2ea2eb 100644 --- a/demo/carla/README.md +++ b/demo/carla/README.md @@ -106,7 +106,7 @@ The worker's gate (`sim/moq_carla_sim/drive.py`) owns every truck's controls: - **One driver at a time.** The first driver to send a command holds the lease until its broadcast ends or its 1 s watchdog expires; the player heartbeats every 250 ms. The lease is bound to the driver's path and the - route instance it announced with, so a driver that reconnects at the same + publisher instance serving it, so a driver that reconnects at the same path is a new claimant rather than a continuation. - **E-stop latches** until an explicit reset, from any viewer: the player latches and resets it through a short-lived safety broadcast without taking diff --git a/demo/carla/sim/moq_carla_sim/drive.py b/demo/carla/sim/moq_carla_sim/drive.py index 34487dd81fe..9262fc47833 100644 --- a/demo/carla/sim/moq_carla_sim/drive.py +++ b/demo/carla/sim/moq_carla_sim/drive.py @@ -94,10 +94,10 @@ class Command: `drive`, `estop`, `reset_estop`, and `respawn` arrive on the wire; `driver_left` and `watchdog_expired` are synthesized locally. - `driver_id` is the driver's path segment, which `status` echoes. `instance` is - the route instance its broadcast was announced under: the same id announced - under another instance is another run of the driver, so it is a different - driver for the lease. + `driver_id` is the driver's path segment, which `status` echoes. `instance` + names the run that sent it, one per publisher instance serving the path: the + same id under another instance is another run of the driver, so it is a + different driver for the lease. """ kind: CommandKind @@ -114,8 +114,8 @@ class Drive: The first driver to send a command owns the truck until it disconnects or its command lease expires. Other drivers cannot silently steal control. - The lease binds to the driver's broadcast path and the instance it was - announced under, so a driver whose broadcast ends or restarts loses it. + The lease binds to the driver's broadcast path and the run serving it, so a + driver whose broadcast ends or restarts loses it. It is still cooperative, not enforced: the holder's id is echoed on the public `status` track, so anyone allowed to publish there can announce at that path under another instance, which ends the holder's broadcast and frees diff --git a/demo/carla/sim/moq_carla_sim/publish.py b/demo/carla/sim/moq_carla_sim/publish.py index 2b2088dfedf..1ad084c77e2 100644 --- a/demo/carla/sim/moq_carla_sim/publish.py +++ b/demo/carla/sim/moq_carla_sim/publish.py @@ -10,6 +10,7 @@ from __future__ import annotations import asyncio +import itertools import logging import math from dataclasses import dataclass @@ -298,70 +299,83 @@ async def watch_drivers( ) -> None: """Discover driver broadcasts at `{prefix}/{driverId}` and fan their commands in. - Runs until cancelled. Each run of a driver, its path plus the route instance it - announced under, gets its own task, so one slow or stuck driver cannot hold - up the others. A broadcast that ends, or restarts under another instance, ends - its task, and with it the lease of that run; a restart starts a new task. + Runs until cancelled. Each driver path the listing reports present gets its own + task, so one slow or stuck driver cannot hold up the others. That task follows + the path across the driver's runs, one publisher instance each; a run that + another takes over, or whose path goes absent, ends, and with it its lease. """ - drivers: dict[str, tuple[str, asyncio.Task[None]]] = {} - - def forget(driver_id: str, task: asyncio.Task[None]) -> None: - # Only this run's entry: a restart has already put its successor there. - current = drivers.get(driver_id) - if current is not None and current[1] is task: - del drivers[driver_id] + drivers: dict[str, asyncio.Task[None]] = {} try: async with client.announced(prefix, filter="*") as announced: async for event in announced: - # Every variant carries `announce`; uniffi's stubs type only the enum. - announce = event.announce # pyright: ignore[reportAttributeAccessIssue] - path = announce.prefix + # Both variants carry `announce`; uniffi's stubs type only the enum. + path = event.announce.prefix # pyright: ignore[reportAttributeAccessIssue] driver_id = path.removeprefix(prefix + "/") # The filter admits one segment below the prefix; anything else # is a route that only overlaps it, not a driver's broadcast. if driver_id == path or not driver_id or "/" in driver_id: continue - instance = announce.route.instance - current = drivers.get(driver_id) - if isinstance(event, moq.AnnounceEventEnd): - if current is not None: - del drivers[driver_id] - current[1].cancel() + if isinstance(event, moq.AnnounceEventAbsent): + task = drivers.pop(driver_id, None) + if task is not None: + task.cancel() continue - if current is not None: - # Same run: the route only changed hops or cost. - if current[0] == instance and not isinstance(event, moq.AnnounceEventRestart): - continue - current[1].cancel() - task = asyncio.create_task( - _pump_driver(driver_id, instance, client, path, commands), + drivers[driver_id] = asyncio.create_task( + _follow_driver(driver_id, client, path, commands), name=f"driver:{driver_id}", ) - drivers[driver_id] = (instance, task) - task.add_done_callback(lambda task, driver_id=driver_id: forget(driver_id, task)) finally: - for _, task in drivers.values(): + for task in drivers.values(): task.cancel() -async def _pump_driver( +# Names each driver run for the lease. The bindings hand out a run's broadcast +# without its route instance, and a process-wide count keeps a run's late +# `driver_left` from releasing a later run of the same driver. +_runs = itertools.count(1) + + +async def _follow_driver( driver_id: str, - instance: str, client: moq.Client, path: str, commands: asyncio.Queue[Command], +) -> None: + """Pump each run of one driver in turn, ending a run once another takes over.""" + run: asyncio.Task[None] | None = None + try: + async with client.follow(path) as following: + while True: + broadcast = await following.available() + if run is not None: + run.cancel() + instance = str(next(_runs)) + run = asyncio.create_task( + _pump_driver(driver_id, instance, broadcast, commands), + name=f"driver:{driver_id}:{instance}", + ) + # uniffi's stubs declare the error a plain class; at runtime it is an Exception. + except moq.Error as err: # pyright: ignore[reportGeneralTypeIssues] + log.info("driver %s follow ended: %s", driver_id, err) + finally: + if run is not None: + run.cancel() + + +async def _pump_driver( + driver_id: str, + instance: str, + broadcast: moq.BroadcastConsumer, + commands: asyncio.Queue[Command], ) -> None: """Feed one driver run's `control` track into the command queue. Always emits `driver_left` on the way out, however it leaves, so the gate releases a lease even when the track ends abnormally. """ - log.info("driver %s connected (instance %s)", driver_id, instance) + log.info("driver %s connected (run %s)", driver_id, instance) try: - # Pinned to this run, so a newer one that took over before its own - # announcement cancels this task is never read under this run's lease. - broadcast = await client.request(path, instance=instance) control = moq.json.SnapshotConsumer(await broadcast.subscribe_track("control")) async for message in control: command = parse_command(driver_id, message.value, instance) @@ -371,7 +385,7 @@ async def _pump_driver( except moq.Error as err: # pyright: ignore[reportGeneralTypeIssues] log.info("driver %s track ended: %s", driver_id, err) finally: - log.info("driver %s disconnected (instance %s)", driver_id, instance) + log.info("driver %s disconnected (run %s)", driver_id, instance) await commands.put(Command(kind="driver_left", driver_id=driver_id, instance=instance)) diff --git a/demo/carla/sim/tests/conftest.py b/demo/carla/sim/tests/conftest.py index bd3eef5702c..0622765b136 100644 --- a/demo/carla/sim/tests/conftest.py +++ b/demo/carla/sim/tests/conftest.py @@ -17,19 +17,11 @@ def __init__(self, announce: SimpleNamespace) -> None: self.announce = announce -class AnnounceEventStart(AnnounceEvent): +class AnnounceEventPresent(AnnounceEvent): pass -class AnnounceEventUpdate(AnnounceEvent): - pass - - -class AnnounceEventEnd(AnnounceEvent): - pass - - -class AnnounceEventRestart(AnnounceEvent): +class AnnounceEventAbsent(AnnounceEvent): pass @@ -60,10 +52,8 @@ async def __aiter__(self): moq = ModuleType("moq") moq.Error = MoqError -moq.AnnounceEventStart = AnnounceEventStart -moq.AnnounceEventUpdate = AnnounceEventUpdate -moq.AnnounceEventEnd = AnnounceEventEnd -moq.AnnounceEventRestart = AnnounceEventRestart +moq.AnnounceEventPresent = AnnounceEventPresent +moq.AnnounceEventAbsent = AnnounceEventAbsent 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 6cd1881faf3..ffd08cb9898 100644 --- a/demo/carla/sim/tests/test_publish.py +++ b/demo/carla/sim/tests/test_publish.py @@ -175,14 +175,30 @@ def closed(_payload: object) -> None: publisher.publish({}) -class Announcements: - """A scripted announcement stream. `send` returns once the watcher has - handled the event and come back for the next one.""" +class Scripted: + """A scripted async source. `send` returns once the reader has handled the + item and come back for the next one.""" def __init__(self) -> None: - self._events: asyncio.Queue = asyncio.Queue() + self._items: asyncio.Queue = asyncio.Queue() self._idle = asyncio.Event() + async def next(self): + if self._items.empty(): + self._idle.set() + item = await self._items.get() + self._idle.clear() + return item + + async def send(self, item) -> None: + self._idle.clear() + self._items.put_nowait(item) + await self._idle.wait() + + +class Announcements(Scripted): + """The scripted listing of driver paths.""" + async def __aenter__(self): return self @@ -193,33 +209,29 @@ def __aiter__(self): return self async def __anext__(self): - if self._events.empty(): - self._idle.set() - event = await self._events.get() - self._idle.clear() - return event + return await self.next() - async def send(self, kind: type, path: str, instance: str) -> None: - self._idle.clear() - self._events.put_nowait(kind(SimpleNamespace(prefix=path, route=SimpleNamespace(instance=instance)))) - await self._idle.wait() + async def present(self, path: str) -> None: + await self.send(moq.AnnounceEventPresent(SimpleNamespace(prefix=path))) + async def absent(self, path: str) -> None: + await self.send(moq.AnnounceEventAbsent(SimpleNamespace(prefix=path))) -class Drivers: - """A relay holding driver broadcasts: each request serves one drive command - numbered by how many requests came before it, then stays open.""" - def __init__(self) -> None: - self.announcements = Announcements() - self.requested: list[tuple[str, str | None]] = [] +class Following(Scripted): + """A scripted follow of one path: each `run` hands out another instance.""" - def announced(self, prefix: str, *, filter: str): - assert (prefix, filter) == ("viewer/carla/truck1", "*") - return self.announcements + async def __aenter__(self): + return self + + async def __aexit__(self, *_exc) -> None: + pass - async def request(self, path: str, *, instance: str | None = None): - self.requested.append((path, instance)) - sequence = len(self.requested) + async def available(self): + return await self.next() + + async def run(self, sequence: int) -> None: + """Hand out an instance that serves one drive command numbered `sequence`, then stays open.""" async def control(): yield {"type": "drive", "sequence": sequence, "throttle": 0.5} @@ -229,7 +241,27 @@ async def subscribe_track(name: str): assert name == "control" return control() - return SimpleNamespace(subscribe_track=subscribe_track) + await self.send(SimpleNamespace(subscribe_track=subscribe_track)) + + +class Drivers: + """A relay holding driver broadcasts.""" + + def __init__(self) -> None: + self.announcements = Announcements() + self.followed: list[str] = [] + self._followings: dict[str, Following] = {} + + def announced(self, prefix: str, *, filter: str): + assert (prefix, filter) == ("viewer/carla/truck1", "*") + return self.announcements + + def following(self, path: str) -> Following: + return self._followings.setdefault(path, Following()) + + def follow(self, path: str) -> Following: + self.followed.append(path) + return self.following(path) async def watching(scenario) -> None: @@ -251,63 +283,49 @@ async def next_command(commands: asyncio.Queue, gate: Drive): return command -def test_a_driver_run_keeps_the_lease_across_route_updates() -> None: - """An update is the same run re-priced: no second subscription, no release.""" - - async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None: - await relay.announcements.send(moq.AnnounceEventStart, "viewer/carla/truck1/abc", "run-1") - command = await next_command(commands, gate) - assert (command.kind, command.driver_id, command.instance) == ("drive", "abc", "run-1") - assert gate.driver == "abc" +DRIVER = "viewer/carla/truck1/abc" - await relay.announcements.send(moq.AnnounceEventUpdate, "viewer/carla/truck1/abc", "run-1") - assert commands.empty() - assert gate.driver == "abc" - assert relay.requested == [("viewer/carla/truck1/abc", "run-1")] - asyncio.run(watching(scenario)) - - -def test_a_driver_whose_broadcast_ends_loses_the_lease() -> None: +def test_a_driver_whose_broadcast_goes_absent_loses_the_lease() -> None: async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None: - await relay.announcements.send(moq.AnnounceEventStart, "viewer/carla/truck1/abc", "run-1") - await next_command(commands, gate) + await relay.announcements.present(DRIVER) + await relay.following(DRIVER).run(1) + command = await next_command(commands, gate) + assert (command.kind, command.driver_id) == ("drive", "abc") assert gate.driver == "abc" - await relay.announcements.send(moq.AnnounceEventEnd, "viewer/carla/truck1/abc", "run-1") + await relay.announcements.absent(DRIVER) left = await next_command(commands, gate) - assert (left.kind, left.instance) == ("driver_left", "run-1") + assert (left.kind, left.instance) == ("driver_left", command.instance) assert gate.driver is None asyncio.run(watching(scenario)) -@pytest.mark.parametrize("kind", ["restart", "update"]) -def test_a_driver_that_restarts_under_a_new_instance_is_a_new_driver(kind: str) -> None: - """The old run's lease ends with it, even though the path and id are the same. - - A new instance is a restart whether the relay says so or reports it as an update. - """ - event = moq.AnnounceEventRestart if kind == "restart" else moq.AnnounceEventUpdate +def test_a_driver_that_restarts_under_a_new_instance_is_a_new_driver() -> None: + """The old run's lease ends with it, even though the path and id are the same.""" async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None: - await relay.announcements.send(moq.AnnounceEventStart, "viewer/carla/truck1/abc", "run-1") - await next_command(commands, gate) + await relay.announcements.present(DRIVER) + await relay.following(DRIVER).run(1) + first = await next_command(commands, gate) - await relay.announcements.send(event, "viewer/carla/truck1/abc", "run-2") + await relay.following(DRIVER).run(2) received = [await next_command(commands, gate) for _ in range(2)] - assert {(command.kind, command.instance) for command in received} == { - ("driver_left", "run-1"), - ("drive", "run-2"), + assert {(command.kind, command.instance == first.instance) for command in received} == { + ("driver_left", True), + ("drive", False), } - assert relay.requested == [("viewer/carla/truck1/abc", "run-1"), ("viewer/carla/truck1/abc", "run-2")] + # The path stays present across the restart, so one follow sees both runs. + assert relay.followed == [DRIVER] # Whichever order those two arrived in, the new run holds the lease # by its next command, and the old run can no longer release it. - assert not gate.holds(Command(kind="drive", driver_id="abc", instance="run-1")) - gate.apply(Command(kind="drive", driver_id="abc", instance="run-2", sequence=3, state=DriveState())) - assert gate.holds(Command(kind="drive", driver_id="abc", instance="run-2")) - assert not gate.apply(Command(kind="driver_left", driver_id="abc", instance="run-1")) + second = next(command.instance for command in received if command.kind == "drive") + assert not gate.holds(Command(kind="drive", driver_id="abc", instance=first.instance)) + gate.apply(Command(kind="drive", driver_id="abc", instance=second, sequence=3, state=DriveState())) + assert gate.holds(Command(kind="drive", driver_id="abc", instance=second)) + assert not gate.apply(Command(kind="driver_left", driver_id="abc", instance=first.instance)) assert gate.driver == "abc" asyncio.run(watching(scenario)) @@ -315,9 +333,9 @@ async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None def test_only_direct_children_of_the_prefix_are_drivers() -> None: async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None: - await relay.announcements.send(moq.AnnounceEventStart, "viewer/carla", None) - await relay.announcements.send(moq.AnnounceEventStart, "viewer/carla/truck1/abc/deeper", None) - await relay.announcements.send(moq.AnnounceEventStart, "viewer/carla/truck10", None) - assert relay.requested == [] + await relay.announcements.present("viewer/carla") + await relay.announcements.present("viewer/carla/truck1/abc/deeper") + await relay.announcements.present("viewer/carla/truck10") + assert relay.followed == [] asyncio.run(watching(scenario)) diff --git a/doc/concept/identity.md b/doc/concept/identity.md index 3e626bd79a0..5facd6bcdeb 100644 --- a/doc/concept/identity.md +++ b/doc/concept/identity.md @@ -119,14 +119,20 @@ content into it: subscriptions already open stay on the old stream until its last route goes, then end with an error. New requests resolve the winner on a fresh broadcast. Choose between two kinds of reader. -**Follow announcements** when the reader should outlive any one stream, as a -player does. Start on each broadcast, drop all decoder and buffer state on a -restart, and wait on an end. Rust uses `consumer.follow(path, None)` (or -`moq_mux::follow::Instances`), JavaScript `origin.follow(path)`, and the -moq-ffi bindings `follow(path)` with `available()`. `@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 announcement is. Nor is a track's error kind: a track withdrawn +**Follow the path** when the reader should outlive any one stream, as a +player does. A follower hands out a new broadcast each time another instance +takes the path; an epoch change or another route of the same instance hands +out nothing. Start on each broadcast, drop all decoder and buffer state when the +next one arrives, and wait while the path is offline. Rust uses +`consumer.follow(path, None)`, whose `available()` returns `None` once the path +goes offline; JavaScript `origin.follow(path)`, whose `active` is undefined +between instances; and the moq-ffi bindings `follow(path)` with `available()`. +An announcement listing (`announced()`) only reports a path becoming present or +absent: 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 unfinished ends `Unroutable` over moq-lite but `Internal` over moq-transport, whose wire has no code for it. @@ -187,19 +193,19 @@ A lazy job's lifecycle, as a viewer of `transcode/alice` sees it through a relay 2. **Takeover.** Publishing the answer through the claim proves it was job A, so job A's route takes over the claim: what the viewer already resolved through the claim beneath `transcode/alice` keeps playing, now as instance - A. A Rust follower sees a takeover rather than a restart (JavaScript still - reports a start or restart). A different worker, or a job restarted under - the same claim, never inherits it. Only moq-lite 07 carries the takeover + A. A Rust follower is handed nothing new (a JavaScript follower still moves + to a new broadcast). A different worker, or a job restarted under the same + claim, never inherits it. Only moq-lite 07 carries the takeover across relays. Older wires, and paths where a relay cannot vouch for it, send an ordinary announcement instead, so the first subscription through - the claim is reset there: a follower sees a restart and requests again, and - a holder's track ends with an error, and it requests again. Either way the + the claim is reset there: a follower is handed the new broadcast, and a + holder's track ends with an error, and it requests again. Either way the second request reaches job A. 3. **Steady state.** Requests resolve instance A by its exact route. Routes carrying instance A through other relays fail over without a seam. 4. **Job restart.** The worker closes job A's publication. The path falls back to the claim, the next request asks the worker again, and job B publishes - under a fresh instance. Followers see each change as a restart; relays drop + under a fresh instance. Followers are handed each new broadcast; relays drop job A's cached groups, so a viewer returning within the cache window never gets them. Other paths under the claim, such as `transcode/bob`, are untouched. diff --git a/doc/lib/c/index.md b/doc/lib/c/index.md index a9b5d6533cc..5fdfd1e7c34 100644 --- a/doc/lib/c/index.md +++ b/doc/lib/c/index.md @@ -79,8 +79,8 @@ if (moq_publication_announce((uint32_t)publication, &route) < 0) A route carries only a cost and the stream's instance; relays add the hops. Each publication mints a fresh instance and keeps it across re-announcing, so a restarted -publisher is a new stream viewers restart onto (`MOQ_ANNOUNCE_KIND_RESTART`) instead of a -stalled broadcast. Set `instance` only for a publisher that continues its group sequences +publisher is a new stream that `moq_origin_follow` hands viewers instead of a stalled +broadcast; the path stays `MOQ_ANNOUNCE_KIND_PRESENT` throughout. Set `instance` only for a publisher that continues its group sequences across restarts, and raise `epoch` on each: readers stitch every route of one instance together, so restarting the sequences under an old instance splices unrelated groups into their tracks. diff --git a/doc/lib/dart/index.md b/doc/lib/dart/index.md index 106c767cb72..65712542984 100644 --- a/doc/lib/dart/index.md +++ b/doc/lib/dart/index.md @@ -59,16 +59,14 @@ moq ) .updates() .listen((event) { - // A restart is a new publisher run at the same path: request it again. A takeover - // continues what an earlier route served, like a start. + // A path stays present across publisher restarts: hold moq.follow(path) to be handed + // each new run. switch (event) { - case AnnounceEventStart(:final announce) || - AnnounceEventRestart(:final announce) || - AnnounceEventTakeover(:final announce): + case AnnounceEventPresent(:final announce): print(announce.prefix); // Captures are a list of wildcard matches, empty without wildcards. print(announce.captures); - default: + case AnnounceEventAbsent(): } }); // Wait for a publisher at one path; call available() again for the next one. diff --git a/doc/lib/go/index.md b/doc/lib/go/index.md index 5ad9e4eb92e..17f71a20fde 100644 --- a/doc/lib/go/index.md +++ b/doc/lib/go/index.md @@ -66,17 +66,13 @@ for event, err := range announced.All(ctx) { if moq.IsShutdown(err) { break } log.Fatal(err) } - var ann moq.Announce - switch event := event.(type) { - case moq.AnnounceEventStart: - ann = event.Announce - case moq.AnnounceEventRestart: // a new publisher run at the same path: request it again - ann = event.Announce - case moq.AnnounceEventTakeover: // continues what an earlier route served, like a start - ann = event.Announce - default: - continue // AnnounceEventUpdate or AnnounceEventEnd + // A path stays present across publisher restarts: hold client.Follow(path, nil) to be + // handed each new run. + present, ok := event.(moq.AnnounceEventPresent) + if !ok { + continue // AnnounceEventAbsent } + ann := present.Announce // Prefix stays origin-relative; Captures is a list, empty without wildcards. fmt.Printf("captures: %v\n", ann.Captures) broadcast, err := client.Request(ctx, ann.Prefix, nil) diff --git a/doc/lib/kt/index.md b/doc/lib/kt/index.md index d7c33fb9fe5..06623ed13ae 100644 --- a/doc/lib/kt/index.md +++ b/doc/lib/kt/index.md @@ -53,13 +53,11 @@ import dev.moq.media.* // Subscribe. The Flow is live, so run it in its own coroutine. Moq.connect("https://relay.example.com", ClientConfig(tls = ClientTls(roots = listOf("ca.pem")))).use { moq -> moq.announced(AnnounceConfig(prefix = "live/", filter = "*/camera")).updates().collect { event -> - // A restart is a new publisher run at the same path: request it again. A takeover - // continues what an earlier route served, like a start. + // A path stays present across publisher restarts: hold moq.follow(path) to be handed + // each new run. val announce = when (event) { - is AnnounceEventStart -> event.announce - is AnnounceEventRestart -> event.announce - is AnnounceEventTakeover -> event.announce - else -> return@collect // Update or End + is AnnounceEventPresent -> event.announce + 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 3f1a8d5ae3f..9c81adb75f8 100644 --- a/doc/lib/py/index.md +++ b/doc/lib/py/index.md @@ -47,10 +47,10 @@ async def main(): async with moq.Client("https://cdn.moq.dev/anon") as client: # The filter is relative to the literal prefix; prefixes stay origin-relative. async for event in client.announced("live/", filter="*/camera"): - # A restart is a new publisher run at the same path: request it again. A - # takeover continues what an earlier route served, like a start. - if not isinstance(event, (moq.AnnounceEventStart, moq.AnnounceEventRestart, moq.AnnounceEventTakeover)): - continue # AnnounceEventUpdate or AnnounceEventEnd + # A path stays present across publisher restarts: hold client.follow(path) to + # be handed each new run. + if not isinstance(event, moq.AnnounceEventPresent): + 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/index.md b/doc/lib/rs/index.md index ddf1e7bf83b..68fa9c0aafd 100644 --- a/doc/lib/rs/index.md +++ b/doc/lib/rs/index.md @@ -63,8 +63,9 @@ let session = client.with_origin(origin.clone()).connect(url); let consumer = origin.consume(); let mut announced = consumer.announced(); while let Some(event) = announced.next().await { - // Skip updates and retractions. - let moq_net::announce::Event::Start(update) = event else { continue }; + // Skip retractions. A path stays present across publisher restarts: hold + // `consumer.follow(path, None)` to be handed each new run. + let moq_net::announce::Event::Present(update) = event else { continue }; let broadcast = consumer.request(&update.prefix, update.route.instance).await?; let catalog = broadcast .track(hang::Catalog::DEFAULT_NAME)? diff --git a/doc/lib/swift/index.md b/doc/lib/swift/index.md index ec0ae5b804a..0d5e3484766 100644 --- a/doc/lib/swift/index.md +++ b/doc/lib/swift/index.md @@ -54,13 +54,9 @@ let client = try Client() let session = try await client.connect(to: "https://relay.example.com") for try await event in try session.consume.announced(prefix: "live/", filter: "*/camera") { - // A restart is a new publisher run at the same path: request it again. A takeover - // continues what an earlier route served, like a start. - let announcement: Announce - switch event { - case .start(let started), .restart(let started), .takeover(let started, _): announcement = started - default: continue // .update or .end - } + // A path stays present across publisher restarts: hold follow(path:) to be handed each + // new run. + guard case .present(let announcement) = event else { continue } // Prefixes stay origin-relative; captures is a list of wildcard matches, empty without wildcards. print(announcement.captures) let broadcast = try await session.consume.request(path: announcement.prefix) diff --git a/doc/setup/redundancy.md b/doc/setup/redundancy.md index 83e415b068c..3b6e385ba55 100644 --- a/doc/setup/redundancy.md +++ b/doc/setup/redundancy.md @@ -57,10 +57,10 @@ again as a new broadcast. This is not a fixed primary/standby priority unless the routes' costs make it one, and a restarted publisher takes a fresh instance, so it may rank either way. -The switch is announced as a `Restart`. Players that follow announcements -request the path again and begin the replacement broadcast. Existing +The path stays announced across the switch, and a follower hands out the +replacement broadcast. Players that follow the path begin it. Existing subscriptions stay on the old instance while it remains available, unless the -consumer chooses to follow the restart. +consumer chooses to follow the switch. For MPEG-TS output, opt into following replacements: diff --git a/go/wrapper/MIGRATE.md b/go/wrapper/MIGRATE.md index 8f0b8385259..9a364c2c519 100644 --- a/go/wrapper/MIGRATE.md +++ b/go/wrapper/MIGRATE.md @@ -4,6 +4,28 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing + +`AnnounceConsumer` yields only `AnnounceEventPresent`, when a route now covers a path that was absent, and `AnnounceEventAbsent`, when none does any more. +Rename `AnnounceEventStart` to `AnnounceEventPresent` and `AnnounceEventEnd` to `AnnounceEventAbsent`. +`AnnounceEventUpdate`, `AnnounceEventRestart`, and `AnnounceEventTakeover` with its `Predecessor` are gone: a route changing cost or hops, a restarted publisher, and a takeover all keep the path present and report nothing. +Instead of requesting the path again on a restart, hold `Follow` and read each new publisher instance from `Available`, dropping what was read from the previous one. + +```go +following, err := client.Follow(path, nil) +if err != nil { + return err +} +defer following.Cancel() +for { + broadcast, err := following.Available(ctx) + if err != nil { + return err + } + play(broadcast) +} +``` + ### `media.VideoInit` is a struct `media.VideoInit` is its own struct rather than an alias of the generated record, so its new `Lower` field takes a `*media.TrackProducer`. A composite literal with `Format`, `Data`, `Label`, and `Hint` compiles unchanged; build one that way where you converted a generated `MoqVideoInit`. diff --git a/go/wrapper/README.md b/go/wrapper/README.md index dc8f4550fba..c8937a7df37 100644 --- a/go/wrapper/README.md +++ b/go/wrapper/README.md @@ -51,17 +51,19 @@ for event, err := range announced.All(ctx) { log.Fatal(err) } switch event := event.(type) { - case moq.AnnounceEventStart: + case moq.AnnounceEventPresent: // Prefix stays origin-relative; Captures reports wildcard matches. - fmt.Println("got broadcast", event.Announce.Prefix) - case moq.AnnounceEventRestart: // a new publisher run at the same path - fmt.Println("restarted broadcast", event.Announce.Prefix) - case moq.AnnounceEventTakeover: // continues what an earlier route served - fmt.Println("took over broadcast", event.Announce.Prefix) + fmt.Println("broadcast online", event.Announce.Prefix) + case moq.AnnounceEventAbsent: + fmt.Println("broadcast offline", event.Announce.Prefix) } } ``` +The listing reports only whether each path is present. A restarted publisher or another +instance taking the path over keeps it present: to read the broadcast across them, hold +`client.Follow(path, nil)` and read each new instance from `Available`. + ## Common APIs `Dial` takes a `ClientConfig` whose names and nesting mirror moq-ffi's diff --git a/go/wrapper/client.go b/go/wrapper/client.go index 87f37134d71..3982bca6ad4 100644 --- a/go/wrapper/client.go +++ b/go/wrapper/client.go @@ -307,7 +307,7 @@ func (c *Client) CreateBroadcast(path string) (*Publication, error) { return c.publisher.CreateBroadcast(path) } -// Announced streams routes announced by the remote under a pattern scope. +// Announced lists the paths the remote announces under a pattern scope, as each becomes present or absent. func (c *Client) Announced(options AnnounceOptions) (*AnnounceConsumer, error) { return c.consumer.Announced(options) } diff --git a/go/wrapper/example_test.go b/go/wrapper/example_test.go index da49aff1e08..767953303a9 100644 --- a/go/wrapper/example_test.go +++ b/go/wrapper/example_test.go @@ -33,7 +33,7 @@ func ExampleClient_Announced() { } log.Fatal(err) } - if event, ok := event.(moq.AnnounceEventStart); ok { + if event, ok := event.(moq.AnnounceEventPresent); ok { fmt.Println("broadcast:", event.Announce.Prefix) } } diff --git a/go/wrapper/moq_test.go b/go/wrapper/moq_test.go index 9a1e813e68b..fc6dcb3c9e9 100644 --- a/go/wrapper/moq_test.go +++ b/go/wrapper/moq_test.go @@ -1539,7 +1539,7 @@ func TestBroadcastIsReachableOnlyWhileAnnounced(t *testing.T) { t.Fatal(err) } event := nextRoute(t, ctx, announced) - if retracted, ok := event.(moq.AnnounceEventEnd); !ok || retracted.Announce.Prefix != "live" { + if retracted, ok := event.(moq.AnnounceEventAbsent); !ok || retracted.Announce.Prefix != "live" { t.Fatalf("unannounce: event=%+v", event) } if _, err := consumer.Request(ctx, "live", nil); err == nil { @@ -1662,18 +1662,24 @@ func TestAnnouncedExactFilterCapturesEmpty(t *testing.T) { } } -// A broadcast mints its own instance and keeps it across re-announcing; another -// instance is another stream and restarts announce consumers. -func TestAnnouncedInstanceRestarts(t *testing.T) { +// A broadcast mints its own instance and keeps it across re-announcing. Another +// instance keeps the path present in the listing and reaches only followers. +func TestInstanceChangeReachesFollowers(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() origin := newOrigin(t) - announced, err := origin.Consume().Announced(moq.AnnounceOptions{}) + consumer := origin.Consume() + announced, err := consumer.Announced(moq.AnnounceOptions{}) if err != nil { t.Fatal(err) } defer announced.Cancel() + following, err := consumer.Follow("instance", nil) + if err != nil { + t.Fatal(err) + } + defer following.Cancel() publication, err := origin.CreateBroadcast("instance") if err != nil { @@ -1684,24 +1690,30 @@ func TestAnnouncedInstanceRestarts(t *testing.T) { } minted := nextAnnounced(t, ctx, announced).Route.Instance if minted == "" { - t.Fatal("start instance is empty, want a minted one") + t.Fatal("present instance is empty, want a minted one") + } + if _, err := following.Available(ctx); err != nil { + t.Fatal(err) } if err := publication.Announce(moq.AnnounceRoute{Cost: 1}); err != nil { t.Fatal(err) } - update, ok := nextRoute(t, ctx, announced).(moq.AnnounceEventUpdate) - if !ok || update.Announce.Route.Instance != minted { - t.Fatalf("update = %+v, want instance %s", update, minted) - } - stable := "cam" if err := publication.Announce(moq.AnnounceRoute{Instance: &stable, Epoch: 1}); err != nil { t.Fatal(err) } - restart, ok := nextRoute(t, ctx, announced).(moq.AnnounceEventRestart) - if !ok || restart.Announce.Route.Instance != stable { - t.Fatalf("restart = %+v, want instance %s", restart, stable) + if _, err := following.Available(ctx); err != nil { + t.Fatalf("follow after the instance change: %v", err) + } + + // The listing's next event is the absence, so neither re-announce reached it. + if err := publication.Unannounce(); err != nil { + t.Fatal(err) + } + event := nextRoute(t, ctx, announced) + if absent, ok := event.(moq.AnnounceEventAbsent); !ok || absent.Announce.Route.Instance != stable { + t.Fatalf("event = %+v, want absent with instance %s", event, stable) } empty := "" @@ -1724,12 +1736,12 @@ func nextRoute(t *testing.T, ctx context.Context, announced *moq.AnnounceConsume return event } -// nextAnnounced returns the next newly announced route. +// nextAnnounced returns the route of the next path to become present. func nextAnnounced(t *testing.T, ctx context.Context, announced *moq.AnnounceConsumer) moq.Announce { t.Helper() event := nextRoute(t, ctx, announced) - announcedEvent, ok := event.(moq.AnnounceEventStart) + announcedEvent, ok := event.(moq.AnnounceEventPresent) if !ok { t.Fatalf("expected an announcement, got %+v", event) } diff --git a/go/wrapper/origin.go b/go/wrapper/origin.go index 91c73aec3cb..70ab7600e11 100644 --- a/go/wrapper/origin.go +++ b/go/wrapper/origin.go @@ -187,7 +187,8 @@ type AnnounceOptions struct { Hidden bool } -// Announced streams routes under a literal prefix matching an optional pattern filter. +// Announced lists the paths under a literal prefix matching an optional pattern filter, as each +// 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, @@ -226,12 +227,12 @@ func (o *OriginConsumer) Request(ctx context.Context, path string, instance *str return &BroadcastConsumer{inner: inner}, nil } -// AnnounceConsumer is a stream of announce events. +// AnnounceConsumer is a listing of paths, each present or absent. type AnnounceConsumer struct { inner *ffi.MoqAnnounceConsumer } -// Next returns the next announce event, or (nil, nil) when the stream ends. +// Next returns the next path becoming present or absent, or (nil, nil) when the stream ends. func (a *AnnounceConsumer) Next(ctx context.Context) (AnnounceEvent, error) { res, err := bridge.Call(ctx, a.inner.Cancel, a.inner.Next) if err != nil || res == nil { @@ -240,12 +241,12 @@ func (a *AnnounceConsumer) Next(ctx context.Context) (AnnounceEvent, error) { return *res, nil } -// All ranges over announce events until the stream ends or the loop breaks. +// All ranges over the listing's events until the stream ends or the loop breaks. func (a *AnnounceConsumer) All(ctx context.Context) iter.Seq2[AnnounceEvent, error] { return bridge.Seq(ctx, a.Next) } -// Cancel stops the announcement stream. +// Cancel stops the listing. func (a *AnnounceConsumer) Cancel() { a.inner.Cancel() } diff --git a/go/wrapper/reconnect_test.go b/go/wrapper/reconnect_test.go index eca76e3b1fa..398fe4f8a66 100644 --- a/go/wrapper/reconnect_test.go +++ b/go/wrapper/reconnect_test.go @@ -109,7 +109,7 @@ func waitConnects(t *testing.T, ctx context.Context, session *moq.Session, want } } -// awaitAnnouncement drains announcements until an active one names path. +// awaitAnnouncement drains announcements until path is present. func awaitAnnouncement(t *testing.T, ctx context.Context, announced *moq.AnnounceConsumer, path string) { t.Helper() @@ -121,7 +121,7 @@ func awaitAnnouncement(t *testing.T, ctx context.Context, announced *moq.Announc if event == nil { t.Fatalf("announcement stream ended before %q", path) } - if ann, ok := event.(moq.AnnounceEventStart); ok && ann.Announce.Prefix == path { + if ann, ok := event.(moq.AnnounceEventPresent); ok && ann.Announce.Prefix == path { return } } diff --git a/go/wrapper/types.go b/go/wrapper/types.go index 1ee5b6beb73..5f1b7e08c5f 100644 --- a/go/wrapper/types.go +++ b/go/wrapper/types.go @@ -46,21 +46,13 @@ 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: AnnounceEventStart, - // AnnounceEventUpdate, AnnounceEventEnd, AnnounceEventRestart, or AnnounceEventTakeover. + // 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 - // AnnounceEventStart reports a route now covering a prefix that had none. - AnnounceEventStart = ffi.MoqAnnounceEventStart - // AnnounceEventUpdate reports the route covering a prefix changing hops or cost. - AnnounceEventUpdate = ffi.MoqAnnounceEventUpdate - // AnnounceEventEnd reports that no route covers a prefix any more, carrying its last route. - AnnounceEventEnd = ffi.MoqAnnounceEventEnd - // AnnounceEventRestart reports another publisher instance now serving a prefix: - // drop what was resolved under it and request afresh. - AnnounceEventRestart = ffi.MoqAnnounceEventRestart - // AnnounceEventTakeover reports a route now covering a prefix that continues what the - // route at Predecessor served beneath it: keep what was resolved through that one. - AnnounceEventTakeover = ffi.MoqAnnounceEventTakeover + // AnnounceEventPresent reports a route now covering a path that was absent. + AnnounceEventPresent = ffi.MoqAnnounceEventPresent + // AnnounceEventAbsent reports that no route covers a path any more, carrying its last route. + AnnounceEventAbsent = ffi.MoqAnnounceEventAbsent // 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/MIGRATE.md b/js/net/MIGRATE.md index b9d95ca28e4..9517d03ad95 100644 --- a/js/net/MIGRATE.md +++ b/js/net/MIGRATE.md @@ -4,6 +4,11 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing ([#7678](https://github.com/moq-dev/moq/pull/7678)) + +`Announce.Event` is `{ kind: "present" | "absent" } & Announce`. Another instance taking a path over keeps it present, and a route's cost or hops changing is not reported, so `start`, `update`, `restart` and `end` are gone. +Map `"start"` to `"present"` and `"end"` to `"absent"`, and drop `"update"` branches. Where you requested the path again on `"restart"`, hold `origin.follow(path)`: its `active` moves to each new instance's broadcast. + ### `Subscription.maxDelay` is `delay: Track.Delay` ([#7597](https://github.com/moq-dev/moq/pull/7597)) `Track.Subscription` carries a `delay: Track.Delay` (`{ min?: Milli | null; max?: Milli | null }`) in place of `maxDelay`, which is now refused at runtime. diff --git a/kt/README.md b/kt/README.md index 1fb202ee284..1aceb78d033 100644 --- a/kt/README.md +++ b/kt/README.md @@ -31,13 +31,11 @@ import kotlinx.coroutines.flow.collect // connect() wires up an internal origin and returns a live connection. Moq.connect("https://relay.example.com").use { moq -> moq.announced(AnnounceConfig(prefix = "demos/", filter = "*/camera")).updates().collect { event -> - // A restart is a new publisher run at the same path: request it again. A takeover - // continues what an earlier route served, like a start. + // The listing reports each path once while it stays present, even as its publisher + // restarts; `moq.follow(path)` hands out each new run. val announce = when (event) { - is AnnounceEventStart -> event.announce - is AnnounceEventRestart -> event.announce - is AnnounceEventTakeover -> event.announce - else -> return@collect // Update or End + is AnnounceEventPresent -> event.announce + is AnnounceEventAbsent -> return@collect } // Prefix stays origin-relative; captures reports what * matched. println("got broadcast ${announce.prefix}") diff --git a/kt/moq/MIGRATE.md b/kt/moq/MIGRATE.md index ecb3c831ba8..cf4ad4370dc 100644 --- a/kt/moq/MIGRATE.md +++ b/kt/moq/MIGRATE.md @@ -4,6 +4,18 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing + +`announced(config).updates()` emits `AnnounceEventPresent` when a path becomes present and `AnnounceEventAbsent` when it goes, each carrying an `Announce` as `announce`. +`AnnounceEventStart` is `AnnounceEventPresent` and `AnnounceEventEnd` is `AnnounceEventAbsent`. +`AnnounceEventUpdate`, `AnnounceEventRestart`, and `AnnounceEventTakeover` are gone: a path whose route or publisher instance changes stays present and is not reported again. +Where you requested the path again on a restart, hold `follow(path)` instead; each `available()` returns the next instance's broadcast. + +```kotlin +val following = moq.follow("live/camera") +while (true) play(following.available()) +``` + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `Announce.captures` is `List` instead of `List?`. Remove null checks and pass `captures = emptyList()` when constructing an announcement for a filter without wildcards. Rebuild with the matching generated bindings and native library. diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt index fe561d01165..55c70ec1d56 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt @@ -92,33 +92,20 @@ typealias Following = uniffi.moq.MoqFollowing typealias Announce = uniffi.moq.MoqAnnounce /** - * What an [AnnounceConsumer] yields: [AnnounceEventStart], [AnnounceEventUpdate], - * [AnnounceEventEnd], [AnnounceEventRestart], or [AnnounceEventTakeover]. + * 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. */ typealias AnnounceEvent = uniffi.moq.MoqAnnounceEvent // Kotlin cannot reach a sealed class's subtypes through its typealias, so each // variant gets its own. -/** A route now covers the prefix; the stream had none there. */ -typealias AnnounceEventStart = uniffi.moq.MoqAnnounceEvent.Start +/** A route now covers the path, which was absent. */ +typealias AnnounceEventPresent = uniffi.moq.MoqAnnounceEvent.Present -/** The route covering the prefix changed hops or cost. */ -typealias AnnounceEventUpdate = uniffi.moq.MoqAnnounceEvent.Update - -/** No route covers the prefix any more; carries its last route. */ -typealias AnnounceEventEnd = uniffi.moq.MoqAnnounceEvent.End - -/** - * Another publisher instance now serves the prefix: drop what was resolved under it and request - * afresh. - */ -typealias AnnounceEventRestart = uniffi.moq.MoqAnnounceEvent.Restart - -/** - * A route now covers the prefix and continues what the route at `predecessor` served beneath it: - * keep what was resolved through that one. - */ -typealias AnnounceEventTakeover = uniffi.moq.MoqAnnounceEvent.Takeover +/** No route covers the path any more; carries its last route. */ +typealias AnnounceEventAbsent = uniffi.moq.MoqAnnounceEvent.Absent // Broadcast / track / group producers and consumers. /** The write side of a broadcast: publish tracks into it. */ diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt index 46dc101fff8..c7545bf21e5 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt @@ -26,9 +26,10 @@ internal constructor( fun createBroadcast(path: String): Publication = session.publish().createBroadcast(path) /** - * Discover routes matching [config]; prefixes stay relative to the origin. Collect - * `announced(config).updates()` for a [Flow] of [AnnounceEvent] that cancels the handle when - * collection ends. + * 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/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt index cad86be4475..6762b4f4af9 100644 --- a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt +++ b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt @@ -703,16 +703,16 @@ class SmokeTest { publication.announce(AnnounceRoute()) val announced = consumer.announced(AnnounceConfig()) - val first = assertIs(announced.nextRoute()) + val first = assertIs(announced.nextRoute()) assertEquals("live", first.announce.prefix) publication.unannounce() - val retracted = assertIs(announced.nextRoute()) + val retracted = assertIs(announced.nextRoute()) assertEquals("live", retracted.announce.prefix) assertFailsWith { consumer.request("live") } publication.announce(AnnounceRoute()) - assertIs(announced.nextRoute()) + assertIs(announced.nextRoute()) consumer.request("live") } } @@ -726,11 +726,11 @@ class SmokeTest { val publication = origin.createBroadcast("live") publication.broadcast().use { broadcast -> publication.use { it.announce(AnnounceRoute()) } - assertIs(announced.nextRoute()) + assertIs(announced.nextRoute()) consumer.request("live") broadcast.end() - assertIs(announced.nextRoute()) + assertIs(announced.nextRoute()) assertFailsWith { consumer.request("live") } } } @@ -755,22 +755,30 @@ class SmokeTest { } @Test - fun `a new instance restarts announce consumers`() = runTest { + fun `a new instance restarts followers but stays listed`() = runTest { OriginProducer(OriginConfig()).use { origin -> - val announced = origin.consume().announced(AnnounceConfig()) + val consumer = origin.consume() + val announced = consumer.announced(AnnounceConfig()) + val following = consumer.follow("instance", null) origin.createBroadcast("instance").use { publication -> publication.announce(AnnounceRoute()) - val start = assertIs(announced.nextRoute()) - assertTrue(start.announce.route.instance.isNotEmpty()) + val present = assertIs(announced.nextRoute()) + assertTrue(present.announce.route.instance.isNotEmpty()) + following.available().close() publication.announce(AnnounceRoute(instance = "camera", epoch = 1uL)) - val restart = assertIs(announced.nextRoute()) - assertEquals("camera", restart.announce.route.instance) + following.available().close() + + // The takeover was not listed, so the next event is the path going absent. + publication.unannounce() + val absent = assertIs(announced.nextRoute()) + assertEquals("camera", absent.announce.route.instance) assertFailsWith { publication.announce(AnnounceRoute(instance = "")) } } + following.cancel() } } @@ -781,7 +789,7 @@ class SmokeTest { origin.consume().announced(AnnounceConfig(prefix = "room", filter = "*/chat")) origin.createBroadcast("room/alice/chat").use { publication -> publication.announce(AnnounceRoute()) - val update = assertIs(announced.nextRoute()) + val update = assertIs(announced.nextRoute()) assertEquals("room/alice/chat", update.announce.prefix) assertEquals(listOf("alice"), update.announce.captures) } diff --git a/py/moq-rs/MIGRATE.md b/py/moq-rs/MIGRATE.md index af31a32d54a..f84bef984da 100644 --- a/py/moq-rs/MIGRATE.md +++ b/py/moq-rs/MIGRATE.md @@ -4,6 +4,12 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing of present and absent paths + +`AnnounceConsumer` yields `AnnounceEventPresent` when a route starts covering a path and `AnnounceEventAbsent` when none covers it any more, each carrying an `Announce` as `announce`. +`AnnounceEventStart`, `AnnounceEventUpdate`, `AnnounceEventEnd`, `AnnounceEventRestart`, and `AnnounceEventTakeover` are removed: read `AnnounceEventStart` as `AnnounceEventPresent` and `AnnounceEventEnd` as `AnnounceEventAbsent`, and drop the `Update` branch, since a re-priced route is no longer reported. +Another publisher instance taking a path over keeps it present and is not listed. Where you requested the path again on `AnnounceEventRestart`, hold `follow(path)` instead and read each `BroadcastConsumer` that `await following.available()` returns, dropping what you read from the previous one. + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `Announce.captures` is `list[str]` instead of `list[str] | None`. Remove `None` checks and pass `captures=[]` when constructing an announcement for a filter without wildcards. Rebuild with the matching generated bindings and native library. diff --git a/py/moq-rs/README.md b/py/moq-rs/README.md index a14ba3aabf9..54611353563 100644 --- a/py/moq-rs/README.md +++ b/py/moq-rs/README.md @@ -29,10 +29,8 @@ import moq async def main(): async with moq.connect("https://cdn.moq.dev/anon") as client: async for event in client.announced(): - # A restart is a new publisher run at the same path: request it again. A - # takeover continues what an earlier route served, like a start. - if not isinstance(event, (moq.AnnounceEventStart, moq.AnnounceEventRestart, moq.AnnounceEventTakeover)): - continue # AnnounceEventUpdate or AnnounceEventEnd + if not isinstance(event, moq.AnnounceEventPresent): + 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) @@ -262,7 +260,7 @@ Every handle whose cleanup is `cancel()` is an async context manager, so exiting - `await .requested_broadcast() → BroadcastRequest`. Call `.prepare()`, fill its `.broadcast`, then `.publish() → Publication` to serve it as a new stream under a fresh instance, or `.reject(code)` to fail the requester. - Async iterator yielding `BroadcastRequest` - **`OriginConsumer`**. Discover broadcasts. - - `.announced(prefix, filter=None) → AnnounceConsumer` (async iterator of `AnnounceEvent`: `AnnounceEventStart`, `AnnounceEventUpdate`, `AnnounceEventEnd`, `AnnounceEventRestart`, or `AnnounceEventTakeover`, each carrying an `Announce` whose `.route.instance` names the stream; on a restart, request the path again; a takeover continues what the route at `.predecessor` served); `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 each stream that takes over; 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/docs/index.md b/py/moq-rs/docs/index.md index e563f229ac9..a58476434bd 100644 --- a/py/moq-rs/docs/index.md +++ b/py/moq-rs/docs/index.md @@ -17,7 +17,7 @@ import moq async def main(): async with moq.Client("https://cdn.moq.dev/anon") as client: async for event in client.announced(): - if isinstance(event, moq.AnnounceEventStart): + if isinstance(event, moq.AnnounceEventPresent): broadcast = await client.request(event.announce.prefix) print(await moq.media.catalog(broadcast)) @@ -172,11 +172,8 @@ broadcast, and producers advertise it in the catalog. Following Announce AnnounceEvent - AnnounceEventStart - AnnounceEventUpdate - AnnounceEventEnd - AnnounceEventRestart - AnnounceEventTakeover + AnnounceEventPresent + AnnounceEventAbsent ``` ## Data types diff --git a/py/moq-rs/examples/announced.py b/py/moq-rs/examples/announced.py index 74786144aee..77dc6617c28 100644 --- a/py/moq-rs/examples/announced.py +++ b/py/moq-rs/examples/announced.py @@ -14,9 +14,9 @@ async def run(url: str, prefix: str, insecure: bool) -> None: async with moq.Client(url, tls=moq.ClientTls(insecure=insecure)) as client: print(f"watching route announcements under {prefix!r} at {url}") async for event in client.announced(prefix): - if isinstance(event, moq.AnnounceEventStart): + if isinstance(event, moq.AnnounceEventPresent): print(f" + {event.announce.prefix}") - elif isinstance(event, moq.AnnounceEventEnd): + 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 1725cd51a03..564dfbbef97 100644 --- a/py/moq-rs/moq/__init__.py +++ b/py/moq-rs/moq/__init__.py @@ -17,11 +17,8 @@ Announce, AnnounceConsumer, AnnounceEvent, - AnnounceEventEnd, - AnnounceEventRestart, - AnnounceEventStart, - AnnounceEventTakeover, - AnnounceEventUpdate, + AnnounceEventAbsent, + AnnounceEventPresent, BroadcastPrepared, BroadcastRequest, Following, @@ -97,11 +94,8 @@ "Announce", "AnnounceConsumer", "AnnounceEvent", - "AnnounceEventEnd", - "AnnounceEventRestart", - "AnnounceEventTakeover", - "AnnounceEventStart", - "AnnounceEventUpdate", + "AnnounceEventAbsent", + "AnnounceEventPresent", "AnnounceRoute", "AudioCodec", "AudioEncoderInput", diff --git a/py/moq-rs/moq/origin.py b/py/moq-rs/moq/origin.py index aa1d145d149..3bac0956403 100644 --- a/py/moq-rs/moq/origin.py +++ b/py/moq-rs/moq/origin.py @@ -33,27 +33,18 @@ """ AnnounceEvent = MoqAnnounceEvent -"""What :class:`AnnounceConsumer` yields: :data:`AnnounceEventStart`, -:data:`AnnounceEventUpdate`, :data:`AnnounceEventEnd`, :data:`AnnounceEventRestart`, -or :data:`AnnounceEventTakeover`, each carrying an :data:`Announce` as ``announce``. -""" - -AnnounceEventStart = MoqAnnounceEvent.START -"""A route now covers the prefix; the stream had none there.""" +"""What :class:`AnnounceConsumer` yields: :data:`AnnounceEventPresent` or +:data:`AnnounceEventAbsent`, each carrying an :data:`Announce` as ``announce``. -AnnounceEventUpdate = MoqAnnounceEvent.UPDATE -"""The route covering the prefix changed hops or cost.""" - -AnnounceEventEnd = MoqAnnounceEvent.END -"""No route covers the prefix any more; carries its last route.""" +Another publisher instance taking a path over keeps it present; hold +:meth:`OriginConsumer.follow` to see the broadcast change. +""" -AnnounceEventRestart = MoqAnnounceEvent.RESTART -"""Another publisher instance now serves the prefix: drop what was resolved under -it and request afresh.""" +AnnounceEventPresent = MoqAnnounceEvent.PRESENT +"""A route now covers the path, which was absent.""" -AnnounceEventTakeover = MoqAnnounceEvent.TAKEOVER -"""A route now covers the prefix and continues what the route at ``predecessor`` -served beneath it: keep what was resolved through that one.""" +AnnounceEventAbsent = MoqAnnounceEvent.ABSENT +"""No route covers the path any more; carries its last route.""" class AnnounceConsumer(_Stream[MoqAnnounceEvent]): diff --git a/py/moq-rs/tests/test_local.py b/py/moq-rs/tests/test_local.py index 7803aca57ba..911e4b698e9 100644 --- a/py/moq-rs/tests/test_local.py +++ b/py/moq-rs/tests/test_local.py @@ -28,9 +28,9 @@ def create_announced(origin: moq.OriginProducer, path: str) -> moq.BroadcastProd async def routes(announced: moq.AnnounceConsumer): - """Yield each newly announced route, skipping updates and ends.""" + """Yield each route that makes its path present, skipping absences.""" async for event in announced: - if isinstance(event, moq.AnnounceEventStart): + if isinstance(event, moq.AnnounceEventPresent): yield event.announce @@ -403,32 +403,34 @@ async def test_announced_broadcast(): break -async def test_announced_instance_restarts(): +async def test_following_restarts_on_a_new_instance(): origin = moq.OriginProducer() consumer = origin.consume() announced = consumer.announced() + following = consumer.follow("instance") publication = origin.create_broadcast("instance") # The broadcast mints its own instance and keeps it across re-announcing. publication.announce() - start = await next_route(announced) - assert isinstance(start, moq.AnnounceEventStart) - minted = start.announce.route.instance + present = await next_route(announced) + assert isinstance(present, moq.AnnounceEventPresent) + minted = present.announce.route.instance assert minted + await asyncio.wait_for(following.available(), timeout=5.0) + # Another instance is another stream: followers restart onto it, while the path + # stays present, so neither the re-price nor the restart is listed. publication.announce(moq.AnnounceRoute(cost=1)) - update = await next_route(announced) - assert isinstance(update, moq.AnnounceEventUpdate) - assert update.announce.route.instance == minted - - # Another instance is another stream: consumers restart onto it. publication.announce(moq.AnnounceRoute(instance="cam", epoch=1)) - restart = await next_route(announced) - assert isinstance(restart, moq.AnnounceEventRestart) - assert restart.announce.route.instance == "cam" + await asyncio.wait_for(following.available(), timeout=5.0) + publication.unannounce() + absent = await next_route(announced) + assert isinstance(absent, moq.AnnounceEventAbsent) + assert absent.announce.route.instance == "cam" with pytest.raises(moq.Error.InvalidInstance): publication.announce(moq.AnnounceRoute(instance="")) + following.cancel() publication.broadcast.close() @@ -437,7 +439,7 @@ async def test_finish_serves_until_closed(): consumer = origin.consume() announced = consumer.announced() broadcast = create_announced(origin, "finish") - assert isinstance(await next_route(announced), moq.AnnounceEventStart) + assert isinstance(await next_route(announced), moq.AnnounceEventPresent) track = broadcast.publish_track("status") track.write_frame(b"tail") @@ -451,7 +453,7 @@ async def test_finish_serves_until_closed(): assert frame is not None and frame.payload == b"tail" broadcast.close() - assert isinstance(await next_route(announced), moq.AnnounceEventEnd) + assert isinstance(await next_route(announced), moq.AnnounceEventAbsent) def test_publish_lifecycle(): @@ -1632,19 +1634,19 @@ async def test_broadcast_is_reachable_only_while_announced(): publication.announce() announced = consumer.announced() first = await next_route(announced) - assert isinstance(first, moq.AnnounceEventStart) + assert isinstance(first, moq.AnnounceEventPresent) assert first.announce.prefix == "live" publication.unannounce() retracted = await next_route(announced) - assert isinstance(retracted, moq.AnnounceEventEnd) + assert isinstance(retracted, moq.AnnounceEventAbsent) assert retracted.announce.prefix == "live" with pytest.raises(Exception): await asyncio.wait_for(consumer.request("live"), timeout=5.0) publication.announce() back = await next_route(announced) - assert isinstance(back, moq.AnnounceEventStart) + assert isinstance(back, moq.AnnounceEventPresent) await asyncio.wait_for(consumer.request("live"), timeout=5.0) announced.cancel() track.finish() @@ -1710,7 +1712,7 @@ async def test_announced_pattern_captures(): audio = create_announced(origin, "room/alice/audio") chat = create_announced(origin, "room/alice/chat") match = await next_route(announced) - assert isinstance(match, moq.AnnounceEventStart) + assert isinstance(match, moq.AnnounceEventPresent) assert match.announce.prefix == "room/alice/chat" assert match.announce.captures == ["alice"] diff --git a/py/moq-rs/tests/test_server.py b/py/moq-rs/tests/test_server.py index 11297357e69..f4b8bcb679f 100644 --- a/py/moq-rs/tests/test_server.py +++ b/py/moq-rs/tests/test_server.py @@ -10,17 +10,12 @@ async def routes(announced: moq.AnnounceConsumer): - """Yield each newly announced route, skipping updates and ends.""" + """Yield each route that makes its path present, skipping absences.""" async for event in announced: - if isinstance(event, moq.AnnounceEventStart): + if isinstance(event, moq.AnnounceEventPresent): yield event.announce -async def next_route(announced: moq.AnnounceConsumer) -> moq.AnnounceEvent: - """The next announce event.""" - return await asyncio.wait_for(anext(announced), timeout=5.0) - - def opus_head() -> bytes: return ( b"OpusHead" @@ -450,50 +445,6 @@ async def test_broadcast_route_over_wire(): broadcast.close() -async def test_route_update_observes_restart(): - """A route metadata update arrives as an AnnounceEventUpdate. - - The publisher re-prices its announced route; the subscriber observes the new - cost in place (no retraction), and unannouncing retracts it. - """ - origin = moq.OriginProducer() - async with moq.Server("127.0.0.1:0", tls_generate=["localhost"], publish=origin) as server: - publication = origin.create_broadcast("routed") - publication.announce(moq.AnnounceRoute(cost=1)) - - serve_task = asyncio.create_task(server.serve()) - try: - async with moq.Client( - f"https://{server.local_addr}", - tls=moq.ClientTls(insecure=True), - bind="127.0.0.1:0", - ) as client: - announced = client.announced() - first = await next_route(announced) - assert isinstance(first, moq.AnnounceEventStart) - assert first.announce.prefix == "routed" - first_cost = first.announce.route.cost - - # The publisher raises its cost: an in-place update. - publication.announce(moq.AnnounceRoute(cost=5)) - updated = await next_route(announced) - assert isinstance(updated, moq.AnnounceEventUpdate) - assert updated.announce.prefix == "routed" - assert updated.announce.route.cost == first_cost + 4 - - # Unannouncing retracts the route. - publication.unannounce() - ended = await next_route(announced) - assert isinstance(ended, moq.AnnounceEventEnd) - assert ended.announce.prefix == "routed" - finally: - serve_task.cancel() - try: - await serve_task - except asyncio.CancelledError: - pass - - async def test_client_context_keeps_the_body_error(): """An error in the body survives the context manager, and the session is still cancelled. A live subscribed track never drains, so draining on the way out would diff --git a/quest/m1/announce-takeover.md b/quest/m1/announce-takeover.md index 0a55f9850f3..0429fdc7176 100644 --- a/quest/m1/announce-takeover.md +++ b/quest/m1/announce-takeover.md @@ -49,12 +49,11 @@ this quest removes the predecessor machinery and grows to [XL]. `rs/moq-net/src/model/origin.rs` and `front.rs` (the `seen` stamps in `OriginConsumerState` and `PendingFront::via`); relay forwarding in `rs/moq-relay`; and `rs/moq-net/tests/integration/announce_takeover.rs`. - Remove the `Takeover` event from Rust (unless - [Listing and follow](/quest/m1/api-audit/route/events.md) has already - removed the event kinds), `TAKEOVER` and the predecessor fields from - `MoqAnnounceEvent` in `rs/moq-ffi/src/origin.rs` and from - `moq_announce_event` in `rs/moq-c/src/api.rs`, and their wrapper and - binding-doc mentions. In `js/net`, drop the ANNOUNCE_TAKEOVER decoding in + Remove `RouteEvent::Takeover` from the relay-level `routes()` stream + (`rs/moq-net/src/model/origin.rs`, and its folds in `follow.rs`, + `announced.rs` and the session publishers); the app listing, `MoqAnnounceEvent` + and `moq_announce_event` dropped it already in + [moq-dev/moq#7678](https://github.com/moq-dev/moq/pull/7678). In `js/net`, drop the ANNOUNCE_TAKEOVER decoding in `lite/announce.ts` and `lite/subscriber.ts`. Remove the takeover sections from `drafts/draft-lcurley-moq-lite.md`, `doc/concept/identity.md` and `doc/concept/moq-lite.md`. @@ -148,7 +147,6 @@ beyond [Instance and epoch](https://github.com/moq-dev/moq/pull/7489)'s fields. ## Related -- [Listing and follow](/quest/m1/api-audit/route/events.md) - continuity shows up inside `follow`, not as an event - [Claim answer epochs](https://github.com/moq-dev/moq/pull/5678) - why a restarted job must never be stitched to its predecessor - [Retired requests](https://github.com/moq-dev/moq/pull/5294) - replacements never substitute content into held handles - [Routes and announces](/quest/m1/cluster-routing/routes.md) - the route layer whose ANNOUNCE_START layout carries the instance diff --git a/quest/m1/api-audit/route/README.md b/quest/m1/api-audit/route/README.md index dfcaca2c13b..298cfe86040 100644 --- a/quest/m1/api-audit/route/README.md +++ b/quest/m1/api-audit/route/README.md @@ -170,7 +170,6 @@ stale, including `doc/concept/identity.md`. - [Serve a held broadcast](/quest/m1/api-audit/route/serve.md) - a prefix route's request can be answered with a broadcast the app already holds, and the first subscribe succeeds on every wire - [One Route handle](/quest/m1/api-audit/route/handle.md) - `Publication`, `Prepared`, `Announcer` and `Requests` become one `Route` that owns its broadcast, with app options separate from transit facts - [Instances are percent-encoded in paths](/quest/m1/api-audit/route/instance-encoding.md) - HLS URLs and archive keys round-trip any stable instance -- [Listing and follow](/quest/m1/api-audit/route/events.md) - apps read a path listing plus `follow`/`request`, and route metadata moves to a relay-level stream ## Related diff --git a/quest/m1/api-audit/route/events.md b/quest/m1/api-audit/route/events.md deleted file mode 100644 index 13416b5f679..00000000000 --- a/quest/m1/api-audit/route/events.md +++ /dev/null @@ -1,54 +0,0 @@ -# [M] Listing and follow - -## Goal - -Applications read announcements as a listing: each path is present or -absent. Instance changes, whether a restart or a takeover, are handled -inside `follow` and `request`, not seen as announce events. The `Start`, -`Update`, `End`, `Restart` and `Takeover` variants leave the app API in -Rust, JS, moq-ffi, moq-c and the wrappers. Route metadata changes (cost, hops, -preference) move to a relay-level `routes()` stream that moq-relay and -stats use. - -Non-goals: the wire's ANNOUNCE and ANNOUNCE_RESTART messages, which stay as -they are, and the route handle ([One Route handle](/quest/m1/api-audit/route/handle.md)). - -## Plan - -Decided 2026-10-30 (maintainer); see the [epic](/quest/m1/api-audit/route/README.md). -The audit found that almost every production caller merges the variants, -for example `rs/moq-relay/src/internal.rs:933`, `rs/moq-rtc/src/lib.rs:81` -and `rs/moq-cli/src/archive.rs:85`. Every JS consumer branches only on -`end`. Only `rs/moq-boy/src/input.rs:79` handles `Restart` alone, and it -moves to `follow`. - -- The listing yields present and absent per path, with the announcement's - read-only facts. A path that changes instance stays present. To see an - instance change, hold a `follow`. -- `follow` yields a new broadcast when the path's instance changes, as the - read side of [Instance and epoch](https://github.com/moq-dev/moq/pull/7489) - defines (an epoch change within one instance is invisible). It also needs an `End` - signal for when the path goes absent, so that `moq_mux::follow::Instances` - can fold into it: delete the wrapper's duplicate epoch filter and keep - its one-shot fixed mode only if a caller needs it. -- `routes()` lives on the origin consumer for relays and stats, and is - hidden from the app-level docs. -- Format the go and python interop clients while touching them (two lines - were already unformatted on 2026-10-30). -- `Takeover` (landed in [moq-dev/moq#6994](https://github.com/moq-dev/moq/pull/6994)) - goes with the rest, along with its predecessor fields in - `MoqAnnounceEvent` and `moq_announce_event`, unless - [announce takeover](/quest/m1/announce-takeover.md) has already removed it. -- Bindings: replace `MoqAnnounceEvent`'s variants, and the go and python - interop clients' and carla `publish.py:303-340`'s Restart handling, with - the listing plus `follow`. -- Update `doc/concept/identity.md`'s follower section and the binding docs. - -Run `just check` and `just test interop --all`. - -Public API: breaking across the announce stream in every language. Wire: -none. - -## Related - -- [Announce takeover](/quest/m1/announce-takeover.md) - a job's exact route continues its claim's readers inside `follow`, with no public event diff --git a/quest/m1/api-audit/route/handle.md b/quest/m1/api-audit/route/handle.md index f666d58cf61..b8145833591 100644 --- a/quest/m1/api-audit/route/handle.md +++ b/quest/m1/api-audit/route/handle.md @@ -40,7 +40,8 @@ read-only facts on a received announcement, and `Hop`, `Hops` and `HopLimit` leave the public API. Non-goals: the instance model ([Instance and epoch](https://github.com/moq-dev/moq/pull/7489)), -announce events ([Listing and follow](/quest/m1/api-audit/route/events.md)), +announce events (a path listing plus `follow` since +[moq-dev/moq#7678](https://github.com/moq-dev/moq/pull/7678)), the read side, which instance owns, and the route layer's wire metric ([Routes and announces](/quest/m1/cluster-routing/routes.md)). diff --git a/quest/m2/room-bench.md b/quest/m2/room-bench.md index 13e7f1f87cd..dd91824a281 100644 --- a/quest/m2/room-bench.md +++ b/quest/m2/room-bench.md @@ -10,10 +10,9 @@ benchmark shows the change. ## Plan -Planned 2026-10-31 (`/quest-plan`, maintainer), a follow-up to the -required [Listing and follow](/quest/m1/api-audit/route/events.md) -implementation, after which `Room` will hold a follower per listed path and -poll every follower on each wake. That should be fine at room sizes seen +Planned 2026-10-31 (`/quest-plan`, maintainer), a follow-up to +[Listing and follow](https://github.com/moq-dev/moq/pull/7678), after which +`Room` holds a follower per listed path and polls every follower on each wake. That should be fine at room sizes seen today. Benchmark first, as [moq-dev/moq#7340](https://github.com/moq-dev/moq/pull/7340) did for the lite subscriber's prefixes, and fix @@ -21,7 +20,3 @@ only if it shows a slope. Wire the benchmark into the existing bench lanes ([Benchmark sources](/quest/m2/bench-sources.md)). Public API: none. Wire: none. - -## Required - -- [Listing and follow](/quest/m1/api-audit/route/events.md) - the follower-per-path room this measures diff --git a/rs/moq-c/MIGRATE.md b/rs/moq-c/MIGRATE.md index 8a782e11d76..5c560f1ab0d 100644 --- a/rs/moq-c/MIGRATE.md +++ b/rs/moq-c/MIGRATE.md @@ -4,6 +4,13 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing ([#7678](https://github.com/moq-dev/moq/pull/7678)) + +`moq_announce_kind` is `MOQ_ANNOUNCE_KIND_PRESENT` (0) or `MOQ_ANNOUNCE_KIND_ABSENT` (1), and `moq_announce_event` loses `predecessor` and `predecessor_len`, changing the C ABI. +Another instance taking a path over keeps it present, and a route's cost changing is not reported. +Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. +Recompile callers against the regenerated `moq.h`. + ### JSON window edits take an optional timestamp `moq_publish_json_window_push` and `moq_publish_json_window_pop` take a final diff --git a/rs/moq-ffi/MIGRATE.md b/rs/moq-ffi/MIGRATE.md index 7f6f48e6d25..690c72877b9 100644 --- a/rs/moq-ffi/MIGRATE.md +++ b/rs/moq-ffi/MIGRATE.md @@ -5,6 +5,11 @@ These are the UniFFI names; each language wrapper has its own `MIGRATE.md` in it ## Unreleased +### Announcements are a listing ([#7678](https://github.com/moq-dev/moq/pull/7678)) + +`MoqAnnounceEvent` is `Present { announce }` or `Absent { announce }`. `Start`, `Update`, `End`, `Restart` and `Takeover` (with its `predecessor`) are gone: another instance taking a path over keeps it present, and a route's cost changing is not reported. +Map `Start` to `Present` and `End` to `Absent`, and drop `Update` handling. Where you requested the path again on `Restart`, hold `MoqOriginConsumer::follow(path)` and await `available()` for each new instance. + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `MoqAnnounce.captures` is `Vec` instead of `Option>`. Remove optional checks and pass an empty list when constructing an announcement for a filter without wildcards. Regenerate bindings and rebuild the matching native library together. diff --git a/rs/moq-mux/MIGRATE.md b/rs/moq-mux/MIGRATE.md index d1522c7f1f0..26d65fe817e 100644 --- a/rs/moq-mux/MIGRATE.md +++ b/rs/moq-mux/MIGRATE.md @@ -4,6 +4,12 @@ How to update your code for each breaking change, newest first. ## Unreleased +### `follow::Instances` folds into `Following` ([#7678](https://github.com/moq-dev/moq/pull/7678)) + +`follow::Instances::new` is removed: call `origin.follow(path, instance)` and read `Following::available()`, which returns `Some(broadcast)` where `Event::Start` did and `None` where `Event::End` did. +`Source::follow` still returns `follow::Instances`, for its one-shot hand-out of the catalog's own broadcast; its `next()` and `poll_next()` now return `Option`, and `follow::Event` is gone. +A pinned instance is now pinned in the origin's follower, which ends the rendition when another instance takes the path. + ### fMP4 decode errors are terminal After `container::fmp4::Import::decode` fails, later decodes, cuts, seeks and discontinuities return that error without reading input or changing tracks, including through `import::Container`. diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index 65116fcd78f..fc3b80986bf 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -4,6 +4,35 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing; `follow` reports the path going offline ([#7678](https://github.com/moq-dev/moq/pull/7678)) + +`origin::Consumer::announced()` lists paths: `announce::Event` is `Present(Announce)` or `Absent(Announce)`. +Another instance taking a path over keeps it present, and a route's cost or hops changing is not reported, so `Start`, `Update`, `End`, `Restart` and `Takeover` are gone. +Map `Start` to `Present` and `End` to `Absent`, and drop `Update` arms. +Where you requested the path again on `Restart`, hold `consumer.follow(path, None)` instead: each `available()` returns the next instance's broadcast. + +`Following::available()` returns `Result, Error>`: `None` reports the path going offline (or, when pinned, another instance taking it over), and the next `Some` is whatever serves it again. +The first call never returns `None`. + +```rust +// Before +match announced.next().await { + Some(announce::Event::Start(a) | announce::Event::Restart(a)) => play(consumer.request(&a.prefix, None).await?), + _ => {} +} +let broadcast = consumer.follow(path, None)?.available().await?; +// After +if let Some(announce::Event::Present(a)) = announced.next().await { + let mut following = consumer.follow(&a.prefix, None)?; + while let Some(broadcast) = following.available().await? { + play(broadcast); + } +} +let broadcast = consumer.follow(path, None)?.available().await?.expect("the first change is an instance"); +``` + +Relays and stats that forward every route change call `consumer.routes()`, a hidden `origin::Routes` stream of `origin::RouteEvent`, which keeps the old five variants. + ### `Subscription::max_delay` is `delay: track::Delay` ([#7597](https://github.com/moq-dev/moq/pull/7597)) `track::Subscription` carries a `track::Delay { min, max }` in place of `max_delay`, and `with_max_delay(d)` is `with_delay(Delay)`. diff --git a/rs/moq-net/src/model/announced.rs b/rs/moq-net/src/model/announced.rs index e1499eb283d..a01fb82a1f4 100644 --- a/rs/moq-net/src/model/announced.rs +++ b/rs/moq-net/src/model/announced.rs @@ -14,15 +14,6 @@ pub enum AnnounceEvent { Absent(Announce), } -impl AnnounceEvent { - /// The announcement this event reports. - pub fn announce(&self) -> &Announce { - match self { - Self::Present(announce) | Self::Absent(announce) => 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 diff --git a/swift/MIGRATE.md b/swift/MIGRATE.md index 3ff5db0b9d9..81c3d85499b 100644 --- a/swift/MIGRATE.md +++ b/swift/MIGRATE.md @@ -4,6 +4,20 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Announcements are a listing + +`AnnounceConsumer` yields `.present` when a path becomes present and `.absent` when it goes, each carrying an `Announce`. +`.start` is `.present` and `.end` is `.absent`. +`.update`, `.restart`, and `.takeover` are gone: a path whose route or publisher instance changes stays present and is not reported again. +Where you requested the path again on a restart, hold `follow(path:)` instead; each `available()` returns the next instance's broadcast. + +```swift +let following = try session.consume.follow(path: "live/camera") +while true { + play(try await following.available()) +} +``` + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `Announce.captures` is `[String]` instead of `[String]?`. Remove optional checks and pass `captures: []` when constructing an announcement for a filter without wildcards. Rebuild with the matching MoqFFI package and native library. diff --git a/swift/README.md b/swift/README.md index 84e51c90725..d5917bf45e3 100644 --- a/swift/README.md +++ b/swift/README.md @@ -35,14 +35,9 @@ let session = try await client.connect(to: "https://relay.example.com") // origin between both sides. let announced = try session.consume.announced(prefix: "demos/", filter: "*/camera") for try await event in announced { - // `.update` reprices a route and `.end` retracts it. A `.restart` is a new - // publisher run at the same path: request it again. A `.takeover` continues what an - // earlier route served, like a `.start`. - let announcement: Announce - switch event { - case .start(let started), .restart(let started), .takeover(let started, _): announcement = started - default: continue - } + // The listing reports each path once while it stays present, even as its publisher + // restarts; `session.consume.follow(path:)` hands out each new run. + guard case .present(let announcement) = event else { continue } // Prefix stays origin-relative; captures reports what * matched. print("got broadcast \(announcement.prefix)") print("captures \(announcement.captures)") diff --git a/swift/Sources/Moq/Aliases.swift b/swift/Sources/Moq/Aliases.swift index 4c6bca3e995..2bff16b0d2a 100644 --- a/swift/Sources/Moq/Aliases.swift +++ b/swift/Sources/Moq/Aliases.swift @@ -62,8 +62,9 @@ public typealias Route = MoqFFI.MoqRoute /// wildcard matched (`captures`, a required list, empty without wildcards), and the `route` serving it. /// Resolve a path with `OriginConsumer.request`. public typealias Announce = MoqFFI.MoqAnnounce -/// What an `AnnounceConsumer` yields: `.start`, `.update`, `.end`, or -/// `.restart` (request the path again), each carrying an `Announce`. +/// What an `AnnounceConsumer` yields: `.present` or `.absent`, each carrying an +/// `Announce`. 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, latency budget, 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 6d5fec99b8f..2c15da5e047 100644 --- a/swift/Sources/Moq/Origin.swift +++ b/swift/Sources/Moq/Origin.swift @@ -146,8 +146,10 @@ public final class OriginConsumer: Sendable { self.ffi = ffi } - /// Stream routes under a literal prefix matching an optional pattern filter. - /// Paths with a segment starting with `.` below the prefix are left out unless `hidden`. + /// List the paths under a literal prefix matching an optional pattern filter, as each + /// 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 { AnnounceConsumer(try ffi.announced(config: MoqAnnounceConfig(prefix: prefix, filter: filter, hidden: hidden))) } @@ -168,7 +170,7 @@ public final class OriginConsumer: Sendable { } } -/// A stream of announce events. Iterate directly: +/// 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 /// cancels the subscription. @@ -218,7 +220,7 @@ public final class Following: Sendable { BroadcastConsumer(try await ffi.available()) } - /// Cancel the pending `available()` call. + /// Cancel all current and future `available()` calls. public func cancel() { ffi.cancel() } diff --git a/swift/Tests/MoqTests/SmokeTests.swift b/swift/Tests/MoqTests/SmokeTests.swift index bc090bcebb9..822e542d6c5 100644 --- a/swift/Tests/MoqTests/SmokeTests.swift +++ b/swift/Tests/MoqTests/SmokeTests.swift @@ -206,13 +206,13 @@ final class SmokeTests: XCTestCase { try publication.announce() let announced = try consumer.announced(prefix: "") - guard case .start(let first) = try await nextRoute(announced) else { + guard case .present(let first) = try await nextRoute(announced) else { return XCTFail("expected an announcement") } XCTAssertEqual(first.prefix, "live") try publication.unannounce() - guard case .end(let retracted) = try await nextRoute(announced) else { + guard case .absent(let retracted) = try await nextRoute(announced) else { return XCTFail("expected a retraction") } XCTAssertEqual(retracted.prefix, "live") @@ -222,7 +222,7 @@ final class SmokeTests: XCTestCase { } catch {} try publication.announce() - guard case .start = try await nextRoute(announced) else { + guard case .present = try await nextRoute(announced) else { return XCTFail("expected a reannouncement") } _ = try await consumer.request(path: "live") @@ -275,35 +275,43 @@ final class SmokeTests: XCTestCase { let chat = try origin.createBroadcast(path: "room/alice/chat") try chat.announce() - guard case .start(let update) = try await nextRoute(announced) else { + guard case .present(let update) = try await nextRoute(announced) else { return XCTFail("expected an announcement") } XCTAssertEqual(update.prefix, "room/alice/chat") XCTAssertEqual(update.captures, ["alice"]) } - func testAnnouncedInstanceRestarts() async throws { + func testNewInstanceRestartsFollowersButStaysListed() async throws { let origin = OriginProducer() - let announced = try origin.consume().announced(prefix: "") + let consumer = origin.consume() + let announced = try consumer.announced(prefix: "") + let following = try consumer.follow(path: "instance") let publication = try origin.createBroadcast(path: "instance") try publication.announce(route: AnnounceRoute()) - guard case .start(let start) = try await nextRoute(announced) else { + guard case .present(let present) = try await nextRoute(announced) else { return XCTFail("expected an announcement") } - XCTAssertFalse(start.route.instance.isEmpty) + XCTAssertFalse(present.route.instance.isEmpty) + _ = try await following.available() try publication.announce(route: AnnounceRoute(instance: "camera", epoch: 1)) - guard case .restart(let restart) = try await nextRoute(announced) else { - return XCTFail("expected a restart") + _ = try await following.available() + + // The takeover was not listed, so the next event is the path going absent. + try publication.unannounce() + guard case .absent(let absent) = try await nextRoute(announced) else { + return XCTFail("expected the path to go absent") } - XCTAssertEqual(restart.route.instance, "camera") + XCTAssertEqual(absent.route.instance, "camera") XCTAssertThrowsError(try publication.announce(route: AnnounceRoute(instance: ""))) { error in guard case MoqError.InvalidInstance = error else { return XCTFail("expected InvalidInstance, got \(error)") } } + following.cancel() } func testDynamicServesARequestUnderAPrefix() async throws { diff --git a/test/interop/clients/c/subscribe.c b/test/interop/clients/c/subscribe.c index cc4ff43f0da..09ba203f221 100644 --- a/test/interop/clients/c/subscribe.c +++ b/test/interop/clients/c/subscribe.c @@ -364,7 +364,7 @@ static void on_finish_announce(void *ud, int32_t event) { if (read < 0) c->finish.failed = 1; else if (info.prefix_len == strlen(c->finish.path) && memcmp(info.prefix, c->finish.path, info.prefix_len) == 0 && - info.kind == MOQ_ANNOUNCE_KIND_END) c->finish.announce_end = 1; + info.kind == MOQ_ANNOUNCE_KIND_ABSENT) c->finish.announce_end = 1; pthread_cond_broadcast(&c->cv); pthread_mutex_unlock(&c->mu); moq_origin_announced_free((uint32_t)event); diff --git a/test/interop/clients/go/main.go b/test/interop/clients/go/main.go index 8ab4f683d5d..bd8ea0ec9b8 100644 --- a/test/interop/clients/go/main.go +++ b/test/interop/clients/go/main.go @@ -12,7 +12,7 @@ // ffmpeg ... -f h264 - | go-interop publish --url http://localhost:4443 --broadcast b.hang --tone 440,660 // go-interop subscribe --url http://localhost:4443 --broadcast b.hang --timeout 20 --audio-out /tmp/audio --audio-ms 600 // -// --finish verifies a finite tail, natural media/catalog EOF, announcement END, and +// --finish verifies a finite tail, natural media/catalog EOF, the announcement going absent, and // same-session health; --frames sets its exact size. --finish-ack selects publisher // finish mode and names the FIFO releasing teardown after the real linger. // --version offers only that version. --grant waits for the grant the relay sends @@ -383,29 +383,26 @@ func finishSubscribe(ctx context.Context, client *moq.Client, broadcast string, break } } - started := false + present := false for { event, err := announcements.Next(ctx) if err != nil { return err } if event == nil { - return errors.New("announcement stream ended before broadcast END") + return errors.New("announcement stream ended before the broadcast went absent") } - if start, ok := event.(moq.AnnounceEventStart); ok && start.Announce.Prefix == broadcast { - started = true + if added, ok := event.(moq.AnnounceEventPresent); ok && added.Announce.Prefix == broadcast { + present = true } - if restart, ok := event.(moq.AnnounceEventRestart); ok && restart.Announce.Prefix == broadcast { - return errors.New("broadcast restarted during finish") - } - if end, ok := event.(moq.AnnounceEventEnd); ok && end.Announce.Prefix == broadcast { - if !started { - return errors.New("broadcast ended without announcement") + if removed, ok := event.(moq.AnnounceEventAbsent); ok && removed.Announce.Prefix == broadcast { + if !present { + return errors.New("broadcast went absent without being present") } break } } - healthAnnounced, err := client.Follow(broadcast + ".health", nil) + healthAnnounced, err := client.Follow(broadcast+".health", nil) if err != nil { return err } diff --git a/test/interop/clients/python/interop.py b/test/interop/clients/python/interop.py index cf0a899a87f..d395a34fa02 100644 --- a/test/interop/clients/python/interop.py +++ b/test/interop/clients/python/interop.py @@ -9,7 +9,7 @@ has been decoded to --audio-out. for tone.py to judge (exit 1 on timeout / no data). ---finish verifies a finite tail, natural media/catalog EOF, announcement END, and +--finish verifies a finite tail, natural media/catalog EOF, the announcement going absent, and same-session health; --frames sets its exact size. --finish-ack selects publisher finish mode and names the FIFO releasing teardown after the real linger. --version offers only that version. --grant waits for the grant the relay sends over @@ -184,10 +184,10 @@ async def _catalog_with_media(consumer: moq.BroadcastConsumer) -> moq.media.Cata async def _finish_subscribe(client: moq.Client, broadcast: str, frames: int) -> None: - # Watch the exact path before resolving it, retaining END while media drains. + # Watch the exact path before resolving it, retaining its absence while media drains. async with client.announced(broadcast) as announcements: - async with client.follow(broadcast) as announced: - consumer = await announced + async with client.follow(broadcast) as following: + consumer = await following async with await moq.media.CatalogConsumer.subscribe(consumer) as catalogs: async for catalog in catalogs: if catalog.video: @@ -218,16 +218,14 @@ async def _finish_subscribe(client: moq.Client, broadcast: str, frames: int) -> started = False async for event in announcements: - if isinstance(event, moq.AnnounceEventRestart) and event.announce.prefix == broadcast: - raise RuntimeError("broadcast restarted during finish") - if isinstance(event, moq.AnnounceEventStart) and event.announce.prefix == broadcast: + if isinstance(event, moq.AnnounceEventPresent) and event.announce.prefix == broadcast: started = True - if isinstance(event, moq.AnnounceEventEnd) and event.announce.prefix == broadcast: + if isinstance(event, moq.AnnounceEventAbsent) and event.announce.prefix == broadcast: if not started: raise RuntimeError("broadcast ended without announcement") break else: - raise RuntimeError("announcement stream ended before broadcast END") + raise RuntimeError("announcement stream ended before the broadcast went absent") async with client.follow(f"{broadcast}.health") as announced_health: health = await announced_health From 256e421d8ac70a0c42bd549591b5d0915428946b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 00:27:13 -0800 Subject: [PATCH 06/21] wip: move relay-level tests to routes() Co-Authored-By: Claude Opus 5.5 --- rs/moq-ffi/src/test.rs | 16 +++++++------- rs/moq-tokio/tests/integration/broadcast.rs | 23 ++++++++++++++++++--- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index d260138858c..97151f4b7c6 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -483,16 +483,18 @@ async fn following_restarts_on_a_new_instance() { ..Default::default() }) .unwrap(); - tokio::time::timeout(std::time::Duration::from_secs(1), following.available()) + kio::clock::timeout(TIMEOUT, following.available()) .await .expect("the new instance is handed out") .unwrap(); - assert!( - tokio::time::timeout(std::time::Duration::from_millis(100), announced.next()) - .await - .is_err(), - "a restart is not listed" - ); + + // The next listed event is the path going absent under the new instance: the restart + // itself was never listed. + publication.unannounce().unwrap(); + match next_event(&announced).await { + MoqAnnounceEvent::Absent { announce } => assert_eq!(announce.route.instance, second), + other => panic!("expected an absence, got {other:?}"), + } publication.broadcast().close().unwrap(); } diff --git a/rs/moq-tokio/tests/integration/broadcast.rs b/rs/moq-tokio/tests/integration/broadcast.rs index 2eb4f5dea15..757aa91d84a 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -801,6 +801,22 @@ async fn broadcast_moq_transport_22_current_group_join() { server_handle.await.expect("server panicked").expect("server failed"); } +/// Wait for the next route change as `(announce, active)`, failing the test on a timeout or a +/// closed origin. +async fn next_route(routes: &mut moq_net::origin::Routes) -> (moq_net::announce::Announce, bool) { + let event = kio::clock::timeout(TIMEOUT, routes.next()) + .await + .expect("announce timeout") + .expect("origin closed"); + match event { + moq_net::origin::RouteEvent::End(announce) => (announce, false), + moq_net::origin::RouteEvent::Start(announce) + | moq_net::origin::RouteEvent::Update(announce) + | moq_net::origin::RouteEvent::Restart(announce) + | moq_net::origin::RouteEvent::Takeover { announce, .. } => (announce, true), + } +} + /// Wait for the next announce event, failing the test on a timeout or a closed origin. async fn next_announce(announcements: &mut moq_net::announce::Consumer) -> (moq_net::announce::Announce, bool) { kio::clock::timeout(TIMEOUT, next_update(announcements)) @@ -1439,7 +1455,8 @@ async fn route_reannounce_test(version: Option<&str>) { // ── subscriber (client) ───────────────────────────────────────── let sub_origin = moq_tokio::origin::spawn(); let sub_consumer = sub_origin.consume(); - let mut announcements = sub_consumer.announced(); + // A hop change is a route update, which only the relay-level stream reports. + let mut announcements = sub_consumer.routes(); let mut client_config = moq_tokio::connect::Config::default(); client_config.tls.insecure = Some(true); @@ -1453,7 +1470,7 @@ async fn route_reannounce_test(version: Option<&str>) { .expect("connect timeout") .expect("connect failed"); - let (update, active) = next_announce(&mut announcements).await; + let (update, active) = next_route(&mut announcements).await; assert_eq!(update.prefix.as_str(), "test"); assert!(active, "expected announce"); let initial = update.route; @@ -1480,7 +1497,7 @@ async fn route_reannounce_test(version: Option<&str>) { .expect("update route"); // The subscriber sees the new chain as another active update for the prefix... - let (update, active) = next_announce(&mut announcements).await; + let (update, active) = next_route(&mut announcements).await; assert_eq!(update.prefix.as_str(), "test"); assert!(active, "a restart must not retract the route"); assert_ne!(initial.hops, update.route.hops, "route must change"); From 8e410e8f0816913ca6e9585a351cf658d591310a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 00:39:09 -0800 Subject: [PATCH 07/21] wip(cpp): announce listing in the interop client and OBS test Co-Authored-By: Claude Opus 5.5 --- cpp/obs/test/moq-output-test.cpp | 6 +++--- test/interop/clients/cpp/main.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/obs/test/moq-output-test.cpp b/cpp/obs/test/moq-output-test.cpp index 4c8ae88281a..da6b44d8fa0 100644 --- a/cpp/obs/test/moq-output-test.cpp +++ b/cpp/obs/test/moq-output-test.cpp @@ -408,10 +408,10 @@ struct MoQOutputStatsTest { auto event = TestOk(next.get(), "announcement"); if (!event) return std::nullopt; - const auto *start = std::get_if(&event->get_variant()); - if (!start) + const auto *present = std::get_if(&event->get_variant()); + if (!present) return std::nullopt; - return start->announce.route.instance; + return present->announce.route.instance; } static std::shared_ptr Session(MoQOutput &output) diff --git a/test/interop/clients/cpp/main.cpp b/test/interop/clients/cpp/main.cpp index 37a3fda1adf..bb8c8af14d4 100644 --- a/test/interop/clients/cpp/main.cpp +++ b/test/interop/clients/cpp/main.cpp @@ -399,9 +399,9 @@ int subscribe( if (frames != expected_frames) fail("wrong finished media frame count"); while (until(catalogs->next(), read_deadline, "catalog EOF")) {} for (;;) { - auto event = until(routes->next(), read_deadline, "announcement END"); + auto event = until(routes->next(), read_deadline, "announcement absent"); if (!event) fail("origin ended before broadcast withdrawal"); - const auto *end = std::get_if(&event->get_variant()); + const auto *end = std::get_if(&event->get_variant()); if (end && end->announce.prefix == path) break; } auto watch = ok(session->consume()->follow(path + ".health", std::nullopt), "health watch"); From f402aae18fba29572ff01cd2ff038134351fc462 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 10:08:16 -0800 Subject: [PATCH 08/21] feat(bindings)!: follow reports the path going offline Co-Authored-By: Claude Opus 5.5 --- c/moq/MIGRATE.md | 2 + cpp/moq/MIGRATE.md | 4 + cpp/moq/test/probe.cpp | 2 + cpp/obs/src/moq-source.cpp | 11 +- dart/moq/MIGRATE.md | 10 +- dart/moq/README.md | 3 +- dart/moq/lib/src/client.dart | 5 +- dart/moq/test/moq_test.dart | 25 +- dart/moq_ffi/lib/src/moq.dart | 248 ++++++------------ demo/carla/sim/moq_carla_sim/publish.py | 5 +- demo/carla/sim/tests/test_publish.py | 24 +- doc/concept/identity.md | 4 +- doc/lib/c/index.md | 4 +- doc/lib/cpp/index.md | 7 +- doc/lib/dart/index.md | 9 +- doc/lib/go/index.md | 2 +- doc/lib/kt/index.md | 2 +- doc/lib/py/index.md | 2 +- doc/lib/rs/moq-net.md | 2 +- doc/lib/swift/index.md | 2 +- go/wrapper/MIGRATE.md | 9 + go/wrapper/README.md | 3 +- go/wrapper/example_test.go | 36 +++ go/wrapper/moq_test.go | 71 +++++ go/wrapper/origin.go | 29 +- kt/README.md | 2 +- kt/moq/MIGRATE.md | 11 +- .../jvmAndAndroidMain/kotlin/dev/moq/Moq.kt | 5 +- .../kotlin/dev/moq/SmokeTest.kt | 22 +- py/moq-rs/MIGRATE.md | 6 + py/moq-rs/README.md | 2 +- py/moq-rs/examples/clock.py | 1 + py/moq-rs/moq/origin.py | 25 +- py/moq-rs/tests/test_local.py | 23 +- rs/moq-c/MIGRATE.md | 2 + rs/moq-ffi/MIGRATE.md | 2 + swift/MIGRATE.md | 9 +- swift/README.md | 3 +- swift/Sources/Moq/Origin.swift | 13 +- swift/Tests/MoqTests/SmokeTests.swift | 25 +- test/interop/clients/c/subscribe.c | 11 + test/interop/clients/cpp/main.cpp | 2 + test/interop/clients/python/interop.py | 3 + 43 files changed, 447 insertions(+), 241 deletions(-) diff --git a/c/moq/MIGRATE.md b/c/moq/MIGRATE.md index 3b902f18212..92f4dadf9ce 100644 --- a/c/moq/MIGRATE.md +++ b/c/moq/MIGRATE.md @@ -12,6 +12,8 @@ The hand-written crate never published as moq-c: a libmoq 0.6 user applies these Another instance taking a path over keeps it present, and a route's cost changing is not reported. Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. +`moq_origin_follow`'s callback also receives `MOQ_FOLLOW_OFFLINE` (`INT32_MAX`) once the path goes offline, or, for a follow pinned to an instance, once another instance takes it over. It is positive and not terminal, and no handle ever takes that value: check for it before treating a positive code as a broadcast handle. + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `moq_announce_event.has_captures` is removed, changing the C ABI. Read `captures_len` directly: zero means the filter has no wildcards. Rebuild consumers against the regenerated header and matching native library. diff --git a/cpp/moq/MIGRATE.md b/cpp/moq/MIGRATE.md index d561d680531..9592f42ea42 100644 --- a/cpp/moq/MIGRATE.md +++ b/cpp/moq/MIGRATE.md @@ -2,6 +2,10 @@ ## Unreleased +### `Following::available()` reports the path going offline ([#7678](https://github.com/moq-dev/moq/pull/7678)) + +`moq::Following::available()` resolves to a null `std::shared_ptr` once the path goes offline (or, for a follow pinned to an instance, once another instance takes it over), then the next broadcast when something serves the path again. The first call is never null. Check for null before using a later result, and treat it like the previous instance ending. + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `moq::Announce.captures` is `std::vector` instead of an optional vector. Remove optional checks and dereferences; an empty vector means the filter has no wildcards. Regenerate bindings and rebuild with the matching native library. diff --git a/cpp/moq/test/probe.cpp b/cpp/moq/test/probe.cpp index 23e4aaacff3..a85d975cfe8 100644 --- a/cpp/moq/test/probe.cpp +++ b/cpp/moq/test/probe.cpp @@ -313,7 +313,9 @@ int main() // Subscriber: resolve the announced broadcast and subscribe to its track. auto announced = ok(session->consume()->follow("probe", std::nullopt), "follow"); + // The first available() is never offline. auto remote = ok(announced->available().get(), "available"); + CHECK(remote); auto consumer = ok(remote->subscribe_track("data", std::nullopt).get(), "subscribe_track"); // Cancel a read that has nothing to deliver yet. diff --git a/cpp/obs/src/moq-source.cpp b/cpp/obs/src/moq-source.cpp index 626f96e3b6e..ec44904fb5b 100644 --- a/cpp/obs/src/moq-source.cpp +++ b/cpp/obs/src/moq-source.cpp @@ -439,7 +439,8 @@ static void moq_source_on_connect(struct moq_source *ctx, const std::shared_ptr< moq_source_next_broadcast(ctx, conn); } -// Waits for the next publisher instance: the first one announced, then each that takes over. +// Waits for the next publisher instance: the first one announced, then each that takes over +// or returns after the broadcast went offline. static void moq_source_next_broadcast(struct moq_source *ctx, const std::shared_ptr &conn) { conn->available_call = conn->announced->available().then( @@ -457,6 +458,14 @@ static void moq_source_on_broadcast(struct moq_source *ctx, const std::shared_pt return; } + // The offline instance's tracks end on their own once its route dies, holding the last + // frame, so only wait for whatever serves the path next. + if (!*result) { + LOG_INFO("Broadcast went offline: %s", conn->broadcast.c_str()); + moq_source_next_broadcast(ctx, conn); + return; + } + // Another instance took over, or the broadcast came back. The previous one's active tracks // keep playing until the new catalog's renditions commit, or until they end once its // route dies, holding the last frame. diff --git a/dart/moq/MIGRATE.md b/dart/moq/MIGRATE.md index 08e176dab62..7fc18dd5e8e 100644 --- a/dart/moq/MIGRATE.md +++ b/dart/moq/MIGRATE.md @@ -4,6 +4,12 @@ How to update your code for each breaking change, newest first. ## Unreleased +### `Following.available()` returns null once the path goes offline + +`await following.available()` returns `BroadcastConsumer?`. +After the first call, it returns null once the followed path goes offline, or, for a `follow(path, instance: ...)` pinned to an instance, once another instance takes it over; the next call returns whatever serves the path next. The first call never returns null. +Drop what you read from the previous broadcast either way. A caller that only waits for the first broadcast can take it with `!`. + ### Announcements are a listing `announced(...).updates()` yields `AnnounceEventPresent` when a path becomes present and `AnnounceEventAbsent` when it goes, each carrying an `Announce`. @@ -14,7 +20,9 @@ Where you requested the path again on a restart, hold `follow(path)` instead; ea ```dart final following = moq.follow('live/camera'); while (true) { - play(await following.available()); + final broadcast = await following.available(); + if (broadcast == null) continue; // offline until the next instance + play(broadcast); } ``` diff --git a/dart/moq/README.md b/dart/moq/README.md index 8dbec24e263..c6ccb9272be 100644 --- a/dart/moq/README.md +++ b/dart/moq/README.md @@ -11,7 +11,8 @@ final announced = connection.announced( ); await for (final event in announced.updates()) { // The listing reports each path once while it stays present, even as its - // publisher restarts; `connection.follow(path)` hands out each new run. + // publisher restarts; `connection.follow(path)` hands out each new run, or + // null once it goes offline. switch (event) { case AnnounceEventPresent(:final announce): // Prefix stays origin-relative; captures reports wildcard matches. diff --git a/dart/moq/lib/src/client.dart b/dart/moq/lib/src/client.dart index 9e374bdd0e1..c4fc4e4e160 100644 --- a/dart/moq/lib/src/client.dart +++ b/dart/moq/lib/src/client.dart @@ -232,8 +232,9 @@ final class Moq { }) => session.consume().announced(config: options._ffi); /// Follow the broadcast at exactly [path]: each `available()` resolves the - /// next instance serving it, such as a restarted publisher. Pass an - /// [instance] to follow only that stream. + /// next instance serving it, such as a restarted publisher, or null once the + /// path goes offline. Pass an [instance] to follow only that stream; another + /// one taking over also resolves null. Following follow(String path, {String? instance}) => session.consume().follow(path: path, instance: instance); diff --git a/dart/moq/test/moq_test.dart b/dart/moq/test/moq_test.dart index 47569ca045c..88404b088f5 100644 --- a/dart/moq/test/moq_test.dart +++ b/dart/moq/test/moq_test.dart @@ -526,10 +526,10 @@ void main() { publication.announce(route: AnnounceRoute()); final present = await nextRoute(announced) as AnnounceEventPresent; expect(present.announce.route.instance, isNotEmpty); - (await following.available().timeout(timeout)).dispose(); + (await following.available().timeout(timeout))!.dispose(); publication.announce(route: AnnounceRoute(instance: 'camera', epoch: 1)); - (await following.available().timeout(timeout)).dispose(); + (await following.available().timeout(timeout))!.dispose(); // The takeover was not listed, so the next event is the path going absent. publication.unannounce(); @@ -546,6 +546,27 @@ void main() { announced.dispose(); }); + test( + 'a follower reports the path going offline and the next broadcast', + () async { + final origin = MoqOriginProducer(config: MoqOriginConfig()); + final following = origin.consume().follow(path: 'offline'); + final publication = origin.createBroadcast(path: 'offline'); + + publication.announce(route: AnnounceRoute()); + (await following.available().timeout(timeout))!.dispose(); + + publication.unannounce(); + expect(await following.available().timeout(timeout), isNull); + + publication.announce(route: AnnounceRoute()); + (await following.available().timeout(timeout))!.dispose(); + + following.cancel(); + following.dispose(); + }, + ); + test('announced pattern reports captures', () async { final origin = MoqOriginProducer(config: MoqOriginConfig()); final announced = origin.consume().announced( diff --git a/dart/moq_ffi/lib/src/moq.dart b/dart/moq_ffi/lib/src/moq.dart index afad90c9868..6a080632e5d 100644 --- a/dart/moq_ffi/lib/src/moq.dart +++ b/dart/moq_ffi/lib/src/moq.dart @@ -8085,31 +8085,13 @@ class FfiConverterMoqAnnounceEvent { final subview = Uint8List.view(buf.buffer, buf.offsetInBytes + 4); switch (index) { case 1: - final lifted = StartMoqAnnounceEvent.read(subview); + final lifted = PresentMoqAnnounceEvent.read(subview); return LiftRetVal( lifted.value, lifted.bytesRead - subview.offsetInBytes + 4, ); case 2: - final lifted = UpdateMoqAnnounceEvent.read(subview); - return LiftRetVal( - lifted.value, - lifted.bytesRead - subview.offsetInBytes + 4, - ); - case 3: - final lifted = EndMoqAnnounceEvent.read(subview); - return LiftRetVal( - lifted.value, - lifted.bytesRead - subview.offsetInBytes + 4, - ); - case 4: - final lifted = RestartMoqAnnounceEvent.read(subview); - return LiftRetVal( - lifted.value, - lifted.bytesRead - subview.offsetInBytes + 4, - ); - case 5: - final lifted = TakeoverMoqAnnounceEvent.read(subview); + final lifted = AbsentMoqAnnounceEvent.read(subview); return LiftRetVal( lifted.value, lifted.bytesRead - subview.offsetInBytes + 4, @@ -8135,18 +8117,18 @@ class FfiConverterMoqAnnounceEvent { } } -class StartMoqAnnounceEvent extends MoqAnnounceEvent { +class PresentMoqAnnounceEvent extends MoqAnnounceEvent { final MoqAnnounce announce; - StartMoqAnnounceEvent(MoqAnnounce this.announce); - StartMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { + PresentMoqAnnounceEvent(MoqAnnounce this.announce); + PresentMoqAnnounceEvent._(MoqAnnounce this.announce); + static LiftRetVal read(Uint8List buf) { int new_offset = buf.offsetInBytes; final announce_lifted = FfiConverterMoqAnnounce.read( Uint8List.view(buf.buffer, new_offset), ); final announce = announce_lifted.value; new_offset += announce_lifted.bytesRead; - return LiftRetVal(StartMoqAnnounceEvent._(announce), new_offset); + return LiftRetVal(PresentMoqAnnounceEvent._(announce), new_offset); } @override @@ -8173,18 +8155,18 @@ class StartMoqAnnounceEvent extends MoqAnnounceEvent { } } -class UpdateMoqAnnounceEvent extends MoqAnnounceEvent { +class AbsentMoqAnnounceEvent extends MoqAnnounceEvent { final MoqAnnounce announce; - UpdateMoqAnnounceEvent(MoqAnnounce this.announce); - UpdateMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { + AbsentMoqAnnounceEvent(MoqAnnounce this.announce); + AbsentMoqAnnounceEvent._(MoqAnnounce this.announce); + static LiftRetVal read(Uint8List buf) { int new_offset = buf.offsetInBytes; final announce_lifted = FfiConverterMoqAnnounce.read( Uint8List.view(buf.buffer, new_offset), ); final announce = announce_lifted.value; new_offset += announce_lifted.bytesRead; - return LiftRetVal(UpdateMoqAnnounceEvent._(announce), new_offset); + return LiftRetVal(AbsentMoqAnnounceEvent._(announce), new_offset); } @override @@ -8211,141 +8193,6 @@ class UpdateMoqAnnounceEvent extends MoqAnnounceEvent { } } -class EndMoqAnnounceEvent extends MoqAnnounceEvent { - final MoqAnnounce announce; - EndMoqAnnounceEvent(MoqAnnounce this.announce); - EndMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { - int new_offset = buf.offsetInBytes; - final announce_lifted = FfiConverterMoqAnnounce.read( - Uint8List.view(buf.buffer, new_offset), - ); - final announce = announce_lifted.value; - new_offset += announce_lifted.bytesRead; - return LiftRetVal(EndMoqAnnounceEvent._(announce), new_offset); - } - - @override - RustBuffer lower() { - final buf = Uint8List(allocationSize()); - write(buf); - return toRustBuffer(buf); - } - - @override - int allocationSize() { - return FfiConverterMoqAnnounce.allocationSize(announce) + 4; - } - - @override - int write(Uint8List buf) { - buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 3); - int new_offset = buf.offsetInBytes + 4; - new_offset += FfiConverterMoqAnnounce.write( - announce, - Uint8List.view(buf.buffer, new_offset), - ); - return new_offset; - } -} - -class RestartMoqAnnounceEvent extends MoqAnnounceEvent { - final MoqAnnounce announce; - RestartMoqAnnounceEvent(MoqAnnounce this.announce); - RestartMoqAnnounceEvent._(MoqAnnounce this.announce); - static LiftRetVal read(Uint8List buf) { - int new_offset = buf.offsetInBytes; - final announce_lifted = FfiConverterMoqAnnounce.read( - Uint8List.view(buf.buffer, new_offset), - ); - final announce = announce_lifted.value; - new_offset += announce_lifted.bytesRead; - return LiftRetVal(RestartMoqAnnounceEvent._(announce), new_offset); - } - - @override - RustBuffer lower() { - final buf = Uint8List(allocationSize()); - write(buf); - return toRustBuffer(buf); - } - - @override - int allocationSize() { - return FfiConverterMoqAnnounce.allocationSize(announce) + 4; - } - - @override - int write(Uint8List buf) { - buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 4); - int new_offset = buf.offsetInBytes + 4; - new_offset += FfiConverterMoqAnnounce.write( - announce, - Uint8List.view(buf.buffer, new_offset), - ); - return new_offset; - } -} - -class TakeoverMoqAnnounceEvent extends MoqAnnounceEvent { - final MoqAnnounce announce; - final String predecessor; - TakeoverMoqAnnounceEvent({ - required MoqAnnounce this.announce, - required String this.predecessor, - }); - TakeoverMoqAnnounceEvent._( - MoqAnnounce this.announce, - String this.predecessor, - ); - static LiftRetVal read(Uint8List buf) { - int new_offset = buf.offsetInBytes; - final announce_lifted = FfiConverterMoqAnnounce.read( - Uint8List.view(buf.buffer, new_offset), - ); - final announce = announce_lifted.value; - new_offset += announce_lifted.bytesRead; - final predecessor_lifted = FfiConverterString.read( - Uint8List.view(buf.buffer, new_offset), - ); - final predecessor = predecessor_lifted.value; - new_offset += predecessor_lifted.bytesRead; - return LiftRetVal( - TakeoverMoqAnnounceEvent._(announce, predecessor), - new_offset, - ); - } - - @override - RustBuffer lower() { - final buf = Uint8List(allocationSize()); - write(buf); - return toRustBuffer(buf); - } - - @override - int allocationSize() { - return FfiConverterMoqAnnounce.allocationSize(announce) + - FfiConverterString.allocationSize(predecessor) + - 4; - } - - @override - int write(Uint8List buf) { - buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 5); - int new_offset = buf.offsetInBytes + 4; - new_offset += FfiConverterMoqAnnounce.write( - announce, - Uint8List.view(buf.buffer, new_offset), - ); - new_offset += FfiConverterString.write( - predecessor, - Uint8List.view(buf.buffer, new_offset), - ); - return new_offset; - } -} - enum MoqTransport { quic, webSocket, tcp, unix, webTransport } class FfiConverterMoqTransport { @@ -12541,7 +12388,7 @@ class FfiConverterMoqBroadcastRequest { } abstract class MoqFollowingInterface { - UniffiRustFuture available(); + UniffiRustFuture available(); void cancel(); } @@ -12582,16 +12429,15 @@ class MoqFollowing implements MoqFollowingInterface { } } - UniffiRustFuture available() { + UniffiRustFuture available() { return uniffiRustCallAsync( () => uniffi_moq_ffi_fn_method_moqfollowing_available(uniffiClonePointer()), - ffi_moq_ffi_rust_future_poll_u64, - ffi_moq_ffi_rust_future_complete_u64, - ffi_moq_ffi_rust_future_cancel_u64, - ffi_moq_ffi_rust_future_free_u64, - (ptr) => - FfiConverterMoqBroadcastConsumer.lift(Pointer.fromAddress(ptr)), + ffi_moq_ffi_rust_future_poll_rust_buffer, + ffi_moq_ffi_rust_future_complete_rust_buffer, + ffi_moq_ffi_rust_future_cancel_rust_buffer, + ffi_moq_ffi_rust_future_free_rust_buffer, + FfiConverterOptionalMoqBroadcastConsumer.lift, moqExceptionErrorHandler, ); } @@ -15951,6 +15797,58 @@ class FfiConverterOptionalMoqBandwidthConsumer { } } +class FfiConverterOptionalMoqBroadcastConsumer { + static MoqBroadcastConsumer? lift(RustBuffer buf) { + return FfiConverterOptionalMoqBroadcastConsumer.read( + buf.asUint8List(), + ).value; + } + + static LiftRetVal read(Uint8List buf) { + if (ByteData.view(buf.buffer, buf.offsetInBytes).getInt8(0) == 0) { + return LiftRetVal(null, 1); + } + final result = FfiConverterMoqBroadcastConsumer.read( + Uint8List.view(buf.buffer, buf.offsetInBytes + 1), + ); + return LiftRetVal( + result.value, + result.bytesRead + 1, + ); + } + + static int allocationSize([MoqBroadcastConsumer? value]) { + if (value == null) { + return 1; + } + return FfiConverterMoqBroadcastConsumer.allocationSize(value) + 1; + } + + static RustBuffer lower(MoqBroadcastConsumer? value) { + if (value == null) { + return toRustBuffer(Uint8List.fromList([0])); + } + final buf = Uint8List( + FfiConverterOptionalMoqBroadcastConsumer.allocationSize(value), + ); + FfiConverterOptionalMoqBroadcastConsumer.write(value, buf); + return toRustBuffer(buf); + } + + static int write(MoqBroadcastConsumer? value, Uint8List buf) { + if (value == null) { + buf[0] = 0; + return 1; + } + buf[0] = 1; + return FfiConverterMoqBroadcastConsumer.write( + value, + Uint8List.view(buf.buffer, buf.offsetInBytes + 1), + ) + + 1; + } +} + class FfiConverterOptionalMoqCatalog { static MoqCatalog? lift(RustBuffer buf) { return FfiConverterOptionalMoqCatalog.read(buf.asUint8List()).value; @@ -22103,7 +22001,7 @@ void _checkApiChecksums() { if (uniffi_moq_ffi_checksum_method_moqbroadcastrequest_reject() != 9727) { throw UniffiInternalError.panicked("UniFFI API checksum mismatch"); } - if (uniffi_moq_ffi_checksum_method_moqfollowing_available() != 39867) { + if (uniffi_moq_ffi_checksum_method_moqfollowing_available() != 26337) { throw UniffiInternalError.panicked("UniFFI API checksum mismatch"); } if (uniffi_moq_ffi_checksum_method_moqfollowing_cancel() != 37387) { @@ -22112,7 +22010,7 @@ void _checkApiChecksums() { if (uniffi_moq_ffi_checksum_method_moqoriginconsumer_announced() != 35661) { throw UniffiInternalError.panicked("UniFFI API checksum mismatch"); } - if (uniffi_moq_ffi_checksum_method_moqoriginconsumer_follow() != 34533) { + if (uniffi_moq_ffi_checksum_method_moqoriginconsumer_follow() != 55889) { throw UniffiInternalError.panicked("UniFFI API checksum mismatch"); } if (uniffi_moq_ffi_checksum_method_moqoriginconsumer_request() != 40910) { diff --git a/demo/carla/sim/moq_carla_sim/publish.py b/demo/carla/sim/moq_carla_sim/publish.py index 1ad084c77e2..b21ab1cffbb 100644 --- a/demo/carla/sim/moq_carla_sim/publish.py +++ b/demo/carla/sim/moq_carla_sim/publish.py @@ -342,7 +342,7 @@ async def _follow_driver( path: str, commands: asyncio.Queue[Command], ) -> None: - """Pump each run of one driver in turn, ending a run once another takes over.""" + """Pump each run of one driver in turn, ending a run once another takes over or it goes offline.""" run: asyncio.Task[None] | None = None try: async with client.follow(path) as following: @@ -350,6 +350,9 @@ async def _follow_driver( broadcast = await following.available() if run is not None: run.cancel() + run = None + if broadcast is None: + continue instance = str(next(_runs)) run = asyncio.create_task( _pump_driver(driver_id, instance, broadcast, commands), diff --git a/demo/carla/sim/tests/test_publish.py b/demo/carla/sim/tests/test_publish.py index ffd08cb9898..da0d4fda989 100644 --- a/demo/carla/sim/tests/test_publish.py +++ b/demo/carla/sim/tests/test_publish.py @@ -219,7 +219,7 @@ async def absent(self, path: str) -> None: class Following(Scripted): - """A scripted follow of one path: each `run` hands out another instance.""" + """A scripted follow of one path: each `run` hands out another instance, and `offline` a `None`.""" async def __aenter__(self): return self @@ -243,6 +243,9 @@ async def subscribe_track(name: str): await self.send(SimpleNamespace(subscribe_track=subscribe_track)) + async def offline(self) -> None: + await self.send(None) + class Drivers: """A relay holding driver broadcasts.""" @@ -302,6 +305,25 @@ async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None asyncio.run(watching(scenario)) +def test_a_driver_whose_run_goes_offline_loses_the_lease_until_it_returns() -> None: + async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None: + await relay.announcements.present(DRIVER) + await relay.following(DRIVER).run(1) + first = await next_command(commands, gate) + + await relay.following(DRIVER).offline() + left = await next_command(commands, gate) + assert (left.kind, left.instance) == ("driver_left", first.instance) + assert gate.driver is None + + await relay.following(DRIVER).run(2) + second = await next_command(commands, gate) + assert second.kind == "drive" and second.instance != first.instance + assert gate.driver == "abc" + + asyncio.run(watching(scenario)) + + def test_a_driver_that_restarts_under_a_new_instance_is_a_new_driver() -> None: """The old run's lease ends with it, even though the path and id are the same.""" diff --git a/doc/concept/identity.md b/doc/concept/identity.md index 5facd6bcdeb..71cfbaf2b1d 100644 --- a/doc/concept/identity.md +++ b/doc/concept/identity.md @@ -126,7 +126,9 @@ out nothing. Start on each broadcast, drop all decoder and buffer state when the next one arrives, and wait while the path is offline. Rust uses `consumer.follow(path, None)`, whose `available()` returns `None` once the path goes offline; JavaScript `origin.follow(path)`, whose `active` is undefined -between instances; and the moq-ffi bindings `follow(path)` with `available()`. +between instances; the moq-ffi bindings `follow(path)`, whose `available()` +returns null once the path goes offline; and C `moq_origin_follow`, whose +callback receives `MOQ_FOLLOW_OFFLINE`. An announcement listing (`announced()`) only reports a path becoming present or absent: 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 diff --git a/doc/lib/c/index.md b/doc/lib/c/index.md index 98632ca4908..18c6b93b164 100644 --- a/doc/lib/c/index.md +++ b/doc/lib/c/index.md @@ -83,7 +83,9 @@ if (moq_publication_announce((uint32_t)publication, &route) < 0) A route carries only a cost and the stream's instance; relays add the hops. Each publication mints a fresh instance and keeps it across re-announcing, so a restarted publisher is a new stream that `moq_origin_follow` hands viewers instead of a stalled -broadcast; the path stays `MOQ_ANNOUNCE_KIND_PRESENT` throughout. Set `instance` only for a publisher that continues its group sequences +broadcast; the path stays `MOQ_ANNOUNCE_KIND_PRESENT` throughout. The follow callback +receives `MOQ_FOLLOW_OFFLINE` once the path goes offline, which is positive but never a +handle. Set `instance` only for a publisher that continues its group sequences across restarts, and raise `epoch` on each: readers stitch every route of one instance together, so restarting the sequences under an old instance splices unrelated groups into their tracks. diff --git a/doc/lib/cpp/index.md b/doc/lib/cpp/index.md index 4b139d69663..7b5a33255d6 100644 --- a/doc/lib/cpp/index.md +++ b/doc/lib/cpp/index.md @@ -94,7 +94,7 @@ void ok(moq::expected result) { auto client = ok(moq::Client::init({})); // a moq::ClientConfig; {} takes every default auto session = ok(client->connect("https://relay.example.com").get()); auto announced = ok(session->consume()->follow("my-stream.hang", std::nullopt)); -auto broadcast = ok(announced->available().get()); +auto broadcast = ok(announced->available().get()); // the first call is never null auto catalogs = ok(moq::MediaCatalogConsumer::subscribe(broadcast).get()); if (auto catalog = ok(catalogs->next().get())) { // std::nullopt once the catalog ends for (const auto &[id, video] : catalog->video) { @@ -111,8 +111,9 @@ The config is generated, so nothing names this package for you: set after any product tokens of your own, and moq-ffi appends its own. Call `available()` again to wait for the next publisher instance at that path, such as a -restarted publisher, and drop what was read from the previous one then: its tracks end -when its session does. +restarted publisher. It returns null once the path goes offline, then the next +broadcast when something serves it again. Drop what was read from the previous instance +on either: its tracks end when its session does. `MediaTrackConsumer` reads `MediaRead` records in decode order: `kFrame`, `kGap`, or `kEnd`, like the audio and video decoders. Match the variant before taking its frame. diff --git a/doc/lib/dart/index.md b/doc/lib/dart/index.md index 65712542984..6774439cf1d 100644 --- a/doc/lib/dart/index.md +++ b/doc/lib/dart/index.md @@ -60,7 +60,7 @@ moq .updates() .listen((event) { // A path stays present across publisher restarts: hold moq.follow(path) to be handed - // each new run. + // each new run, or null once it goes offline. switch (event) { case AnnounceEventPresent(:final announce): print(announce.prefix); @@ -69,8 +69,9 @@ moq case AnnounceEventAbsent(): } }); -// Wait for a publisher at one path; call available() again for the next one. -final broadcast = await moq.follow('live/camera').available(); +// Wait for a publisher at one path. The first call never returns null; call available() +// again for the next one, or null once the path goes offline. +final broadcast = (await moq.follow('live/camera').available())!; final catalog = await media.CatalogConsumer.subscribe(broadcast: broadcast); print(await catalog.next()); ``` @@ -105,7 +106,7 @@ encoder.finish(); // Decode a subscribed rendition. Dispose each frame promptly. import 'package:moq/video.dart' as video; -final remote = await moq.follow('live/camera').available(); +final remote = (await moq.follow('live/camera').available())!; final renditions = await media.CatalogConsumer.subscribe(broadcast: remote); final decoder = await video.Consumer.subscribe( broadcast: remote, diff --git a/doc/lib/go/index.md b/doc/lib/go/index.md index 17f71a20fde..98d21d69b86 100644 --- a/doc/lib/go/index.md +++ b/doc/lib/go/index.md @@ -67,7 +67,7 @@ for event, err := range announced.All(ctx) { log.Fatal(err) } // A path stays present across publisher restarts: hold client.Follow(path, nil) to be - // handed each new run. + // handed each new run, with Available returning nil while the path is offline. present, ok := event.(moq.AnnounceEventPresent) if !ok { continue // AnnounceEventAbsent diff --git a/doc/lib/kt/index.md b/doc/lib/kt/index.md index 06623ed13ae..727fe8cc5dd 100644 --- a/doc/lib/kt/index.md +++ b/doc/lib/kt/index.md @@ -54,7 +54,7 @@ import dev.moq.media.* Moq.connect("https://relay.example.com", ClientConfig(tls = ClientTls(roots = listOf("ca.pem")))).use { moq -> moq.announced(AnnounceConfig(prefix = "live/", filter = "*/camera")).updates().collect { event -> // A path stays present across publisher restarts: hold moq.follow(path) to be handed - // each new run. + // each new run, or null once it goes offline. val announce = when (event) { is AnnounceEventPresent -> event.announce is AnnounceEventAbsent -> return@collect diff --git a/doc/lib/py/index.md b/doc/lib/py/index.md index 9c81adb75f8..0f86cc61454 100644 --- a/doc/lib/py/index.md +++ b/doc/lib/py/index.md @@ -48,7 +48,7 @@ async def main(): # The filter is relative to the literal prefix; prefixes stay origin-relative. async for event in client.announced("live/", filter="*/camera"): # A path stays present across publisher restarts: hold client.follow(path) to - # be handed each new run. + # be handed each new run, or None once it goes offline. if not isinstance(event, moq.AnnounceEventPresent): continue # AnnounceEventAbsent announcement = event.announce diff --git a/doc/lib/rs/moq-net.md b/doc/lib/rs/moq-net.md index 0ed50e2dfe7..b69571c2ceb 100644 --- a/doc/lib/rs/moq-net.md +++ b/doc/lib/rs/moq-net.md @@ -18,7 +18,7 @@ What you use it for, beyond what the concept page already describes: - **An origin outlives the session.** Creating a broadcast returns an origin publication that controls its announcement and exposes the broadcast to fill. Standalone and Prepared fill producers cannot announce; only publishing the Prepared answer admits its publication. A reconnect announces existing publications again, and closing the session does not delete them. - **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. A broadcast announced with `Route::default()` serves a random instance it keeps across re-announcing; set one with `Route::with_instance(instance, epoch)` only for a publisher that continues its group sequences across restarts and raises the epoch each time. - **Rank several CDNs.** Dial each with its own subscribe handle, `origin.clone().with_preference(origin::Preference::new(rank))` (higher wins; 0 is neutral and a negative rank demotes), all on one origin. Requests use the preferred link that has a route 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 or returns after an end, like JS `follow(path)`. 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 only as present or absent. 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-rtc 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. - **One track per name.** Concurrent subscriptions share one request and producer. The application owns sequence numbers: the broadcast keeps nothing of an ended track, so a producer that replaces it starts at 0. A name always means the same content, so the replacement continues past its predecessor's groups with `create_group` at an explicit sequence. 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. - **End content by finishing tracks.** A broadcast has no finished state. When the input ends, finish each track; the broadcast stays announced and keeps serving them until you close it or drop its last producer. How long to keep it up for late readers is yours to decide: `moq_mux::Linger` holds a hang broadcast for a fixed window. diff --git a/doc/lib/swift/index.md b/doc/lib/swift/index.md index 0d5e3484766..b3566637fae 100644 --- a/doc/lib/swift/index.md +++ b/doc/lib/swift/index.md @@ -55,7 +55,7 @@ let session = try await client.connect(to: "https://relay.example.com") for try await event in try session.consume.announced(prefix: "live/", filter: "*/camera") { // A path stays present across publisher restarts: hold follow(path:) to be handed each - // new run. + // new run, or nil once it goes offline. guard case .present(let announcement) = event else { continue } // Prefixes stay origin-relative; captures is a list of wildcard matches, empty without wildcards. print(announcement.captures) diff --git a/go/wrapper/MIGRATE.md b/go/wrapper/MIGRATE.md index 9a364c2c519..22bf4a50be1 100644 --- a/go/wrapper/MIGRATE.md +++ b/go/wrapper/MIGRATE.md @@ -4,6 +4,12 @@ How to update your code for each breaking change, newest first. ## Unreleased +### `Following.Available` reports the path going offline + +After the first call, `Available` returns `(nil, nil)` once the followed path goes offline, or, for a `Follow` pinned to an instance, once another instance takes it over. +The next call returns whatever serves the path next. The first call is never nil. +Check for nil before using the broadcast, and drop what was read from the previous instance either way. + ### Announcements are a listing `AnnounceConsumer` yields only `AnnounceEventPresent`, when a route now covers a path that was absent, and `AnnounceEventAbsent`, when none does any more. @@ -22,6 +28,9 @@ for { if err != nil { return err } + if broadcast == nil { + continue // offline until the next instance + } play(broadcast) } ``` diff --git a/go/wrapper/README.md b/go/wrapper/README.md index c8937a7df37..19aabbfb9de 100644 --- a/go/wrapper/README.md +++ b/go/wrapper/README.md @@ -62,7 +62,8 @@ for event, err := range announced.All(ctx) { The listing reports only whether each path is present. A restarted publisher or another instance taking the path over keeps it present: to read the broadcast across them, hold -`client.Follow(path, nil)` and read each new instance from `Available`. +`client.Follow(path, nil)` and read each new instance from `Available`, which returns nil +while the path is offline. ## Common APIs diff --git a/go/wrapper/example_test.go b/go/wrapper/example_test.go index 767953303a9..aaba35f5a70 100644 --- a/go/wrapper/example_test.go +++ b/go/wrapper/example_test.go @@ -39,6 +39,42 @@ func ExampleClient_Announced() { } } +// Read a broadcast across publisher restarts, noticing when it goes offline. +func ExampleClient_Follow() { + ctx := context.Background() + + client, err := moq.Dial(ctx, "https://relay.example.com", moq.ClientConfig{}) + if err != nil { + log.Fatal(err) + } + defer client.Close() + + following, err := client.Follow("demos/bbb", nil) + if err != nil { + log.Fatal(err) + } + defer following.Cancel() + + for { + broadcast, err := following.Available(ctx) + if err != nil { + if moq.IsShutdown(err) { + break + } + log.Fatal(err) + } + if broadcast == nil { + fmt.Println("offline") + continue + } + catalog, err := moqmedia.CatalogSnapshot(ctx, broadcast) + if err != nil { + log.Fatal(err) + } + fmt.Printf("online: %+v\n", catalog) + } +} + // Publish a media track to a relay. func ExampleClient_CreateBroadcast() { ctx := context.Background() diff --git a/go/wrapper/moq_test.go b/go/wrapper/moq_test.go index fc6dcb3c9e9..a86f50fbcd0 100644 --- a/go/wrapper/moq_test.go +++ b/go/wrapper/moq_test.go @@ -1722,6 +1722,77 @@ func TestInstanceChangeReachesFollowers(t *testing.T) { } } +// A follower reports the path going offline as nil, then the next broadcast once it returns. +func TestFollowReportsOffline(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), testTimeout) + defer cancel() + + origin := newOrigin(t) + following, err := origin.Consume().Follow("offline", nil) + if err != nil { + t.Fatal(err) + } + defer following.Cancel() + + publication, err := origin.CreateBroadcast("offline") + if err != nil { + t.Fatal(err) + } + if err := publication.Announce(moq.AnnounceRoute{}); err != nil { + t.Fatal(err) + } + if broadcast, err := following.Available(ctx); err != nil || broadcast == nil { + t.Fatalf("first Available = %v, %v; want a broadcast", broadcast, err) + } + + if err := publication.Unannounce(); err != nil { + t.Fatal(err) + } + if broadcast, err := following.Available(ctx); err != nil || broadcast != nil { + t.Fatalf("Available after unannounce = %v, %v; want nil", broadcast, err) + } + + if err := publication.Announce(moq.AnnounceRoute{}); err != nil { + t.Fatal(err) + } + if broadcast, err := following.Available(ctx); err != nil || broadcast == nil { + t.Fatalf("Available after re-announce = %v, %v; want a broadcast", broadcast, err) + } +} + +// A follower pinned to an instance reports another instance taking over as nil. +func TestPinnedFollowReportsTakeoverOffline(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), testTimeout) + defer cancel() + + origin := newOrigin(t) + pinned := "cam" + following, err := origin.Consume().Follow("pinned", &pinned) + if err != nil { + t.Fatal(err) + } + defer following.Cancel() + + publication, err := origin.CreateBroadcast("pinned") + if err != nil { + t.Fatal(err) + } + if err := publication.Announce(moq.AnnounceRoute{Instance: &pinned}); err != nil { + t.Fatal(err) + } + if broadcast, err := following.Available(ctx); err != nil || broadcast == nil { + t.Fatalf("first Available = %v, %v; want a broadcast", broadcast, err) + } + + other := "other" + if err := publication.Announce(moq.AnnounceRoute{Instance: &other, Epoch: 1}); err != nil { + t.Fatal(err) + } + if broadcast, err := following.Available(ctx); err != nil || broadcast != nil { + t.Fatalf("Available after takeover = %v, %v; want nil", broadcast, err) + } +} + // nextRoute returns the next announce event. func nextRoute(t *testing.T, ctx context.Context, announced *moq.AnnounceConsumer) moq.AnnounceEvent { t.Helper() diff --git a/go/wrapper/origin.go b/go/wrapper/origin.go index 70ab7600e11..eedb18543c5 100644 --- a/go/wrapper/origin.go +++ b/go/wrapper/origin.go @@ -201,9 +201,9 @@ func (o *OriginConsumer) Announced(options AnnounceOptions) (*AnnounceConsumer, return &AnnounceConsumer{inner: inner}, nil } -// Follow follows an exact path, resolving each stream that serves it. A non-nil -// instance follows only that stream: another one taking over is never handed out, -// and the stream is handed out again if it returns after an end. +// Follow follows an exact path, resolving each stream that serves it and reporting +// when it goes offline. A non-nil instance follows only that stream: another one +// taking over reads as offline, and the stream is handed out again if it returns. func (o *OriginConsumer) Follow(path string, instance *string) (*Following, error) { inner, err := o.inner.Follow(path, instance) if err != nil { @@ -256,15 +256,22 @@ type Following struct { inner *ffi.MoqFollowing } -// Available blocks until the next publisher instance serves the broadcast and -// returns its consumer. The first call resolves the instance serving the path once -// one is announced. Each later call waits for another to take over (a restarted -// publisher, or a replacement session) or for the broadcast to return after it went -// offline. Drop what was read from the previous instance then: its tracks end when -// its session does. +// Available blocks until the publisher instance serving the broadcast changes and +// returns its consumer, or (nil, nil) once the path goes offline. The first call +// resolves the instance serving the path once one is announced, and is never nil. +// Each later call returns another instance taking over (a restarted publisher, or a +// replacement session), nil once the path goes offline (or, when following a pinned +// instance, once another instance takes it over), then whatever serves it next. Drop +// what was read from the previous instance then: its tracks end when its route does. func (a *Following) Available(ctx context.Context) (*BroadcastConsumer, error) { - inner, err := bridge.CallHandle(ctx, a.inner.Cancel, a.inner.Available) - if err != nil { + inner, err := bridge.CallHandle(ctx, a.inner.Cancel, func(ctx context.Context) (*ffi.MoqBroadcastConsumer, error) { + res, err := a.inner.Available(ctx) + if err != nil || res == nil { + return nil, err + } + return *res, nil + }) + if err != nil || inner == nil { return nil, err } return &BroadcastConsumer{inner: inner}, nil diff --git a/kt/README.md b/kt/README.md index 1aceb78d033..fa80aa9d6ac 100644 --- a/kt/README.md +++ b/kt/README.md @@ -32,7 +32,7 @@ import kotlinx.coroutines.flow.collect Moq.connect("https://relay.example.com").use { moq -> moq.announced(AnnounceConfig(prefix = "demos/", filter = "*/camera")).updates().collect { event -> // The listing reports each path once while it stays present, even as its publisher - // restarts; `moq.follow(path)` hands out each new run. + // restarts; `moq.follow(path)` hands out each new run, or null once it goes offline. val announce = when (event) { is AnnounceEventPresent -> event.announce is AnnounceEventAbsent -> return@collect diff --git a/kt/moq/MIGRATE.md b/kt/moq/MIGRATE.md index cf4ad4370dc..d3fa5f0fe58 100644 --- a/kt/moq/MIGRATE.md +++ b/kt/moq/MIGRATE.md @@ -4,6 +4,12 @@ How to update your code for each breaking change, newest first. ## Unreleased +### `Following.available()` returns null once the path goes offline + +`following.available()` returns `BroadcastConsumer?`. +After the first call, it returns null once the followed path goes offline, or, for a `follow(path, instance)` pinned to an instance, once another instance takes it over; the next call returns whatever serves the path next. The first call never returns null. +Drop what you read from the previous broadcast either way. A caller that only waits for the first broadcast can take it with `!!`. + ### Announcements are a listing `announced(config).updates()` emits `AnnounceEventPresent` when a path becomes present and `AnnounceEventAbsent` when it goes, each carrying an `Announce` as `announce`. @@ -13,7 +19,10 @@ Where you requested the path again on a restart, hold `follow(path)` instead; ea ```kotlin val following = moq.follow("live/camera") -while (true) play(following.available()) +while (true) { + val broadcast = following.available() ?: continue // offline until the next instance + play(broadcast) +} ``` ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) diff --git a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt index c7545bf21e5..a268b8ca4ff 100644 --- a/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt +++ b/kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Moq.kt @@ -38,8 +38,9 @@ internal constructor( * Follow exactly [path], resolving each stream that serves it. * * Unlike [request] this waits indefinitely for a future announcement, and each later - * `available()` waits for the next stream, such as a restarted publisher. Pass an [instance] to - * follow only that stream. Cancel the returned handle to stop waiting. + * `available()` waits for the next stream, such as a restarted publisher, or returns null once + * the path goes offline. Pass an [instance] to follow only that stream; another one taking over + * also returns null. Cancel the returned handle to stop waiting. */ fun follow(path: String, instance: String? = null): Following = session.consume().follow(path, instance) diff --git a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt index 6762b4f4af9..2db2f0f3712 100644 --- a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt +++ b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt @@ -764,10 +764,10 @@ class SmokeTest { publication.announce(AnnounceRoute()) val present = assertIs(announced.nextRoute()) assertTrue(present.announce.route.instance.isNotEmpty()) - following.available().close() + assertNotNull(following.available()).close() publication.announce(AnnounceRoute(instance = "camera", epoch = 1uL)) - following.available().close() + assertNotNull(following.available()).close() // The takeover was not listed, so the next event is the path going absent. publication.unannounce() @@ -782,6 +782,24 @@ class SmokeTest { } } + @Test + fun `a follower reports the path going offline and the next broadcast`() = runTest { + OriginProducer(OriginConfig()).use { origin -> + val following = origin.consume().follow("offline", null) + origin.createBroadcast("offline").use { publication -> + publication.announce(AnnounceRoute()) + assertNotNull(following.available()).close() + + publication.unannounce() + assertNull(following.available()) + + publication.announce(AnnounceRoute()) + assertNotNull(following.available()).close() + } + following.cancel() + } + } + @Test fun `announced pattern reports captures`() = runTest { OriginProducer(OriginConfig()).use { origin -> diff --git a/py/moq-rs/MIGRATE.md b/py/moq-rs/MIGRATE.md index f84bef984da..4f47b094104 100644 --- a/py/moq-rs/MIGRATE.md +++ b/py/moq-rs/MIGRATE.md @@ -10,6 +10,12 @@ How to update your code for each breaking change, newest first. `AnnounceEventStart`, `AnnounceEventUpdate`, `AnnounceEventEnd`, `AnnounceEventRestart`, and `AnnounceEventTakeover` are removed: read `AnnounceEventStart` as `AnnounceEventPresent` and `AnnounceEventEnd` as `AnnounceEventAbsent`, and drop the `Update` branch, since a re-priced route is no longer reported. Another publisher instance taking a path over keeps it present and is not listed. Where you requested the path again on `AnnounceEventRestart`, hold `follow(path)` instead and read each `BroadcastConsumer` that `await following.available()` returns, dropping what you read from the previous one. +### `Following.available()` returns `None` once the path goes offline + +`await following.available()` (or `await following`) returns `BroadcastConsumer | None`. +Later calls return `None` when the path goes offline, or, when following an `instance`, when another instance takes it over, then the next broadcast once something serves the path again; the first call never returns `None`. +Stop reading the previous broadcast on `None` and call `available()` again. A caller that only awaits the first broadcast can assert it is not `None`. + ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) `Announce.captures` is `list[str]` instead of `list[str] | None`. Remove `None` checks and pass `captures=[]` when constructing an announcement for a filter without wildcards. Rebuild with the matching generated bindings and native library. diff --git a/py/moq-rs/README.md b/py/moq-rs/README.md index 54611353563..ad259e28e70 100644 --- a/py/moq-rs/README.md +++ b/py/moq-rs/README.md @@ -261,7 +261,7 @@ Every handle whose cleanup is `cancel()` is an async context manager, so exiting - Async iterator yielding `BroadcastRequest` - **`OriginConsumer`**. Discover broadcasts. - `.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 each stream that takes over; an `instance` follows only that stream) + - `.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) ### Types diff --git a/py/moq-rs/examples/clock.py b/py/moq-rs/examples/clock.py index 7fd03a5a569..4df4e102f8b 100644 --- a/py/moq-rs/examples/clock.py +++ b/py/moq-rs/examples/clock.py @@ -42,6 +42,7 @@ async def subscribe(url: str, broadcast_name: str, track_name: str, insecure: bo async with moq.Client(url, tls=moq.ClientTls(insecure=insecure)) as client: print(f"waiting for {broadcast_name!r} at {url}") broadcast = await client.follow(broadcast_name) + assert broadcast is not None print(f"subscribed to {broadcast_name!r} track={track_name!r}") track = await broadcast.subscribe_track(track_name) diff --git a/py/moq-rs/moq/origin.py b/py/moq-rs/moq/origin.py index 3bac0956403..4ca1a5af42b 100644 --- a/py/moq-rs/moq/origin.py +++ b/py/moq-rs/moq/origin.py @@ -69,8 +69,8 @@ class Following: """Follows a specific path across the publisher instances that serve it. ``await`` it (or call :meth:`available`) to get the :class:`BroadcastConsumer` - once the broadcast becomes available, and again for each instance that takes over. - Usable as an async context manager. + once the broadcast becomes available, again for each instance that takes over, + and ``None`` while the path is offline. Usable as an async context manager. """ def __init__(self, inner: MoqFollowing) -> None: @@ -82,15 +82,18 @@ async def __aenter__(self): async def __aexit__(self, *exc) -> None: self.cancel() - async def available(self) -> BroadcastConsumer: - """Await the next publisher instance serving the path and return its consumer. + async def available(self) -> BroadcastConsumer | None: + """Await the next change to the publisher instance serving the path. - The first call resolves the instance serving the path once one is announced. Each - later call waits for another to take over (a restarted publisher, or a replacement - session) or for the broadcast to return after it went offline. Drop what was read - from the previous instance then: its tracks end when its session does. + The first call resolves the instance serving the path once one is announced, and + never returns ``None``. Each later call returns another instance taking over (a + restarted publisher, or a replacement session), or ``None`` once the path goes + offline (or, when following an ``instance``, another one takes it over), then + whatever serves it next. Drop what was read from the previous instance then: its + tracks end when its session does. """ - return BroadcastConsumer(await self._inner.available()) + broadcast = await self._inner.available() + return BroadcastConsumer(broadcast) if broadcast is not None else None def __await__(self): return self.available().__await__() @@ -212,8 +215,8 @@ def follow(self, path: str, *, instance: str | None = None) -> Following: A broadcast created on this origin resolves once it is announced, like a remote one. Pass an ``instance`` to follow only that stream: another one - taking over is never handed out, and the stream is handed out again if it - returns after an end. + taking over reads as ``None`` and is never handed out, and the stream is + handed out again if it returns. """ return Following(self._inner.follow(path, instance)) diff --git a/py/moq-rs/tests/test_local.py b/py/moq-rs/tests/test_local.py index 911e4b698e9..96143d4ad93 100644 --- a/py/moq-rs/tests/test_local.py +++ b/py/moq-rs/tests/test_local.py @@ -416,13 +416,13 @@ async def test_following_restarts_on_a_new_instance(): assert isinstance(present, moq.AnnounceEventPresent) minted = present.announce.route.instance assert minted - await asyncio.wait_for(following.available(), timeout=5.0) + assert await asyncio.wait_for(following.available(), timeout=5.0) is not None # Another instance is another stream: followers restart onto it, while the path # stays present, so neither the re-price nor the restart is listed. publication.announce(moq.AnnounceRoute(cost=1)) publication.announce(moq.AnnounceRoute(instance="cam", epoch=1)) - await asyncio.wait_for(following.available(), timeout=5.0) + assert await asyncio.wait_for(following.available(), timeout=5.0) is not None publication.unannounce() absent = await next_route(announced) assert isinstance(absent, moq.AnnounceEventAbsent) @@ -434,6 +434,20 @@ async def test_following_restarts_on_a_new_instance(): publication.broadcast.close() +async def test_following_reports_the_path_offline_until_it_returns(): + origin = moq.OriginProducer() + consumer = origin.consume() + publication = origin.create_broadcast("live") + publication.announce() + async with consumer.follow("live") as following: + assert await asyncio.wait_for(following.available(), timeout=5.0) is not None + publication.unannounce() + assert await asyncio.wait_for(following.available(), timeout=5.0) is None + publication.announce() + assert await asyncio.wait_for(following.available(), timeout=5.0) is not None + publication.broadcast.close() + + async def test_finish_serves_until_closed(): origin = moq.OriginProducer() consumer = origin.consume() @@ -1665,7 +1679,10 @@ async def test_an_instance_pins_request_and_follow(): with pytest.raises(moq.Error.InvalidInstance): consumer.follow("live", instance="") async with consumer.follow("live", instance="cam") as following: - await asyncio.wait_for(following.available(), timeout=5.0) + assert await asyncio.wait_for(following.available(), timeout=5.0) is not None + # Another instance taking the path over ends the pinned stream. + publication.announce(moq.AnnounceRoute(instance="other")) + assert await asyncio.wait_for(following.available(), timeout=5.0) is None publication.broadcast.close() diff --git a/rs/moq-c/MIGRATE.md b/rs/moq-c/MIGRATE.md index 5c560f1ab0d..34fabfc1471 100644 --- a/rs/moq-c/MIGRATE.md +++ b/rs/moq-c/MIGRATE.md @@ -9,6 +9,8 @@ How to update your code for each breaking change, newest first. `moq_announce_kind` is `MOQ_ANNOUNCE_KIND_PRESENT` (0) or `MOQ_ANNOUNCE_KIND_ABSENT` (1), and `moq_announce_event` loses `predecessor` and `predecessor_len`, changing the C ABI. Another instance taking a path over keeps it present, and a route's cost changing is not reported. Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. + +`moq_origin_follow`'s callback also receives `MOQ_FOLLOW_OFFLINE` (`INT32_MAX`) once the path goes offline, or, for a follow pinned to an instance, once another instance takes it over. It is positive and not terminal, and no handle ever takes that value: check for it before treating a positive code as a broadcast handle. Recompile callers against the regenerated `moq.h`. ### JSON window edits take an optional timestamp diff --git a/rs/moq-ffi/MIGRATE.md b/rs/moq-ffi/MIGRATE.md index 0058c27d3c7..706d6655452 100644 --- a/rs/moq-ffi/MIGRATE.md +++ b/rs/moq-ffi/MIGRATE.md @@ -10,6 +10,8 @@ These are the UniFFI names; each language wrapper has its own `MIGRATE.md` in it `MoqAnnounceEvent` is `Present { announce }` or `Absent { announce }`. `Start`, `Update`, `End`, `Restart` and `Takeover` (with its `predecessor`) are gone: another instance taking a path over keeps it present, and a route's cost changing is not reported. Map `Start` to `Present` and `End` to `Absent`, and drop `Update` handling. Where you requested the path again on `Restart`, hold `MoqOriginConsumer::follow(path)` and await `available()` for each new instance. +`MoqFollowing::available()` returns `Option>`: `None` once the path goes offline (or, for a follow pinned to an `instance`, once another instance takes it over), then the next broadcast when something serves the path again. The first call never returns `None`. Handle `None` as offline: drop what you read from the last broadcast and call `available()` again. + ### `MoqTransport::Iroh` is removed ([#7345](https://github.com/moq-dev/moq/pull/7345)) moq-tokio no longer accepts iroh sessions, so `MoqTransport` loses its `Iroh` variant and the later variants renumber; Go loses `TransportIroh`. diff --git a/swift/MIGRATE.md b/swift/MIGRATE.md index 81c3d85499b..2f0345cf3a4 100644 --- a/swift/MIGRATE.md +++ b/swift/MIGRATE.md @@ -4,6 +4,12 @@ How to update your code for each breaking change, newest first. ## Unreleased +### `Following.available()` returns nil once the path goes offline + +`try await following.available()` returns `BroadcastConsumer?`. +After the first call, it returns nil once the followed path goes offline, or, for a `follow(path:instance:)` pinned to an instance, once another instance takes it over; the next call returns whatever serves the path next. The first call never returns nil. +Drop what you read from the previous broadcast either way. A caller that only waits for the first broadcast can take it with `!`. + ### Announcements are a listing `AnnounceConsumer` yields `.present` when a path becomes present and `.absent` when it goes, each carrying an `Announce`. @@ -14,7 +20,8 @@ Where you requested the path again on a restart, hold `follow(path:)` instead; e ```swift let following = try session.consume.follow(path: "live/camera") while true { - play(try await following.available()) + guard let broadcast = try await following.available() else { continue } // offline until the next instance + play(broadcast) } ``` diff --git a/swift/README.md b/swift/README.md index d5917bf45e3..efc16ed5a47 100644 --- a/swift/README.md +++ b/swift/README.md @@ -36,7 +36,8 @@ let session = try await client.connect(to: "https://relay.example.com") let announced = try session.consume.announced(prefix: "demos/", filter: "*/camera") for try await event in announced { // The listing reports each path once while it stays present, even as its publisher - // restarts; `session.consume.follow(path:)` hands out each new run. + // restarts; `session.consume.follow(path:)` hands out each new run, or nil once it + // goes offline. guard case .present(let announcement) = event else { continue } // Prefix stays origin-relative; captures reports what * matched. print("got broadcast \(announcement.prefix)") diff --git a/swift/Sources/Moq/Origin.swift b/swift/Sources/Moq/Origin.swift index 2c15da5e047..52a62e52d4b 100644 --- a/swift/Sources/Moq/Origin.swift +++ b/swift/Sources/Moq/Origin.swift @@ -210,14 +210,15 @@ public final class Following: Sendable { self.ffi = ffi } - /// Suspend until the next publisher instance serves the path, then resolve it. - /// The first call resolves the instance serving the path once one is announced. - /// Each later call waits for another to take over (a restarted publisher, or a - /// replacement session) or for the broadcast to return after it went offline. + /// Suspend until the publisher instance serving the path changes. + /// The first call resolves the instance serving the path once one is announced, and + /// never returns nil. Each later call returns another instance taking over (a + /// restarted publisher, or a replacement session), or nil once the path goes offline + /// (or, with an `instance`, another one takes it over), then whatever serves it next. /// Drop what was read from the previous instance then: its tracks end when its /// session does. Throws `Closed` if cancelled or the origin closes first. - public func available() async throws -> BroadcastConsumer { - BroadcastConsumer(try await ffi.available()) + public func available() async throws -> BroadcastConsumer? { + (try await ffi.available()).map(BroadcastConsumer.init) } /// Cancel all current and future `available()` calls. diff --git a/swift/Tests/MoqTests/SmokeTests.swift b/swift/Tests/MoqTests/SmokeTests.swift index 822e542d6c5..8b09edbcc8d 100644 --- a/swift/Tests/MoqTests/SmokeTests.swift +++ b/swift/Tests/MoqTests/SmokeTests.swift @@ -294,10 +294,12 @@ final class SmokeTests: XCTestCase { return XCTFail("expected an announcement") } XCTAssertFalse(present.route.instance.isEmpty) - _ = try await following.available() + let first = try await following.available() + XCTAssertNotNil(first) try publication.announce(route: AnnounceRoute(instance: "camera", epoch: 1)) - _ = try await following.available() + let takeover = try await following.available() + XCTAssertNotNil(takeover) // The takeover was not listed, so the next event is the path going absent. try publication.unannounce() @@ -314,6 +316,25 @@ final class SmokeTests: XCTestCase { following.cancel() } + func testFollowerReportsOfflineAndTheNextBroadcast() async throws { + let origin = OriginProducer() + let following = try origin.consume().follow(path: "offline") + let publication = try origin.createBroadcast(path: "offline") + + try publication.announce(route: AnnounceRoute()) + let first = try await following.available() + XCTAssertNotNil(first) + + try publication.unannounce() + let offline = try await following.available() + XCTAssertNil(offline) + + try publication.announce(route: AnnounceRoute()) + let returned = try await following.available() + XCTAssertNotNil(returned) + following.cancel() + } + func testDynamicServesARequestUnderAPrefix() async throws { let origin = OriginProducer() let dynamic = try origin.requests(prefix: "live") diff --git a/test/interop/clients/c/subscribe.c b/test/interop/clients/c/subscribe.c index 09ba203f221..b8328ce4d62 100644 --- a/test/interop/clients/c/subscribe.c +++ b/test/interop/clients/c/subscribe.c @@ -271,6 +271,9 @@ static void start_audio(ctx_t *c, int32_t catalog) { // is all this client reads, so a later instance's handle is freed unread. static void on_broadcast(void *ud, int32_t broadcast) { ctx_t *c = (ctx_t *)ud; + // Going offline is how a finished broadcast withdraws, and the stored handle's + // tracks report their own end, so there is nothing to do here. + if (broadcast == MOQ_FOLLOW_OFFLINE) return; if (broadcast <= 0) { // 0 = ended, negative = error if (c->finish.enabled) { if (broadcast < 0) fprintf(stderr, "finish broadcast error: %d %s\n", broadcast, moq_error()); @@ -398,6 +401,14 @@ static void on_finish_health_frame(void *ud, int32_t frame) { static void on_finish_health(void *ud, int32_t broadcast) { ctx_t *c = ud; + // The session that finished the broadcast must keep serving its health broadcast. + if (broadcast == MOQ_FOLLOW_OFFLINE) { + pthread_mutex_lock(&c->mu); + c->finish.failed = 1; + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); + return; + } if (broadcast <= 0) { if (broadcast < 0) fprintf(stderr, "finish health broadcast error: %d %s\n", broadcast, moq_error()); pthread_mutex_lock(&c->mu); diff --git a/test/interop/clients/cpp/main.cpp b/test/interop/clients/cpp/main.cpp index bb8c8af14d4..a55a309bab2 100644 --- a/test/interop/clients/cpp/main.cpp +++ b/test/interop/clients/cpp/main.cpp @@ -350,6 +350,7 @@ int subscribe( : deadline; auto announced = ok(session->consume()->follow(path, std::nullopt), "follow"); auto consumer = until(announced->available(), read_deadline, "available"); + if (!consumer) fail("first available() reported offline"); // The catalog is a live track. A lazy publisher (e.g. the browser, which only encodes on // demand) may announce a rendition in a later update rather than the first snapshot, so @@ -406,6 +407,7 @@ int subscribe( } auto watch = ok(session->consume()->follow(path + ".health", std::nullopt), "health watch"); auto health = until(watch->available(), read_deadline, "health available"); + if (!health) fail("first health available() reported offline"); auto track = until(health->subscribe_track("live", std::nullopt), read_deadline, "health subscribe"); auto group = until(track->next_group(), read_deadline, "health group"); if (!group) fail("missing health group"); diff --git a/test/interop/clients/python/interop.py b/test/interop/clients/python/interop.py index d395a34fa02..73f8e277324 100644 --- a/test/interop/clients/python/interop.py +++ b/test/interop/clients/python/interop.py @@ -188,6 +188,7 @@ async def _finish_subscribe(client: moq.Client, broadcast: str, frames: int) -> async with client.announced(broadcast) as announcements: async with client.follow(broadcast) as following: consumer = await following + assert consumer is not None async with await moq.media.CatalogConsumer.subscribe(consumer) as catalogs: async for catalog in catalogs: if catalog.video: @@ -229,6 +230,7 @@ async def _finish_subscribe(client: moq.Client, broadcast: str, frames: int) -> async with client.follow(f"{broadcast}.health") as announced_health: health = await announced_health + assert health is not None async with await health.subscribe_track("live") as live: seen = False async for group in live: @@ -305,6 +307,7 @@ async def subscribe( return assert audio_out is not None and audio_ms is not None consumer = await asyncio.wait_for(client.follow(broadcast), timeout) + assert consumer is not None catalog = await asyncio.wait_for(_catalog_with_media(consumer), timeout) id, video = next(iter(catalog.video.items())) From 73bac219bf683925ff59cfb26e3128b42dcf26c5 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 10:28:20 -0800 Subject: [PATCH 09/21] fix(room): keep a participant listed after its follower fails Co-Authored-By: Claude Opus 5.5 --- rs/moq-room/src/room.rs | 43 +++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/rs/moq-room/src/room.rs b/rs/moq-room/src/room.rs index eaa1e4a7cb4..7891f4e59b1 100644 --- a/rs/moq-room/src/room.rs +++ b/rs/moq-room/src/room.rs @@ -35,7 +35,9 @@ struct Participant { identity: Path, kind: Kind, path: Path, - following: origin::Following, + /// `None` once the follower failed, such as a handler refusing the path: the participant + /// stays listed until the listing reports it absent. + following: Option, } /// Runs the announce loop and yields remote participant broadcasts. @@ -108,17 +110,21 @@ impl Room { identity: parsed.identity, kind: parsed.kind, path, - following, + following: Some(following), }); } /// The next broadcast a participant's follower hands out. A follower that fails, such as a - /// handler refusing its path, is dropped until the path is listed again; its end comes - /// from the listing. + /// handler refusing its path, stops until the path is listed again; its end comes from the + /// listing. fn poll_participants(&mut self, waiter: &kio::Waiter) -> Poll { let mut index = 0; while let Some(participant) = self.participants.get_mut(index) { - match participant.following.poll_available(waiter) { + let Some(following) = participant.following.as_mut() else { + index += 1; + continue; + }; + match following.poll_available(waiter) { Poll::Ready(Ok(Some(broadcast))) => { return Poll::Ready(Event { identity: participant.identity.clone(), @@ -128,9 +134,7 @@ impl Room { }); } Poll::Ready(Ok(None)) => continue, - Poll::Ready(Err(_)) => { - self.participants.swap_remove(index); - } + Poll::Ready(Err(_)) => participant.following = None, Poll::Pending => index += 1, } } @@ -180,6 +184,29 @@ mod tests { assert!(gone.broadcast.is_none()); } + /// A participant whose follower fails stays listed, so its absence is still reported. + #[tokio::test(start_paused = true)] + async fn reports_the_absence_of_a_refused_participant() { + let wait = std::time::Duration::from_secs(1); + let origin = origin(); + let mut room = Room::new(&origin.consume(), None); + + let claim = origin.requests("bob/camera").expect("claim"); + let (request, nothing) = tokio::join!(claim.requested_broadcast(), kio::clock::timeout(wait, room.next())); + assert!(nothing.is_err(), "nothing serves bob yet"); + request.expect("requested").reject(moq_net::Error::NotFound); + // The refusal fails bob's follower, which yields nothing. + assert!(kio::clock::timeout(wait, room.next()).await.is_err()); + + drop(claim); + let gone = kio::clock::timeout(wait, room.next()) + .await + .expect("the absence was never reported") + .expect("bob unannounce"); + assert_eq!(gone.identity.as_str(), "bob"); + assert!(gone.broadcast.is_none()); + } + #[tokio::test] async fn yields_screen() { let origin = origin(); From 92ec3cf0015f6d31375e8deb257e1dcdf0ad18ce Mon Sep 17 00:00:00 2001 From: "pullfrog[bot]" <226033991+pullfrog[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 19:03:38 +0000 Subject: [PATCH 10/21] fix(test): wait for the present announcement in max-age --- test/max-age/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/max-age/client.ts b/test/max-age/client.ts index 64b10455b86..23d75a71015 100644 --- a/test/max-age/client.ts +++ b/test/max-age/client.ts @@ -39,7 +39,7 @@ try { for (;;) { const event = await announcements.next(); assert(event, "announcements closed"); - if (event.kind === "start" && event.prefix === "age") break; + if (event.kind === "present" && event.prefix === "age") break; } const request = origin.consume().request(Path.from("age")); let broadcast = request.active.peek(); From 201c8a688f2e6f880c8a43b10c12bb195e100a52 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 12:01:41 -0800 Subject: [PATCH 11/21] feat(c)!: moq_origin_follow reports an explicit follow event Co-Authored-By: Claude Opus 5.5 --- c/moq/MIGRATE.md | 2 +- doc/concept/identity.md | 2 +- doc/lib/c/index.md | 4 +- rs/moq-c/MIGRATE.md | 2 +- rs/moq-c/README.md | 2 +- rs/moq-c/src/api.rs | 62 +++++++++++++++----------- rs/moq-c/src/ffi.rs | 59 +++++++++++++++++++++++++ rs/moq-c/src/id.rs | 24 +++++----- rs/moq-c/src/lib.rs | 2 +- rs/moq-c/src/origin.rs | 34 +++++++++------ rs/moq-c/src/task.rs | 18 ++++++-- rs/moq-c/src/test.rs | 70 ++++++++++++++++++++++++------ test/interop/clients/c/subscribe.c | 16 +++---- 13 files changed, 212 insertions(+), 85 deletions(-) diff --git a/c/moq/MIGRATE.md b/c/moq/MIGRATE.md index 92f4dadf9ce..933ec56c616 100644 --- a/c/moq/MIGRATE.md +++ b/c/moq/MIGRATE.md @@ -12,7 +12,7 @@ The hand-written crate never published as moq-c: a libmoq 0.6 user applies these Another instance taking a path over keeps it present, and a route's cost changing is not reported. Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. -`moq_origin_follow`'s callback also receives `MOQ_FOLLOW_OFFLINE` (`INT32_MAX`) once the path goes offline, or, for a follow pinned to an instance, once another instance takes it over. It is positive and not terminal, and no handle ever takes that value: check for it before treating a positive code as a broadcast handle. +`moq_origin_follow` takes a `moq_follow_callback`, `(void *user_data, moq_follow_event event, int32_t code)`, instead of a `moq_status_callback`. `MOQ_FOLLOW_EVENT_ONLINE` carries each broadcast handle (where a positive code did), `MOQ_FOLLOW_EVENT_OFFLINE` reports the path going offline (or, for a follow pinned to an instance, another instance taking it over) with code `0`, and `MOQ_FOLLOW_EVENT_END` is the terminal callback, with `0` or a negative error that `moq_error()` explains (where a code `<= 0` was). Release `user_data` on `MOQ_FOLLOW_EVENT_END`. ### Announcement captures are required ([#7484](https://github.com/moq-dev/moq/pull/7484)) diff --git a/doc/concept/identity.md b/doc/concept/identity.md index 71cfbaf2b1d..9ff4f2e8d04 100644 --- a/doc/concept/identity.md +++ b/doc/concept/identity.md @@ -128,7 +128,7 @@ next one arrives, and wait while the path is offline. Rust uses 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 receives `MOQ_FOLLOW_OFFLINE`. +callback reports `MOQ_FOLLOW_EVENT_OFFLINE`. An announcement listing (`announced()`) only reports a path becoming present or absent: 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 diff --git a/doc/lib/c/index.md b/doc/lib/c/index.md index 18c6b93b164..e5c486b7a47 100644 --- a/doc/lib/c/index.md +++ b/doc/lib/c/index.md @@ -84,8 +84,8 @@ A route carries only a cost and the stream's instance; relays add the hops. Each publication mints a fresh instance and keeps it across re-announcing, so a restarted publisher is a new stream that `moq_origin_follow` hands viewers instead of a stalled broadcast; the path stays `MOQ_ANNOUNCE_KIND_PRESENT` throughout. The follow callback -receives `MOQ_FOLLOW_OFFLINE` once the path goes offline, which is positive but never a -handle. Set `instance` only for a publisher that continues its group sequences +reports each instance as `MOQ_FOLLOW_EVENT_ONLINE` with its handle, +`MOQ_FOLLOW_EVENT_OFFLINE` when the path goes offline, and one `MOQ_FOLLOW_EVENT_END`. Set `instance` only for a publisher that continues its group sequences across restarts, and raise `epoch` on each: readers stitch every route of one instance together, so restarting the sequences under an old instance splices unrelated groups into their tracks. diff --git a/rs/moq-c/MIGRATE.md b/rs/moq-c/MIGRATE.md index 34fabfc1471..8f8e07d3016 100644 --- a/rs/moq-c/MIGRATE.md +++ b/rs/moq-c/MIGRATE.md @@ -10,7 +10,7 @@ How to update your code for each breaking change, newest first. Another instance taking a path over keeps it present, and a route's cost changing is not reported. Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. -`moq_origin_follow`'s callback also receives `MOQ_FOLLOW_OFFLINE` (`INT32_MAX`) once the path goes offline, or, for a follow pinned to an instance, once another instance takes it over. It is positive and not terminal, and no handle ever takes that value: check for it before treating a positive code as a broadcast handle. +`moq_origin_follow` takes a `moq_follow_callback`, `(void *user_data, moq_follow_event event, int32_t code)`, instead of a `moq_status_callback`. `MOQ_FOLLOW_EVENT_ONLINE` carries each broadcast handle (where a positive code did), `MOQ_FOLLOW_EVENT_OFFLINE` reports the path going offline (or, for a follow pinned to an instance, another instance taking it over) with code `0`, and `MOQ_FOLLOW_EVENT_END` is the terminal callback, with `0` or a negative error that `moq_error()` explains (where a code `<= 0` was). Release `user_data` on `MOQ_FOLLOW_EVENT_END`. Recompile callers against the regenerated `moq.h`. ### JSON window edits take an optional timestamp diff --git a/rs/moq-c/README.md b/rs/moq-c/README.md index 16835118d7e..0cb742e5f28 100644 --- a/rs/moq-c/README.md +++ b/rs/moq-c/README.md @@ -57,7 +57,7 @@ int32_t moq_origin_close(uint32_t origin); int32_t moq_origin_create_broadcast(uint32_t origin, const char *path, uintptr_t path_len, uint32_t *broadcast); int32_t moq_origin_request(uint32_t origin, const char *path, uintptr_t path_len, const char *instance, uintptr_t instance_len, moq_status_callback on_broadcast, void *user_data); int32_t moq_origin_request_cancel(uint32_t task); -int32_t moq_origin_follow(uint32_t origin, const char *path, uintptr_t path_len, const char *instance, uintptr_t instance_len, moq_status_callback on_broadcast, void *user_data); +int32_t moq_origin_follow(uint32_t origin, const char *path, uintptr_t path_len, const char *instance, uintptr_t instance_len, moq_follow_callback on_follow, void *user_data); int32_t moq_origin_follow_cancel(uint32_t task); int32_t moq_origin_announced(uint32_t origin, const moq_announce_config *config, moq_status_callback on_announce, void *user_data); int32_t moq_origin_announced_info(uint32_t announced, moq_announce_event *dst); diff --git a/rs/moq-c/src/api.rs b/rs/moq-c/src/api.rs index 792f52ce739..a52632b4475 100644 --- a/rs/moq-c/src/api.rs +++ b/rs/moq-c/src/api.rs @@ -2258,15 +2258,25 @@ pub extern "C" fn moq_origin_announced_cancel(announced: u32) -> i32 { }) } -/// What a [moq_origin_follow] callback receives once the path goes offline, or, for a pinned -/// follow, once another instance takes it over. Positive, so not terminal; no handle ever -/// takes this value. -pub const MOQ_FOLLOW_OFFLINE: i32 = i32::MAX; +/// What a [moq_origin_follow] callback reports. +#[repr(C)] +#[expect(non_camel_case_types, reason = "C ABI type names match moq.h")] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum moq_follow_event { + /// An instance now serves the path. `code` is its broadcast handle. + MOQ_FOLLOW_EVENT_ONLINE = 0, + /// The path went offline, or, for a pinned follow, another instance took it over. `code` + /// is `0`. + MOQ_FOLLOW_EVENT_OFFLINE = 1, + /// The follow ended. `code` is `0` (after [moq_origin_follow_cancel], or the origin closing + /// once a handle was delivered) or a negative error. + MOQ_FOLLOW_EVENT_END = 2, +} /// Follow a broadcast on an origin by path, delivering each publisher instance that serves it. /// /// Resolves against future announcements: it waits for the announcement to arrive (e.g. over the -/// network) and then delivers the broadcast handle via `on_broadcast`. Use it right after +/// network) and then delivers the broadcast handle via `on_follow`. Use it right after /// [moq_session_connect] to avoid racing announcement gossip. To resolve one publisher instance /// instead, use [moq_origin_request]. A broadcast created on this origin resolves once it is /// announced, like a remote one. @@ -2275,23 +2285,23 @@ pub const MOQ_FOLLOW_OFFLINE: i32 = i32::MAX; /// the path. A pinned follow never delivers another instance taking over: that ends it, and its /// own instance is delivered again when it returns. /// -/// `on_broadcast` is invoked with a positive broadcast handle once announced, and again with a -/// new handle each time another publisher instance takes over (a restarted publisher, or a -/// replacement session) or the broadcast returns after it went offline. It is invoked with -/// [MOQ_FOLLOW_OFFLINE] once the path goes offline, before whatever serves it next. Drop what -/// was read from the previous handle on either: its tracks end when its session does. The wait ends with -/// exactly one terminal code: `0` (after [moq_origin_follow_cancel], or the origin closing -/// once a handle was delivered) or a negative error. After the terminal (`<= 0`) callback, -/// `on_broadcast` is never called again and `user_data` is never touched again, so release -/// `user_data` there. The broadcast handle is usable with [moq_consume_catalog] / [moq_consume_track] -/// and must be freed separately with [moq_consume_close]. +/// `on_follow` receives a [moq_follow_event] and a code. `MOQ_FOLLOW_EVENT_ONLINE` carries a +/// broadcast handle once announced, and again a new one each time another publisher instance +/// takes over (a restarted publisher, or a replacement session) or the broadcast returns. +/// `MOQ_FOLLOW_EVENT_OFFLINE` reports the path going offline, before whatever serves it next. +/// Drop what was read from the previous handle on either: its tracks end when its session does. +/// The follow ends with exactly one `MOQ_FOLLOW_EVENT_END`, whose code is `0` or a negative +/// error that [moq_error] explains inside the callback. After it, `on_follow` is never called +/// again and `user_data` is never touched again, so release `user_data` there. Each broadcast +/// handle is usable with [moq_consume_catalog] / [moq_consume_track] and must be freed separately +/// with [moq_consume_close]. /// -/// Returns a non-zero handle to the wait on success, or a negative code on (immediate) failure. +/// Returns a non-zero handle to the follow on success, or a negative code on (immediate) failure. /// /// # Safety /// - The caller must ensure that path is a valid pointer to path_len bytes of data. /// - `instance` may be NULL, or must point at `instance_len` readable bytes. -/// - The caller must keep `user_data` valid until the terminal (`<= 0`) `on_broadcast` callback. +/// - The caller must keep `user_data` valid until the `MOQ_FOLLOW_EVENT_END` callback. #[unsafe(no_mangle)] pub unsafe extern "C" fn moq_origin_follow( origin: u32, @@ -2299,30 +2309,30 @@ pub unsafe extern "C" fn moq_origin_follow( path_len: usize, instance: *const c_char, instance_len: usize, - on_broadcast: ffi::moq_status_callback, + on_follow: ffi::moq_follow_callback, user_data: *mut c_void, ) -> i32 { ffi::enter(move || { let origin = ffi::parse_id(origin)?; let path = unsafe { ffi::parse_str(path, path_len)? }.to_string(); let instance = unsafe { parse_instance(instance, instance_len)? }; - let on_broadcast = unsafe { ffi::OnStatus::new(user_data, on_broadcast)? }; - State::lock().origin.follow(origin, path, instance, on_broadcast) + let on_follow = unsafe { ffi::OnFollow::new(user_data, on_follow)? }; + State::lock().origin.follow(origin, path, instance, on_follow) }) } -/// Abort a wait started by [moq_origin_follow]. +/// Stop a follow started by [moq_origin_follow]. /// /// Returns immediately: zero on success, or a negative code if already closed. Does NOT free -/// `user_data`. The [moq_origin_follow] `on_broadcast` callback still fires once more -/// with a terminal `0` (or a negative error), and that final callback is where `user_data` should -/// be released. Any broadcast handle already delivered is unaffected and must still be freed with -/// [moq_consume_close]. +/// `user_data`. The [moq_origin_follow] `on_follow` callback still fires once more with +/// `MOQ_FOLLOW_EVENT_END` (code `0`, or a negative error), and that final callback is where +/// `user_data` should be released. Any broadcast handle already delivered is unaffected and must +/// still be freed with [moq_consume_close]. #[unsafe(no_mangle)] pub extern "C" fn moq_origin_follow_cancel(task: u32) -> i32 { ffi::enter(move || { let task = ffi::parse_id(task)?; - State::lock().origin.resolve_close(task) + State::lock().origin.follow_close(task) }) } diff --git a/rs/moq-c/src/ffi.rs b/rs/moq-c/src/ffi.rs index be21fc414ee..6113bd55265 100644 --- a/rs/moq-c/src/ffi.rs +++ b/rs/moq-c/src/ffi.rs @@ -20,6 +20,13 @@ pub type moq_status_callback = Option; +/// Callback for [crate::moq_origin_follow]: each [crate::moq_follow_event] and its code. +/// +/// `code` is the broadcast handle for `MOQ_FOLLOW_EVENT_ONLINE`, `0` for +/// `MOQ_FOLLOW_EVENT_OFFLINE`, and the terminal status for `MOQ_FOLLOW_EVENT_END`: `0`, or a +/// negative error whose reason [crate::moq_error] reports inside the callback. +pub type moq_follow_callback = Option; + pub static RUNTIME: LazyLock = LazyLock::new(|| { let runtime = tokio::runtime::Builder::new_current_thread() .enable_all() @@ -270,6 +277,58 @@ impl OnState { // safe to use on moq-c's runtime thread until the terminal callback. unsafe impl Send for OnState {} +/// A [moq_follow_callback] and its user data. +#[derive(Clone, Copy)] +pub struct OnFollow { + user_data: *mut c_void, + on_follow: extern "C" fn(user_data: *mut c_void, event: crate::moq_follow_event, code: i32), +} + +impl OnFollow { + /// Wrap a C follow callback. + /// + /// # Safety + /// - The caller must keep `user_data` valid until the `MOQ_FOLLOW_EVENT_END` callback. + /// - The callback and `user_data` must be safe to use on moq-c's runtime thread. + pub unsafe fn new(user_data: *mut c_void, on_follow: moq_follow_callback) -> Result { + Ok(Self { + user_data, + on_follow: on_follow.ok_or(Error::InvalidPointer)?, + }) + } + + /// Deliver a broadcast handle for an instance now serving the path. + pub fn online(&self, broadcast: crate::Id) { + (self.on_follow)( + self.user_data, + crate::moq_follow_event::MOQ_FOLLOW_EVENT_ONLINE, + i32::from(broadcast), + ); + } + + /// Report that the path went offline. + pub fn offline(&self) { + (self.on_follow)(self.user_data, crate::moq_follow_event::MOQ_FOLLOW_EVENT_OFFLINE, 0); + } +} + +impl crate::task::Terminal for OnFollow { + /// Deliver the terminal status, recording its failure first so the callback can read + /// `moq_error()`. + fn terminal(&self, res: Result<(), Error>) { + record_error(&res); + (self.on_follow)( + self.user_data, + crate::moq_follow_event::MOQ_FOLLOW_EVENT_END, + res.code(), + ); + } +} + +// SAFETY: The constructor requires the callback and user_data to remain valid and +// safe to use on moq-c's runtime thread until the terminal callback. +unsafe impl Send for OnFollow {} + /// Types that can be converted to C-compatible return codes. pub trait ReturnCode { /// Convert to an i32 status code. diff --git a/rs/moq-c/src/id.rs b/rs/moq-c/src/id.rs index 986526bee34..30210f988b5 100644 --- a/rs/moq-c/src/id.rs +++ b/rs/moq-c/src/id.rs @@ -19,11 +19,7 @@ impl std::fmt::Display for Id { } } -/// The highest ID issued. `i32::MAX` stays free for [`crate::MOQ_FOLLOW_OFFLINE`], so a -/// follow callback can tell it from a broadcast handle. -const MAX_ID: u32 = crate::MOQ_FOLLOW_OFFLINE as u32 - 1; - -/// Process-wide counter wrapping from [`MAX_ID`] back to 1. +/// Process-wide counter wrapping from i32::MAX back to 1. static NEXT_ID: AtomicU32 = AtomicU32::new(1); /// Map that assigns IDs from a process-wide counter, skipping live entries. @@ -40,14 +36,14 @@ impl NonZeroSlab { } fn insert_next(&mut self, value: T, next: &AtomicU32) -> Result { - if self.map.len() == MAX_ID as usize { + if self.map.len() == i32::MAX as usize { return Err(Error::InvalidId); } loop { let raw = next .fetch_update(Ordering::Relaxed, Ordering::Relaxed, |id| { - Some(if id >= MAX_ID { 1 } else { id + 1 }) + Some(if id == i32::MAX as u32 { 1 } else { id + 1 }) }) .unwrap(); let id = Id::try_from(raw)?; @@ -113,11 +109,11 @@ mod tests { use super::*; #[test] - fn wrap_uses_the_positive_i32_range_below_the_offline_code() { - let next = AtomicU32::new(MAX_ID); + fn wrap_uses_the_whole_positive_i32_range() { + let next = AtomicU32::new(i32::MAX as u32); let mut slab = NonZeroSlab::default(); let high = slab.insert_next((), &next).unwrap(); - assert_eq!(i32::from(high), i32::MAX - 1); + assert_eq!(i32::from(high), i32::MAX); let low = slab.insert_next((), &next).unwrap(); assert_eq!(i32::from(low), 1); assert_eq!(slab.remove(high), Some(())); @@ -126,15 +122,15 @@ mod tests { #[test] fn wrap_skips_live_handles_and_preserves_their_values() { - let next = AtomicU32::new(MAX_ID - 1); + let next = AtomicU32::new(i32::MAX as u32 - 1); let mut slab = NonZeroSlab::default(); let low = Id::try_from(1u32).unwrap(); - let high = Id::try_from(MAX_ID).unwrap(); + let high = Id::try_from(i32::MAX).unwrap(); slab.map.insert(low, "low"); slab.map.insert(high, "high"); let before = slab.insert_next("before wrap", &next).unwrap(); - assert_eq!(i32::from(before), i32::MAX - 2); + assert_eq!(i32::from(before), i32::MAX - 1); let after = slab.insert_next("after wrap", &next).unwrap(); assert_eq!(i32::from(after), 2); assert_eq!(slab.get(low), Some(&"low")); @@ -164,7 +160,7 @@ mod tests { let start = kio::clock::Instant::now(); for _ in 0..iterations { if wrap { - next.store(MAX_ID, Ordering::Relaxed); + next.store(i32::MAX as u32, Ordering::Relaxed); let high = slab.insert_next(black_box(42), &next).unwrap(); black_box(slab.remove(high).unwrap()); } diff --git a/rs/moq-c/src/lib.rs b/rs/moq-c/src/lib.rs index 74c2fba2d66..dee7f08661b 100644 --- a/rs/moq-c/src/lib.rs +++ b/rs/moq-c/src/lib.rs @@ -40,7 +40,7 @@ pub use audio::*; pub use bandwidth::*; pub use decode::{moq_decode_gap, moq_decode_read_kind, moq_decode_start}; pub use error::*; -pub use ffi::{moq_state_callback, moq_status_callback}; +pub use ffi::{moq_follow_callback, moq_state_callback, moq_status_callback}; pub use id::*; pub use video::*; diff --git a/rs/moq-c/src/origin.rs b/rs/moq-c/src/origin.rs index 5fd44cd7f82..b1eb57a1e4e 100644 --- a/rs/moq-c/src/origin.rs +++ b/rs/moq-c/src/origin.rs @@ -1,7 +1,7 @@ use std::ffi::c_char; use tokio::sync::oneshot; -use crate::ffi::OnStatus; +use crate::ffi::{OnFollow, OnStatus}; use crate::task::Task; use crate::{Error, Id, NonZeroSlab, State, moq_announce_event, moq_announce_kind, moq_route, moq_string}; @@ -22,9 +22,12 @@ pub struct Origin { /// Announcement listener tasks. Close signals shutdown; the task delivers a final callback, then removes itself. announced_task: NonZeroSlab, - /// Pending consume-until-announced tasks. Close signals shutdown; the task delivers a final callback, then removes itself. + /// Pending requests. Close signals shutdown; the task delivers a final callback, then removes itself. consume_task: NonZeroSlab, + /// Follows. Close signals shutdown; the task delivers its end event, then removes itself. + follow_task: NonZeroSlab>, + /// Served routes from [Self::dynamic], retracted when the handle is closed. dynamic: NonZeroSlab, @@ -230,34 +233,37 @@ impl Origin { /// Follow the broadcast at `path`, delivering each publisher instance's handle via the callback. /// - /// The callback fires a broadcast handle (> 0) for each instance serving the path, and - /// [`crate::MOQ_FOLLOW_OFFLINE`] once it goes offline, until a single terminal code (`0` on - /// close, negative on error). Returns a task handle for - /// cancellation via [`Self::resolve_close`]. + /// The callback reports each instance serving the path as online with its broadcast handle, + /// the path going offline, and one end with `0` on close or a negative error. Returns a task + /// handle for cancellation via [`Self::follow_close`]. pub fn follow( &mut self, origin: Id, path: String, instance: Option, - on_broadcast: OnStatus, + on_follow: OnFollow, ) -> Result { let origin = self.active.get(origin).ok_or(Error::OriginNotFound)?; origin.driver.check()?; let driver = origin.driver.clone(); let consumer = origin.consume_owned(); - self.consume_task.spawn( - on_broadcast, - |state| &mut state.origin.consume_task, + self.follow_task.spawn( + on_follow, + |state| &mut state.origin.follow_task, |close| async move { driver - .watch(Self::run_follow(on_broadcast, consumer, path, instance, close)) + .watch(Self::run_follow(on_follow, consumer, path, instance, close)) .await }, ) } + pub fn follow_close(&mut self, task: Id) -> Result<(), Error> { + self.follow_task.close(task, Error::NotFound) + } + async fn run_follow( - callback: OnStatus, + callback: OnFollow, consumer: Consumer, path: String, instance: Option, @@ -280,7 +286,7 @@ impl Origin { available = announced.available() => match available { Ok(Some(broadcast)) => broadcast, Ok(None) => { - callback.call(crate::MOQ_FOLLOW_OFFLINE); + callback.offline(); continue; } // The origin closing ends the wait, cleanly once a handle was delivered. @@ -293,7 +299,7 @@ impl Origin { // Hold the lock only to buffer the broadcast; release it before the callback. let broadcast_id = State::lock().consume.start(broadcast, Some(consumer.clone()))?; delivered = true; - callback.call(broadcast_id); + callback.online(broadcast_id); } } diff --git a/rs/moq-c/src/task.rs b/rs/moq-c/src/task.rs index 58fde665388..7a0e41c0dc9 100644 --- a/rs/moq-c/src/task.rs +++ b/rs/moq-c/src/task.rs @@ -32,13 +32,25 @@ impl Task { } } -impl NonZeroSlab { +/// A task's callback, which receives the task's result once it ends. +pub(crate) trait Terminal: Copy + Send + 'static { + /// Deliver the terminal result. + fn terminal(&self, res: Result<(), Error>); +} + +impl Terminal for OnStatus { + fn terminal(&self, res: Result<(), Error>) { + self.call(res); + } +} + +impl NonZeroSlab> { /// Spawn `run` with its close receiver, then deliver its result as the terminal callback. /// /// `slab` finds this slab again from the task, so it can remove its own entry. pub fn spawn( &mut self, - callback: OnStatus, + callback: C, slab: fn(&mut State) -> &mut Self, run: impl FnOnce(oneshot::Receiver<()>) -> F, ) -> Result @@ -55,7 +67,7 @@ impl NonZeroSlab { // Pull the entry out from under the lock so the callback never runs while held. let entry = slab(&mut State::lock()).remove(id); if let Some(entry) = entry { - entry.callback.call(res); + entry.callback.terminal(res); } }); diff --git a/rs/moq-c/src/test.rs b/rs/moq-c/src/test.rs index 631d72aaff1..ba00c27dc49 100644 --- a/rs/moq-c/src/test.rs +++ b/rs/moq-c/src/test.rs @@ -240,6 +240,34 @@ extern "C" fn channel_callback(user_data: *mut c_void, code: i32) { let _ = tx.send(code); } +/// What [follow_channel_callback] forwards for `MOQ_FOLLOW_EVENT_OFFLINE`, so follow tests read +/// one channel of codes: a handle, this, or a terminal code. Test-only: the ABI reports +/// offline as its own event. +const FOLLOW_OFFLINE: i32 = i32::MAX; + +/// The code a follow event forwards as, checking that each event carries what it promises. +fn follow_code(event: moq_follow_event, code: i32) -> i32 { + match event { + moq_follow_event::MOQ_FOLLOW_EVENT_ONLINE => { + assert!(code > 0, "online carries a handle, got {code}"); + code + } + moq_follow_event::MOQ_FOLLOW_EVENT_OFFLINE => { + assert_eq!(code, 0, "offline carries no code"); + FOLLOW_OFFLINE + } + moq_follow_event::MOQ_FOLLOW_EVENT_END => { + assert!(code <= 0, "end carries a terminal code, got {code}"); + code + } + } +} + +/// [channel_callback] for [moq_origin_follow], forwarding through [follow_code]. +extern "C" fn follow_channel_callback(user_data: *mut c_void, event: moq_follow_event, code: i32) { + channel_callback(user_data, follow_code(event, code)); +} + /// FFI callback for tests that only inspect the registrar's immediate return code. extern "C" fn ignore_callback(_user_data: *mut c_void, _code: i32) {} @@ -3692,7 +3720,7 @@ fn announce_under_a_new_instance_restarts() { path.len(), std::ptr::null(), 0, - Some(channel_callback), + Some(follow_channel_callback), follow_cb.ptr, ) }); @@ -4615,7 +4643,7 @@ fn follow_local() { path.len(), std::ptr::null(), 0, - Some(channel_callback), + Some(follow_channel_callback), cb.ptr, ) }); @@ -4778,7 +4806,7 @@ fn follow_close_cancels() { path.len(), std::ptr::null(), 0, - Some(channel_callback), + Some(follow_channel_callback), cb.ptr, ) }); @@ -4815,7 +4843,7 @@ fn follow_delivers_a_restart() { path.len(), std::ptr::null(), 0, - Some(channel_callback), + Some(follow_channel_callback), cb.ptr, ) }); @@ -4854,7 +4882,7 @@ fn follow_delivers_a_takeover_once(dynamic_at: &str) { path.len(), std::ptr::null(), 0, - Some(channel_callback), + Some(follow_channel_callback), cb.ptr, ) }); @@ -4887,7 +4915,7 @@ fn follow_delivers_a_held_takeover_once() { follow_delivers_a_takeover_once("live"); } -/// `moq_origin_request` and `moq_origin_follow` share one signature. +/// The signature of `moq_origin_request`. type Resolve = unsafe extern "C" fn( u32, *const c_char, @@ -4944,11 +4972,22 @@ fn an_instance_pins_request_and_follow() { // follower delivers it while it still serves, and nothing for the winner. let second = publish_run(origin, "live"); let cb = Callback::new(); - let task = id(resolve_pinned(moq_origin_follow, origin, &instance, &cb)); + let path = b"live"; + let task = id(unsafe { + moq_origin_follow( + origin, + path.as_ptr() as *const c_char, + path.len(), + instance.as_ptr() as *const c_char, + instance.len(), + Some(follow_channel_callback), + cb.ptr, + ) + }); let delivered = id(cb.recv()); let tx = unsafe { &*(cb.ptr as *const mpsc::Sender) }.clone(); - crate::ffi::RUNTIME.spawn(async move { tx.send(i32::MAX).unwrap() }); - assert_eq!(cb.recv(), i32::MAX, "the follower delivered another instance"); + crate::ffi::RUNTIME.spawn(async move { tx.send(i32::MAX - 1).unwrap() }); + assert_eq!(cb.recv(), i32::MAX - 1, "the follower delivered another instance"); assert_eq!(moq_consume_close(delivered), 0); assert_eq!(moq_origin_follow_cancel(task), 0); assert_eq!(cb.recv_terminal(), 0, "cancel delivers terminal 0"); @@ -4972,7 +5011,7 @@ fn follow(origin: u32, path: &[u8], cb: &Callback) -> u32 { path.len(), std::ptr::null(), 0, - Some(channel_callback), + Some(follow_channel_callback), cb.ptr, ) }) @@ -4985,6 +5024,11 @@ struct Gate { hold: std::sync::Mutex>>, } +/// [gated_callback] for [moq_origin_follow], forwarding through [follow_code]. +extern "C" fn gated_follow_callback(user_data: *mut c_void, event: moq_follow_event, code: i32) { + gated_callback(user_data, follow_code(event, code)); +} + extern "C" fn gated_callback(user_data: *mut c_void, code: i32) { let gate = unsafe { &*(user_data as *const Gate) }; // The receiver may free gate as soon as it receives the terminal code. @@ -5016,7 +5060,7 @@ fn follow_delivers_the_instance_again_after_an_end() { path.len(), std::ptr::null(), 0, - Some(gated_callback), + Some(gated_follow_callback), &*gate as *const Gate as *mut c_void, ) }); @@ -5034,7 +5078,7 @@ fn follow_delivers_the_instance_again_after_an_end() { run.announce(route.clone()).unwrap(); } release.send(()).unwrap(); - assert_eq!(recv(), MOQ_FOLLOW_OFFLINE, "the gap is reported before the return"); + assert_eq!(recv(), FOLLOW_OFFLINE, "the gap is reported before the return"); let again = id(recv()); assert_eq!(moq_consume_close(first), 0); @@ -7362,7 +7406,7 @@ fn server_accepts_a_session() { path.len(), std::ptr::null(), 0, - Some(channel_callback), + Some(follow_channel_callback), announced_cb.ptr, ) }); diff --git a/test/interop/clients/c/subscribe.c b/test/interop/clients/c/subscribe.c index b8328ce4d62..211d17fd457 100644 --- a/test/interop/clients/c/subscribe.c +++ b/test/interop/clients/c/subscribe.c @@ -267,14 +267,14 @@ static void start_audio(ctx_t *c, int32_t catalog) { } // Delivers a broadcast handle for each publisher instance serving the path, then -// a terminal code (<= 0). Store the first positive handle and wake main; one frame -// is all this client reads, so a later instance's handle is freed unread. -static void on_broadcast(void *ud, int32_t broadcast) { +// the follow's end. Store the first handle and wake main; one frame is all this +// client reads, so a later instance's handle is freed unread. +static void on_broadcast(void *ud, moq_follow_event event, int32_t broadcast) { ctx_t *c = (ctx_t *)ud; // Going offline is how a finished broadcast withdraws, and the stored handle's // tracks report their own end, so there is nothing to do here. - if (broadcast == MOQ_FOLLOW_OFFLINE) return; - if (broadcast <= 0) { // 0 = ended, negative = error + if (event == MOQ_FOLLOW_EVENT_OFFLINE) return; + if (event == MOQ_FOLLOW_EVENT_END) { // 0 = ended, negative = error if (c->finish.enabled) { if (broadcast < 0) fprintf(stderr, "finish broadcast error: %d %s\n", broadcast, moq_error()); pthread_mutex_lock(&c->mu); @@ -399,17 +399,17 @@ static void on_finish_health_frame(void *ud, int32_t frame) { moq_consume_track_frame_free((uint32_t)frame); } -static void on_finish_health(void *ud, int32_t broadcast) { +static void on_finish_health(void *ud, moq_follow_event event, int32_t broadcast) { ctx_t *c = ud; // The session that finished the broadcast must keep serving its health broadcast. - if (broadcast == MOQ_FOLLOW_OFFLINE) { + if (event == MOQ_FOLLOW_EVENT_OFFLINE) { pthread_mutex_lock(&c->mu); c->finish.failed = 1; pthread_cond_broadcast(&c->cv); pthread_mutex_unlock(&c->mu); return; } - if (broadcast <= 0) { + if (event == MOQ_FOLLOW_EVENT_END) { if (broadcast < 0) fprintf(stderr, "finish health broadcast error: %d %s\n", broadcast, moq_error()); pthread_mutex_lock(&c->mu); c->finish.failed = 1; From 6f3ad66a146371bf7c7547846702138005dacc29 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 12:11:45 -0800 Subject: [PATCH 12/21] chore(c): allow the C name on moq_follow_callback Co-Authored-By: Claude Opus 5.5 --- rs/moq-c/src/ffi.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rs/moq-c/src/ffi.rs b/rs/moq-c/src/ffi.rs index 6113bd55265..ca0a3d78553 100644 --- a/rs/moq-c/src/ffi.rs +++ b/rs/moq-c/src/ffi.rs @@ -25,6 +25,9 @@ pub type moq_state_callback = Option; pub static RUNTIME: LazyLock = LazyLock::new(|| { From 0d3e373de4194c39efafabfff457ad41faecdc76 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 12:30:53 -0800 Subject: [PATCH 13/21] fix(cli): fail the archive export when a listed path is refused Co-Authored-By: Claude Opus 5.5 --- rs/moq-cli/src/archive.rs | 55 ++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/rs/moq-cli/src/archive.rs b/rs/moq-cli/src/archive.rs index 217f5e66192..02f619c28ae 100644 --- a/rs/moq-cli/src/archive.rs +++ b/rs/moq-cli/src/archive.rs @@ -101,7 +101,15 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp } continue; } - Some(_) = following.join_next() => continue, + Some(followed) = following.join_next() => { + match followed { + Ok(result) => result?, + // Aborted once its path went absent. + Err(err) if err.is_cancelled() => {} + Err(err) => return Err(err).context("follower panicked"), + } + continue; + } Some(instance) = instances.recv() => { if !running.start(&instance) { continue; @@ -128,20 +136,27 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp /// Report each instance serving `path` as it comes online or takes over. An instance comes /// again after the path went offline, since a return is announced anew. +/// +/// Fails when the path cannot be followed or a handler refuses it, as a recording would. async fn follow( origin: moq_net::origin::Consumer, path: moq_net::Path, served: tokio::sync::mpsc::UnboundedSender, -) { - let Ok(mut following) = origin.follow(&path, None) else { - return; - }; - while let Ok(change) = following.available().await { +) -> anyhow::Result<()> { + let unavailable = || format!("broadcast `{path}` is unavailable"); + let mut following = origin.follow(&path, None).with_context(unavailable)?; + loop { + let change = match following.available().await { + Ok(change) => change, + // The origin closed, which ends the export through its announcements. + Err(moq_net::Error::Closed) => return Ok(()), + Err(err) => return Err(err).with_context(unavailable), + }; let Some(instance) = change.and_then(|broadcast| broadcast.info().instance.clone()) else { continue; }; if served.send((path.clone(), instance)).is_err() { - return; + return Ok(()); } } } @@ -435,6 +450,32 @@ mod tests { assert!(!files.iter().any(|file| file.starts_with("other")), "{files:?}"); } + /// A handler refusing a listed path fails the export, as a refused recording did. + #[tokio::test] + async fn a_refused_path_fails_the_export() { + let dir = tempfile::tempdir().unwrap(); + let args = ExportArgs { + store: Url::from_directory_path(dir.path()).unwrap(), + retention: None, + retention_grace: None, + }; + let origin = moq_tokio::origin::spawn(); + let claim = origin.requests("live/a").unwrap(); + let recording = tokio::spawn(export(origin.consume(), "live".into(), args)); + + let request = kio::clock::timeout(Duration::from_secs(10), claim.requested_broadcast()) + .await + .expect("the export follows the listed path") + .unwrap(); + request.reject(moq_net::Error::NotFound); + let result = kio::clock::timeout(Duration::from_secs(10), recording) + .await + .expect("the export ends") + .unwrap(); + let err = result.expect_err("a refused path fails the export"); + assert!(err.to_string().contains("live/a"), "{err:#}"); + } + /// `import archive` republishes a recording `export archive` wrote under the given name and /// instance, serving its stored groups. #[tokio::test] From 5154cc505576e0d25aa0fb5c7e00288321b18c31 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 13:31:11 -0800 Subject: [PATCH 14/21] fix: follow past a refusal, check named sibling instances, reset cluster stats on restart Co-Authored-By: Claude Opus 5.5 --- demo/carla/sim/moq_carla_sim/publish.py | 9 ++- demo/carla/sim/tests/conftest.py | 2 + demo/carla/sim/tests/test_publish.py | 26 +++++++- demo/web/src/stats.ts | 3 + rs/moq-mux/MIGRATE.md | 1 - rs/moq-mux/src/follow.rs | 84 +++++++++++++++++++++---- rs/moq-mux/src/source.rs | 2 +- rs/moq-net/MIGRATE.md | 2 +- rs/moq-net/src/model/follow.rs | 31 ++++++++- rs/moq-room/src/room.rs | 37 ++++++----- 10 files changed, 159 insertions(+), 38 deletions(-) diff --git a/demo/carla/sim/moq_carla_sim/publish.py b/demo/carla/sim/moq_carla_sim/publish.py index b21ab1cffbb..9bcc1c33526 100644 --- a/demo/carla/sim/moq_carla_sim/publish.py +++ b/demo/carla/sim/moq_carla_sim/publish.py @@ -347,7 +347,14 @@ async def _follow_driver( try: async with client.follow(path) as following: while True: - broadcast = await following.available() + try: + broadcast = await following.available() + # A refusal leaves the follow waiting for another run; only shutdown ends it. + except moq.Error as err: # pyright: ignore[reportGeneralTypeIssues] + if moq.is_shutdown(err): + raise + log.info("driver %s refused: %s", driver_id, err) + continue if run is not None: run.cancel() run = None diff --git a/demo/carla/sim/tests/conftest.py b/demo/carla/sim/tests/conftest.py index 0622765b136..7688e0675eb 100644 --- a/demo/carla/sim/tests/conftest.py +++ b/demo/carla/sim/tests/conftest.py @@ -52,6 +52,8 @@ async def __aiter__(self): moq = ModuleType("moq") moq.Error = MoqError +# The stub has no shutdown errors: every `MoqError` it raises is a failure. +moq.is_shutdown = lambda err: False moq.AnnounceEventPresent = AnnounceEventPresent moq.AnnounceEventAbsent = AnnounceEventAbsent moq.Timestamp = lambda value, scale: SimpleNamespace(value=value, scale=scale) diff --git a/demo/carla/sim/tests/test_publish.py b/demo/carla/sim/tests/test_publish.py index da0d4fda989..aee07ded9c4 100644 --- a/demo/carla/sim/tests/test_publish.py +++ b/demo/carla/sim/tests/test_publish.py @@ -219,7 +219,8 @@ async def absent(self, path: str) -> None: class Following(Scripted): - """A scripted follow of one path: each `run` hands out another instance, and `offline` a `None`.""" + """A scripted follow of one path: each `run` hands out another instance, `offline` a `None`, + and `refuse` an error.""" async def __aenter__(self): return self @@ -228,7 +229,14 @@ async def __aexit__(self, *_exc) -> None: pass async def available(self): - return await self.next() + item = await self.next() + if isinstance(item, BaseException): + raise item + return item + + async def refuse(self) -> None: + """Fail the next `available()`, as a handler refusing the path does.""" + await self.send(moq.Error("refused")) async def run(self, sequence: int) -> None: """Hand out an instance that serves one drive command numbered `sequence`, then stays open.""" @@ -324,6 +332,20 @@ async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None asyncio.run(watching(scenario)) +def test_a_refused_driver_is_still_followed() -> None: + """A refusal leaves the follow waiting, so the driver's next run still takes the lease.""" + + async def scenario(relay: Drivers, commands: asyncio.Queue, gate: Drive) -> None: + await relay.announcements.present(DRIVER) + await relay.following(DRIVER).refuse() + await relay.following(DRIVER).run(1) + command = await next_command(commands, gate) + assert (command.kind, command.driver_id) == ("drive", "abc") + assert relay.followed == [DRIVER] + + asyncio.run(watching(scenario)) + + def test_a_driver_that_restarts_under_a_new_instance_is_a_new_driver() -> None: """The old run's lease ends with it, even though the path and id are the same.""" diff --git a/demo/web/src/stats.ts b/demo/web/src/stats.ts index 75ae1c0dc32..91afe60451d 100644 --- a/demo/web/src/stats.ts +++ b/demo/web/src/stats.ts @@ -195,6 +195,9 @@ function subscribeNode(effect: Signals.Effect, origin: Net.Origin.Reader, path: }; }); history.delete(node); + // The aggregate spans every node, so a restarted node's counters must not splice into + // its history either. + clusterMembership = ""; if (!consumer) return; const track = consumer.track("group.json").subscribe(); diff --git a/rs/moq-mux/MIGRATE.md b/rs/moq-mux/MIGRATE.md index 26d65fe817e..3d5d4f773e5 100644 --- a/rs/moq-mux/MIGRATE.md +++ b/rs/moq-mux/MIGRATE.md @@ -8,7 +8,6 @@ How to update your code for each breaking change, newest first. `follow::Instances::new` is removed: call `origin.follow(path, instance)` and read `Following::available()`, which returns `Some(broadcast)` where `Event::Start` did and `None` where `Event::End` did. `Source::follow` still returns `follow::Instances`, for its one-shot hand-out of the catalog's own broadcast; its `next()` and `poll_next()` now return `Option`, and `follow::Event` is gone. -A pinned instance is now pinned in the origin's follower, which ends the rendition when another instance takes the path. ### fMP4 decode errors are terminal diff --git a/rs/moq-mux/src/follow.rs b/rs/moq-mux/src/follow.rs index da2ececdd5e..70325703fb1 100644 --- a/rs/moq-mux/src/follow.rs +++ b/rs/moq-mux/src/follow.rs @@ -3,7 +3,7 @@ //! An announcement is the online and offline signal, so a reader that restarts on each instance //! follows [`Instances`] rather than pinning one broadcast as a [`Binding`](crate::Binding) does. -use std::task::Poll; +use std::task::{Poll, ready}; /// The publisher instances serving a rendition's broadcast, as each comes online, takes over, /// and goes. Created by [`Source::follow`](crate::Source::follow). @@ -15,14 +15,30 @@ pub struct Instances(Feed); enum Feed { /// Every instance announced at a path. - Following(Box), + Following { + following: Box, + /// The instance a reference named, if any. + instance: Option, + /// An instance was handed out and its end not reported yet. + live: bool, + }, /// One instance, handed out once. Fixed(Option), } impl Instances { - pub(crate) fn following(following: moq_net::origin::Following) -> Self { - Self(Feed::Following(Box::new(following))) + /// Follow every instance, handing out only `instance` when given. + /// + /// The path is followed unpinned and each instance checked here, rather than pinned in the + /// origin: a hop older than moq-lite 07 mints instances a pin never matches, which + /// [`check_instance`](crate::source::check_instance) lets through, and another instance + /// winning the path ends the rendition rather than leaving an older one to resolve. + pub(crate) fn following(following: moq_net::origin::Following, instance: Option) -> Self { + Self(Feed::Following { + following: Box::new(following), + instance, + live: false, + }) } pub(crate) fn fixed(broadcast: moq_net::broadcast::Consumer) -> Self { @@ -32,16 +48,39 @@ impl Instances { /// Poll for the next change, registering `waiter` when there is none yet. /// /// Returns each instance as it comes online or takes over, and `None` once the path goes - /// offline; see [`Following::available`](moq_net::origin::Following::available). Fails - /// once the origin closes, and with any resolution failure, such as a handler refusing the - /// path. + /// offline or, with an instance named, another one takes it over; see + /// [`Following::available`](moq_net::origin::Following::available). Fails once the origin + /// closes, and with any resolution failure, such as a handler refusing the path. pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll>> { - match &mut self.0 { - Feed::Following(following) => following.poll_available(waiter).map_err(crate::Error::from), - Feed::Fixed(broadcast) => match broadcast.take() { - Some(broadcast) => Poll::Ready(Ok(Some(broadcast))), - None => Poll::Pending, - }, + let (following, instance, live) = match &mut self.0 { + Feed::Following { + following, + instance, + live, + } => (following, instance, live), + Feed::Fixed(broadcast) => { + return match broadcast.take() { + Some(broadcast) => Poll::Ready(Ok(Some(broadcast))), + None => Poll::Pending, + }; + } + }; + loop { + match ready!(following.poll_available(waiter))? { + Some(broadcast) if crate::source::check_instance(instance.as_ref(), &broadcast).is_ok() => { + *live = true; + return Poll::Ready(Ok(Some(broadcast))); + } + Some(broadcast) => { + tracing::debug!(path = %broadcast.info().path, "skipping a broadcast of another instance"); + } + None => {} + } + // Report the end of what was handed out once, whether it went offline or another + // instance took over. + if std::mem::take(live) { + return Poll::Ready(Ok(None)); + } } } @@ -142,6 +181,25 @@ mod tests { assert_eq!(back.info().instance.as_ref(), Some(&old_instance)); } + /// A reference naming an instance still follows a sibling whose instance an older hop + /// minted, which proves nothing either way. + #[tokio::test(start_paused = true)] + async fn a_named_instance_follows_a_minted_one() { + let origin = produce_origin(); + let _catalog = origin.publish("a/pub", Default::default()).unwrap(); + let minted: moq_net::Instance = "~minted".parse().unwrap(); + assert!(minted.is_minted()); + let _sibling = origin.publish("a/source", route(&minted)).unwrap(); + settle().await; + let source = resolved(&origin, "a/pub").await; + let named = moq_net::Instance::random(); + let mut follow = source + .follow(Some(&Relative::new("./source").unwrap()), Some(&named)) + .unwrap(); + let served = followed(&mut follow).await.expect("the minted sibling"); + assert_eq!(served.info().instance.as_ref(), Some(&minted)); + } + /// A self-reference reads only the catalog instance, whatever replaces it at the path. #[tokio::test(start_paused = true)] async fn a_follow_of_the_catalog_keeps_its_instance() { diff --git a/rs/moq-mux/src/source.rs b/rs/moq-mux/src/source.rs index b1f0f126c5f..c90d9955712 100644 --- a/rs/moq-mux/src/source.rs +++ b/rs/moq-mux/src/source.rs @@ -389,7 +389,7 @@ impl Source { check_instance(instance, &broadcast)?; crate::follow::Instances::fixed(broadcast) } - false => crate::follow::Instances::following(self.origin.follow(&path, instance.cloned())?), + false => crate::follow::Instances::following(self.origin.follow(&path, None)?, instance.cloned()), }) } } diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index 7909a7d50cc..bd7c7779257 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -12,7 +12,7 @@ Map `Start` to `Present` and `End` to `Absent`, and drop `Update` arms. Where you requested the path again on `Restart`, hold `consumer.follow(path, None)` instead: each `available()` returns the next instance's broadcast. `Following::available()` returns `Result, Error>`: `None` reports the path going offline (or, when pinned, another instance taking it over), and the next `Some` is whatever serves it again. -The first call never returns `None`. +The first call never returns `None`. After a resolution failure, such as a handler refusing the path, the next `available()` waits for another instance to serve it instead of asking the same handler again, so keep the follower rather than dropping it. ```rust // Before diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index 998aaa8d1fa..f2214dd0403 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -246,8 +246,10 @@ impl Following { /// /// Returns the broadcast of each instance as it comes online or takes over, and `None` /// once the path the one handed out last served goes offline, or, when pinned, another - /// instance takes it over. Returns [`Error::Closed`] once the origin closes, and any other resolution - /// failure as-is. Dropping the future keeps the wait's progress for the next call. + /// instance takes it over. Returns [`Error::Closed`] once the origin closes, and any other + /// resolution failure as-is, such as a handler refusing the path; the next call then waits + /// for another instance to serve it. Dropping the future keeps the wait's progress for the + /// next call. #[cfg(feature = "async")] pub async fn available(&mut self) -> Result, Error> { kio::wait(|waiter| self.poll_available(waiter)).await @@ -306,8 +308,10 @@ impl Following { .get_or_insert_with(|| self.consumer.routing(self.path.clone(), self.instance.clone())); let resolved = ready!(kio::Task::poll(resolving, waiter)); self.resolving = None; - let broadcast = resolved?; + // A refusal answers for the routes serving the path now: wait for another instance + // to serve it before asking again, rather than asking the same handler at once. self.unseen = false; + let broadcast = resolved?; // Resolving can run ahead of the follower: a takeover resolves at once while the // origin holds its restart, and that restart then names the instance handed out. @@ -730,6 +734,27 @@ mod tests { )); } + /// A refusal is reported once, and the follower then waits for another instance rather than + /// asking the refusing handler again. + #[kio::test] + async fn announced_waits_for_another_instance_after_a_refusal() { + let origin = Hop::new(1).unwrap().produce(); + let claim = origin.requests("live").unwrap(); + let mut announced = origin.consume().follow("live", None).unwrap(); + let (result, ()) = futures::join!( + kio::clock::timeout(Duration::from_secs(1), announced.available()), + async { requested(&claim).await.reject(Error::NotFound) } + ); + assert!(matches!(result.expect("the refusal answers"), Err(Error::NotFound))); + none(&mut announced).await; + let again = kio::clock::timeout(Duration::from_secs(1), claim.requested_broadcast()).await; + assert!(again.is_err(), "the refusing handler was asked again"); + + // A publisher takes the path over from the claim, and is handed out. + let _publisher = origin.publish("live", route(&Instance::random())).unwrap(); + let _served = available(&mut announced).await; + } + /// A path no pattern can spell is refused rather than followed through the whole scope, /// where a route that never serves it could win its prefix. #[test] diff --git a/rs/moq-room/src/room.rs b/rs/moq-room/src/room.rs index 7891f4e59b1..416ca31a293 100644 --- a/rs/moq-room/src/room.rs +++ b/rs/moq-room/src/room.rs @@ -35,9 +35,7 @@ struct Participant { identity: Path, kind: Kind, path: Path, - /// `None` once the follower failed, such as a handler refusing the path: the participant - /// stays listed until the listing reports it absent. - following: Option, + following: origin::Following, } /// Runs the announce loop and yields remote participant broadcasts. @@ -110,21 +108,17 @@ impl Room { identity: parsed.identity, kind: parsed.kind, path, - following: Some(following), + following, }); } - /// The next broadcast a participant's follower hands out. A follower that fails, such as a - /// handler refusing its path, stops until the path is listed again; its end comes from the - /// listing. + /// The next broadcast a participant's follower hands out. A refusal, such as a handler + /// refusing the path, yields nothing: the follower waits for another instance to serve it, + /// and the participant's end comes from the listing. fn poll_participants(&mut self, waiter: &kio::Waiter) -> Poll { let mut index = 0; while let Some(participant) = self.participants.get_mut(index) { - let Some(following) = participant.following.as_mut() else { - index += 1; - continue; - }; - match following.poll_available(waiter) { + match participant.following.poll_available(waiter) { Poll::Ready(Ok(Some(broadcast))) => { return Poll::Ready(Event { identity: participant.identity.clone(), @@ -134,7 +128,9 @@ impl Room { }); } Poll::Ready(Ok(None)) => continue, - Poll::Ready(Err(_)) => participant.following = None, + // Re-polled on the next wake, rather than again now: a closed origin answers + // `Closed` every time until the listing ends. + Poll::Ready(Err(_)) => index += 1, Poll::Pending => index += 1, } } @@ -184,7 +180,8 @@ mod tests { assert!(gone.broadcast.is_none()); } - /// A participant whose follower fails stays listed, so its absence is still reported. + /// A refused participant stays listed and followed: a publisher taking it over is yielded, and + /// its absence is still reported. #[tokio::test(start_paused = true)] async fn reports_the_absence_of_a_refused_participant() { let wait = std::time::Duration::from_secs(1); @@ -195,10 +192,18 @@ mod tests { let (request, nothing) = tokio::join!(claim.requested_broadcast(), kio::clock::timeout(wait, room.next())); assert!(nothing.is_err(), "nothing serves bob yet"); request.expect("requested").reject(moq_net::Error::NotFound); - // The refusal fails bob's follower, which yields nothing. + // The refusal yields nothing. assert!(kio::clock::timeout(wait, room.next()).await.is_err()); - drop(claim); + // A publisher taking the path over from the claim is still followed. + let bob = publish(&origin, "bob/camera"); + let back = kio::clock::timeout(wait, room.next()) + .await + .expect("the publisher was never yielded") + .expect("bob camera"); + assert!(back.broadcast.is_some()); + + drop((bob, claim)); let gone = kio::clock::timeout(wait, room.next()) .await .expect("the absence was never reported") From 76d20d54283978c7a7663681acf301c5ba554505 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 13:39:42 -0800 Subject: [PATCH 15/21] fix(net): a refusal does not leave the follower retrying a moved broadcast Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/follow.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index f2214dd0403..ffab9b94bf7 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -309,9 +309,18 @@ impl Following { let resolved = ready!(kio::Task::poll(resolving, waiter)); self.resolving = None; // A refusal answers for the routes serving the path now: wait for another instance - // to serve it before asking again, rather than asking the same handler at once. + // to serve it before asking again, rather than asking the same handler at once. That + // includes the broadcast handed out last moving off the path, which led here. self.unseen = false; - let broadcast = resolved?; + let broadcast = match resolved { + Ok(broadcast) => broadcast, + Err(err) => { + self.last = None; + self.moved = None; + self.absorbed = false; + return Poll::Ready(Err(err)); + } + }; // Resolving can run ahead of the follower: a takeover resolves at once while the // origin holds its restart, and that restart then names the instance handed out. @@ -755,6 +764,27 @@ mod tests { let _served = available(&mut announced).await; } + /// A refusal by the route that took over from a closed broadcast is not retried when that + /// broadcast's movement is seen: the follower waits for another instance. + #[kio::test] + async fn announced_does_not_retry_a_refusal_after_a_takeover() { + let origin = Hop::new(1).unwrap().produce(); + let dynamic = origin.requests_route("", route(&Instance::random()), None).unwrap(); + let exact = origin.publish("live", route(&Instance::random())).unwrap(); + let mut announced = origin.consume().follow("live", None).unwrap(); + let _first = available(&mut announced).await; + + drop(exact); + let (result, ()) = futures::join!( + kio::clock::timeout(Duration::from_secs(1), announced.available()), + async { requested(&dynamic).await.reject(Error::NotFound) } + ); + assert!(matches!(result.expect("the refusal answers"), Err(Error::NotFound))); + none(&mut announced).await; + let again = kio::clock::timeout(Duration::from_secs(1), dynamic.requested_broadcast()).await; + assert!(again.is_err(), "the refusing handler was asked again"); + } + /// A path no pattern can spell is refused rather than followed through the whole scope, /// where a route that never serves it could win its prefix. #[test] From d02957c3e67171df960e97ce3b2650ad3c001d13 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 14:09:38 -0800 Subject: [PATCH 16/21] test: guard the owed end after a refusal; check the pinned C follow delivers nothing Co-Authored-By: Claude Opus 5.5 --- rs/moq-c/src/test.rs | 9 ++++++--- rs/moq-net/src/model/follow.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/rs/moq-c/src/test.rs b/rs/moq-c/src/test.rs index f952f312cf7..87625659a3f 100644 --- a/rs/moq-c/src/test.rs +++ b/rs/moq-c/src/test.rs @@ -5069,9 +5069,12 @@ fn an_instance_pins_request_and_follow() { ) }); let delivered = id(cb.recv()); - let tx = unsafe { &*(cb.ptr as *const mpsc::Sender) }.clone(); - crate::ffi::RUNTIME.spawn(async move { tx.send(i32::MAX - 1).unwrap() }); - assert_eq!(cb.recv(), i32::MAX - 1, "the follower delivered another instance"); + assert!( + cb.rx + .recv_timeout(moq_net::origin::Config::default().update_hold * 2) + .is_err(), + "the follower delivered another instance" + ); assert_eq!(moq_consume_close(delivered), 0); assert_eq!(moq_origin_follow_cancel(task), 0); assert_eq!(cb.recv_terminal(), 0, "cancel delivers terminal 0"); diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index 0f6fcc5f565..156670d3bd4 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -314,6 +314,8 @@ impl Following { self.unseen = false; let broadcast = match resolved { Ok(broadcast) => broadcast, + // `live` stays: the end of what was handed out is still owed once the path goes + // offline. Err(err) => { self.last = None; self.moved = None; @@ -765,7 +767,8 @@ mod tests { } /// A refusal by the route that took over from a closed broadcast is not retried when that - /// broadcast's movement is seen: the follower waits for another instance. + /// broadcast's movement is seen: the follower waits for another instance, and still reports + /// the end of what it handed out once the path goes offline. #[kio::test] async fn announced_does_not_retry_a_refusal_after_a_takeover() { let origin = Hop::new(1).unwrap().produce(); @@ -783,6 +786,11 @@ mod tests { none(&mut announced).await; let again = kio::clock::timeout(Duration::from_secs(1), dynamic.requested_broadcast()).await; assert!(again.is_err(), "the refusing handler was asked again"); + + // The broadcast handed out before the refusal is still owed its end once the path goes + // offline. + drop(dynamic); + ended(&mut announced).await; } /// A path no pattern can spell is refused rather than followed through the whole scope, From 4fba2ec8a01c4c84a2a289279a0f8271104c61a5 Mon Sep 17 00:00:00 2001 From: "pullfrog[bot]" <226033991+pullfrog[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 22:13:19 +0000 Subject: [PATCH 17/21] fix(quest): drop links to the implemented listing quest --- quest/m1/cluster-routing/routes/availability.md | 2 +- quest/m1/cluster-routing/routes/session.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/quest/m1/cluster-routing/routes/availability.md b/quest/m1/cluster-routing/routes/availability.md index eeeb9dbf560..30c4e8d0382 100644 --- a/quest/m1/cluster-routing/routes/availability.md +++ b/quest/m1/cluster-routing/routes/availability.md @@ -16,7 +16,7 @@ ends them. Bindings mirror Rust. route recovers; let-go reported as END, as today; and availability with let-go kept as END, which hides whether the origin ended or the network lost it. -- Build on [Listing and follow](/quest/m1/api-audit/route/events.md)'s +- Build on [Listing and follow](https://github.com/moq-dev/moq/pull/7678)'s listing and its offline report rather than adding event kinds beside it. - JS gets the API shape here, fed by what `js/net` knows today; the [js/net route layer](/quest/m1/cluster-routing/routes/js.md) feeds it from the wire. diff --git a/quest/m1/cluster-routing/routes/session.md b/quest/m1/cluster-routing/routes/session.md index ec2395ad365..62329838762 100644 --- a/quest/m1/cluster-routing/routes/session.md +++ b/quest/m1/cluster-routing/routes/session.md @@ -152,7 +152,6 @@ separate", in the epic). - [lite-07 route wire](/quest/m1/cluster-routing/routes/wire.md) - the messages this drives - [One Route handle](/quest/m1/api-audit/route/handle.md) - the origin's route surface this rewrites -- [Listing and follow](/quest/m1/api-audit/route/events.md) - the announcement events this feeds ([moq-dev/moq#7678](https://github.com/moq-dev/moq/pull/7678)) ## Related From 25c2526611931a0700ddabd48e54573fb51a5d94 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 4 Nov 2026 22:39:10 -0800 Subject: [PATCH 18/21] fix: align the merged refusal retry with the listing; format Main's #7836 retries a refused follower on any serving-route change. Drop its test that duplicated this branch's refusal-after-takeover test, and say the follower waits for a route change, not another instance. Co-Authored-By: Claude Opus 5.5 --- c/moq/MIGRATE.md | 1 + cpp/moq/MIGRATE.md | 1 + dart/moq/MIGRATE.md | 1 + go/wrapper/MIGRATE.md | 1 + js/net/MIGRATE.md | 1 + kt/moq/MIGRATE.md | 1 + py/moq-rs/MIGRATE.md | 1 + rs/moq-c/MIGRATE.md | 1 + rs/moq-ffi/MIGRATE.md | 1 + rs/moq-gst/src/source/imp.rs | 8 +++-- rs/moq-mux/MIGRATE.md | 1 + rs/moq-net/MIGRATE.md | 3 +- rs/moq-net/src/model/follow.rs | 37 +++----------------- rs/moq-net/tests/integration/compress.rs | 8 ++++- rs/moq-net/tests/integration/range_fill.rs | 9 ++++- rs/moq-relay/src/cluster.rs | 10 +++++- rs/moq-room/src/room.rs | 2 +- rs/moq-tokio/tests/integration/relay_fill.rs | 14 ++++++-- swift/MIGRATE.md | 1 + 19 files changed, 61 insertions(+), 41 deletions(-) diff --git a/c/moq/MIGRATE.md b/c/moq/MIGRATE.md index e9e37fd2bc2..8c738b9bda8 100644 --- a/c/moq/MIGRATE.md +++ b/c/moq/MIGRATE.md @@ -27,6 +27,7 @@ Another instance taking a path over keeps it present, and a route's cost changin Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. `moq_origin_follow` takes a `moq_follow_callback`, `(void *user_data, moq_follow_event event, int32_t code)`, instead of a `moq_status_callback`. `MOQ_FOLLOW_EVENT_ONLINE` carries each broadcast handle (where a positive code did), `MOQ_FOLLOW_EVENT_OFFLINE` reports the path going offline (or, for a follow pinned to an instance, another instance taking it over) with code `0`, and `MOQ_FOLLOW_EVENT_END` is the terminal callback, with `0` or a negative error that `moq_error()` explains (where a code `<= 0` was). Release `user_data` on `MOQ_FOLLOW_EVENT_END`. + ### Authored tracks default to a zero max age ([#7729](https://github.com/moq-dev/moq/pull/7729)) A NULL or zeroed `moq_track_info` now advertises a zero max age, serving only the live edge, instead of no publisher limit. `max_age_present` is gone and `max_age_us` always applies; set the new `max_age_unlimited`, which ignores `max_age_us`, where you relied on `max_age_present` false meaning no limit. Zero-initialize the struct (`moq_track_info info = {0};`) or assign every member. In the generated API, an unset `moq_track_info.max_age` is likewise zero, and `max_age_unlimited` sets no limit. diff --git a/cpp/moq/MIGRATE.md b/cpp/moq/MIGRATE.md index cd02b1ee0c9..b3a688e0dca 100644 --- a/cpp/moq/MIGRATE.md +++ b/cpp/moq/MIGRATE.md @@ -5,6 +5,7 @@ ### `Following::available()` reports the path going offline ([#7678](https://github.com/moq-dev/moq/pull/7678)) `moq::Following::available()` resolves to a null `std::shared_ptr` once the path goes offline (or, for a follow pinned to an instance, once another instance takes it over), then the next broadcast when something serves the path again. The first call is never null. Check for null before using a later result, and treat it like the previous instance ending. + ### Separate datagram tracks Replace stream-track datagram methods with `BroadcastProducer::create_datagrams(name, info)` and `BroadcastConsumer::datagrams(name)`. The generated `DatagramProducer` exposes `append(timestamp, payload)` and `insert(Datagram)`; `DatagramConsumer::recv()` returns an optional datagram through a future. `DatagramInfo` has only priority and optional timescale. Demand is aggregate subscriber `priority()` / `priority_changed(last)`; on-demand datagram requests come from `BroadcastRequests::datagrams()` / `DatagramRequests::requested()`. Stream tracks of the same name are independent. diff --git a/dart/moq/MIGRATE.md b/dart/moq/MIGRATE.md index 11569b87494..898fc9b7625 100644 --- a/dart/moq/MIGRATE.md +++ b/dart/moq/MIGRATE.md @@ -25,6 +25,7 @@ while (true) { play(broadcast); } ``` + ### Catalog renditions carry their warmup ([#7864](https://github.com/moq-dev/moq/pull/7864)) `Video` and `Audio` gain `warmup`, the catalog's decoder warmup; it defaults to `null`, so existing constructors still compile. `TrackConsumer` and the audio and video consumers read it from the rendition and start that much earlier. diff --git a/go/wrapper/MIGRATE.md b/go/wrapper/MIGRATE.md index 7bbadae5972..b4f883b5510 100644 --- a/go/wrapper/MIGRATE.md +++ b/go/wrapper/MIGRATE.md @@ -34,6 +34,7 @@ for { play(broadcast) } ``` + ### Catalog renditions carry their warmup ([#7864](https://github.com/moq-dev/moq/pull/7864)) `ffi.MoqVideo` and `ffi.MoqAudio` (`media.Video` and `media.Audio`) gain `Warmup`, the catalog's decoder warmup, nil when absent. `media.NewTrackConsumer` and the audio and video `Subscribe` read it from the rendition and start that much earlier; a negative one is refused with an error. Only unkeyed struct literals change. diff --git a/js/net/MIGRATE.md b/js/net/MIGRATE.md index 77c71159fd9..7116046186f 100644 --- a/js/net/MIGRATE.md +++ b/js/net/MIGRATE.md @@ -8,6 +8,7 @@ How to update your code for each breaking change, newest first. `Announce.Event` is `{ kind: "present" | "absent" } & Announce`. Another instance taking a path over keeps it present, and a route's cost or hops changing is not reported, so `start`, `update`, `restart` and `end` are gone. Map `"start"` to `"present"` and `"end"` to `"absent"`, and drop `"update"` branches. Where you requested the path again on `"restart"`, hold `origin.follow(path)`: its `active` moves to each new instance's broadcast. + ### Opens wait their turn for stream credit ([#7894](https://github.com/moq-dev/moq/pull/7894)) `NoStreamCredit` is removed: a request no longer fails when the peer grants no more streams. Every open waits for credit, and returning credit goes to the open with the highest `sendOrder`. A request's 10s deadline runs only while none of its streams waits to open. diff --git a/kt/moq/MIGRATE.md b/kt/moq/MIGRATE.md index 5b73397cfb4..8ee94bdc198 100644 --- a/kt/moq/MIGRATE.md +++ b/kt/moq/MIGRATE.md @@ -24,6 +24,7 @@ while (true) { play(broadcast) } ``` + ### Catalog renditions carry their warmup ([#7864](https://github.com/moq-dev/moq/pull/7864)) `Video` and `Audio` gain `warmup`, the catalog's decoder warmup; it defaults to `null` as the last field, so existing code keeps working. `TrackConsumer` and the audio and video consumers read it from the rendition and start that much earlier. diff --git a/py/moq-rs/MIGRATE.md b/py/moq-rs/MIGRATE.md index c07d0e2479b..64d9180cfa4 100644 --- a/py/moq-rs/MIGRATE.md +++ b/py/moq-rs/MIGRATE.md @@ -15,6 +15,7 @@ Another publisher instance taking a path over keeps it present and is not listed `await following.available()` (or `await following`) returns `BroadcastConsumer | None`. Later calls return `None` when the path goes offline, or, when following an `instance`, when another instance takes it over, then the next broadcast once something serves the path again; the first call never returns `None`. Stop reading the previous broadcast on `None` and call `available()` again. A caller that only awaits the first broadcast can assert it is not `None`. + ### Catalog renditions carry their warmup ([#7864](https://github.com/moq-dev/moq/pull/7864)) `Video` and `Audio` gain `warmup`, the catalog's decoder warmup; it defaults to `None` as the last field, so existing code keeps working. `TrackConsumer` and the audio and video consumers read it from the rendition and start that much earlier. diff --git a/rs/moq-c/MIGRATE.md b/rs/moq-c/MIGRATE.md index 3106b0f4b3e..104b94f772b 100644 --- a/rs/moq-c/MIGRATE.md +++ b/rs/moq-c/MIGRATE.md @@ -11,6 +11,7 @@ Another instance taking a path over keeps it present, and a route's cost changin Map `_START` to `_PRESENT` and `_END` to `_ABSENT`, and drop `_UPDATE` handling. Where you requested the path again on `_RESTART` or `_TAKEOVER`, call `moq_origin_follow`, whose callback delivers a broadcast handle for each new instance. `moq_origin_follow` takes a `moq_follow_callback`, `(void *user_data, moq_follow_event event, int32_t code)`, instead of a `moq_status_callback`. `MOQ_FOLLOW_EVENT_ONLINE` carries each broadcast handle (where a positive code did), `MOQ_FOLLOW_EVENT_OFFLINE` reports the path going offline (or, for a follow pinned to an instance, another instance taking it over) with code `0`, and `MOQ_FOLLOW_EVENT_END` is the terminal callback, with `0` or a negative error that `moq_error()` explains (where a code `<= 0` was). Release `user_data` on `MOQ_FOLLOW_EVENT_END`. + ### Separate datagram tracks Create a separate producer with `moq_publish_datagrams` and `moq_datagram_info`; replace `moq_publish_track_datagram` with `moq_publish_datagrams_append` on that handle, or `moq_publish_datagrams_insert` for an explicit sequence. `moq_consume_datagrams` now takes a subscriber priority before its callback and never subscribes to a stream track. Use `moq_publish_datagrams_demand` and `moq_datagram_demand_priority` for aggregate priority, and `moq_publish_datagrams_requests` / `moq_datagram_request_accept` for on-demand publishing. Finish or abort datagram producers separately. A zeroed datagram info is untimed, unlike the microsecond default of stream-track info. `moq_consume_datagrams` returns a negative code at once when the broadcast has neither the datagram track nor a datagram request handler, and a remote name without one ends its callback with a not-found error. diff --git a/rs/moq-ffi/MIGRATE.md b/rs/moq-ffi/MIGRATE.md index 4401f5e6bf5..c030b7ecf42 100644 --- a/rs/moq-ffi/MIGRATE.md +++ b/rs/moq-ffi/MIGRATE.md @@ -11,6 +11,7 @@ These are the UniFFI names; each language wrapper has its own `MIGRATE.md` in it Map `Start` to `Present` and `End` to `Absent`, and drop `Update` handling. Where you requested the path again on `Restart`, hold `MoqOriginConsumer::follow(path)` and await `available()` for each new instance. `MoqFollowing::available()` returns `Option>`: `None` once the path goes offline (or, for a follow pinned to an `instance`, once another instance takes it over), then the next broadcast when something serves the path again. The first call never returns `None`. Handle `None` as offline: drop what you read from the last broadcast and call `available()` again. + ### Catalog renditions carry their warmup ([#7864](https://github.com/moq-dev/moq/pull/7864)) `MoqVideo` and `MoqAudio` gain `warmup`, the catalog's decoder warmup, null when absent. `MoqMediaTrackConsumer::subscribe` reads it from the rendition: it starts that much further back than the subscription's min delay and asks the publisher for its max delay plus the warmup, while it still skips at the max delay alone. `MoqAudioConsumer::subscribe` and `MoqVideoConsumer::subscribe` now honor it too. diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index 66b39345f93..0f192dd28d6 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -4304,9 +4304,13 @@ mod session_tests { assert_eq!(recorder.written(&mut first, 2), pad); let mut follow = watch(&origin, "cam"); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::Start(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::Start(_)) + }); drop(first); - await_event(&mut follow, |event| matches!(event, moq_net::origin::RouteEvent::End(_))); + await_event(&mut follow, |event| { + matches!(event, moq_net::origin::RouteEvent::End(_)) + }); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 3), pad, "the return moved to another pad"); assert_eq!( diff --git a/rs/moq-mux/MIGRATE.md b/rs/moq-mux/MIGRATE.md index d22e05ca547..d1875cceed9 100644 --- a/rs/moq-mux/MIGRATE.md +++ b/rs/moq-mux/MIGRATE.md @@ -8,6 +8,7 @@ How to adopt new APIs and update for breaking changes, newest first. `follow::Instances::new` is removed: call `origin.follow(path, instance)` and read `Following::available()`, which returns `Some(broadcast)` where `Event::Start` did and `None` where `Event::End` did. `Source::follow` still returns `follow::Instances`, for its one-shot hand-out of the catalog's own broadcast; its `next()` and `poll_next()` now return `Option`, and `follow::Event` is gone. + ### `container::Playout` replaces `with_warmup` ([#7864](https://github.com/moq-dev/moq/pull/7864)) `container::Consumer::with_warmup` is gone. Build a `container::Playout::new(delay, warmup)` from the `Delay` and the catalog rendition's `warmup`, subscribe with `playout.subscription(subscription)`, which widens the max delay by the warmup, and build the consumer with `playout.consumer(track, format)`, which skips at the max delay alone. The order no longer matters, and a track subscribed without the widening is widened when the consumer is built. diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index 0e3a979573f..5963f90782d 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -12,7 +12,7 @@ Map `Start` to `Present` and `End` to `Absent`, and drop `Update` arms. Where you requested the path again on `Restart`, hold `consumer.follow(path, None)` instead: each `available()` returns the next instance's broadcast. `Following::available()` returns `Result, Error>`: `None` reports the path going offline (or, when pinned, another instance taking it over), and the next `Some` is whatever serves it again. -The first call never returns `None`. After a resolution failure, such as a handler refusing the path, the next `available()` waits for another instance to serve it instead of asking the same handler again, so keep the follower rather than dropping it. +The first call never returns `None`. After a resolution failure, such as a handler refusing the path, the next `available()` waits for the serving route to change instead of asking the same handler again, so keep the follower rather than dropping it. ```rust // Before @@ -32,6 +32,7 @@ let broadcast = consumer.follow(path, None)?.available().await?.expect("the firs ``` Relays and stats that forward every route change call `consumer.routes()`, a hidden `origin::Routes` stream of `origin::RouteEvent`, which keeps the old five variants. + ### Opens wait their turn for stream credit ([#7894](https://github.com/moq-dev/moq/pull/7894)) A request no longer fails with `Error::NoStreamCredit` when the peer grants no more streams: every stream a session opens waits for credit, and returning credit goes to the open whose stream the transport would send first. The variant is removed; drop any arm matching it. diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index 6611d2cdc87..78d90882a38 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -790,37 +790,10 @@ mod tests { ); } - /// A refusal after the instance handed out closed is not asked again on every call: the - /// closed instance's handover is settled until the serving route changes. + /// A refusal is reported once, and the follower then waits for the serving route to change + /// rather than asking the refusing handler again. #[kio::test] - async fn announced_waits_after_refusing_a_closed_instances_successor() { - let origin = Hop::new(1).unwrap().produce(); - let claim = origin.requests_route("", route(&Instance::random()), None).unwrap(); - let exact = origin.publish("live", route(&Instance::random())).unwrap(); - let mut announced = origin.consume().follow("live", None).unwrap(); - let _first = available(&mut announced).await; - drop(exact); - let (result, ()) = futures::join!( - kio::clock::timeout(Duration::from_secs(1), announced.available()), - async { - requested(&claim).await.reject(Error::Unroutable); - } - ); - assert!(matches!( - result.expect("the refusal must answer"), - Err(Error::Unroutable) - )); - let ((), again) = futures::join!( - none(&mut announced), - kio::clock::timeout(Duration::from_secs(1), claim.requested_broadcast()) - ); - assert!(again.is_err(), "the refusing route was asked again"); - } - - /// A refusal is reported once, and the follower then waits for another instance rather than - /// asking the refusing handler again. - #[kio::test] - async fn announced_waits_for_another_instance_after_a_refusal() { + async fn announced_waits_for_a_route_change_after_a_refusal() { let origin = Hop::new(1).unwrap().produce(); let claim = origin.requests("live").unwrap(); let mut announced = origin.consume().follow("live", None).unwrap(); @@ -839,8 +812,8 @@ mod tests { } /// A refusal by the route that took over from a closed broadcast is not retried when that - /// broadcast's movement is seen: the follower waits for another instance, and still reports - /// the end of what it handed out once the path goes offline. + /// broadcast's movement is seen: the follower waits for the serving route to change, and + /// still reports the end of what it handed out once the path goes offline. #[kio::test] async fn announced_does_not_retry_a_refusal_after_a_takeover() { let origin = Hop::new(1).unwrap().produce(); diff --git a/rs/moq-net/tests/integration/compress.rs b/rs/moq-net/tests/integration/compress.rs index cac10dd120d..140957d3803 100644 --- a/rs/moq-net/tests/integration/compress.rs +++ b/rs/moq-net/tests/integration/compress.rs @@ -101,7 +101,13 @@ async fn relay(published: Published, hops: [&str; 2], subscription: moq_net::tra let downstream = connect_mock(options).await; let consumer = origin.consume(); - let remote = consumer.follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = consumer + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); let subscriber = remote.track("data").unwrap().subscribe(subscription).await.unwrap(); support::harness::subscribed(&track).await; diff --git a/rs/moq-net/tests/integration/range_fill.rs b/rs/moq-net/tests/integration/range_fill.rs index 4926ef454f0..6792429dbd2 100644 --- a/rs/moq-net/tests/integration/range_fill.rs +++ b/rs/moq-net/tests/integration/range_fill.rs @@ -63,7 +63,14 @@ impl Fixture { options.server_publish = Some(publisher.consume()); options.client_subscribe = Some(copy.clone()); let pair = connect_mock(options).await; - let remote = copy.consume().follow("bcast", None).unwrap().available().await.unwrap().unwrap(); + let remote = copy + .consume() + .follow("bcast", None) + .unwrap() + .available() + .await + .unwrap() + .unwrap(); Self { track, remote, diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 896848c0d9f..60eee46dabe 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -2650,7 +2650,15 @@ mod tests { let (cluster, driver) = Cluster::new(with_stats()).unwrap(); let consumer = cluster.origin.consume(); let path = Path::from_static(".stats/node"); - let announced = async { consumer.follow(&path, None).unwrap().available().await.unwrap().unwrap() }; + let announced = async { + consumer + .follow(&path, None) + .unwrap() + .available() + .await + .unwrap() + .unwrap() + }; let futures::future::Either::Right((broadcast, driver)) = futures::future::select(Box::pin(driver.run()), Box::pin(announced)).await else { diff --git a/rs/moq-room/src/room.rs b/rs/moq-room/src/room.rs index 416ca31a293..6d6cf5aa675 100644 --- a/rs/moq-room/src/room.rs +++ b/rs/moq-room/src/room.rs @@ -113,7 +113,7 @@ impl Room { } /// The next broadcast a participant's follower hands out. A refusal, such as a handler - /// refusing the path, yields nothing: the follower waits for another instance to serve it, + /// refusing the path, yields nothing: the follower waits for the serving route to change, /// and the participant's end comes from the listing. fn poll_participants(&mut self, waiter: &kio::Waiter) -> Poll { let mut index = 0; diff --git a/rs/moq-tokio/tests/integration/relay_fill.rs b/rs/moq-tokio/tests/integration/relay_fill.rs index c54a07e6679..12fe84fd356 100644 --- a/rs/moq-tokio/tests/integration/relay_fill.rs +++ b/rs/moq-tokio/tests/integration/relay_fill.rs @@ -91,7 +91,12 @@ impl Relay { async fn fetch(&mut self, sequence: u64) -> anyhow::Result { self.command("dial", "dialed").await?; let viewer = self.viewers.recv().await.context("no downstream session")?; - let remote = viewer.consume().follow("history", None)?.available().await?.context("offline")?; + let remote = viewer + .consume() + .follow("history", None)? + .available() + .await? + .context("offline")?; let mut group = remote.track("video")?.fetch_group(sequence, None).await?; let frame = group.read_frame().await?.context("empty group")?; Ok(String::from_utf8(frame.payload.to_vec())?) @@ -101,7 +106,12 @@ impl Relay { async fn subscribe(&mut self, subscription: Subscription) -> anyhow::Result { self.command("dial", "dialed").await?; let viewer = self.viewers.recv().await.context("no downstream session")?; - let remote = viewer.consume().follow("history", None)?.available().await?.context("offline")?; + let remote = viewer + .consume() + .follow("history", None)? + .available() + .await? + .context("offline")?; Ok(remote.track("video")?.subscribe(subscription).await?) } } diff --git a/swift/MIGRATE.md b/swift/MIGRATE.md index b5d61427380..a346c81e28d 100644 --- a/swift/MIGRATE.md +++ b/swift/MIGRATE.md @@ -24,6 +24,7 @@ while true { play(broadcast) } ``` + ### Catalog renditions carry their warmup ([#7864](https://github.com/moq-dev/moq/pull/7864)) `Media.Video` and `Media.Audio` gain `warmup`, the catalog's decoder warmup; it defaults to `nil`, so existing initializers still compile. `Media.TrackConsumer` and the audio and video consumers read it from the rendition and start that much earlier. From 9c8adbe7ff9837a94b5039ed91969ebbadabb39d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 4 Nov 2026 23:17:12 -0800 Subject: [PATCH 19/21] fix: keep the moq-boy and echo followers past a refusal The listing reports nothing new when a publisher takes over a path that stays present, so a reader that quit on a refusal never saw the takeover. Only an origin close ends them now. Co-Authored-By: Claude Opus 5.5 --- rs/moq-boy/src/input.rs | 51 +++++++++++++++++++++++++++++++++------- rs/moq-cli/src/report.rs | 32 ++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 10 deletions(-) diff --git a/rs/moq-boy/src/input.rs b/rs/moq-boy/src/input.rs index 3e5ab0137c9..c88712251cb 100644 --- a/rs/moq-boy/src/input.rs +++ b/rs/moq-boy/src/input.rs @@ -91,7 +91,8 @@ pub async fn handle_viewers( } /// Read the commands of each broadcast a viewer publishes at `path`, switching to the new one -/// when the viewer restarts. +/// when the viewer restarts. A refused resolution waits for the serving route to change, since +/// the listing reports nothing new while the path stays present. async fn follow_viewer( origin: moq_net::origin::Consumer, path: moq_net::Path, @@ -101,20 +102,27 @@ async fn follow_viewer( let Ok(mut following) = origin.follow(&path, None) else { return; }; - let mut next = following.available().await; - while let Ok(Some(broadcast)) = next { - tracing::info!(%viewer_id, "viewer connected"); - next = tokio::select! { - read = handle_viewer_commands(&viewer_id, broadcast, &cmd_tx) => { + let mut reading = None; + loop { + tokio::select! { + change = following.available() => match change { + Ok(Some(broadcast)) => { + tracing::info!(%viewer_id, "viewer connected"); + reading = Some(Box::pin(handle_viewer_commands(&viewer_id, broadcast, &cmd_tx))); + } + Ok(None) => {} + Err(moq_net::Error::Closed) => return, + Err(err) => tracing::debug!(%viewer_id, %err, "viewer not resolved; waiting for a route change"), + }, + read = async { reading.as_mut().expect("guarded").await }, if reading.is_some() => { + reading = None; if let Err(e) = read { tracing::warn!(%viewer_id, error = %e, "viewer command error"); } tracing::info!(%viewer_id, "viewer disconnected"); let _ = cmd_tx.send(Command::ViewerLeft { viewer_id: viewer_id.clone() }).await; - following.available().await } - changed = following.available() => changed, - }; + } } } @@ -262,4 +270,29 @@ mod tests { kio::clock::sleep(Duration::from_secs(1)).await; assert!(rx.try_recv().is_err(), "the old reader is still running"); } + + /// A viewer whose handler refuses it stays followed: the listing reports nothing new when a + /// publisher takes the path over, so only the follower can pick it up. + #[tokio::test(start_paused = true)] + async fn a_refused_viewer_is_read_once_a_publisher_takes_over() { + let (origin, driver) = moq_net::origin::Producer::new(moq_net::origin::Config::default()); + tokio::spawn(moq_net::time::run(driver)); + let (tx, mut rx) = tokio::sync::mpsc::channel(16); + let consumer = origin.consume(); + tokio::spawn(async move { handle_viewers(&consumer, &tx).await }); + + let claim = origin.requests("alice").unwrap(); + kio::clock::timeout(Duration::from_secs(1), claim.requested_broadcast()) + .await + .expect("never asked") + .expect("the claim closed") + .reject(moq_net::Error::NotFound); + kio::clock::sleep(Duration::from_secs(1)).await; + + let (_viewer, track) = viewer(&origin); + kio::clock::sleep(Duration::from_secs(1)).await; + send(&track, r#"{"type":"reset"}"#); + let next = kio::clock::timeout(Duration::from_secs(1), rx.recv()).await; + assert!(matches!(next, Ok(Some(Command::Reset))), "{next:?}"); + } } diff --git a/rs/moq-cli/src/report.rs b/rs/moq-cli/src/report.rs index 72dba5c8cab..43f68a82b66 100644 --- a/rs/moq-cli/src/report.rs +++ b/rs/moq-cli/src/report.rs @@ -574,7 +574,10 @@ async fn read_echo(origin: moq_net::origin::Consumer, path: moq_net::Path, lines change = following.available() => match change { Ok(Some(broadcast)) => reading = Some(Box::pin(read_feedback(broadcast, path.clone(), lines.clone()))), Ok(None) => {} - Err(err) => return tracing::debug!(%err, path = %path.as_str(), "stopped reading feedback"), + Err(moq_net::Error::Closed) => return, + // The listing reports nothing new while the path stays present, so a refusal + // waits here for the serving route to change. + Err(err) => tracing::debug!(%err, path = %path.as_str(), "feedback not resolved; waiting for a route change"), }, read = async { reading.as_mut().expect("guarded").await }, if reading.is_some() => { reading = None; @@ -675,6 +678,33 @@ mod tests { assert!(late.is_err(), "a drained reader wrote {late:?}"); } + /// A refused path stays followed: the listing reports nothing new when a publisher takes it + /// over, so only the follower can pick it up. + #[tokio::test(start_paused = true)] + async fn a_refused_feedback_path_is_read_once_a_publisher_takes_over() { + let origin = moq_tokio::origin::spawn(); + let (out, read) = tokio::io::duplex(4096); + let mut lines = BufReader::new(read).lines(); + tokio::spawn(write_echo(origin.consume(), String::new(), out)); + + let claim = origin.requests("viewer.echo").unwrap(); + kio::clock::timeout(Duration::from_secs(1), claim.requested_broadcast()) + .await + .expect("never asked") + .expect("the claim closed") + .reject(moq_net::Error::NotFound); + kio::clock::sleep(Duration::from_secs(1)).await; + + let broadcast = origin.create_broadcast("viewer.echo").unwrap(); + let track = broadcast.create_track(hang::echo::TRACK, None).unwrap(); + let mut feedback = moq_json::snapshot::Producer::::new(track, Default::default()); + broadcast.announce(Default::default()).unwrap(); + feedback.update(&serde_json::json!({ "n": 1 })).unwrap(); + let line = kio::clock::timeout(Duration::from_secs(5), lines.next_line()).await; + let line = line.expect("the takeover was never read").unwrap().unwrap(); + assert!(line.contains(r#""n":1"#), "{line}"); + } + /// A reader is forgotten once its drain passes, unless a start at its path replaced it. #[tokio::test(start_paused = true)] async fn a_drained_reader_is_forgotten() { From f5c5ee3faa2b2f58bea8566b6e787ab7b9fac4c3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 4 Nov 2026 23:41:31 -0800 Subject: [PATCH 20/21] fix(carla): read driver control with the self-subscribing snapshot consumer Main's #7736 has moq.json.SnapshotConsumer take the broadcast and track name; publish.py and its test fake still used the subscribed track. Co-Authored-By: Claude Opus 5.5 --- demo/carla/sim/moq_carla_sim/publish.py | 2 +- demo/carla/sim/tests/conftest.py | 7 ++++--- demo/carla/sim/tests/test_publish.py | 6 +----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/demo/carla/sim/moq_carla_sim/publish.py b/demo/carla/sim/moq_carla_sim/publish.py index 27a6a6fc383..34f334ce683 100644 --- a/demo/carla/sim/moq_carla_sim/publish.py +++ b/demo/carla/sim/moq_carla_sim/publish.py @@ -389,7 +389,7 @@ async def _pump_driver( """ log.info("driver %s connected (run %s)", driver_id, instance) try: - control = moq.json.SnapshotConsumer(await broadcast.subscribe_track("control")) + control = moq.json.SnapshotConsumer(broadcast, "control") async for message in control: command = parse_command(driver_id, message.value, instance) if command is not None: diff --git a/demo/carla/sim/tests/conftest.py b/demo/carla/sim/tests/conftest.py index e7efe0f55d5..1aa31b9689e 100644 --- a/demo/carla/sim/tests/conftest.py +++ b/demo/carla/sim/tests/conftest.py @@ -40,10 +40,11 @@ def update(self, value: object, timestamp: object) -> None: class SnapshotConsumer: - """Wraps parsed fake values in timed records, like the runtime consumer.""" + """Reads the named fake track of a broadcast, wrapping its parsed values in timed records, + like the runtime consumer.""" - def __init__(self, track: object) -> None: - self._track = track + def __init__(self, broadcast: object, name: str, *, priority: int = 0) -> None: + self._track = broadcast.tracks[name] async def __aiter__(self): async for value in self._track: diff --git a/demo/carla/sim/tests/test_publish.py b/demo/carla/sim/tests/test_publish.py index a68c5e77307..c4736d765ab 100644 --- a/demo/carla/sim/tests/test_publish.py +++ b/demo/carla/sim/tests/test_publish.py @@ -246,11 +246,7 @@ async def control(): yield {"type": "drive", "sequence": sequence, "throttle": 0.5} await asyncio.Event().wait() - async def subscribe_track(name: str): - assert name == "control" - return control() - - await self.send(SimpleNamespace(subscribe_track=subscribe_track)) + await self.send(SimpleNamespace(tracks={"control": control()})) async def offline(self) -> None: await self.send(None) From a18da85e188bac58cb5cde43958998b5a42aa35d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 4 Nov 2026 23:49:56 -0800 Subject: [PATCH 21/21] fix(bench): the fan-out session harness reads the optional follow result Co-Authored-By: Claude Opus 5.5 --- bench/fanout/session/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bench/fanout/session/src/main.rs b/bench/fanout/session/src/main.rs index 88d07fea4f4..6c841192bd7 100644 --- a/bench/fanout/session/src/main.rs +++ b/bench/fanout/session/src/main.rs @@ -87,7 +87,8 @@ fn main() { .unwrap() .available() .await - .expect("broadcast resolves"); + .expect("broadcast resolves") + .expect("the room is online"); let subscriber = remote.track("chat").unwrap().subscribe(None).await.expect("subscribe"); audience.push((sessions, local, subscriber)); }