2020-04-29 05:54:03 +00:00
|
|
|
import
|
2020-06-02 11:27:20 +00:00
|
|
|
os, strutils, strformat, chronicles, json_rpc/[rpcclient, rpcserver], nimcrypto/sysrand,
|
2020-04-29 05:54:03 +00:00
|
|
|
eth/common as eth_common, eth/keys,
|
2020-05-27 04:25:10 +00:00
|
|
|
options
|
|
|
|
#options as what # TODO: Huh? Redefinition?
|
2020-04-29 05:54:03 +00:00
|
|
|
|
|
|
|
from os import DirSep
|
|
|
|
from strutils import rsplit
|
|
|
|
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
|
|
|
|
|
|
|
const sigWakuPath = &"{sourceDir}{DirSep}rpc{DirSep}wakucallsigs.nim"
|
|
|
|
createRpcSigs(RpcHttpClient, sigWakuPath)
|
|
|
|
|
2020-05-27 04:25:10 +00:00
|
|
|
const topicAmount = 100
|
|
|
|
|
2020-05-22 07:35:31 +00:00
|
|
|
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
|
|
|
debug "Hit handler", topic=topic, data=data
|
|
|
|
|
2020-06-02 03:18:55 +00:00
|
|
|
# All full nodes connected etc
|
|
|
|
#
|
|
|
|
# let node1 = newRpcHttpClient()
|
|
|
|
# let node2 = newRpcHttpClient()
|
|
|
|
# let node3 = newRpcHttpClient()
|
|
|
|
# let node4 = newRpcHttpClient()
|
|
|
|
# let node5 = newRpcHttpClient()
|
|
|
|
# let node6 = newRpcHttpClient()
|
2020-05-27 04:25:10 +00:00
|
|
|
|
2020-06-02 03:18:55 +00:00
|
|
|
# waitFor node1.connect("localhost", Port(8547))
|
|
|
|
# waitFor node2.connect("localhost", Port(8548))
|
|
|
|
# waitFor node3.connect("localhost", Port(8549))
|
|
|
|
# waitFor node4.connect("localhost", Port(8550))
|
|
|
|
# waitFor node5.connect("localhost", Port(8551))
|
|
|
|
# waitFor node6.connect("localhost", Port(8552))
|
|
|
|
|
|
|
|
# let version = waitFor node6.wakuVersion()
|
|
|
|
# info "Version is", version
|
|
|
|
|
|
|
|
# # TODO: Implement handler logic
|
|
|
|
# # All subscribing to foobar topic
|
|
|
|
# let res2 = waitFor node2.wakuSubscribe("foobar")
|
|
|
|
# let res3 = waitFor node3.wakuSubscribe("foobar")
|
|
|
|
# let res4 = waitFor node4.wakuSubscribe("foobar")
|
|
|
|
# let res5 = waitFor node5.wakuSubscribe("foobar")
|
|
|
|
# let res6 = waitFor node6.wakuSubscribe("foobar")
|
|
|
|
# os.sleep(2000)
|
|
|
|
|
|
|
|
# # info "Posting envelopes on all subscribed topics"
|
|
|
|
# for i in 0..<topicAmount:
|
|
|
|
# os.sleep(50)
|
|
|
|
# let res2 = waitFor node1.wakuPublish("foobar", "hello world")
|
|
|
|
|
|
|
|
# os.sleep(2000)
|
|
|
|
|
|
|
|
# for i in 0..<topicAmount:
|
|
|
|
# os.sleep(50)
|
|
|
|
# let res2 = waitFor node1.wakuPublish("foobar", "hello world2")
|
|
|
|
|
|
|
|
let nodea = newRpcHttpClient()
|
|
|
|
let nodeb = newRpcHttpClient()
|
|
|
|
|
|
|
|
waitFor nodea.connect("localhost", Port(8545))
|
|
|
|
waitFor nodeb.connect("localhost", Port(8546))
|
|
|
|
|
|
|
|
let version = waitFor nodea.wakuVersion()
|
|
|
|
info "Version is", version
|
|
|
|
|
2020-06-02 11:27:20 +00:00
|
|
|
# XXX: Unclear if we want nodea to subscribe to own topic or not
|
2020-06-02 03:18:55 +00:00
|
|
|
let res1 = waitFor nodea.wakuSubscribe("foobar")
|
|
|
|
let res2 = waitFor nodeb.wakuSubscribe("foobar")
|
2020-05-27 04:25:10 +00:00
|
|
|
|
2020-06-03 11:30:37 +00:00
|
|
|
# Node 00 and 05 also subscribe
|
2020-06-03 11:32:11 +00:00
|
|
|
# XXX I confirm this works. As in - with this we have A-B
|
|
|
|
# Now to tweak it!
|
|
|
|
# let node0 = newRpcHttpClient()
|
|
|
|
# let node5 = newRpcHttpClient()
|
|
|
|
# waitFor node0.connect("localhost", Port(8547))
|
|
|
|
# waitFor node5.connect("localhost", Port(8552))
|
|
|
|
# let res4 = waitFor node0.wakuSubscribe("foobar")
|
|
|
|
# let res5 = waitFor node5.wakuSubscribe("foobar")
|
2020-06-03 11:30:37 +00:00
|
|
|
|
2020-05-26 04:02:25 +00:00
|
|
|
os.sleep(2000)
|
2020-06-02 03:18:55 +00:00
|
|
|
|
2020-06-02 11:27:20 +00:00
|
|
|
# XXX: Where is hello world tho?
|
2020-06-02 03:18:55 +00:00
|
|
|
for i in 0..<topicAmount:
|
|
|
|
os.sleep(50)
|
2020-06-02 11:27:20 +00:00
|
|
|
var s = "hello " & $2
|
|
|
|
var res3 = waitFor nodea.wakuPublish("foobar", s)
|