Skip to content

Commit

Permalink
fix(networkmonitor): break import dependency with wakunode2 app
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Delgado committed Apr 19, 2023
1 parent 91baa23 commit 043feac
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions tools/networkmonitor/networkmonitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ else:

import
std/[tables,strutils,times,sequtils],
stew/results,
stew/shims/net,
chronicles,
chronicles/topics_registry,
Expand All @@ -14,12 +15,11 @@ import
eth/keys,
eth/p2p/discoveryv5/enr,
libp2p/crypto/crypto,
libp2p/nameresolving/dnsresolver,
metrics,
metrics/chronos_httpserver,
presto/[route, server, client]

import
../../apps/wakunode2/wakunode2,
../../waku/v2/node/peer_manager,
../../waku/v2/waku_node,
../../waku/v2/waku_core,
Expand Down Expand Up @@ -148,7 +148,7 @@ proc populateInfoFromIp(allPeersRef: CustomPeersTableRef,
var location: NodeLocation
try:
# IP-API endpoints are now limited to 45 HTTP requests per minute
await sleepAsync(1400)
await sleepAsync(1400.millis)
let response = await restClient.ipToLocation(allPeersRef[peer].ip)
location = response.data
except CatchableError:
Expand Down Expand Up @@ -193,7 +193,33 @@ proc crawlNetwork(node: WakuNode,
# we dont run ipMajorityLoop
# we dont run revalidateLoop

await sleepAsync(crawlInterval)
await sleepAsync(crawlInterval.millis)

proc retrieveDynamicBootstrapNodes(dnsDiscovery: bool, dnsDiscoveryUrl: string, dnsDiscoveryNameServers: seq[ValidIpAddress]): Result[seq[RemotePeerInfo], string] =
if dnsDiscovery and dnsDiscoveryUrl != "":
# DNS discovery
debug "Discovering nodes using Waku DNS discovery", url=dnsDiscoveryUrl

var nameServers: seq[TransportAddress]
for ip in dnsDiscoveryNameServers:
nameServers.add(initTAddress(ip, Port(53))) # Assume all servers use port 53

let dnsResolver = DnsResolver.new(nameServers)

proc resolver(domain: string): Future[string] {.async, gcsafe.} =
trace "resolving", domain=domain
let resolved = await dnsResolver.resolveTxt(domain)
return resolved[0] # Use only first answer

var wakuDnsDiscovery = WakuDnsDiscovery.init(dnsDiscoveryUrl, resolver)
if wakuDnsDiscovery.isOk():
return wakuDnsDiscovery.get().findPeers()
.mapErr(proc (e: cstring): string = $e)
else:
warn "Failed to init Waku DNS discovery"

debug "No method for retrieving dynamic bootstrap nodes specified."
ok(newSeq[RemotePeerInfo]()) # Return an empty seq by default

proc getBootstrapFromDiscDns(conf: NetworkMonitorConf): Result[seq[enr.Record], string] =
try:
Expand Down

0 comments on commit 043feac

Please sign in to comment.