mirror of https://github.com/waku-org/nwaku.git
Change Waku RPC to have access to wakuProto; basic publish rpc
This commit is contained in:
parent
dd4a1615f1
commit
f7b9fc2613
|
@ -1,5 +1,6 @@
|
|||
# NOTE: Taken from v1, only version exists right now
|
||||
proc waku_version(): string
|
||||
proc waku_publish(message: string): bool
|
||||
|
||||
proc waku_info(): WakuInfo
|
||||
proc waku_setMaxMessageSize(size: uint64): bool
|
||||
|
|
|
@ -18,13 +18,26 @@ from stew/byteutils import hexToSeqByte, hexToByteArray
|
|||
# Where is the equivalent in Waku/2?
|
||||
# TODO: Extend to get access to protocol state and keys
|
||||
#proc setupWakuRPC*(node: EthereumNode, keys: KeyStorage, rpcsrv: RpcServer) =
|
||||
proc setupWakuRPC*(rpcsrv: RpcServer) =
|
||||
proc setupWakuRPC*(wakuProto: WakuProto, rpcsrv: RpcServer) =
|
||||
|
||||
# Seems easy enough, lets try to get this first
|
||||
rpcsrv.rpc("waku_version") do() -> string:
|
||||
## Returns string of the current Waku protocol version.
|
||||
result = WakuSubCodec
|
||||
|
||||
# XXX Type
|
||||
# TODO: Implement symkey etc logic
|
||||
rpcsrv.rpc("waku_post") do(message: string) -> bool:
|
||||
let data = cast[seq[byte]](message)
|
||||
# Assumes someone subscribing on this topic
|
||||
#let wakuSub = wakuProto.switch.pubsub
|
||||
let wakuSub = cast[WakuSub](wakuProto.switch.pubSub.get())
|
||||
# XXX also future return type
|
||||
discard wakuSub.publish("foobar", data)
|
||||
return true
|
||||
#if not result:
|
||||
# raise newException(ValueError, "Message could not be posted")
|
||||
|
||||
# TODO: Dial/Connect
|
||||
# XXX: Though wrong layer for that - wait how does this work in devp2p sim?
|
||||
# We connect to nodes there, should be very similar here
|
||||
|
|
|
@ -144,26 +144,6 @@ proc run(config: WakuNodeConf) =
|
|||
|
||||
peerInfo.addrs.add(Multiaddress.init(DefaultAddr))
|
||||
|
||||
# XXX: It isn't clear that it is a good idea use dial/connect as RPC
|
||||
# But let's try it
|
||||
# More of a hello world thing, we'd want to mount it on to of gossipsub
|
||||
if config.rpc:
|
||||
# What is ta? transport address...right.
|
||||
let ta = initTAddress(config.rpcAddress,
|
||||
Port(config.rpcPort + config.portsShift))
|
||||
var rpcServer = newRpcHttpServer([ta])
|
||||
|
||||
# Not using keys right now
|
||||
let keys = newKeyStorage()
|
||||
#setupWakuRPC(node, keys, rpcServer)
|
||||
#setupWakuSimRPC(node, rpcServer)
|
||||
setupWakuRPC(rpcServer)
|
||||
rpcServer.start()
|
||||
|
||||
# TODO: Use it to get waku version
|
||||
# Huh not printed
|
||||
info "rpcServer started", ta=ta
|
||||
|
||||
# TODO: Here setup a libp2p node
|
||||
# Essentially something like this in nbc/eth2_network:
|
||||
# proc createEth2Node*(conf: BeaconNodeConf): Future[Eth2Node]
|
||||
|
@ -179,10 +159,23 @@ proc run(config: WakuNodeConf) =
|
|||
|
||||
# Is it a "Standard" Switch? Assume it is for now
|
||||
# NOTE: This should be WakuSub here
|
||||
|
||||
# XXX: Do we want to use this wakuProto? Or Switch?
|
||||
# We need access to the WakuSub thing
|
||||
# switch.pubsub = wakusub, plus all the peer info etc
|
||||
# And it has wakuProto lets use wakuProto maybe, cause it has switch
|
||||
var switch = newStandardSwitch(some keys.seckey, hostAddress, triggerSelf = true, gossip = false)
|
||||
let wakuProto = newWakuProto(switch)
|
||||
switch.mount(wakuProto)
|
||||
|
||||
if config.rpc:
|
||||
let ta = initTAddress(config.rpcAddress,
|
||||
Port(config.rpcPort + config.portsShift))
|
||||
var rpcServer = newRpcHttpServer([ta])
|
||||
setupWakuRPC(wakuProto, rpcServer)
|
||||
rpcServer.start()
|
||||
info "rpcServer started", ta=ta
|
||||
|
||||
# TODO: Make context async
|
||||
#let fut = await switch.start()
|
||||
discard switch.start()
|
||||
|
|
Loading…
Reference in New Issue