From bc2b76f09abb837bd45b281159de0634bc5f03aa Mon Sep 17 00:00:00 2001 From: kdeme Date: Thu, 21 Nov 2019 11:03:43 +0100 Subject: [PATCH] cleaner solution for sharing the queue --- eth/p2p/rlpx_protocols/waku_protocol.nim | 10 +++++----- tests/p2p/test_waku_bridge.nim | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/eth/p2p/rlpx_protocols/waku_protocol.nim b/eth/p2p/rlpx_protocols/waku_protocol.nim index ff04886..99c88c5 100644 --- a/eth/p2p/rlpx_protocols/waku_protocol.nim +++ b/eth/p2p/rlpx_protocols/waku_protocol.nim @@ -100,11 +100,8 @@ proc run(peer: Peer) {.gcsafe, async.} proc run(node: EthereumNode, network: WakuNetwork) {.gcsafe, async.} proc initProtocolState*(network: WakuNetwork, node: EthereumNode) {.gcsafe.} = - if node.protocolState(Whisper).isNil: - new(network.queue) - network.queue[] = initQueue(defaultQueueCapacity) - else: - network.queue = node.protocolState(Whisper).queue + new(network.queue) + network.queue[] = initQueue(defaultQueueCapacity) network.filters = initTable[string, Filter]() network.config.bloom = fullBloom() network.config.powRequirement = defaultMinPow @@ -466,3 +463,6 @@ proc resetMessageQueue*(node: EthereumNode) = ## ## NOTE: Not something that should be run in normal circumstances. node.protocolState(Waku).queue[] = initQueue(defaultQueueCapacity) + +proc shareMessageQueue*(node: EthereumNode) = + node.protocolState(Waku).queue = node.protocolState(Whisper).queue diff --git a/tests/p2p/test_waku_bridge.nim b/tests/p2p/test_waku_bridge.nim index 4f17c00..ed548ae 100644 --- a/tests/p2p/test_waku_bridge.nim +++ b/tests/p2p/test_waku_bridge.nim @@ -28,6 +28,8 @@ suite "Waku - Whisper bridge tests": nodeWakuWhisper.startListening() let bridgeNode = newNode(initENode(nodeWakuWhisper.keys.pubKey, nodeWakuWhisper.address)) + nodeWakuWhisper.shareMessageQueue() + waitFor nodeWhisper.peerPool.connectToNode(bridgeNode) waitFor nodeWaku.peerPool.connectToNode(bridgeNode)