Prevent multiple events per synced peer
We were not properly guarding against the fact that we could receive multiple sync events from the same node. Normally though, this wouldn't happen, as further announcements would be stale.
This commit is contained in:
parent
159944f7b5
commit
f38d2b2ef8
|
|
@ -1,4 +1,5 @@
|
||||||
#![allow(clippy::type_complexity)]
|
#![allow(clippy::type_complexity)]
|
||||||
|
#![allow(clippy::collapsible_if)]
|
||||||
mod features;
|
mod features;
|
||||||
|
|
||||||
pub mod address;
|
pub mod address;
|
||||||
|
|
@ -897,13 +898,13 @@ impl Node {
|
||||||
rid: RepoId,
|
rid: RepoId,
|
||||||
seeds: impl IntoIterator<Item = NodeId>,
|
seeds: impl IntoIterator<Item = NodeId>,
|
||||||
timeout: time::Duration,
|
timeout: time::Duration,
|
||||||
mut callback: impl FnMut(AnnounceEvent, &[PublicKey]) -> ControlFlow<()>,
|
mut callback: impl FnMut(AnnounceEvent, &HashSet<PublicKey>) -> ControlFlow<()>,
|
||||||
) -> Result<AnnounceResult, Error> {
|
) -> Result<AnnounceResult, Error> {
|
||||||
let events = self.subscribe(timeout)?;
|
let events = self.subscribe(timeout)?;
|
||||||
let refs = self.announce_refs(rid)?;
|
let refs = self.announce_refs(rid)?;
|
||||||
|
|
||||||
let mut unsynced = seeds.into_iter().collect::<BTreeSet<_>>();
|
let mut unsynced = seeds.into_iter().collect::<BTreeSet<_>>();
|
||||||
let mut synced = Vec::new();
|
let mut synced = HashSet::new();
|
||||||
let mut timeout: Vec<NodeId> = Vec::new();
|
let mut timeout: Vec<NodeId> = Vec::new();
|
||||||
|
|
||||||
callback(AnnounceEvent::Announced, &synced);
|
callback(AnnounceEvent::Announced, &synced);
|
||||||
|
|
@ -915,10 +916,15 @@ impl Node {
|
||||||
rid: rid_,
|
rid: rid_,
|
||||||
at,
|
at,
|
||||||
}) if rid == rid_ && refs.at == at => {
|
}) if rid == rid_ && refs.at == at => {
|
||||||
|
log::debug!(target: "radicle", "Received {e:?}");
|
||||||
|
|
||||||
unsynced.remove(&remote);
|
unsynced.remove(&remote);
|
||||||
synced.push(remote);
|
// We can receive synced events from nodes we didn't directly announce to,
|
||||||
if callback(AnnounceEvent::RefsSynced { remote }, &synced).is_break() {
|
// and it's possible to receive duplicates as well.
|
||||||
break;
|
if synced.insert(remote) {
|
||||||
|
if callback(AnnounceEvent::RefsSynced { remote }, &synced).is_break() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
|
@ -933,7 +939,10 @@ impl Node {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(AnnounceResult { timeout, synced })
|
Ok(AnnounceResult {
|
||||||
|
timeout,
|
||||||
|
synced: synced.into_iter().collect(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue