Skip to content

Commit

Permalink
feat(discv5): added find random nodes with predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
LNSD committed May 2, 2023
1 parent 16b4452 commit d514e32
Show file tree
Hide file tree
Showing 7 changed files with 414 additions and 310 deletions.
10 changes: 4 additions & 6 deletions apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,11 @@ proc startNode(node: WakuNode, conf: WakuNodeConf,
except CatchableError:
return err("failed to start waku node: " & getCurrentExceptionMsg())

# Start discv5 and connect to discovered nodes
# Start discv5 based discovery service (discovery loop)
if conf.discv5Discovery:
try:
if not await node.startDiscv5():
error "could not start Discovery v5"
except CatchableError:
return err("failed to start waku discovery v5: " & getCurrentExceptionMsg())
let startDiscv5Res = await node.startDiscv5()
if startDiscv5Res.isErr():
return err("failed to start waku discovery v5: " & startDiscv5Res.error)

# Connect to configured static nodes
if conf.staticnodes.len > 0:
Expand Down
6 changes: 4 additions & 2 deletions examples/v2/publisher.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
await node.start()
await node.mountRelay()
node.peerManager.start()
if not await node.startDiscv5():
error "failed to start discv5"

let discv5Res = await node.startDiscv5()
if discv5Res.isErr():
error "failed to start discv5", error= discv5Res.error
quit(1)

# wait for a minimum of peers to be connected, otherwise messages wont be gossiped
Expand Down
4 changes: 3 additions & 1 deletion examples/v2/subscriber.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ proc setupAndSubscribe(rng: ref HmacDrbgContext) {.async.} =
await node.start()
await node.mountRelay()
node.peerManager.start()
if not await node.startDiscv5():

let discv5Res = await node.startDiscv5()
if discv5Res.isErr():
error "failed to start discv5"
quit(1)

Expand Down
Loading

0 comments on commit d514e32

Please sign in to comment.