mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Prevent re-adding peers to mesh
This commit is contained in:
@ -204,8 +204,9 @@ class GossipSub(IPubsubRouter):
|
|||||||
|
|
||||||
# Add fanout peers to mesh and notifies them with a GRAFT(topic) control message.
|
# Add fanout peers to mesh and notifies them with a GRAFT(topic) control message.
|
||||||
for peer in fanout_peers:
|
for peer in fanout_peers:
|
||||||
self.mesh[topic].append(peer)
|
if peer not in self.mesh[topic]:
|
||||||
await self.emit_graft(topic, peer)
|
self.mesh[topic].append(peer)
|
||||||
|
await self.emit_graft(topic, peer)
|
||||||
|
|
||||||
if topic_in_fanout:
|
if topic_in_fanout:
|
||||||
del self.fanout[topic]
|
del self.fanout[topic]
|
||||||
@ -281,7 +282,12 @@ class GossipSub(IPubsubRouter):
|
|||||||
self.mesh[topic]
|
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]
|
# Add peer to mesh[topic]
|
||||||
self.mesh[topic].append(peer)
|
self.mesh[topic].append(peer)
|
||||||
|
|
||||||
@ -460,7 +466,8 @@ class GossipSub(IPubsubRouter):
|
|||||||
|
|
||||||
# Add peer to mesh for topic
|
# Add peer to mesh for topic
|
||||||
if topic in self.mesh:
|
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:
|
else:
|
||||||
# Respond with PRUNE if not subscribed to the topic
|
# Respond with PRUNE if not subscribed to the topic
|
||||||
await self.emit_prune(topic, sender_peer_id)
|
await self.emit_prune(topic, sender_peer_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user