Skip to content

Commit

Permalink
feat: peer manager can filter select peer by shard (#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS authored Sep 22, 2023
1 parent 6fdee05 commit 0d9e9fb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions waku/node/peer_manager/peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import
../../common/nimchronos,
../../waku_core,
../../waku_relay,
../../waku_enr/sharding,
./peer_store/peer_storage,
./waku_peer_store

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0d9e9fb

Please sign in to comment.