-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
Signed-off-by: onur-ozkan <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,7 @@ | |
|
||
use std::{ | ||
cmp::{max, Ordering}, | ||
collections::HashSet, | ||
collections::{hash_map::Entry, VecDeque}, | ||
collections::{BTreeSet, HashMap}, | ||
collections::{hash_map::Entry, BTreeSet, HashMap, HashSet, VecDeque}, | ||
fmt, | ||
net::IpAddr, | ||
task::{Context, Poll}, | ||
|
@@ -2070,6 +2068,14 @@ where | |
|
||
// remove topic from the peer_topics mapping | ||
subscribed_topics.remove(topic_hash); | ||
self.topic_peers.retain(|th, peers| { | ||
if th == topic_hash { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mariocynicys
|
||
peers.remove(propagation_source); | ||
} | ||
|
||
!peers.is_empty() | ||
}); | ||
|
||
unsubscribed_peers.push((*propagation_source, topic_hash.clone())); | ||
// generate an unsubscribe event to be polled | ||
application_event.push(ToSwarm::GenerateEvent(Event::Unsubscribed { | ||
|
@@ -2080,6 +2086,10 @@ where | |
} | ||
|
||
if let Some(m) = self.metrics.as_mut() { | ||
let peer_list = self | ||
.topic_peers | ||
.entry(topic_hash.clone()) | ||
This comment has been minimized.
Sorry, something went wrong.
mariocynicys
|
||
.or_insert_with(Default::default); | ||
This comment has been minimized.
Sorry, something went wrong.
laruh
Member
|
||
m.set_topic_peers(topic_hash, peer_list.len()); | ||
} | ||
} | ||
|
@@ -3337,6 +3347,11 @@ where | |
// support the protocol. | ||
self.peer_topics.remove(&peer_id); | ||
|
||
self.topic_peers.retain(|_, peers| { | ||
peers.remove(&peer_id); | ||
!peers.is_empty() | ||
}); | ||
|
||
// If metrics are enabled, register the disconnection of a peer based on its protocol. | ||
if let Some(metrics) = self.metrics.as_mut() { | ||
let peer_kind = &self | ||
|
since we lock on a single topic hash, why not select it first from the hashmap?
self.topic_peers[topic_hash].remove(source)