From 0d9e9fbdd2e61aba6a65886ef19f55073c5902bd Mon Sep 17 00:00:00 2001 From: Simon-Pierre Vivier Date: Fri, 22 Sep 2023 15:13:50 -0400 Subject: [PATCH] feat: peer manager can filter select peer by shard (#2063) --- waku/node/peer_manager/peer_manager.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/waku/node/peer_manager/peer_manager.nim b/waku/node/peer_manager/peer_manager.nim index 3e7d0f533..a705ed450 100644 --- a/waku/node/peer_manager/peer_manager.nim +++ b/waku/node/peer_manager/peer_manager.nim @@ -16,6 +16,7 @@ import ../../common/nimchronos, ../../waku_core, ../../waku_relay, + ../../waku_enr/sharding, ./peer_store/peer_storage, ./waku_peer_store @@ -631,11 +632,14 @@ proc prunePeerStore*(pm: PeerManager) = capacity = capacity, pruned = pruned -proc selectPeer*(pm: PeerManager, proto: string): Option[RemotePeerInfo] = +proc selectPeer*(pm: PeerManager, proto: string, shard: Option[PubsubTopic] = none(PubsubTopic)): Option[RemotePeerInfo] = debug "Selecting peer from peerstore", protocol=proto # Selects the best peer for a given protocol - let peers = pm.peerStore.getPeersByProtocol(proto) + var peers = pm.peerStore.getPeersByProtocol(proto) + + if shard.isSome(): + peers.keepItIf((it.enr.isSome() and it.enr.get().containsShard(shard.get()))) # No criteria for selecting a peer for WakuRelay, random one if proto == WakuRelayCodec: