Skip to content

Commit c6b3906

Browse files
committed
fix: Only free up sending a call me maybe when the best addr was invalidated
1 parent b08df6a commit c6b3906

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

iroh/src/magicsock/node_map/node_state.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,12 @@ impl NodeState {
10371037
}
10381038
}
10391039
}
1040-
// Clear trust on our best_addr if it is not included in the updated set. Also
1041-
// clear the last call-me-maybe send time so we will send one again.
1042-
self.udp_paths.update_to_best_addr(now);
1043-
self.last_call_me_maybe = None;
1040+
// Clear trust on our best_addr if it is not included in the updated set.
1041+
let changed = self.udp_paths.update_to_best_addr(now);
1042+
if changed {
1043+
// Clear the last call-me-maybe send time so we will send one again.
1044+
self.last_call_me_maybe = None;
1045+
}
10441046
debug!(
10451047
paths = %summarize_node_paths(&self.udp_paths.paths),
10461048
"updated endpoint paths from call-me-maybe",

iroh/src/magicsock/node_map/udp_paths.rs

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

1010
use n0_future::time::Instant;
11+
use tracing::{event, Level};
1112

1213
use super::{path_state::PathState, IpPort};
1314

@@ -113,9 +114,34 @@ impl NodeUdpPaths {
113114
&self.best
114115
}
115116

116-
pub(super) fn update_to_best_addr(&mut self, now: Instant) {
117-
self.best_ipv4 = self.best_addr(false, now);
118-
self.best = self.best_addr(true, now);
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.
120+
///
121+
/// This should be called any time that `paths` is modified.
122+
pub(super) fn update_to_best_addr(&mut self, now: Instant) -> bool {
123+
let best_ipv4 = self.best_addr(false, now);
124+
let best = self.best_addr(true, now);
125+
let mut changed = false;
126+
if best_ipv4 != self.best_ipv4 {
127+
event!(
128+
target: "iroh::_events::udp::best_ipv4",
129+
Level::DEBUG,
130+
?best_ipv4,
131+
);
132+
changed = true;
133+
}
134+
if best != self.best {
135+
event!(
136+
target: "iroh::_events::udp::best",
137+
Level::DEBUG,
138+
?best,
139+
);
140+
changed = true;
141+
}
142+
self.best_ipv4 = best_ipv4;
143+
self.best = best;
144+
changed
119145
}
120146

121147
pub(super) fn best_addr(&self, have_ipv6: bool, now: Instant) -> UdpSendAddr {

0 commit comments

Comments
 (0)