feature/rpc-query (#186)

* started working on rpc query

* rpc

* fixes

* setup

* made it work

* update

* Create store.md

* Update nangang.md
This commit is contained in:
Dean Eigenmann 2020-09-25 13:35:32 +02:00 committed by GitHub
parent 29706734a8
commit bcc931baf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 5 deletions

34
docs/tutorial/store.md Normal file
View File

@ -0,0 +1,34 @@
# Running Store 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 --storenode:/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 8546
./build/rpc_publish 8545 # enter your message in STDIN
./build/rpc_query 8546 # enter your topic default is "foobar"
```
You should see other node receive something.

View File

@ -71,6 +71,7 @@ task wakusim2, "Build Experimental Waku simulation tools":
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_query", "waku/node/v2/rpc/", "-d:chronicles_log_level=DEBUG"
task wakuexample2, "Build example Waku usage":
let name = "basic2"

View File

@ -68,6 +68,11 @@ type
desc: "Enode URL to directly connect with. Argument may be repeated."
name: "staticnode" }: seq[string]
storenode* {.
desc: "Enode URL to query for storage.",
defaultValue: ""
name: "storenode" }: string
whisper* {.
desc: "Enable the Whisper protocol."
defaultValue: false

View File

@ -0,0 +1,30 @@
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)
var res = waitfor node.wakuQuery("foo", @[input])
echo "Waku query response: ", res

View File

@ -199,15 +199,17 @@ when isMainModule:
confutils, json_rpc/rpcserver, metrics,
./config, ./rpc/wakurpc, ../common
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 multiAddr = MultiAddress.initAddress(address)
info "multiAddr", ma = multiAddr
let parts = address.split("/")
let remotePeer = PeerInfo.init(parts[^1], [multiAddr])
let remotePeer = parsePeerInfo(address)
info "Dialing peer", multiAddr
info "Dialing peer", ma = remotePeer.addrs[0]
# 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)
@ -215,6 +217,13 @@ when isMainModule:
discard n.switch.dial(remotePeer, WakuRelayCodec)
info "Post switch dial"
proc setStorePeer(n: WakuNode, address: string) =
info "dialPeer", address = address
let remotePeer = parsePeerInfo(address)
n.wakuStore.setPeer(remotePeer)
proc connectToNodes(n: WakuNode, nodes: openArray[string]) =
for nodeId in nodes:
info "connectToNodes", node = nodeId
@ -261,6 +270,9 @@ when isMainModule:
if conf.staticnodes.len > 0:
connectToNodes(node, conf.staticnodes)
if conf.storenode != "":
setStorePeer(node, conf.storenode)
if conf.rpc:
startRpc(node, conf.rpcAddress, Port(conf.rpcPort + conf.portsShift))