mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-18 19:01:24 +00:00
9518322198
* Change folder structure to {v1,v2,common}/... Addresses https://github.com/status-im/nim-waku/issues/261 * Update waku.nimble paths * Flatten paths * Fix import paths * Pull out utils folder for nat * Pull out waku_types to top level for v2 * Fix test import paths * Remove old READMEs and replace with one liner * Update README and split v1 and v2 * Skeleton READMEs * Update README.md Co-authored-by: Kim De Mey <kim.demey@gmail.com> * Update README.md Co-authored-by: Kim De Mey <kim.demey@gmail.com> Co-authored-by: Kim De Mey <kim.demey@gmail.com>
32 lines
1.0 KiB
Nim
32 lines
1.0 KiB
Nim
import
|
|
json_rpc/rpcserver, stew/endians2, nimcrypto/sysrand,
|
|
eth/[p2p, async_utils],
|
|
../../protocol/waku_protocol
|
|
|
|
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
|