feature/add-filter (#244)

* started working on adding filter

* fix

* fix

* fix

* not subscribing

* fix

* filter

Co-authored-by: Oskar Thorén <ot@oskarthoren.com>
This commit is contained in:
Dean Eigenmann 2020-10-27 11:40:29 +01:00 committed by GitHub
parent 16c4e65762
commit 45d57efaea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -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 (?)

View File

@ -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]