diff --git a/radicle-node/src/main.rs b/radicle-node/src/main.rs index aac84954..ea92fd6e 100644 --- a/radicle-node/src/main.rs +++ b/radicle-node/src/main.rs @@ -91,9 +91,8 @@ fn execute() -> anyhow::Result<()> { }; let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050); let daemon = ([0, 0, 0, 0], 9418).into(); - let runtime = Runtime::with(home, config, options.listen, proxy, daemon, signer)?; - runtime.run()?; + Runtime::init(home, config, options.listen, proxy, daemon, signer)?.run()?; Ok(()) } diff --git a/radicle-node/src/runtime.rs b/radicle-node/src/runtime.rs index 39272c46..aad89eb2 100644 --- a/radicle-node/src/runtime.rs +++ b/radicle-node/src/runtime.rs @@ -22,7 +22,7 @@ use crate::service::{routing, tracking}; use crate::wire; use crate::wire::Wire; use crate::worker::{WorkerPool, WorkerReq}; -use crate::{crypto, service, LocalTime}; +use crate::{service, LocalTime}; pub use handle::Error as HandleError; pub use handle::Handle; @@ -68,7 +68,6 @@ pub struct Runtime { pub id: NodeId, pub home: Home, pub handle: Handle, - pub control: thread::JoinHandle>, pub storage: Storage, pub reactor: Reactor>, pub daemon: net::SocketAddr, @@ -76,11 +75,11 @@ pub struct Runtime { pub local_addrs: Vec, } -impl Runtime { +impl Runtime { /// Initialize the runtime. /// /// This function spawns threads. - pub fn with( + pub fn init( home: Home, config: service::Config, listen: Vec, @@ -89,10 +88,9 @@ impl Runtime { signer: G, ) -> Result, Error> where - G: crypto::Signer + EcSign + Clone + 'static, + G: EcSign + Clone, { let id = *signer.public_key(); - let node_sock = home.socket(); let node_dir = home.node(); let network = config.network; let rng = fastrand::Rng::new(); @@ -144,24 +142,6 @@ impl Runtime { let reactor = Reactor::named(wire, popol::Poller::new(), id.to_human())?; let handle = Handle::new(home.clone(), reactor.controller()); - log::info!(target: "node", "Binding control socket {}..", node_sock.display()); - - // TODO: Move this stuff to `run` function. - - let listener = match UnixListener::bind(&node_sock) { - Ok(sock) => sock, - Err(err) if err.kind() == io::ErrorKind::AddrInUse => { - return Err(Error::AlreadyRunning(node_sock)); - } - Err(err) => { - return Err(err.into()); - } - }; - let control = thread::spawn({ - let handle = handle.clone(); - move || control::listen(listener, handle) - }); - let pool = WorkerPool::with( 8, time::Duration::from_secs(9), @@ -175,7 +155,6 @@ impl Runtime { Ok(Runtime { id, home, - control, storage, reactor, daemon, @@ -186,7 +165,22 @@ impl Runtime { } pub fn run(self) -> Result<(), Error> { - log::info!(target: "node", "Running node {}..", self.id); + let home = self.home; + + log::info!(target: "node", "Running node {} in {}..", self.id, home.path().display()); + log::info!(target: "node", "Binding control socket {}..", home.socket().display()); + + let listener = match UnixListener::bind(home.socket()) { + Ok(sock) => sock, + Err(err) if err.kind() == io::ErrorKind::AddrInUse => { + return Err(Error::AlreadyRunning(home.socket())); + } + Err(err) => { + return Err(err.into()); + } + }; + let control = thread::spawn(move || control::listen(listener, self.handle)); + log::info!(target: "node", "Spawning git daemon at {}..", self.storage.path().display()); let mut daemon = daemon::spawn(self.storage.path(), self.daemon)?; @@ -201,12 +195,12 @@ impl Runtime { self.pool.run().unwrap(); self.reactor.join().unwrap(); - self.control.join().unwrap()?; + control.join().unwrap()?; daemon.kill().ok(); // Ignore error if daemon has already exited, for whatever reason. daemon.wait()?; - fs::remove_file(self.home.socket()).ok(); + fs::remove_file(home.socket()).ok(); log::debug!(target: "node", "Node shutdown completed for {}", self.id); diff --git a/radicle-node/src/tests/e2e.rs b/radicle-node/src/tests/e2e.rs index 58d97876..cd1d7356 100644 --- a/radicle-node/src/tests/e2e.rs +++ b/radicle-node/src/tests/e2e.rs @@ -105,7 +105,7 @@ impl Node { let listen = vec![([0, 0, 0, 0], 0).into()]; let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050); let daemon = ([0, 0, 0, 0], fastrand::u16(1025..)).into(); - let rt = Runtime::with( + let rt = Runtime::init( self.home, config, listen,