mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
feat: add waku_disconnect_all_peers to libwaku (#3438)
This commit is contained in:
parent
66d8d3763d
commit
daa4a6a986
@ -150,6 +150,10 @@ int waku_disconnect_peer_by_id(void* ctx,
|
||||
WakuCallBack callback,
|
||||
void* userData);
|
||||
|
||||
int waku_disconnect_all_peers(void* ctx,
|
||||
WakuCallBack callback,
|
||||
void* userData);
|
||||
|
||||
int waku_dial_peer(void* ctx,
|
||||
const char* peerMultiAddr,
|
||||
const char* protocol,
|
||||
|
||||
@ -580,6 +580,20 @@ proc waku_disconnect_peer_by_id(
|
||||
userData,
|
||||
)
|
||||
|
||||
proc waku_disconnect_all_peers(
|
||||
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
||||
): cint {.dynlib, exportc.} =
|
||||
initializeLibrary()
|
||||
checkLibwakuParams(ctx, callback, userData)
|
||||
|
||||
handleRequest(
|
||||
ctx,
|
||||
RequestType.PEER_MANAGER,
|
||||
PeerManagementRequest.createShared(op = PeerManagementMsgType.DISCONNECT_ALL_PEERS),
|
||||
callback,
|
||||
userData,
|
||||
)
|
||||
|
||||
proc waku_dial_peer(
|
||||
ctx: ptr WakuContext,
|
||||
peerMultiAddr: cstring,
|
||||
|
||||
@ -12,6 +12,7 @@ type PeerManagementMsgType* {.pure.} = enum
|
||||
GET_CONNECTED_PEERS_INFO
|
||||
GET_PEER_IDS_BY_PROTOCOL
|
||||
DISCONNECT_PEER_BY_ID
|
||||
DISCONNECT_ALL_PEERS
|
||||
DIAL_PEER
|
||||
DIAL_PEER_BY_ID
|
||||
GET_CONNECTED_PEERS
|
||||
@ -121,6 +122,16 @@ proc process*(
|
||||
return err($error)
|
||||
await waku.node.peerManager.disconnectNode(peerId)
|
||||
return ok("")
|
||||
of DISCONNECT_ALL_PEERS:
|
||||
let connectedPeers = waku.node.peerManager.switch.peerStore.peers().filterIt(
|
||||
it.connectedness == Connected
|
||||
)
|
||||
|
||||
var futs: seq[Future[void]]
|
||||
for peer in connectedPeers:
|
||||
futs.add(waku.node.peerManager.disconnectNode(peer))
|
||||
await allFutures(futs)
|
||||
return ok("")
|
||||
of DIAL_PEER:
|
||||
let remotePeerInfo = parsePeerInfo($self[].peerMultiAddr).valueOr:
|
||||
error "DIAL_PEER failed", error = $error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user