From b943948a5f9721b01023b2189a88177d87256d49 Mon Sep 17 00:00:00 2001 From: jm-clius Date: Thu, 18 Mar 2021 10:24:42 +0000 Subject: [PATCH] deploy: 4ae1cd4737dacdd30f879eea199e0a89a9c1532e --- .update.timestamp | 2 +- .../vendor/libbacktrace-upstream/libtool | 2 +- waku/common/wakubridge.nim | 47 +++++++++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/.update.timestamp b/.update.timestamp index 61c9b4eda..113ff9e39 100644 --- a/.update.timestamp +++ b/.update.timestamp @@ -1 +1 @@ -1615974546 \ No newline at end of file +1616061687 \ No newline at end of file diff --git a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool index f5085af2c..d0be4ed9a 100755 --- a/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool +++ b/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/libtool @@ -2,7 +2,7 @@ # libtool - Provide generalized library-building support services. # Generated automatically by config.status (libbacktrace) version-unused -# Libtool was configured on host fv-az132-27: +# Libtool was configured on host fv-az196-102: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, diff --git a/waku/common/wakubridge.nim b/waku/common/wakubridge.nim index a97ca5d4a..037239e7e 100644 --- a/waku/common/wakubridge.nim +++ b/waku/common/wakubridge.nim @@ -1,6 +1,7 @@ import std/[strutils, tables], chronos, confutils, chronicles, chronicles/topics_registry, metrics, + stew/endians2, stew/shims/net as stewNet, json_rpc/rpcserver, # Waku v1 imports eth/[keys, p2p], eth/common/utils, @@ -22,7 +23,24 @@ import # Common cli config ./config_bridge -const clientIdV1 = "nim-waku v1 node" +const + clientIdV1 = "nim-waku v1 node" + defaultBridgeTopic = "/waku/2/default-bridge/proto" + defaultTTL = 5'u32 + +proc toWakuMessage(env: Envelope): WakuMessage = + # Translate a Waku v1 envelope to a Waku v2 message + WakuMessage(payload: env.data, + contentTopic: ContentTopic(uint32.fromBytes(env.topic)), + version: 1) + +proc toWakuV2(env: Envelope, nodev2: WakuNode) {.async.} = + await nodev2.publish(defaultBridgeTopic, env.toWakuMessage()) + +proc toWakuV1(msg: WakuMessage, nodev1: EthereumNode) {.gcsafe.} = + discard nodev1.postMessage(ttl = defaultTTL, + topic = msg.contentTopic.toBytes(), + payload = msg.payload) proc startWakuV1(config: WakuNodeConf, rng: ref BrHmacDrbgContext): EthereumNode = @@ -127,10 +145,31 @@ when isMainModule: if conf.logLevel != LogLevel.NONE: setLogLevel(conf.logLevel) + + var + nodev1 {.threadvar.}: EthereumNode + nodev2 {.threadvar.}: WakuNode + + nodev1 = startWakuV1(conf, rng) + nodev2 = waitFor startWakuV2(conf) + + + # Handle messages on Waku v1 and bridge to Waku v2 + proc handleEnvReceived(envelope: Envelope) {.gcsafe.} = + debug "Bridging envelope from V1 to V2", envelope=envelope + waitFor envelope.toWakuV2(nodev2) + + nodev1.registerEnvReceivedHandler(handleEnvReceived) + + # 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(): + debug "Bridging message from V2 to V1", msg=msg[] + msg[].toWakuV1(nodev1) + + nodev2.subscribe(defaultBridgeTopic, relayHandler) - let - nodev1 = startWakuV1(conf, rng) - nodev2 = waitFor startWakuV2(conf) if conf.rpc: let ta = initTAddress(conf.rpcAddress,