mirror of https://github.com/waku-org/nwaku.git
chore: discv5 re-org clean-up (#1823)
- Remove discv5 from node and it's builder - Require a record to init a node (was previously using discv5 record). - Fix various tests that assumed nodes with discv5. - Fix ENR creation - Fix wakubridge - Fix networkmonitor
This commit is contained in:
parent
e4d9ee1f7a
commit
cf46fb7cf6
|
@ -160,6 +160,7 @@ proc populateInfoFromIp(allPeersRef: CustomPeersTableRef,
|
||||||
# crawls the network discovering peers and trying to connect to them
|
# crawls the network discovering peers and trying to connect to them
|
||||||
# metrics are processed and exposed
|
# metrics are processed and exposed
|
||||||
proc crawlNetwork(node: WakuNode,
|
proc crawlNetwork(node: WakuNode,
|
||||||
|
wakuDiscv5: WakuDiscoveryV5,
|
||||||
restClient: RestClientRef,
|
restClient: RestClientRef,
|
||||||
conf: NetworkMonitorConf,
|
conf: NetworkMonitorConf,
|
||||||
allPeersRef: CustomPeersTableRef) {.async.} =
|
allPeersRef: CustomPeersTableRef) {.async.} =
|
||||||
|
@ -167,10 +168,10 @@ proc crawlNetwork(node: WakuNode,
|
||||||
let crawlInterval = conf.refreshInterval * 1000
|
let crawlInterval = conf.refreshInterval * 1000
|
||||||
while true:
|
while true:
|
||||||
# discover new random nodes
|
# discover new random nodes
|
||||||
let discoveredNodes = await node.wakuDiscv5.protocol.queryRandom()
|
let discoveredNodes = await wakuDiscv5.protocol.queryRandom()
|
||||||
|
|
||||||
# nodes are nested into bucket, flat it
|
# nodes are nested into bucket, flat it
|
||||||
let flatNodes = node.wakuDiscv5.protocol.routingTable.buckets.mapIt(it.nodes).flatten()
|
let flatNodes = wakuDiscv5.protocol.routingTable.buckets.mapIt(it.nodes).flatten()
|
||||||
|
|
||||||
# populate metrics related to capabilities as advertised by the ENR (see waku field)
|
# populate metrics related to capabilities as advertised by the ENR (see waku field)
|
||||||
setDiscoveredPeersCapabilities(flatNodes)
|
setDiscoveredPeersCapabilities(flatNodes)
|
||||||
|
@ -242,27 +243,56 @@ proc getBootstrapFromDiscDns(conf: NetworkMonitorConf): Result[seq[enr.Record],
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
error("failed discovering peers from DNS")
|
error("failed discovering peers from DNS")
|
||||||
|
|
||||||
proc initAndStartNode(conf: NetworkMonitorConf): Result[WakuNode, string] =
|
proc initAndStartApp(conf: NetworkMonitorConf): Result[(WakuNode, WakuDiscoveryV5), string] =
|
||||||
|
let bindIp = try:
|
||||||
|
ValidIpAddress.init("0.0.0.0")
|
||||||
|
except CatchableError:
|
||||||
|
return err("could not start node: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
|
let extIp = try:
|
||||||
|
ValidIpAddress.init("127.0.0.1")
|
||||||
|
except CatchableError:
|
||||||
|
return err("could not start node: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
let
|
let
|
||||||
# some hardcoded parameters
|
# some hardcoded parameters
|
||||||
rng = keys.newRng()
|
rng = keys.newRng()
|
||||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
key = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||||
nodeTcpPort = Port(60000)
|
nodeTcpPort = Port(60000)
|
||||||
nodeUdpPort = Port(9000)
|
nodeUdpPort = Port(9000)
|
||||||
flags = CapabilitiesBitfield.init(lightpush = false, filter = false, store = false, relay = true)
|
flags = CapabilitiesBitfield.init(lightpush = false, filter = false, store = false, relay = true)
|
||||||
|
|
||||||
try:
|
var builder = EnrBuilder.init(key)
|
||||||
let
|
|
||||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
|
||||||
extIp = ValidIpAddress.init("127.0.0.1")
|
|
||||||
|
|
||||||
var builder = WakuNodeBuilder.init()
|
builder.withIpAddressAndPorts(
|
||||||
builder.withNodeKey(nodeKey)
|
ipAddr = some(extIp),
|
||||||
? builder.withNetworkConfigurationDetails(bindIp, nodeTcpPort)
|
tcpPort = some(nodeTcpPort),
|
||||||
let node = ? builder.build()
|
udpPort = some(nodeUdpPort),
|
||||||
|
)
|
||||||
|
builder.withWakuCapabilities(flags)
|
||||||
|
|
||||||
|
let recordRes = builder.build()
|
||||||
|
let record =
|
||||||
|
if recordRes.isErr():
|
||||||
|
return err("cannot build record: " & $recordRes.error)
|
||||||
|
else: recordRes.get()
|
||||||
|
|
||||||
|
var nodeBuilder = WakuNodeBuilder.init()
|
||||||
|
|
||||||
|
nodeBuilder.withNodeKey(key)
|
||||||
|
nodeBuilder.withRecord(record)
|
||||||
|
let res = nodeBuilder.withNetworkConfigurationDetails(bindIp, nodeTcpPort)
|
||||||
|
if res.isErr():
|
||||||
|
return err("node building error" & $res.error)
|
||||||
|
|
||||||
|
let nodeRes = nodeBuilder.build()
|
||||||
|
let node =
|
||||||
|
if nodeRes.isErr():
|
||||||
|
return err("node building error" & $res.error)
|
||||||
|
else: nodeRes.get()
|
||||||
|
|
||||||
var discv5BootstrapEnrsRes = getBootstrapFromDiscDns(conf)
|
var discv5BootstrapEnrsRes = getBootstrapFromDiscDns(conf)
|
||||||
if not discv5BootstrapEnrsRes.isOk():
|
if discv5BootstrapEnrsRes.isErr():
|
||||||
error("failed discovering peers from DNS")
|
error("failed discovering peers from DNS")
|
||||||
var discv5BootstrapEnrs = discv5BootstrapEnrsRes.get()
|
var discv5BootstrapEnrs = discv5BootstrapEnrsRes.get()
|
||||||
|
|
||||||
|
@ -270,16 +300,24 @@ proc initAndStartNode(conf: NetworkMonitorConf): Result[WakuNode, string] =
|
||||||
for enrUri in conf.bootstrapNodes:
|
for enrUri in conf.bootstrapNodes:
|
||||||
addBootstrapNode(enrUri, discv5BootstrapEnrs)
|
addBootstrapNode(enrUri, discv5BootstrapEnrs)
|
||||||
|
|
||||||
# mount discv5
|
# discv5
|
||||||
node.wakuDiscv5 = WakuDiscoveryV5.new(
|
let discv5Conf = WakuDiscoveryV5Config(
|
||||||
some(extIp), some(nodeTcpPort), some(nodeUdpPort),
|
discv5Config: none(DiscoveryConfig),
|
||||||
bindIp, nodeUdpPort, discv5BootstrapEnrs, false,
|
address: bindIp,
|
||||||
keys.PrivateKey(nodeKey.skkey), flags, @[], node.rng, @[])
|
port: nodeUdpPort,
|
||||||
|
privateKey: keys.PrivateKey(key.skkey),
|
||||||
|
bootstrapRecords: discv5BootstrapEnrs,
|
||||||
|
autoupdateRecord: false
|
||||||
|
)
|
||||||
|
|
||||||
node.wakuDiscv5.protocol.open()
|
let wakuDiscv5 = WakuDiscoveryV5.new(node.rng, discv5Conf, some(record))
|
||||||
return ok(node)
|
|
||||||
|
try:
|
||||||
|
wakuDiscv5.protocol.open()
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
error("could not start node")
|
return err("could not start node: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
|
ok((node, wakuDiscv5))
|
||||||
|
|
||||||
proc startRestApiServer(conf: NetworkMonitorConf,
|
proc startRestApiServer(conf: NetworkMonitorConf,
|
||||||
allPeersInfo: CustomPeersTableRef,
|
allPeersInfo: CustomPeersTableRef,
|
||||||
|
@ -366,12 +404,12 @@ when isMainModule:
|
||||||
let restClient = clientRest.get()
|
let restClient = clientRest.get()
|
||||||
|
|
||||||
# start waku node
|
# start waku node
|
||||||
let nodeRes = initAndStartNode(conf)
|
let nodeRes = initAndStartApp(conf)
|
||||||
if nodeRes.isErr():
|
if nodeRes.isErr():
|
||||||
error "could not start node"
|
error "could not start node"
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
let node = nodeRes.get()
|
let (node, discv5) = nodeRes.get()
|
||||||
|
|
||||||
waitFor node.mountRelay()
|
waitFor node.mountRelay()
|
||||||
|
|
||||||
|
@ -380,6 +418,6 @@ when isMainModule:
|
||||||
|
|
||||||
# spawn the routine that crawls the network
|
# spawn the routine that crawls the network
|
||||||
# TODO: split into 3 routines (discovery, connections, ip2location)
|
# TODO: split into 3 routines (discovery, connections, ip2location)
|
||||||
asyncSpawn crawlNetwork(node, restClient, conf, allPeersInfo)
|
asyncSpawn crawlNetwork(node, discv5, restClient, conf, allPeersInfo)
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
|
@ -24,6 +24,7 @@ import
|
||||||
# Waku v2 imports
|
# Waku v2 imports
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/nameresolving/nameresolver,
|
libp2p/nameresolving/nameresolver,
|
||||||
|
../../waku/v2/waku_enr,
|
||||||
../../waku/v2/waku_core,
|
../../waku/v2/waku_core,
|
||||||
../../waku/v2/waku_store,
|
../../waku/v2/waku_store,
|
||||||
../../waku/v2/waku_filter,
|
../../waku/v2/waku_filter,
|
||||||
|
@ -228,10 +229,15 @@ proc new*(T: type WakuBridge,
|
||||||
topics: topicInterest)
|
topics: topicInterest)
|
||||||
nodev1.configureWaku(wakuConfig)
|
nodev1.configureWaku(wakuConfig)
|
||||||
|
|
||||||
|
var builder = EnrBuilder.init(nodev2Key)
|
||||||
|
builder.withIpAddressAndPorts(nodev2ExtIp, nodev2ExtPort, none(Port))
|
||||||
|
let record = builder.build().tryGet()
|
||||||
|
|
||||||
# Setup Waku v2 node
|
# Setup Waku v2 node
|
||||||
let nodev2 = block:
|
let nodev2 = block:
|
||||||
var builder = WakuNodeBuilder.init()
|
var builder = WakuNodeBuilder.init()
|
||||||
builder.withNodeKey(nodev2Key)
|
builder.withNodeKey(nodev2Key)
|
||||||
|
builder.withRecord(record)
|
||||||
builder.withNetworkConfigurationDetails(nodev2BindIp, nodev2BindPort, nodev2ExtIp, nodev2ExtPort).tryGet()
|
builder.withNetworkConfigurationDetails(nodev2BindIp, nodev2BindPort, nodev2ExtIp, nodev2ExtPort).tryGet()
|
||||||
builder.withSwitchConfiguration(nameResolver=nameResolver)
|
builder.withSwitchConfiguration(nameResolver=nameResolver)
|
||||||
builder.build().tryGet()
|
builder.build().tryGet()
|
||||||
|
|
|
@ -220,7 +220,7 @@ proc setupDiscoveryV5*(app: App): WakuDiscoveryV5 =
|
||||||
|
|
||||||
let discv5Conf = WakuDiscoveryV5Config(
|
let discv5Conf = WakuDiscoveryV5Config(
|
||||||
discv5Config: some(discv5Config),
|
discv5Config: some(discv5Config),
|
||||||
address: app.netConf.bindIp,
|
address: app.conf.listenAddress,
|
||||||
port: discv5UdpPort,
|
port: discv5UdpPort,
|
||||||
privateKey: keys.PrivateKey(app.key.skkey),
|
privateKey: keys.PrivateKey(app.key.skkey),
|
||||||
bootstrapRecords: discv5BootstrapEnrs,
|
bootstrapRecords: discv5BootstrapEnrs,
|
||||||
|
@ -504,7 +504,7 @@ proc startApp*(app: App): Future[AppResult[void]] {.async.} =
|
||||||
let res = app.wakuDiscv5.get().start()
|
let res = app.wakuDiscv5.get().start()
|
||||||
|
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
return err("failed to start waku discovery v5: " & res.error)
|
return err("failed to start waku discovery v5: " & $res.error)
|
||||||
|
|
||||||
asyncSpawn app.wakuDiscv5.get().searchLoop(app.node.peerManager, some(app.record))
|
asyncSpawn app.wakuDiscv5.get().searchLoop(app.node.peerManager, some(app.record))
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,8 @@ proc createRecord*(conf: WakuNodeConf, netConf: NetConfig, key: crypto.PrivateKe
|
||||||
var builder = EnrBuilder.init(key)
|
var builder = EnrBuilder.init(key)
|
||||||
|
|
||||||
builder.withIpAddressAndPorts(
|
builder.withIpAddressAndPorts(
|
||||||
ipAddr = netConf.extIp,
|
ipAddr = netConf.enrIp,
|
||||||
tcpPort = netConf.extPort,
|
tcpPort = netConf.enrPort,
|
||||||
udpPort = netConf.discv5UdpPort,
|
udpPort = netConf.discv5UdpPort,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -51,12 +51,34 @@ proc newTestWakuNode*(nodeKey: crypto.PrivateKey,
|
||||||
dns4DomainName = dns4DomainName,
|
dns4DomainName = dns4DomainName,
|
||||||
discv5UdpPort = discv5UdpPort,
|
discv5UdpPort = discv5UdpPort,
|
||||||
)
|
)
|
||||||
|
let netConf =
|
||||||
if netConfigRes.isErr():
|
if netConfigRes.isErr():
|
||||||
raise newException(Defect, "Invalid network configuration: " & $netConfigRes.error)
|
raise newException(Defect, "Invalid network configuration: " & $netConfigRes.error)
|
||||||
|
else:
|
||||||
|
netConfigRes.get()
|
||||||
|
|
||||||
|
var enrBuilder = EnrBuilder.init(nodeKey)
|
||||||
|
|
||||||
|
enrBuilder.withIpAddressAndPorts(
|
||||||
|
ipAddr = netConf.enrIp,
|
||||||
|
tcpPort = netConf.enrPort,
|
||||||
|
udpPort = netConf.discv5UdpPort,
|
||||||
|
)
|
||||||
|
if netConf.wakuFlags.isSome():
|
||||||
|
enrBuilder.withWakuCapabilities(netConf.wakuFlags.get())
|
||||||
|
enrBuilder.withMultiaddrs(netConf.enrMultiaddrs)
|
||||||
|
|
||||||
|
let recordRes = enrBuilder.build()
|
||||||
|
let record =
|
||||||
|
if recordRes.isErr():
|
||||||
|
raise newException(Defect, "Invalid record: " & $recordRes.error)
|
||||||
|
else:
|
||||||
|
recordRes.get()
|
||||||
|
|
||||||
var builder = WakuNodeBuilder.init()
|
var builder = WakuNodeBuilder.init()
|
||||||
builder.withRng(rng())
|
builder.withRng(rng())
|
||||||
builder.withNodeKey(nodeKey)
|
builder.withNodeKey(nodeKey)
|
||||||
|
builder.withRecord(record)
|
||||||
builder.withNetworkConfiguration(netConfigRes.get())
|
builder.withNetworkConfiguration(netConfigRes.get())
|
||||||
builder.withPeerStorage(peerStorage, capacity = peerStoreCapacity)
|
builder.withPeerStorage(peerStorage, capacity = peerStoreCapacity)
|
||||||
builder.withSwitchConfiguration(
|
builder.withSwitchConfiguration(
|
||||||
|
|
|
@ -19,6 +19,7 @@ import
|
||||||
../../waku/v1/protocol/waku_protocol,
|
../../waku/v1/protocol/waku_protocol,
|
||||||
../../waku/v2/waku_core,
|
../../waku/v2/waku_core,
|
||||||
../../waku/v2/waku_node,
|
../../waku/v2/waku_node,
|
||||||
|
../../waku/v2/waku_enr,
|
||||||
../../waku/v2/utils/compat,
|
../../waku/v2/utils/compat,
|
||||||
../test_helpers
|
../test_helpers
|
||||||
|
|
||||||
|
@ -54,9 +55,16 @@ procSuite "WakuBridge":
|
||||||
|
|
||||||
# Waku v2 node
|
# Waku v2 node
|
||||||
v2NodeKey = crypto.PrivateKey.random(Secp256k1, cryptoRng[])[]
|
v2NodeKey = crypto.PrivateKey.random(Secp256k1, cryptoRng[])[]
|
||||||
|
|
||||||
|
var builder = EnrBuilder.init(v2NodeKey)
|
||||||
|
builder.withIpAddressAndPorts(none(ValidIpAddress), none(Port), none(Port))
|
||||||
|
let record = builder.build().tryGet()
|
||||||
|
|
||||||
|
let
|
||||||
v2Node = block:
|
v2Node = block:
|
||||||
var builder = WakuNodeBuilder.init()
|
var builder = WakuNodeBuilder.init()
|
||||||
builder.withNodeKey(v2NodeKey)
|
builder.withNodeKey(v2NodeKey)
|
||||||
|
builder.withRecord(record)
|
||||||
builder.withNetworkConfigurationDetails(ValidIpAddress.init("0.0.0.0"), Port(62203)).tryGet()
|
builder.withNetworkConfigurationDetails(ValidIpAddress.init("0.0.0.0"), Port(62203)).tryGet()
|
||||||
builder.build().tryGet()
|
builder.build().tryGet()
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,7 @@ proc withNetworkConfigurationDetails*(builder: var WakuNodeBuilder,
|
||||||
wsEnabled: bool = false,
|
wsEnabled: bool = false,
|
||||||
wssEnabled: bool = false,
|
wssEnabled: bool = false,
|
||||||
wakuFlags = none(CapabilitiesBitfield),
|
wakuFlags = none(CapabilitiesBitfield),
|
||||||
dns4DomainName = none(string),
|
dns4DomainName = none(string)): WakuNodeBuilderResult {.
|
||||||
discv5UdpPort = none(Port)): WakuNodeBuilderResult {.
|
|
||||||
deprecated: "use 'builder.withNetworkConfiguration()' instead".} =
|
deprecated: "use 'builder.withNetworkConfiguration()' instead".} =
|
||||||
let netConfig = ? NetConfig.init(
|
let netConfig = ? NetConfig.init(
|
||||||
bindIp = bindIp,
|
bindIp = bindIp,
|
||||||
|
@ -91,7 +90,6 @@ proc withNetworkConfigurationDetails*(builder: var WakuNodeBuilder,
|
||||||
wssEnabled = wssEnabled,
|
wssEnabled = wssEnabled,
|
||||||
wakuFlags = wakuFlags,
|
wakuFlags = wakuFlags,
|
||||||
dns4DomainName = dns4DomainName,
|
dns4DomainName = dns4DomainName,
|
||||||
discv5UdpPort = discv5UdpPort,
|
|
||||||
)
|
)
|
||||||
builder.withNetworkConfiguration(netConfig)
|
builder.withNetworkConfiguration(netConfig)
|
||||||
ok()
|
ok()
|
||||||
|
@ -144,6 +142,9 @@ proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] =
|
||||||
if builder.netConfig.isNone():
|
if builder.netConfig.isNone():
|
||||||
return err("network configuration is required")
|
return err("network configuration is required")
|
||||||
|
|
||||||
|
if builder.record.isNone():
|
||||||
|
return err("node record is required")
|
||||||
|
|
||||||
# fallbck to max connections if not set
|
# fallbck to max connections if not set
|
||||||
var maxRelayPeers: int
|
var maxRelayPeers: int
|
||||||
if builder.maxRelayPeers.isNone():
|
if builder.maxRelayPeers.isNone():
|
||||||
|
@ -181,9 +182,8 @@ proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] =
|
||||||
var node: WakuNode
|
var node: WakuNode
|
||||||
try:
|
try:
|
||||||
node = WakuNode.new(
|
node = WakuNode.new(
|
||||||
nodeKey = builder.nodeKey.get(),
|
|
||||||
netConfig = builder.netConfig.get(),
|
netConfig = builder.netConfig.get(),
|
||||||
enr = builder.record,
|
enr = builder.record.get(),
|
||||||
switch = switch,
|
switch = switch,
|
||||||
peerManager = peerManager,
|
peerManager = peerManager,
|
||||||
rng = rng,
|
rng = rng,
|
||||||
|
|
|
@ -37,7 +37,6 @@ import
|
||||||
../waku_lightpush/client as lightpush_client,
|
../waku_lightpush/client as lightpush_client,
|
||||||
../waku_enr,
|
../waku_enr,
|
||||||
../waku_dnsdisc,
|
../waku_dnsdisc,
|
||||||
../waku_discv5,
|
|
||||||
../waku_peer_exchange,
|
../waku_peer_exchange,
|
||||||
./config,
|
./config,
|
||||||
./peer_manager,
|
./peer_manager,
|
||||||
|
@ -101,37 +100,10 @@ type
|
||||||
enr*: enr.Record
|
enr*: enr.Record
|
||||||
libp2pPing*: Ping
|
libp2pPing*: Ping
|
||||||
rng*: ref rand.HmacDrbgContext
|
rng*: ref rand.HmacDrbgContext
|
||||||
wakuDiscv5*: WakuDiscoveryV5
|
|
||||||
rendezvous*: RendezVous
|
rendezvous*: RendezVous
|
||||||
announcedAddresses* : seq[MultiAddress]
|
announcedAddresses* : seq[MultiAddress]
|
||||||
started*: bool # Indicates that node has started listening
|
started*: bool # Indicates that node has started listening
|
||||||
|
|
||||||
proc getEnr*(netConfig: NetConfig,
|
|
||||||
wakuDiscV5 = none(WakuDiscoveryV5),
|
|
||||||
nodeKey: crypto.PrivateKey): Result[enr.Record, string] =
|
|
||||||
if wakuDiscV5.isSome():
|
|
||||||
return ok(wakuDiscV5.get().protocol.getRecord())
|
|
||||||
|
|
||||||
var builder = EnrBuilder.init(nodeKey, seqNum = 1)
|
|
||||||
|
|
||||||
builder.withIpAddressAndPorts(
|
|
||||||
ipAddr = netConfig.enrIp,
|
|
||||||
tcpPort = netConfig.enrPort,
|
|
||||||
udpPort = netConfig.discv5UdpPort
|
|
||||||
)
|
|
||||||
|
|
||||||
if netConfig.wakuFlags.isSome():
|
|
||||||
builder.withWakuCapabilities(netConfig.wakuFlags.get())
|
|
||||||
|
|
||||||
if netConfig.enrMultiAddrs.len > 0:
|
|
||||||
builder.withMultiaddrs(netConfig.enrMultiAddrs)
|
|
||||||
|
|
||||||
let recordRes = builder.build()
|
|
||||||
if recordRes.isErr():
|
|
||||||
return err($recordRes.error)
|
|
||||||
|
|
||||||
return ok(recordRes.get())
|
|
||||||
|
|
||||||
proc getAutonatService*(rng: ref HmacDrbgContext): AutonatService =
|
proc getAutonatService*(rng: ref HmacDrbgContext): AutonatService =
|
||||||
## AutonatService request other peers to dial us back
|
## AutonatService request other peers to dial us back
|
||||||
## flagging us as Reachable or NotReachable.
|
## flagging us as Reachable or NotReachable.
|
||||||
|
@ -156,11 +128,9 @@ proc getAutonatService*(rng: ref HmacDrbgContext): AutonatService =
|
||||||
return autonatService
|
return autonatService
|
||||||
|
|
||||||
proc new*(T: type WakuNode,
|
proc new*(T: type WakuNode,
|
||||||
nodeKey: crypto.PrivateKey,
|
|
||||||
netConfig: NetConfig,
|
netConfig: NetConfig,
|
||||||
enr: Option[enr.Record],
|
enr: enr.Record,
|
||||||
switch: Switch,
|
switch: Switch,
|
||||||
wakuDiscv5 = none(WakuDiscoveryV5),
|
|
||||||
peerManager: PeerManager,
|
peerManager: PeerManager,
|
||||||
# TODO: make this argument required after tests are updated
|
# TODO: make this argument required after tests are updated
|
||||||
rng: ref HmacDrbgContext = crypto.newRng()
|
rng: ref HmacDrbgContext = crypto.newRng()
|
||||||
|
@ -169,23 +139,12 @@ proc new*(T: type WakuNode,
|
||||||
|
|
||||||
info "Initializing networking", addrs= $netConfig.announcedAddresses
|
info "Initializing networking", addrs= $netConfig.announcedAddresses
|
||||||
|
|
||||||
let enr =
|
|
||||||
if enr.isNone():
|
|
||||||
let nodeEnrRes = getEnr(netConfig, wakuDiscv5, nodekey)
|
|
||||||
|
|
||||||
if nodeEnrRes.isErr():
|
|
||||||
raise newException(Defect, "failed to generate the node ENR record: " & $nodeEnrRes.error)
|
|
||||||
|
|
||||||
nodeEnrRes.get()
|
|
||||||
else: enr.get()
|
|
||||||
|
|
||||||
return WakuNode(
|
return WakuNode(
|
||||||
peerManager: peerManager,
|
peerManager: peerManager,
|
||||||
switch: switch,
|
switch: switch,
|
||||||
rng: rng,
|
rng: rng,
|
||||||
enr: enr,
|
enr: enr,
|
||||||
announcedAddresses: netConfig.announcedAddresses,
|
announcedAddresses: netConfig.announcedAddresses,
|
||||||
wakuDiscv5: if wakuDiscV5.isSome(): wakuDiscV5.get() else: nil,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
proc peerInfo*(node: WakuNode): PeerInfo =
|
proc peerInfo*(node: WakuNode): PeerInfo =
|
||||||
|
|
Loading…
Reference in New Issue