diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index 5f9a47bd7c7..fd2736bc6ff 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -671,11 +671,12 @@ fn earliest(a: Option, b: Option) -> Option { } /// A retraction's quarantine, keyed by prefix in its [`AnnounceConsumer`]: the -/// retracted route's publisher and rank, and when the quarantine ends. +/// retracted route's publisher (none for an anonymous route, which holds +/// nothing), rank, and when the quarantine ends. #[derive(Clone, Copy)] struct Quarantine { held: Held, - publisher: Hop, + publisher: Option, rank: (Cost, usize), } @@ -684,7 +685,7 @@ impl Quarantine { /// first hop, ranked strictly worse. A republish ranks the same and a reconnect /// names a fresh first hop, so neither waits. fn holds(&self, meta: &RouteMeta) -> bool { - meta.0.iter().next() == Some(&self.publisher) && (meta.1, meta.0.len()) > self.rank + self.publisher.is_some_and(|hop| meta.0.iter().next() == Some(&hop)) && (meta.1, meta.0.len()) > self.rank } } @@ -4616,25 +4617,24 @@ impl AnnounceConsumer { let Some(now) = now.filter(|_| !self.update_hold.is_zero()) else { return; }; - // An anonymous route names no publisher to tie a later stale path to. - let Some(&publisher) = update.route.hops.iter().next().filter(|hop| **hop != Hop::UNKNOWN) else { - self.retracted.remove(&update.prefix); - return; - }; - // A prefix retracted again at the same reading is already queued, so churn - // between clock readings can't grow the queue past one entry per prefix. - let queued = self - .retracted - .get(&update.prefix) - .is_some_and(|q| q.held == Held::Anchoring(now)); + // An anonymous route names no publisher, so its quarantine holds nothing. + let publisher = update + .route + .hops + .iter() + .next() + .copied() + .filter(|hop| *hop != Hop::UNKNOWN); // The reading may be stale; [`Self::settle`] starts the quarantine on a fresh one. let quarantine = Quarantine { held: Held::Anchoring(now), publisher, rank: (update.route.cost, update.route.hops.len()), }; - self.retracted.insert(update.prefix.clone(), quarantine); - if !queued { + let replaced = self.retracted.insert(update.prefix.clone(), quarantine); + // A prefix retracted again at the same reading is already queued, so churn + // between clock readings cannot grow the queue past one entry per prefix. + if !replaced.is_some_and(|q| q.held == Held::Anchoring(now)) { self.anchoring.push_back((now, update.prefix.clone())); } } @@ -7244,14 +7244,16 @@ mod tests { let _other = peer.dynamic("anonymous", route(&[0, 3, 4], 4)).unwrap(); announced.assert_next_active("anonymous"); - // Retract and announce cycles at one clock reading queue the prefix once. - for _ in 0..4 { - let churn = peer.dynamic("churn", route(&[9, 2], 2)).unwrap(); + // Retract and announce cycles at one clock reading queue the prefix once, + // whether or not the route names its publisher. + let queued = announced.anchoring.len(); + for chain in [[9, 2], [0, 2], [9, 2], [0, 2]] { + let churn = peer.dynamic("churn", route(&chain, 2)).unwrap(); announced.assert_next_active("churn"); drop(churn); announced.assert_next_ended("churn"); } - assert_eq!(announced.anchoring.len(), 1); + assert_eq!(announced.anchoring.len(), queued + 1); // A quarantine is forgotten once it ends: the cursor wakes to anchor it, // then again to drop it. @@ -7259,7 +7261,7 @@ mod tests { announced.assert_next_active("gone"); drop(gone); announced.assert_next_ended("gone"); - assert_eq!(announced.retracted.len(), 2); + assert!(!announced.retracted.is_empty()); for _ in 0..2 { announced.assert_next_wait(); tokio::time::sleep(RETRACT_QUARANTINE).await;