chore: exposing online state in libwaku (#3433)

This commit is contained in:
gabrielmer 2025-05-30 17:47:06 +02:00 committed by GitHub
parent 5e22ea18b6
commit 94cd2f88b4
3 changed files with 21 additions and 0 deletions

View File

@ -232,6 +232,10 @@ int waku_ping_peer(void* ctx,
WakuCallBack callback,
void* userData);
int waku_is_online(void* ctx,
WakuCallBack callback,
void* userData);
#ifdef __cplusplus
}
#endif

View File

@ -842,5 +842,19 @@ proc waku_ping_peer(
userData,
)
proc waku_is_online(
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
): cint {.dynlib, exportc.} =
initializeLibrary()
checkLibwakuParams(ctx, callback, userData)
handleRequest(
ctx,
RequestType.PEER_MANAGER,
PeerManagementRequest.createShared(PeerManagementMsgType.IS_ONLINE),
callback,
userData,
)
### End of exported procs
################################################################################

View File

@ -15,6 +15,7 @@ type PeerManagementMsgType* {.pure.} = enum
DIAL_PEER
DIAL_PEER_BY_ID
GET_CONNECTED_PEERS
IS_ONLINE
type PeerManagementRequest* = object
operation: PeerManagementMsgType
@ -144,5 +145,7 @@ proc process*(
(inPeerIds, outPeerIds) = waku.node.peerManager.connectedPeers()
connectedPeerids = concat(inPeerIds, outPeerIds)
return ok(connectedPeerids.mapIt($it).join(","))
of IS_ONLINE:
return ok($waku.node.peerManager.isOnline())
return ok("")