aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/relay.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/relay.rs')
-rw-r--r--src/swarm/relay.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs
index 95abab8..f141dbb 100644
--- a/src/swarm/relay.rs
+++ b/src/swarm/relay.rs
@@ -50,7 +50,8 @@ use crate::swarm::peer::announce_heads;
use crate::swarm::topology;
use crate::transport::{self, HeadsSummary};
-/// A pull that brought nothing for this long no longer blocks pulling from another peer.
+/// A pull that brought nothing for this long no longer blocks pulling from another peer
+/// (sooner once its answer is overdue: `pull_unanswered`).
const PULL_TIMEOUT: Duration = Duration::from_secs(15);
/// The longest a STATUS's heads we lack wait before we pull them (`pull_after_grace`: a
@@ -336,6 +337,26 @@ pub(crate) fn pulled(state: &AppState, peer: &str) {
tokio::spawn(async move { pull_next(&state).await });
}
+/// Our sync message to `peer` went unanswered for the reply timeout: a pull from it no
+/// longer blocks the others, and the next waiting neighbour's turn comes. Otherwise
+/// they would wait for `PULL_TIMEOUT`, and then for their next keepalive, as nothing
+/// else brings them back.
+pub(crate) fn pull_unanswered(state: &AppState, peer: &str) {
+ {
+ let mut pulling = state.pulling.lock_or_recover();
+ if pulling.current.as_ref().is_none_or(|(p, _)| p != peer) {
+ return;
+ }
+ debug!(peer = %peer, "Pull unanswered; pulling from the next neighbour");
+ pulling.current = None;
+ if pulling.waiting.is_empty() {
+ return;
+ }
+ }
+ let state = state.clone();
+ tokio::spawn(async move { pull_next(&state).await });
+}
+
/// Pulls from the first waiting neighbour that still has heads we lack.
async fn pull_next(state: &AppState) {
loop {