mirror of https://github.com/waku-org/nwaku.git
Subscribe RPC and quicksim WIP; hacky in-line handler
This commit is contained in:
parent
bcf6ec95ed
commit
97d3119c33
|
@ -34,7 +34,11 @@ waitFor node2.connect("localhost", Port(8548))
|
||||||
|
|
||||||
let version = waitFor node1.wakuVersion()
|
let version = waitFor node1.wakuVersion()
|
||||||
|
|
||||||
let res = waitFor node1.wakuPost("hello world")
|
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
||||||
|
debug "Hit handler", topic=topic, data=data
|
||||||
|
|
||||||
|
# TODO: Implement handler logic
|
||||||
|
let res1 = waitFor node2.wakuSubscribe("foobar")
|
||||||
let res2 = waitFor node1.wakuPublish("foobar", "hello world")
|
let res2 = waitFor node1.wakuPublish("foobar", "hello world")
|
||||||
|
|
||||||
info "Version is", version
|
info "Version is", version
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# Alpha - Currently implemented in v2
|
# Alpha - Currently implemented in v2
|
||||||
proc waku_version(): string
|
proc waku_version(): string
|
||||||
proc waku_publish(topic: string, message: string): bool
|
proc waku_publish(topic: string, message: string): bool
|
||||||
|
proc waku_subscribe(topic: string): bool
|
||||||
|
#proc waku_subscribe(topic: string, handler: Topichandler): bool
|
||||||
|
|
||||||
# NYI
|
# NYI
|
||||||
proc waku_info(): WakuInfo
|
proc waku_info(): WakuInfo
|
||||||
|
|
|
@ -4,7 +4,8 @@ import
|
||||||
../../../protocol/v2/waku_protocol,
|
../../../protocol/v2/waku_protocol,
|
||||||
nimcrypto/[sysrand, hmac, sha2, pbkdf2],
|
nimcrypto/[sysrand, hmac, sha2, pbkdf2],
|
||||||
../../v1/rpc/[rpc_types, hexstrings, key_storage],
|
../../v1/rpc/[rpc_types, hexstrings, key_storage],
|
||||||
../waku_types
|
../waku_types,
|
||||||
|
libp2p/protocols/pubsub/pubsub
|
||||||
|
|
||||||
from stew/byteutils import hexToSeqByte, hexToByteArray
|
from stew/byteutils import hexToSeqByte, hexToByteArray
|
||||||
|
|
||||||
|
@ -34,6 +35,16 @@ proc setupWakuRPC*(wakuProto: WakuProto, rpcsrv: RpcServer) =
|
||||||
return true
|
return true
|
||||||
#if not result:
|
#if not result:
|
||||||
# raise newException(ValueError, "Message could not be posted")
|
# raise newException(ValueError, "Message could not be posted")
|
||||||
|
|
||||||
|
# TODO: Handler / Identifier logic
|
||||||
|
rpcsrv.rpc("waku_subscribe") do(topic: string) -> bool:
|
||||||
|
let wakuSub = cast[WakuSub](wakuProto.switch.pubSub.get())
|
||||||
|
|
||||||
|
# XXX: Hacky in-line handler
|
||||||
|
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
||||||
|
info "Hit subscribe handler", topic=topic, data=data
|
||||||
|
|
||||||
|
discard wakuSub.subscribe(topic, handler)
|
||||||
return true
|
return true
|
||||||
#if not result:
|
#if not result:
|
||||||
# raise newException(ValueError, "Message could not be posted")
|
# raise newException(ValueError, "Message could not be posted")
|
||||||
|
|
|
@ -47,6 +47,14 @@ method initPubSub*(w: WakuSub) =
|
||||||
procCall FloodSub(w).initPubSub()
|
procCall FloodSub(w).initPubSub()
|
||||||
w.init()
|
w.init()
|
||||||
|
|
||||||
|
method subscribe*(w: WakuSub,
|
||||||
|
topic: string,
|
||||||
|
handler: TopicHandler) {.async.} =
|
||||||
|
debug "subscribe", topic=topic
|
||||||
|
# XXX: Pubsub really
|
||||||
|
await procCall FloodSub(w).subscribe(topic, handler)
|
||||||
|
|
||||||
|
# Subscribing a peer to a specified topic
|
||||||
method subscribeTopic*(w: WakuSub,
|
method subscribeTopic*(w: WakuSub,
|
||||||
topic: string,
|
topic: string,
|
||||||
subscribe: bool,
|
subscribe: bool,
|
||||||
|
|
Loading…
Reference in New Issue