Skip to content

Commit e4bc650

Browse files
authored
Use if-addrs instead of local_ip_address (#8659)
Swaps out the `local_ip_address` dependency for `if-addrs`. The reason for this is that is that `local_ip_address` is a relatively heavy dependency (depends on `neli`) compared to `if-addrs` and we only use it to check the presence of an IPv6 interface. This is an experiment to see if we can use the more lightweight `if-addrs` instead. Co-Authored-By: Mac L <mjladson@pm.me>
1 parent bb133d5 commit e4bc650

File tree

3 files changed

+18
-92
lines changed

3 files changed

+18
-92
lines changed

Cargo.lock

Lines changed: 12 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon_node/lighthouse_network/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fixed_bytes = { workspace = true }
2222
fnv = { workspace = true }
2323
futures = { workspace = true }
2424
hex = { workspace = true }
25+
if-addrs = "0.14"
2526
itertools = { workspace = true }
2627
libp2p = { workspace = true }
2728
libp2p-mplex = { git = "https://github.com/libp2p/rust-libp2p.git" }
2829
lighthouse_version = { workspace = true }
29-
local-ip-address = "0.6"
3030
logging = { workspace = true }
3131
lru = { workspace = true }
3232
lru_cache = { workspace = true }

beacon_node/lighthouse_network/src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::{Enr, PeerIdSerialized};
55
use directory::{
66
DEFAULT_BEACON_NODE_DIR, DEFAULT_HARDCODED_NETWORK, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR,
77
};
8+
use if_addrs::get_if_addrs;
89
use libp2p::{Multiaddr, gossipsub};
9-
use local_ip_address::local_ipv6;
1010
use network_utils::listen_addr::{ListenAddr, ListenAddress};
1111
use serde::{Deserialize, Serialize};
1212
use sha2::{Digest, Sha256};
@@ -262,13 +262,13 @@ impl Config {
262262
/// A helper function to check if the local host has a globally routeable IPv6 address. If so,
263263
/// returns true.
264264
pub fn is_ipv6_supported() -> bool {
265-
// If IPv6 is supported
266-
let Ok(std::net::IpAddr::V6(local_ip)) = local_ipv6() else {
265+
let Ok(addrs) = get_if_addrs() else {
267266
return false;
268267
};
269268

270-
// If its globally routable, return true
271-
is_global_ipv6(&local_ip)
269+
addrs.iter().any(
270+
|iface| matches!(iface.addr, if_addrs::IfAddr::V6(ref v6) if is_global_ipv6(&v6.ip)),
271+
)
272272
}
273273

274274
pub fn listen_addrs(&self) -> &ListenAddress {

0 commit comments

Comments
 (0)