Skip to content

Commit

Permalink
node: add Node::join method
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 22, 2024
1 parent 858731e commit 20d0d51
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/node/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::collections::{HashMap, VecDeque};
use std::io::Write;
use std::os::fd::{AsRawFd, RawFd};
use std::sync::Arc;
use std::{io, net};
use std::{io, net, thread};

use cyphernet::addr::Addr;
use reactor::poller::popol;
Expand Down Expand Up @@ -663,18 +663,21 @@ impl Node {
L: NetListener<Stream = S::Connection> + 'static,
C: NodeController<<S::Connection as NetConnection>::Addr, S, L> + 'static,
>(
note_id: <S::Artifact as Artifact>::NodeId,
node_id: <S::Artifact as Artifact>::NodeId,
delegate: C,
listen: impl IntoIterator<Item = NetAccept<S, L>>,
) -> io::Result<Self> {
let mut service = NodeService::<S, L, C>::new(note_id, delegate);
let mut service = NodeService::<S, L, C>::new(node_id, delegate);
for socket in listen {
service.listen(socket);
}
let reactor = Reactor::named(service, popol::Poller::new(), s!("node-service"))?;
Ok(Self { reactor })
}

/// Joins the reactor thread.
pub fn join(self) -> thread::Result<()> { self.reactor.join() }

/// Terminates the node, closing all connections, unbinding listeners and stopping the reactor
/// thread.
pub fn terminate(self) -> Result<(), Box<dyn Any + Send>> {
Expand Down

0 comments on commit 20d0d51

Please sign in to comment.