-
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,10 @@ where | |
|
||
// remove topic from the peer_topics mapping | ||
subscribed_topics.remove(topic_hash); | ||
if let Some(peers) = self.topic_peers.get_mut(topic_hash) { | ||
peers.remove(propagation_source); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
onur-ozkan
Author
Member
|
||
} | ||
|
||
unsubscribed_peers.push((*propagation_source, topic_hash.clone())); | ||
// generate an unsubscribe event to be polled | ||
application_event.push(ToSwarm::GenerateEvent(Event::Unsubscribed { | ||
|
@@ -2079,8 +2081,11 @@ where | |
} | ||
} | ||
|
||
if let Some(m) = self.metrics.as_mut() { | ||
m.set_topic_peers(topic_hash, peer_list.len()); | ||
if let (Some(m), Some(len)) = ( | ||
self.metrics.as_mut(), | ||
self.topic_peers.get(topic_hash).map(|set| set.len()), | ||
This comment has been minimized.
Sorry, something went wrong.
mariocynicys
|
||
) { | ||
m.set_topic_peers(topic_hash, len); | ||
} | ||
} | ||
|
||
|
@@ -3337,6 +3342,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 | ||
|
i meant we still should remove the empty key if the propagation source was the last one, but just for this key
topic_hash
and not looping over all the topics with each unsubscribtion.also looking at this now, looks like we already removed the
propagatino_source
from thetopic_peers[topic_hash]
a couple of lines above (L2061) (note that thispeer_list
variable is an entry reference totopic_peers[topoic_hash]
.so we just need to remove the
topic_peers[topic_hash]
all together if no more peers are listening (emmpty vector).