Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: format ipv6 addresses in square brackets
✗ CI failure Defelo committed 2 months ago
commit 90cd259815ab01f9b3a23c4b4fc8569f2e3e62cb
parent 33b5754c05612056491b5bee2b7df26d6c2edc67
1 failed (1 total) View logs
2 files changed +16 -2
modified crates/radicle-cli/src/terminal/format.rs
@@ -1,4 +1,5 @@
use std::fmt;
+
use std::net::IpAddr;

use localtime::LocalTime;

@@ -35,7 +36,8 @@ pub fn node_id_human(node: &NodeId) -> Paint<String> {
#[must_use]
pub fn addr_compact(address: &Address) -> Paint<String> {
    let host = match address.host() {
-
        HostName::Ip(ip) => ip.to_string(),
+
        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();
modified crates/radicle/src/node.rs
@@ -17,6 +17,7 @@ pub mod sync;
pub mod timestamp;

use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
+
use std::fmt::Display;
use std::io::{BufRead, BufReader};
use std::marker::PhantomData;
use std::net::Ipv6Addr;
@@ -423,7 +424,7 @@ impl TryFrom<&sqlite::Value> for Alias {

/// Peer public protocol address.
#[derive(Clone, Eq, PartialEq, Debug, Hash, From, Wrapper, WrapperMut, Serialize, Deserialize)]
-
#[wrapper(Deref, Display)]
+
#[wrapper(Deref)]
#[wrapper_mut(DerefMut)]
#[cfg_attr(
    feature = "schemars",
@@ -491,6 +492,17 @@ impl Address {
    }
}

+
impl Display for Address {
+
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+
        match self.host() {
+
            HostName::Ip(net::IpAddr::V6(ip)) => {
+
                write!(f, "[{ip}]:{}", self.port())
+
            }
+
            _ => self.0.fmt(f),
+
        }
+
    }
+
}
+

impl FromStr for Address {
    type Err = AddrParseError;