mirror of https://github.com/waku-org/nwaku.git
Improvement/bridge improvements (#429)
* General test, import and log improvements * Bridge improvements
This commit is contained in:
parent
2fe6935623
commit
a30d6a8aae
|
@ -1,3 +1,5 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[unittest, options, sets, tables, os, strutils, sequtils],
|
std/[unittest, options, sets, tables, os, strutils, sequtils],
|
||||||
stew/shims/net as stewNet,
|
stew/shims/net as stewNet,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[unittest, options, tables, sets],
|
std/[unittest, options, tables, sets],
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[unittest, options, sets, tables, sequtils],
|
std/[unittest, options, sets, tables, sequtils],
|
||||||
stew/shims/net as stewNet,
|
stew/shims/net as stewNet,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/unittest,
|
std/[unittest, strutils],
|
||||||
chronicles, chronos, stew/shims/net as stewNet, stew/byteutils,
|
chronicles, chronos, stew/shims/net as stewNet, stew/byteutils,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/crypto/secp,
|
libp2p/crypto/secp,
|
||||||
|
@ -14,10 +14,10 @@ import
|
||||||
eth/keys,
|
eth/keys,
|
||||||
../../waku/common/wakubridge,
|
../../waku/common/wakubridge,
|
||||||
../../waku/v1/protocol/waku_protocol,
|
../../waku/v1/protocol/waku_protocol,
|
||||||
../../waku/v2/protocol/[waku_message, message_notifier],
|
../../waku/v2/protocol/waku_message,
|
||||||
../../waku/v2/protocol/waku_store/waku_store,
|
../../waku/v2/protocol/waku_store/waku_store,
|
||||||
../../waku/v2/protocol/waku_filter/waku_filter,
|
../../waku/v2/protocol/waku_filter/waku_filter,
|
||||||
../../waku/v2/node/wakunode2,
|
../../waku/v2/node/[wakunode2, waku_payload],
|
||||||
../test_helpers
|
../test_helpers
|
||||||
|
|
||||||
procSuite "WakuBridge":
|
procSuite "WakuBridge":
|
||||||
|
@ -61,6 +61,10 @@ procSuite "WakuBridge":
|
||||||
proc relayHandler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
proc relayHandler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
||||||
let msg = WakuMessage.init(data)
|
let msg = WakuMessage.init(data)
|
||||||
if msg.isOk() and msg.value().version == 1:
|
if msg.isOk() and msg.value().version == 1:
|
||||||
|
check:
|
||||||
|
# Message fields are as expected
|
||||||
|
msg.value().contentTopic == contentTopic # Topic translation worked
|
||||||
|
string.fromBytes(msg.value().payload).contains("from V1")
|
||||||
completionFut.complete(true)
|
completionFut.complete(true)
|
||||||
|
|
||||||
v2Node.subscribe(defaultBridgeTopic, relayHandler)
|
v2Node.subscribe(defaultBridgeTopic, relayHandler)
|
||||||
|
@ -76,6 +80,13 @@ procSuite "WakuBridge":
|
||||||
# v1Node received message published by v2Node
|
# v1Node received message published by v2Node
|
||||||
v1Node.protocolState(Waku).queue.items.len == 1
|
v1Node.protocolState(Waku).queue.items.len == 1
|
||||||
|
|
||||||
|
let msg = v1Node.protocolState(Waku).queue.items[0]
|
||||||
|
|
||||||
|
check:
|
||||||
|
# Message fields are as expected
|
||||||
|
msg.env.topic == topic # Topic translation worked
|
||||||
|
string.fromBytes(msg.env.data).contains("from V2")
|
||||||
|
|
||||||
# Test bridging from V1 to V2
|
# Test bridging from V1 to V2
|
||||||
check:
|
check:
|
||||||
v1Node.postMessage(ttl = 5,
|
v1Node.postMessage(ttl = 5,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
chronos, chronicles, options, stint, unittest,
|
chronos, chronicles, options, stint, unittest,
|
||||||
web3,
|
web3,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[unittest, options, tables, sets],
|
std/[unittest, options, tables, sets],
|
||||||
chronos, chronicles, stew/shims/net as stewNet, stew/byteutils,
|
chronos, chronicles, stew/shims/net as stewNet, stew/byteutils,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import web3
|
import web3
|
||||||
proc web3Test() =
|
proc web3Test() =
|
||||||
var web3: Web3 # an identifier from web3 package
|
var web3: Web3 # an identifier from web3 package
|
||||||
|
|
|
@ -1,28 +1,21 @@
|
||||||
import
|
import
|
||||||
std/[strutils, tables],
|
std/tables,
|
||||||
chronos, confutils, chronicles, chronicles/topics_registry, metrics,
|
chronos, confutils, chronicles, chronicles/topics_registry, metrics,
|
||||||
stew/endians2,
|
stew/endians2,
|
||||||
stew/shims/net as stewNet, json_rpc/rpcserver,
|
stew/shims/net as stewNet, json_rpc/rpcserver,
|
||||||
# Waku v1 imports
|
# Waku v1 imports
|
||||||
eth/[keys, p2p], eth/common/utils,
|
eth/[keys, p2p], eth/common/utils,
|
||||||
eth/p2p/[enode, whispernodes],
|
eth/p2p/enode,
|
||||||
../v1/protocol/waku_protocol,
|
../v1/protocol/waku_protocol,
|
||||||
./utils/nat,
|
|
||||||
../v1/node/rpc/wakusim,
|
|
||||||
../v1/node/rpc/waku,
|
|
||||||
../v1/node/rpc/key_storage,
|
|
||||||
../v1/node/waku_helpers,
|
|
||||||
# Waku v2 imports
|
# Waku v2 imports
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
../v2/protocol/waku_filter/waku_filter_types,
|
../v2/protocol/waku_filter/waku_filter_types,
|
||||||
../v2/node/wakunode2,
|
../v2/node/wakunode2,
|
||||||
../v2/node/jsonrpc/[debug_api,
|
|
||||||
filter_api,
|
|
||||||
relay_api,
|
|
||||||
store_api],
|
|
||||||
# Common cli config
|
# Common cli config
|
||||||
./config_bridge
|
./config_bridge
|
||||||
|
|
||||||
|
declarePublicCounter waku_bridge_transfers, "Number of messages transferred between Waku v1 and v2 networks", ["type"]
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "wakubridge"
|
topics = "wakubridge"
|
||||||
|
|
||||||
|
@ -51,15 +44,17 @@ type
|
||||||
func toWakuMessage(env: Envelope): WakuMessage =
|
func toWakuMessage(env: Envelope): WakuMessage =
|
||||||
# Translate a Waku v1 envelope to a Waku v2 message
|
# Translate a Waku v1 envelope to a Waku v2 message
|
||||||
WakuMessage(payload: env.data,
|
WakuMessage(payload: env.data,
|
||||||
contentTopic: ContentTopic(uint32.fromBytes(env.topic)),
|
contentTopic: ContentTopic(uint32.fromBytes(env.topic, Endianness.bigEndian)),
|
||||||
version: 1)
|
version: 1)
|
||||||
|
|
||||||
proc toWakuV2(bridge: WakuBridge, env: Envelope) {.async.} =
|
proc toWakuV2(bridge: WakuBridge, env: Envelope) {.async.} =
|
||||||
|
waku_bridge_transfers.inc(labelValues = ["v1_to_v2"])
|
||||||
await bridge.nodev2.publish(defaultBridgeTopic, env.toWakuMessage())
|
await bridge.nodev2.publish(defaultBridgeTopic, env.toWakuMessage())
|
||||||
|
|
||||||
proc toWakuV1(bridge: WakuBridge, msg: WakuMessage) {.gcsafe.} =
|
proc toWakuV1(bridge: WakuBridge, msg: WakuMessage) {.gcsafe.} =
|
||||||
|
waku_bridge_transfers.inc(labelValues = ["v2_to_v1"])
|
||||||
discard bridge.nodev1.postMessage(ttl = defaultTTL,
|
discard bridge.nodev1.postMessage(ttl = defaultTTL,
|
||||||
topic = msg.contentTopic.toBytes(),
|
topic = msg.contentTopic.toBytes(Endianness.bigEndian),
|
||||||
payload = msg.payload)
|
payload = msg.payload)
|
||||||
|
|
||||||
##############
|
##############
|
||||||
|
@ -144,6 +139,18 @@ proc stop*(bridge: WakuBridge) {.async.} =
|
||||||
await bridge.nodev2.stop()
|
await bridge.nodev2.stop()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
|
import
|
||||||
|
eth/p2p/whispernodes,
|
||||||
|
./utils/nat,
|
||||||
|
../v1/node/rpc/wakusim,
|
||||||
|
../v1/node/rpc/waku,
|
||||||
|
../v1/node/rpc/key_storage,
|
||||||
|
../v1/node/waku_helpers,
|
||||||
|
../v2/node/jsonrpc/[debug_api,
|
||||||
|
filter_api,
|
||||||
|
relay_api,
|
||||||
|
store_api]
|
||||||
|
|
||||||
proc startV2Rpc(node: WakuNode, rpcServer: RpcHttpServer, conf: WakuNodeConf) =
|
proc startV2Rpc(node: WakuNode, rpcServer: RpcHttpServer, conf: WakuNodeConf) =
|
||||||
installDebugApiHandlers(node, rpcServer)
|
installDebugApiHandlers(node, rpcServer)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,9 @@ import
|
||||||
|
|
||||||
export jsonrpc_types
|
export jsonrpc_types
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "admin api"
|
||||||
|
|
||||||
const futTimeout* = 30.seconds # Max time to wait for futures
|
const futTimeout* = 30.seconds # Max time to wait for futures
|
||||||
|
|
||||||
proc constructMultiaddrStr*(wireaddr: MultiAddress, peerId: PeerId): string =
|
proc constructMultiaddrStr*(wireaddr: MultiAddress, peerId: PeerId): string =
|
||||||
|
|
|
@ -2,6 +2,9 @@ import
|
||||||
json_rpc/rpcserver,
|
json_rpc/rpcserver,
|
||||||
../wakunode2
|
../wakunode2
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "debug api"
|
||||||
|
|
||||||
proc installDebugApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
proc installDebugApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
||||||
|
|
||||||
## Debug API version 1 definitions
|
## Debug API version 1 definitions
|
||||||
|
|
|
@ -10,6 +10,9 @@ import
|
||||||
|
|
||||||
export jsonrpc_types
|
export jsonrpc_types
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "filter api"
|
||||||
|
|
||||||
const futTimeout* = 5.seconds # Max time to wait for futures
|
const futTimeout* = 5.seconds # Max time to wait for futures
|
||||||
const maxCache* = 100 # Max number of messages cached per topic @TODO make this configurable
|
const maxCache* = 100 # Max number of messages cached per topic @TODO make this configurable
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
std/[options, json, sequtils],
|
std/[options, json],
|
||||||
eth/keys,
|
eth/keys,
|
||||||
../../../v1/node/rpc/hexstrings,
|
../../../v1/node/rpc/hexstrings,
|
||||||
../../protocol/waku_store/waku_store_types,
|
../../protocol/waku_store/waku_store_types,
|
||||||
|
|
|
@ -10,6 +10,9 @@ import
|
||||||
|
|
||||||
export waku_payload, jsonrpc_types
|
export waku_payload, jsonrpc_types
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "private api"
|
||||||
|
|
||||||
const futTimeout* = 5.seconds # Max time to wait for futures
|
const futTimeout* = 5.seconds # Max time to wait for futures
|
||||||
|
|
||||||
proc installPrivateApiHandlers*(node: WakuNode, rpcsrv: RpcServer, rng: ref BrHmacDrbgContext, topicCache: TopicCache) =
|
proc installPrivateApiHandlers*(node: WakuNode, rpcsrv: RpcServer, rng: ref BrHmacDrbgContext, topicCache: TopicCache) =
|
||||||
|
|
|
@ -11,6 +11,9 @@ import
|
||||||
|
|
||||||
export jsonrpc_types
|
export jsonrpc_types
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "relay api"
|
||||||
|
|
||||||
const futTimeout* = 5.seconds # Max time to wait for futures
|
const futTimeout* = 5.seconds # Max time to wait for futures
|
||||||
const maxCache* = 100 # Max number of messages cached per topic @TODO make this configurable
|
const maxCache* = 100 # Max number of messages cached per topic @TODO make this configurable
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@ import
|
||||||
|
|
||||||
export jsonrpc_types
|
export jsonrpc_types
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "store api"
|
||||||
|
|
||||||
proc installStoreApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
proc installStoreApiHandlers*(node: WakuNode, rpcsrv: RpcServer) =
|
||||||
const futTimeout = 5.seconds
|
const futTimeout = 5.seconds
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
chronicles, options, chronos, stint, sequtils,
|
chronicles, options, chronos, stint,
|
||||||
web3,
|
web3,
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
|
|
Loading…
Reference in New Issue