Add disconnect test

This commit is contained in:
Daniel Sanchez Quiros 2022-10-17 18:40:18 +02:00
parent e54d744471
commit 5c2ff26971
3 changed files with 9 additions and 3 deletions

View File

@ -135,7 +135,7 @@ impl WakuNodeHandle<Running> {
/// Disconnect a peer using its peerID
///
/// 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)
}

View File

@ -86,10 +86,10 @@ pub fn waku_connect_peer_with_id(peer_id: PeerId, timeout: Option<Duration>) ->
/// Disconnect a peer using its peer id
/// 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 {
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")
.into_raw(),
))

View File

@ -136,6 +136,12 @@ pub fn main() -> Result<(), String> {
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));
node.stop()?;
Ok(())