-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some basic debug and relay json-rpc calls (#305)
- Loading branch information
Showing
5 changed files
with
164 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import | ||
json_rpc/rpcserver, | ||
../../waku_types, | ||
../wakunode2 | ||
|
||
proc installDebugApiHandlers*(node: WakuNode, rpcsrv: RpcServer) = | ||
|
||
## Debug API version 1 definitions | ||
|
||
rpcsrv.rpc("get_waku_v2_debug_v1_info") do() -> WakuInfo: | ||
## Returns information about WakuNode | ||
debug "get_waku_v2_debug_v1_info" | ||
|
||
return node.info() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
# Debug API | ||
|
||
proc get_waku_v2_debug_v1_info(): WakuInfo | ||
|
||
# Relay API | ||
|
||
proc post_waku_v2_relay_v1_subscriptions(topics: seq[string]): bool | ||
proc delete_waku_v2_relay_v1_subscriptions(topics: seq[string]): bool | ||
|
||
# Store API | ||
|
||
proc get_waku_v2_store_v1_messages(topics: seq[ContentTopic], pagingOptions: Option[StorePagingOptions]): StoreResponse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import | ||
json_rpc/rpcserver, | ||
eth/[common, rlp, keys, p2p], | ||
../../waku_types, | ||
../wakunode2 | ||
|
||
proc installRelayApiHandlers*(node: WakuNode, rpcsrv: RpcServer) = | ||
const futTimeout = 5.seconds | ||
|
||
## Relay API version 1 definitions | ||
|
||
rpcsrv.rpc("post_waku_v2_relay_v1_subscriptions") do(topics: seq[string]) -> bool: | ||
## Subscribes a node to a list of PubSub topics | ||
debug "post_waku_v2_relay_v1_subscriptions" | ||
|
||
proc topicHandler(topic: string, data: seq[byte]) {.async, gcsafe.} = | ||
let msg = WakuMessage.init(data) | ||
if msg.isOk(): | ||
debug "WakuMessage received", msg=msg, topic=topic | ||
# @TODO handle message | ||
else: | ||
debug "WakuMessage received but failed to decode", msg=msg, topic=topic | ||
# @TODO handle message decode failure | ||
|
||
var failedTopics: seq[string] | ||
|
||
# Subscribe to all requested topics | ||
for topic in topics: | ||
# If any topic fails to subscribe, add to list of failedTopics | ||
if not(await node.subscribe(topic, topicHandler).withTimeout(futTimeout)): | ||
failedTopics.add(topic) | ||
|
||
if (failedTopics.len() == 0): | ||
# Successfully subscribed to all requested topics | ||
return true | ||
else: | ||
# Failed to subscribe to one or more topics | ||
raise newException(ValueError, "Failed to subscribe to topics " & repr(failedTopics)) | ||
|
||
rpcsrv.rpc("delete_waku_v2_relay_v1_subscriptions") do(topics: seq[string]) -> bool: | ||
## Unsubscribes a node from a list of PubSub topics | ||
debug "delete_waku_v2_relay_v1_subscriptions" | ||
|
||
var failedTopics: seq[string] | ||
|
||
# Unsubscribe all handlers from requested topics | ||
for topic in topics: | ||
# If any topic fails to unsubscribe, add to list of failedTopics | ||
if not(await node.unsubscribeAll(topic).withTimeout(futTimeout)): | ||
failedTopics.add(topic) | ||
|
||
if (failedTopics.len() == 0): | ||
# Successfully unsubscribed from all requested topics | ||
return true | ||
else: | ||
# Failed to unsubscribe from one or more topics | ||
raise newException(ValueError, "Failed to unsubscribe from topics " & repr(failedTopics)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters