feat: peer manager can filter select peer by shard (#2063)

This commit is contained in:
Simon-Pierre Vivier 2023-09-22 15:13:50 -04:00 committed by GitHub
parent 6fdee05811
commit 0d9e9fbdd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -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: