Skip to content

Commit

Permalink
fix: setting a default num peers requested in PX
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 16, 2024
1 parent 18c375a commit 15893d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,11 @@ proc startNode*(

# retrieve px peers and add the to the peer store
if conf.peerExchangeNode != "":
let desiredOutDegree = node.wakuRelay.parameters.d.uint64()
let desiredOutDegree =
if not node.wakuRelay.isNil():
node.wakuRelay.parameters.d.uint64()
else:
DefaultPXNumPeersReq
(await node.fetchPeerExchangePeers(desiredOutDegree)).isOkOr:
error "error while fetching peers from peer exchange", error = error
quit(QuitFailure)
Expand Down
7 changes: 4 additions & 3 deletions waku/waku_peer_exchange/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const
CacheRefreshInterval = 10.minutes

WakuPeerExchangeCodec* = "/vac/waku/peer-exchange/2.0.0-alpha1"
DefaultPXNumPeersReq* = 5.uint64()

# Error types (metric label values)
const
Expand All @@ -57,7 +58,7 @@ type
requestRateLimiter*: RequestRateLimiter

proc request*(
wpx: WakuPeerExchange, numPeers: uint64, conn: Connection
wpx: WakuPeerExchange, numPeers = DefaultPXNumPeersReq, conn: Connection
): Future[WakuPeerExchangeResult[PeerExchangeResponse]] {.async: (raises: []).} =
let rpc = PeerExchangeRpc.makeRequest(numPeers)

Expand Down Expand Up @@ -99,7 +100,7 @@ proc request*(
return ok(decodedBuff.get().response)

proc request*(
wpx: WakuPeerExchange, numPeers: uint64, peer: RemotePeerInfo
wpx: WakuPeerExchange, numPeers = DefaultPXNumPeersReq, peer: RemotePeerInfo
): Future[WakuPeerExchangeResult[PeerExchangeResponse]] {.async: (raises: []).} =
try:
let connOpt = await wpx.peerManager.dialPeer(peer, WakuPeerExchangeCodec)
Expand All @@ -120,7 +121,7 @@ proc request*(
)

proc request*(
wpx: WakuPeerExchange, numPeers: uint64
wpx: WakuPeerExchange, numPeers = DefaultPXNumPeersReq
): Future[WakuPeerExchangeResult[PeerExchangeResponse]] {.async: (raises: []).} =
let peerOpt = wpx.peerManager.selectPeer(WakuPeerExchangeCodec)
if peerOpt.isNone():
Expand Down

0 comments on commit 15893d1

Please sign in to comment.