diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index dcd2179043..7cc24428a6 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -414,7 +414,9 @@ proc startNode*( # retrieve px peers and add the to the peer store if conf.peerExchangeNode != "": - let desiredOutDegree = node.wakuRelay.parameters.d.uint64() + var desiredOutDegree = DefaultPXNumPeersReq + if not node.wakuRelay.isNil() and node.wakuRelay.parameters.d.uint64() > 0: + desiredOutDegree = node.wakuRelay.parameters.d.uint64() (await node.fetchPeerExchangePeers(desiredOutDegree)).isOkOr: error "error while fetching peers from peer exchange", error = error quit(QuitFailure) diff --git a/waku/waku_peer_exchange/protocol.nim b/waku/waku_peer_exchange/protocol.nim index 4bfc03c13b..6821d848b2 100644 --- a/waku/waku_peer_exchange/protocol.nim +++ b/waku/waku_peer_exchange/protocol.nim @@ -35,6 +35,7 @@ const # TODO what is the expected size of a PX message? As currently specified, it can contain an arbitary number of ENRs... MaxPeersCacheSize = 60 CacheRefreshInterval = 10.minutes + DefaultPXNumPeersReq* = 5.uint64() WakuPeerExchangeCodec* = "/vac/waku/peer-exchange/2.0.0-alpha1" @@ -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) @@ -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) @@ -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():