mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
chore: bindings return multiaddress array (#2461)
* waku_example.c: adapt signature to new parameter 'void* userData' * libwaku: add new DEBUG request handler to retrieve the list of listened multiaddresses * waku_example.c: use example the new 'waku_listen_addresses' * add debug_node_request.nim file
This commit is contained in:
parent
d01585e9fa
commit
7aea145efe
@ -91,7 +91,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
|
|
||||||
static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };
|
static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };
|
||||||
|
|
||||||
void event_handler(int callerRet, const char* msg, size_t len) {
|
void event_handler(int callerRet, const char* msg, size_t len, void* userData) {
|
||||||
if (callerRet == RET_ERR) {
|
if (callerRet == RET_ERR) {
|
||||||
printf("Error: %s\n", msg);
|
printf("Error: %s\n", msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -102,7 +102,7 @@ void event_handler(int callerRet, const char* msg, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* contentTopic = NULL;
|
char* contentTopic = NULL;
|
||||||
void handle_content_topic(int callerRet, const char* msg, size_t len) {
|
void handle_content_topic(int callerRet, const char* msg, size_t len, void* userData) {
|
||||||
if (contentTopic != NULL) {
|
if (contentTopic != NULL) {
|
||||||
free(contentTopic);
|
free(contentTopic);
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ void handle_content_topic(int callerRet, const char* msg, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* publishResponse = NULL;
|
char* publishResponse = NULL;
|
||||||
void handle_publish_ok(int callerRet, const char* msg, size_t len) {
|
void handle_publish_ok(int callerRet, const char* msg, size_t len, void* userData) {
|
||||||
printf("Publish Ok: %s %lu\n", msg, len);
|
printf("Publish Ok: %s %lu\n", msg, len);
|
||||||
|
|
||||||
if (publishResponse != NULL) {
|
if (publishResponse != NULL) {
|
||||||
@ -159,11 +159,11 @@ void show_help_and_exit() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_default_pubsub_topic(int callerRet, const char* msg, size_t len) {
|
void print_default_pubsub_topic(int callerRet, const char* msg, size_t len, void* userData) {
|
||||||
printf("Default pubsub topic: %s\n", msg);
|
printf("Default pubsub topic: %s\n", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_waku_version(int callerRet, const char* msg, size_t len) {
|
void print_waku_version(int callerRet, const char* msg, size_t len, void* userData) {
|
||||||
printf("Git Version: %s\n", msg);
|
printf("Git Version: %s\n", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,6 +297,8 @@ int main(int argc, char** argv) {
|
|||||||
waku_set_event_callback(ctx, event_handler, userData);
|
waku_set_event_callback(ctx, event_handler, userData);
|
||||||
waku_start(ctx, event_handler, userData);
|
waku_start(ctx, event_handler, userData);
|
||||||
|
|
||||||
|
waku_listen_addresses(ctx, event_handler, userData);
|
||||||
|
|
||||||
printf("Establishing connection with: %s\n", cfgNode.peers);
|
printf("Establishing connection with: %s\n", cfgNode.peers);
|
||||||
|
|
||||||
WAKU_CALL( waku_connect(ctx,
|
WAKU_CALL( waku_connect(ctx,
|
||||||
|
|||||||
@ -83,6 +83,10 @@ int waku_connect(void* ctx,
|
|||||||
WakuCallBack callback,
|
WakuCallBack callback,
|
||||||
void* userData);
|
void* userData);
|
||||||
|
|
||||||
|
int waku_listen_addresses(void* ctx,
|
||||||
|
WakuCallBack callback,
|
||||||
|
void* userData);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import
|
|||||||
./waku_thread/inter_thread_communication/requests/peer_manager_request,
|
./waku_thread/inter_thread_communication/requests/peer_manager_request,
|
||||||
./waku_thread/inter_thread_communication/requests/protocols/relay_request,
|
./waku_thread/inter_thread_communication/requests/protocols/relay_request,
|
||||||
./waku_thread/inter_thread_communication/requests/protocols/store_request,
|
./waku_thread/inter_thread_communication/requests/protocols/store_request,
|
||||||
|
./waku_thread/inter_thread_communication/requests/debug_node_request,
|
||||||
./waku_thread/inter_thread_communication/waku_thread_request,
|
./waku_thread/inter_thread_communication/waku_thread_request,
|
||||||
./alloc,
|
./alloc,
|
||||||
./callback
|
./callback
|
||||||
@ -353,5 +354,26 @@ proc waku_store_query(ctx: ptr Context,
|
|||||||
|
|
||||||
return RET_OK
|
return RET_OK
|
||||||
|
|
||||||
|
proc waku_listen_addresses(ctx: ptr Context,
|
||||||
|
callback: WakuCallBack,
|
||||||
|
userData: pointer): cint
|
||||||
|
{.dynlib, exportc.} =
|
||||||
|
|
||||||
|
ctx[].userData = userData
|
||||||
|
|
||||||
|
let connRes = waku_thread.sendRequestToWakuThread(
|
||||||
|
ctx,
|
||||||
|
RequestType.DEBUG,
|
||||||
|
DebugNodeRequest.createShared(
|
||||||
|
DebugNodeMsgType.RETRIEVE_LISTENING_ADDRESSES))
|
||||||
|
if connRes.isErr():
|
||||||
|
let msg = $connRes.error
|
||||||
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
||||||
|
return RET_ERR
|
||||||
|
else:
|
||||||
|
let msg = $connRes.value
|
||||||
|
callback(RET_OK, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
||||||
|
return RET_OK
|
||||||
|
|
||||||
### End of exported procs
|
### End of exported procs
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
import
|
||||||
|
std/[options,sequtils,strutils,json]
|
||||||
|
import
|
||||||
|
chronicles,
|
||||||
|
chronos,
|
||||||
|
stew/results,
|
||||||
|
stew/shims/net
|
||||||
|
import
|
||||||
|
../../../../waku/node/waku_node,
|
||||||
|
../../../alloc
|
||||||
|
|
||||||
|
type
|
||||||
|
DebugNodeMsgType* = enum
|
||||||
|
RETRIEVE_LISTENING_ADDRESSES
|
||||||
|
|
||||||
|
type
|
||||||
|
DebugNodeRequest* = object
|
||||||
|
operation: DebugNodeMsgType
|
||||||
|
|
||||||
|
proc createShared*(T: type DebugNodeRequest,
|
||||||
|
op: DebugNodeMsgType): ptr type T =
|
||||||
|
|
||||||
|
var ret = createShared(T)
|
||||||
|
ret[].operation = op
|
||||||
|
return ret
|
||||||
|
|
||||||
|
proc destroyShared(self: ptr DebugNodeRequest) =
|
||||||
|
deallocShared(self)
|
||||||
|
|
||||||
|
proc getMultiaddresses(node: WakuNode): seq[string] =
|
||||||
|
return node.info().listenAddresses
|
||||||
|
|
||||||
|
proc process*(self: ptr DebugNodeRequest,
|
||||||
|
node: WakuNode): Future[Result[string, string]] {.async.} =
|
||||||
|
|
||||||
|
defer: destroyShared(self)
|
||||||
|
|
||||||
|
case self.operation:
|
||||||
|
of RETRIEVE_LISTENING_ADDRESSES:
|
||||||
|
return ok($( %* node.getMultiaddresses()))
|
||||||
|
|
||||||
|
return err("unsupported operation in DebugNodeRequest")
|
||||||
|
|
||||||
@ -13,7 +13,8 @@ import
|
|||||||
./requests/node_lifecycle_request,
|
./requests/node_lifecycle_request,
|
||||||
./requests/peer_manager_request,
|
./requests/peer_manager_request,
|
||||||
./requests/protocols/relay_request,
|
./requests/protocols/relay_request,
|
||||||
./requests/protocols/store_request
|
./requests/protocols/store_request,
|
||||||
|
./requests/debug_node_request
|
||||||
|
|
||||||
type
|
type
|
||||||
RequestType* {.pure.} = enum
|
RequestType* {.pure.} = enum
|
||||||
@ -21,6 +22,7 @@ type
|
|||||||
PEER_MANAGER,
|
PEER_MANAGER,
|
||||||
RELAY,
|
RELAY,
|
||||||
STORE,
|
STORE,
|
||||||
|
DEBUG,
|
||||||
|
|
||||||
type
|
type
|
||||||
InterThreadRequest* = object
|
InterThreadRequest* = object
|
||||||
@ -54,6 +56,8 @@ proc process*(T: type InterThreadRequest,
|
|||||||
cast[ptr RelayRequest](request[].reqContent).process(node)
|
cast[ptr RelayRequest](request[].reqContent).process(node)
|
||||||
of STORE:
|
of STORE:
|
||||||
cast[ptr StoreRequest](request[].reqContent).process(node)
|
cast[ptr StoreRequest](request[].reqContent).process(node)
|
||||||
|
of DEBUG:
|
||||||
|
cast[ptr DebugNodeRequest](request[].reqContent).process(node[])
|
||||||
|
|
||||||
return await retFut
|
return await retFut
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user