Skip to content

Commit

Permalink
Added timeout & missing call to disco
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS committed Oct 5, 2023
1 parent bd1ac61 commit 743e78c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 6 additions & 1 deletion waku/waku_api/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ type DiscoveryHandler* = proc(): Future[Result[Option[RemotePeerInfo], string]]
proc defaultDiscoveryHandler*(discv5: WakuDiscoveryV5, cap: Capabilities): DiscoveryHandler =
proc(): Future[Result[Option[RemotePeerInfo], string]] {.async, closure.} =
#Discv5 is already filtering peers by shards no need to pass a predicate.
var peers = await discv5.findRandomPeers()
let findPeers = discv5.findRandomPeers()

if not await findPeers.withTimeout(60.seconds):
return err("Discovery process out!")

var peers = findPeers.read()

peers.keepItIf(it.supportsCapability(cap))

Expand Down
25 changes: 17 additions & 8 deletions waku/waku_api/rest/filter/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,23 @@ proc filterPostPutSubscriptionRequestHandler(

let req: FilterSubscribeRequest = decodedBody.value()

let peerOpt = node.peerManager.selectPeer(WakuFilterSubscribeCodec)

if peerOpt.isNone():
return makeRestResponse(req.requestId, FilterSubscribeError.serviceUnavailable("No suitable peers"))

let subFut = node.filterSubscribe(req.pubsubTopic,
req.contentFilters,
peerOpt.get())
let peer = node.peerManager.selectPeer(WakuFilterSubscribeCodec).valueOr:
let handler = discHandler.valueOr:
return makeRestResponse(
req.requestId,
FilterSubscribeError.serviceUnavailable("No suitable peers")
)

let peerOp = (await handler()).valueOr:
return RestApiResponse.internalServerError($error)

peerOp.valueOr:
return makeRestResponse(
req.requestId,
FilterSubscribeError.serviceUnavailable("No suitable peers")
)

let subFut = node.filterSubscribe(req.pubsubTopic, req.contentFilters, peer)

if not await subFut.withTimeout(futTimeoutForSubscriptionProcessing):
error "Failed to subscribe to contentFilters do to timeout!"
Expand Down

0 comments on commit 743e78c

Please sign in to comment.