Allow light node to send the regular way #131

This commit is contained in:
kdeme 2019-12-20 11:56:12 +01:00
parent 4dde3af2d5
commit f3357602e4
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
3 changed files with 52 additions and 5 deletions

View File

@ -52,6 +52,7 @@ proc runP2pTests() =
"test_shh", "test_shh",
"test_shh_config", "test_shh_config",
"test_shh_connect", "test_shh_connect",
"test_waku_connect",
"test_waku_bridge", "test_waku_bridge",
"test_waku_mail", "test_waku_mail",
"test_waku_mode", "test_waku_mode",

View File

@ -227,6 +227,7 @@ p2pProtocol Waku(version = wakuVersion,
wakuPeer.trusted = false wakuPeer.trusted = false
wakuPeer.initialized = true wakuPeer.initialized = true
# No timer based queue processing for a light node.
if not wakuNet.config.isLightNode: if not wakuNet.config.isLightNode:
traceAsyncErrors peer.run() traceAsyncErrors peer.run()
@ -471,7 +472,7 @@ proc postMessage*(node: EthereumNode, pubKey = none[PublicKey](),
# Allow lightnode to post only direct p2p messages # Allow lightnode to post only direct p2p messages
if targetPeer.isSome(): if targetPeer.isSome():
return node.sendP2PMessage(targetPeer.get(), [env]) return node.sendP2PMessage(targetPeer.get(), [env])
elif not node.protocolState(Waku).config.isLightNode: else:
# non direct p2p message can not have ttl of 0 # non direct p2p message can not have ttl of 0
if env.ttl == 0: if env.ttl == 0:
return false return false
@ -490,10 +491,19 @@ proc postMessage*(node: EthereumNode, pubKey = none[PublicKey](),
if not msg.env.valid(): if not msg.env.valid():
return false return false
return node.queueMessage(msg) result = node.queueMessage(msg)
else:
warn "Light node not allowed to post messages" # Allows light nodes to post via untrusted messages packet.
return false # 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: else:
error "Encoding of payload failed" error "Encoding of payload failed"
return false return false

View File

@ -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