2020-04-29 05:54:03 +00:00
|
|
|
import
|
2022-07-25 11:01:37 +00:00
|
|
|
std/[os, strutils, times, options], #options as what # TODO: Huh? Redefinition?
|
2021-07-21 18:05:10 +00:00
|
|
|
chronicles,
|
|
|
|
eth/common as eth_common,
|
|
|
|
eth/keys,
|
|
|
|
json_rpc/[rpcclient, rpcserver],
|
2022-07-25 11:01:37 +00:00
|
|
|
libp2p/protobuf/minprotobuf
|
|
|
|
import
|
2022-11-16 19:02:38 +00:00
|
|
|
../../waku/v2/protocol/waku_filter/rpc,
|
2022-11-09 17:50:18 +00:00
|
|
|
../../waku/v2/protocol/waku_store/rpc,
|
2022-10-12 19:41:25 +00:00
|
|
|
../../waku/v2/protocol/waku_message,
|
|
|
|
../../waku/v2/utils/time,
|
2022-10-18 14:05:53 +00:00
|
|
|
../../waku/v2/node/waku_node,
|
2022-10-12 19:41:25 +00:00
|
|
|
../../waku/v2/node/waku_payload,
|
|
|
|
../../waku/v2/node/jsonrpc/[jsonrpc_types,jsonrpc_utils]
|
2021-07-21 18:05:10 +00:00
|
|
|
|
2020-04-29 05:54:03 +00:00
|
|
|
|
|
|
|
from strutils import rsplit
|
|
|
|
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
|
|
|
|
2022-10-12 19:41:25 +00:00
|
|
|
const sigWakuPath = sourceDir / ".." / ".." / "waku" / "v2" / "node" / "jsonrpc" / "jsonrpc_callsigs.nim"
|
2020-04-29 05:54:03 +00:00
|
|
|
createRpcSigs(RpcHttpClient, sigWakuPath)
|
|
|
|
|
2020-06-15 03:06:08 +00:00
|
|
|
const topicAmount = 10 #100
|
2020-05-27 04:25:10 +00:00
|
|
|
|
2020-07-23 02:53:29 +00:00
|
|
|
proc message(i: int): ProtoBuffer =
|
|
|
|
let value = "hello " & $(i)
|
|
|
|
|
|
|
|
var result = initProtoBuffer()
|
2021-11-04 14:46:38 +00:00
|
|
|
result.write(1, value)
|
2020-07-23 02:53:29 +00:00
|
|
|
result.finish()
|
|
|
|
|
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-15 03:06:08 +00:00
|
|
|
# Scenario xx1 - 16 full nodes
|
|
|
|
#########################################
|
|
|
|
let amount = 16
|
|
|
|
var nodes: seq[RPCHttpClient]
|
|
|
|
for i in 0..<amount:
|
|
|
|
var node = newRpcHttpClient()
|
|
|
|
nodes.add(node)
|
2022-01-14 09:25:01 +00:00
|
|
|
waitFor nodes[i].connect("localhost", Port(8547+i), false)
|
2022-11-09 08:55:47 +00:00
|
|
|
var res = waitFor nodes[i].post_waku_v2_relay_v1_subscriptions(@[DefaultPubsubTopic])
|
2020-06-15 03:06:08 +00:00
|
|
|
|
|
|
|
os.sleep(2000)
|
|
|
|
|
2020-06-15 03:34:10 +00:00
|
|
|
# # TODO: Show plaintext message in log
|
|
|
|
# for i in 0..<topicAmount:
|
|
|
|
# os.sleep(50)
|
|
|
|
# # TODO: This would then publish on a subtopic here
|
|
|
|
# var s = "hello " & $2
|
2022-11-09 08:55:47 +00:00
|
|
|
# var res3 = waitFor nodes[0].wakuPublish(DefaultPbsubTopic, s)
|
2020-06-15 03:34:10 +00:00
|
|
|
|
|
|
|
# Scenario xx3 - same as xx1 but publish from multiple nodes
|
|
|
|
# To compare FloodSub and GossipSub factor
|
2020-06-15 03:06:08 +00:00
|
|
|
for i in 0..<topicAmount:
|
|
|
|
os.sleep(50)
|
|
|
|
# TODO: This would then publish on a subtopic here
|
2022-11-09 08:55:47 +00:00
|
|
|
var res3 = waitFor nodes[0].post_waku_v2_relay_v1_message(DefaultPubsubTopic, WakuRelayMessage(payload: message(0).buffer, contentTopic: some(DefaultContentTopic), timestamp: some(getNanosecondTime(epochTime()))))
|
|
|
|
res3 = waitFor nodes[1].post_waku_v2_relay_v1_message(DefaultPubsubTopic, WakuRelayMessage(payload: message(1).buffer, contentTopic: some(DefaultContentTopic), timestamp: some(getNanosecondTime(epochTime()))))
|
|
|
|
res3 = waitFor nodes[2].post_waku_v2_relay_v1_message(DefaultPubsubTopic, WakuRelayMessage(payload: message(2).buffer, contentTopic: some(DefaultContentTopic), timestamp: some(getNanosecondTime(epochTime()))))
|
|
|
|
res3 = waitFor nodes[3].post_waku_v2_relay_v1_message(DefaultPubsubTopic, WakuRelayMessage(payload: message(3).buffer, contentTopic: some(DefaultContentTopic), timestamp: some(getNanosecondTime(epochTime()))))
|
|
|
|
res3 = waitFor nodes[4].post_waku_v2_relay_v1_message(DefaultPubsubTopic, WakuRelayMessage(payload: message(4).buffer, contentTopic: some(DefaultContentTopic), timestamp: some(getNanosecondTime(epochTime()))))
|
2020-06-15 03:06:08 +00:00
|
|
|
|
|
|
|
# Scenario xx2 - 14 full nodes, two edge nodes
|
|
|
|
# Assume one full topic
|
|
|
|
#########################################
|
|
|
|
#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
|
|
|
|
#
|
2022-11-09 08:55:47 +00:00
|
|
|
#let res1 = waitFor nodea.wakuSubscribe(DefaultPbsubTopic)
|
|
|
|
#let res2 = waitFor nodeb.wakuSubscribe(DefaultPbsubTopic)
|
2020-06-15 03:06:08 +00:00
|
|
|
#
|
|
|
|
#let amount = 14
|
|
|
|
#var nodes: seq[RPCHttpClient]
|
|
|
|
#for i in 0..<amount:
|
|
|
|
# var node = newRpcHttpClient()
|
|
|
|
# nodes.add(node)
|
|
|
|
# waitFor nodes[i].connect("localhost", Port(8547+i))
|
2022-11-09 08:55:47 +00:00
|
|
|
# var res = waitFor nodes[i].wakuSubscribe(DefaultPbsubTopic)
|
2020-06-15 03:06:08 +00:00
|
|
|
#
|
|
|
|
#os.sleep(2000)
|
|
|
|
#
|
|
|
|
## TODO: Show plaintext message in log
|
|
|
|
#for i in 0..<topicAmount:
|
|
|
|
# os.sleep(50)
|
|
|
|
# # TODO: This would then publish on a subtopic here
|
|
|
|
# var s = "hello " & $2
|
2022-11-09 08:55:47 +00:00
|
|
|
# var res3 = waitFor nodea.wakuPublish(DefaultPbsubTopic, s)
|
2020-06-15 03:06:08 +00:00
|
|
|
|
|
|
|
# Misc old scenarios
|
|
|
|
#########################################
|
|
|
|
|
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")
|
|
|
|
|
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")
|