Skip to content

Commit

Permalink
chore: add to libwaku peer id retrieval proc (#3124)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer authored Oct 17, 2024
1 parent c35dc54 commit c5a825e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions library/libwaku.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions library/libwaku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.} =
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

0 comments on commit c5a825e

Please sign in to comment.