import strformat, os, osproc, net, confutils, strformat, chronicles, json, strutils, eth/keys, eth/p2p/enode const defaults ="--log-level:DEBUG --log-metrics --metrics-server --rpc" wakuNodeBin = "build" / "wakunode" metricsDir = "waku" / "metrics" portOffset = 2 type NodeType = enum FullNode = "--waku-mode:WakuSan", LightNode = "--light-node:on", WakuNode = "--light-node:on --waku-mode:WakuChan" Topology = enum Star, FullMesh, DiscoveryBased # Whatever topology the discovery brings WakuNetworkConf* = object topology* {. desc: "Set the network topology." defaultValue: Star name: "topology" }: Topology amount* {. desc: "Amount of full nodes to be started." defaultValue: 4 name: "amount" }: int testNodePeers* {. desc: "Amount of peers a test node should connect to." defaultValue: 1 name: "test-node-peers" }: int NodeInfo* = object cmd: string master: bool enode: string shift: int label: string proc initNodeCmd(nodeType: NodeType, shift: int, staticNodes: seq[string] = @[], discovery = false, bootNodes: seq[string] = @[], master = false, label: string): NodeInfo = let keypair = newKeyPair() address = Address(ip: parseIpAddress("127.0.0.1"), udpPort: (30303 + shift).Port, tcpPort: (30303 + shift).Port) enode = ENode(pubkey: keypair.pubkey, address: address) result.cmd = wakuNodeBin & " " & defaults & " " result.cmd &= $nodeType & " " result.cmd &= "--nodekey:" & $keypair.seckey & " " result.cmd &= "--ports-shift:" & $shift & " " if discovery: result.cmd &= "--discovery:on" & " " if bootNodes.len > 0: for bootNode in bootNodes: result.cmd &= "--bootnode:" & bootNode & " " else: result.cmd &= "--discovery:off" & " " if staticNodes.len > 0: for staticNode in staticNodes: result.cmd &= "--staticnode:" & staticNode & " " result.master = master result.enode = $enode result.shift = shift result.label = label debug "Node command created.", cmd=result.cmd proc starNetwork(amount: int): seq[NodeInfo] = let masterNode = initNodeCmd(FullNode, portOffset, master = true, label = "master node") result.add(masterNode) for i in 1..