From b16977b18fdd1e5193f5c015eadcb61a63f4fae1 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 3 Nov 2026 06:11:06 +0100 Subject: announcement round counters --- src/swarm/relay.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/swarm/relay.rs') diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs index 29da2eb..a8560a5 100644 --- a/src/swarm/relay.rs +++ b/src/swarm/relay.rs @@ -104,7 +104,7 @@ pub(crate) async fn announce(state: &AppState, from: &str, writer: Option) schedule }; if schedule { - round(state, &state.announce_pending, ANNOUNCE_DELAY); + round(state, &state.announce_pending, ANNOUNCE_DELAY, false); } if !tree { return; @@ -121,15 +121,17 @@ pub(crate) async fn announce(state: &AppState, from: &str, writer: Option) schedule }; if schedule { - round(state, &state.announce_slow, SLOW_ANNOUNCE_DELAY); + round(state, &state.announce_slow, SLOW_ANNOUNCE_DELAY, true); } } -/// An announcement round of what `pending` collects, `delay` (and a jitter) from now. +/// An announcement round of what `pending` collects, `delay` (and a jitter) from now: +/// the `slow` one, or the quick one. fn round( state: &AppState, pending: &std::sync::Arc>>, delay: Duration, + slow: bool, ) { let state = state.clone(); let pending = std::sync::Arc::clone(pending); @@ -140,14 +142,14 @@ fn round( .max(1); tokio::time::sleep(delay + Duration::from_millis(jitter)).await; let pending = pending.lock_or_recover().take().unwrap_or_default(); - announce_now(&state, &pending).await; + announce_now(&state, &pending, slow).await; }); } /// One announcement round. The peer whose changes we announce has them already, so a /// round with a single sender skips it; with several, each lacks the others' changes, /// so every neighbour is told. -async fn announce_now(state: &AppState, pending: &Pending) { +async fn announce_now(state: &AppState, pending: &Pending, slow: bool) { let mut neighbours = unreached(state, &pending.senders, &pending.sent).await; if !pending.all { neighbours.retain(|peer| pending.targets.contains(peer)); @@ -155,7 +157,7 @@ async fn announce_now(state: &AppState, pending: &Pending) { if neighbours.is_empty() { return; } - state.stats.announce_round(); + state.stats.announce_round(pending.all, slow); for peer in neighbours { if let Err(error) = announce_heads(state, &peer, false).await { debug!(peer = %peer, error = %format!("{error:#}"), "Announcing our heads failed"); -- cgit v1.3.1