Skip to content

Commit

Permalink
initial setup for disconnect_peer_by_id
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Oct 11, 2024
1 parent ed0ee5b commit 553d449
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions library/libwaku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,27 @@ proc waku_connect(
)
.handleRes(callback, userData)

proc waku_disconnect_peer_by_id(
ctx: ptr WakuContext,
peerId: cstring,
timeoutMs: cuint,
callback: WakuCallBack,
userData: pointer,
): cint {.dynlib, exportc.} =
checkLibwakuParams(ctx, callback, userData)

waku_thread
.sendRequestToWakuThread(
ctx,
RequestType.PEER_MANAGER,
PeerManagementRequest.createShared(
op = PeerManagementMsgType.DISCONNECT_PEER_BY_ID,
dialTimeout = chronos.milliseconds(timeoutMs),
peerId = $peerId,
),
)
.handleRes(callback, userData)

proc waku_get_peerids_from_peerstore(
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
): cint {.dynlib, exportc.} =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ type PeerManagementMsgType* {.pure.} = enum
CONNECT_TO
GET_ALL_PEER_IDS
GET_PEER_IDS_BY_PROTOCOL
DISCONNECT_PEER_BY_ID

type PeerManagementRequest* = object
operation: PeerManagementMsgType
peerMultiAddr: cstring
dialTimeout: Duration
protocol: cstring
peerId: cstring

proc createShared*(
T: type PeerManagementRequest,
op: PeerManagementMsgType,
peerMultiAddr = "",
dialTimeout = chronos.milliseconds(0), ## arbitrary Duration as not all ops needs dialTimeout
peerId = "",
): ptr type T =
var ret = createShared(T)
ret[].operation = op
ret[].peerMultiAddr = peerMultiAddr.alloc()
ret[].peerId = peerId.alloc()
ret[].dialTimeout = dialTimeout
return ret

Expand All @@ -41,6 +45,9 @@ proc destroyShared(self: ptr PeerManagementRequest) =
if not isNil(self[].peerMultiAddr):
deallocShared(self[].peerMultiAddr)

if not isNil(self[].peerId):
deallocShared(self[].peerId)

if not isNil(self[].protocol):
deallocShared(self[].protocol)

Expand Down Expand Up @@ -87,5 +94,7 @@ proc process*(
.mapIt($it.peerId)
.join(",")
return ok(connectedPeers)
of DISCONNECT_PEER_BY_ID:
return ok("")

return ok("")

0 comments on commit 553d449

Please sign in to comment.