mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-05 19:43:41 +00:00
deploy: 067478d7255e22750fa9988c285e59eb4c841bbe
This commit is contained in:
parent
6021d6dcb2
commit
f3a74d8d58
@ -36,6 +36,11 @@ procSuite "Waku Discovery v5":
|
|||||||
nodeUdpPort3 = Port(9004)
|
nodeUdpPort3 = Port(9004)
|
||||||
node3 = WakuNode.new(nodeKey3, bindIp, nodeTcpPort3)
|
node3 = WakuNode.new(nodeKey3, bindIp, nodeTcpPort3)
|
||||||
|
|
||||||
|
flags = initWakuFlags(lightpush = false,
|
||||||
|
filter = false,
|
||||||
|
store = false,
|
||||||
|
relay = true)
|
||||||
|
|
||||||
# E2E relay test paramaters
|
# E2E relay test paramaters
|
||||||
pubSubTopic = "/waku/2/default-waku/proto"
|
pubSubTopic = "/waku/2/default-waku/proto"
|
||||||
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
||||||
@ -50,6 +55,7 @@ procSuite "Waku Discovery v5":
|
|||||||
@[],
|
@[],
|
||||||
false,
|
false,
|
||||||
keys.PrivateKey(nodeKey1.skkey),
|
keys.PrivateKey(nodeKey1.skkey),
|
||||||
|
flags,
|
||||||
[], # Empty enr fields, for now
|
[], # Empty enr fields, for now
|
||||||
node1.rng
|
node1.rng
|
||||||
)
|
)
|
||||||
@ -61,6 +67,7 @@ procSuite "Waku Discovery v5":
|
|||||||
@[node1.wakuDiscv5.protocol.localNode.record.toURI()], # Bootstrap with node1
|
@[node1.wakuDiscv5.protocol.localNode.record.toURI()], # Bootstrap with node1
|
||||||
false,
|
false,
|
||||||
keys.PrivateKey(nodeKey2.skkey),
|
keys.PrivateKey(nodeKey2.skkey),
|
||||||
|
flags,
|
||||||
[], # Empty enr fields, for now
|
[], # Empty enr fields, for now
|
||||||
node2.rng
|
node2.rng
|
||||||
)
|
)
|
||||||
@ -72,6 +79,7 @@ procSuite "Waku Discovery v5":
|
|||||||
@[node2.wakuDiscv5.protocol.localNode.record.toURI()], # Bootstrap with node2
|
@[node2.wakuDiscv5.protocol.localNode.record.toURI()], # Bootstrap with node2
|
||||||
false,
|
false,
|
||||||
keys.PrivateKey(nodeKey3.skkey),
|
keys.PrivateKey(nodeKey3.skkey),
|
||||||
|
flags,
|
||||||
[], # Empty enr fields, for now
|
[], # Empty enr fields, for now
|
||||||
node3.rng
|
node3.rng
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# libtool - Provide generalized library-building support services.
|
# libtool - Provide generalized library-building support services.
|
||||||
# Generated automatically by config.status (libbacktrace) version-unused
|
# Generated automatically by config.status (libbacktrace) version-unused
|
||||||
# Libtool was configured on host fv-az129-680:
|
# Libtool was configured on host fv-az269-238:
|
||||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||||
#
|
#
|
||||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[strutils, options],
|
std/[bitops, sequtils, strutils, options],
|
||||||
chronos, chronicles, metrics,
|
chronos, chronicles, metrics,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
eth/p2p/discoveryv5/[enr, protocol],
|
eth/p2p/discoveryv5/[enr, node, protocol],
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
stew/results,
|
stew/results,
|
||||||
../config,
|
../config,
|
||||||
@ -19,10 +19,22 @@ logScope:
|
|||||||
topics = "wakudiscv5"
|
topics = "wakudiscv5"
|
||||||
|
|
||||||
type
|
type
|
||||||
|
## 8-bit flag field to indicate Waku capabilities.
|
||||||
|
## Only the 4 LSBs are currently defined according
|
||||||
|
## to RFC31 (https://rfc.vac.dev/spec/31/).
|
||||||
|
WakuEnrBitfield* = uint8
|
||||||
|
|
||||||
WakuDiscoveryV5* = ref object
|
WakuDiscoveryV5* = ref object
|
||||||
protocol*: protocol.Protocol
|
protocol*: protocol.Protocol
|
||||||
listening*: bool
|
listening*: bool
|
||||||
|
|
||||||
|
const
|
||||||
|
WAKU_ENR_FIELD* = "waku2"
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Helper functions #
|
||||||
|
####################
|
||||||
|
|
||||||
proc parseBootstrapAddress(address: TaintedString):
|
proc parseBootstrapAddress(address: TaintedString):
|
||||||
Result[enr.Record, cstring] =
|
Result[enr.Record, cstring] =
|
||||||
logScope:
|
logScope:
|
||||||
@ -55,6 +67,24 @@ proc addBootstrapNode(bootstrapAddr: string,
|
|||||||
warn "Ignoring invalid bootstrap address",
|
warn "Ignoring invalid bootstrap address",
|
||||||
bootstrapAddr, reason = enrRes.error
|
bootstrapAddr, reason = enrRes.error
|
||||||
|
|
||||||
|
proc initWakuFlags*(lightpush, filter, store, relay: bool): WakuEnrBitfield =
|
||||||
|
## Creates an waku2 ENR flag bit field according to RFC 31 (https://rfc.vac.dev/spec/31/)
|
||||||
|
var v = 0b0000_0000'u8
|
||||||
|
if lightpush: v.setBit(3)
|
||||||
|
if filter: v.setBit(2)
|
||||||
|
if store: v.setBit(1)
|
||||||
|
if relay: v.setBit(0)
|
||||||
|
|
||||||
|
return v.WakuEnrBitfield
|
||||||
|
|
||||||
|
proc isWakuNode(node: Node): bool =
|
||||||
|
let wakuField = node.record.tryGet(WAKU_ENR_FIELD, uint8)
|
||||||
|
|
||||||
|
if wakuField.isSome:
|
||||||
|
return wakuField.get().WakuEnrBitfield != 0x00 # True if any flag set to true
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Discovery v5 API #
|
# Discovery v5 API #
|
||||||
####################
|
####################
|
||||||
@ -63,12 +93,14 @@ proc findRandomPeers*(wakuDiscv5: WakuDiscoveryV5): Future[Result[seq[RemotePeer
|
|||||||
## Find random peers to connect to using Discovery v5
|
## Find random peers to connect to using Discovery v5
|
||||||
|
|
||||||
## Query for a random target and collect all discovered nodes
|
## Query for a random target and collect all discovered nodes
|
||||||
## @TODO: we could filter nodes here
|
|
||||||
let discoveredNodes = await wakuDiscv5.protocol.queryRandom()
|
let discoveredNodes = await wakuDiscv5.protocol.queryRandom()
|
||||||
|
|
||||||
|
## Filter based on our needs
|
||||||
|
let filteredNodes = discoveredNodes.filter(isWakuNode) # Currently only a single predicate
|
||||||
|
|
||||||
var discoveredPeers: seq[RemotePeerInfo]
|
var discoveredPeers: seq[RemotePeerInfo]
|
||||||
|
|
||||||
for node in discoveredNodes:
|
for node in filteredNodes:
|
||||||
# Convert discovered ENR to RemotePeerInfo and add to discovered nodes
|
# Convert discovered ENR to RemotePeerInfo and add to discovered nodes
|
||||||
let res = node.record.toRemotePeerInfo()
|
let res = node.record.toRemotePeerInfo()
|
||||||
|
|
||||||
@ -92,6 +124,7 @@ proc new*(T: type WakuDiscoveryV5,
|
|||||||
bootstrapNodes: seq[string],
|
bootstrapNodes: seq[string],
|
||||||
enrAutoUpdate = false,
|
enrAutoUpdate = false,
|
||||||
privateKey: PrivateKey,
|
privateKey: PrivateKey,
|
||||||
|
flags: WakuEnrBitfield,
|
||||||
enrFields: openArray[(string, seq[byte])],
|
enrFields: openArray[(string, seq[byte])],
|
||||||
rng: ref BrHmacDrbgContext): T =
|
rng: ref BrHmacDrbgContext): T =
|
||||||
|
|
||||||
@ -101,10 +134,14 @@ proc new*(T: type WakuDiscoveryV5,
|
|||||||
|
|
||||||
## TODO: consider loading from a configurable bootstrap file
|
## TODO: consider loading from a configurable bootstrap file
|
||||||
|
|
||||||
|
## We always add the waku field as specified
|
||||||
|
var enrInitFields = @[(WAKU_ENR_FIELD, @[flags.byte])]
|
||||||
|
enrInitFields.add(enrFields)
|
||||||
|
|
||||||
let protocol = newProtocol(
|
let protocol = newProtocol(
|
||||||
privateKey,
|
privateKey,
|
||||||
enrIp = extIp, enrTcpPort = extTcpPort, enrUdpPort = extUdpPort, # We use the external IP & ports for ENR
|
enrIp = extIp, enrTcpPort = extTcpPort, enrUdpPort = extUdpPort, # We use the external IP & ports for ENR
|
||||||
enrFields,
|
enrInitFields,
|
||||||
bootstrapEnrs,
|
bootstrapEnrs,
|
||||||
bindPort = discv5UdpPort,
|
bindPort = discv5UdpPort,
|
||||||
bindIp = bindIP,
|
bindIp = bindIP,
|
||||||
|
@ -959,6 +959,10 @@ when isMainModule:
|
|||||||
conf.discv5BootstrapNodes,
|
conf.discv5BootstrapNodes,
|
||||||
conf.discv5EnrAutoUpdate,
|
conf.discv5EnrAutoUpdate,
|
||||||
keys.PrivateKey(conf.nodekey.skkey),
|
keys.PrivateKey(conf.nodekey.skkey),
|
||||||
|
initWakuFlags(conf.lightpush,
|
||||||
|
conf.filter,
|
||||||
|
conf.store,
|
||||||
|
conf.relay),
|
||||||
[], # Empty enr fields, for now
|
[], # Empty enr fields, for now
|
||||||
node.rng
|
node.rng
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user