From 45d57efaea130b590a3ddc88034d06be5217eb0f Mon Sep 17 00:00:00 2001 From: Dean Eigenmann <7621705+decanus@users.noreply.github.com> Date: Tue, 27 Oct 2020 11:40:29 +0100 Subject: [PATCH] feature/add-filter (#244) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * started working on adding filter * fix * fix * fix * not subscribing * fix * filter Co-authored-by: Oskar Thorén --- examples/v2/chat2.nim | 23 +++++++++++++++++++++-- waku/node/v2/waku_types.nim | 1 - 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/v2/chat2.nim b/examples/v2/chat2.nim index 70bb866f2..36ebcedb4 100644 --- a/examples/v2/chat2.nim +++ b/examples/v2/chat2.nim @@ -19,7 +19,7 @@ import libp2p/[switch, # manage transports, a single entry poi muxers/muxer, # define an interface for stream multiplexing, allowing peers to offer many protocols over a single connection muxers/mplex/mplex] # define some contants and message types for stream multiplexing import ../../waku/node/v2/[config, wakunode2, waku_types], - ../../waku/protocol/v2/[waku_relay, waku_store], + ../../waku/protocol/v2/[waku_relay, waku_store, waku_filter], ../../waku/node/common const Help = """ @@ -158,7 +158,11 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} = # waitFor vs await await node.start() - await node.mountRelay(conf.topics.split(" ")) + + if conf.filternode != "": + await node.mountRelay(conf.topics.split(" ")) + else: + await node.mountRelay(@[]) var chat = Chat(node: node, transp: transp, subscribed: true, connected: false, started: true) @@ -182,6 +186,21 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} = await node.query(HistoryQuery(topics: @[DefaultContentTopic]), storeHandler) + if conf.filternode != "": + node.mountFilter() + + node.wakuFilter.setPeer(parsePeer(conf.filternode)) + + proc filterHandler(msg: WakuMessage) {.gcsafe.} = + let payload = cast[string](msg.payload) + echo &"{payload}" + info "Hit filter handler" + + await node.subscribe( + FilterRequest(contentFilters: @[ContentFilter(topics: @[DefaultContentTopic])], topic: DefaultTopic), + filterHandler + ) + # Subscribe to a topic # TODO To get end to end sender would require more information in payload # We could possibly indicate the relayer point with connection somehow probably (?) diff --git a/waku/node/v2/waku_types.nim b/waku/node/v2/waku_types.nim index b83265425..ea181aae0 100644 --- a/waku/node/v2/waku_types.nim +++ b/waku/node/v2/waku_types.nim @@ -35,7 +35,6 @@ type QueryHandlerFunc* = proc(response: HistoryResponse) {.gcsafe, closure.} - Index* = object ## This type contains the description of an index used in the pagination of waku messages digest*: MDigest[256]