import strformat, os, osproc, net, strformat, chronicles, json, libp2p/multiaddress, libp2p/crypto/crypto, libp2p/crypto/secp, libp2p/peerinfo # Fix ambiguous call error import strutils except fromHex const defaults ="--log-level:TRACE --log-metrics --metrics-server --rpc" wakuNodeBin = "build" / "wakunode2" metricsDir = "metrics" portOffset = 2 type NodeInfo* = object cmd: string master: bool address: string shift: int label: string Topology = enum Star, FullMesh # NOTE: Don't distinguish between node types here a la full node, light node etc proc initNodeCmd(shift: int, staticNodes: seq[string] = @[], master = false, label: string): NodeInfo = let rng = crypto.newRng() key = SkPrivateKey.random(rng[]) hkey = key.getBytes().toHex() rkey = SkPrivateKey.init(fromHex(hkey))[] #assumes ok privKey = PrivateKey(scheme: Secp256k1, skkey: rkey) #privKey = PrivateKey.random(Secp256k1) pubkey = privKey.getKey()[] #assumes ok keys = KeyPair(seckey: privKey, pubkey: pubkey) peerInfo = PeerInfo.init(privKey) port = 60000 + shift #DefaultAddr = "/ip4/127.0.0.1/tcp/55505" address = "/ip4/127.0.0.1/tcp/" & $port hostAddress = MultiAddress.init(address).tryGet() info "Address", address # TODO: Need to port shift peerInfo.addrs.add(hostAddress) let id = $peerInfo.peerId 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.master = master result.address = listenStr info "Node command created.", cmd=result.cmd, address = result.address proc starNetwork(amount: int): seq[NodeInfo] = let masterNode = initNodeCmd(portOffset, master = true, label = "master node") result.add(masterNode) for i in 1..