Skip to content

Commit

Permalink
fix: waku_peer_count conversion to usize (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Oct 1, 2023
1 parent 32bd05c commit 00bf354
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions waku-bindings/src/node/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn waku_listen_addresses() -> Result<Vec<Multiaddr>> {
mod test {
use super::waku_new;
use crate::node::management::{waku_listen_addresses, waku_peer_id, waku_start, waku_stop};
use crate::node::peers::waku_peer_count;
use serial_test::serial;

#[test]
Expand All @@ -74,6 +75,9 @@ mod test {
dbg!(&id);
assert!(!id.is_empty());

let peer_cnt = waku_peer_count().unwrap();
dbg!(peer_cnt);

// test addresses, since we cannot start different instances of the node
let addresses = waku_listen_addresses().unwrap();
dbg!(&addresses);
Expand Down
6 changes: 5 additions & 1 deletion waku-bindings/src/node/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ pub fn waku_disconnect_peer_with_id(peer_id: &PeerId) -> Result<()> {
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_peer_count)
pub fn waku_peer_count() -> Result<usize> {
let response_ptr = unsafe { waku_sys::waku_peer_cnt() };
decode_and_free_response(response_ptr)
let num_str = decode_and_free_response::<String>(response_ptr)?;
let num = num_str
.parse::<u32>()
.map_err(|_| "could not convert peer count into u32".to_string())?;
usize::try_from(num).map_err(|_| "could not convert peer count into usize".to_string())
}

/// Waku peer supported protocol
Expand Down

0 comments on commit 00bf354

Please sign in to comment.