2020-05-19 05:00:03 +00:00
|
|
|
import
|
2020-05-20 05:34:43 +00:00
|
|
|
strformat, os, osproc, net, confutils, strformat, chronicles, json,
|
2020-05-19 05:00:03 +00:00
|
|
|
libp2p/multiaddress,
|
|
|
|
libp2p/crypto/crypto,
|
2020-05-20 05:34:43 +00:00
|
|
|
libp2p/crypto/secp,
|
2020-05-19 05:00:03 +00:00
|
|
|
libp2p/protocols/protocol,
|
|
|
|
libp2p/peerinfo
|
|
|
|
|
2020-05-20 05:34:43 +00:00
|
|
|
# Fix ambiguous call error
|
|
|
|
import strutils except fromHex
|
|
|
|
|
2020-05-20 06:21:17 +00:00
|
|
|
const
|
|
|
|
defaults ="--log-level:DEBUG --log-metrics --metrics-server --rpc"
|
|
|
|
wakuNodeBin = "build" / "wakunode"
|
2020-05-21 04:28:57 +00:00
|
|
|
portOffset = 2
|
2020-05-20 06:21:17 +00:00
|
|
|
|
2020-05-19 05:00:03 +00:00
|
|
|
type
|
|
|
|
NodeInfo* = object
|
|
|
|
cmd: string
|
2020-05-21 04:28:57 +00:00
|
|
|
master: bool
|
2020-05-19 05:00:03 +00:00
|
|
|
address: string
|
2020-05-20 06:21:17 +00:00
|
|
|
shift: int
|
2020-05-19 05:00:03 +00:00
|
|
|
label: string
|
|
|
|
|
|
|
|
# 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 "
|
|
|
|
# Ok cool so it is config.nim parseCmdArg, then use fromHex
|
2020-05-21 04:28:57 +00:00
|
|
|
proc initNodeCmd(shift: int, staticNodes: seq[string] = @[], master = false, label: string): NodeInfo =
|
2020-05-19 05:00:03 +00:00
|
|
|
let
|
2020-05-20 05:34:43 +00:00
|
|
|
key = SkPrivateKey.random()
|
|
|
|
hkey = key.getBytes().toHex()
|
|
|
|
rkey = SkPrivateKey.init(fromHex(hkey))
|
|
|
|
privKey = PrivateKey(scheme: Secp256k1, skkey: rkey)
|
|
|
|
#privKey = PrivateKey.random(Secp256k1)
|
2020-05-19 05:00:03 +00:00
|
|
|
keys = KeyPair(seckey: privKey, pubkey: privKey.getKey())
|
|
|
|
peerInfo = PeerInfo.init(privKey)
|
|
|
|
# XXX
|
|
|
|
DefaultAddr = "/ip4/127.0.0.1/tcp/55505"
|
|
|
|
hostAddress = MultiAddress.init(DefaultAddr)
|
|
|
|
|
|
|
|
peerInfo.addrs.add(hostAddress)
|
2020-05-20 06:21:17 +00:00
|
|
|
let id = peerInfo.id
|
|
|
|
|
|
|
|
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
|
2020-05-21 04:28:57 +00:00
|
|
|
result.master = master
|
2020-05-20 06:21:17 +00:00
|
|
|
result.address = listenStr
|
|
|
|
|
|
|
|
info "Node command created.", cmd=result.cmd, address = result.address
|
2020-05-19 05:00:03 +00:00
|
|
|
|
2020-05-20 06:21:17 +00:00
|
|
|
# TODO: Setup diff topology, star, mesh, etc
|
2020-05-21 04:28:57 +00:00
|
|
|
let masterNode = initNodeCmd(portOffset, @[], "master node")
|
|
|
|
let otherNode = initNodeCmd(portOFfset + 1, @[masterNode.address], "other node")
|
2020-05-19 05:00:03 +00:00
|
|
|
|
2020-05-20 06:21:17 +00:00
|
|
|
echo masterNode
|
|
|
|
echo "---"
|
|
|
|
echo otherNode
|