Build node command with key and adress

This commit is contained in:
Oskar Thoren 2020-05-20 14:21:17 +08:00
parent 532fdf644b
commit a9b3f02062

View File

@ -9,22 +9,23 @@ import
# Fix ambiguous call error
import strutils except fromHex
const
defaults ="--log-level:DEBUG --log-metrics --metrics-server --rpc"
wakuNodeBin = "build" / "wakunode"
type
NodeInfo* = object
cmd: string
address: string
shift: int
label: string
# TODO: initNodeCmd and get multiaddress here
# TODO: Then, setup a star network
# TODO: Create Node command, something like this:
# "build/wakunode --log-level:DEBUG --log-metrics --metrics-server --rpc --waku-topic-interest:false --nodekey:e685079b7fa34dd35d3ffb2e40ab970360e94aa7dcc1262d36a8e2320a2c08ce --ports-shift:2 --discovery:off "
# What's equivalent of nodekey for libp2p? It is keypair.seckey in v1
# desc: "P2P node private key as hex.",
# Should be straightforward
# Ok cool so it is config.nim parseCmdArg, then use fromHex
proc initNodeCmd(): NodeInfo =
proc initNodeCmd(shift: int, staticNodes: seq[string] = @[], label: string): NodeInfo =
let
key = SkPrivateKey.random()
hkey = key.getBytes().toHex()
@ -38,6 +39,27 @@ proc initNodeCmd(): NodeInfo =
hostAddress = MultiAddress.init(DefaultAddr)
peerInfo.addrs.add(hostAddress)
let id = peerInfo.id
result.cmd = "./build/foo"
info "PeerInfo", id = id, addrs = peerInfo.addrs
let listenStr = $peerInfo.addrs[0] & "/p2p/" & id
result.cmd = wakuNodeBin & " " & defaults & " "
result.cmd &= "--nodekey:" & hkey & " "
result.cmd &= "--ports-shift:" & $shift & " "
if staticNodes.len > 0:
for staticNode in staticNodes:
result.cmd &= "--staticnode:" & staticNode & " "
result.shift = shift
result.label = label
result.address = listenStr
info "Node command created.", cmd=result.cmd, address = result.address
# TODO: Setup diff topology, star, mesh, etc
let masterNode = initNodeCmd(0, @[], "master node")
let otherNode = initNodeCmd(0, @[masterNode.address], "other node")
echo masterNode
echo "---"
echo otherNode