Skip to content

Commit

Permalink
adding waku_get_connected_peers
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 28, 2024
1 parent 4cf7f82 commit b28101e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/libwaku.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ int waku_listen_addresses(void* ctx,
WakuCallBack callback,
void* userData);

int waku_get_connected_peers(void* ctx,
WakuCallBack callback,
void* userData);

// Returns a list of multiaddress given a url to a DNS discoverable ENR tree
// Parameters
// char* entTreeUrl: URL containing a discoverable ENR tree
Expand Down
13 changes: 13 additions & 0 deletions library/libwaku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,19 @@ proc waku_get_peerids_from_peerstore(
)
.handleRes(callback, userData)

proc waku_get_connected_peers(
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
): cint {.dynlib, exportc.} =
checkLibwakuParams(ctx, callback, userData)

waku_thread
.sendRequestToWakuThread(
ctx,
RequestType.PEER_MANAGER,
PeerManagementRequest.createShared(PeerManagementMsgType.GET_CONNECTED_PEERS),
)
.handleRes(callback, userData)

proc waku_get_peerids_by_protocol(
ctx: ptr WakuContext, protocol: cstring, callback: WakuCallBack, userData: pointer
): cint {.dynlib, exportc.} =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type PeerManagementMsgType* {.pure.} = enum
DISCONNECT_PEER_BY_ID
DIAL_PEER
DIAL_PEER_BY_ID
GET_CONNECTED_PEERS

type PeerManagementRequest* = object
operation: PeerManagementMsgType
Expand Down Expand Up @@ -114,5 +115,11 @@ proc process*(
let msg = "failed dialing peer"
error "DIAL_PEER_BY_ID failed", error = msg
return err(msg)
of GET_CONNECTED_PEERS:
## returns a comma-separated string of peerIDs
let
(inPeerIds, outPeerIds) = waku.node.peerManager.connectedPeers()
connectedPeerids = concat(inPeerIds, outPeerIds)
return ok(connectedPeerids.mapIt($it).join(","))

return ok("")

0 comments on commit b28101e

Please sign in to comment.