Prevent re-adding peers to mesh

This commit is contained in:
NIC619 2019-07-21 22:28:17 +08:00
parent 42093e40ec
commit 99252e49f8
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17

View File

@ -204,8 +204,9 @@ class GossipSub(IPubsubRouter):
# Add fanout peers to mesh and notifies them with a GRAFT(topic) control message.
for peer in fanout_peers:
self.mesh[topic].append(peer)
await self.emit_graft(topic, peer)
if peer not in self.mesh[topic]:
self.mesh[topic].append(peer)
await self.emit_graft(topic, peer)
if topic_in_fanout:
del self.fanout[topic]
@ -281,7 +282,12 @@ class GossipSub(IPubsubRouter):
self.mesh[topic]
)
for peer in selected_peers:
fanout_peers_not_in_mesh = [
peer
for peer in selected_peers
if peer not in self.mesh[topic]
]
for peer in fanout_peers_not_in_mesh:
# Add peer to mesh[topic]
self.mesh[topic].append(peer)
@ -460,7 +466,8 @@ class GossipSub(IPubsubRouter):
# Add peer to mesh for topic
if topic in self.mesh:
self.mesh[topic].append(from_id_str)
if from_id_str not in self.mesh[topic]:
self.mesh[topic].append(from_id_str)
else:
# Respond with PRUNE if not subscribed to the topic
await self.emit_prune(topic, sender_peer_id)