Skip to content

Commit 14e9bb9

Browse files
committed
Use &self instead of &mut self in get_send_addr
1 parent e521208 commit 14e9bb9

File tree

4 files changed

+226
-195
lines changed

4 files changed

+226
-195
lines changed

iroh/src/magicsock/node_map.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl NodeMap {
200200
.expect("poisoned")
201201
.get_mut(NodeStateKey::Idx(id))
202202
{
203-
ep.ping_timeout(tx_id);
203+
ep.ping_timeout(tx_id, Instant::now());
204204
}
205205
}
206206

@@ -277,9 +277,10 @@ impl NodeMap {
277277
}
278278

279279
pub(super) fn reset_node_states(&self) {
280+
let now = Instant::now();
280281
let mut inner = self.inner.lock().expect("poisoned");
281282
for (_, ep) in inner.node_states_mut() {
282-
ep.note_connectivity_change();
283+
ep.note_connectivity_change(now);
283284
}
284285
}
285286

@@ -328,7 +329,7 @@ impl NodeMap {
328329
self.inner
329330
.lock()
330331
.expect("poisoned")
331-
.on_direct_addr_discovered(discovered);
332+
.on_direct_addr_discovered(discovered, Instant::now());
332333
}
333334
}
334335

@@ -389,18 +390,22 @@ impl NodeMapInner {
389390
}
390391

391392
/// Prunes direct addresses from nodes that claim to share an address we know points to us.
392-
pub(super) fn on_direct_addr_discovered(&mut self, discovered: BTreeSet<SocketAddr>) {
393+
pub(super) fn on_direct_addr_discovered(
394+
&mut self,
395+
discovered: BTreeSet<SocketAddr>,
396+
now: Instant,
397+
) {
393398
for addr in discovered {
394-
self.remove_by_ipp(addr.into(), ClearReason::MatchesOurLocalAddr)
399+
self.remove_by_ipp(addr.into(), ClearReason::MatchesOurLocalAddr, now)
395400
}
396401
}
397402

398403
/// Removes a direct address from a node.
399-
fn remove_by_ipp(&mut self, ipp: IpPort, reason: ClearReason) {
404+
fn remove_by_ipp(&mut self, ipp: IpPort, reason: ClearReason, now: Instant) {
400405
if let Some(id) = self.by_ip_port.remove(&ipp) {
401406
if let Entry::Occupied(mut entry) = self.by_id.entry(id) {
402407
let node = entry.get_mut();
403-
node.remove_direct_addr(&ipp, reason);
408+
node.remove_direct_addr(&ipp, reason, now);
404409
if node.direct_addresses().count() == 0 {
405410
let node_id = node.public_key();
406411
let mapped_addr = node.quic_mapped_addr();
@@ -853,7 +858,7 @@ mod tests {
853858
}
854859

855860
info!("Pruning addresses");
856-
endpoint.prune_direct_addresses();
861+
endpoint.prune_direct_addresses(Instant::now());
857862

858863
// Half the offline addresses should have been pruned. All the active and alive
859864
// addresses should have been kept.

0 commit comments

Comments
 (0)