From 83b0d894515ccd45556c5a030e0f539174604b0b Mon Sep 17 00:00:00 2001 From: Frando Date: Wed, 4 Nov 2026 15:18:41 +0100 Subject: [PATCH 1/2] feat(net): add route accessors to origin::RouteEvent Every variant carries an `Announce`, so readers that only want the route spell out a five-way or-pattern. `announce()`, `into_announce()`, and `is_end()` replace those patterns across moq-net's production code and are available to downstream relays reading `origin::Routes`. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/CHANGELOG.md | 1 + rs/moq-net/src/ietf/publisher.rs | 16 +++----- rs/moq-net/src/ietf/subscriber.rs | 9 +--- rs/moq-net/src/lite/publisher.rs | 16 +++----- rs/moq-net/src/lite/replay.rs | 9 +--- rs/moq-net/src/model/follow.rs | 8 +--- rs/moq-net/src/model/origin.rs | 68 +++++++++++++++++++------------ 7 files changed, 60 insertions(+), 67 deletions(-) diff --git a/rs/moq-net/CHANGELOG.md b/rs/moq-net/CHANGELOG.md index 60287cad324..ace71d30e22 100644 --- a/rs/moq-net/CHANGELOG.md +++ b/rs/moq-net/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `socket`: `Endpoint`, which announces a hidden `/.socket/` broadcast, dials other endpoints, and accepts their dials in two protocols: `tcp` sessions (`dial_tcp`, `accept_tcp`, `TcpStream`), one group each way as a reliable, ordered byte pipe, and `track` sessions (`dial_track`, `accept_track`, `TrackStream`), a track each way with one message per group. Dials and accepts fail `Unsupported` while the origin has a moq-lite client session before 07 whose publish half doesn't opt into hidden broadcasts, since its peer never hears the endpoint; see `doc/concept/socket.md`. - `transport::SETUP_RECEIVE_WINDOW`, the connection credit a server offers before it admits a session: enough for the SETUP and one in-band AUTH. +- `origin::RouteEvent::{announce, into_announce, is_end}`, so a reader gets the route without matching every variant. ## [0.3.10](https://github.com/moq-dev/moq/compare/moq-net-v0.3.9...moq-net-v0.3.10) - 2026-10-05 diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 10d1d790f23..c7c9d610fdb 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -4290,16 +4290,12 @@ impl Publisher { fn snapshot(announced: &mut crate::origin::Routes) -> Vec { let mut initial = std::collections::BTreeMap::new(); while let Some(event) = announced.try_next() { - match event { - crate::origin::RouteEvent::Start(update) - | crate::origin::RouteEvent::Update(update) - | crate::origin::RouteEvent::Restart(update) - | crate::origin::RouteEvent::Takeover { announce: update, .. } => { - initial.insert(update.prefix.clone(), update); - } - crate::origin::RouteEvent::End(update) => { - initial.remove(&update.prefix); - } + let active = !event.is_end(); + let update = event.into_announce(); + if active { + initial.insert(update.prefix.clone(), update); + } else { + initial.remove(&update.prefix); } } initial.into_values().collect() diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 12b19e6d989..480f20f8599 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -9057,13 +9057,8 @@ mod tests { /// The current best route covering `path`, if any (synchronous peek). fn routed_now(consumer: &crate::origin::Consumer, path: &str) -> Option { use futures::FutureExt; - match consumer.path_routes(path).ok()?.next().now_or_never()?? { - crate::origin::RouteEvent::End(_) => None, - crate::origin::RouteEvent::Start(announce) - | crate::origin::RouteEvent::Update(announce) - | crate::origin::RouteEvent::Restart(announce) - | crate::origin::RouteEvent::Takeover { announce, .. } => Some(announce.route), - } + let event = consumer.path_routes(path).ok()?.next().now_or_never()??; + (!event.is_end()).then(|| event.into_announce().route) } fn hop_path(ids: &[u64]) -> cluster::HopPath { diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 2a4fbdfcb07..a57be6457a4 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -1172,16 +1172,12 @@ impl AnnounceRun { let mut snapshot = origin.routes(); 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::Takeover { announce: update, .. } => { - current.insert(update.prefix, update.route); - } - origin::RouteEvent::End(update) => { - current.remove(&update.prefix); - } + let active = !event.is_end(); + let update = event.into_announce(); + if active { + current.insert(update.prefix, update.route); + } else { + current.remove(&update.prefix); } } diff --git a/rs/moq-net/src/lite/replay.rs b/rs/moq-net/src/lite/replay.rs index 1d5549d6689..a4cbde55abe 100644 --- a/rs/moq-net/src/lite/replay.rs +++ b/rs/moq-net/src/lite/replay.rs @@ -9,13 +9,8 @@ pub(super) fn initial(events: impl IntoIterator) -> V let mut pending: Vec> = Vec::new(); 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) - | origin::RouteEvent::Takeover { announce: update, .. } => (update, true), - origin::RouteEvent::End(update) => (update, false), - }; + let active = !event.is_end(); + let update = event.into_announce(); if let Some(index) = positions.remove(&update.prefix) { pending[index] = None; } diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index 78d90882a38..88d623b3fc7 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -94,7 +94,7 @@ impl Follow { return Poll::Ready(None); }; if let Some(event) = self.fold(event) { - self.idle = matches!(event, RouteEvent::End(_)); + self.idle = event.is_end(); return Poll::Ready(Some(event)); } } @@ -127,11 +127,7 @@ 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::Takeover { announce, .. } - | RouteEvent::End(announce)) = &event; + let announce = event.announce(); if !self.path.has_prefix(&announce.prefix) { return None; } diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 2faa52d7925..06f2bd8a2f8 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -1124,13 +1124,8 @@ 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::Takeover { 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 @@ -2051,6 +2046,35 @@ pub enum RouteEvent { }, } +impl RouteEvent { + /// The route the event carries; for [`End`](Self::End), its last advertised route. + pub fn announce(&self) -> &Announce { + match self { + Self::Start(announce) + | Self::Update(announce) + | Self::End(announce) + | Self::Restart(announce) + | Self::Takeover { announce, .. } => announce, + } + } + + /// Consume the event, returning the route it carries. + pub fn into_announce(self) -> Announce { + match self { + Self::Start(announce) + | Self::Update(announce) + | Self::End(announce) + | Self::Restart(announce) + | Self::Takeover { announce, .. } => announce, + } + } + + /// Whether no route covers the prefix any more; every other event leaves one in place. + pub fn is_end(&self) -> bool { + matches!(self, Self::End(_)) + } +} + /// A route over a prefix, as an announcement listing or a [`Routes`] stream reports it. /// /// An announcement is always a prefix, never a broadcast: it advertises that @@ -6260,14 +6284,9 @@ 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) - | RouteEvent::Takeover { announce, .. }, - )) => { - self.routed = self.instance.is_none() || announce.route.instance == self.instance; + Poll::Ready(Some(event)) if event.is_end() => self.routed = false, + Poll::Ready(Some(event)) => { + self.routed = self.instance.is_none() || event.announce().route.instance == self.instance; } Poll::Ready(None) => return Poll::Ready(Err(Error::Closed)), Poll::Pending => break, @@ -7398,19 +7417,14 @@ 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::Takeover { 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) => { - self.guards.remove(&announce.prefix); - } + let announce = event.announce(); + if event.is_end() { + self.guards.remove(&announce.prefix); + } else { + let scope = self.stats.egress(self.root.rejoin(&announce.prefix)); + self.guards + .entry(announce.prefix.clone()) + .or_insert_with(|| scope.announce()); } event } From 91aba4a39d786473385aa0e4d4b9bc191aa9e80c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 14:54:28 -0800 Subject: [PATCH 2/2] refactor: read RouteEvent's route and end through its accessors Switch the remaining five-way or-patterns that treat every live variant alike, in moq-net, moq-relay, moq-stats, moq-gst, tests, and benches, to RouteEvent::{announce, into_announce, is_end}. Matches that tell Start, Update, Restart, or Takeover apart stay as they are. Co-Authored-By: Claude Opus 5.5 --- rs/moq-gst/src/source/imp.rs | 40 +++++-------------- rs/moq-net-tests/tests/integration/restart.rs | 2 +- rs/moq-net/benches/announce.rs | 9 +---- rs/moq-net/benches/auth.rs | 13 ++---- rs/moq-net/benches/session/mod.rs | 2 +- rs/moq-net/src/model/origin.rs | 23 ++++------- rs/moq-net/tests/integration/auth.rs | 16 +++----- .../tests/integration/dial_split_horizon.rs | 11 ++--- rs/moq-net/tests/integration/extensions.rs | 12 +----- rs/moq-net/tests/integration/multi_cdn.rs | 11 +---- rs/moq-net/tests/integration/session_panic.rs | 10 +---- rs/moq-relay/src/cluster.rs | 10 ++--- rs/moq-relay/src/internal.rs | 10 ++--- rs/moq-relay/src/web.rs | 8 +--- rs/moq-relay/tests/drills.rs | 10 ++--- .../tests/integration/auth_lifetime.rs | 10 ++--- .../tests/integration/cluster_unknown.rs | 10 ++--- rs/moq-relay/tests/integration/connection.rs | 12 ++---- rs/moq-relay/tests/integration/embed.rs | 10 ++--- .../tests/integration/goaway_cluster.rs | 17 ++------ .../tests/integration/runtime_uring.rs | 10 ++--- .../tests/integration/runtime_workers.rs | 10 ++--- rs/moq-relay/tests/integration/smoke.rs | 10 ++--- .../tests/integration/tenant_matrix.rs | 14 ++----- rs/moq-stats/src/aggregate.rs | 10 ++--- rs/moq-stats/src/consume.rs | 10 ++--- rs/moq-stats/src/produce.rs | 10 ++--- rs/moq-tokio/tests/integration/broadcast.rs | 9 +---- 28 files changed, 93 insertions(+), 236 deletions(-) diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index 0105f7ef25f..20605703820 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -4333,9 +4333,7 @@ mod session_tests { matches!(event, moq_net::origin::RouteEvent::Start(_)) }); drop(first); - await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut follow, moq_net::origin::RouteEvent::is_end); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad"); @@ -4394,9 +4392,7 @@ mod session_tests { matches!(event, moq_net::origin::RouteEvent::Start(_)) }); drop(first); - await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut follow, moq_net::origin::RouteEvent::is_end); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 3), pad, "the return moved to another pad"); assert_eq!( @@ -4493,9 +4489,7 @@ mod session_tests { matches!(event, moq_net::origin::RouteEvent::Start(_)) }); first.route.as_ref().unwrap().withdraw(); - await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut follow, moq_net::origin::RouteEvent::is_end); first.route.as_ref().unwrap().announce().unwrap(); await_event(&mut follow, |event| { matches!(event, moq_net::origin::RouteEvent::Start(_)) @@ -4578,9 +4572,7 @@ mod session_tests { matches!(event, moq_net::origin::RouteEvent::Start(_)) }); drop(first); - await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut follow, moq_net::origin::RouteEvent::is_end); let mut second = Publisher::sibling(&origin, Default::default()); assert_eq!(recorder.written(&mut second, 2), pad, "the return moved to another pad"); @@ -4845,9 +4837,7 @@ mod session_tests { matches!(event, moq_net::origin::RouteEvent::Start(_)) }); drop(first); - await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut follow, moq_net::origin::RouteEvent::is_end); room.catalog.modify().unwrap().video.renditions.clear(); for _ in 0..200 { @@ -4893,9 +4883,7 @@ mod session_tests { matches!(event, moq_net::origin::RouteEvent::Start(_)) }); drop(first); - await_event(&mut follow, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut follow, moq_net::origin::RouteEvent::is_end); let listed = room.catalog.modify().unwrap().video.renditions.clone(); room.catalog.modify().unwrap().video.renditions.clear(); @@ -5264,9 +5252,7 @@ mod session_tests { block(Duration::from_millis(100)); old.catalog.finish().unwrap(); drop(old); - await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut announced, moq_net::origin::RouteEvent::is_end); let mut new = Publisher::new(&origin, Default::default(), video_rendition()); assert_eq!( @@ -5294,9 +5280,7 @@ mod session_tests { let pad = recorder.written(&mut old, 1); old.route.as_ref().unwrap().withdraw(); - await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut announced, moq_net::origin::RouteEvent::is_end); drop(old); let mut new = Publisher::new(&origin, Default::default(), video_rendition()); @@ -5369,9 +5353,7 @@ mod session_tests { let mut announced = announced(&origin); let route = next.route.as_ref().unwrap(); route.withdraw(); - await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut announced, moq_net::origin::RouteEvent::is_end); route.announce().unwrap(); assert_eq!( recorder.written(&mut next, tag + 2), @@ -5865,9 +5847,7 @@ mod session_tests { let mut announced = announced(&relay.origin); session.abort(moq_net::Error::App(1)); - await_event(&mut announced, |event| { - matches!(event, moq_net::origin::RouteEvent::End(_)) - }); + await_event(&mut announced, moq_net::origin::RouteEvent::is_end); let mut new = Publisher::new(&relay.origin, Default::default(), video_rendition()); rendered(&sink, &mut new, 2); diff --git a/rs/moq-net-tests/tests/integration/restart.rs b/rs/moq-net-tests/tests/integration/restart.rs index 3dcd2cfffd3..9b53269deb9 100644 --- a/rs/moq-net-tests/tests/integration/restart.rs +++ b/rs/moq-net-tests/tests/integration/restart.rs @@ -603,7 +603,7 @@ async fn withdrawal_refuses_new_fetches_but_keeps_open_reads() { 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!(next_event(&mut announced).await.is_end()); assert!(track.fetch_group(1, None).await.is_err(), "{version}"); write(&produced, "old:1"); assert_eq!(read(&mut subscription).await, "old:1"); diff --git a/rs/moq-net/benches/announce.rs b/rs/moq-net/benches/announce.rs index 55372555a20..806853b418b 100644 --- a/rs/moq-net/benches/announce.rs +++ b/rs/moq-net/benches/announce.rs @@ -33,13 +33,8 @@ mod replay; 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) - | origin::RouteEvent::Takeover { announce: update, .. } => (update, true), - origin::RouteEvent::End(update) => (update, false), - }; + let active = !event.is_end(); + let update = event.into_announce(); initial.retain(|held| held.prefix != update.prefix); if active { initial.push(update); diff --git a/rs/moq-net/benches/auth.rs b/rs/moq-net/benches/auth.rs index f90c8b82fe3..bfef7034b02 100644 --- a/rs/moq-net/benches/auth.rs +++ b/rs/moq-net/benches/auth.rs @@ -304,16 +304,9 @@ fn waiting(c: &mut Criterion) { let mut announced = receive.consume().routes(); 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) - | moq_net::origin::RouteEvent::Takeover { announce: update, .. } - if update.prefix.as_str().starts_with(&prefix) => - { - seen.insert(update.prefix); - } - _ => {} + let event = announced.next().await.unwrap(); + if !event.is_end() && event.announce().prefix.as_str().starts_with(&prefix) { + seen.insert(event.into_announce().prefix); } } drop(broadcasts); diff --git a/rs/moq-net/benches/session/mod.rs b/rs/moq-net/benches/session/mod.rs index 37d276eed3e..cf838506655 100644 --- a/rs/moq-net/benches/session/mod.rs +++ b/rs/moq-net/benches/session/mod.rs @@ -1905,7 +1905,7 @@ pub(crate) fn withdrawal(c: &mut Criterion) { while let Ok(Some(event)) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { - assert!(matches!(event, moq_net::origin::RouteEvent::End(_)), "{event:?}"); + assert!(event.is_end(), "{event:?}"); retracted += 1; } let elapsed = start.elapsed(); diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index d1fc65f0ffb..9e6176152a0 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -3698,21 +3698,14 @@ impl OwnClaims { /// The route not learned upstream changed at a prefix: whether the claim there may /// go to an upstream peer follows it. fn local(&mut self, event: RouteEvent) { - match event { - RouteEvent::End(announce) => { - self.local.remove(&announce.prefix); - self.feed(announce.prefix, None); - } - RouteEvent::Start(announce) - | RouteEvent::Update(announce) - | RouteEvent::Restart(announce) - | RouteEvent::Takeover { announce, .. } => { - if let Some(instance) = announce.route.instance { - self.local.insert(announce.prefix.clone(), instance); - } - self.feed(announce.prefix, None); - } - } + let end = event.is_end(); + let announce = event.into_announce(); + if end { + self.local.remove(&announce.prefix); + } else if let Some(instance) = announce.route.instance { + self.local.insert(announce.prefix.clone(), instance); + } + self.feed(announce.prefix, None); } /// Feed the node the claim at `prefix`, marked as learned upstream unless a route diff --git a/rs/moq-net/tests/integration/auth.rs b/rs/moq-net/tests/integration/auth.rs index 2aed7b3c6eb..d8916b29b7c 100644 --- a/rs/moq-net/tests/integration/auth.rs +++ b/rs/moq-net/tests/integration/auth.rs @@ -404,16 +404,12 @@ async fn granted(session: &Session) -> Grant { 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::Takeover { announce: update, .. } => { - live.insert(update.prefix.to_string()); - } - moq_net::origin::RouteEvent::End(update) => { - live.remove(update.prefix.as_str()); - } + let apply = |live: &mut std::collections::HashSet, event: moq_net::origin::RouteEvent| { + let prefix = event.announce().prefix.to_string(); + match event.is_end() { + true => live.remove(&prefix), + false => live.insert(prefix), + }; }; // Take in the replay first, so a retraction is judged against what is announced now // rather than against an empty start. diff --git a/rs/moq-net/tests/integration/dial_split_horizon.rs b/rs/moq-net/tests/integration/dial_split_horizon.rs index ef02f794539..054dce1db21 100644 --- a/rs/moq-net/tests/integration/dial_split_horizon.rs +++ b/rs/moq-net/tests/integration/dial_split_horizon.rs @@ -99,13 +99,10 @@ async fn learned_hop(dialer: &origin::Producer, path: &str) -> u64 { let event = kio::clock::timeout(SETTLE, async { 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) - | moq_net::origin::RouteEvent::Takeover { announce, .. } => announce, - moq_net::origin::RouteEvent::End(_) => continue, - }; + if event.is_end() { + continue; + } + let announce = event.into_announce(); if announce.prefix.as_str() == path { return announce; } diff --git a/rs/moq-net/tests/integration/extensions.rs b/rs/moq-net/tests/integration/extensions.rs index 937143e1102..483b77bf9dd 100644 --- a/rs/moq-net/tests/integration/extensions.rs +++ b/rs/moq-net/tests/integration/extensions.rs @@ -43,16 +43,8 @@ fn announced(origin: &origin::Producer, path: &str) -> bool { let mut announced = origin.consume().routes(); 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::Takeover { announce: update, .. } => { - live |= update.prefix.as_str() == path; - } - moq_net::origin::RouteEvent::End(update) => { - live &= update.prefix.as_str() != path; - } + if event.announce().prefix.as_str() == path { + live = !event.is_end(); } } live diff --git a/rs/moq-net/tests/integration/multi_cdn.rs b/rs/moq-net/tests/integration/multi_cdn.rs index 62338a6b746..c44b9e8be3a 100644 --- a/rs/moq-net/tests/integration/multi_cdn.rs +++ b/rs/moq-net/tests/integration/multi_cdn.rs @@ -131,15 +131,8 @@ 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) - | origin::RouteEvent::Takeover { announce: a, .. } => &a.route, - origin::RouteEvent::End(_) => return false, - }; - route.cost().value() >= A_COST +fn via_a(event: &origin::RouteEvent) -> bool { + !event.is_end() && event.announce().route.cost().value() >= A_COST } struct Topology { diff --git a/rs/moq-net/tests/integration/session_panic.rs b/rs/moq-net/tests/integration/session_panic.rs index cf9e40cb086..f9306acf4d7 100644 --- a/rs/moq-net/tests/integration/session_panic.rs +++ b/rs/moq-net/tests/integration/session_panic.rs @@ -80,14 +80,8 @@ async fn publish(version: Version, relay: &origin::Producer, hop: u64, name: &st 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) - | origin::RouteEvent::Takeover { announce, .. } => (announce, true), - origin::RouteEvent::End(announce) => (announce, false), - }; - if announce.prefix.as_str() == path && now_active == active { + let event = announced.next().await.expect("origin closed"); + if event.announce().prefix.as_str() == path && event.is_end() != active { return; } } diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index d47179d427c..339794ba8fc 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -2582,13 +2582,9 @@ mod tests { /// The next route and whether it is active. #[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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } /// The next announcement without blocking. diff --git a/rs/moq-relay/src/internal.rs b/rs/moq-relay/src/internal.rs index fd4955a28eb..777cdf9a96f 100644 --- a/rs/moq-relay/src/internal.rs +++ b/rs/moq-relay/src/internal.rs @@ -1364,13 +1364,9 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } /// An `Config` whose listener is enabled, so `Internal` registers its own. diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 88f3f576eca..2ff41ae1764 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -983,12 +983,8 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: update, .. } = event - { - broadcasts.push(update.prefix); + if !event.is_end() { + broadcasts.push(event.into_announce().prefix); } } diff --git a/rs/moq-relay/tests/drills.rs b/rs/moq-relay/tests/drills.rs index b22e68f8ecd..1b42bc45ecd 100644 --- a/rs/moq-relay/tests/drills.rs +++ b/rs/moq-relay/tests/drills.rs @@ -1400,13 +1400,9 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } #[tokio::test] diff --git a/rs/moq-relay/tests/integration/auth_lifetime.rs b/rs/moq-relay/tests/integration/auth_lifetime.rs index 1329fea6db8..c05b02f2b8a 100644 --- a/rs/moq-relay/tests/integration/auth_lifetime.rs +++ b/rs/moq-relay/tests/integration/auth_lifetime.rs @@ -1859,13 +1859,9 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } /// The auth server sees the accepted transport, independent of negotiated MoQ ALPN. diff --git a/rs/moq-relay/tests/integration/cluster_unknown.rs b/rs/moq-relay/tests/integration/cluster_unknown.rs index ead28679e0e..6f5e068cf1c 100644 --- a/rs/moq-relay/tests/integration/cluster_unknown.rs +++ b/rs/moq-relay/tests/integration/cluster_unknown.rs @@ -429,11 +429,7 @@ async fn unknown_publisher_does_not_flap_across_a_lite04_cluster_triangle() { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } diff --git a/rs/moq-relay/tests/integration/connection.rs b/rs/moq-relay/tests/integration/connection.rs index ceee8a968cc..1cc6993b307 100644 --- a/rs/moq-relay/tests/integration/connection.rs +++ b/rs/moq-relay/tests/integration/connection.rs @@ -97,16 +97,12 @@ fn publish( /// The next active route's prefix. async fn next_active(announced: &mut moq_net::origin::Routes) -> String { loop { - match kio::clock::timeout(TIMEOUT, announced.next()) + let event = kio::clock::timeout(TIMEOUT, announced.next()) .await .expect("announcement timeout") - .expect("origin closed") - { - moq_net::origin::RouteEvent::Start(route) - | moq_net::origin::RouteEvent::Update(route) - | moq_net::origin::RouteEvent::Restart(route) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => return route.prefix.to_string(), - moq_net::origin::RouteEvent::End(_) => {} + .expect("origin closed"); + if !event.is_end() { + return event.into_announce().prefix.to_string(); } } } diff --git a/rs/moq-relay/tests/integration/embed.rs b/rs/moq-relay/tests/integration/embed.rs index 6aee992ce7f..04142044c76 100644 --- a/rs/moq-relay/tests/integration/embed.rs +++ b/rs/moq-relay/tests/integration/embed.rs @@ -596,11 +596,7 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } diff --git a/rs/moq-relay/tests/integration/goaway_cluster.rs b/rs/moq-relay/tests/integration/goaway_cluster.rs index 5d8312e2031..7ac7561d838 100644 --- a/rs/moq-relay/tests/integration/goaway_cluster.rs +++ b/rs/moq-relay/tests/integration/goaway_cluster.rs @@ -223,12 +223,7 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: update, .. } = event - && update.route.cost() != moq_net::origin::Cost::DRAIN - { + if !event.is_end() && event.announce().route.cost() != moq_net::origin::Cost::DRAIN { break; } } @@ -890,11 +885,7 @@ async fn goaway_handover_is_enforced_while_the_replacement_dial_hangs_inner() { /// The next route and whether it is active. async fn next_update(announced: &mut moq_net::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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } diff --git a/rs/moq-relay/tests/integration/runtime_uring.rs b/rs/moq-relay/tests/integration/runtime_uring.rs index 6aa98392bac..2b447f99bc9 100644 --- a/rs/moq-relay/tests/integration/runtime_uring.rs +++ b/rs/moq-relay/tests/integration/runtime_uring.rs @@ -927,13 +927,9 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } /// A moq-transport SETUP credential reaches the decider on both ring transports. diff --git a/rs/moq-relay/tests/integration/runtime_workers.rs b/rs/moq-relay/tests/integration/runtime_workers.rs index 2a96182fc7f..5f7e0a3a014 100644 --- a/rs/moq-relay/tests/integration/runtime_workers.rs +++ b/rs/moq-relay/tests/integration/runtime_workers.rs @@ -166,11 +166,7 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } diff --git a/rs/moq-relay/tests/integration/smoke.rs b/rs/moq-relay/tests/integration/smoke.rs index 5f028189eca..e3996a6aee2 100644 --- a/rs/moq-relay/tests/integration/smoke.rs +++ b/rs/moq-relay/tests/integration/smoke.rs @@ -994,11 +994,7 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } diff --git a/rs/moq-relay/tests/integration/tenant_matrix.rs b/rs/moq-relay/tests/integration/tenant_matrix.rs index a8fa9d0e8a4..d9509c29871 100644 --- a/rs/moq-relay/tests/integration/tenant_matrix.rs +++ b/rs/moq-relay/tests/integration/tenant_matrix.rs @@ -350,16 +350,10 @@ async fn synced_listing(url: url::Url) -> BTreeSet { Poll::Pending => routes.poll_synced(waiter).map(|()| None), }) .await; - use moq_net::origin::RouteEvent; - match next { - Some(RouteEvent::End(route)) => listed.remove(route.prefix.as_str()), - Some( - RouteEvent::Start(route) - | RouteEvent::Update(route) - | RouteEvent::Restart(route) - | RouteEvent::Takeover { announce: route, .. }, - ) => listed.insert(route.prefix.to_string()), - None => return, + let Some(event) = next else { return }; + match event.is_end() { + true => listed.remove(event.announce().prefix.as_str()), + false => listed.insert(event.into_announce().prefix.to_string()), }; } }) diff --git a/rs/moq-stats/src/aggregate.rs b/rs/moq-stats/src/aggregate.rs index 4d55994184f..9870d7cda3a 100644 --- a/rs/moq-stats/src/aggregate.rs +++ b/rs/moq-stats/src/aggregate.rs @@ -1144,13 +1144,9 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } use std::time::Duration; diff --git a/rs/moq-stats/src/consume.rs b/rs/moq-stats/src/consume.rs index e1a13551c01..8d96a5a5219 100644 --- a/rs/moq-stats/src/consume.rs +++ b/rs/moq-stats/src/consume.rs @@ -177,13 +177,9 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } use std::time::Duration; diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 5aaf91b2f62..255fdd16f52 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -1667,13 +1667,9 @@ 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) - | moq_net::origin::RouteEvent::Takeover { announce: route, .. } => Some((route, true)), - moq_net::origin::RouteEvent::End(route) => Some((route, false)), - } + let event = announced.next().await?; + let active = !event.is_end(); + Some((event.into_announce(), active)) } use std::collections::BTreeMap; diff --git a/rs/moq-tokio/tests/integration/broadcast.rs b/rs/moq-tokio/tests/integration/broadcast.rs index 5508bbfe111..a0c482b69ce 100644 --- a/rs/moq-tokio/tests/integration/broadcast.rs +++ b/rs/moq-tokio/tests/integration/broadcast.rs @@ -818,13 +818,8 @@ async fn next_route(routes: &mut moq_net::origin::Routes) -> (moq_net::announce: .await .expect("announce timeout") .expect("origin closed"); - match event { - moq_net::origin::RouteEvent::End(announce) => (announce, false), - moq_net::origin::RouteEvent::Start(announce) - | moq_net::origin::RouteEvent::Update(announce) - | moq_net::origin::RouteEvent::Restart(announce) - | moq_net::origin::RouteEvent::Takeover { announce, .. } => (announce, true), - } + let active = !event.is_end(); + (event.into_announce(), active) } /// Wait for the next announce event, failing the test on a timeout or a closed origin.