mirror of https://github.com/status-im/nim-eth.git
Allow light node to send the regular way #131
This commit is contained in:
parent
4dde3af2d5
commit
f3357602e4
|
@ -52,6 +52,7 @@ proc runP2pTests() =
|
|||
"test_shh",
|
||||
"test_shh_config",
|
||||
"test_shh_connect",
|
||||
"test_waku_connect",
|
||||
"test_waku_bridge",
|
||||
"test_waku_mail",
|
||||
"test_waku_mode",
|
||||
|
|
|
@ -227,6 +227,7 @@ p2pProtocol Waku(version = wakuVersion,
|
|||
wakuPeer.trusted = false
|
||||
wakuPeer.initialized = true
|
||||
|
||||
# No timer based queue processing for a light node.
|
||||
if not wakuNet.config.isLightNode:
|
||||
traceAsyncErrors peer.run()
|
||||
|
||||
|
@ -471,7 +472,7 @@ proc postMessage*(node: EthereumNode, pubKey = none[PublicKey](),
|
|||
# Allow lightnode to post only direct p2p messages
|
||||
if targetPeer.isSome():
|
||||
return node.sendP2PMessage(targetPeer.get(), [env])
|
||||
elif not node.protocolState(Waku).config.isLightNode:
|
||||
else:
|
||||
# non direct p2p message can not have ttl of 0
|
||||
if env.ttl == 0:
|
||||
return false
|
||||
|
@ -490,10 +491,19 @@ proc postMessage*(node: EthereumNode, pubKey = none[PublicKey](),
|
|||
if not msg.env.valid():
|
||||
return false
|
||||
|
||||
return node.queueMessage(msg)
|
||||
else:
|
||||
warn "Light node not allowed to post messages"
|
||||
return false
|
||||
result = node.queueMessage(msg)
|
||||
|
||||
# Allows light nodes to post via untrusted messages packet.
|
||||
# Queue gets processed immediatly as the node sends only its own messages,
|
||||
# so the privacy ship has already sailed anyhow.
|
||||
# TODO:
|
||||
# - Could be still a concern in terms of efficiency, if multiple messages
|
||||
# need to be send.
|
||||
# - For Waku Mode, the checks in processQueue are rather useless as the
|
||||
# idea is to connect only to 1 node? Also refactor in that case.
|
||||
if node.protocolState(Waku).config.isLightNode:
|
||||
for peer in node.peers(Waku):
|
||||
peer.processQueue()
|
||||
else:
|
||||
error "Encoding of payload failed"
|
||||
return false
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
#
|
||||
# Waku
|
||||
# (c) Copyright 2019
|
||||
# Status Research & Development GmbH
|
||||
#
|
||||
# Licensed under either of
|
||||
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
||||
# MIT license (LICENSE-MIT)
|
||||
|
||||
import
|
||||
sequtils, tables, unittest, chronos, eth/[keys, p2p],
|
||||
eth/p2p/rlpx_protocols/waku_protocol, eth/p2p/peer_pool,
|
||||
./p2p_test_helper
|
||||
|
||||
const safeTTL = 5'u32
|
||||
|
||||
# TODO: Just repeat all the test_shh_connect tests here that are applicable or
|
||||
# have some commonly shared test code for both protocols.
|
||||
suite "Waku connections":
|
||||
asyncTest "Light node posting":
|
||||
var ln = setupTestNode(Waku)
|
||||
ln.setLightNode(true)
|
||||
var fn = setupTestNode(Waku)
|
||||
fn.startListening()
|
||||
await ln.peerPool.connectToNode(newNode(initENode(fn.keys.pubKey,
|
||||
fn.address)))
|
||||
|
||||
let topic = [byte 0, 0, 0, 0]
|
||||
|
||||
check:
|
||||
ln.peerPool.connectedNodes.len() == 1
|
||||
# normal post
|
||||
ln.postMessage(ttl = safeTTL, topic = topic,
|
||||
payload = repeat(byte 0, 10)) == true
|
||||
ln.protocolState(Waku).queue.items.len == 1
|
||||
# TODO: add test on message relaying
|
Loading…
Reference in New Issue