mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
feat: adding waku_dial_peer and get_connected_peers to libwaku (#3149)
This commit is contained in:
parent
400d7a54f6
commit
507b1fc4d9
@ -120,6 +120,13 @@ int waku_disconnect_peer_by_id(void* ctx,
|
|||||||
WakuCallBack callback,
|
WakuCallBack callback,
|
||||||
void* userData);
|
void* userData);
|
||||||
|
|
||||||
|
int waku_dial_peer(void* ctx,
|
||||||
|
const char* peerMultiAddr,
|
||||||
|
const char* protocol,
|
||||||
|
int timeoutMs,
|
||||||
|
WakuCallBack callback,
|
||||||
|
void* userData);
|
||||||
|
|
||||||
int waku_dial_peer_by_id(void* ctx,
|
int waku_dial_peer_by_id(void* ctx,
|
||||||
const char* peerId,
|
const char* peerId,
|
||||||
const char* protocol,
|
const char* protocol,
|
||||||
@ -140,6 +147,10 @@ int waku_listen_addresses(void* ctx,
|
|||||||
WakuCallBack callback,
|
WakuCallBack callback,
|
||||||
void* userData);
|
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
|
// Returns a list of multiaddress given a url to a DNS discoverable ENR tree
|
||||||
// Parameters
|
// Parameters
|
||||||
// char* entTreeUrl: URL containing a discoverable ENR tree
|
// char* entTreeUrl: URL containing a discoverable ENR tree
|
||||||
|
|||||||
@ -498,6 +498,28 @@ proc waku_disconnect_peer_by_id(
|
|||||||
)
|
)
|
||||||
.handleRes(callback, userData)
|
.handleRes(callback, userData)
|
||||||
|
|
||||||
|
proc waku_dial_peer(
|
||||||
|
ctx: ptr WakuContext,
|
||||||
|
peerMultiAddr: cstring,
|
||||||
|
protocol: 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.DIAL_PEER,
|
||||||
|
peerMultiAddr = $peerMultiAddr,
|
||||||
|
protocol = $protocol,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.handleRes(callback, userData)
|
||||||
|
|
||||||
proc waku_dial_peer_by_id(
|
proc waku_dial_peer_by_id(
|
||||||
ctx: ptr WakuContext,
|
ctx: ptr WakuContext,
|
||||||
peerId: cstring,
|
peerId: cstring,
|
||||||
@ -513,7 +535,7 @@ proc waku_dial_peer_by_id(
|
|||||||
ctx,
|
ctx,
|
||||||
RequestType.PEER_MANAGER,
|
RequestType.PEER_MANAGER,
|
||||||
PeerManagementRequest.createShared(
|
PeerManagementRequest.createShared(
|
||||||
op = PeerManagementMsgType.DIAL_PEER_BY_ID, peerId = $peerId
|
op = PeerManagementMsgType.DIAL_PEER_BY_ID, peerId = $peerId, protocol = $protocol
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.handleRes(callback, userData)
|
.handleRes(callback, userData)
|
||||||
@ -531,6 +553,19 @@ proc waku_get_peerids_from_peerstore(
|
|||||||
)
|
)
|
||||||
.handleRes(callback, userData)
|
.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(
|
proc waku_get_peerids_by_protocol(
|
||||||
ctx: ptr WakuContext, protocol: cstring, callback: WakuCallBack, userData: pointer
|
ctx: ptr WakuContext, protocol: cstring, callback: WakuCallBack, userData: pointer
|
||||||
): cint {.dynlib, exportc.} =
|
): cint {.dynlib, exportc.} =
|
||||||
|
|||||||
@ -11,7 +11,9 @@ type PeerManagementMsgType* {.pure.} = enum
|
|||||||
GET_ALL_PEER_IDS
|
GET_ALL_PEER_IDS
|
||||||
GET_PEER_IDS_BY_PROTOCOL
|
GET_PEER_IDS_BY_PROTOCOL
|
||||||
DISCONNECT_PEER_BY_ID
|
DISCONNECT_PEER_BY_ID
|
||||||
|
DIAL_PEER
|
||||||
DIAL_PEER_BY_ID
|
DIAL_PEER_BY_ID
|
||||||
|
GET_CONNECTED_PEERS
|
||||||
|
|
||||||
type PeerManagementRequest* = object
|
type PeerManagementRequest* = object
|
||||||
operation: PeerManagementMsgType
|
operation: PeerManagementMsgType
|
||||||
@ -95,6 +97,15 @@ proc process*(
|
|||||||
return err($error)
|
return err($error)
|
||||||
await waku.node.peerManager.disconnectNode(peerId)
|
await waku.node.peerManager.disconnectNode(peerId)
|
||||||
return ok("")
|
return ok("")
|
||||||
|
of DIAL_PEER:
|
||||||
|
let remotePeerInfo = parsePeerInfo($self[].peerMultiAddr).valueOr:
|
||||||
|
error "DIAL_PEER failed", error = $error
|
||||||
|
return err($error)
|
||||||
|
let conn = await waku.node.peerManager.dialPeer(remotePeerInfo, $self[].protocol)
|
||||||
|
if conn.isNone():
|
||||||
|
let msg = "failed dialing peer"
|
||||||
|
error "DIAL_PEER failed", error = msg, peerId = $remotePeerInfo.peerId
|
||||||
|
return err(msg)
|
||||||
of DIAL_PEER_BY_ID:
|
of DIAL_PEER_BY_ID:
|
||||||
let peerId = PeerId.init($self[].peerId).valueOr:
|
let peerId = PeerId.init($self[].peerId).valueOr:
|
||||||
error "DIAL_PEER_BY_ID failed", error = $error
|
error "DIAL_PEER_BY_ID failed", error = $error
|
||||||
@ -102,7 +113,13 @@ proc process*(
|
|||||||
let conn = await waku.node.peerManager.dialPeer(peerId, $self[].protocol)
|
let conn = await waku.node.peerManager.dialPeer(peerId, $self[].protocol)
|
||||||
if conn.isNone():
|
if conn.isNone():
|
||||||
let msg = "failed dialing peer"
|
let msg = "failed dialing peer"
|
||||||
error "DIAL_PEER_BY_ID failed", error = msg
|
error "DIAL_PEER_BY_ID failed", error = msg, peerId = $peerId
|
||||||
return err(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("")
|
return ok("")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user