feat(waku utils): Set up default bootstrap node

This commit is contained in:
Emil Ivanichkov 2024-04-30 18:42:48 +03:00 committed by Emil Ivanichkov
parent dfefa8b852
commit b9fa56ed9b
7 changed files with 37 additions and 16 deletions

View File

@ -0,0 +1,7 @@
const defaultWakuBootstrapNode* = "enr:-P-4QGVNANzbhCI49du6Moyw98AjuMhKoOpE_Jges9JlCq-I" &
"CAVadktjfcNpuhQgT0g1cu86_S3nbM7eYkCsqDAQG7UBgmlkgnY0" &
"gmlwhI_G-a6KbXVsdGlhZGRyc7hgAC02KG5vZGUtMDEuZG8tYW1z" &
"My5zdGF0dXMucHJvZC5zdGF0dXNpbS5uZXQGdl8ALzYobm9kZS0w" &
"MS5kby1hbXMzLnN0YXR1cy5wcm9kLnN0YXR1c2ltLm5ldAYBu94D" &
"iXNlY3AyNTZrMaECoVyonsTGEQvVioM562Q1fjzTb_vKD152PPId" &
"sV7sM6SDdGNwgnZfg3VkcIIjKIV3YWt1Mg8"

View File

@ -15,7 +15,8 @@ import
# Local modules
../../waku_handshake_utils,
../../waku_node
../../waku_node,
../constants
const
wakuPort = 60000
@ -49,7 +50,8 @@ proc exampleJSWaku(rng: ref HmacDrbgContext) {.async.} =
# Start nwaku instance
let node = await startWakuNode(rng, wakuPort, discv5Port,
requiredConnectedPeers)
requiredConnectedPeers,
defaultWakuBootstrapNode)
# Perform the handshake
initiatorHSResult = await initiatorHandshake(rng, node, pubSubTopic,

View File

@ -15,7 +15,8 @@ import
# Local modules
../../waku_handshake_utils,
../../waku_node
../../waku_node,
../constants
const
wakuPort = 60000
@ -47,7 +48,8 @@ proc exampleNwakuAgentA(rng: ref HmacDrbgContext) {.async.} =
# Start nwaku instance
let node = await startWakuNode(rng, wakuPort, discv5Port,
requiredConnectedPeers)
requiredConnectedPeers,
defaultWakuBootstrapNode)
# Perform the handshake
agentAHSResult = await initiatorHandshake(rng, node, pubSubTopic, contentTopic,

View File

@ -15,7 +15,8 @@ import
# Local modules
../../waku_handshake_utils,
../../waku_node
../../waku_node,
../constants
const
wakuPort = 50000
@ -61,7 +62,8 @@ proc exampleNwakuAgentB(rng: ref HmacDrbgContext) {.async.} =
# Start nwaku instance
let node = await startWakuNode(rng, wakuPort, discv5Port,
requiredConnectedPeers)
requiredConnectedPeers,
defaultWakuBootstrapNode)
# Make sure it matches the publisher. Use default value
# see spec: https://rfc.vac.dev/spec/23/

View File

@ -16,16 +16,10 @@ import
proc startWakuNode*(rng: ref HmacDrbgContext,
wakuPort, discv5Port: uint16,
requiredConnectedPeers: int
requiredConnectedPeers: int,
bootstrapNode: string
): Future[WakuNode] {.async.} =
let
bootstrapNode = "enr:-P-4QGVNANzbhCI49du6Moyw98AjuMhKoOpE_Jges9JlCq-I" &
"CAVadktjfcNpuhQgT0g1cu86_S3nbM7eYkCsqDAQG7UBgmlkgnY0" &
"gmlwhI_G-a6KbXVsdGlhZGRyc7hgAC02KG5vZGUtMDEuZG8tYW1z" &
"My5zdGF0dXMucHJvZC5zdGF0dXNpbS5uZXQGdl8ALzYobm9kZS0w" &
"MS5kby1hbXMzLnN0YXR1cy5wcm9kLnN0YXR1c2ltLm5ldAYBu94D" &
"iXNlY3AyNTZrMaECoVyonsTGEQvVioM562Q1fjzTb_vKD152PPId" &
"sV7sM6SDdGNwgnZfg3VkcIIjKIV3YWt1Mg8"
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).get()
ip = parseIpAddress("0.0.0.0")
flags = CapabilitiesBitfield.init(lightpush = false, filter = false,
@ -44,8 +38,8 @@ proc startWakuNode*(rng: ref HmacDrbgContext,
builder.withNodeKey(nodeKey)
builder.withRecord(record)
builder.withNetworkConfigurationDetails(ip, Port(wakuPort)).tryGet()
let node = builder.build().tryGet()
let node = builder.build().tryGet()
var bootstrapNodeEnr: enr.Record
discard bootstrapNodeEnr.fromURI(bootstrapNode)

View File

@ -17,6 +17,13 @@ export
const wakuHandshakeDataFilename* = "handshake_data.json"
const defaultWakuContentTopic* = "/snm/0.0.1/default/proto"
const defaultWakuPubsubTopic* = "/waku/2/default-waku/proto"
const defaultWakuBootstrapNode* = "enr:-P-4QGVNANzbhCI49du6Moyw98AjuMhKoOpE_Jges9JlCq-I" &
"CAVadktjfcNpuhQgT0g1cu86_S3nbM7eYkCsqDAQG7UBgmlkgnY0" &
"gmlwhI_G-a6KbXVsdGlhZGRyc7hgAC02KG5vZGUtMDEuZG8tYW1z" &
"My5zdGF0dXMucHJvZC5zdGF0dXNpbS5uZXQGdl8ALzYobm9kZS0w" &
"MS5kby1hbXMzLnN0YXR1cy5wcm9kLnN0YXR1c2ltLm5ldAYBu94D" &
"iXNlY3AyNTZrMaECoVyonsTGEQvVioM562Q1fjzTb_vKD152PPId" &
"sV7sM6SDdGNwgnZfg3VkcIIjKIV3YWt1Mg8"
type
SNMStartUpCmd* {.pure.} = enum
@ -96,6 +103,11 @@ type
defaultValue: config.defaultWakuHandshakeFilePath()
name: "waku-handshake-file" .}: string
wakuBootstrapNode* {.
desc: "The bootstrap node to use for the Waku node"
defaultValue: defaultWakuBootstrapNode
name: "waku-bootstrap-node" .}: string
of SNMStartUpCmd.waku:
case wakuCmd* {.command.}: WakuCommand

View File

@ -117,9 +117,11 @@ proc wakuSendMessage*(wakuHost: ref WakuHost,
proc init*(T: type WakuHost,
rng: ref HmacDrbgContext,
config: StatusNodeManagerConfig): Future[WakuHost] {.async.} =
let node = await startWakuNode(rng, config.wakuPort,
config.discv5Port,
config.requiredConnectedPeers)
config.requiredConnectedPeers,
config.wakuBootstrapNode)
# Try to load handshake data from file, if the file exists
let handshakeDataFile = OutFile(config.wakuHandshakeFile)