From f322305f86ed4a8288f86f861313c51afab80e91 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 1 Mar 2023 15:44:53 +0000 Subject: [PATCH] node: wire up connect command The connect command was unimplemented for both Node and the control socket. This wires up the connect functionality in both places. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-node/src/control.rs | 7 ++++++- radicle/src/node.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/radicle-node/src/control.rs b/radicle-node/src/control.rs index 2fb2542c..7ed48c7c 100644 --- a/radicle-node/src/control.rs +++ b/radicle-node/src/control.rs @@ -90,7 +90,12 @@ fn command>( match cmd.name { CommandName::Connect => { - todo!(); + let (nid, addr) = parse::args(cmd)?; + if let Err(e) = handle.connect(nid, addr) { + return Err(CommandError::Runtime(e)); + } else { + CommandResult::Okay { updated: true }.to_writer(writer)?; + } } CommandName::Fetch => { let (rid, nid): (Id, NodeId) = parse::args(cmd)?; diff --git a/radicle/src/node.rs b/radicle/src/node.rs index 495cab54..95809eed 100644 --- a/radicle/src/node.rs +++ b/radicle/src/node.rs @@ -479,8 +479,13 @@ impl Handle for Node { matches!(result, CommandResult::Okay { .. }) } - fn connect(&mut self, _node: NodeId, _addr: Address) -> Result<(), Error> { - todo!() + fn connect(&mut self, nid: NodeId, addr: Address) -> Result<(), Error> { + self.call::<_, CommandResult>(CommandName::Connect, [nid.to_human(), addr.to_string()])? + .next() + .ok_or(Error::EmptyResponse { + cmd: CommandName::Connect, + })??; + Ok(()) } fn seeds(&mut self, id: Id) -> Result {