Skip to content

Commit

Permalink
Filter v2 rest api support implemented - WIP: some test fixes still n…
Browse files Browse the repository at this point in the history
…eeded

Filter rest api documentation updated with v1 and v2 interface support.
Separated legacy filter rest interface
Fix code and tests of v2 Filter rest api
Filter v2 message push test added

Small enhancment on Makefile. 'make list' will list all targets defined

Applied autoshard to Filter V2
  • Loading branch information
NagyZoltanPeter authored and NagyZoltanPeter committed Aug 29, 2023
1 parent bd3be21 commit 18c2953
Show file tree
Hide file tree
Showing 18 changed files with 1,467 additions and 258 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,12 @@ release-notes:
sed -E 's@#([0-9]+)@[#\1](https://github.com/waku-org/nwaku/issues/\1)@g'
# I could not get the tool to replace issue ids with links, so using sed for now,
# asked here: https://github.com/bvieira/sv4git/discussions/101


#############################
# List all possible Targets #
#############################

.PHONY: list
list:
@LC_ALL=C $(MAKE) -pRrq -f $(firstword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'
15 changes: 12 additions & 3 deletions apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import
../../waku/waku_store,
../../waku/waku_lightpush,
../../waku/waku_filter,
../../waku/waku_filter_v2,
../../waku/waku_filter_v2/client as waku_filter_client,
./wakunode2_validator_signed,
./internal_config,
./external_config
Expand All @@ -45,6 +47,7 @@ import
../../waku/node/rest/debug/handlers as rest_debug_api,
../../waku/node/rest/relay/handlers as rest_relay_api,
../../waku/node/rest/relay/topic_cache,
../../waku/node/rest/filter/legacy_handlers as rest_legacy_filter_api,
../../waku/node/rest/filter/handlers as rest_filter_api,
../../waku/node/rest/store/handlers as rest_store_api,
../../waku/node/jsonrpc/admin/handlers as rpc_admin_api,
Expand Down Expand Up @@ -468,7 +471,12 @@ proc setupProtocols(node: WakuNode,
if conf.filternode != "":
let filterNode = parsePeerInfo(conf.filternode)
if filterNode.isOk():
await mountFilterClient(node)
let filterMessageCache = TopicCache.init(capacity=rest_legacy_filter_api.filterMessageCacheDefaultCapacity)

let filterPushMessageHandler : waku_filter_client.MessagePushHandler = proc(pubsubTopic: string, message: WakuMessage) {.gcsafe, closure.} =
filterMessageCache.addMessage(message.contentTopic, message)

await node.mountFilterClient(some(filterPushMessageHandler))
node.peerManager.addServicePeer(filterNode.value, WakuFilterCodec)
else:
return err("failed to set node waku filter peer: " & filterNode.error)
Expand Down Expand Up @@ -572,8 +580,9 @@ proc startRestServer(app: App, address: ValidIpAddress, port: Port, conf: WakuNo

## Filter REST API
if conf.filter:
let filterCache = rest_filter_api.MessageCache.init(capacity=rest_filter_api.filterMessageCacheDefaultCapacity)
installFilterApiHandlers(server.router, app.node, filterCache)
let filterCache = rest_legacy_filter_api.MessageCache.init(capacity=rest_legacy_filter_api.filterMessageCacheDefaultCapacity)
rest_legacy_filter_api.installLegacyFilterRestApiHandlers(server.router, app.node, filterCache)
rest_filter_api.installFilterRestApiHandlers(server.router, app.node)

## Store REST API
installStoreApiHandlers(server.router, app.node)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wakunode_filter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ suite "WakuNode - Filter":
filterPushHandlerFut.complete((pubsubTopic, msg))

## When
await client.filterSubscribe(some(pubsubTopic), contentTopic, filterPushHandler, peer=serverPeerInfo)
await client.legacyFilterSubscribe(some(pubsubTopic), contentTopic, filterPushHandler, peer=serverPeerInfo)

# Wait for subscription to take effect
waitFor sleepAsync(100.millis)
Expand Down
4 changes: 2 additions & 2 deletions tests/waku_store/test_wakunode_store.nim
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ procSuite "WakuNode - Store":

let mountArchiveRes = server.mountArchive(driver)
assert mountArchiveRes.isOk(), mountArchiveRes.error

waitFor server.mountStore()
waitFor server.mountFilterClient()
client.mountStoreClient()
Expand All @@ -232,7 +232,7 @@ procSuite "WakuNode - Store":
proc filterHandler(pubsubTopic: PubsubTopic, msg: WakuMessage) {.async, gcsafe, closure.} =
filterFut.complete((pubsubTopic, msg))

waitFor server.filterSubscribe(some(DefaultPubsubTopic), DefaultContentTopic, filterHandler, peer=filterSourcePeer)
waitFor server.legacyFilterSubscribe(some(DefaultPubsubTopic), DefaultContentTopic, filterHandler, peer=filterSourcePeer)

waitFor sleepAsync(100.millis)

Expand Down
Loading

0 comments on commit 18c2953

Please sign in to comment.