deploy: ed979a7d60d77e42f0d5480cc380b248918a7ebe

This commit is contained in:
jm-clius 2021-01-25 11:17:10 +00:00
parent 2e84315f87
commit fbf6bf4af8
7 changed files with 108 additions and 47 deletions

View File

@ -10,21 +10,18 @@ import confutils, chronicles, chronos, stew/shims/net as stewNet,
nimcrypto/pbkdf2
import libp2p/[switch, # manage transports, a single entry point for dialing and listening
crypto/crypto, # cryptographic functions
protocols/identify, # identify the peer info of a peer
stream/connection, # create and close stream read / write connections
transports/tcptransport, # listen and dial to other peers using client-server protocol
multiaddress, # encode different addressing schemes. For example, /ip4/7.7.7.7/tcp/6543 means it is using IPv4 protocol and TCP
peerinfo, # manage the information of a peer, such as peer ID and public / private key
peerid, # Implement how peers interact
protocols/protocol, # define the protocol base type
protocols/secure/secure, # define the protocol of secure connection
protocols/secure/secio, # define the protocol of secure input / output, allows encrypted communication that uses public keys to validate signed messages instead of a certificate authority like in TLS
muxers/muxer, # define an interface for stream multiplexing, allowing peers to offer many protocols over a single connection
muxers/mplex/mplex] # define some contants and message types for stream multiplexing
muxers/muxer] # define an interface for stream multiplexing, allowing peers to offer many protocols over a single connection
import ../../waku/v2/node/[config, wakunode2, waku_payload],
../../waku/v2/protocol/[waku_relay, waku_message],
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store/waku_store,
../../waku/v2/protocol/waku_filter/waku_filter,
../../waku/v2/utils/peers,
../../waku/common/utils/nat
const Help = """
@ -68,19 +65,6 @@ proc generateSymKey(contentTopic: ContentTopic): SymKey =
let DefaultSymKey = generateSymKey(DefaultContentTopic)
proc initAddress(T: type MultiAddress, str: string): T =
let address = MultiAddress.init(str).tryGet()
if IPFS.match(address) and matchPartial(multiaddress.TCP, address):
result = address
else:
raise newException(ValueError,
"Invalid bootstrap node multi-address")
proc parsePeer(address: string): PeerInfo =
let multiAddr = MultiAddress.initAddress(address)
let parts = address.split("/")
result = PeerInfo.init(parts[^1], [multiAddr])
proc connectToNodes(c: Chat, nodes: seq[string]) {.async.} =
echo "Connecting to nodes"
await c.node.connectToNodes(nodes)
@ -211,7 +195,7 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
if conf.storenode != "":
node.mountStore()
node.wakuStore.setPeer(parsePeer(conf.storenode))
node.wakuStore.setPeer(parsePeerInfo(conf.storenode))
proc storeHandler(response: HistoryResponse) {.gcsafe.} =
for msg in response.messages:
@ -224,7 +208,7 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
if conf.filternode != "":
node.mountFilter()
node.wakuFilter.setPeer(parsePeer(conf.filternode))
node.wakuFilter.setPeer(parsePeerInfo(conf.filternode))
proc filterHandler(msg: WakuMessage) {.gcsafe.} =
let payload = string.fromBytes(msg.payload)

View File

@ -5,11 +5,14 @@ import
chronicles, chronos, stew/shims/net as stewNet, stew/byteutils,
libp2p/crypto/crypto,
libp2p/crypto/secp,
libp2p/peerid,
libp2p/multiaddress,
libp2p/switch,
eth/keys,
../../waku/v2/protocol/[waku_relay, waku_message, message_notifier],
../../waku/v2/protocol/waku_store/waku_store,
../../waku/v2/protocol/waku_filter/waku_filter,
../../waku/v2/utils/peers,
../../waku/v2/node/wakunode2,
../test_helpers
@ -251,3 +254,42 @@ procSuite "WakuNode":
await node1.stop()
await node2.stop()
await node3.stop()
asyncTest "Peer info parses correctly":
## This is such an important utility function for wakunode2
## that it deserves its own test :)
# First test the `happy path` expected case
let
addrStr = "/ip4/127.0.0.1/tcp/60002/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
peerInfo = parsePeerInfo(addrStr)
check:
$(peerInfo.peerId) == "16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"
$(peerInfo.addrs[0][0].tryGet()) == "/ip4/127.0.0.1"
$(peerInfo.addrs[0][1].tryGet()) == "/tcp/60002"
# Now test some common corner cases
expect ValueError:
# gibberish
discard parsePeerInfo("/p2p/$UCH GIBBER!SH")
expect ValueError:
# leading whitespace
discard parsePeerInfo(" /ip4/127.0.0.1/tcp/60002/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc")
expect ValueError:
# trailing whitespace
discard parsePeerInfo("/ip4/127.0.0.1/tcp/60002/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc ")
expect ValueError:
# invalid IP address
discard parsePeerInfo("/ip4/127.0.0.0.1/tcp/60002/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc")
expect ValueError:
# no PeerID
discard parsePeerInfo("/ip4/127.0.0.1/tcp/60002")
expect ValueError:
# unsupported transport
discard parsePeerInfo("/ip4/127.0.0.1/udp/60002/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc")

View File

@ -10,7 +10,7 @@ generated by GNU Autoconf 2.69. Invocation command line was
## Platform. ##
## --------- ##
hostname = fv-az16-906
hostname = fv-az54-27
uname -m = x86_64
uname -r = 5.4.0-1032-azure
uname -s = Linux
@ -841,7 +841,7 @@ configure:12482: $? = 0
configure:12482: result: yes
configure:12499: checking for getexecname
configure:12499: gcc -o conftest -g -O3 -std=gnu11 -pipe -Wall -Wextra -fPIC conftest.c >&5
/tmp/ccVHmrIL.o: In function `main':
/tmp/ccjOQuB3.o: In function `main':
/home/runner/work/nim-waku/nim-waku/vendor/nim-libbacktrace/vendor/libbacktrace-upstream/conftest.c:73: undefined reference to `getexecname'
collect2: error: ld returned 1 exit status
configure:12499: $? = 1
@ -1134,7 +1134,7 @@ generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_COMMANDS =
$ ./config.status
on fv-az16-906
on fv-az54-27
config.status:1150: creating Makefile
config.status:1150: creating backtrace-supported.h

View File

@ -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-az16-906:
# Libtool was configured on host fv-az54-27:
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
#
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,

View File

@ -2,17 +2,24 @@ import
os, strutils, chronicles, json_rpc/[rpcclient, rpcserver],
libp2p/protobuf/minprotobuf,
eth/common as eth_common, eth/keys,
options
../protocol/waku_filter/waku_filter_types,
../protocol/waku_store/waku_store_types,
../protocol/waku_message,
./wakunode2, ./waku_payload,
./jsonrpc/[jsonrpc_types,jsonrpc_utils],
std/options
#options as what # TODO: Huh? Redefinition?
from strutils import rsplit
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
const sigWakuPath = sourceDir / "rpc" / "wakucallsigs.nim"
const sigWakuPath = sourceDir / "jsonrpc" / "jsonrpc_callsigs.nim"
createRpcSigs(RpcHttpClient, sigWakuPath)
const defaultTopic = "/waku/2/default-waku/proto"
const defaultContentTopic = ContentTopic(1)
const topicAmount = 10 #100
proc message(i: int): ProtoBuffer =
@ -33,7 +40,7 @@ for i in 0..<amount:
var node = newRpcHttpClient()
nodes.add(node)
waitFor nodes[i].connect("localhost", Port(8547+i))
var res = waitFor nodes[i].wakuSubscribe(defaultTopic)
var res = waitFor nodes[i].post_waku_v2_relay_v1_subscriptions(@[defaultTopic])
os.sleep(2000)
@ -49,11 +56,11 @@ os.sleep(2000)
for i in 0..<topicAmount:
os.sleep(50)
# TODO: This would then publish on a subtopic here
var res3 = waitFor nodes[0].wakuPublish(defaultTopic, message(0).buffer)
res3 = waitFor nodes[1].wakuPublish(defaultTopic, message(1).buffer)
res3 = waitFor nodes[2].wakuPublish(defaultTopic, message(2).buffer)
res3 = waitFor nodes[3].wakuPublish(defaultTopic, message(3).buffer)
res3 = waitFor nodes[4].wakuPublish(defaultTopic, message(4).buffer)
var res3 = waitFor nodes[0].post_waku_v2_relay_v1_message(defaultTopic, WakuRelayMessage(payload: message(0).buffer, contentTopic: some(defaultContentTopic)))
res3 = waitFor nodes[1].post_waku_v2_relay_v1_message(defaultTopic, WakuRelayMessage(payload: message(1).buffer, contentTopic: some(defaultContentTopic)))
res3 = waitFor nodes[2].post_waku_v2_relay_v1_message(defaultTopic, WakuRelayMessage(payload: message(2).buffer, contentTopic: some(defaultContentTopic)))
res3 = waitFor nodes[3].post_waku_v2_relay_v1_message(defaultTopic, WakuRelayMessage(payload: message(3).buffer, contentTopic: some(defaultContentTopic)))
res3 = waitFor nodes[4].post_waku_v2_relay_v1_message(defaultTopic, WakuRelayMessage(payload: message(4).buffer, contentTopic: some(defaultContentTopic)))
# Scenario xx2 - 14 full nodes, two edge nodes
# Assume one full topic

View File

@ -14,6 +14,7 @@ import
../protocol/waku_store/waku_store,
../protocol/waku_swap/waku_swap,
../protocol/waku_filter/waku_filter,
../utils/peers,
./message_store/message_store,
../utils/requests
@ -61,14 +62,6 @@ type
func asEthKey*(key: PrivateKey): keys.PrivateKey =
keys.PrivateKey(key.skkey)
proc initAddress(T: type MultiAddress, str: string): T =
let address = MultiAddress.init(str).tryGet()
if IPFS.match(address) and matchPartial(multiaddress.TCP, address):
result = address
else:
raise newException(ValueError,
"Invalid bootstrap node multi-address")
proc removeContentFilters(filters: var Filters, contentFilters: seq[ContentFilter]) {.gcsafe.} =
# Flatten all unsubscribe topics into single seq
var unsubscribeTopics: seq[ContentTopic]
@ -336,17 +329,12 @@ proc mountRelay*(node: WakuNode, topics: seq[string] = newSeq[string](), rlnRela
discard node.subscribe(topic, handler)
## Helpers
proc parsePeerInfo(address: string): PeerInfo =
let multiAddr = MultiAddress.initAddress(address)
let parts = address.split("/")
return PeerInfo.init(parts[^1], [multiAddr])
proc dialPeer*(n: WakuNode, address: string) {.async.} =
info "dialPeer", address = address
# XXX: This turns ipfs into p2p, not quite sure why
let remotePeer = parsePeerInfo(address)
info "Dialing peer", ma = remotePeer.addrs[0]
info "Dialing peer", wireAddr = remotePeer.addrs[0], peerId = remotePeer.peerId
# NOTE This is dialing on WakuRelay protocol specifically
# TODO Keep track of conn and connected state somewhere (WakuRelay?)
#p.conn = await p.switch.dial(remotePeer, WakuRelayCodec)

40
waku/v2/utils/peers.nim Normal file
View File

@ -0,0 +1,40 @@
# Collection of utilities related to Waku peers
import
std/strutils,
libp2p/multiaddress,
libp2p/peerinfo
proc initAddress(T: type MultiAddress, str: string): T =
let address = MultiAddress.init(str).tryGet()
if IPFS.match(address) and matchPartial(multiaddress.TCP, address):
result = address
else:
raise newException(ValueError,
"Invalid bootstrap node multi-address")
## Parses a fully qualified peer multiaddr, in the
## format `(ip4|ip6)/tcp/p2p`, into dialable PeerInfo
proc parsePeerInfo*(address: string): PeerInfo =
let multiAddr = MultiAddress.initAddress(address)
var
ipPart, tcpPart, p2pPart: MultiAddress
for addrPart in multiAddr.items():
case addrPart[].protoName()[]
of "ip4", "ip6":
ipPart = addrPart.tryGet()
of "tcp":
tcpPart = addrPart.tryGet()
of "p2p":
p2pPart = addrPart.tryGet()
# nim-libp2p dialing requires remote peers to be initialised with a peerId and a wire address
let
peerIdStr = p2pPart.toString()[].split("/")[^1]
wireAddr = ipPart & tcpPart
if (not wireAddr.isWire()):
raise newException(ValueError, "Invalid node multi-address")
return PeerInfo.init(peerIdStr, [wireAddr])