2021-07-16 15:13:36 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
|
2020-10-21 09:54:29 +00:00
|
|
|
import
|
2021-05-20 16:03:56 +00:00
|
|
|
std/[tables, hashes, sequtils],
|
2021-11-10 12:05:36 +00:00
|
|
|
chronos, confutils, chronicles, chronicles/topics_registry, chronos/streams/tlsstream,
|
2021-06-10 14:18:41 +00:00
|
|
|
metrics, metrics/chronos_httpserver,
|
2021-07-22 08:43:41 +00:00
|
|
|
stew/byteutils,
|
2020-10-21 09:54:29 +00:00
|
|
|
stew/shims/net as stewNet, json_rpc/rpcserver,
|
|
|
|
# Waku v1 imports
|
|
|
|
eth/[keys, p2p], eth/common/utils,
|
2021-03-23 08:04:51 +00:00
|
|
|
eth/p2p/enode,
|
2020-11-17 09:34:53 +00:00
|
|
|
../v1/protocol/waku_protocol,
|
2020-10-21 09:54:29 +00:00
|
|
|
# Waku v2 imports
|
|
|
|
libp2p/crypto/crypto,
|
2021-06-18 10:30:24 +00:00
|
|
|
../v2/utils/namespacing,
|
2020-11-17 09:34:53 +00:00
|
|
|
../v2/node/wakunode2,
|
2020-10-21 09:54:29 +00:00
|
|
|
# Common cli config
|
|
|
|
./config_bridge
|
|
|
|
|
2021-03-23 08:04:51 +00:00
|
|
|
declarePublicCounter waku_bridge_transfers, "Number of messages transferred between Waku v1 and v2 networks", ["type"]
|
2021-05-20 16:03:56 +00:00
|
|
|
declarePublicCounter waku_bridge_dropped, "Number of messages dropped", ["type"]
|
2021-03-23 08:04:51 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
logScope:
|
|
|
|
topics = "wakubridge"
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Default values #
|
|
|
|
##################
|
|
|
|
|
2021-03-18 10:01:27 +00:00
|
|
|
const
|
2021-05-20 16:03:56 +00:00
|
|
|
ClientIdV1 = "nim-waku v1 node"
|
|
|
|
DefaultTTL = 5'u32
|
|
|
|
DeduplQSize = 20 # Maximum number of seen messages to keep in deduplication queue
|
2021-03-18 10:01:27 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
#########
|
|
|
|
# Types #
|
|
|
|
#########
|
|
|
|
|
|
|
|
type
|
|
|
|
WakuBridge* = ref object of RootObj
|
|
|
|
nodev1*: EthereumNode
|
|
|
|
nodev2*: WakuNode
|
2021-06-17 10:59:28 +00:00
|
|
|
nodev2PubsubTopic: wakunode2.Topic # Pubsub topic to bridge to/from
|
2021-05-20 16:03:56 +00:00
|
|
|
seen: seq[hashes.Hash] # FIFO queue of seen WakuMessages. Used for deduplication.
|
2021-03-22 09:44:45 +00:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Helper funtions #
|
|
|
|
###################
|
|
|
|
|
2021-06-18 10:30:24 +00:00
|
|
|
# Deduplication
|
|
|
|
|
2021-05-20 16:03:56 +00:00
|
|
|
proc containsOrAdd(sequence: var seq[hashes.Hash], hash: hashes.Hash): bool =
|
|
|
|
if sequence.contains(hash):
|
|
|
|
return true
|
|
|
|
|
|
|
|
if sequence.len >= DeduplQSize:
|
|
|
|
trace "Deduplication queue full. Removing oldest item."
|
|
|
|
sequence.delete 0, 0 # Remove first item in queue
|
|
|
|
|
|
|
|
sequence.add(hash)
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
2021-06-18 10:30:24 +00:00
|
|
|
# Topic conversion
|
|
|
|
|
|
|
|
proc toV2ContentTopic*(v1Topic: waku_protocol.Topic): ContentTopic =
|
|
|
|
## Convert a 4-byte array v1 topic to a namespaced content topic
|
2021-08-26 12:24:00 +00:00
|
|
|
## with format `/waku/1/<v1-topic-bytes-as-hex>/rfc26`
|
2021-07-21 12:22:40 +00:00
|
|
|
##
|
|
|
|
## <v1-topic-bytes-as-hex> should be prefixed with `0x`
|
2021-06-18 10:30:24 +00:00
|
|
|
|
|
|
|
var namespacedTopic = NamespacedTopic()
|
|
|
|
|
|
|
|
namespacedTopic.application = "waku"
|
|
|
|
namespacedTopic.version = "1"
|
2021-07-21 12:22:40 +00:00
|
|
|
namespacedTopic.topicName = "0x" & v1Topic.toHex()
|
2021-08-26 12:24:00 +00:00
|
|
|
namespacedTopic.encoding = "rfc26"
|
2021-06-18 10:30:24 +00:00
|
|
|
|
|
|
|
return ContentTopic($namespacedTopic)
|
|
|
|
|
2021-07-16 15:13:36 +00:00
|
|
|
proc toV1Topic*(contentTopic: ContentTopic): waku_protocol.Topic {.raises: [Defect, LPError, ValueError]} =
|
2021-06-18 10:30:24 +00:00
|
|
|
## Extracts the 4-byte array v1 topic from a content topic
|
2021-08-26 12:24:00 +00:00
|
|
|
## with format `/waku/1/<v1-topic-bytes-as-hex>/rfc26`
|
2021-06-18 10:30:24 +00:00
|
|
|
|
|
|
|
hexToByteArray(hexStr = NamespacedTopic.fromString(contentTopic).tryGet().topicName,
|
|
|
|
N = 4) # Byte array length
|
|
|
|
|
|
|
|
# Message conversion
|
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
func toWakuMessage(env: Envelope): WakuMessage =
|
2021-03-18 10:01:27 +00:00
|
|
|
# Translate a Waku v1 envelope to a Waku v2 message
|
|
|
|
WakuMessage(payload: env.data,
|
2021-06-18 10:30:24 +00:00
|
|
|
contentTopic: toV2ContentTopic(env.topic),
|
2021-08-26 12:24:00 +00:00
|
|
|
timestamp: float64(env.expiry - env.ttl),
|
2021-03-18 10:01:27 +00:00
|
|
|
version: 1)
|
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
proc toWakuV2(bridge: WakuBridge, env: Envelope) {.async.} =
|
2021-05-20 16:03:56 +00:00
|
|
|
let msg = env.toWakuMessage()
|
|
|
|
|
|
|
|
if bridge.seen.containsOrAdd(msg.encode().buffer.hash()):
|
|
|
|
# This is a duplicate message. Return
|
|
|
|
trace "Already seen. Dropping.", msg=msg
|
|
|
|
waku_bridge_dropped.inc(labelValues = ["duplicate"])
|
|
|
|
return
|
2021-05-24 11:19:33 +00:00
|
|
|
|
|
|
|
trace "Sending message to V2", msg=msg
|
2021-05-20 16:03:56 +00:00
|
|
|
|
2021-03-23 08:04:51 +00:00
|
|
|
waku_bridge_transfers.inc(labelValues = ["v1_to_v2"])
|
2021-04-08 09:55:19 +00:00
|
|
|
|
2021-06-17 10:59:28 +00:00
|
|
|
await bridge.nodev2.publish(bridge.nodev2PubsubTopic, msg)
|
2021-03-22 09:44:45 +00:00
|
|
|
|
2021-07-16 15:13:36 +00:00
|
|
|
proc toWakuV1(bridge: WakuBridge, msg: WakuMessage) {.gcsafe, raises: [Defect, LPError, ValueError].} =
|
2021-05-20 16:03:56 +00:00
|
|
|
if bridge.seen.containsOrAdd(msg.encode().buffer.hash()):
|
|
|
|
# This is a duplicate message. Return
|
|
|
|
trace "Already seen. Dropping.", msg=msg
|
|
|
|
waku_bridge_dropped.inc(labelValues = ["duplicate"])
|
|
|
|
return
|
|
|
|
|
2021-05-24 11:19:33 +00:00
|
|
|
trace "Sending message to V1", msg=msg
|
|
|
|
|
2021-03-23 08:04:51 +00:00
|
|
|
waku_bridge_transfers.inc(labelValues = ["v2_to_v1"])
|
2021-04-08 09:55:19 +00:00
|
|
|
|
|
|
|
# @TODO: use namespacing to map v2 contentTopics to v1 topics
|
|
|
|
let v1TopicSeq = msg.contentTopic.toBytes()[0..3]
|
2021-08-26 12:24:00 +00:00
|
|
|
|
|
|
|
case msg.version:
|
|
|
|
of 1:
|
|
|
|
discard bridge.nodev1.postEncoded(ttl = DefaultTTL,
|
|
|
|
topic = toV1Topic(msg.contentTopic),
|
|
|
|
encodedPayload = msg.payload) # The payload is already encoded according to https://rfc.vac.dev/spec/26/
|
|
|
|
else:
|
|
|
|
discard bridge.nodev1.postMessage(ttl = DefaultTTL,
|
|
|
|
topic = toV1Topic(msg.contentTopic),
|
|
|
|
payload = msg.payload)
|
2021-03-22 09:44:45 +00:00
|
|
|
|
|
|
|
##############
|
|
|
|
# Public API #
|
|
|
|
##############
|
|
|
|
proc new*(T: type WakuBridge,
|
|
|
|
# NodeV1 initialisation
|
|
|
|
nodev1Key: keys.KeyPair,
|
|
|
|
nodev1Address: Address,
|
|
|
|
powRequirement = 0.002,
|
|
|
|
rng: ref BrHmacDrbgContext,
|
2021-06-17 10:59:28 +00:00
|
|
|
topicInterest = none(seq[waku_protocol.Topic]),
|
|
|
|
bloom = some(fullBloom()),
|
2021-03-22 09:44:45 +00:00
|
|
|
# NodeV2 initialisation
|
|
|
|
nodev2Key: crypto.PrivateKey,
|
|
|
|
nodev2BindIp: ValidIpAddress, nodev2BindPort: Port,
|
2021-06-17 10:59:28 +00:00
|
|
|
nodev2ExtIp = none[ValidIpAddress](), nodev2ExtPort = none[Port](),
|
|
|
|
# Bridge configuration
|
2021-07-16 15:13:36 +00:00
|
|
|
nodev2PubsubTopic: wakunode2.Topic): T
|
2021-11-10 12:05:36 +00:00
|
|
|
{.raises: [Defect,IOError, TLSStreamProtocolError, LPError].} =
|
2021-03-22 09:44:45 +00:00
|
|
|
|
|
|
|
# Setup Waku v1 node
|
|
|
|
var
|
|
|
|
nodev1 = newEthereumNode(keys = nodev1Key, address = nodev1Address,
|
2021-05-20 16:03:56 +00:00
|
|
|
networkId = NetworkId(1), chain = nil, clientId = ClientIdV1,
|
2021-03-22 09:44:45 +00:00
|
|
|
addAllCapabilities = false, rng = rng)
|
|
|
|
|
|
|
|
nodev1.addCapability Waku # Always enable Waku protocol
|
2020-10-21 09:54:29 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
# Setup the Waku configuration.
|
2021-06-17 10:59:28 +00:00
|
|
|
# This node is being set up as a bridge. By default it gets configured as a node with
|
2020-10-21 09:54:29 +00:00
|
|
|
# a full bloom filter so that it will receive and forward all messages.
|
2021-06-17 10:59:28 +00:00
|
|
|
# It is, however, possible to configure a topic interest to bridge only
|
|
|
|
# selected messages.
|
2020-10-21 09:54:29 +00:00
|
|
|
# TODO: What is the PoW setting now?
|
2021-03-22 09:44:45 +00:00
|
|
|
let wakuConfig = WakuConfig(powRequirement: powRequirement,
|
2021-06-17 10:59:28 +00:00
|
|
|
bloom: bloom, isLightNode: false,
|
2021-03-22 09:44:45 +00:00
|
|
|
maxMsgSize: waku_protocol.defaultMaxMsgSize,
|
2021-06-17 10:59:28 +00:00
|
|
|
topics: topicInterest)
|
2021-03-22 09:44:45 +00:00
|
|
|
nodev1.configureWaku(wakuConfig)
|
|
|
|
|
|
|
|
# Setup Waku v2 node
|
|
|
|
let
|
2021-07-14 17:58:46 +00:00
|
|
|
nodev2 = WakuNode.new(nodev2Key,
|
2021-07-16 15:13:36 +00:00
|
|
|
nodev2BindIp, nodev2BindPort,
|
|
|
|
nodev2ExtIp, nodev2ExtPort)
|
2021-03-22 09:44:45 +00:00
|
|
|
|
2021-06-17 10:59:28 +00:00
|
|
|
return WakuBridge(nodev1: nodev1, nodev2: nodev2, nodev2PubsubTopic: nodev2PubsubTopic)
|
2021-03-22 09:44:45 +00:00
|
|
|
|
|
|
|
proc start*(bridge: WakuBridge) {.async.} =
|
|
|
|
info "Starting WakuBridge"
|
|
|
|
|
|
|
|
debug "Start listening on Waku v1"
|
|
|
|
# Start listening on Waku v1 node
|
|
|
|
let connectedFut = bridge.nodev1.connectToNetwork(@[],
|
2020-10-21 09:54:29 +00:00
|
|
|
true, # Always enable listening
|
|
|
|
false # Disable discovery (only discovery v4 is currently supported)
|
|
|
|
)
|
|
|
|
connectedFut.callback = proc(data: pointer) {.gcsafe.} =
|
|
|
|
{.gcsafe.}:
|
|
|
|
if connectedFut.failed:
|
|
|
|
fatal "connectToNetwork failed", msg = connectedFut.readError.msg
|
|
|
|
quit(1)
|
2021-03-22 09:44:45 +00:00
|
|
|
|
|
|
|
# Start Waku v2 node
|
|
|
|
debug "Start listening on Waku v2"
|
|
|
|
await bridge.nodev2.start()
|
|
|
|
|
2021-05-24 11:19:33 +00:00
|
|
|
# Always mount relay for bridge.
|
|
|
|
# `triggerSelf` is false on a `bridge` to avoid duplicates
|
|
|
|
bridge.nodev2.mountRelay(triggerSelf = false)
|
2020-10-21 09:54:29 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
# Bridging
|
|
|
|
# Handle messages on Waku v1 and bridge to Waku v2
|
2021-06-14 12:40:08 +00:00
|
|
|
proc handleEnvReceived(envelope: Envelope) {.gcsafe, raises: [Defect].} =
|
2021-03-22 09:44:45 +00:00
|
|
|
trace "Bridging envelope from V1 to V2", envelope=envelope
|
2021-06-14 12:40:08 +00:00
|
|
|
asyncSpawn bridge.toWakuV2(envelope)
|
2020-10-21 09:54:29 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
bridge.nodev1.registerEnvReceivedHandler(handleEnvReceived)
|
2020-10-21 09:54:29 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
# Handle messages on Waku v2 and bridge to Waku v1
|
|
|
|
proc relayHandler(pubsubTopic: string, data: seq[byte]) {.async, gcsafe.} =
|
|
|
|
let msg = WakuMessage.init(data)
|
|
|
|
if msg.isOk():
|
2021-06-18 10:30:24 +00:00
|
|
|
try:
|
|
|
|
trace "Bridging message from V2 to V1", msg=msg.tryGet()
|
|
|
|
bridge.toWakuV1(msg.tryGet())
|
|
|
|
except ValueError:
|
|
|
|
trace "Failed to convert message to Waku v1. Check content-topic format.", msg=msg
|
|
|
|
waku_bridge_dropped.inc(labelValues = ["value_error"])
|
2021-03-22 09:44:45 +00:00
|
|
|
|
2021-06-17 10:59:28 +00:00
|
|
|
bridge.nodev2.subscribe(bridge.nodev2PubsubTopic, relayHandler)
|
2020-10-21 09:54:29 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
proc stop*(bridge: WakuBridge) {.async.} =
|
|
|
|
await bridge.nodev2.stop()
|
2020-10-21 09:54:29 +00:00
|
|
|
|
2021-07-16 15:13:36 +00:00
|
|
|
{.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
|
2020-10-21 09:54:29 +00:00
|
|
|
when isMainModule:
|
2021-03-23 08:04:51 +00:00
|
|
|
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]
|
|
|
|
|
2021-02-04 08:39:55 +00:00
|
|
|
proc startV2Rpc(node: WakuNode, rpcServer: RpcHttpServer, conf: WakuNodeConf) =
|
|
|
|
installDebugApiHandlers(node, rpcServer)
|
|
|
|
|
|
|
|
# Install enabled API handlers:
|
|
|
|
if conf.relay:
|
|
|
|
let topicCache = newTable[string, seq[WakuMessage]]()
|
|
|
|
installRelayApiHandlers(node, rpcServer, topicCache)
|
|
|
|
|
|
|
|
if conf.filter:
|
|
|
|
let messageCache = newTable[ContentTopic, seq[WakuMessage]]()
|
|
|
|
installFilterApiHandlers(node, rpcServer, messageCache)
|
|
|
|
|
|
|
|
if conf.store:
|
|
|
|
installStoreApiHandlers(node, rpcServer)
|
|
|
|
|
|
|
|
rpcServer.start()
|
|
|
|
|
2020-10-21 09:54:29 +00:00
|
|
|
let
|
|
|
|
rng = keys.newRng()
|
2021-03-22 09:44:45 +00:00
|
|
|
conf = WakuNodeConf.load()
|
|
|
|
|
2020-10-21 09:54:29 +00:00
|
|
|
if conf.logLevel != LogLevel.NONE:
|
|
|
|
setLogLevel(conf.logLevel)
|
2021-03-22 09:44:45 +00:00
|
|
|
|
2021-10-12 11:43:01 +00:00
|
|
|
## `udpPort` is only supplied to satisfy underlying APIs but is not
|
|
|
|
## actually a supported transport.
|
|
|
|
let udpPort = conf.devp2pTcpPort
|
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
# Load address configuration
|
|
|
|
let
|
2021-05-20 16:03:56 +00:00
|
|
|
(nodev1ExtIp, _, _) = setupNat(conf.nat, ClientIdV1,
|
2021-03-22 09:44:45 +00:00
|
|
|
Port(conf.devp2pTcpPort + conf.portsShift),
|
2021-10-12 11:43:01 +00:00
|
|
|
Port(udpPort + conf.portsShift))
|
2021-03-22 09:44:45 +00:00
|
|
|
# TODO: EthereumNode should have a better split of binding address and
|
|
|
|
# external address. Also, can't have different ports as it stands now.
|
|
|
|
nodev1Address = if nodev1ExtIp.isNone():
|
|
|
|
Address(ip: parseIpAddress("0.0.0.0"),
|
|
|
|
tcpPort: Port(conf.devp2pTcpPort + conf.portsShift),
|
2021-10-12 11:43:01 +00:00
|
|
|
udpPort: Port(udpPort + conf.portsShift))
|
2021-03-22 09:44:45 +00:00
|
|
|
else:
|
|
|
|
Address(ip: nodev1ExtIp.get(),
|
|
|
|
tcpPort: Port(conf.devp2pTcpPort + conf.portsShift),
|
2021-10-12 11:43:01 +00:00
|
|
|
udpPort: Port(udpPort + conf.portsShift))
|
2021-03-22 09:44:45 +00:00
|
|
|
(nodev2ExtIp, nodev2ExtPort, _) = setupNat(conf.nat, clientId,
|
|
|
|
Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
|
2021-10-12 11:43:01 +00:00
|
|
|
Port(uint16(udpPort) + conf.portsShift))
|
2021-06-17 10:59:28 +00:00
|
|
|
|
|
|
|
# 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())
|
2021-03-22 09:44:45 +00:00
|
|
|
|
|
|
|
let
|
2021-05-12 10:55:09 +00:00
|
|
|
bridge = WakuBridge.new(nodev1Key = conf.nodekeyV1,
|
2021-03-22 09:44:45 +00:00
|
|
|
nodev1Address = nodev1Address,
|
2021-06-17 10:59:28 +00:00
|
|
|
powRequirement = conf.wakuV1Pow,
|
2021-03-22 09:44:45 +00:00
|
|
|
rng = rng,
|
2021-06-17 10:59:28 +00:00
|
|
|
topicInterest = topicInterest,
|
|
|
|
bloom = bloom,
|
2021-05-12 10:55:09 +00:00
|
|
|
nodev2Key = conf.nodekeyV2,
|
2021-03-22 09:44:45 +00:00
|
|
|
nodev2BindIp = conf.listenAddress, nodev2BindPort = Port(uint16(conf.libp2pTcpPort) + conf.portsShift),
|
2021-06-17 10:59:28 +00:00
|
|
|
nodev2ExtIp = nodev2ExtIp, nodev2ExtPort = nodev2ExtPort,
|
|
|
|
nodev2PubsubTopic = conf.bridgePubsubTopic)
|
2021-03-18 10:01:27 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
waitFor bridge.start()
|
2021-03-18 10:01:27 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
# Now load rest of config
|
|
|
|
# Optionally direct connect nodev1 with a set of nodes
|
2021-05-11 15:07:26 +00:00
|
|
|
|
|
|
|
if conf.staticnodesV1.len > 0: connectToNodes(bridge.nodev1, conf.staticnodesV1)
|
|
|
|
elif conf.fleetV1 == prod: connectToNodes(bridge.nodev1, WhisperNodes)
|
|
|
|
elif conf.fleetV1 == staging: connectToNodes(bridge.nodev1, WhisperNodesStaging)
|
|
|
|
elif conf.fleetV1 == test: connectToNodes(bridge.nodev1, WhisperNodesTest)
|
2021-03-18 10:01:27 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
# Mount configured Waku v2 protocols
|
2021-06-15 08:55:47 +00:00
|
|
|
mountLibp2pPing(bridge.nodev2)
|
2021-06-02 14:54:38 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
if conf.store:
|
2021-05-11 15:07:26 +00:00
|
|
|
mountStore(bridge.nodev2, persistMessages = false) # Bridge does not persist messages
|
2021-03-18 10:01:27 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
if conf.filter:
|
|
|
|
mountFilter(bridge.nodev2)
|
2021-03-18 10:01:27 +00:00
|
|
|
|
2021-05-12 10:55:09 +00:00
|
|
|
if conf.staticnodesV2.len > 0:
|
2021-05-11 15:07:26 +00:00
|
|
|
waitFor connectToNodes(bridge.nodev2, conf.staticnodesV2)
|
2021-03-22 09:44:45 +00:00
|
|
|
|
|
|
|
if conf.storenode != "":
|
|
|
|
setStorePeer(bridge.nodev2, conf.storenode)
|
2020-10-21 09:54:29 +00:00
|
|
|
|
2021-03-22 09:44:45 +00:00
|
|
|
if conf.filternode != "":
|
|
|
|
setFilterPeer(bridge.nodev2, conf.filternode)
|
2020-10-21 09:54:29 +00:00
|
|
|
|
|
|
|
if conf.rpc:
|
|
|
|
let ta = initTAddress(conf.rpcAddress,
|
|
|
|
Port(conf.rpcPort + conf.portsShift))
|
|
|
|
var rpcServer = newRpcHttpServer([ta])
|
|
|
|
# Waku v1 RPC
|
2021-02-04 08:39:55 +00:00
|
|
|
let keys = newKeyStorage()
|
2021-03-22 09:44:45 +00:00
|
|
|
setupWakuRPC(bridge.nodev1, keys, rpcServer, rng)
|
|
|
|
setupWakuSimRPC(bridge.nodev1, rpcServer)
|
2020-10-21 09:54:29 +00:00
|
|
|
# Waku v2 rpc
|
2021-03-22 09:44:45 +00:00
|
|
|
startV2Rpc(bridge.nodev2, rpcServer, conf)
|
2020-10-21 09:54:29 +00:00
|
|
|
|
|
|
|
rpcServer.start()
|
|
|
|
|
2021-06-10 14:18:41 +00:00
|
|
|
if conf.metricsServer:
|
|
|
|
let
|
|
|
|
address = conf.metricsServerAddress
|
|
|
|
port = conf.metricsServerPort + conf.portsShift
|
|
|
|
info "Starting metrics HTTP server", address, port
|
|
|
|
startMetricsHttpServer($address, Port(port))
|
2020-10-21 09:54:29 +00:00
|
|
|
|
|
|
|
runForever()
|