summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/state.rs b/src/state.rs
index 72013b9..8ff8b9d 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -478,6 +478,8 @@ pub(crate) struct Timing {
pub(crate) dormant_after: Duration,
pub(crate) resync_after: Duration,
pub(crate) dormant_probe: Duration,
+ /// While catching up: PING the source after this much silence (`swarm::source`).
+ pub(crate) catch_up_probe: Duration,
}
impl Timing {
@@ -494,6 +496,9 @@ impl Timing {
dormant_after: keepalive * 4, // dormant_after >= 4* keepalive to tolerate three lost PINGs in a row
resync_after: keepalive * 2, // resync_after should be >= 2* keepalive to guarantee at least one digest exchange while sync is idle
dormant_probe: keepalive * 10, // >= 10*: dormant peers cost almost nothing, but still rejoin within minutes
+ // Seconds, not a keepalive interval: a dead source should cost little time.
+ // Only the source gets these, and only while catching up.
+ catch_up_probe: (keepalive / 30).clamp(Duration::from_secs(1), Duration::from_secs(5)),
}
}
}
@@ -541,12 +546,16 @@ pub(crate) struct AppState {
pub(crate) catch_up_source: Arc<std::sync::Mutex<Option<CatchUpSource>>>,
}
-/// The peer a catching-up node syncs with first (`swarm::sync::defer_for_catch_up`).
+/// The peer a catching-up node syncs with first (`swarm::source`).
#[derive(Clone, Debug)]
pub(crate) struct CatchUpSource {
pub(crate) peer: String,
- /// When it was chosen or last sent us something.
- pub(crate) last_progress: Instant,
+ /// When it was chosen or last sent us anything.
+ pub(crate) last_heard: Instant,
+ /// Our last probe PING to it.
+ pub(crate) last_probe: Option<Instant>,
+ /// Its keepalives in a row saying it wouldn't sync with us.
+ pub(crate) refusals: u32,
}
impl AppState {
@@ -786,6 +795,8 @@ impl AppState {
let mut announce = Vec::new();
for (id, peer_state_mutex) in &peers {
let mut peer_state = peer_state_mutex.lock().await;
+ // What it said about syncing with us was about our old epoch.
+ peer_state.syncs_with_us = None;
let syncs_with_us = peer_state.liveness == Liveness::Active
&& matches!(peer_state.standing, Standing::Member { .. })
&& peer_state.epoch == Some(local);