2020-04-30 20:35:57 +00:00
|
|
|
import
|
|
|
|
json_rpc/rpcserver, stew/endians2, nimcrypto/sysrand,
|
2020-05-01 12:43:25 +00:00
|
|
|
eth/[p2p, async_utils],
|
2020-11-17 09:34:53 +00:00
|
|
|
../../protocol/waku_protocol
|
2020-04-30 20:35:57 +00:00
|
|
|
|
|
|
|
proc generateTraffic(node: EthereumNode, amount = 100) {.async.} =
|
|
|
|
let payload = @[byte 0]
|
|
|
|
for i in 0..<amount:
|
|
|
|
discard waku_protocol.postMessage(node, ttl = 10,
|
|
|
|
topic = toBytesLE(i.uint32), payload = payload)
|
|
|
|
await sleepAsync(1.milliseconds)
|
|
|
|
|
|
|
|
proc generateRandomTraffic(node: EthereumNode, amount = 100) {.async.} =
|
|
|
|
var topic: array[4, byte]
|
|
|
|
let payload = @[byte 0]
|
|
|
|
for i in 0..<amount:
|
|
|
|
while randomBytes(topic) != 4:
|
|
|
|
discard
|
|
|
|
discard waku_protocol.postMessage(node, ttl = 10, topic = topic,
|
|
|
|
payload = payload)
|
|
|
|
await sleepAsync(1.milliseconds)
|
|
|
|
|
|
|
|
proc setupWakuSimRPC*(node: EthereumNode, rpcsrv: RpcServer) =
|
|
|
|
|
|
|
|
rpcsrv.rpc("wakusim_generateTraffic") do(amount: int) -> bool:
|
|
|
|
traceAsyncErrors node.generateTraffic(amount)
|
|
|
|
return true
|
|
|
|
|
|
|
|
rpcsrv.rpc("wakusim_generateRandomTraffic") do(amount: int) -> bool:
|
|
|
|
traceAsyncErrors node.generateRandomTraffic(amount)
|
|
|
|
return true
|