From db41c5e6f37e9ee50b27b5c4c7bb6053869ac8a3 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 18 Jan 2024 11:15:03 +0100 Subject: [PATCH] refactor(iroh-net): Log best addr on debug if not changed (#1958) ## Description The best addr is renewed every few seconds, always logging this on info level floods the info log. Now we log it on debug if the address has not changed. Logging that is still useful since it shows how long the validity is and the latency. ## Notes & open questions ## Change checklist - [x] Self-review. Co-authored-by: Friedel Ziegelmayer --- iroh-net/src/magicsock/peer_map/best_addr.rs | 28 +++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/iroh-net/src/magicsock/peer_map/best_addr.rs b/iroh-net/src/magicsock/peer_map/best_addr.rs index 1e37a4ac1b..2cd5625124 100644 --- a/iroh-net/src/magicsock/peer_map/best_addr.rs +++ b/iroh-net/src/magicsock/peer_map/best_addr.rs @@ -6,7 +6,7 @@ use std::{ }; use iroh_metrics::inc; -use tracing::info; +use tracing::{debug, info}; use crate::magicsock::metrics::Metrics as MagicsockMetrics; @@ -149,12 +149,26 @@ impl BestAddr { ) { let trust_until = source.trust_until(confirmed_at); - info!( - %addr, - latency = ?latency, - trust_for = ?trust_until.duration_since(Instant::now()), - "new best_addr" - ); + if self + .0 + .as_ref() + .map(|prev| prev.addr.addr == addr) + .unwrap_or_default() + { + debug!( + %addr, + latency = ?latency, + trust_for = ?trust_until.duration_since(Instant::now()), + "new best_addr" + ); + } else { + info!( + %addr, + latency = ?latency, + trust_for = ?trust_until.duration_since(Instant::now()), + "new best_addr" + ); + } let was_empty = self.is_empty(); let inner = BestAddrInner { addr: AddrLatency { addr, latency },