From 8f89f088c6fcc5722dbc19488c9908454d917bc8 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 21 Mar 2024 17:39:19 +0100 Subject: [PATCH] cli: Correctly honor sync timeout --- radicle-cli/src/commands/sync.rs | 2 +- radicle/src/node.rs | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/radicle-cli/src/commands/sync.rs b/radicle-cli/src/commands/sync.rs index 1af04476..e45cb60a 100644 --- a/radicle-cli/src/commands/sync.rs +++ b/radicle-cli/src/commands/sync.rs @@ -525,7 +525,7 @@ fn announce_refs( } } } - for seed in result.timeout { + for seed in result.timed_out { term::notice!("Seed {seed} timed out.."); } if result.synced.is_empty() { diff --git a/radicle/src/node.rs b/radicle/src/node.rs index 7b0e15f3..7a4d6dcb 100644 --- a/radicle/src/node.rs +++ b/radicle/src/node.rs @@ -640,7 +640,7 @@ impl From> for Seeds { #[derive(Debug)] pub struct AnnounceResult { /// Nodes that timed out. - pub timeout: Vec, + pub timed_out: Vec, /// Nodes that synced. pub synced: Vec<(NodeId, time::Duration)>, } @@ -937,34 +937,34 @@ impl Node { let mut unsynced = seeds.into_iter().collect::>(); let mut synced = HashMap::new(); - let mut timeout: Vec = Vec::new(); + let mut timed_out: Vec = Vec::new(); let started = time::Instant::now(); callback(AnnounceEvent::Announced, &synced); for e in events { + let elapsed = started.elapsed(); + if elapsed >= timeout { + timed_out.extend(unsynced.iter()); + break; + } match e { Ok(Event::RefsSynced { remote, rid: rid_, at, }) if rid == rid_ && refs.at == at => { - let elapsed = started.elapsed(); log::debug!(target: "radicle", "Received {e:?}"); unsynced.remove(&remote); // We can receive synced events from nodes we didn't directly announce to, // and it's possible to receive duplicates as well. if synced.insert(remote, elapsed).is_none() { - if callback( - AnnounceEvent::RefsSynced { - remote, - time: elapsed, - }, - &synced, - ) - .is_break() - { + let event = AnnounceEvent::RefsSynced { + remote, + time: elapsed, + }; + if callback(event, &synced).is_break() { break; } } @@ -972,7 +972,7 @@ impl Node { Ok(_) => {} Err(Error::TimedOut) => { - timeout.extend(unsynced.iter()); + timed_out.extend(unsynced.iter()); break; } Err(e) => return Err(e), @@ -981,8 +981,9 @@ impl Node { break; } } + Ok(AnnounceResult { - timeout, + timed_out, synced: synced.into_iter().collect(), }) }