fix: waku_peer_count conversion to usize

This commit is contained in:
Richard Ramos 2023-10-01 15:23:50 -04:00
parent 32bd05c6fc
commit e17cb311a3
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
2 changed files with 9 additions and 1 deletions

View File

@ -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]
@ -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);

View File

@ -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