Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions iroh/src/magicsock/node_map/node_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 19 additions & 5 deletions iroh/src/magicsock/node_map/udp_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
);
Comment on lines +127 to +131
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would be fitting to promote these to be events.

FWIW, we also have "new connection type" events that contain the send addr, but this additionally prints whether we think this is an outdated, valid or unconfirmed address.

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
Expand Down
Loading