diff --git a/Cargo.lock b/Cargo.lock index 7f4867379a..c7e2325bb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7172,6 +7172,7 @@ version = "0.1.0" dependencies = [ "clap", "clap-verbosity-flag", + "color-eyre", "futures", "libp2p", "sn_networking", diff --git a/sn_nat_detection/Cargo.toml b/sn_nat_detection/Cargo.toml index 32a135d9c9..a8365ccd9e 100644 --- a/sn_nat_detection/Cargo.toml +++ b/sn_nat_detection/Cargo.toml @@ -16,6 +16,7 @@ path = "src/main.rs" [dependencies] clap = { version = "4.5.4", features = ["derive"] } clap-verbosity-flag = "2.2.0" +color-eyre = { version = "0.6", default-features = false } futures = "~0.3.13" libp2p = { version = "0.53", features = ["tokio", "tcp", "noise", "yamux", "autonat", "identify", "macros", "upnp"] } sn_networking = { path = "../sn_networking", version = "0.15.2" } diff --git a/sn_nat_detection/src/behaviour/upnp.rs b/sn_nat_detection/src/behaviour/upnp.rs index e5f7c8bcbd..db39c5cbf9 100644 --- a/sn_nat_detection/src/behaviour/upnp.rs +++ b/sn_nat_detection/src/behaviour/upnp.rs @@ -8,16 +8,16 @@ impl App { pub(crate) fn on_event_upnp(&mut self, event: upnp::Event) { match event { upnp::Event::NewExternalAddr(addr) => { - info!(%addr, "UPnP: New external address detected"); + info!(%addr, "Successfully mapped UPnP port"); } upnp::Event::ExpiredExternalAddr(addr) => { - debug!(%addr, "UPnP: External address expired"); + debug!(%addr, "External UPnP port mapping expired"); } upnp::Event::GatewayNotFound => { - error!("UPnP: No gateway not found"); + error!("No UPnP gateway not found"); } upnp::Event::NonRoutableGateway => { - error!("UPnP: Gateway is not routable"); + error!("UPnP gateway is not routable"); } } } diff --git a/sn_nat_detection/src/main.rs b/sn_nat_detection/src/main.rs index bf48a7e3a5..dd721f2d21 100644 --- a/sn_nat_detection/src/main.rs +++ b/sn_nat_detection/src/main.rs @@ -7,13 +7,13 @@ // permissions and limitations relating to use of the SAFE Network Software. use clap::Parser; +use color_eyre::eyre::{eyre, Result}; use futures::StreamExt; use libp2p::autonat::NatStatus; use libp2p::core::{multiaddr::Protocol, Multiaddr}; use libp2p::swarm::SwarmEvent; use libp2p::{noise, tcp, yamux}; use std::collections::HashSet; -use std::error::Error; use std::net::Ipv4Addr; use std::time::Duration; use tracing::{debug, info, warn}; @@ -60,7 +60,9 @@ struct Opt { } #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> Result<()> { + color_eyre::install()?; + // Process command line arguments. let opt = Opt::parse(); @@ -104,10 +106,10 @@ async fn main() -> Result<(), Box> { builder = builder.upnp(true); running_with_upnp = true; } else { - break Err("NAT is private".into()); + break Err(eyre!("NAT is private")); } } - NatStatus::Unknown => break Err("NAT is unknown".into()), + NatStatus::Unknown => break Err(eyre!("NAT is unknown")), } } } @@ -180,9 +182,9 @@ impl App { // `SwarmEvent::Dialing` is only triggered when peer ID is included, so // we log here too to make sure we log that we're dialing a server. if let Err(e) = self.swarm.dial(addr.clone()) { - warn!(%addr, ?e, "failed to dial server"); + warn!(%addr, ?e, "Failed to dial server"); } else { - info!(%addr, "dialing server"); + info!(%addr, "Dialing server"); } } } @@ -206,7 +208,7 @@ impl App { info!( ?status, %confidence, - "confidence in NAT status {}", + "Confidence in NAT status {}", if confidence > old_confidence { "increased" } else { @@ -330,7 +332,7 @@ fn parse_peer_addr(addr: &str) -> Result { return Ok(addr); } - Err("could not parse address") + Err("Could not parse address") } struct AppBuilder { @@ -363,7 +365,7 @@ impl AppBuilder { self } - fn build(&self) -> Result> { + fn build(&self) -> Result { // If no servers are provided, we are in server mode. Conversely, with servers // provided, we are in client mode. let client_mode = !self.servers.is_empty(); @@ -391,7 +393,7 @@ impl AppBuilder { info!( peer_id=%swarm.local_peer_id(), - "starting in {} mode", + "Starting in {} mode", if client_mode { "client" } else { "server" } );