mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-03-24 22:21:28 +00:00
Del entry if no more peers subscribe to the topic
This commit is contained in:
@ -316,6 +316,10 @@ class Pubsub:
|
||||
|
||||
for topic in self.peer_topics:
|
||||
if peer_id in self.peer_topics[topic]:
|
||||
# Delete the entry if no other peers left
|
||||
if len(self.peer_topics[topic]) == 1:
|
||||
del self.peer_topics[topic]
|
||||
else:
|
||||
self.peer_topics[topic].remove(peer_id)
|
||||
|
||||
self.router.remove_peer(peer_id)
|
||||
@ -361,6 +365,10 @@ class Pubsub:
|
||||
else:
|
||||
if sub_message.topicid in self.peer_topics:
|
||||
if origin_id in self.peer_topics[sub_message.topicid]:
|
||||
# Delete the entry if no other peers left
|
||||
if len(self.peer_topics[sub_message.topicid]) == 1:
|
||||
del self.peer_topics[sub_message.topicid]
|
||||
else:
|
||||
self.peer_topics[sub_message.topicid].remove(origin_id)
|
||||
|
||||
# FIXME(mhchia): Change the function name?
|
||||
|
||||
Reference in New Issue
Block a user