summaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-25 23:50:29 +0100
committertv <tv@krebsco.de>2026-10-25 23:50:29 +0100
commit0039ffe04d290935936d33e681c2a0f2575c4264 (patch)
tree1bfcaa189bcc5670b1959d766dfdc0e9f5816334 /src/swarm
parenta232ec43702cdd23614737351120fd3b065e987d (diff)
refresh peers after stall
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/peer.rs13
-rw-r--r--src/swarm/source.rs7
2 files changed, 19 insertions, 1 deletions
diff --git a/src/swarm/peer.rs b/src/swarm/peer.rs
index e8248bf..1240966 100644
--- a/src/swarm/peer.rs
+++ b/src/swarm/peer.rs
@@ -221,6 +221,19 @@ pub(crate) async fn remember_peer(state: &AppState, peer: &str) {
}
}
+/// Starts a new handshake with `peer` even though one is complete: its reply resets
+/// sync on both sides and brings its current peer list (`swarm::source`, after giving
+/// it up as the catch-up source).
+pub(crate) async fn rehandshake(state: &AppState, peer: &str) {
+ if let Some(peer_state) = state.get_peer_state(peer).await {
+ let mut peer_state = peer_state.lock().await;
+ if peer_state.hello_state == HelloState::Established {
+ peer_state.hello_state = HelloState::NotSent;
+ }
+ }
+ ensure_handshake(state, peer).await;
+}
+
pub(crate) async fn send_hello_once(state: &AppState, peer: &str) -> Result<()> {
let Some(peer_state_mutex) = state.get_peer_state(peer).await else {
trace!(peer = %peer, "Peer was forgotten; not sending HELLO");
diff --git a/src/swarm/source.rs b/src/swarm/source.rs
index 9eac445..b1701b3 100644
--- a/src/swarm/source.rs
+++ b/src/swarm/source.rs
@@ -23,7 +23,10 @@
//! `Timing::delivery_limit`, after which Mycelium has delivered or dropped anything it
//! sent before. It isn't chosen again for another `delivery_limit`, so another peer
//! takes over rather than the same one stalling again; if it is the only candidate,
-//! catching up waits that long before trying it again. Meanwhile, every minute without a sync message from it is logged as a
+//! catching up waits that long before trying it again. It also gets a fresh HELLO: a
+//! joining node learns of other peers only from HELLO_REPLYs, and the one it got from
+//! this peer may have listed none (a peer lists only its neighbours, which a new member
+//! isn't until its registration has spread). Meanwhile, every minute without a sync message from it is logged as a
//! warning.
use std::sync::atomic::Ordering;
@@ -203,6 +206,8 @@ pub(crate) fn reply_timed_out(state: &AppState, peer: &str) {
"Catch-up source doesn't answer our sync messages; catching up from another peer"
);
resync_everyone(state);
+ let (state, peer) = (state.clone(), peer.to_owned());
+ tokio::spawn(async move { crate::swarm::peer::rehandshake(&state, &peer).await });
}
}