Fix: should not remove topic if no peers

This commit is contained in:
NIC619 2019-12-03 23:10:47 +08:00
parent a9abf1e3dd
commit c08b2375e1
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17
2 changed files with 5 additions and 20 deletions

View File

@ -150,16 +150,10 @@ class GossipSub(IPubsubRouter):
for topic in self.mesh: for topic in self.mesh:
if peer_id in self.mesh[topic]: if peer_id in self.mesh[topic]:
# Delete the entry if no other peers left # Delete the entry if no other peers left
if len(self.mesh[topic]) == 1:
del self.mesh[topic]
else:
self.mesh[topic].remove(peer_id) self.mesh[topic].remove(peer_id)
for topic in self.fanout: for topic in self.fanout:
if peer_id in self.fanout[topic]: if peer_id in self.fanout[topic]:
# Delete the entry if no other peers left # Delete the entry if no other peers left
if len(self.fanout[topic]) == 1:
del self.fanout[topic]
else:
self.fanout[topic].remove(peer_id) self.fanout[topic].remove(peer_id)
self.peers_to_protocol.pop(peer_id, None) self.peers_to_protocol.pop(peer_id, None)
@ -647,9 +641,6 @@ class GossipSub(IPubsubRouter):
# Remove peer from mesh for topic, if peer is in topic # Remove peer from mesh for topic, if peer is in topic
if topic in self.mesh and sender_peer_id in self.mesh[topic]: if topic in self.mesh and sender_peer_id in self.mesh[topic]:
if len(self.mesh[topic]) == 1:
del self.mesh[topic]
else:
self.mesh[topic].remove(sender_peer_id) self.mesh[topic].remove(sender_peer_id)
# RPC emitters # RPC emitters

View File

@ -317,9 +317,6 @@ class Pubsub:
for topic in self.peer_topics: for topic in self.peer_topics:
if peer_id in self.peer_topics[topic]: if peer_id in self.peer_topics[topic]:
# Delete the entry if no other peers left # 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.peer_topics[topic].remove(peer_id)
self.router.remove_peer(peer_id) self.router.remove_peer(peer_id)
@ -364,9 +361,6 @@ class Pubsub:
if sub_message.topicid in self.peer_topics: if sub_message.topicid in self.peer_topics:
if origin_id in self.peer_topics[sub_message.topicid]: if origin_id in self.peer_topics[sub_message.topicid]:
# Delete the entry if no other peers left # 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) self.peer_topics[sub_message.topicid].remove(origin_id)
# FIXME(mhchia): Change the function name? # FIXME(mhchia): Change the function name?