Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Implement `rad node stop`
Alexis Sellier committed 2 years ago
commit e32e28f8b4ce082bf078106e4556741a9133d54c
parent 0d0d354d557f5c13ef836c5d5c3001998ee8ba1c
3 files changed +15 -7
modified radicle-cli/src/commands/node/control.rs
@@ -44,9 +44,9 @@ pub fn start(daemon: bool, options: Vec<OsString>) -> anyhow::Result<()> {
}

pub fn stop(node: Node) -> anyhow::Result<()> {
-
    let spinner = term::spinner("Stopping the node...");
-
    if let Err(err) = node.shutdown() {
-
        spinner.error(format!("Error occurred while shutting down node: {err}"));
+
    let spinner = term::spinner("Stopping node...");
+
    if node.shutdown().is_err() {
+
        spinner.error("node is not running");
    } else {
        spinner.finish();
    }
modified radicle-node/src/control.rs
@@ -211,6 +211,7 @@ fn command<H: Handle<Error = runtime::HandleError> + 'static>(
            // Channel might already be disconnected if shutdown
            // came from somewhere else. Ignore errors.
            handle.shutdown().ok();
+
            CommandResult::ok().to_writer(writer).ok();
        }
    }
    Ok(())
modified radicle/src/node.rs
@@ -10,7 +10,7 @@ use std::io::{BufRead, BufReader};
use std::ops::Deref;
use std::os::unix::net::UnixStream;
use std::path::{Path, PathBuf};
-
use std::{fmt, io, net, time};
+
use std::{fmt, io, net, thread, time};

use amplify::WrapperMut;
use cyphernet::addr::{HostName, NetAddr};
@@ -697,7 +697,14 @@ impl Handle for Node {
    }

    fn shutdown(self) -> Result<(), Error> {
-
        todo!();
+
        for line in self.call::<&str, CommandResult>(CommandName::Shutdown, [], DEFAULT_TIMEOUT)? {
+
            line?;
+
        }
+
        // Wait until the shutdown has completed.
+
        while self.is_running() {
+
            thread::sleep(time::Duration::from_secs(1));
+
        }
+
        Ok(())
    }
}

@@ -709,7 +716,7 @@ pub trait AliasStore {

impl<T: AliasStore + ?Sized> AliasStore for &T {
    fn alias(&self, nid: &NodeId) -> Option<String> {
-
        dbg!((*self).alias(nid))
+
        (*self).alias(nid)
    }
}

@@ -721,7 +728,7 @@ impl<T: AliasStore + ?Sized> AliasStore for Box<T> {

impl AliasStore for HashMap<NodeId, String> {
    fn alias(&self, nid: &NodeId) -> Option<String> {
-
        dbg!(self.get(nid).map(ToOwned::to_owned))
+
        self.get(nid).map(ToOwned::to_owned)
    }
}