diff --git a/iroh/src/magicsock/node_map/node_state.rs b/iroh/src/magicsock/node_map/node_state.rs index 13278c3367..5a84f5ae37 100644 --- a/iroh/src/magicsock/node_map/node_state.rs +++ b/iroh/src/magicsock/node_map/node_state.rs @@ -1025,10 +1025,12 @@ impl NodeState { } } } - // Clear trust on our best_addr if it is not included in the updated set. Also - // clear the last call-me-maybe send time so we will send one again. - self.udp_paths.update_to_best_addr(now); - self.last_call_me_maybe = None; + // Clear trust on our best_addr if it is not included in the updated set. + let changed = self.udp_paths.update_to_best_addr(now); + if changed { + // Clear the last call-me-maybe send time so we will send one again. + self.last_call_me_maybe = None; + } debug!( paths = %summarize_node_paths(&self.udp_paths.paths), "updated endpoint paths from call-me-maybe", diff --git a/iroh/src/magicsock/node_map/udp_paths.rs b/iroh/src/magicsock/node_map/udp_paths.rs index 5f09dc3344..29c43ccc99 100644 --- a/iroh/src/magicsock/node_map/udp_paths.rs +++ b/iroh/src/magicsock/node_map/udp_paths.rs @@ -8,7 +8,7 @@ use std::{collections::BTreeMap, net::SocketAddr}; use n0_future::time::Instant; -use tracing::debug; +use tracing::{Level, event}; use super::{IpPort, path_state::PathState}; @@ -114,20 +114,34 @@ impl NodeUdpPaths { &self.best } - /// Change the current best address(es) to ones chosen as described in [`Self::best_addr`] docs. + /// Changes the current best address(es) to ones chosen as described in [`Self::best_addr`] docs. + /// + /// Returns whether one of the best addresses had to change. /// /// This should be called any time that `paths` is modified. - pub(super) fn update_to_best_addr(&mut self, now: Instant) { + pub(super) fn update_to_best_addr(&mut self, now: Instant) -> bool { let best_ipv4 = self.best_addr(false, now); let best = self.best_addr(true, now); + let mut changed = false; if best_ipv4 != self.best_ipv4 { - debug!(?best_ipv4, "update best addr (IPv4)"); + event!( + target: "iroh::_events::udp::best_ipv4", + Level::DEBUG, + ?best_ipv4, + ); + changed = true; } if best != self.best { - debug!(?best, "update best addr (IPv4 or IPv6)"); + event!( + target: "iroh::_events::udp::best", + Level::DEBUG, + ?best, + ); + changed = true; } self.best_ipv4 = best_ipv4; self.best = best; + changed } /// Returns the current best address of all available paths, ignoring