Skip to content

Commit bcb60d4

Browse files
authored
fix(iroh): Only clear last_call_me_maybe when the best addr became invalid (#3415)
## Description Fixes a bug introduced in #3400 We used to only reset `last_call_me_maybe` to `None` when the best address was cleared. The above PR accidentally changed that to always reset. ## Change checklist <!-- Remove any that are not relevant. --> - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant.
1 parent a8485ad commit bcb60d4

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

iroh/src/magicsock/node_map/node_state.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,12 @@ impl NodeState {
10251025
}
10261026
}
10271027
}
1028-
// Clear trust on our best_addr if it is not included in the updated set. Also
1029-
// clear the last call-me-maybe send time so we will send one again.
1030-
self.udp_paths.update_to_best_addr(now);
1031-
self.last_call_me_maybe = None;
1028+
// Clear trust on our best_addr if it is not included in the updated set.
1029+
let changed = self.udp_paths.update_to_best_addr(now);
1030+
if changed {
1031+
// Clear the last call-me-maybe send time so we will send one again.
1032+
self.last_call_me_maybe = None;
1033+
}
10321034
debug!(
10331035
paths = %summarize_node_paths(&self.udp_paths.paths),
10341036
"updated endpoint paths from call-me-maybe",

iroh/src/magicsock/node_map/udp_paths.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::{collections::BTreeMap, net::SocketAddr};
99

1010
use n0_future::time::Instant;
11-
use tracing::debug;
11+
use tracing::{Level, event};
1212

1313
use super::{IpPort, path_state::PathState};
1414

@@ -114,20 +114,34 @@ impl NodeUdpPaths {
114114
&self.best
115115
}
116116

117-
/// Change the current best address(es) to ones chosen as described in [`Self::best_addr`] docs.
117+
/// Changes the current best address(es) to ones chosen as described in [`Self::best_addr`] docs.
118+
///
119+
/// Returns whether one of the best addresses had to change.
118120
///
119121
/// This should be called any time that `paths` is modified.
120-
pub(super) fn update_to_best_addr(&mut self, now: Instant) {
122+
pub(super) fn update_to_best_addr(&mut self, now: Instant) -> bool {
121123
let best_ipv4 = self.best_addr(false, now);
122124
let best = self.best_addr(true, now);
125+
let mut changed = false;
123126
if best_ipv4 != self.best_ipv4 {
124-
debug!(?best_ipv4, "update best addr (IPv4)");
127+
event!(
128+
target: "iroh::_events::udp::best_ipv4",
129+
Level::DEBUG,
130+
?best_ipv4,
131+
);
132+
changed = true;
125133
}
126134
if best != self.best {
127-
debug!(?best, "update best addr (IPv4 or IPv6)");
135+
event!(
136+
target: "iroh::_events::udp::best",
137+
Level::DEBUG,
138+
?best,
139+
);
140+
changed = true;
128141
}
129142
self.best_ipv4 = best_ipv4;
130143
self.best = best;
144+
changed
131145
}
132146

133147
/// Returns the current best address of all available paths, ignoring

0 commit comments

Comments
 (0)