Pipe peers methods to waku node handle

This commit is contained in:
Daniel Sanchez Quiros 2022-10-03 19:20:00 +02:00
parent fb6a2c4950
commit 70b7792c53
1 changed files with 35 additions and 1 deletions

View File

@ -6,11 +6,13 @@ mod peers;
use multiaddr::Multiaddr;
use std::marker::PhantomData;
use std::sync::Mutex;
use std::time::Duration;
// crates
// internal
use crate::general::Result;
use crate::general::{PeerId, Result};
pub use config::WakuNodeConfig;
pub use peers::{Protocol, WakuPeerData, WakuPeers};
/// Shared flag to check if a waku node is already running in the current process
static WAKU_NODE_INITIALIZED: Mutex<bool> = Mutex::new(false);
@ -37,6 +39,10 @@ impl<State: WakuNodeState> WakuNodeHandle<State> {
pub fn listen_addresses(&self) -> Result<Vec<Multiaddr>> {
management::waku_listen_addressses()
}
pub fn add_peer(&mut self, address: Multiaddr, protocol_id: usize) -> Result<PeerId> {
peers::waku_add_peers(address, protocol_id)
}
}
fn stop_node() -> Result<()> {
let mut node_initialized = WAKU_NODE_INITIALIZED
@ -60,6 +66,34 @@ impl WakuNodeHandle<Running> {
pub fn stop(self) -> Result<()> {
stop_node()
}
pub fn connect_peer_with_address(
&mut self,
address: Multiaddr,
timeout: Option<Duration>,
) -> Result<()> {
peers::waku_connect_peer_with_address(address, timeout)
}
pub fn connect_peer_with_id(
&mut self,
peer_id: PeerId,
timeout: Option<Duration>,
) -> Result<()> {
peers::waku_connect_peer_with_id(peer_id, timeout)
}
pub fn disconnect_peer_with_id(&mut self, peer_id: PeerId) -> Result<()> {
peers::waku_disconnect_peer_with_id(peer_id)
}
pub fn peer_count(&self) -> Result<usize> {
peers::waku_peer_count()
}
pub fn peers(&self) -> Result<WakuPeers> {
peers::waku_peers()
}
}
pub fn waku_new(config: Option<WakuNodeConfig>) -> Result<WakuNodeHandle<Initialized>> {