mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-27 08:08:15 -05:00
chore: Log an error when failing to resolve external ip address (#11085)
Co-authored-by: garwah <garwah@garwah>
This commit is contained in:
@@ -25,7 +25,7 @@ use std::{
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
use tracing::error;
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::net_if::resolve_net_if_ip;
|
||||
#[cfg(feature = "serde")]
|
||||
@@ -191,20 +191,30 @@ pub async fn external_addr_with(resolver: NatResolver) -> Option<IpAddr> {
|
||||
match resolver {
|
||||
NatResolver::Any | NatResolver::Upnp | NatResolver::PublicIp => resolve_external_ip().await,
|
||||
NatResolver::ExternalIp(ip) => Some(ip),
|
||||
NatResolver::NetIf => match resolve_net_if_ip(DEFAULT_NET_IF_NAME) {
|
||||
Ok(ip) => Some(ip),
|
||||
Err(err) => {
|
||||
error!("Failed to resolve network interface IP: {}", err);
|
||||
None
|
||||
}
|
||||
},
|
||||
NatResolver::NetIf => resolve_net_if_ip(DEFAULT_NET_IF_NAME)
|
||||
.inspect_err(|err| {
|
||||
debug!(target: "net::nat",
|
||||
%err,
|
||||
"Failed to resolve network interface IP"
|
||||
);
|
||||
})
|
||||
.ok(),
|
||||
NatResolver::None => None,
|
||||
}
|
||||
}
|
||||
|
||||
async fn resolve_external_ip() -> Option<IpAddr> {
|
||||
let futures = EXTERNAL_IP_APIS.iter().copied().map(resolve_external_ip_url_res).map(Box::pin);
|
||||
futures_util::future::select_ok(futures).await.ok().map(|(res, _)| res)
|
||||
futures_util::future::select_ok(futures)
|
||||
.await
|
||||
.inspect_err(|err| {
|
||||
debug!(target: "net::nat",
|
||||
?err,
|
||||
external_ip_apis=?EXTERNAL_IP_APIS,
|
||||
"Failed to resolve external IP from any API");
|
||||
})
|
||||
.ok()
|
||||
.map(|(ip, _)| ip)
|
||||
}
|
||||
|
||||
async fn resolve_external_ip_url_res(url: &str) -> Result<IpAddr, ()> {
|
||||
|
||||
Reference in New Issue
Block a user