mirror of https://github.com/waku-org/nwaku.git
fix: avoid segfault by setting a default num peers requested in PX (#3122)
This commit is contained in:
parent
3321fd05e7
commit
82fd5dde61
|
@ -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)
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Reference in New Issue