cli: Correctly honor sync timeout
This commit is contained in:
parent
38a76a42de
commit
8f89f088c6
|
|
@ -525,7 +525,7 @@ fn announce_refs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for seed in result.timeout {
|
for seed in result.timed_out {
|
||||||
term::notice!("Seed {seed} timed out..");
|
term::notice!("Seed {seed} timed out..");
|
||||||
}
|
}
|
||||||
if result.synced.is_empty() {
|
if result.synced.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -640,7 +640,7 @@ impl From<Vec<Seed>> for Seeds {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AnnounceResult {
|
pub struct AnnounceResult {
|
||||||
/// Nodes that timed out.
|
/// Nodes that timed out.
|
||||||
pub timeout: Vec<NodeId>,
|
pub timed_out: Vec<NodeId>,
|
||||||
/// Nodes that synced.
|
/// Nodes that synced.
|
||||||
pub synced: Vec<(NodeId, time::Duration)>,
|
pub synced: Vec<(NodeId, time::Duration)>,
|
||||||
}
|
}
|
||||||
|
|
@ -937,34 +937,34 @@ impl Node {
|
||||||
|
|
||||||
let mut unsynced = seeds.into_iter().collect::<BTreeSet<_>>();
|
let mut unsynced = seeds.into_iter().collect::<BTreeSet<_>>();
|
||||||
let mut synced = HashMap::new();
|
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();
|
let started = time::Instant::now();
|
||||||
|
|
||||||
callback(AnnounceEvent::Announced, &synced);
|
callback(AnnounceEvent::Announced, &synced);
|
||||||
|
|
||||||
for e in events {
|
for e in events {
|
||||||
|
let elapsed = started.elapsed();
|
||||||
|
if elapsed >= timeout {
|
||||||
|
timed_out.extend(unsynced.iter());
|
||||||
|
break;
|
||||||
|
}
|
||||||
match e {
|
match e {
|
||||||
Ok(Event::RefsSynced {
|
Ok(Event::RefsSynced {
|
||||||
remote,
|
remote,
|
||||||
rid: rid_,
|
rid: rid_,
|
||||||
at,
|
at,
|
||||||
}) if rid == rid_ && refs.at == at => {
|
}) if rid == rid_ && refs.at == at => {
|
||||||
let elapsed = started.elapsed();
|
|
||||||
log::debug!(target: "radicle", "Received {e:?}");
|
log::debug!(target: "radicle", "Received {e:?}");
|
||||||
|
|
||||||
unsynced.remove(&remote);
|
unsynced.remove(&remote);
|
||||||
// We can receive synced events from nodes we didn't directly announce to,
|
// We can receive synced events from nodes we didn't directly announce to,
|
||||||
// and it's possible to receive duplicates as well.
|
// and it's possible to receive duplicates as well.
|
||||||
if synced.insert(remote, elapsed).is_none() {
|
if synced.insert(remote, elapsed).is_none() {
|
||||||
if callback(
|
let event = AnnounceEvent::RefsSynced {
|
||||||
AnnounceEvent::RefsSynced {
|
remote,
|
||||||
remote,
|
time: elapsed,
|
||||||
time: elapsed,
|
};
|
||||||
},
|
if callback(event, &synced).is_break() {
|
||||||
&synced,
|
|
||||||
)
|
|
||||||
.is_break()
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -972,7 +972,7 @@ impl Node {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|
||||||
Err(Error::TimedOut) => {
|
Err(Error::TimedOut) => {
|
||||||
timeout.extend(unsynced.iter());
|
timed_out.extend(unsynced.iter());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
|
|
@ -981,8 +981,9 @@ impl Node {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(AnnounceResult {
|
Ok(AnnounceResult {
|
||||||
timeout,
|
timed_out,
|
||||||
synced: synced.into_iter().collect(),
|
synced: synced.into_iter().collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue