mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 18:40:39 +08:00
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:
committed by
Fintan Halpenny
parent
76e00a34ea
commit
895ca5d025
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user