Add simple example and readme

This commit is contained in:
kdeme 2019-12-17 00:41:20 +01:00 committed by zah
parent 7a7075eea6
commit bcaf6d03ee
3 changed files with 82 additions and 1 deletions

View File

@ -40,5 +40,6 @@ task test, "Run tests":
task nimbus, "Build Nimbus":
buildBinary "nimbus", "nimbus/", "-d:chronicles_log_level=TRACE"
task wakunode, "Build Nimbus":
task wakunode, "Build Waku":
buildBinary "wakunode", "waku/", "-d:chronicles_log_level=TRACE"
buildBinary "quicksim", "waku/", "-d:chronicles_log_level=TRACE"

35
waku/README.md Normal file
View File

@ -0,0 +1,35 @@
# Introduction
`wakunode` is a cli application that allows you to run a
[Waku](https://github.com/vacp2p/specs/blob/master/waku.md) enabled node.
The application and Waku specification are still experimental and fully in flux.
Additionally the original Whisper (EIP-627) protocol can also be enabled as can
an experimental Whisper - Waku bridging option.
# How to Build & Run
```bash
make wakunode
./build/wakunode --help
```
# Testing Waku Protocol
One can set up several nodes, get them connected and then instruct them via the
JSON-RPC interface. This can be done via e.g. web3.js, nim-web3 (needs to be
updated) or simply curl your way out.
The JSON-RPC interface is currently the same as the one of Whisper. The only
difference is the addition of broadcasting the topics interest when a filter
with a certain set of topics is subcribed.
Example of a quick test with nim-web3:
```
./build/wakunode --log-level:DEBUG --bootnode-only --nodekey:5dc5381cae54ba3174dc0d46040fe11614d0cc94d41185922585198b4fcef9d3
./build/wakunode --log-level:DEBUG --bootnodes:enode://e5fd642a0f630bbb1e4cd7df629d7b8b019457a9a74f983c0484a045cebb176def86a54185b50bbba6bbf97779173695e92835d63109c23471e6da382f922fdb@0.0.0.0:30303 --rpc --ports-shift:1 --waku-mode:WakuSan
./build/wakunode --log-level:DEBUG --bootnodes:enode://e5fd642a0f630bbb1e4cd7df629d7b8b019457a9a74f983c0484a045cebb176def86a54185b50bbba6bbf97779173695e92835d63109c23471e6da382f922fdb@0.0.0.0:30303 --rpc --ports-shift:2 --waku-mode:WakuChan
./build/quicksim
```

45
waku/quicksim.nim Normal file
View File

@ -0,0 +1,45 @@
import
strformat, chronicles, json_rpc/[rpcclient, rpcserver],
eth/common as eth_common, eth/keys, eth/p2p/rlpx_protocols/waku_protocol,
../nimbus/rpc/[hexstrings, rpc_types, waku],
options as what # TODO: Huh?
from os import DirSep
from strutils import rsplit
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
# TODO: move this to rpc folder? Or just directly to nim-web3 and import that?
const sigPath = &"{sourceDir}{DirSep}..{DirSep}tests{DirSep}rpcclient{DirSep}ethcallsigs.nim"
createRpcSigs(RpcHttpClient, sigPath)
let
bob = newRpcHttpClient()
alice = newRpcHttpClient()
waitFor bob.connect("localhost", Port(8546))
waitFor alice.connect("localhost", Port(8547))
let symKey = "0x0000000000000000000000000000000000000000000000000000000000000001"
let
topic = "0x12345678".toTopic()
symKeyID = waitFor alice.shh_addSymKey(symKey)
options = WhisperFilterOptions(symKeyID: some(symKeyID),
topics: some(@[topic]))
filterID = waitFor alice.shh_newMessageFilter(options)
let
symkeyID2 = waitFor bob.shh_addSymKey(symKey)
message = WhisperPostMessage(symKeyID: some(symkeyID2),
ttl: 30,
topic: some(topic),
payload: "0x45879632".HexDataStr,
powTime: 1.0,
powTarget: 0.002)
discard waitFor bob.shh_post(message)
var messages: seq[WhisperFilterMessage]
while messages.len == 0:
messages = waitFor alice.shh_getFilterMessages(filterID)
waitFor sleepAsync(100.milliseconds)
debug "Received message", payload = messages[0].payload