cli: rad node connect using only NodeId

Allow the `rad node connect` command to use only a `NodeId` when connecting.

The `NodeId` is used to connect to known addresses, and will stop at the first
address that is connected to.
This commit is contained in:
Johannes Kühlewindt
2025-07-03 12:13:49 +01:00
committed by Fintan Halpenny
parent 76e00a34ea
commit 895ca5d025
3 changed files with 126 additions and 7 deletions
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::ffi::OsString;
use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, Read, Seek, SeekFrom};
@@ -205,6 +206,46 @@ pub fn connect(
Ok(())
}
pub fn connect_many(
node: &mut Node,
nid: NodeId,
addrs: Vec<Address>,
timeout: time::Duration,
) -> anyhow::Result<()> {
let mut spinner = term::spinner("Connecting...");
let mut errors = HashMap::new();
for addr in addrs {
spinner.message(format!(
"Connecting to {}@{addr}...",
term::format::node(&nid)
));
match node.connect(
nid,
addr.clone(),
node::ConnectOptions {
persistent: true,
timeout,
},
) {
Ok(ConnectResult::Connected) => {
spinner.finish();
return Ok(());
}
Ok(ConnectResult::Disconnected { reason }) => {
errors.insert(addr, reason);
}
Err(err) => {
errors.insert(addr, err.to_string());
}
}
}
spinner.failed();
for (addr, err) in errors {
term::error(format!("Failed to connect to {addr}: {err}"));
}
Ok(())
}
pub fn status(node: &Node, profile: &Profile) -> anyhow::Result<()> {
for warning in crate::warning::nodes_renamed(&profile.config) {
term::warning(warning);