Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions rs/moq-net/src/model/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,12 @@ fn earliest(a: Option<Instant>, b: Option<Instant>) -> Option<Instant> {
}

/// 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<Hop>,
rank: (Cost, usize),
}

Expand All @@ -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
}
}

Expand Down Expand Up @@ -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()));
}
}
Expand Down Expand Up @@ -7244,22 +7244,24 @@ 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.
let gone = peer.dynamic("gone", route(&[9, 2], 2)).unwrap();
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;
Expand Down
Loading