mirror of https://github.com/waku-org/nwaku.git
feature/filter-rpc-script (#200)
* started working * fixes * added tutorial * added * rm from description
This commit is contained in:
parent
7a3e18d4b0
commit
9ac41b2eda
|
@ -0,0 +1,33 @@
|
|||
# Running Filter Protocol
|
||||
|
||||
## How to
|
||||
|
||||
Build:
|
||||
|
||||
```
|
||||
# make wakunode2 is run as part of scripts2 target
|
||||
make scripts2
|
||||
```
|
||||
|
||||
Run two nodes and connect them:
|
||||
|
||||
```
|
||||
# Starts listening on 60000 with RPC server on 8545.
|
||||
# Note the "listening on address" in logs.
|
||||
./build/wakunode2 --ports-shift:0
|
||||
|
||||
# Run another node with staticnode argument
|
||||
./build/wakunode2 --ports-shift:1 --staticnode:/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmF4tuht6fmna6uDqoSMgFqhUrdaVR6VQRyGr6sCpfS2jp --filternode:/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmF4tuht6fmna6uDqoSMgFqhUrdaVR6VQRyGr6sCpfS2jp
|
||||
```
|
||||
|
||||
You should see your nodes connecting.
|
||||
|
||||
Do basic RPC calls:
|
||||
|
||||
```
|
||||
./build/rpc_subscribe 8545
|
||||
./build/rpc_subscribe_filter 8546 # enter your topic default is "foobar"
|
||||
./build/rpc_publish 8545 # enter your message in STDIN
|
||||
```
|
||||
|
||||
You should see other node receive something.
|
|
@ -72,6 +72,7 @@ task test2, "Build & run Waku v2 tests":
|
|||
task scripts2, "Build Waku v2 scripts":
|
||||
buildBinary "rpc_publish", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG"
|
||||
buildBinary "rpc_subscribe", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG"
|
||||
buildBinary "rpc_subscribe_filter", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG"
|
||||
buildBinary "rpc_query", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG"
|
||||
buildBinary "rpc_info", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG"
|
||||
|
||||
|
|
|
@ -73,6 +73,11 @@ type
|
|||
defaultValue: ""
|
||||
name: "storenode" }: string
|
||||
|
||||
filternode* {.
|
||||
desc: "Enode URL to filter.",
|
||||
defaultValue: ""
|
||||
name: "filternode" }: string
|
||||
|
||||
whisper* {.
|
||||
desc: "Enable the Whisper protocol."
|
||||
defaultValue: false
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import
|
||||
os, strutils, strformat, chronicles, json_rpc/[rpcclient, rpcserver], nimcrypto/sysrand,
|
||||
libp2p/protobuf/minprotobuf,
|
||||
libp2p/[peerinfo, multiaddress],
|
||||
eth/common as eth_common, eth/keys,
|
||||
system,
|
||||
options
|
||||
|
||||
from strutils import rsplit
|
||||
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
|
||||
|
||||
const sigWakuPath = sourceDir / "wakucallsigs.nim"
|
||||
createRpcSigs(RpcHttpClient, sigWakuPath)
|
||||
|
||||
if paramCount() < 1:
|
||||
echo "Please provide rpcPort as argument."
|
||||
quit(1)
|
||||
|
||||
let rpcPort = Port(parseInt(paramStr(1)))
|
||||
|
||||
echo "Please enter your topic:"
|
||||
let raw_input = readLine(stdin)
|
||||
let input = fmt"{raw_input}"
|
||||
echo "Input is:", input
|
||||
|
||||
var node = newRpcHttpClient()
|
||||
waitfor node.connect("localhost", rpcPort)
|
||||
|
||||
let pubSubTopic = "waku"
|
||||
let contentTopic = "foobar"
|
||||
var res = waitfor node.wakuSubscribeFilter(pubSubTopic, @[@[contentTopic]])
|
||||
echo "Waku query response: ", res
|
|
@ -249,6 +249,13 @@ when isMainModule:
|
|||
|
||||
n.wakuStore.setPeer(remotePeer)
|
||||
|
||||
proc setFilterPeer(n: WakuNode, address: string) =
|
||||
info "dialPeer", address = address
|
||||
|
||||
let remotePeer = parsePeerInfo(address)
|
||||
|
||||
n.wakuFilter.setPeer(remotePeer)
|
||||
|
||||
proc connectToNodes(n: WakuNode, nodes: openArray[string]) =
|
||||
for nodeId in nodes:
|
||||
info "connectToNodes", node = nodeId
|
||||
|
@ -298,6 +305,9 @@ when isMainModule:
|
|||
if conf.storenode != "":
|
||||
setStorePeer(node, conf.storenode)
|
||||
|
||||
if conf.filternode != "":
|
||||
setFilterPeer(node, conf.filternode)
|
||||
|
||||
if conf.rpc:
|
||||
startRpc(node, conf.rpcAddress, Port(conf.rpcPort + conf.portsShift))
|
||||
|
||||
|
|
Loading…
Reference in New Issue