2019-12-16 23:41:20 +00:00
|
|
|
import
|
2020-01-15 12:19:24 +00:00
|
|
|
os, strformat, chronicles, json_rpc/[rpcclient, rpcserver], nimcrypto/sysrand,
|
2019-12-16 23:41:20 +00:00
|
|
|
eth/common as eth_common, eth/keys, eth/p2p/rlpx_protocols/waku_protocol,
|
|
|
|
../nimbus/rpc/[hexstrings, rpc_types, waku],
|
2020-01-20 18:01:02 +00:00
|
|
|
options as what # TODO: Huh? Redefinition?
|
2019-12-16 23:41:20 +00:00
|
|
|
|
|
|
|
from os import DirSep
|
|
|
|
from strutils import rsplit
|
|
|
|
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
|
|
|
|
2020-01-14 23:09:39 +00:00
|
|
|
const sigWakuPath = &"{sourceDir}{DirSep}rpc{DirSep}wakucallsigs.nim"
|
|
|
|
createRpcSigs(RpcHttpClient, sigWakuPath)
|
2019-12-16 23:41:20 +00:00
|
|
|
|
|
|
|
let
|
2020-01-14 23:09:39 +00:00
|
|
|
trafficNode = newRpcHttpClient()
|
|
|
|
lightWakuNode = newRpcHttpClient()
|
|
|
|
lightNode = newRpcHttpClient()
|
2019-12-16 23:41:20 +00:00
|
|
|
|
2020-01-17 16:52:34 +00:00
|
|
|
waitFor lightWakuNode.connect("localhost", Port(8545))
|
|
|
|
waitFor lightNode.connect("localhost", Port(8546))
|
|
|
|
waitFor trafficNode.connect("localhost", Port(8548))
|
2019-12-16 23:41:20 +00:00
|
|
|
|
2020-01-15 12:19:24 +00:00
|
|
|
proc generateTopics(amount = 100): seq[waku_protocol.Topic] =
|
|
|
|
var topic: waku_protocol.Topic
|
|
|
|
for i in 0..<amount:
|
|
|
|
if randomBytes(topic) != 4:
|
|
|
|
raise newException(ValueError, "Generation of random topic failed.")
|
|
|
|
result.add(topic)
|
|
|
|
|
2019-12-16 23:41:20 +00:00
|
|
|
let
|
2020-01-14 23:09:39 +00:00
|
|
|
symKey = "0x0000000000000000000000000000000000000000000000000000000000000001"
|
2020-01-15 12:19:24 +00:00
|
|
|
topics = generateTopics()
|
2020-01-20 17:01:18 +00:00
|
|
|
symKeyID = waitFor lightWakuNode.waku_addSymKey(symKey)
|
2019-12-16 23:41:20 +00:00
|
|
|
options = WhisperFilterOptions(symKeyID: some(symKeyID),
|
2020-01-15 12:19:24 +00:00
|
|
|
topics: some(topics))
|
2020-01-20 17:01:18 +00:00
|
|
|
filterID = waitFor lightWakuNode.waku_newMessageFilter(options)
|
2019-12-16 23:41:20 +00:00
|
|
|
|
2020-01-20 17:01:18 +00:00
|
|
|
symKeyID2 = waitFor lightNode.waku_addSymKey(symKey)
|
2020-01-14 23:09:39 +00:00
|
|
|
options2 = WhisperFilterOptions(symKeyID: some(symKeyID2),
|
2020-01-15 12:19:24 +00:00
|
|
|
topics: some(topics))
|
2020-01-20 17:01:18 +00:00
|
|
|
filterID2 = waitFor lightNode.waku_newMessageFilter(options2)
|
2020-01-14 23:09:39 +00:00
|
|
|
|
2020-01-20 17:01:18 +00:00
|
|
|
symkeyID3 = waitFor trafficNode.waku_addSymKey(symKey)
|
2020-01-14 23:09:39 +00:00
|
|
|
|
|
|
|
var message = WhisperPostMessage(symKeyID: some(symkeyID3),
|
|
|
|
ttl: 30,
|
2020-01-15 12:19:24 +00:00
|
|
|
topic: some(topics[0]),
|
2020-01-14 23:09:39 +00:00
|
|
|
payload: "0x45879632".HexDataStr,
|
|
|
|
powTime: 1.0,
|
|
|
|
powTarget: 0.002)
|
2020-01-20 17:01:18 +00:00
|
|
|
discard waitFor trafficNode.waku_post(message)
|
2019-12-16 23:41:20 +00:00
|
|
|
|
|
|
|
var messages: seq[WhisperFilterMessage]
|
2019-12-17 05:46:23 +00:00
|
|
|
|
2020-01-14 23:09:39 +00:00
|
|
|
# Check if the subscription for the topic works
|
2019-12-16 23:41:20 +00:00
|
|
|
while messages.len == 0:
|
2020-01-20 17:01:18 +00:00
|
|
|
messages = waitFor lightWakuNode.waku_getFilterMessages(filterID)
|
2020-01-14 23:09:39 +00:00
|
|
|
waitFor sleepAsync(1000.milliseconds)
|
|
|
|
info "Received test message", payload = messages[0].payload
|
2019-12-17 05:46:23 +00:00
|
|
|
|
2020-01-14 23:09:39 +00:00
|
|
|
# Generate test traffic on node
|
2020-01-15 12:19:24 +00:00
|
|
|
discard waitFor trafficNode.wakusim_generateRandomTraffic(10_000)
|