Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Add `Disconnect` command
Alexis Sellier committed 3 years ago
commit 448ef678338ee9a074e3eef0366dd275da06979c
parent 0bfc3f59ee383966cdd7a50fbba4509497921991
2 files changed +11 -1
modified radicle-node/src/runtime/handle.rs
@@ -114,7 +114,7 @@ impl Handle {
        self.controller.cmd(wire::Control::Flush { remote, stream })
    }

-
    fn command(&self, cmd: service::Command) -> Result<(), io::Error> {
+
    pub(crate) fn command(&self, cmd: service::Command) -> Result<(), io::Error> {
        self.controller.cmd(wire::Control::User(cmd))
    }
}
modified radicle-node/src/service.rs
@@ -126,6 +126,8 @@ pub enum Command {
    SyncInventory(chan::Sender<bool>),
    /// Connect to node with the given address.
    Connect(NodeId, Address),
+
    /// Disconnect from node.
+
    Disconnect(NodeId),
    /// Lookup seeds for the given repository in the routing table.
    Seeds(Id, chan::Sender<Seeds>),
    /// Fetch the given repository from the network.
@@ -149,6 +151,7 @@ impl fmt::Debug for Command {
            Self::AnnounceInventory => write!(f, "AnnounceInventory"),
            Self::SyncInventory(_) => write!(f, "SyncInventory(..)"),
            Self::Connect(id, addr) => write!(f, "Connect({id}, {addr})"),
+
            Self::Disconnect(id) => write!(f, "Disconnect({id})"),
            Self::Seeds(id, _) => write!(f, "Seeds({id})"),
            Self::Fetch(id, node, _) => write!(f, "Fetch({id}, {node})"),
            Self::TrackRepo(id, scope, _) => write!(f, "TrackRepo({id}, {scope})"),
@@ -466,6 +469,9 @@ where
            Command::Connect(nid, addr) => {
                self.connect(nid, addr);
            }
+
            Command::Disconnect(nid) => {
+
                self.reactor.disconnect(nid, DisconnectReason::Command);
+
            }
            Command::Seeds(rid, resp) => match self.seeds(&rid) {
                Ok(seeds) => {
                    resp.send(seeds).ok();
@@ -1547,6 +1553,8 @@ pub enum DisconnectReason {
    Fetch(FetchError),
    /// Session error.
    Session(session::Error),
+
    /// User requested disconnect
+
    Command,
}

impl DisconnectReason {
@@ -1564,6 +1572,7 @@ impl DisconnectReason {
        match self {
            Self::Dial(_) => false,
            Self::Connection(_) => true,
+
            Self::Command => false,
            Self::Fetch(_) => true,
            Self::Session(err) => err.is_transient(),
        }
@@ -1575,6 +1584,7 @@ impl fmt::Display for DisconnectReason {
        match self {
            Self::Dial(err) => write!(f, "{err}"),
            Self::Connection(err) => write!(f, "{err}"),
+
            Self::Command => write!(f, "command"),
            Self::Session(err) => write!(f, "{err}"),
            Self::Fetch(err) => write!(f, "fetch: {err}"),
        }