feat: add listen addresses
This commit is contained in:
parent
9c696e6097
commit
79b8428bb5
|
@ -3,7 +3,8 @@ name = "waku-bindings"
|
|||
version = "0.5.0"
|
||||
edition = "2021"
|
||||
authors = [
|
||||
"Daniel Sanchez Quiros <danielsq@status.im>"
|
||||
"Daniel Sanchez Quiros <danielsq@status.im>",
|
||||
"Richard Ramos <richard@waku.org>"
|
||||
]
|
||||
description = "Waku networking library"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
use std::ffi::CString;
|
||||
// crates
|
||||
use libc::c_void;
|
||||
use multiaddr::Multiaddr;
|
||||
// internal
|
||||
use super::config::WakuNodeConfig;
|
||||
use crate::general::Result;
|
||||
|
@ -33,13 +34,11 @@ pub fn waku_new(config: Option<WakuNodeConfig>) -> Result<*mut c_void> {
|
|||
out
|
||||
};
|
||||
|
||||
// TODO: create error handler function, format of err message is
|
||||
// {"message":"The actual message","eventType":"error"}
|
||||
if !error.is_empty() {
|
||||
return Err(error);
|
||||
return if !error.is_empty() {
|
||||
Err(error)
|
||||
} else {
|
||||
Ok(node_ptr)
|
||||
}
|
||||
|
||||
Ok(node_ptr)
|
||||
}
|
||||
|
||||
/// Start a Waku node mounting all the protocols that were enabled during the Waku node instantiation.
|
||||
|
@ -84,10 +83,24 @@ pub fn waku_version(ctx: *mut c_void) -> Result<String> {
|
|||
handle_response(code, &result)
|
||||
}
|
||||
|
||||
/// Get the multiaddresses the Waku node is listening to
|
||||
/// as per [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_listen_addresses)
|
||||
pub fn waku_listen_addresses(ctx: *mut c_void) -> Result<Vec<Multiaddr>> {
|
||||
let mut result: String = Default::default();
|
||||
let result_cb = |v: &str| result = v.to_string();
|
||||
let code = unsafe {
|
||||
let mut closure = result_cb;
|
||||
let cb = get_trampoline(&closure);
|
||||
waku_sys::waku_listen_addresses(ctx, cb, &mut closure as *mut _ as *mut c_void)
|
||||
};
|
||||
|
||||
handle_json_response(code, &result)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::waku_new;
|
||||
use crate::node::management::{waku_start, waku_stop, waku_version};
|
||||
use crate::node::management::{waku_start, waku_stop, waku_listen_addresses, waku_version};
|
||||
use serial_test::serial;
|
||||
|
||||
#[test]
|
||||
|
@ -97,6 +110,11 @@ mod test {
|
|||
|
||||
waku_start(node).unwrap();
|
||||
|
||||
// test addresses
|
||||
let addresses = waku_listen_addresses(node).unwrap();
|
||||
dbg!(&addresses);
|
||||
assert!(!addresses.is_empty());
|
||||
|
||||
waku_stop(node).unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,12 @@ impl WakuNodeHandle {
|
|||
management::waku_stop(self.ctx)
|
||||
}
|
||||
|
||||
/// Get the multiaddresses the Waku node is listening to
|
||||
/// as per [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_listen_addresses)
|
||||
pub fn listen_addresses(&self) -> Result<Vec<Multiaddr>> {
|
||||
management::waku_listen_addresses(self.ctx)
|
||||
}
|
||||
|
||||
/// Get the nwaku version
|
||||
pub fn version(&self) -> Result<String> {
|
||||
management::waku_version(self.ctx)
|
||||
|
|
Loading…
Reference in New Issue