mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-03 22:43:07 +00:00
Add disconnect test
This commit is contained in:
parent
e54d744471
commit
5c2ff26971
@ -135,7 +135,7 @@ impl WakuNodeHandle<Running> {
|
|||||||
/// Disconnect a peer using its peerID
|
/// Disconnect a peer using its peerID
|
||||||
///
|
///
|
||||||
/// wrapper around [`peers::waku_disconnect_peer_with_id`]
|
/// wrapper around [`peers::waku_disconnect_peer_with_id`]
|
||||||
pub fn disconnect_peer_with_id(&self, peer_id: PeerId) -> Result<()> {
|
pub fn disconnect_peer_with_id(&self, peer_id: &PeerId) -> Result<()> {
|
||||||
peers::waku_disconnect_peer_with_id(peer_id)
|
peers::waku_disconnect_peer_with_id(peer_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -86,10 +86,10 @@ pub fn waku_connect_peer_with_id(peer_id: PeerId, timeout: Option<Duration>) ->
|
|||||||
|
|
||||||
/// Disconnect a peer using its peer id
|
/// Disconnect a peer using its peer id
|
||||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_disconnect_peerchar-peerid)
|
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_disconnect_peerchar-peerid)
|
||||||
pub fn waku_disconnect_peer_with_id(peer_id: PeerId) -> Result<()> {
|
pub fn waku_disconnect_peer_with_id(peer_id: &PeerId) -> Result<()> {
|
||||||
let response = unsafe {
|
let response = unsafe {
|
||||||
CStr::from_ptr(waku_sys::waku_disconnect(
|
CStr::from_ptr(waku_sys::waku_disconnect(
|
||||||
CString::new(peer_id)
|
CString::new(peer_id.as_bytes())
|
||||||
.expect("CString should build properly from peer id")
|
.expect("CString should build properly from peer id")
|
||||||
.into_raw(),
|
.into_raw(),
|
||||||
))
|
))
|
||||||
|
|||||||
@ -136,6 +136,12 @@ pub fn main() -> Result<(), String> {
|
|||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
for node_data in node.peers()? {
|
||||||
|
if node_data.peer_id() != &node.peer_id()? {
|
||||||
|
node.disconnect_peer_with_id(node_data.peer_id())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::thread::sleep(Duration::from_secs(2));
|
std::thread::sleep(Duration::from_secs(2));
|
||||||
node.stop()?;
|
node.stop()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user