From 2d1670bf57284c731f968ae6ebbbb64f19a21ef7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 04:58:59 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m2/api-shape/net.md Quest-Claim: c96bdf994b95eeb8 From 998cdf34821618424142bd6121b680a54cf2bedf Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 05:11:19 -0800 Subject: [PATCH 2/3] feat(net)!: route stream goes public; RouteEvent is kind + announce Co-Authored-By: Claude Opus 5.5 --- quest/m2/api-shape/README.md | 1 - quest/m2/api-shape/net.md | 43 --- quest/m2/instance-provenance.md | 5 - quest/m3/qos/lag-histogram.md | 2 +- quest/m3/session-outcome-records.md | 2 +- quest/m5/rate-grant.md | 2 +- rs/moq-cli/tests/integration/export.rs | 5 +- rs/moq-cli/tests/integration/instances.rs | 49 ++- rs/moq-cli/tests/integration/rtsp.rs | 10 +- rs/moq-gst/src/source/imp.rs | 213 +++++++++++-- rs/moq-net-tests/tests/integration/restart.rs | 99 +++++- rs/moq-net/benches/announce.rs | 19 +- rs/moq-net/benches/auth.rs | 18 +- rs/moq-net/benches/origin.rs | 23 +- rs/moq-net/benches/session/mod.rs | 22 +- rs/moq-net/src/auth.rs | 12 +- rs/moq-net/src/ietf/publisher.rs | 32 +- rs/moq-net/src/ietf/subscriber.rs | 13 +- rs/moq-net/src/lite/publisher.rs | 67 +++- rs/moq-net/src/lite/replay.rs | 12 +- rs/moq-net/src/model/announced.rs | 33 +- rs/moq-net/src/model/follow.rs | 140 ++++++--- rs/moq-net/src/model/mod.rs | 2 +- rs/moq-net/src/model/origin.rs | 286 +++++++++++++----- .../integration/announce_covering_route.rs | 9 +- .../tests/integration/announce_to_serve.rs | 10 +- rs/moq-net/tests/integration/auth.rs | 13 +- .../tests/integration/catalog_acquisition.rs | 15 +- .../tests/integration/claim_continues.rs | 20 +- .../tests/integration/dial_split_horizon.rs | 21 +- rs/moq-net/tests/integration/extensions.rs | 15 +- rs/moq-net/tests/integration/goaway.rs | 8 +- rs/moq-net/tests/integration/instance.rs | 15 +- .../tests/integration/lazy_discovery.rs | 39 ++- rs/moq-net/tests/integration/mount.rs | 10 +- rs/moq-net/tests/integration/multi_cdn.rs | 42 ++- rs/moq-net/tests/integration/rejoin.rs | 13 +- rs/moq-net/tests/integration/replacement.rs | 10 +- rs/moq-net/tests/integration/route_change.rs | 30 +- rs/moq-net/tests/integration/session_panic.rs | 12 +- rs/moq-net/tests/integration/support/mod.rs | 29 +- rs/moq-net/tests/integration/synced.rs | 19 +- rs/moq-relay/src/cluster.rs | 20 +- rs/moq-relay/src/internal.rs | 15 +- rs/moq-relay/src/web.rs | 8 +- rs/moq-relay/tests/drills.rs | 13 +- .../tests/integration/auth_lifetime.rs | 13 +- .../tests/integration/cluster_fresh_port.rs | 6 +- .../tests/integration/cluster_idle.rs | 12 +- .../tests/integration/cluster_unknown.rs | 13 +- rs/moq-relay/tests/integration/connection.rs | 15 +- rs/moq-relay/tests/integration/embed.rs | 13 +- .../tests/integration/goaway_cluster.rs | 16 +- .../tests/integration/hidden_cluster.rs | 6 +- rs/moq-relay/tests/integration/memory.rs | 15 +- .../tests/integration/public_rules.rs | 5 +- .../tests/integration/runtime_uring.rs | 13 +- .../tests/integration/runtime_workers.rs | 13 +- rs/moq-relay/tests/integration/smoke.rs | 19 +- .../tests/integration/tenant_matrix.rs | 20 +- .../tests/integration/upstream_links.rs | 6 +- rs/moq-rtmp/src/server.rs | 8 +- rs/moq-stats/src/aggregate.rs | 32 +- rs/moq-stats/src/consume.rs | 15 +- rs/moq-stats/src/produce.rs | 15 +- rs/moq-tokio/tests/integration/broadcast.rs | 13 +- 66 files changed, 1303 insertions(+), 461 deletions(-) delete mode 100644 quest/m2/api-shape/net.md diff --git a/quest/m2/api-shape/README.md b/quest/m2/api-shape/README.md index c32ca6acaf8..724d4e6a156 100644 --- a/quest/m2/api-shape/README.md +++ b/quest/m2/api-shape/README.md @@ -59,5 +59,4 @@ Rejected in planning: ## Required -- [moq-net's route stream goes public](/quest/m2/api-shape/net.md) - un-hide `origin::Consumer::routes` and reshape `RouteEvent`, now that #8063 merged - [JS Key.sign takes exactly Claims](/quest/m2/api-shape/auth-sign.md) - `@moq/auth` signs only `Claims`, with no legacy `put`/`get` input, like Rust diff --git a/quest/m2/api-shape/net.md b/quest/m2/api-shape/net.md deleted file mode 100644 index 9a7d17ae002..00000000000 --- a/quest/m2/api-shape/net.md +++ /dev/null @@ -1,43 +0,0 @@ -# [S] moq-net's route stream goes public - -## Goal - -The rest of moq-net's small surface fixes, with their JS mirrors: - -- Un-hide `origin::Consumer::routes`, `Routes`, and `RouteEvent`, documented - as the relay-level stream that moq-relay and downstream relays already - consume, and fix `request`'s doc to say what - [moq-dev/moq#8063](https://github.com/moq-dev/moq/pull/8063) made it do. - `RouteEvent` becomes `pub struct RouteEvent { pub kind: RouteKind, pub - announce: Announce }` with `pub enum RouteKind { Start, Update, Restart, End }`, - mirroring JS's `{ kind } & Routed`, so callers need no or-pattern and no - accessors. - -## Plan - -Found by the 2026-11-07 API shape audit (net model and net session); see -the [epic](/quest/m2/api-shape/README.md). The rest of the audit's items landed in -[moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266). The un-hide -waited on #8063 removing `RouteEvent::Takeover`; #8063 has merged, so it is -unblocked. The `RouteEvent` reshape replaces -[moq-dev/moq#7862](https://github.com/moq-dev/moq/pull/7862)'s accessors, which -closed without taking it. - -Decided 2026-11-08 (maintainer): ✅ `group::Demand` and -`group::Producer::demand` stay public, documented for paced flights -(rejected: fold reader demand into `Fill::poll_unwanted` then make it -private; make it private and move the flight test and bench in-crate). -`Fill::poll_unwanted` resolves as soon as readers take the group, while a -paced flight has to see its riders leave; `tests/integration/flights.rs` and -`benches/group.rs` use it for that. Its docs say so since -[moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266). - -Decided 2026-11-08 (maintainer): whether a route refuses a minted instance -is replaced by [Minted instances are a typed flag](/quest/m2/instance-provenance.md). -The `~` prefix is a spoofable in-band sentinel; once only a session can mint -an instance, the route needs no refusal. - -## Related - -- [Minted instances are a typed flag](/quest/m2/instance-provenance.md) - - replaces this quest's minted-route refusal item diff --git a/quest/m2/instance-provenance.md b/quest/m2/instance-provenance.md index f50b685128b..e6a826b05e7 100644 --- a/quest/m2/instance-provenance.md +++ b/quest/m2/instance-provenance.md @@ -72,8 +72,3 @@ lite-07 (SUBSCRIBE_DROP and SUBSCRIBE_SKIP ranges) and touches `lite/subscriber.rs`, `lite/subscribe.rs`, their JS mirrors, and the lite draft, but not the instance encoding; expect textual conflicts only, and whichever lands second adds its changelog line beside the other's. - -## Related - -- [moq-net's route stream goes public](/quest/m2/api-shape/net.md) - the - audit item this replaces diff --git a/quest/m3/qos/lag-histogram.md b/quest/m3/qos/lag-histogram.md index dd8d4674d03..d7288415bc7 100644 --- a/quest/m3/qos/lag-histogram.md +++ b/quest/m3/qos/lag-histogram.md @@ -98,7 +98,7 @@ re-exported by `moq-stats`. Wire: the stats JSON gains the egress fields. Update `doc/concept/stats.md` and the stats section of `doc/bin/relay/config.md`. -Changed 2026-11-07 (maintainer, /quest-plan from the API sweep of open PRs and remaining quests): [api-shape/net](/quest/m2/api-shape/net.md) makes `stats::Registry::report` take `now` and the handle's arguments `#[non_exhaustive]` before the cut, so this adds fields and is not breaking. +Changed 2026-11-07 (maintainer, /quest-plan from the API sweep of open PRs and remaining quests): [moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266) makes `stats::Registry::report` take `now` and the handle's arguments `#[non_exhaustive]` before the cut, so this adds fields and is not breaking. ## Required diff --git a/quest/m3/session-outcome-records.md b/quest/m3/session-outcome-records.md index 65ca1911446..a9d8bf429b7 100644 --- a/quest/m3/session-outcome-records.md +++ b/quest/m3/session-outcome-records.md @@ -57,4 +57,4 @@ Tests: a refused session and an abnormal end each produce exactly one record under the right label; a flood past the rate produces summaries whose counts match the counters; an admitted session that ends normally produces none. -Changed 2026-11-07 (maintainer, /quest-plan from the API sweep of open PRs and remaining quests): [api-shape/net](/quest/m2/api-shape/net.md) makes `stats::Handle::{refuse, session}` take `#[non_exhaustive]` structs before the cut, so the records add fields and are not breaking. +Changed 2026-11-07 (maintainer, /quest-plan from the API sweep of open PRs and remaining quests): [moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266) makes `stats::Handle::{refuse, session}` take `#[non_exhaustive]` structs before the cut, so the records add fields and are not breaking. diff --git a/quest/m5/rate-grant.md b/quest/m5/rate-grant.md index 83236b96a43..ab9d37fec62 100644 --- a/quest/m5/rate-grant.md +++ b/quest/m5/rate-grant.md @@ -45,4 +45,4 @@ Public API: the in-band grant types in `rs/moq-net` and `js/net` gain the two rates, and the publishers gain a clamp. Wire: the AUTH grant gains optional rates, on the next unpublished lite version after lite-07 only. -Changed 2026-11-07 (maintainer, /quest-plan from the API sweep of open PRs and remaining quests): [api-shape/net](/quest/m2/api-shape/net.md) makes `auth::Grant` `#[non_exhaustive]` before the cut, so the rates are additive fields. +Changed 2026-11-07 (maintainer, /quest-plan from the API sweep of open PRs and remaining quests): [moq-dev/moq#8266](https://github.com/moq-dev/moq/pull/8266) makes `auth::Grant` `#[non_exhaustive]` before the cut, so the rates are additive fields. diff --git a/rs/moq-cli/tests/integration/export.rs b/rs/moq-cli/tests/integration/export.rs index 737490f8348..6f4234fa1a8 100644 --- a/rs/moq-cli/tests/integration/export.rs +++ b/rs/moq-cli/tests/integration/export.rs @@ -1064,7 +1064,10 @@ async fn next_instance(announced: &mut moq_net::origin::Routes) -> moq_net::Inst kio::clock::timeout(TIMEOUT, async { loop { match announced.next().await.expect("the relay stays up") { - moq_net::origin::RouteEvent::Start(announce) | moq_net::origin::RouteEvent::Restart(announce) => { + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Restart, + announce, + } => { return announce.route.instance().clone(); } _ => continue, diff --git a/rs/moq-cli/tests/integration/instances.rs b/rs/moq-cli/tests/integration/instances.rs index 8e0ae972275..f487bd14a5f 100644 --- a/rs/moq-cli/tests/integration/instances.rs +++ b/rs/moq-cli/tests/integration/instances.rs @@ -106,12 +106,27 @@ fn publish(origin: &origin::Producer, instance: &Instance, tag: &str) -> Publish async fn changed(follow: &mut origin::Routes) -> bool { loop { match follow.next().await.unwrap() { - origin::RouteEvent::Restart(_) => return true, - origin::RouteEvent::End(_) => { - assert!(matches!(follow.next().await, Some(origin::RouteEvent::Start(_)))); + origin::RouteEvent { + kind: origin::RouteKind::Restart, + .. + } => return true, + origin::RouteEvent { + kind: origin::RouteKind::End, + .. + } => { + assert!(matches!( + follow.next().await, + Some(origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + }) + )); return false; } - origin::RouteEvent::Update(_) => {} + origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + } => {} other => panic!("expected replacement, got {other:?}"), } } @@ -146,9 +161,18 @@ async fn replacement(version: &str) { .unwrap(); assert!(matches!( catalog_follow.next().await, - Some(origin::RouteEvent::Start(_)) + Some(origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + }) + )); + assert!(matches!( + media_follow.next().await, + Some(origin::RouteEvent { + kind: origin::RouteKind::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); @@ -380,7 +404,13 @@ async fn a_player_reads_through_a_claim_on_its_first_request() { .established() .await .unwrap(); - assert!(matches!(routes.next().await, Some(origin::RouteEvent::Start(_)))); + assert!(matches!( + routes.next().await, + Some(origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + }) + )); let held = viewer.request("live/catalog.hang", None).await.unwrap(); let source = moq_mux::Source::new(viewer.clone(), held); @@ -414,7 +444,10 @@ async fn a_player_reads_through_a_claim_on_its_first_request() { assert_ne!(worker.claim.instance(), lent); loop { match routes.next().await.unwrap() { - origin::RouteEvent::End(end) if end.prefix.as_str() == "live/media" => break, + origin::RouteEvent { + kind: origin::RouteKind::End, + announce: end, + } if end.prefix.as_str() == "live/media" => break, _ => {} } } diff --git a/rs/moq-cli/tests/integration/rtsp.rs b/rs/moq-cli/tests/integration/rtsp.rs index 71a3e6ad663..3512a4c5e35 100644 --- a/rs/moq-cli/tests/integration/rtsp.rs +++ b/rs/moq-cli/tests/integration/rtsp.rs @@ -64,8 +64,14 @@ async fn next_broadcast( .await .expect("origin closed") { - moq_net::origin::RouteEvent::Start(_) | moq_net::origin::RouteEvent::Restart(_) => break, - moq_net::origin::RouteEvent::End(_) | moq_net::origin::RouteEvent::Update(_) => {} + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Restart, + .. + } => break, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End | moq_net::origin::RouteKind::Update, + .. + } => {} } } let broadcast = running(child, "the broadcast", consumer.request("camera", None)) diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index 6f780bd3f15..971708043da 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -4394,7 +4394,13 @@ mod session_tests { 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(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); follow } @@ -4518,11 +4524,23 @@ mod session_tests { 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(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); drop(first); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); let mut second = Publisher::sibling(&origin, Default::default()); @@ -4579,11 +4597,23 @@ mod session_tests { let mut follow = watch(&origin, "cam"); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Start(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); drop(first); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 3), pad, "the return moved to another pad"); @@ -4678,15 +4708,33 @@ mod session_tests { first.video.finish().unwrap(); await_finished(&first); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Start(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); first.route.as_ref().unwrap().withdraw(); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); first.route.as_ref().unwrap().announce().unwrap(); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Start(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); let mut second = Publisher::sibling(&origin, Default::default()); @@ -4734,14 +4782,26 @@ mod session_tests { let mut first = Publisher::sibling(&origin, None); let pad = recorder.written(&mut first, 1); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Start(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); // The pad plays out the failure while the instance is still announced. first.video.abort(moq_net::Error::Cancel); super::RUNTIME.block_on(pads.settled(&(TrackKind::Video, "video".to_string()))); first.route.as_ref().unwrap().withdraw(); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); // The returning instance serves the track again, from a later group. @@ -4821,11 +4881,23 @@ mod session_tests { room.catalog.finish().unwrap(); let mut follow = watch(&origin, "cam"); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Start(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); drop(first); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); let mut second = Publisher::sibling(&origin, Default::default()); @@ -5034,13 +5106,22 @@ mod session_tests { 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(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); drop(second); await_event(&mut follow, |event| { matches!( event, - moq_net::origin::RouteEvent::Restart(_) | moq_net::origin::RouteEvent::Start(_) + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Restart | moq_net::origin::RouteKind::Start, + .. + } ) }); @@ -5086,11 +5167,23 @@ mod session_tests { 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(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); drop(first); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); room.catalog.modify().unwrap().video.renditions.clear(); @@ -5107,7 +5200,13 @@ mod session_tests { let mut second = Publisher::sibling(&origin, Default::default()); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Start(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); for _ in 0..10 { second.write(2); @@ -5134,11 +5233,23 @@ mod session_tests { 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(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); drop(first); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); let listed = room.catalog.modify().unwrap().video.renditions.clone(); @@ -5214,17 +5325,35 @@ mod session_tests { // 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(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ) }); let mut new = Publisher::sibling(&origin, Default::default()); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Restart(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Restart, + .. + } + ) }); await_demand(&old, false); new.write(2); drop(new); await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::Restart(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Restart, + .. + } + ) }); await_demand(&old, true); @@ -5324,7 +5453,13 @@ mod session_tests { publisher.route.as_ref().unwrap().set_cost(5).unwrap(); await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::Update(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Update, + .. + } + ) }); recorder.written(&mut publisher, 2); stop(session); @@ -5509,7 +5644,13 @@ mod session_tests { old.catalog.finish().unwrap(); drop(old); await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); let mut new = Publisher::new(&origin, Default::default(), video_rendition()); @@ -5539,7 +5680,13 @@ mod session_tests { old.route.as_ref().unwrap().withdraw(); await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); drop(old); @@ -5614,7 +5761,13 @@ mod session_tests { let route = next.route.as_ref().unwrap(); route.withdraw(); await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); route.announce().unwrap(); assert_eq!( @@ -6110,7 +6263,13 @@ 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::origin::RouteEvent::End(_)) + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ) }); let mut new = Publisher::new(&relay.origin, Default::default(), video_rendition()); diff --git a/rs/moq-net-tests/tests/integration/restart.rs b/rs/moq-net-tests/tests/integration/restart.rs index e0d5b9dbe3d..8cf357e6321 100644 --- a/rs/moq-net-tests/tests/integration/restart.rs +++ b/rs/moq-net-tests/tests/integration/restart.rs @@ -67,11 +67,20 @@ async fn expect_restart(version: Version, announced: &mut origin::Routes, prefix /// place, so the path was never absent, or as an end then a start. async fn expect_replaced(version: Version, announced: &mut origin::Routes, prefix: &str, restarts: bool) { match next_event(announced).await { - origin::RouteEvent::Restart(announce) if restarts => assert_eq!(announce.prefix.as_str(), prefix), - origin::RouteEvent::End(announce) if !restarts => { + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce, + } if restarts => assert_eq!(announce.prefix.as_str(), prefix), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } if !restarts => { assert_eq!(announce.prefix.as_str(), prefix); match next_event(announced).await { - origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), prefix), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => assert_eq!(announce.prefix.as_str(), prefix), other => panic!("{version}: expected the start, got {other:?}"), } } @@ -125,7 +134,10 @@ async fn relay_chain(version: &str) { let old_track = old.broadcast().create_track("video", timed()).unwrap(); let mut announced = viewer.consume().routes(); match next_event(&mut announced).await { - origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected the route, got {other:?}"), } @@ -236,7 +248,10 @@ async fn prefix_pool(version: &str) { }; let mut announced = downstream.consume().routes(); match next_event(&mut announced).await { - origin::RouteEvent::Start(announce) => advertised(announce), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => advertised(announce), other => panic!("{version}: expected the pool, got {other:?}"), } @@ -264,7 +279,10 @@ 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 { - origin::RouteEvent::Restart(announce) => advertised(announce), + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce, + } => advertised(announce), other => panic!("{version}: expected a restart at most, got {other:?}"), } } @@ -356,7 +374,10 @@ async fn dynamic_instance(version: &str, from: Option, to: Instance) { let claim = Claim::new(&publisher, from.clone()); let mut announced = viewer.consume().routes(); match next_event(&mut announced).await { - origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected the claim, got {other:?}"), } @@ -368,7 +389,13 @@ async fn dynamic_instance(version: &str, from: Option, to: Instance) { claim.update_cost(5); while let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { assert!( - matches!(event, Some(origin::RouteEvent::Update(_))), + matches!( + event, + Some(origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + }) + ), "{version}: a re-price delivered {event:?}" ); } @@ -459,7 +486,13 @@ async fn retired_fetch(version: &str, explicit: bool) { let old = publisher.route("live", old_route).unwrap(); let old_track = old.broadcast().create_track("video", timed()).unwrap(); let mut announced = viewer.consume().routes(); - assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); + assert!(matches!( + next_event(&mut announced).await, + origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + } + )); let (held, mut subscription) = subscribe(&viewer, "live").await; let track = held.track("video").unwrap(); write(&old_track, "old:0"); @@ -538,7 +571,13 @@ async fn unanswered_takeover(version: &str) { // Quiet, so the publisher has nothing to answer the SUBSCRIBE with yet. let old_track = old.broadcast().create_track("video", timed()).unwrap(); let mut announced = viewer.consume().routes(); - assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); + assert!(matches!( + next_event(&mut announced).await, + origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + } + )); let (_held, mut subscription) = subscribe(&viewer, "live").await; settle().await; assert!( @@ -597,13 +636,25 @@ async fn withdrawal_refuses_new_fetches_but_keeps_open_reads() { let source = publisher.route("live", origin::RouteOptions::default()).unwrap(); let produced = source.broadcast().create_track("video", timed()).unwrap(); let mut announced = viewer.consume().routes(); - assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); + assert!(matches!( + next_event(&mut announced).await, + origin::RouteEvent { + kind: origin::RouteKind::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.withdraw(); - assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::End(_))); + assert!(matches!( + next_event(&mut announced).await, + origin::RouteEvent { + kind: origin::RouteKind::End, + .. + } + )); assert!(track.fetch_group(1, None).await.is_err(), "{version}"); write(&produced, "old:1"); assert_eq!(read(&mut subscription).await, "old:1"); @@ -619,7 +670,13 @@ async fn a_more_specific_source_cannot_fill_a_held_covering_track() { let _session = link(version, &publisher, &viewer).await; let old = Claim::new(&publisher, None); let mut announced = viewer.consume().routes(); - assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); + assert!(matches!( + next_event(&mut announced).await, + origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + } + )); let (held, mut subscription) = subscribe(&viewer, "live/job").await; let track = held.track("video").unwrap(); old.write(0, "old:0"); @@ -628,7 +685,13 @@ async fn a_more_specific_source_cannot_fill_a_held_covering_track() { let replacement_track = replacement.broadcast().create_track("video", timed()).unwrap(); write(&replacement_track, "new:0"); write(&replacement_track, "new:1"); - assert!(matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_))); + assert!(matches!( + next_event(&mut announced).await, + origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + } + )); assert!( track.fetch_group(1, None).await.is_err(), "{version}: covering handle fetched replacement" @@ -779,7 +842,13 @@ async fn priority_update(version: &str, relayed: bool, switch: bool) { let old_track = old.broadcast().create_track("video", timed()).unwrap(); let mut announced = viewer.consume().routes(); assert!( - matches!(next_event(&mut announced).await, origin::RouteEvent::Start(_)), + matches!( + next_event(&mut announced).await, + origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + } + ), "{case}" ); diff --git a/rs/moq-net/benches/announce.rs b/rs/moq-net/benches/announce.rs index 183fc21f188..38b4dd58a6c 100644 --- a/rs/moq-net/benches/announce.rs +++ b/rs/moq-net/benches/announce.rs @@ -34,10 +34,14 @@ fn scanned(events: Vec) -> Vec { let mut initial: Vec = Vec::new(); for event in events { let (update, active) = match event { - origin::RouteEvent::Start(update) - | origin::RouteEvent::Update(update) - | origin::RouteEvent::Restart(update) => (update, true), - origin::RouteEvent::End(update) => (update, false), + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Update | origin::RouteKind::Restart, + announce: update, + } => (update, true), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce: update, + } => (update, false), }; initial.retain(|held| held.prefix != update.prefix); if active { @@ -53,12 +57,13 @@ fn initial(c: &mut Criterion) { for updates in [1, 8, 32] { let events: Vec<_> = (0..updates) .flat_map(|cost| { - (0..routes).map(move |route| { - origin::RouteEvent::Update(announce::Announce { + (0..routes).map(move |route| origin::RouteEvent { + kind: origin::RouteKind::Update, + announce: announce::Announce { prefix: moq_net::Path::new(&format!("route/{route}")).unwrap(), captures: None, route: moq_net::fuzz::route_info([], cost, None), - }) + }, }) }) .collect(); diff --git a/rs/moq-net/benches/auth.rs b/rs/moq-net/benches/auth.rs index 163be6fb058..36502948713 100644 --- a/rs/moq-net/benches/auth.rs +++ b/rs/moq-net/benches/auth.rs @@ -305,11 +305,13 @@ fn waiting(c: &mut Criterion) { let mut seen = std::collections::HashSet::new(); while seen.len() < paths { match announced.next().await.unwrap() { - moq_net::origin::RouteEvent::Start(update) - | moq_net::origin::RouteEvent::Update(update) - | moq_net::origin::RouteEvent::Restart(update) - if update.prefix.as_str().starts_with(&prefix) => - { + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: update, + } if update.prefix.as_str().starts_with(&prefix) => { seen.insert(update.prefix); } _ => {} @@ -383,8 +385,10 @@ fn shared_requests(c: &mut Criterion) { } let mut seen = std::collections::HashSet::new(); while seen.len() < tokens * requests { - if let moq_net::origin::RouteEvent::Start(update) - | moq_net::origin::RouteEvent::Restart(update) = announced.next().await.unwrap() + if let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Restart, + announce: update, + } = announced.next().await.unwrap() && update.prefix.as_str().starts_with(&prefix) { seen.insert(update.prefix); diff --git a/rs/moq-net/benches/origin.rs b/rs/moq-net/benches/origin.rs index 650c77cd2b3..4f25e31b27f 100644 --- a/rs/moq-net/benches/origin.rs +++ b/rs/moq-net/benches/origin.rs @@ -586,7 +586,11 @@ 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::origin::RouteEvent::Restart(update) = event else { + let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Restart, + announce: update, + } = event + else { panic!("expected a restart: got {event:?}"); }; assert_eq!( @@ -702,7 +706,16 @@ fn bench_lend(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(origin::RouteEvent::Start(_))), "{event:?}"); + assert!( + matches!( + event, + Some(origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + }) + ), + "{event:?}" + ); } drop(request); drop(output); @@ -777,7 +790,11 @@ fn bench_subscribe(c: &mut Criterion) { b.iter(|| { let mut cursor = fleet.consumer.routes(); let mut replayed = 0; - while let Some(origin::RouteEvent::Start(_)) = cursor.next().now_or_never().flatten() { + while let Some(origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + }) = cursor.next().now_or_never().flatten() + { replayed += 1; } assert_eq!(replayed, publishers); diff --git a/rs/moq-net/benches/session/mod.rs b/rs/moq-net/benches/session/mod.rs index d943ef5d156..e71aa8fab63 100644 --- a/rs/moq-net/benches/session/mod.rs +++ b/rs/moq-net/benches/session/mod.rs @@ -745,7 +745,16 @@ impl Viewer { .unwrap() .routes(); let event = announced.next().await.expect("announced"); - assert!(matches!(event, moq_net::origin::RouteEvent::Start(_)), "{event:?}"); + assert!( + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + .. + } + ), + "{event:?}" + ); self.following.push(announced); } @@ -1911,7 +1920,16 @@ 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::origin::RouteEvent::End(_)), "{event:?}"); + assert!( + matches!( + event, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } + ), + "{event:?}" + ); retracted += 1; } let elapsed = start.elapsed(); diff --git a/rs/moq-net/src/auth.rs b/rs/moq-net/src/auth.rs index b144175fefe..72b2fe7500b 100644 --- a/rs/moq-net/src/auth.rs +++ b/rs/moq-net/src/auth.rs @@ -2737,9 +2737,10 @@ impl Enforce { return Poll::Ready(None); }; match event { - crate::origin::RouteEvent::Start(update) | crate::origin::RouteEvent::Update(update) - if !self.live.contains(&update.prefix) => - { + crate::origin::RouteEvent { + kind: crate::origin::RouteKind::Start | crate::origin::RouteKind::Update, + announce: update, + } if !self.live.contains(&update.prefix) => { if self.pending.iter().any(|gate| gate.path == update.prefix) { continue; } @@ -2753,7 +2754,10 @@ impl Enforce { } self.live.insert(gate.path); } - crate::origin::RouteEvent::End(update) => { + crate::origin::RouteEvent { + kind: crate::origin::RouteKind::End, + announce: update, + } => { self.live.remove(&update.prefix); self.pending.retain(|gate| gate.path != update.prefix); } diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 343b588eeba..4d342cbd403 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -4131,12 +4131,19 @@ impl Publisher { let mut initial = std::collections::BTreeMap::new(); while let Some(event) = announced.try_next() { match event { - crate::origin::RouteEvent::Start(update) - | crate::origin::RouteEvent::Update(update) - | crate::origin::RouteEvent::Restart(update) => { + crate::origin::RouteEvent { + kind: + crate::origin::RouteKind::Start + | crate::origin::RouteKind::Update + | crate::origin::RouteKind::Restart, + announce: update, + } => { initial.insert(update.prefix.clone(), update); } - crate::origin::RouteEvent::End(update) => { + crate::origin::RouteEvent { + kind: crate::origin::RouteKind::End, + announce: update, + } => { initial.remove(&update.prefix); } } @@ -5898,11 +5905,18 @@ impl ForwardNamespaces { } if let Poll::Ready(next) = self.announced.poll_next(waiter) { return Poll::Ready(NamespaceEvent::Update(next.map(|event| match event { - crate::origin::RouteEvent::Start(update) | crate::origin::RouteEvent::Update(update) => { - (update, true, false) - } - crate::origin::RouteEvent::Restart(update) => (update, true, true), - crate::origin::RouteEvent::End(update) => (update, false, false), + crate::origin::RouteEvent { + kind: crate::origin::RouteKind::Start | crate::origin::RouteKind::Update, + announce: update, + } => (update, true, false), + crate::origin::RouteEvent { + kind: crate::origin::RouteKind::Restart, + announce: update, + } => (update, true, true), + crate::origin::RouteEvent { + kind: crate::origin::RouteKind::End, + announce: update, + } => (update, false, false), }))); } if self.retry.poll(waiter).is_ready() { diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index d3b76f9e9ca..ecd332ef5ce 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -10836,10 +10836,15 @@ mod tests { fn routed_now(consumer: &crate::origin::Consumer, path: &str) -> Option { use futures::FutureExt; 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) => Some(announce.route), + crate::origin::RouteEvent { + kind: crate::origin::RouteKind::End, + .. + } => None, + crate::origin::RouteEvent { + kind: + crate::origin::RouteKind::Start | crate::origin::RouteKind::Update | crate::origin::RouteKind::Restart, + announce, + } => Some(announce.route), } } diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 57e795ef8f2..308c845da35 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -1230,12 +1230,16 @@ impl AnnounceRun { let mut current: HashMap = HashMap::new(); while let Some(event) = snapshot.try_next() { match event { - origin::RouteEvent::Start(update) - | origin::RouteEvent::Update(update) - | origin::RouteEvent::Restart(update) => { + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Update | origin::RouteKind::Restart, + announce: update, + } => { current.insert(update.prefix, update.route); } - origin::RouteEvent::End(update) => { + origin::RouteEvent { + kind: origin::RouteKind::End, + announce: update, + } => { current.remove(&update.prefix); } } @@ -1597,9 +1601,18 @@ impl AnnounceRun { }; let (update, active, restart) = match next { - Some(origin::RouteEvent::Start(update) | origin::RouteEvent::Update(update)) => (update, true, false), - Some(origin::RouteEvent::Restart(update)) => (update, true, true), - Some(origin::RouteEvent::End(update)) => (update, false, false), + Some(origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Update, + announce: update, + }) => (update, true, false), + Some(origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce: update, + }) => (update, true, true), + Some(origin::RouteEvent { + kind: origin::RouteKind::End, + announce: update, + }) => (update, false, false), None => { if self.initial.take().is_some() { stream.writer.buffer(&lite::AnnounceBroadcast::Synced)?; @@ -3605,14 +3618,38 @@ mod announce_test { route: origin::RouteInfo::new().with_cost(cost), }; let events = [ - 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)), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce: update("a", 1), + }, + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce: update("b", 2), + }, + origin::RouteEvent { + kind: origin::RouteKind::Update, + announce: update("a", 3), + }, + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce: update("c", 4), + }, + origin::RouteEvent { + kind: origin::RouteKind::End, + announce: update("b", 2), + }, + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce: update("c", 5), + }, + origin::RouteEvent { + kind: origin::RouteKind::End, + announce: update("c", 5), + }, + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce: update("b", 6), + }, ]; let initial: Vec<_> = super::super::replay::initial(events) .into_iter() diff --git a/rs/moq-net/src/lite/replay.rs b/rs/moq-net/src/lite/replay.rs index 29f826037f4..060b6a16fa1 100644 --- a/rs/moq-net/src/lite/replay.rs +++ b/rs/moq-net/src/lite/replay.rs @@ -10,10 +10,14 @@ pub(super) fn initial(events: impl IntoIterator) -> V let mut positions = HashMap::new(); for event in events { let (update, active) = match event { - origin::RouteEvent::Start(update) - | origin::RouteEvent::Update(update) - | origin::RouteEvent::Restart(update) => (update, true), - origin::RouteEvent::End(update) => (update, false), + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Update | origin::RouteKind::Restart, + announce: update, + } => (update, true), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce: update, + } => (update, false), }; if let Some(index) = positions.remove(&update.prefix) { pending[index] = None; diff --git a/rs/moq-net/src/model/announced.rs b/rs/moq-net/src/model/announced.rs index 4b2d6b8877e..a1b195b5496 100644 --- a/rs/moq-net/src/model/announced.rs +++ b/rs/moq-net/src/model/announced.rs @@ -2,7 +2,7 @@ use std::task::Poll; -use super::origin_impl::{Announce, RouteEvent, Routes}; +use super::origin_impl::{Announce, RouteEvent, RouteKind, Routes}; use crate::{Error, Path}; /// What an announcement listing reports for a path. @@ -32,9 +32,18 @@ impl AnnounceConsumer { /// 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)), - RouteEvent::Update(_) | RouteEvent::Restart(_) => None, + RouteEvent { + kind: RouteKind::Start, + announce, + } => Some(AnnounceEvent::Present(announce)), + RouteEvent { + kind: RouteKind::End, + announce, + } => Some(AnnounceEvent::Absent(announce)), + RouteEvent { + kind: RouteKind::Update | RouteKind::Restart, + .. + } => None, } } @@ -164,7 +173,13 @@ mod tests { let first = origin.route("live", route(&Instance::random())).unwrap(); assert_eq!(listed(&mut announced).await, "present live"); - assert!(matches!(routes.next().await, Some(RouteEvent::Start(_)))); + assert!(matches!( + routes.next().await, + Some(RouteEvent { + kind: RouteKind::Start, + .. + }) + )); first .announce_info( @@ -175,7 +190,13 @@ mod tests { .unwrap(); quiet(&mut announced).await; // The relay-level stream still reports the replacement. - assert!(matches!(routes.next().await, Some(RouteEvent::Restart(_)))); + assert!(matches!( + routes.next().await, + Some(RouteEvent { + kind: RouteKind::Restart, + .. + }) + )); let second = origin.route("live", route(&Instance::random())).unwrap(); drop(first); diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index b061da491e1..c4ed0ae6fa4 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, Consumer, Moved, Requesting, RouteEvent, Routes}; +use super::origin_impl::{Announce, Consumer, Moved, Requesting, RouteEvent, RouteKind, Routes}; use crate::{Error, Instance, Path, broadcast}; /// The announcements covering one path, as one broadcast coming online, being replaced, and @@ -9,9 +9,9 @@ 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`](RouteEvent::Restart), unless both +/// through. Another route taking over is a [`Restart`](RouteKind::Restart), unless both /// carry the same instance: those serve one continuous stream, so it is an -/// [`Update`](RouteEvent::Update), as for a job's route continuing the prefix route it +/// [`Update`](RouteKind::Update), as for a job's route continuing the prefix route it /// answered. Routes beneath the path serve other broadcasts and are ignored. pub(crate) struct Follow { announced: Routes, @@ -81,7 +81,10 @@ impl Follow { return match (self.serving().map(|standing| standing.announce.clone()), ended) { (Some(serving), _) => { self.idle = false; - Poll::Ready(Some(RouteEvent::Start(serving))) + Poll::Ready(Some(RouteEvent { + kind: RouteKind::Start, + announce: serving, + })) } (None, true) => Poll::Ready(None), (None, false) => Poll::Pending, @@ -93,7 +96,13 @@ impl Follow { return Poll::Ready(None); }; if let Some(event) = self.fold(event) { - self.idle = matches!(event, RouteEvent::End(_)); + self.idle = matches!( + event, + RouteEvent { + kind: RouteKind::End, + .. + } + ); return Poll::Ready(Some(event)); } } @@ -126,10 +135,14 @@ impl Follow { /// Apply one route's event, returning what it means for the path, if anything. fn fold(&mut self, event: RouteEvent) -> Option { - let (RouteEvent::Start(announce) - | RouteEvent::Update(announce) - | RouteEvent::Restart(announce) - | RouteEvent::End(announce)) = &event; + let (RouteEvent { + kind: RouteKind::Start | RouteKind::Update, + announce, + } + | RouteEvent { + kind: RouteKind::Restart | RouteKind::End, + announce, + }) = &event; if !self.path.has_prefix(&announce.prefix) { return None; } @@ -144,10 +157,21 @@ impl Follow { .position(|standing| standing.announce.prefix == prefix) .map(|index| self.covering.swap_remove(index).since); let (announce, since, restart) = match event { - RouteEvent::End(_) => (None, None, false), - RouteEvent::Start(announce) => (Some(announce), None, false), - RouteEvent::Update(announce) => (Some(announce), standing, false), - RouteEvent::Restart(announce) => (Some(announce), standing, true), + RouteEvent { + kind: RouteKind::End, .. + } => (None, None, false), + RouteEvent { + kind: RouteKind::Start, + announce, + } => (Some(announce), None, false), + RouteEvent { + kind: RouteKind::Update, + announce, + } => (Some(announce), standing, false), + RouteEvent { + kind: RouteKind::Restart, + announce, + } => (Some(announce), standing, true), }; if let Some(announce) = announce { self.covering.push(Standing { @@ -162,25 +186,46 @@ impl Follow { .map(|standing| (standing.announce.clone(), standing.since)); match (before, after) { (None, None) => None, - (None, Some((after, _))) => Some(RouteEvent::Start(after)), - (Some((before, _)), None) => Some(RouteEvent::End(before)), + (None, Some((after, _))) => Some(RouteEvent { + kind: RouteKind::Start, + announce: after, + }), + (Some((before, _)), None) => Some(RouteEvent { + kind: RouteKind::End, + announce: 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(RouteEvent::End(before)) + Some(RouteEvent { + kind: RouteKind::End, + announce: before, + }) } (Some((before, _)), Some((after, _))) if before.prefix != after.prefix => { let same = before.route.instance == after.route.instance; Some(match same { - true => RouteEvent::Update(after), - false => RouteEvent::Restart(after), + true => RouteEvent { + kind: RouteKind::Update, + announce: after, + }, + false => RouteEvent { + kind: RouteKind::Restart, + announce: 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(RouteEvent::Restart(after)), - (Some(_), Some((after, _))) => Some(RouteEvent::Update(after)), + (Some(_), Some((after, _))) if restart => Some(RouteEvent { + kind: RouteKind::Restart, + announce: after, + }), + (Some(_), Some((after, _))) => Some(RouteEvent { + kind: RouteKind::Update, + announce: after, + }), } } } @@ -364,27 +409,40 @@ impl Following { match event { // 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)) => + RouteEvent { + kind: RouteKind::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. - RouteEvent::Start(_) | RouteEvent::Restart(_) => self.unseen = true, + RouteEvent { + kind: RouteKind::Start | RouteKind::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. - RouteEvent::End(_) => { + RouteEvent { + kind: RouteKind::End, .. + } => { self.unseen = false; self.end(); } // After a refusal, another route may answer what the last one refused. - RouteEvent::Update(_) if self.refused => self.unseen = true, + RouteEvent { + kind: RouteKind::Update, + .. + } if self.refused => self.unseen = true, // The same instance over another route, which its subscriptions ride out. - RouteEvent::Update(_) => return false, + RouteEvent { + kind: RouteKind::Update, + .. + } => return false, } true } @@ -408,10 +466,22 @@ mod tests { .expect("no event") .expect("the origin closed"); match event { - 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::End(announce) => ("end", announce.prefix.to_string()), + RouteEvent { + kind: RouteKind::Start, + announce, + } => ("start", announce.prefix.to_string()), + RouteEvent { + kind: RouteKind::Update, + announce, + } => ("update", announce.prefix.to_string()), + RouteEvent { + kind: RouteKind::Restart, + announce, + } => ("restart", announce.prefix.to_string()), + RouteEvent { + kind: RouteKind::End, + announce, + } => ("end", announce.prefix.to_string()), } } @@ -556,7 +626,7 @@ mod tests { .unwrap() .unwrap(); assert!( - matches!(&event, RouteEvent::Start(announce) if announce.route.cost == Cost::new(5)), + matches!(&event, RouteEvent { kind: RouteKind::Start, announce } if announce.route.cost == Cost::new(5)), "{event:?}" ); @@ -570,7 +640,7 @@ mod tests { .unwrap() .unwrap(); assert!( - matches!(&event, RouteEvent::Restart(announce) if announce.route.cost == Cost::new(5)), + matches!(&event, RouteEvent { kind: RouteKind::Restart, announce } if announce.route.cost == Cost::new(5)), "{event:?}" ); } diff --git a/rs/moq-net/src/model/mod.rs b/rs/moq-net/src/model/mod.rs index dd6a79083e6..4cc845752be 100644 --- a/rs/moq-net/src/model/mod.rs +++ b/rs/moq-net/src/model/mod.rs @@ -72,7 +72,7 @@ pub mod origin { // Relay-level: every route change, for forwarding and stats. Apps read // `announce` and `follow` instead. #[doc(hidden)] - pub use super::origin_impl::{RouteEvent, Routes}; + pub use super::origin_impl::{RouteEvent, RouteKind, Routes}; } /// Listing the paths announced on an origin. diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 9d6f064c724..bbaaf62dc36 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -1160,51 +1160,39 @@ impl OriginConsumerState { /// Take the pending update at `prefix` for delivery. fn take_prefix(&mut self, prefix: Path) -> RouteEvent { let (event, owed) = self.take_update(prefix); - let (RouteEvent::Start(announce) - | RouteEvent::Update(announce) - | RouteEvent::Restart(announce) - | RouteEvent::End(announce)) = &event; // A trailing announce left pending is still owed. - if owed && !self.pending.contains_key(&announce.prefix) { + if owed && !self.pending.contains_key(&event.announce.prefix) { self.owed -= 1; } event } fn take_update(&mut self, prefix: Path) -> (RouteEvent, bool) { - /// What the consumer learns at the prefix. - enum Kind { - Start, - Update, - Restart, - End, - } - let pending = self.remove(&prefix).unwrap(); let owed = pending.owed; let ((meta, captures), kind) = match pending.update.unwrap() { PendingUpdate::Announce(meta) => { // The consumer has seen this prefix before, so it is a metadata update. let kind = match self.delivered.insert(prefix.clone()) { - true => Kind::Start, - false => Kind::Update, + true => RouteKind::Start, + false => RouteKind::Update, }; (meta, kind) } PendingUpdate::Restart(meta) => { self.delivered.insert(prefix.clone()); - (meta, Kind::Restart) + (meta, RouteKind::Restart) } PendingUpdate::Unannounce(meta) => { self.delivered.remove(&prefix); - (meta, Kind::End) + (meta, RouteKind::End) } PendingUpdate::UnannounceAnnounce { old, new } => { // Deliver the retraction now; leave the trailing announce pending so // the next take returns it for the same prefix. self.delivered.remove(&prefix); self.insert(prefix.clone(), PendingUpdate::Announce(new), owed); - (old, Kind::End) + (old, RouteKind::End) } }; let announce = Announce { @@ -1222,13 +1210,7 @@ impl OriginConsumerState { draining: false, }, }; - let event = match kind { - Kind::Start => RouteEvent::Start(announce), - Kind::Update => RouteEvent::Update(announce), - Kind::Restart => RouteEvent::Restart(announce), - Kind::End => RouteEvent::End(announce), - }; - (event, owed) + (RouteEvent { kind, announce }, owed) } } @@ -2044,23 +2026,32 @@ impl Drop for HiddenWithholding { } } -/// What a [`Routes`] yields. +/// What a [`Routes`] yields: how the route covering a prefix changed, and that route. #[derive(Clone, Debug)] -pub enum RouteEvent { +pub struct RouteEvent { + /// How the route changed. + pub kind: RouteKind, + /// The route; for [`RouteKind::End`], its last advertised route. + pub announce: Announce, +} + +/// How the route covering a prefix changed. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum RouteKind { /// A route now covers the prefix; the cursor had none there. - Start(Announce), + Start, /// The route covering the prefix changed hops, cost or epoch, with the same instance; /// it is delivered in place. - Update(Announce), - /// No route covers the prefix any more. Carries its last advertised route. - End(Announce), + Update, + /// No route covers the prefix any more. + End, /// Another [`Instance`] now serves the prefix: another stream, such as a publisher /// that restarted, a redundant ingest switching, or a pool failing over. /// /// Whatever was resolved under the prefix before is the old stream: drop it and /// request afresh to follow the new one. Subscriptions already open stay on the old /// one until dropped or its route goes. - Restart(Announce), + Restart, } /// A route over a prefix, as an announcement listing or a [`Routes`] stream reports it. @@ -3727,8 +3718,14 @@ impl OwnClaims { fn apply(&mut self, event: RouteEvent) { let announce = match event { - RouteEvent::Start(announce) | RouteEvent::Update(announce) | RouteEvent::Restart(announce) => announce, - RouteEvent::End(announce) => { + RouteEvent { + kind: RouteKind::Start | RouteKind::Update | RouteKind::Restart, + announce, + } => announce, + RouteEvent { + kind: RouteKind::End, + announce, + } => { self.best.remove(&announce.prefix); return self.node.own(announce.prefix, None); } @@ -3753,11 +3750,17 @@ impl OwnClaims { /// go to an upstream peer follows it. fn local(&mut self, event: RouteEvent) { match event { - RouteEvent::End(announce) => { + RouteEvent { + kind: RouteKind::End, + announce, + } => { self.local.remove(&announce.prefix); self.feed(announce.prefix); } - RouteEvent::Start(announce) | RouteEvent::Update(announce) | RouteEvent::Restart(announce) => { + RouteEvent { + kind: RouteKind::Start | RouteKind::Update | RouteKind::Restart, + announce, + } => { if let Some(instance) = announce.route.instance { self.local.insert(announce.prefix.clone(), instance); } @@ -6855,10 +6858,13 @@ impl Requesting { if let Some(discovery) = &mut self.discovery { loop { match discovery.poll_next(waiter) { - Poll::Ready(Some(RouteEvent::End(_))) => self.routed = false, - Poll::Ready(Some( - RouteEvent::Start(announce) | RouteEvent::Restart(announce) | RouteEvent::Update(announce), - )) => { + Poll::Ready(Some(RouteEvent { + kind: RouteKind::End, .. + })) => self.routed = false, + Poll::Ready(Some(RouteEvent { + kind: RouteKind::Start | RouteKind::Restart | RouteKind::Update, + announce, + })) => { self.routed = self.instance.is_none() || announce.route.instance == self.instance; } Poll::Ready(None) => return Poll::Ready(Err(Error::Closed)), @@ -7436,7 +7442,6 @@ impl Consumer { /// 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 [`Routes`] to unregister. - #[doc(hidden)] pub fn routes(&self) -> Routes { let state = kio::Producer::::default(); let cursor = @@ -7700,8 +7705,9 @@ 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 [`RouteEvent::Restart`], and - /// [`Self::follow`] yields the next broadcast. + /// [`Consumer::routes`] reports that as [`RouteKind::Restart`], and + /// [`Self::follow`] yields the next broadcast. A job's exact route answering a + /// claim's request continues the claim's instance, so it is no restart. /// /// Pass an owned [`Instance`] to refuse a different stream, both when requesting /// and when an asynchronous answer resolves. `None` leaves lookup unpinned. @@ -7976,7 +7982,10 @@ impl Routes { expected: impl TryInto, ) -> RouteInfo { match self.expect_next().await { - RouteEvent::Restart(announce) => { + RouteEvent { + kind: RouteKind::Restart, + announce, + } => { assert_eq!( announce.prefix, expected.try_into().expect("expected path"), @@ -7991,7 +8000,10 @@ impl Routes { #[cfg(test)] pub(crate) async fn expect_next_ended(&mut self, expected: impl TryInto) { match self.expect_next().await { - RouteEvent::End(announce) => assert_eq!( + RouteEvent { + kind: RouteKind::End, + announce, + } => assert_eq!( announce.prefix, expected.try_into().expect("expected path"), "wrong prefix" @@ -8054,7 +8066,11 @@ impl Routes { /// 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: &RouteEvent, now: Instant) { - let RouteEvent::End(update) = event else { + let RouteEvent { + kind: RouteKind::End, + announce: update, + } = event + else { return; }; if self.update_hold.is_zero() { @@ -8127,13 +8143,19 @@ impl Routes { /// Drive the egress announce guards for one update. fn hand_out(&mut self, event: RouteEvent) -> RouteEvent { match &event { - RouteEvent::Start(announce) | RouteEvent::Update(announce) | RouteEvent::Restart(announce) => { + RouteEvent { + kind: RouteKind::Start | RouteKind::Update | RouteKind::Restart, + announce, + } => { let scope = self.stats.egress(self.root.rejoin(&announce.prefix)); self.guards .entry(announce.prefix.clone()) .or_insert_with(|| scope.announce()); } - RouteEvent::End(announce) => { + RouteEvent { + kind: RouteKind::End, + announce, + } => { self.guards.remove(&announce.prefix); } } @@ -8348,7 +8370,10 @@ impl Routes { /// The route of an active event at `expected`. fn active(event: RouteEvent, expected: &Path) -> RouteInfo { match event { - RouteEvent::Start(announce) | RouteEvent::Update(announce) | RouteEvent::Restart(announce) => { + RouteEvent { + kind: RouteKind::Start | RouteKind::Update | RouteKind::Restart, + announce, + } => { assert_eq!(announce.prefix, *expected, "wrong prefix"); announce.route } @@ -8378,7 +8403,10 @@ impl Routes { .expect("next blocked") .expect("no next") { - RouteEvent::Restart(announce) => { + RouteEvent { + kind: RouteKind::Restart, + announce, + } => { assert_eq!( announce.prefix, expected.try_into().expect("expected path"), @@ -8397,7 +8425,10 @@ impl Routes { .expect("next blocked") .expect("no next") { - RouteEvent::End(announce) => assert_eq!( + RouteEvent { + kind: RouteKind::End, + announce, + } => assert_eq!( announce.prefix, expected.try_into().expect("expected path"), "wrong prefix" @@ -9174,14 +9205,22 @@ mod tests { let _foo = producer.route(".svc/p1/foo", RouteOptions::default()).unwrap(); let project = mounted(&producer, "p1", &["**"]).with_hidden(true); - let Some(RouteEvent::Start(update)) = project.routes().try_next() else { + let Some(RouteEvent { + kind: RouteKind::Start, + announce: 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(RouteEvent::Start(update)) = inside.routes().try_next() else { + let Some(RouteEvent { + kind: RouteKind::Start, + announce: update, + }) = inside.routes().try_next() + else { panic!("expected foo to start"); }; assert_eq!(update.prefix.as_str(), "foo"); @@ -9675,7 +9714,10 @@ mod tests { route.update(RouteInfo::new().with_cost(5)).unwrap(); match announced.next().await.expect("no next") { - RouteEvent::Update(update) => assert_eq!(update.route.cost, Cost::new(5)), + RouteEvent { + kind: RouteKind::Update, + announce: update, + } => assert_eq!(update.route.cost, Cost::new(5)), other => panic!("should be an update: got {other:?}"), } } @@ -9697,7 +9739,10 @@ mod tests { route.update(RouteInfo::new().with_auth(second.clone())).unwrap(); match announced.next().await.expect("no next") { - RouteEvent::Update(update) => assert_eq!(update.route.auth, Some(second)), + RouteEvent { + kind: RouteKind::Update, + announce: update, + } => assert_eq!(update.route.auth, Some(second)), other => panic!("should be an update: got {other:?}"), } } @@ -10128,19 +10173,31 @@ mod tests { .covering(); let mut announced = consumer.routes(); - let Some(Some(RouteEvent::Start(first))) = announced.next().now_or_never() else { + let Some(Some(RouteEvent { + kind: RouteKind::Start, + announce: 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(RouteEvent::End(retracted))) = announced.next().now_or_never() else { + let Some(Some(RouteEvent { + kind: RouteKind::End, + announce: 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(RouteEvent::Start(replacement))) = announced.next().now_or_never() else { + let Some(Some(RouteEvent { + kind: RouteKind::Start, + announce: replacement, + })) = announced.next().now_or_never() + else { panic!("expected the replacement"); }; assert_eq!(replacement.prefix.as_str(), ""); @@ -11457,7 +11514,11 @@ mod tests { let second = producer.forward("live", RouteInfo::new().with_cost(1)).unwrap(); let mut announced = producer.consume().routes(); - let Some(Some(RouteEvent::Start(update))) = announced.next().now_or_never() else { + let Some(Some(RouteEvent { + kind: RouteKind::Start, + announce: update, + })) = announced.next().now_or_never() + else { panic!("expected the announcement"); }; assert_eq!(update.prefix.as_str(), "live"); @@ -11661,13 +11722,23 @@ mod tests { let server = producer.forward("live", RouteInfo::new()).unwrap(); let mut announced = producer.consume().routes(); let mut next = || StreamExt::next(&mut announced).now_or_never(); - let Some(Some(RouteEvent::Start(update))) = next() else { + let Some(Some(RouteEvent { + kind: RouteKind::Start, + announce: 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(RouteEvent::End(_))))); + assert!(matches!( + next(), + Some(Some(RouteEvent { + kind: RouteKind::End, + .. + })) + )); } #[kio::test] @@ -11916,7 +11987,10 @@ 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") { - RouteEvent::Update(update) => assert_eq!(update.route.hops, hops(&[9, 3, 4])), + RouteEvent { + kind: RouteKind::Update, + announce: update, + } => assert_eq!(update.route.hops, hops(&[9, 3, 4])), other => panic!("should be an update: got {other:?}"), } } @@ -11949,7 +12023,13 @@ mod tests { } let mut announced = producer.consume().routes(); for _ in 0..k { - assert!(matches!(announced.try_next(), Some(RouteEvent::Start(_)))); + assert!(matches!( + announced.try_next(), + Some(RouteEvent { + kind: RouteKind::Start, + .. + }) + )); } let before = announced.state.read().steps; @@ -11960,7 +12040,10 @@ mod tests { for (i, route) in far.into_iter().enumerate().rev() { drop(route); match announced.try_next() { - Some(RouteEvent::End(end)) => assert_eq!(end.prefix, Path::new(&format!("room/{i}")).unwrap()), + Some(RouteEvent { + kind: RouteKind::End, + announce: end, + }) => assert_eq!(end.prefix, Path::new(&format!("room/{i}")).unwrap()), other => panic!("should be a retraction: got {other:?}"), } } @@ -12000,7 +12083,10 @@ mod tests { drop(near); drop(far); match announced.next().await.unwrap() { - RouteEvent::Update(update) => assert_eq!(update.route.hops, hops(&[9, 5, 6, 7])), + RouteEvent { + kind: RouteKind::Update, + announce: 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); @@ -12036,7 +12122,10 @@ mod tests { let start = kio::clock::now(); let _stale = peer.forward("named", route(&[9, 3, 4], 4)).unwrap(); match announced.next().await.unwrap() { - RouteEvent::Start(announce) => assert_eq!(announce.route.hops, hops(&[9, 3, 4])), + RouteEvent { + kind: RouteKind::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); @@ -12179,7 +12268,10 @@ mod tests { // The newest identical route wins, so the local twin takes over. let local = producer.forward("room", route).unwrap(); match announced.next().await.expect("no next") { - RouteEvent::Update(announce) => assert_eq!(announce.route.source(), Source::Local), + RouteEvent { + kind: RouteKind::Update, + announce, + } => assert_eq!(announce.route.source(), Source::Local), other => panic!("should be an update: got {other:?}"), } @@ -12357,7 +12449,10 @@ mod tests { let instance = prepared.route().and_then(|route| route.instance); assert_eq!(instance, claim.route().unwrap().instance, "the claim's instance"); match announced.expect_next().await { - RouteEvent::Start(announce) => { + RouteEvent { + kind: RouteKind::Start, + announce, + } => { assert_eq!(announce.prefix.as_str(), "room/alice"); assert_eq!(announce.route.instance, instance); } @@ -12572,11 +12667,17 @@ mod tests { let second = claim.instance(); assert_ne!(second, first, "the claim moved on"); match announced.expect_next().await { - RouteEvent::End(announce) => assert_eq!(announce.prefix.as_str(), "room/alice"), + RouteEvent { + kind: RouteKind::End, + announce, + } => assert_eq!(announce.prefix.as_str(), "room/alice"), other => panic!("should end the job: got {other:?}"), } match announced.expect_next().await { - RouteEvent::Restart(announce) => { + RouteEvent { + kind: RouteKind::Restart, + announce, + } => { assert_eq!(announce.prefix.as_str(), "room"); assert_eq!(announce.route.instance, Some(second.clone())); } @@ -13038,7 +13139,10 @@ mod tests { #[cfg(feature = "async")] fn started(event: Option) -> RouteInfo { match event.expect("routed") { - RouteEvent::Start(announce) => announce.route, + RouteEvent { + kind: RouteKind::Start, + announce, + } => announce.route, other => panic!("should start: got {other:?}"), } } @@ -15737,7 +15841,11 @@ mod tests { let alice = producer.route("room/alice/chat", RouteOptions::hidden()).unwrap(); alice.announce().unwrap(); - let Some(RouteEvent::Start(update)) = announced.try_next() else { + let Some(RouteEvent { + kind: RouteKind::Start, + announce: update, + }) = announced.try_next() + else { panic!("expected alice's chat"); }; assert_eq!(update.prefix.as_str(), "room/alice/chat"); @@ -15749,7 +15857,11 @@ mod tests { announced.assert_next_wait(); let broad = producer.announce("room", RouteInfo::new()).unwrap(); - let Some(RouteEvent::Start(update)) = announced.try_next() else { + let Some(RouteEvent { + kind: RouteKind::Start, + announce: update, + }) = announced.try_next() + else { panic!("expected the overlapping broad route"); }; assert_eq!(update.prefix.as_str(), "room"); @@ -15808,21 +15920,35 @@ mod tests { .announce("room/alice", RouteInfo::new().with_instance(first_instance.clone(), 0)) .unwrap(); assert!( - matches!(selected.expect_next().await, RouteEvent::Start(a) if a.prefix.is_empty() && a.captures.is_some()) + matches!(selected.expect_next().await, RouteEvent { kind: RouteKind::Start, announce: a } if a.prefix.is_empty() && a.captures.is_some()) ); exact .update(RouteInfo::new().with_instance(first_instance, 0).with_cost(2)) .unwrap(); - assert!(matches!(selected.expect_next().await, RouteEvent::Update(a) if a.route.cost == Cost::new(2))); + assert!( + matches!(selected.expect_next().await, RouteEvent { kind: RouteKind::Update, announce: a } if a.route.cost == Cost::new(2)) + ); exact .update(RouteInfo::new().with_instance(crate::Instance::random(), 0)) .unwrap(); - assert!(matches!(selected.expect_next().await, RouteEvent::Restart(_))); + assert!(matches!( + selected.expect_next().await, + RouteEvent { + kind: RouteKind::Restart, + .. + } + )); drop(exact); selected.expect_next_ended("").await; selected.assert_next_wait(); let _again = producer.announce("room/alice", RouteInfo::new()).unwrap(); - assert!(matches!(selected.expect_next().await, RouteEvent::Start(_))); + assert!(matches!( + selected.expect_next().await, + RouteEvent { + kind: RouteKind::Start, + .. + } + )); drop(broad); selected.assert_next_wait(); drop(selected); @@ -15932,7 +16058,11 @@ mod tests { local.announce().unwrap(); let mut announced = producer.consume().routes(); - let Some(RouteEvent::Start(update)) = announced.try_next() else { + let Some(RouteEvent { + kind: RouteKind::Start, + announce: 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 9c56dee001f..1670b135478 100644 --- a/rs/moq-net/tests/integration/announce_covering_route.rs +++ b/rs/moq-net/tests/integration/announce_covering_route.rs @@ -28,16 +28,9 @@ fn produce_origin(hop: u64) -> origin::Producer { /// Drain every event the cursor has pending, as `kind prefix` lines. 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 { - Event::Start(announce) => ("Start", announce), - Event::Update(announce) => ("Update", announce), - Event::Restart(announce) => ("Restart", announce), - Event::End(announce) => ("End", announce), - }; - seen.push(format!("{kind} {}", announce.prefix)); + seen.push(format!("{:?} {}", event.kind, event.announce.prefix)); } seen } diff --git a/rs/moq-net/tests/integration/announce_to_serve.rs b/rs/moq-net/tests/integration/announce_to_serve.rs index bfe2a367c1c..6ef122ef863 100644 --- a/rs/moq-net/tests/integration/announce_to_serve.rs +++ b/rs/moq-net/tests/integration/announce_to_serve.rs @@ -44,17 +44,9 @@ enum Observer { /// Drain every route event the cursor has pending, as `kind prefix` lines. 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 { - Event::Start(announce) => ("Start", announce), - Event::Update(announce) => ("Update", announce), - Event::Restart(announce) => ("Restart", announce), - Event::End(announce) => ("End", announce), - }; - seen.push(format!("{kind} {}", announce.prefix)); + seen.push(format!("{:?} {}", event.kind, event.announce.prefix)); } seen } diff --git a/rs/moq-net/tests/integration/auth.rs b/rs/moq-net/tests/integration/auth.rs index f2a95eb22a1..bc9eadc8c2c 100644 --- a/rs/moq-net/tests/integration/auth.rs +++ b/rs/moq-net/tests/integration/auth.rs @@ -408,12 +408,17 @@ async fn wait_announced(origin: &origin::Consumer, path: &str, active: bool) { let mut announced = origin.routes(); let mut live = std::collections::HashSet::new(); 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 { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: update, + } => { live.insert(update.prefix.to_string()); } - moq_net::origin::RouteEvent::End(update) => { + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: update, + } => { live.remove(update.prefix.as_str()); } }; diff --git a/rs/moq-net/tests/integration/catalog_acquisition.rs b/rs/moq-net/tests/integration/catalog_acquisition.rs index ba8eeb669d2..3ebcd556333 100644 --- a/rs/moq-net/tests/integration/catalog_acquisition.rs +++ b/rs/moq-net/tests/integration/catalog_acquisition.rs @@ -42,7 +42,10 @@ async fn acquisition(version: &str, carries_instance: bool) { .unwrap(); let mut announced = subscriber.consume().routes(); let old_cost = match announced.next().await { - Some(moq_net::origin::RouteEvent::Start(announce)) => announce.route.cost(), + Some(moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::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)); @@ -56,8 +59,14 @@ 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::origin::RouteEvent::Update(announce)) if carries_instance => announce.route.cost(), - Some(moq_net::origin::RouteEvent::Restart(announce)) if !carries_instance => announce.route.cost(), + Some(moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Update, + announce, + }) if carries_instance => announce.route.cost(), + Some(moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::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/claim_continues.rs b/rs/moq-net/tests/integration/claim_continues.rs index fb2cb7fe1c1..170badef339 100644 --- a/rs/moq-net/tests/integration/claim_continues.rs +++ b/rs/moq-net/tests/integration/claim_continues.rs @@ -96,10 +96,22 @@ async fn drain(announced: &mut origin::Routes) -> Vec<(&'static str, String, Ins let mut events = Vec::new(); while let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { let (kind, announce) = match event.expect("announce ended") { - origin::RouteEvent::Start(a) => ("start", a), - origin::RouteEvent::Update(a) => ("update", a), - origin::RouteEvent::Restart(a) => ("restart", a), - origin::RouteEvent::End(a) => ("end", a), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce: a, + } => ("start", a), + origin::RouteEvent { + kind: origin::RouteKind::Update, + announce: a, + } => ("update", a), + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce: a, + } => ("restart", a), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce: a, + } => ("end", a), }; events.push((kind, announce.prefix.to_string(), announce.route.instance().clone())); } diff --git a/rs/moq-net/tests/integration/dial_split_horizon.rs b/rs/moq-net/tests/integration/dial_split_horizon.rs index f7f4daa86fb..4e5ed664a7a 100644 --- a/rs/moq-net/tests/integration/dial_split_horizon.rs +++ b/rs/moq-net/tests/integration/dial_split_horizon.rs @@ -100,10 +100,17 @@ async fn learned_hop(dialer: &origin::Producer, path: &str) -> u64 { loop { let event = announced.next().await.expect("announce cursor closed"); let announce = match event { - moq_net::origin::RouteEvent::Start(announce) - | moq_net::origin::RouteEvent::Update(announce) - | moq_net::origin::RouteEvent::Restart(announce) => announce, - moq_net::origin::RouteEvent::End(_) => continue, + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce, + } => announce, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } => continue, }; if announce.prefix.as_str() == path { return announce; @@ -166,7 +173,11 @@ async fn split_horizon(version: &str, [publisher_hop, subscriber_hop]: [NonZeroU .await .expect("the other edge never learned the namespace") .expect("announce cursor closed"); - let moq_net::origin::RouteEvent::Start(subscriber_saw) = subscriber_saw else { + let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + announce: 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/extensions.rs b/rs/moq-net/tests/integration/extensions.rs index c86ac8d64c1..1ff5117218b 100644 --- a/rs/moq-net/tests/integration/extensions.rs +++ b/rs/moq-net/tests/integration/extensions.rs @@ -44,12 +44,19 @@ fn announced(origin: &origin::Producer, path: &str) -> bool { let mut live = false; while let Some(event) = announced.try_next() { match event { - moq_net::origin::RouteEvent::Start(update) - | moq_net::origin::RouteEvent::Update(update) - | moq_net::origin::RouteEvent::Restart(update) => { + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: update, + } => { live |= update.prefix.as_str() == path; } - moq_net::origin::RouteEvent::End(update) => { + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: update, + } => { live &= update.prefix.as_str() != path; } } diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index 4bcd86402ba..2e17e7295a3 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -539,9 +539,11 @@ async fn route_at( ready: impl Fn(&moq_net::origin::RouteInfo) -> bool, ) -> moq_net::origin::RouteInfo { loop { - let (moq_net::origin::RouteEvent::Start(update) - | moq_net::origin::RouteEvent::Update(update) - | moq_net::origin::RouteEvent::Restart(update)) = announced.next().await.expect("update") + let moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: update, + } = announced.next().await.expect("update") else { continue; }; diff --git a/rs/moq-net/tests/integration/instance.rs b/rs/moq-net/tests/integration/instance.rs index ee64af26bd8..f8fd526a1d4 100644 --- a/rs/moq-net/tests/integration/instance.rs +++ b/rs/moq-net/tests/integration/instance.rs @@ -30,7 +30,10 @@ async fn started(announced: &mut origin::Routes) -> Instance { .expect("announce hung") .expect("announce ended") { - origin::RouteEvent::Start(announce) => announce.route.instance().clone(), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => announce.route.instance().clone(), other => panic!("expected a start, got {other:?}"), } } @@ -41,7 +44,10 @@ async fn ended(announced: &mut origin::Routes) { .expect("announce hung") .expect("announce ended") { - origin::RouteEvent::End(_) => {} + origin::RouteEvent { + kind: origin::RouteKind::End, + .. + } => {} other => panic!("expected an end, got {other:?}"), } } @@ -146,7 +152,10 @@ async fn next_hop_lost(version: &str) { .expect("the standby serves the claim"); } _ => match event.expect("announce hung").expect("announce ended") { - origin::RouteEvent::Restart(announce) => { + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce, + } => { assert_ne!( announce.route.instance(), &first, diff --git a/rs/moq-net/tests/integration/lazy_discovery.rs b/rs/moq-net/tests/integration/lazy_discovery.rs index 3e7a72d2a94..eb3d6105e36 100644 --- a/rs/moq-net/tests/integration/lazy_discovery.rs +++ b/rs/moq-net/tests/integration/lazy_discovery.rs @@ -95,7 +95,10 @@ impl Lazy { let mut announced = consumer.routes(); matches!( announced.poll_next(&kio::Waiter::noop()), - std::task::Poll::Ready(Some(origin::RouteEvent::Start(_))) + std::task::Poll::Ready(Some(origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + })) ) } } @@ -109,11 +112,18 @@ async fn synced(announced: &mut origin::Routes) -> Vec { .expect("synced in time") .expect("the stream stays open"); match event { - origin::RouteEvent::Start(announce) | origin::RouteEvent::Restart(announce) => { - seen.push(announce.prefix.to_string()) - } - origin::RouteEvent::End(announce) => seen.retain(|prefix| *prefix != announce.prefix.as_str()), - origin::RouteEvent::Update(_) => {} + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Restart, + announce, + } => seen.push(announce.prefix.to_string()), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } => seen.retain(|prefix| *prefix != announce.prefix.as_str()), + origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + } => {} } } seen.sort(); @@ -423,14 +433,21 @@ async fn settled(announced: &mut origin::Routes, held: &mut Vec) -> bool let mut ended = false; while let Some(event) = announced.try_next() { match event { - origin::RouteEvent::Start(announce) | origin::RouteEvent::Restart(announce) => { - held.push(announce.prefix.to_string()) - } - origin::RouteEvent::End(announce) => { + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Restart, + announce, + } => held.push(announce.prefix.to_string()), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } => { ended = true; held.retain(|prefix| *prefix != announce.prefix.as_str()) } - origin::RouteEvent::Update(_) => {} + origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + } => {} } } held.sort(); diff --git a/rs/moq-net/tests/integration/mount.rs b/rs/moq-net/tests/integration/mount.rs index 62f3d94e8dc..bf40f0c6869 100644 --- a/rs/moq-net/tests/integration/mount.rs +++ b/rs/moq-net/tests/integration/mount.rs @@ -67,8 +67,14 @@ async fn drain(routes: &mut origin::Routes) -> Vec<(bool, String)> { let mut events = Vec::new(); while let Ok(event) = kio::clock::timeout(Duration::from_secs(1), routes.next()).await { match event.expect("announce ended") { - origin::RouteEvent::Start(announce) => events.push((true, announce.prefix.to_string())), - origin::RouteEvent::End(announce) => events.push((false, announce.prefix.to_string())), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => events.push((true, announce.prefix.to_string())), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } => events.push((false, announce.prefix.to_string())), _ => {} } } diff --git a/rs/moq-net/tests/integration/multi_cdn.rs b/rs/moq-net/tests/integration/multi_cdn.rs index bd335b12d2e..0dd9d2fc898 100644 --- a/rs/moq-net/tests/integration/multi_cdn.rs +++ b/rs/moq-net/tests/integration/multi_cdn.rs @@ -133,8 +133,14 @@ async fn next(rx: &mut mpsc::UnboundedReceiver) -> (u64, Option bool { let route = match announce { - origin::RouteEvent::Start(a) | origin::RouteEvent::Update(a) | origin::RouteEvent::Restart(a) => &a.route, - origin::RouteEvent::End(_) => return false, + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Update | origin::RouteKind::Restart, + announce: a, + } => &a.route, + origin::RouteEvent { + kind: origin::RouteKind::End, + .. + } => return false, }; route.cost().value() >= A_COST } @@ -279,7 +285,13 @@ async fn fails_over_and_back(secondary: &str) { let mut announced = topology.subscriber.consume().routes(); let start = announced.next().await.expect("announced"); assert!( - matches!(start, origin::RouteEvent::Start(_)) && via_a(&start), + matches!( + start, + origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + } + ) && via_a(&start), "the preferred CDN wins over the cheaper one: {start:?}" ); @@ -289,7 +301,13 @@ async fn fails_over_and_back(secondary: &str) { topology.lose_a().await; let update = announced.next().await.expect("announced"); assert!( - matches!(update, origin::RouteEvent::Update(_)) && !via_a(&update), + matches!( + update, + origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + } + ) && !via_a(&update), "same instance over B: {update:?}" ); seen.extend(topology.group_anywhere(&mut rx).await); @@ -297,7 +315,13 @@ async fn fails_over_and_back(secondary: &str) { topology.restore_a().await; let update = announced.next().await.expect("announced"); assert!( - matches!(update, origin::RouteEvent::Update(_)) && via_a(&update), + matches!( + update, + origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + } + ) && via_a(&update), "back on A: {update:?}" ); seen.extend(topology.group_through_a(&mut rx).await); @@ -332,7 +356,13 @@ async fn restarts_across_protocols(secondary: &str) { topology.lose_a().await; let update = announced.next().await.expect("announced"); assert!( - matches!(update, origin::RouteEvent::Restart(_)) && !via_a(&update), + matches!( + update, + origin::RouteEvent { + kind: origin::RouteKind::Restart, + .. + } + ) && !via_a(&update), "another instance over B: {update:?}" ); topology.group(); diff --git a/rs/moq-net/tests/integration/rejoin.rs b/rs/moq-net/tests/integration/rejoin.rs index f908454515d..8068d12fb05 100644 --- a/rs/moq-net/tests/integration/rejoin.rs +++ b/rs/moq-net/tests/integration/rejoin.rs @@ -829,7 +829,13 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { // The new connection is cheaper, so the relay reports its route taking over. let mut follow = relay.consume().routes(); assert!( - matches!(follow.next().await, Some(origin::RouteEvent::Start(_))), + matches!( + follow.next().await, + Some(origin::RouteEvent { + kind: origin::RouteKind::Start, + .. + }) + ), "{version}" ); let replacement = upstream(1).await; @@ -837,7 +843,10 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { assert!( matches!( event, - Some(origin::RouteEvent::Update(_) | origin::RouteEvent::Restart(_)) + Some(origin::RouteEvent { + kind: origin::RouteKind::Update | origin::RouteKind::Restart, + .. + }) ), "{version}: {event:?}" ); diff --git a/rs/moq-net/tests/integration/replacement.rs b/rs/moq-net/tests/integration/replacement.rs index ff8d6de5d29..3cf56444a66 100644 --- a/rs/moq-net/tests/integration/replacement.rs +++ b/rs/moq-net/tests/integration/replacement.rs @@ -94,7 +94,10 @@ async fn replace(version: &str, instance: Option) { let _first = link(version, &publisher, &viewer).await; let mut announced = viewer.consume().routes(); match next_event(&mut announced).await { - origin::RouteEvent::Start(announce) => { + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => { assert_eq!(announce.prefix.as_str(), "cam"); let carried = announce.route.instance(); assert_eq!(carried.is_minted(), !carries, "{version}: minted {carried}"); @@ -133,7 +136,10 @@ 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(origin::RouteEvent::Restart(announce)) => assert_eq!(announce.prefix.as_str(), "cam"), + Some(origin::RouteEvent { + kind: origin::RouteKind::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 { diff --git a/rs/moq-net/tests/integration/route_change.rs b/rs/moq-net/tests/integration/route_change.rs index d882c5f0841..614d5a8c343 100644 --- a/rs/moq-net/tests/integration/route_change.rs +++ b/rs/moq-net/tests/integration/route_change.rs @@ -414,7 +414,10 @@ async fn route_dies_across_instances(version: &str, trigger: Trigger) { // Restart versus end and start is wire-level, which only the route stream shows. let mut announced = consumer.routes(); match announced.next().await.expect("announced") { - origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected the initial start, got {other:?}"), } let mut follow = consumer.follow("live", None).unwrap(); @@ -453,7 +456,10 @@ async fn route_dies_across_instances(version: &str, trigger: Trigger) { // while lite-07 carries ANNOUNCE_RESTART. An in-place update must fail here. if version.alpn() == "moq-lite-07-wip" { match announced.next().await.expect("announced") { - origin::RouteEvent::Restart(announce) => { + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce, + } => { assert_eq!(announce.prefix.as_str(), "live"); assert_eq!( announce.route.instance(), @@ -465,11 +471,17 @@ async fn route_dies_across_instances(version: &str, trigger: Trigger) { } } else { match announced.next().await.expect("announced") { - origin::RouteEvent::End(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version} {trigger:?}: expected an end, got {other:?}"), } match announced.next().await.expect("announced") { - origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version} {trigger:?}: expected a fresh start, got {other:?}"), } } @@ -508,7 +520,10 @@ async fn better_route_restarts(version: &str) { let consumer = topology.subscriber.consume(); let mut announced = consumer.routes(); match announced.next().await.expect("announced") { - origin::RouteEvent::Start(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected the route, got {other:?}"), } @@ -519,7 +534,10 @@ async fn better_route_restarts(version: &str) { topology.trigger(Trigger::BetterRoute).await; match announced.next().await.expect("announced") { - origin::RouteEvent::Restart(announce) => assert_eq!(announce.prefix.as_str(), "live"), + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce, + } => assert_eq!(announce.prefix.as_str(), "live"), other => panic!("{version}: expected a restart, got {other:?}"), } diff --git a/rs/moq-net/tests/integration/session_panic.rs b/rs/moq-net/tests/integration/session_panic.rs index 8ffe4bdf489..a7817c63dbd 100644 --- a/rs/moq-net/tests/integration/session_panic.rs +++ b/rs/moq-net/tests/integration/session_panic.rs @@ -81,10 +81,14 @@ 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") { - origin::RouteEvent::Start(announce) - | origin::RouteEvent::Update(announce) - | origin::RouteEvent::Restart(announce) => (announce, true), - origin::RouteEvent::End(announce) => (announce, false), + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Update | origin::RouteKind::Restart, + announce, + } => (announce, true), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } => (announce, false), }; if announce.prefix.as_str() == path && now_active == active { return; diff --git a/rs/moq-net/tests/integration/support/mod.rs b/rs/moq-net/tests/integration/support/mod.rs index f6b86d93749..6a6d4ba6975 100644 --- a/rs/moq-net/tests/integration/support/mod.rs +++ b/rs/moq-net/tests/integration/support/mod.rs @@ -37,11 +37,10 @@ pub async fn announced(consumer: &origin::Consumer, path: &str) -> origin::Route let mut announced = consumer.routes(); loop { match announced.next().await.expect("the origin closed") { - origin::RouteEvent::Start(announce) - | origin::RouteEvent::Update(announce) - | origin::RouteEvent::Restart(announce) - if announce.prefix.as_str() == path => - { + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Update | origin::RouteKind::Restart, + announce, + } if announce.prefix.as_str() == path => { return announce.route; } _ => {} @@ -79,10 +78,22 @@ pub fn watch(mut announced: origin::Routes) -> mpsc::UnboundedReceiver<(String, kio::clock::sim::spawn(async move { while let Some(event) = announced.next().await { let (kind, announce) = match event { - origin::RouteEvent::Start(announce) => (Kind::Start, announce), - origin::RouteEvent::Update(announce) => (Kind::Update, announce), - origin::RouteEvent::Restart(announce) => (Kind::Restart, announce), - origin::RouteEvent::End(announce) => (Kind::End, announce), + origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } => (Kind::Start, announce), + origin::RouteEvent { + kind: origin::RouteKind::Update, + announce, + } => (Kind::Update, announce), + origin::RouteEvent { + kind: origin::RouteKind::Restart, + announce, + } => (Kind::Restart, announce), + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } => (Kind::End, announce), }; if tx.unbounded_send((announce.prefix.to_string(), kind)).is_err() { break; diff --git a/rs/moq-net/tests/integration/synced.rs b/rs/moq-net/tests/integration/synced.rs index b4c9d96f199..13fa2445dfc 100644 --- a/rs/moq-net/tests/integration/synced.rs +++ b/rs/moq-net/tests/integration/synced.rs @@ -30,13 +30,22 @@ async fn read_until_synced(announced: &mut origin::Routes) -> BTreeSet { .expect("synced in time") .expect("the cursor stays open"); match event { - origin::RouteEvent::Start(announce) | origin::RouteEvent::Restart(announce) => { + origin::RouteEvent { + kind: origin::RouteKind::Start | origin::RouteKind::Restart, + announce, + } => { seen.insert(announce.prefix.to_string()); } - origin::RouteEvent::End(announce) => { + origin::RouteEvent { + kind: origin::RouteKind::End, + announce, + } => { seen.remove(announce.prefix.as_str()); } - origin::RouteEvent::Update(_) => {} + origin::RouteEvent { + kind: origin::RouteKind::Update, + .. + } => {} } } seen @@ -140,6 +149,8 @@ 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, origin::RouteEvent::Start(route) if route.prefix.as_str() == "room/cam")); + assert!( + matches!(event, origin::RouteEvent { kind: origin::RouteKind::Start, announce: route } if route.prefix.as_str() == "room/cam") + ); assert!(announced.poll_synced(&kio::Waiter::noop()).is_ready()); } diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 26ad25d1d1e..0e2d2cacfe1 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -2647,17 +2647,27 @@ mod tests { #[cfg(feature = "cluster-lan")] async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } /// The next announcement without blocking. fn try_next_announced(announced: &mut moq_net::origin::Routes) -> Option { match announced.try_next()? { - moq_net::origin::RouteEvent::Start(route) => Some(route), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + announce: route, + } => Some(route), other => panic!("expected an announcement: got {other:?}"), } } diff --git a/rs/moq-relay/src/internal.rs b/rs/moq-relay/src/internal.rs index 67191e53a22..c78f2d3c8b9 100644 --- a/rs/moq-relay/src/internal.rs +++ b/rs/moq-relay/src/internal.rs @@ -1330,10 +1330,17 @@ mod tests { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 0e9dfd350d9..6c929248b58 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -1007,9 +1007,11 @@ async fn serve_announced( let mut broadcasts = Vec::new(); while let Some(event) = announced.try_next() { - if let moq_net::origin::RouteEvent::Start(update) - | moq_net::origin::RouteEvent::Update(update) - | moq_net::origin::RouteEvent::Restart(update) = event + if let moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: update, + } = event { broadcasts.push(update.prefix); } diff --git a/rs/moq-relay/tests/drills.rs b/rs/moq-relay/tests/drills.rs index 53536d57dc7..b8c57a30f63 100644 --- a/rs/moq-relay/tests/drills.rs +++ b/rs/moq-relay/tests/drills.rs @@ -1400,10 +1400,15 @@ lanes!(no_publisher_never_delivers); /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/auth_lifetime.rs b/rs/moq-relay/tests/integration/auth_lifetime.rs index b4b4e480811..76ae58f97cc 100644 --- a/rs/moq-relay/tests/integration/auth_lifetime.rs +++ b/rs/moq-relay/tests/integration/auth_lifetime.rs @@ -1850,10 +1850,15 @@ 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::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/cluster_fresh_port.rs b/rs/moq-relay/tests/integration/cluster_fresh_port.rs index e4c8b02862b..64861dcbe31 100644 --- a/rs/moq-relay/tests/integration/cluster_fresh_port.rs +++ b/rs/moq-relay/tests/integration/cluster_fresh_port.rs @@ -159,8 +159,10 @@ async fn dropped_flow_recovers(budget: Duration, effective: Duration) { kio::clock::timeout(effective + SLACK, async { loop { let event = announced.next().await.expect("origin closed"); - if let moq_net::origin::RouteEvent::Start(update) | moq_net::origin::RouteEvent::Update(update) = event - && update.prefix.as_str() == "peer" + if let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update, + announce: update, + } = event && update.prefix.as_str() == "peer" { break; } diff --git a/rs/moq-relay/tests/integration/cluster_idle.rs b/rs/moq-relay/tests/integration/cluster_idle.rs index b1f4822a5e0..d04c2e98672 100644 --- a/rs/moq-relay/tests/integration/cluster_idle.rs +++ b/rs/moq-relay/tests/integration/cluster_idle.rs @@ -115,8 +115,10 @@ async fn silent_peer_detected() { kio::clock::timeout(DETECT, async { loop { let event = announced.next().await.expect("origin closed"); - if let moq_net::origin::RouteEvent::Start(update) | moq_net::origin::RouteEvent::Update(update) = event - && update.prefix.as_str() == "peer" + if let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update, + announce: update, + } = event && update.prefix.as_str() == "peer" { break; } @@ -133,8 +135,10 @@ async fn silent_peer_detected() { kio::clock::timeout(DETECT, async { loop { let event = announced.next().await.expect("origin closed"); - if let moq_net::origin::RouteEvent::End(update) = event - && update.prefix.as_str() == "peer" + if let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: 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 268fc0c0713..1bd307bd891 100644 --- a/rs/moq-relay/tests/integration/cluster_unknown.rs +++ b/rs/moq-relay/tests/integration/cluster_unknown.rs @@ -313,9 +313,14 @@ 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::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/connection.rs b/rs/moq-relay/tests/integration/connection.rs index 6b7ba1ee241..4adcfab5d69 100644 --- a/rs/moq-relay/tests/integration/connection.rs +++ b/rs/moq-relay/tests/integration/connection.rs @@ -102,10 +102,17 @@ async fn next_active(announced: &mut moq_net::origin::Routes) -> String { .expect("announcement timeout") .expect("origin closed") { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => return route.prefix.to_string(), - moq_net::origin::RouteEvent::End(_) => {} + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: route, + } => return route.prefix.to_string(), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + .. + } => {} } } } diff --git a/rs/moq-relay/tests/integration/embed.rs b/rs/moq-relay/tests/integration/embed.rs index 625c101f4d6..954dd02cc0d 100644 --- a/rs/moq-relay/tests/integration/embed.rs +++ b/rs/moq-relay/tests/integration/embed.rs @@ -599,9 +599,14 @@ fn embedded_loader_refuses_obsolete_file_settings() { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: 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 90e048f8142..7dffcfa1c9b 100644 --- a/rs/moq-relay/tests/integration/goaway_cluster.rs +++ b/rs/moq-relay/tests/integration/goaway_cluster.rs @@ -182,7 +182,10 @@ async fn cluster_continues_a_group_split_by_goaway_inner() { // route under any other instance is B's. let mut announced = consumer.routes(); let instance_a = match within("A's route", announced.next()).await.expect("announce update") { - moq_net::origin::RouteEvent::Start(update) => update.route.instance().clone(), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + announce: update, + } => update.route.instance().clone(), other => panic!("expected A's route, got {other:?}"), }; session_a @@ -194,10 +197,13 @@ 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::origin::RouteEvent::Start(update) - | moq_net::origin::RouteEvent::Update(update) - | moq_net::origin::RouteEvent::Restart(update) = event - && *update.route.instance() != instance_a + if let moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: update, + } = event && *update.route.instance() != instance_a { break; } diff --git a/rs/moq-relay/tests/integration/hidden_cluster.rs b/rs/moq-relay/tests/integration/hidden_cluster.rs index 604225be1d7..ea543416cf1 100644 --- a/rs/moq-relay/tests/integration/hidden_cluster.rs +++ b/rs/moq-relay/tests/integration/hidden_cluster.rs @@ -74,8 +74,10 @@ 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::origin::RouteEvent::Start(announce) | moq_net::origin::RouteEvent::Update(announce) = - discovered.next().await.expect("peer origin closed") + if let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update, + announce, + } = discovered.next().await.expect("peer origin closed") && announce.prefix.as_str() == ".hidden/test" { break; diff --git a/rs/moq-relay/tests/integration/memory.rs b/rs/moq-relay/tests/integration/memory.rs index 46c94b3f773..a3d9732b1c3 100644 --- a/rs/moq-relay/tests/integration/memory.rs +++ b/rs/moq-relay/tests/integration/memory.rs @@ -323,10 +323,17 @@ pub fn record(mut announced: moq_net::origin::Routes) -> std::sync::Arc (route, false), - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => (route, true), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => (route, false), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: route, + } => (route, true), }; recorded .lock() diff --git a/rs/moq-relay/tests/integration/public_rules.rs b/rs/moq-relay/tests/integration/public_rules.rs index 40a7b698021..1480ea6a0b6 100644 --- a/rs/moq-relay/tests/integration/public_rules.rs +++ b/rs/moq-relay/tests/integration/public_rules.rs @@ -106,7 +106,10 @@ async fn first_broadcast(url: url::Url) -> String { let update = kio::clock::timeout(TIMEOUT, async { match announcements.next().await.expect("origin closed") { - moq_net::origin::RouteEvent::Start(update) => update, + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + announce: update, + } => update, other => panic!("expected announce, got {other:?}"), } }) diff --git a/rs/moq-relay/tests/integration/runtime_uring.rs b/rs/moq-relay/tests/integration/runtime_uring.rs index badc918d50f..5b793d75b31 100644 --- a/rs/moq-relay/tests/integration/runtime_uring.rs +++ b/rs/moq-relay/tests/integration/runtime_uring.rs @@ -924,10 +924,15 @@ 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::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: 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 00bdf2fce12..46519ef40da 100644 --- a/rs/moq-relay/tests/integration/runtime_workers.rs +++ b/rs/moq-relay/tests/integration/runtime_workers.rs @@ -166,9 +166,14 @@ 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::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-relay/tests/integration/smoke.rs b/rs/moq-relay/tests/integration/smoke.rs index 1f32059e683..a94f8960d4c 100644 --- a/rs/moq-relay/tests/integration/smoke.rs +++ b/rs/moq-relay/tests/integration/smoke.rs @@ -270,7 +270,11 @@ async fn announced_until(announcements: &mut moq_net::origin::Routes, until: &st .await .expect("announcement timeout") .expect("origin closed"); - if let moq_net::origin::RouteEvent::Start(announce) | moq_net::origin::RouteEvent::Update(announce) = event { + if let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update, + announce, + } = event + { seen.push(announce.prefix.as_str().to_owned()); } } @@ -994,9 +998,14 @@ async fn connect_once( /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: 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 8520f54e094..889bc81da9a 100644 --- a/rs/moq-relay/tests/integration/tenant_matrix.rs +++ b/rs/moq-relay/tests/integration/tenant_matrix.rs @@ -266,7 +266,11 @@ impl Watcher { let changed = changed.clone(); async move { while let Some(event) = announced.next().await { - if let moq_net::origin::RouteEvent::Start(route) = event { + if let moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start, + announce: route, + } = event + { seen.lock().unwrap().push(route.prefix.to_string()); changed.notify_waiters(); } @@ -349,12 +353,16 @@ async fn synced_listing(url: url::Url) -> BTreeSet { Poll::Pending => routes.poll_synced(waiter).map(|()| None), }) .await; - use moq_net::origin::RouteEvent; + use moq_net::origin::{RouteEvent, RouteKind}; match next { - Some(RouteEvent::End(route)) => listed.remove(route.prefix.as_str()), - Some(RouteEvent::Start(route) | RouteEvent::Update(route) | RouteEvent::Restart(route)) => { - listed.insert(route.prefix.to_string()) - } + Some(RouteEvent { + kind: RouteKind::End, + announce: route, + }) => listed.remove(route.prefix.as_str()), + Some(RouteEvent { + kind: RouteKind::Start | RouteKind::Update | RouteKind::Restart, + announce: route, + }) => listed.insert(route.prefix.to_string()), None => return, }; } diff --git a/rs/moq-relay/tests/integration/upstream_links.rs b/rs/moq-relay/tests/integration/upstream_links.rs index bcb220eafca..90c32596368 100644 --- a/rs/moq-relay/tests/integration/upstream_links.rs +++ b/rs/moq-relay/tests/integration/upstream_links.rs @@ -219,7 +219,11 @@ async fn routes_when( let mut changes = origin.consume().routes(); let mut routes = BTreeMap::new(); while let Some(event) = changes.try_next() { - let origin::RouteEvent::Start(announce) = event else { + let origin::RouteEvent { + kind: origin::RouteKind::Start, + announce, + } = event + else { panic!("an initial set is only starts: got {event:?}"); }; let hops = moq_net::fuzz::route_hops(&announce.route); diff --git a/rs/moq-rtmp/src/server.rs b/rs/moq-rtmp/src/server.rs index 6166173ed7c..866027730a8 100644 --- a/rs/moq-rtmp/src/server.rs +++ b/rs/moq-rtmp/src/server.rs @@ -2806,7 +2806,13 @@ mod tests { 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::origin::RouteEvent::Restart(_))) {} + while !matches!( + announced.next().await, + Some(moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Restart, + .. + }) + ) {} }) .await .expect("the reconnect restarts the broadcast"); diff --git a/rs/moq-stats/src/aggregate.rs b/rs/moq-stats/src/aggregate.rs index 42f6157c80f..df277f11fc6 100644 --- a/rs/moq-stats/src/aggregate.rs +++ b/rs/moq-stats/src/aggregate.rs @@ -810,19 +810,26 @@ impl Merged { // unannounce. A closed stream ends the merged view. loop { match self.announce.poll_next(waiter) { - Poll::Ready(Some( - moq_net::origin::RouteEvent::Start(update) | moq_net::origin::RouteEvent::Update(update), - )) => { + Poll::Ready(Some(moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update, + announce: update, + })) => { let instance = update.route.instance().clone(); changed |= self.apply_announce(&update, instance, true) } - Poll::Ready(Some(moq_net::origin::RouteEvent::End(update))) => { + Poll::Ready(Some(moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: update, + })) => { let instance = update.route.instance().clone(); changed |= self.apply_announce(&update, instance, 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::origin::RouteEvent::Restart(update))) => { + Poll::Ready(Some(moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::Restart, + announce: 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()) { @@ -1142,10 +1149,17 @@ mod tests { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-stats/src/consume.rs b/rs/moq-stats/src/consume.rs index 83e2fce4597..eb2922503e1 100644 --- a/rs/moq-stats/src/consume.rs +++ b/rs/moq-stats/src/consume.rs @@ -175,10 +175,17 @@ mod tests { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index d9b3b8da094..f9a05696194 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -1672,10 +1672,17 @@ mod tests { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::origin::Routes) -> Option<(moq_net::announce::Announce, bool)> { match announced.next().await? { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start + | moq_net::origin::RouteKind::Update + | moq_net::origin::RouteKind::Restart, + announce: route, + } => Some((route, true)), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce: route, + } => Some((route, false)), } } diff --git a/rs/moq-tokio/tests/integration/broadcast.rs b/rs/moq-tokio/tests/integration/broadcast.rs index 4e5cca42e6a..8eabebe8bf9 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -818,10 +818,15 @@ async fn next_route(routes: &mut moq_net::origin::Routes) -> (moq_net::announce: .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) => (announce, true), + moq_net::origin::RouteEvent { + kind: moq_net::origin::RouteKind::End, + announce, + } => (announce, false), + moq_net::origin::RouteEvent { + kind: + moq_net::origin::RouteKind::Start | moq_net::origin::RouteKind::Update | moq_net::origin::RouteKind::Restart, + announce, + } => (announce, true), } } From 721ede480dc5ee83089595f8d6ae2ca3e6a98c65 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 9 Nov 2026 08:42:22 -0800 Subject: [PATCH 3/3] docs(net): show Routes, RouteEvent, RouteKind in rustdoc Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/rs/moq-net/src/model/mod.rs b/rs/moq-net/src/model/mod.rs index 4cc845752be..76a6bffd228 100644 --- a/rs/moq-net/src/model/mod.rs +++ b/rs/moq-net/src/model/mod.rs @@ -71,7 +71,6 @@ pub mod origin { // Relay-level: every route change, for forwarding and stats. Apps read // `announce` and `follow` instead. - #[doc(hidden)] pub use super::origin_impl::{RouteEvent, RouteKind, Routes}; }