mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-14 17:04:53 +00:00
deploy: 9ee0c2ecb37f04ebe6e17fbf69828a60212ffcea
This commit is contained in:
parent
10bd077556
commit
1c95c93fe8
@ -26,6 +26,8 @@ procSuite "WakuBridge":
|
|||||||
# Suite setup #
|
# Suite setup #
|
||||||
###############
|
###############
|
||||||
|
|
||||||
|
const DefaultBridgeTopic = "/waku/2/default-bridge/proto"
|
||||||
|
|
||||||
let
|
let
|
||||||
rng = keys.newRng()
|
rng = keys.newRng()
|
||||||
|
|
||||||
@ -38,7 +40,8 @@ procSuite "WakuBridge":
|
|||||||
powRequirement = 0.002,
|
powRequirement = 0.002,
|
||||||
rng = rng,
|
rng = rng,
|
||||||
nodev2Key = nodev2Key,
|
nodev2Key = nodev2Key,
|
||||||
nodev2BindIp = ValidIpAddress.init("0.0.0.0"), nodev2BindPort= Port(60000))
|
nodev2BindIp = ValidIpAddress.init("0.0.0.0"), nodev2BindPort= Port(60000),
|
||||||
|
nodev2PubsubTopic = DefaultBridgeTopic)
|
||||||
|
|
||||||
# Waku v1 node
|
# Waku v1 node
|
||||||
v1Node = setupTestNode(rng, Waku)
|
v1Node = setupTestNode(rng, Waku)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# libtool - Provide generalized library-building support services.
|
# libtool - Provide generalized library-building support services.
|
||||||
# Generated automatically by config.status (libbacktrace) version-unused
|
# Generated automatically by config.status (libbacktrace) version-unused
|
||||||
# Libtool was configured on host fv-az272-819:
|
# Libtool was configured on host fv-az275-538:
|
||||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||||
#
|
#
|
||||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||||
|
@ -93,10 +93,15 @@ type
|
|||||||
defaultValue: keys.KeyPair.random(keys.newRng()[])
|
defaultValue: keys.KeyPair.random(keys.newRng()[])
|
||||||
name: "nodekey-v1" .}: keys.KeyPair
|
name: "nodekey-v1" .}: keys.KeyPair
|
||||||
|
|
||||||
wakuPow* {.
|
wakuV1Pow* {.
|
||||||
desc: "PoW requirement of Waku node.",
|
desc: "PoW requirement of Waku v1 node.",
|
||||||
defaultValue: 0.002
|
defaultValue: 0.002
|
||||||
name: "waku-pow" .}: float64
|
name: "waku-v1-pow" .}: float64
|
||||||
|
|
||||||
|
wakuV1TopicInterest* {.
|
||||||
|
desc: "Run as Waku v1 node with a topic-interest",
|
||||||
|
defaultValue: false
|
||||||
|
name: "waku-v1-topic-interest" .}: bool
|
||||||
|
|
||||||
### Waku v2 options
|
### Waku v2 options
|
||||||
|
|
||||||
@ -109,11 +114,6 @@ type
|
|||||||
defaultValue: crypto.PrivateKey.random(Secp256k1, keys.newRng()[]).tryGet()
|
defaultValue: crypto.PrivateKey.random(Secp256k1, keys.newRng()[]).tryGet()
|
||||||
name: "nodekey-v2" }: crypto.PrivateKey
|
name: "nodekey-v2" }: crypto.PrivateKey
|
||||||
|
|
||||||
topics* {.
|
|
||||||
desc: "Default topics to subscribe to (space separated list)"
|
|
||||||
defaultValue: "/waku/2/default-waku/proto"
|
|
||||||
name: "topics" .}: string
|
|
||||||
|
|
||||||
store* {.
|
store* {.
|
||||||
desc: "Flag whether to start store protocol",
|
desc: "Flag whether to start store protocol",
|
||||||
defaultValue: true
|
defaultValue: true
|
||||||
@ -138,6 +138,13 @@ type
|
|||||||
desc: "Multiaddr of peer to connect with for waku filter protocol"
|
desc: "Multiaddr of peer to connect with for waku filter protocol"
|
||||||
defaultValue: ""
|
defaultValue: ""
|
||||||
name: "filternode" }: string
|
name: "filternode" }: string
|
||||||
|
|
||||||
|
### Bridge options
|
||||||
|
|
||||||
|
bridgePubsubTopic* {.
|
||||||
|
desc: "Waku v2 Pubsub topic to bridge to/from"
|
||||||
|
defaultValue: "/waku/2/default-waku/proto"
|
||||||
|
name: "bridge-pubsub-topic" }: string
|
||||||
|
|
||||||
proc parseCmdArg*(T: type keys.KeyPair, p: TaintedString): T =
|
proc parseCmdArg*(T: type keys.KeyPair, p: TaintedString): T =
|
||||||
try:
|
try:
|
||||||
|
@ -26,7 +26,6 @@ logScope:
|
|||||||
##################
|
##################
|
||||||
|
|
||||||
const
|
const
|
||||||
DefaultBridgeTopic* = "/waku/2/default-bridge/proto"
|
|
||||||
ClientIdV1 = "nim-waku v1 node"
|
ClientIdV1 = "nim-waku v1 node"
|
||||||
DefaultTTL = 5'u32
|
DefaultTTL = 5'u32
|
||||||
DeduplQSize = 20 # Maximum number of seen messages to keep in deduplication queue
|
DeduplQSize = 20 # Maximum number of seen messages to keep in deduplication queue
|
||||||
@ -39,6 +38,7 @@ type
|
|||||||
WakuBridge* = ref object of RootObj
|
WakuBridge* = ref object of RootObj
|
||||||
nodev1*: EthereumNode
|
nodev1*: EthereumNode
|
||||||
nodev2*: WakuNode
|
nodev2*: WakuNode
|
||||||
|
nodev2PubsubTopic: wakunode2.Topic # Pubsub topic to bridge to/from
|
||||||
seen: seq[hashes.Hash] # FIFO queue of seen WakuMessages. Used for deduplication.
|
seen: seq[hashes.Hash] # FIFO queue of seen WakuMessages. Used for deduplication.
|
||||||
|
|
||||||
###################
|
###################
|
||||||
@ -76,7 +76,7 @@ proc toWakuV2(bridge: WakuBridge, env: Envelope) {.async.} =
|
|||||||
|
|
||||||
waku_bridge_transfers.inc(labelValues = ["v1_to_v2"])
|
waku_bridge_transfers.inc(labelValues = ["v1_to_v2"])
|
||||||
|
|
||||||
await bridge.nodev2.publish(DefaultBridgeTopic, msg)
|
await bridge.nodev2.publish(bridge.nodev2PubsubTopic, msg)
|
||||||
|
|
||||||
proc toWakuV1(bridge: WakuBridge, msg: WakuMessage) {.gcsafe.} =
|
proc toWakuV1(bridge: WakuBridge, msg: WakuMessage) {.gcsafe.} =
|
||||||
if bridge.seen.containsOrAdd(msg.encode().buffer.hash()):
|
if bridge.seen.containsOrAdd(msg.encode().buffer.hash()):
|
||||||
@ -105,10 +105,14 @@ proc new*(T: type WakuBridge,
|
|||||||
nodev1Address: Address,
|
nodev1Address: Address,
|
||||||
powRequirement = 0.002,
|
powRequirement = 0.002,
|
||||||
rng: ref BrHmacDrbgContext,
|
rng: ref BrHmacDrbgContext,
|
||||||
|
topicInterest = none(seq[waku_protocol.Topic]),
|
||||||
|
bloom = some(fullBloom()),
|
||||||
# NodeV2 initialisation
|
# NodeV2 initialisation
|
||||||
nodev2Key: crypto.PrivateKey,
|
nodev2Key: crypto.PrivateKey,
|
||||||
nodev2BindIp: ValidIpAddress, nodev2BindPort: Port,
|
nodev2BindIp: ValidIpAddress, nodev2BindPort: Port,
|
||||||
nodev2ExtIp = none[ValidIpAddress](), nodev2ExtPort = none[Port]()): T =
|
nodev2ExtIp = none[ValidIpAddress](), nodev2ExtPort = none[Port](),
|
||||||
|
# Bridge configuration
|
||||||
|
nodev2PubsubTopic: wakunode2.Topic): T =
|
||||||
|
|
||||||
# Setup Waku v1 node
|
# Setup Waku v1 node
|
||||||
var
|
var
|
||||||
@ -119,13 +123,15 @@ proc new*(T: type WakuBridge,
|
|||||||
nodev1.addCapability Waku # Always enable Waku protocol
|
nodev1.addCapability Waku # Always enable Waku protocol
|
||||||
|
|
||||||
# Setup the Waku configuration.
|
# Setup the Waku configuration.
|
||||||
# This node is being set up as a bridge so it gets configured as a node with
|
# This node is being set up as a bridge. By default it gets configured as a node with
|
||||||
# a full bloom filter so that it will receive and forward all messages.
|
# a full bloom filter so that it will receive and forward all messages.
|
||||||
|
# It is, however, possible to configure a topic interest to bridge only
|
||||||
|
# selected messages.
|
||||||
# TODO: What is the PoW setting now?
|
# TODO: What is the PoW setting now?
|
||||||
let wakuConfig = WakuConfig(powRequirement: powRequirement,
|
let wakuConfig = WakuConfig(powRequirement: powRequirement,
|
||||||
bloom: some(fullBloom()), isLightNode: false,
|
bloom: bloom, isLightNode: false,
|
||||||
maxMsgSize: waku_protocol.defaultMaxMsgSize,
|
maxMsgSize: waku_protocol.defaultMaxMsgSize,
|
||||||
topics: none(seq[waku_protocol.Topic]))
|
topics: topicInterest)
|
||||||
nodev1.configureWaku(wakuConfig)
|
nodev1.configureWaku(wakuConfig)
|
||||||
|
|
||||||
# Setup Waku v2 node
|
# Setup Waku v2 node
|
||||||
@ -134,7 +140,7 @@ proc new*(T: type WakuBridge,
|
|||||||
nodev2BindIp, nodev2BindPort,
|
nodev2BindIp, nodev2BindPort,
|
||||||
nodev2ExtIp, nodev2ExtPort)
|
nodev2ExtIp, nodev2ExtPort)
|
||||||
|
|
||||||
return WakuBridge(nodev1: nodev1, nodev2: nodev2)
|
return WakuBridge(nodev1: nodev1, nodev2: nodev2, nodev2PubsubTopic: nodev2PubsubTopic)
|
||||||
|
|
||||||
proc start*(bridge: WakuBridge) {.async.} =
|
proc start*(bridge: WakuBridge) {.async.} =
|
||||||
info "Starting WakuBridge"
|
info "Starting WakuBridge"
|
||||||
@ -174,7 +180,7 @@ proc start*(bridge: WakuBridge) {.async.} =
|
|||||||
trace "Bridging message from V2 to V1", msg=msg[]
|
trace "Bridging message from V2 to V1", msg=msg[]
|
||||||
bridge.toWakuV1(msg[])
|
bridge.toWakuV1(msg[])
|
||||||
|
|
||||||
bridge.nodev2.subscribe(DefaultBridgeTopic, relayHandler)
|
bridge.nodev2.subscribe(bridge.nodev2PubsubTopic, relayHandler)
|
||||||
|
|
||||||
proc stop*(bridge: WakuBridge) {.async.} =
|
proc stop*(bridge: WakuBridge) {.async.} =
|
||||||
await bridge.nodev2.stop()
|
await bridge.nodev2.stop()
|
||||||
@ -234,15 +240,28 @@ when isMainModule:
|
|||||||
(nodev2ExtIp, nodev2ExtPort, _) = setupNat(conf.nat, clientId,
|
(nodev2ExtIp, nodev2ExtPort, _) = setupNat(conf.nat, clientId,
|
||||||
Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
|
Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
|
||||||
Port(uint16(conf.udpPort) + conf.portsShift))
|
Port(uint16(conf.udpPort) + conf.portsShift))
|
||||||
|
|
||||||
|
# Topic interest and bloom
|
||||||
|
var topicInterest: Option[seq[waku_protocol.Topic]]
|
||||||
|
var bloom: Option[Bloom]
|
||||||
|
|
||||||
|
if conf.wakuV1TopicInterest:
|
||||||
|
var topics: seq[waku_protocol.Topic]
|
||||||
|
topicInterest = some(topics)
|
||||||
|
else:
|
||||||
|
bloom = some(fullBloom())
|
||||||
|
|
||||||
let
|
let
|
||||||
bridge = WakuBridge.new(nodev1Key = conf.nodekeyV1,
|
bridge = WakuBridge.new(nodev1Key = conf.nodekeyV1,
|
||||||
nodev1Address = nodev1Address,
|
nodev1Address = nodev1Address,
|
||||||
powRequirement = conf.wakuPow,
|
powRequirement = conf.wakuV1Pow,
|
||||||
rng = rng,
|
rng = rng,
|
||||||
|
topicInterest = topicInterest,
|
||||||
|
bloom = bloom,
|
||||||
nodev2Key = conf.nodekeyV2,
|
nodev2Key = conf.nodekeyV2,
|
||||||
nodev2BindIp = conf.listenAddress, nodev2BindPort = Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
|
nodev2BindIp = conf.listenAddress, nodev2BindPort = Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
|
||||||
nodev2ExtIp = nodev2ExtIp, nodev2ExtPort = nodev2ExtPort)
|
nodev2ExtIp = nodev2ExtIp, nodev2ExtPort = nodev2ExtPort,
|
||||||
|
nodev2PubsubTopic = conf.bridgePubsubTopic)
|
||||||
|
|
||||||
waitFor bridge.start()
|
waitFor bridge.start()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user