Del entry if no more peers subscribe to the topic

This commit is contained in:
NIC619 2019-11-30 20:02:11 +08:00
parent e59ac6a250
commit 0a52a05375
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17

View File

@ -316,7 +316,11 @@ class Pubsub:
for topic in self.peer_topics:
if peer_id in self.peer_topics[topic]:
self.peer_topics[topic].remove(peer_id)
# 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,7 +365,11 @@ class Pubsub:
else:
if sub_message.topicid in self.peer_topics:
if origin_id in self.peer_topics[sub_message.topicid]:
self.peer_topics[sub_message.topicid].remove(origin_id)
# 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?
async def handle_talk(self, publish_message: rpc_pb2.Message) -> None: