aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/peers.md4
-rw-r--r--src/swarm/peer/forget.rs18
2 files changed, 15 insertions, 7 deletions
diff --git a/docs/peers.md b/docs/peers.md
index ff332c6..dd3186f 100644
--- a/docs/peers.md
+++ b/docs/peers.md
@@ -257,7 +257,9 @@ stateDiagram-v2
and are greeted again, and the time counts as not connected for the node's stability.
- **Strangers** (peers that never became members: listed to us but never answering, or
failing the handshake) are forgotten locally once silent for a day, so peers named
- to a node can't grow its list without bound.
+ to a node can't grow its list without bound. So are members no longer in the member
+ list (their entry gone without a forget record reaching the node); a listed member is
+ kept however long it is silent, as its probe is what finds it when it comes back.
## Member registry and neighbours
diff --git a/src/swarm/peer/forget.rs b/src/swarm/peer/forget.rs
index 68266d5..ce064a2 100644
--- a/src/swarm/peer/forget.rs
+++ b/src/swarm/peer/forget.rs
@@ -135,17 +135,23 @@ pub(crate) async fn forget_unless_alive(state: &AppState, pk: &str, now: Instant
/// the map of peers would only grow.
const STRANGER_KEPT: Duration = Duration::from_secs(24 * 3600);
-/// Forgets peers that never became members and were silent for `STRANGER_KEPT`. Only
-/// here, not swarm-wide; one that comes back is a stranger again.
+/// Forgets peers that never became members and were silent for `STRANGER_KEPT`, and
+/// members no longer in the member list as silent (their entry gone without a forget
+/// record reaching us: nothing else would ever drop them, and each is probed hourly and
+/// copied wherever the peers are walked). A listed member stays however long it is
+/// silent: its probe is what finds it when it comes back. Only here, not swarm-wide;
+/// one that comes back is a stranger again, and a member once its handshake passes.
pub(super) async fn forget_strangers(state: &AppState) {
let now = Instant::now();
let mut strangers = Vec::new();
for (peer, peer_state) in state.peers_snapshot().await {
let peer_state = peer_state.lock().await;
let quiet_since = peer_state.last_seen.unwrap_or(peer_state.added_at);
- if !matches!(peer_state.standing, Standing::Member { .. })
- && now.saturating_duration_since(quiet_since) >= STRANGER_KEPT
- {
+ let unlisted = || {
+ !matches!(peer_state.standing, Standing::Member { .. })
+ || crate::swarm::topology::listed(state, &peer) == Some(false)
+ };
+ if now.saturating_duration_since(quiet_since) >= STRANGER_KEPT && unlisted() {
strangers.push(peer);
}
}
@@ -158,6 +164,6 @@ pub(super) async fn forget_strangers(state: &AppState) {
}
info!(
forgotten = strangers.len(),
- "Forgot peers that never became members and were silent for a day"
+ "Forgot peers that never became members, or are no longer, and were silent for a day"
);
}