Skip to content

Commit

Permalink
fix: display IPv4 addresses for nodes with home-network off across pl…
Browse files Browse the repository at this point in the history
…atforms
  • Loading branch information
bochaco committed Feb 3, 2025
1 parent 58a9980 commit 8d22927
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ leptos_axum = { version = "0.7", optional = true }
leptos_meta = { version = "0.7" }
leptos_router = { version = "0.7" }
libp2p-identity = { version = "0.2", features = ["peerid","ed25519"], optional = true }
local-ip-address = { version = "0.6", optional = true }
rand = "0.8"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"], optional = true }
semver = { version = "1.0", optional = true }
Expand Down Expand Up @@ -75,6 +76,7 @@ ssr = [
"dep:lcd",
"dep:leptos_axum",
"dep:libp2p-identity",
"dep:local-ip-address",
"dep:reqwest",
"dep:semver",
"dep:sqlx",
Expand Down
4 changes: 3 additions & 1 deletion src/docker_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,12 @@ impl DockerClient {
logging::log!("Node peer id in container {id}: {peer_id:?}");

let ips = if get_ips {
let cmd = "hostname -I | sed 's/^[ \t]*//;s/[ \t]*$//;s/ /, /g'".to_string();
let cmd = "ip -4 addr show | awk '/inet / {print $2}' | cut -d/ -f1 | paste -sd ' '"
.to_string();
let (_, ips) = self
.exec_in_container(id, cmd, "get node network IPs")
.await?;
let ips = ips.trim().replace(' ', ", ");
logging::log!("Node IPs in container {id}: {ips}");
Some(ips)
} else {
Expand Down
20 changes: 10 additions & 10 deletions src/node_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bytes::Bytes;
use futures_util::Stream;
use leptos::logging;
use libp2p_identity::{Keypair, PeerId};
use local_ip_address::list_afinet_netifas;
use semver::Version;
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -313,16 +314,15 @@ impl NodeManager {
logging::log!("Peer id in node {id}: {peer_id:?}");

let ips = if get_ips {
// FIXME: this is not cross platform
let mut cmd = Command::new("hostname");
cmd.arg("-I");
match self.exec_cmd(&mut cmd, "get node network IPs") {
Ok(output) => {
let ips = String::from_utf8_lossy(&output.stdout)
.to_string()
.trim()
.replace(' ', ", ");
logging::log!("IPs in host: {ips}");
match list_afinet_netifas() {
Ok(network_interfaces) => {
let ips = network_interfaces
.into_iter()
.filter(|(_, ip)| ip.is_ipv4())
.map(|(_, ip)| ip.to_string())
.collect::<Vec<_>>()
.join(", ");
logging::log!("IPv4 addresses in host: {ips}");
Some(ips)
}
Err(err) => {
Expand Down

0 comments on commit 8d22927

Please sign in to comment.