From 83abcf58d819fe6be5a97a9fc086d81a274bff9c Mon Sep 17 00:00:00 2001 From: Oskar Thoren Date: Wed, 3 Jun 2020 19:32:11 +0800 Subject: [PATCH] Propagating subscribes work, BUT at perf (need light node behavior) --- waku/node/v2/quicksim.nim | 16 ++++++++-------- waku/protocol/v2/waku_protocol.nim | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/waku/node/v2/quicksim.nim b/waku/node/v2/quicksim.nim index 5b2374713..ba185bb0a 100644 --- a/waku/node/v2/quicksim.nim +++ b/waku/node/v2/quicksim.nim @@ -68,15 +68,15 @@ info "Version is", version let res1 = waitFor nodea.wakuSubscribe("foobar") let res2 = waitFor nodeb.wakuSubscribe("foobar") - # Node 00 and 05 also subscribe -# XXX I confirm this works. Now to tweak it! -let node0 = newRpcHttpClient() -let node5 = newRpcHttpClient() -waitFor node0.connect("localhost", Port(8547)) -waitFor node5.connect("localhost", Port(8552)) -let res4 = waitFor node0.wakuSubscribe("foobar") -let res5 = waitFor node5.wakuSubscribe("foobar") +# XXX I confirm this works. As in - with this we have A-B +# Now to tweak it! +# let node0 = newRpcHttpClient() +# let node5 = newRpcHttpClient() +# waitFor node0.connect("localhost", Port(8547)) +# waitFor node5.connect("localhost", Port(8552)) +# let res4 = waitFor node0.wakuSubscribe("foobar") +# let res5 = waitFor node5.wakuSubscribe("foobar") os.sleep(2000) diff --git a/waku/protocol/v2/waku_protocol.nim b/waku/protocol/v2/waku_protocol.nim index 18d6de714..65a374e38 100644 --- a/waku/protocol/v2/waku_protocol.nim +++ b/waku/protocol/v2/waku_protocol.nim @@ -70,16 +70,21 @@ method subscribe*(w: WakuSub, debug "subscribe", topic=topic # XXX: Pubsub really + # XXX: This is what is called, I think if w.gossip_enabled: await procCall GossipSub(w).subscribe(topic, handler) else: await procCall FloodSub(w).subscribe(topic, handler) + # Subscribing a peer to a specified topic method subscribeTopic*(w: WakuSub, topic: string, subscribe: bool, peerId: string) {.async, gcsafe.} = + proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} = + info "Hit NOOP handler", topic + debug "subscribeTopic", topic=topic, subscribe=subscribe, peerId=peerId if w.gossip_enabled: @@ -87,6 +92,15 @@ method subscribeTopic*(w: WakuSub, else: await procCall FloodSub(w).subscribeTopic(topic, subscribe, peerId) + # XXX: This should distingish light and etc node + # NOTE: Relay subscription + # TODO: If peer is light node + info "about to call subscribe" + await w.subscribe(topic, handler) + + + + # TODO: Fix decrement connected peers here or somewhere else method handleDisconnect*(w: WakuSub, peer: PubSubPeer) {.async.} = debug "handleDisconnect (NYI)" @@ -104,6 +118,7 @@ method rpcHandler*(w: WakuSub, await procCall GossipSub(w).rpcHandler(peer, rpcMsgs) else: await procCall FloodSub(w).rpcHandler(peer, rpcMsgs) + # XXX: here method publish*(w: WakuSub, topic: string,