cli: Format IPv6 addresses in square brackets
This commit is contained in:
parent
df8e4e6c88
commit
9ff67562cb
|
|
@ -384,17 +384,17 @@ pub fn sessions(node: &Node) -> Result<Option<term::Table<5, term::Label>>, node
|
||||||
term::Label::blank(),
|
term::Label::blank(),
|
||||||
),
|
),
|
||||||
node::State::Attempted => (
|
node::State::Attempted => (
|
||||||
term::format::addr_compact(&sess.addr).into(),
|
sess.addr.display_compact().to_string().into(),
|
||||||
term::Label::from(state_attempted()),
|
term::Label::from(state_attempted()),
|
||||||
term::Label::blank(),
|
term::Label::blank(),
|
||||||
),
|
),
|
||||||
node::State::Connected { since, .. } => (
|
node::State::Connected { since, .. } => (
|
||||||
term::format::addr_compact(&sess.addr).into(),
|
sess.addr.display_compact().to_string().into(),
|
||||||
term::Label::from(state_connected()),
|
term::Label::from(state_connected()),
|
||||||
term::format::dim(now - since).into(),
|
term::format::dim(now - since).into(),
|
||||||
),
|
),
|
||||||
node::State::Disconnected { since, .. } => (
|
node::State::Disconnected { since, .. } => (
|
||||||
term::format::addr_compact(&sess.addr).into(),
|
sess.addr.display_compact().to_string().into(),
|
||||||
term::Label::from(state_disconnected()),
|
term::Label::from(state_disconnected()),
|
||||||
term::format::dim(now - since).into(),
|
term::format::dim(now - since).into(),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -460,7 +460,7 @@ impl FetcherSpinner {
|
||||||
term::format::secondary(progress.succeeded()),
|
term::format::secondary(progress.succeeded()),
|
||||||
term::format::secondary(self.replicas.lower_bound()),
|
term::format::secondary(self.replicas.lower_bound()),
|
||||||
term::format::tertiary(term::format::node_id_human_compact(node)),
|
term::format::tertiary(term::format::node_id_human_compact(node)),
|
||||||
term::format::tertiary(term::format::addr_compact(addr)),
|
term::format::tertiary(addr.display_compact()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -477,7 +477,7 @@ impl FetcherSpinner {
|
||||||
term::format::secondary(progress.succeeded()),
|
term::format::secondary(progress.succeeded()),
|
||||||
term::format::secondary(self.replicas.lower_bound()),
|
term::format::secondary(self.replicas.lower_bound()),
|
||||||
term::format::tertiary(term::format::node_id_human_compact(node)),
|
term::format::tertiary(term::format::node_id_human_compact(node)),
|
||||||
term::format::tertiary(term::format::addr_compact(addr)),
|
term::format::tertiary(addr.display_compact()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub use radicle_term::{style, Paint};
|
||||||
use radicle::cob::ObjectId;
|
use radicle::cob::ObjectId;
|
||||||
use radicle::identity::Visibility;
|
use radicle::identity::Visibility;
|
||||||
use radicle::node::policy::Policy;
|
use radicle::node::policy::Policy;
|
||||||
use radicle::node::{Address, Alias, AliasStore, HostName, NodeId};
|
use radicle::node::{Alias, AliasStore, NodeId};
|
||||||
use radicle::prelude::Did;
|
use radicle::prelude::Did;
|
||||||
use radicle::profile::{env, Profile};
|
use radicle::profile::{env, Profile};
|
||||||
use radicle::storage::RefUpdate;
|
use radicle::storage::RefUpdate;
|
||||||
|
|
@ -32,28 +32,6 @@ pub fn node_id_human(node: &NodeId) -> Paint<String> {
|
||||||
Paint::new(node.to_human())
|
Paint::new(node.to_human())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn addr_compact(address: &Address) -> Paint<String> {
|
|
||||||
let host = match address.host() {
|
|
||||||
HostName::Ip(ip) => ip.to_string(),
|
|
||||||
HostName::Dns(dns) => dns.clone(),
|
|
||||||
HostName::Tor(onion) => {
|
|
||||||
let onion = onion.to_string();
|
|
||||||
let start = onion.chars().take(8).collect::<String>();
|
|
||||||
let end = onion
|
|
||||||
.chars()
|
|
||||||
.skip(onion.len() - 8 - ".onion".len())
|
|
||||||
.collect::<String>();
|
|
||||||
format!("{start}…{end}")
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let port = address.port().to_string();
|
|
||||||
|
|
||||||
Paint::new(format!("{host}:{port}"))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Format a git Oid.
|
/// Format a git Oid.
|
||||||
pub fn oid(oid: impl Into<radicle::git::Oid>) -> Paint<String> {
|
pub fn oid(oid: impl Into<radicle::git::Oid>) -> Paint<String> {
|
||||||
Paint::new(format!("{:.7}", oid.into()))
|
Paint::new(format!("{:.7}", oid.into()))
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ pub mod sync;
|
||||||
pub mod timestamp;
|
pub mod timestamp;
|
||||||
|
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
|
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
|
||||||
|
use std::fmt::Display;
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
@ -424,7 +425,7 @@ impl TryFrom<&sqlite::Value> for Alias {
|
||||||
|
|
||||||
/// Peer public protocol address.
|
/// Peer public protocol address.
|
||||||
#[derive(Clone, Eq, PartialEq, Debug, Hash, From, Wrapper, WrapperMut, Serialize, Deserialize)]
|
#[derive(Clone, Eq, PartialEq, Debug, Hash, From, Wrapper, WrapperMut, Serialize, Deserialize)]
|
||||||
#[wrapper(Deref, Display)]
|
#[wrapper(Deref)]
|
||||||
#[wrapper_mut(DerefMut)]
|
#[wrapper_mut(DerefMut)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "schemars",
|
feature = "schemars",
|
||||||
|
|
@ -490,6 +491,39 @@ impl Address {
|
||||||
pub fn port(&self) -> u16 {
|
pub fn port(&self) -> u16 {
|
||||||
self.0.port
|
self.0.port
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn display_compact(&self) -> impl Display {
|
||||||
|
let host = match self.host() {
|
||||||
|
HostName::Ip(IpAddr::V4(ip)) => ip.to_string(),
|
||||||
|
HostName::Ip(IpAddr::V6(ip)) => format!("[{ip}]"),
|
||||||
|
HostName::Dns(dns) => dns.clone(),
|
||||||
|
HostName::Tor(onion) => {
|
||||||
|
let onion = onion.to_string();
|
||||||
|
let start = onion.chars().take(8).collect::<String>();
|
||||||
|
let end = onion
|
||||||
|
.chars()
|
||||||
|
.skip(onion.len() - 8 - ".onion".len())
|
||||||
|
.collect::<String>();
|
||||||
|
format!("{start}…{end}")
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let port = self.port().to_string();
|
||||||
|
|
||||||
|
format!("{host}:{port}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Address {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self.host() {
|
||||||
|
HostName::Ip(IpAddr::V6(ip)) => {
|
||||||
|
write!(f, "[{ip}]:{}", self.port())
|
||||||
|
}
|
||||||
|
_ => self.0.fmt(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Address {
|
impl FromStr for Address {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue