Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix: notification only about live adults
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and dirvine committed Apr 30, 2021
1 parent f099483 commit 01a8524
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/routing/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,11 @@ impl Core {
return Ok(vec![]);
}

let old_adults: BTreeSet<_> = self.section.adults().map(|peer| *peer.name()).collect();
let old_adults: BTreeSet<_> = self
.section
.live_adults()
.map(|peer| *peer.name())
.collect();

let snapshot = self.state_snapshot();
trace!(
Expand All @@ -1146,7 +1150,11 @@ impl Core {
self.network.merge(network, self.section.chain());

if !self.is_elder() {
let new_adults: BTreeSet<_> = self.section.adults().map(|peer| *peer.name()).collect();
let new_adults: BTreeSet<_> = self
.section
.live_adults()
.map(|peer| *peer.name())
.collect();
if old_adults != new_adults {
self.send_event(Event::AdultsChanged(new_adults));
}
Expand Down Expand Up @@ -2046,7 +2054,7 @@ impl Core {

let mut commands = vec![];

let adults: Vec<_> = self.section.adults().copied().collect();
let adults: Vec<_> = self.section.live_adults().copied().collect();

let variant = Variant::Sync {
section: self.section.clone(),
Expand Down
11 changes: 11 additions & 0 deletions src/section/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ impl Section {
.filter(move |peer| !self.is_elder(peer.name()))
}

/// Returns live adults from our section.
pub fn live_adults(&self) -> impl Iterator<Item = &Peer> {
self.members.joined().filter_map(move |info| {
if !self.is_elder(info.peer.name()) {
Some(&info.peer)
} else {
None
}
})
}

pub fn find_joined_member_by_addr(&self, addr: &SocketAddr) -> Option<&Peer> {
self.members
.joined()
Expand Down

0 comments on commit 01a8524

Please sign in to comment.