Skip to content

Commit

Permalink
adding discv5 bootstrap nodes to the peer manager
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 17, 2024
1 parent 6de32cc commit c92889c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions waku/discovery/waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,25 @@ proc parseBootstrapAddress(address: string): Result[enr.Record, cstring] =
else:
return err("Ignoring unrecognized bootstrap address type")

proc addBootstrapNode*(bootstrapAddr: string, bootstrapEnrs: var seq[enr.Record]) =
proc addBootstrapNode*(
peerManager: PeerManager, bootstrapAddr: string, bootstrapEnrs: var seq[enr.Record]
) =
# Ignore empty lines or lines starting with #
if bootstrapAddr.len == 0 or bootstrapAddr[0] == '#':
return

let enrRes = parseBootstrapAddress(bootstrapAddr)
if enrRes.isErr():
debug "ignoring invalid bootstrap address", reason = enrRes.error
let enr = parseBootstrapAddress(bootstrapAddr).valueOr:
debug "ignoring invalid bootstrap address", reason = $error
return

bootstrapEnrs.add(enrRes.value)
let peerInfoRes = enr.toRemotePeerInfo()
if peerInfoRes.isOk():
peerManager.addPeer(peerInfoRes.get(), PeerOrigin.Discv5)
else:
debug "could not convert discv5 bootstrap node to peerInfo, not adding peer to Peer Store",
enr = $enr

bootstrapEnrs.add(enr)

proc setupDiscoveryV5*(
myENR: enr.Record,
Expand All @@ -379,7 +387,7 @@ proc setupDiscoveryV5*(

# parse enrURIs from the configuration and add the resulting ENRs to the discv5BootstrapEnrs seq
for enrUri in conf.discv5BootstrapNodes:
addBootstrapNode(enrUri, discv5BootstrapEnrs)
nodePeerManager.addBootstrapNode(enrUri, discv5BootstrapEnrs)

discv5BootstrapEnrs.add(dynamicBootstrapEnrs)

Expand Down
4 changes: 2 additions & 2 deletions waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,13 @@ proc startNode*(
return err("failed to start waku node: " & getCurrentExceptionMsg())

# Connect to configured static nodes
if conf.staticnodes.len > 0:
if conf.relay and conf.staticnodes.len > 0:
try:
await connectToNodes(node, conf.staticnodes, "static")
except CatchableError:
return err("failed to connect to static nodes: " & getCurrentExceptionMsg())

if dynamicBootstrapNodes.len > 0:
if conf.relay and dynamicBootstrapNodes.len > 0:
info "Connecting to dynamic bootstrap peers"
try:
await connectToNodes(node, dynamicBootstrapNodes, "dynamic bootstrap")
Expand Down

0 comments on commit c92889c

Please sign in to comment.