mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-02-27 21:53:16 +00:00
ensure logosdelivery_example can consume debug api
This commit is contained in:
parent
a8fc3cef9d
commit
e069167cdd
@ -161,7 +161,23 @@ int main() {
|
||||
// Wait for subscription
|
||||
sleep(1);
|
||||
|
||||
printf("\n5. Sending a message...\n");
|
||||
printf("\n5. Retrieving all possibl node info ids...\n");
|
||||
logosdelivery_get_available_node_info_ids(ctx, simple_callback, (void *)"get_available_node_info_ids");
|
||||
|
||||
printf("\nRetrieving node info for a specific invalid ID...\n");
|
||||
logosdelivery_get_node_info(ctx, simple_callback, (void *)"get_node_info", "WrongNodeInfoId");
|
||||
|
||||
printf("\nRetrieving several node info for specific correct IDs...\n");
|
||||
logosdelivery_get_node_info(ctx, simple_callback, (void *)"get_node_info", "Version");
|
||||
// logosdelivery_get_node_info(ctx, simple_callback, (void *)"get_node_info", "Metrics");
|
||||
logosdelivery_get_node_info(ctx, simple_callback, (void *)"get_node_info", "MyMultiaddresses");
|
||||
logosdelivery_get_node_info(ctx, simple_callback, (void *)"get_node_info", "MyENR");
|
||||
logosdelivery_get_node_info(ctx, simple_callback, (void *)"get_node_info", "MyPeerId");
|
||||
|
||||
printf("\nRetrieving available configs...\n");
|
||||
logosdelivery_get_available_configs(ctx, simple_callback, (void *)"get_available_configs");
|
||||
|
||||
printf("\n6. Sending a message...\n");
|
||||
printf("Watch for message events (sent, propagated, or error):\n");
|
||||
// Create base64-encoded payload: "Hello, Logos Messaging!"
|
||||
const char *message = "{"
|
||||
@ -175,17 +191,17 @@ int main() {
|
||||
printf("Waiting for message delivery events...\n");
|
||||
sleep(60);
|
||||
|
||||
printf("\n6. Unsubscribing from content topic...\n");
|
||||
printf("\n7. Unsubscribing from content topic...\n");
|
||||
logosdelivery_unsubscribe(ctx, simple_callback, (void *)"unsubscribe", contentTopic);
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf("\n7. Stopping node...\n");
|
||||
printf("\n8. Stopping node...\n");
|
||||
logosdelivery_stop_node(ctx, simple_callback, (void *)"stop_node");
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf("\n8. Destroying context...\n");
|
||||
printf("\n9. Destroying context...\n");
|
||||
logosdelivery_destroy(ctx, simple_callback, (void *)"destroy");
|
||||
|
||||
printf("\n=== Example completed ===\n");
|
||||
|
||||
@ -75,6 +75,22 @@ extern "C"
|
||||
FFICallBack callback,
|
||||
void *userData);
|
||||
|
||||
// Retrieves the list of available node info IDs.
|
||||
int logosdelivery_get_available_node_info_ids(void *ctx,
|
||||
FFICallBack callback,
|
||||
void *userData);
|
||||
|
||||
// Given a node info ID, retrieves the corresponding info.
|
||||
int logosdelivery_get_node_info(void *ctx,
|
||||
FFICallBack callback,
|
||||
void *userData,
|
||||
const char *nodeInfoId);
|
||||
|
||||
// Retrieves the list of available configurations.
|
||||
int logosdelivery_get_available_configs(void *ctx,
|
||||
FFICallBack callback,
|
||||
void *userData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -4,7 +4,10 @@ import waku/factory/waku, waku/node/waku_node, ./declare_lib
|
||||
|
||||
################################################################################
|
||||
## Include different APIs, i.e. all procs with {.ffi.} pragma
|
||||
include ./logos_delivery_api/node_api, ./logos_delivery_api/messaging_api
|
||||
include
|
||||
./logos_delivery_api/node_api,
|
||||
./logos_delivery_api/messaging_api,
|
||||
./logos_delivery_api/debug_api
|
||||
|
||||
################################################################################
|
||||
### Exported procs
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import std/json
|
||||
import std/[json, strutils]
|
||||
import waku/factory/waku_state_info
|
||||
|
||||
proc logosdelivery_get_available_node_info_ids(
|
||||
ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer
|
||||
@ -19,10 +20,14 @@ proc logosdelivery_get_node_info(
|
||||
## Returns the content of the node info item with the given id if it exists.
|
||||
requireInitializedNode(ctx, "GetNodeInfoItem"):
|
||||
return err(errMsg)
|
||||
let infoItemIdEnum = parseEnum[NodeInfoId]($nodeInfoId)
|
||||
if infoItemIdEnum.isNone():
|
||||
return err("Invalid node info id: " & $nodeInfoId)
|
||||
return ok(ctx.myLib[].stateInfo.getNodeInfoItem(infoItemIdEnum.get()))
|
||||
|
||||
let infoItemIdEnum =
|
||||
try:
|
||||
parseEnum[NodeInfoId]($nodeInfoId)
|
||||
except ValueError:
|
||||
return err("Invalid node info id: " & $nodeInfoId)
|
||||
|
||||
return ok(ctx.myLib[].stateInfo.getNodeInfoItem(infoItemIdEnum))
|
||||
|
||||
proc logosdelivery_get_available_configs(
|
||||
ctx: ptr FFIContext[Waku],
|
||||
|
||||
@ -56,7 +56,7 @@ logScope:
|
||||
const git_version* {.strdefine.} = "n/a"
|
||||
|
||||
type Waku* = ref object
|
||||
stateInfo: WakuStateInfo
|
||||
stateInfo*: WakuStateInfo
|
||||
conf*: WakuConf
|
||||
rng*: ref HmacDrbgContext
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
## accessible through the debug API.
|
||||
|
||||
import std/[tables, sequtils, strutils]
|
||||
import metrics, eth/p2p/discoveryv5/enr
|
||||
import metrics, eth/p2p/discoveryv5/enr, libp2p/peerid
|
||||
import waku/waku_node
|
||||
|
||||
type
|
||||
@ -42,7 +42,7 @@ proc getNodeInfoItem*(self: WakuStateInfo, infoItemId: NodeInfoId): string =
|
||||
of NodeInfoId.MyENR:
|
||||
return self.node.enr.toURI()
|
||||
of NodeInfoId.MyPeerId:
|
||||
return $self.node.peerId()
|
||||
return $PeerId(self.node.peerId())
|
||||
else:
|
||||
return "unknown info item id"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user