From 36575e8c9be6b8d3daabc93102285f09b01abbfd Mon Sep 17 00:00:00 2001 From: NIC619 Date: Fri, 19 Jul 2019 19:56:25 +0800 Subject: [PATCH] Add check to prevent gossipsub re-join and re-leave --- libp2p/pubsub/gossipsub.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index 8524ca6c..b2e6f38f 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -179,9 +179,10 @@ class GossipSub(IPubsubRouter): subscription announcement :param topic: topic to join """ + if topic in self.mesh: + return # Create mesh[topic] if it does not yet exist - if topic not in self.mesh: - self.mesh[topic] = [] + self.mesh[topic] = [] if topic in self.fanout and len(self.fanout[topic]) == self.degree: # If router already has D peers from the fanout peers of a topic @@ -228,6 +229,8 @@ class GossipSub(IPubsubRouter): It is invoked after the unsubscription announcement. :param topic: topic to leave """ + if topic not in self.mesh: + return # Notify the peers in mesh[topic] with a PRUNE(topic) message for peer in self.mesh[topic]: await self.emit_prune(topic, peer)