From c5a825e206c1cb3e6e0cf8c01410527804cb76c4 Mon Sep 17 00:00:00 2001 From: gabrielmer <101006718+gabrielmer@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:13:00 +0300 Subject: [PATCH] chore: add to libwaku peer id retrieval proc (#3124) --- library/libwaku.h | 4 ++++ library/libwaku.nim | 13 +++++++++++++ .../requests/debug_node_request.nim | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/library/libwaku.h b/library/libwaku.h index b32ab55ca..5660e3a10 100644 --- a/library/libwaku.h +++ b/library/libwaku.h @@ -172,6 +172,10 @@ int waku_get_my_enr(void* ctx, WakuCallBack callback, void* userData); +int waku_get_my_peerid(void* ctx, + WakuCallBack callback, + void* userData); + int waku_peer_exchange_request(void* ctx, int numPeers, WakuCallBack callback, diff --git a/library/libwaku.nim b/library/libwaku.nim index 80178b46c..93d468f1e 100644 --- a/library/libwaku.nim +++ b/library/libwaku.nim @@ -626,6 +626,19 @@ proc waku_get_my_enr( ) .handleRes(callback, userData) +proc waku_get_my_peerid( + ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer +): cint {.dynlib, exportc.} = + checkLibwakuParams(ctx, callback, userData) + + waku_thread + .sendRequestToWakuThread( + ctx, + RequestType.DEBUG, + DebugNodeRequest.createShared(DebugNodeMsgType.RETRIEVE_MY_PEER_ID), + ) + .handleRes(callback, userData) + proc waku_start_discv5( ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer ): cint {.dynlib, exportc.} = diff --git a/library/waku_thread/inter_thread_communication/requests/debug_node_request.nim b/library/waku_thread/inter_thread_communication/requests/debug_node_request.nim index dbe80b29b..53715e0ed 100644 --- a/library/waku_thread/inter_thread_communication/requests/debug_node_request.nim +++ b/library/waku_thread/inter_thread_communication/requests/debug_node_request.nim @@ -1,10 +1,11 @@ import std/json -import chronicles, chronos, results, eth/p2p/discoveryv5/enr, strutils +import chronicles, chronos, results, eth/p2p/discoveryv5/enr, strutils, libp2p/peerid import ../../../../waku/factory/waku, ../../../../waku/node/waku_node type DebugNodeMsgType* = enum RETRIEVE_LISTENING_ADDRESSES RETRIEVE_MY_ENR + RETRIEVE_MY_PEER_ID type DebugNodeRequest* = object operation: DebugNodeMsgType @@ -32,6 +33,8 @@ proc process*( return ok(waku.node.getMultiaddresses().join(",")) of RETRIEVE_MY_ENR: return ok(waku.node.enr.toURI()) + of RETRIEVE_MY_PEER_ID: + return ok($waku.node.peerId()) error "unsupported operation in DebugNodeRequest" return err("unsupported operation in DebugNodeRequest")