Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Correctly honor sync timeout
cloudhead committed 2 years ago
commit 8f89f088c6fcc5722dbc19488c9908454d917bc8
parent 38a76a42deed6cb98a4c8ccf7874b4adca3e6b07
2 files changed +16 -15
modified 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() {
modified radicle/src/node.rs
@@ -640,7 +640,7 @@ impl From<Vec<Seed>> for Seeds {
#[derive(Debug)]
pub struct AnnounceResult {
    /// Nodes that timed out.
-
    pub timeout: Vec<NodeId>,
+
    pub timed_out: Vec<NodeId>,
    /// Nodes that synced.
    pub synced: Vec<(NodeId, time::Duration)>,
}
@@ -937,34 +937,34 @@ impl Node {

        let mut unsynced = seeds.into_iter().collect::<BTreeSet<_>>();
        let mut synced = HashMap::new();
-
        let mut timeout: Vec<NodeId> = Vec::new();
+
        let mut timed_out: Vec<NodeId> = 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(),
        })
    }