diff options
| author | tv <tv@krebsco.de> | 2026-11-03 06:11:06 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-03 06:11:06 +0100 |
| commit | b16977b18fdd1e5193f5c015eadcb61a63f4fae1 (patch) | |
| tree | 197a9fb7c0c0f5d5b799ecc3f3363c628a4f5e12 /src/swarm/relay.rs | |
| parent | 698ab19bb74e1dbbc7c52fef96caede4d92caf55 (diff) | |
announcement round counters
Diffstat (limited to 'src/swarm/relay.rs')
| -rw-r--r-- | src/swarm/relay.rs | 14 |
1 files changed, 8 insertions, 6 deletions
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<u64>) 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<u64>) 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<std::sync::Mutex<Option<Pending>>>, 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"); |
