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 <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2023-03-01 15:44:53 +00:00 committed by Alexis Sellier
parent 1f837c6572
commit f322305f86
No known key found for this signature in database
2 changed files with 13 additions and 3 deletions

View File

@ -90,7 +90,12 @@ fn command<H: Handle<Error = runtime::HandleError>>(
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)?;

View File

@ -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<Seeds, Error> {