From e3e406dcde3601fa3e699fa54da00ec9d4525200 Mon Sep 17 00:00:00 2001 From: fanyang Date: Mon, 4 Aug 2025 21:18:49 +0800 Subject: [PATCH] cli: sort peers by IPv4 and hostname (#1191) * cli: sort entries by IPv4 and hostname Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- easytier/src/connector/udp_hole_punch/sym_to_cone.rs | 2 +- easytier/src/easytier-cli.rs | 12 ++++++++++++ easytier/src/peer_center/instance.rs | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/easytier/src/connector/udp_hole_punch/sym_to_cone.rs b/easytier/src/connector/udp_hole_punch/sym_to_cone.rs index 95f7a0b..0a69034 100644 --- a/easytier/src/connector/udp_hole_punch/sym_to_cone.rs +++ b/easytier/src/connector/udp_hole_punch/sym_to_cone.rs @@ -342,7 +342,7 @@ impl PunchSymToConeHoleClient { async fn get_rpc_stub( &self, dst_peer_id: PeerId, - ) -> Box<(dyn UdpHolePunchRpc + std::marker::Send + 'static)> { + ) -> Box + std::marker::Send + 'static> { self.peer_mgr .get_peer_rpc_mgr() .rpc_client() diff --git a/easytier/src/easytier-cli.rs b/easytier/src/easytier-cli.rs index 608d616..c8de504 100644 --- a/easytier/src/easytier-cli.rs +++ b/easytier/src/easytier-cli.rs @@ -545,6 +545,18 @@ impl CommandHandler<'_> { items.push(p.into()); } + // Sort items by ipv4 (using IpAddr for proper numeric comparison) first, then by hostname + items.sort_by(|a, b| { + use std::net::{IpAddr, Ipv4Addr}; + use std::str::FromStr; + let a_ip = IpAddr::from_str(&a.ipv4).unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)); + let b_ip = IpAddr::from_str(&b.ipv4).unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)); + match a_ip.cmp(&b_ip) { + std::cmp::Ordering::Equal => a.hostname.cmp(&b.hostname), + other => other, + } + }); + print_output(&items, self.output_format)?; Ok(()) diff --git a/easytier/src/peer_center/instance.rs b/easytier/src/peer_center/instance.rs index d0a49a9..bda929d 100644 --- a/easytier/src/peer_center/instance.rs +++ b/easytier/src/peer_center/instance.rs @@ -96,13 +96,13 @@ impl PeerCenterBase { >( &self, job_ctx: T, - job_fn: (impl Fn( + job_fn: impl Fn( Box + Send>, Arc>, ) -> Fut + Send + Sync - + 'static), + + 'static, ) -> () { let my_peer_id = self.my_peer_id; let peer_mgr = self.peer_mgr.clone();