Skip to content

Commit a3187ca

Browse files
authored
fix(iroh): Track path validity for all paths and replace BestAddr with PathValidity (#3400)
## Description #3398 but now rebased on `main`. See its description for more information. There's only one small change: We don't need to think about `NodeMap::reset`, as that's removed in `main`. ## Breaking Changes None. ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist <!-- Remove any that are not relevant. --> - [x] Self-review.
1 parent 2ce6a73 commit a3187ca

File tree

6 files changed

+381
-453
lines changed

6 files changed

+381
-453
lines changed

iroh/src/magicsock/node_map.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ use serde::{Deserialize, Serialize};
1111
use stun_rs::TransactionId;
1212
use tracing::{debug, info, instrument, trace, warn};
1313

14-
use self::{
15-
best_addr::ClearReason,
16-
node_state::{NodeState, Options, PingHandled},
17-
};
14+
use self::node_state::{NodeState, Options, PingHandled};
1815
use super::{ActorMessage, NodeIdMappedAddr, metrics::Metrics, transports};
1916
use crate::disco::{CallMeMaybe, Pong, SendAddr};
2017
#[cfg(any(test, feature = "test-utils"))]
2118
use crate::endpoint::PathSelection;
2219

23-
mod best_addr;
2420
mod node_state;
2521
mod path_state;
22+
mod path_validity;
2623
mod udp_paths;
2724

2825
pub use node_state::{ConnectionType, ControlMsg, DirectAddrInfo, RemoteInfo};
@@ -196,7 +193,7 @@ impl NodeMap {
196193
.expect("poisoned")
197194
.get_mut(NodeStateKey::Idx(id))
198195
{
199-
ep.ping_timeout(tx_id);
196+
ep.ping_timeout(tx_id, Instant::now());
200197
}
201198
}
202199

@@ -266,9 +263,10 @@ impl NodeMap {
266263
}
267264

268265
pub(super) fn reset_node_states(&self) {
266+
let now = Instant::now();
269267
let mut inner = self.inner.lock().expect("poisoned");
270268
for (_, ep) in inner.node_states_mut() {
271-
ep.note_connectivity_change();
269+
ep.note_connectivity_change(now);
272270
}
273271
}
274272

@@ -317,7 +315,7 @@ impl NodeMap {
317315
self.inner
318316
.lock()
319317
.expect("poisoned")
320-
.on_direct_addr_discovered(discovered);
318+
.on_direct_addr_discovered(discovered, Instant::now());
321319
}
322320
}
323321

@@ -378,24 +376,28 @@ impl NodeMapInner {
378376
}
379377

380378
/// Prunes direct addresses from nodes that claim to share an address we know points to us.
381-
pub(super) fn on_direct_addr_discovered(&mut self, discovered: BTreeSet<SocketAddr>) {
379+
pub(super) fn on_direct_addr_discovered(
380+
&mut self,
381+
discovered: BTreeSet<SocketAddr>,
382+
now: Instant,
383+
) {
382384
for addr in discovered {
383-
self.remove_by_ipp(addr.into(), ClearReason::MatchesOurLocalAddr)
385+
self.remove_by_ipp(addr.into(), now, "matches our local addr")
384386
}
385387
}
386388

387389
/// Removes a direct address from a node.
388-
fn remove_by_ipp(&mut self, ipp: IpPort, reason: ClearReason) {
390+
fn remove_by_ipp(&mut self, ipp: IpPort, now: Instant, why: &'static str) {
389391
if let Some(id) = self.by_ip_port.remove(&ipp) {
390392
if let Entry::Occupied(mut entry) = self.by_id.entry(id) {
391393
let node = entry.get_mut();
392-
node.remove_direct_addr(&ipp, reason);
394+
node.remove_direct_addr(&ipp, now, why);
393395
if node.direct_addresses().count() == 0 {
394396
let node_id = node.public_key();
395397
let mapped_addr = node.quic_mapped_addr();
396398
self.by_node_key.remove(node_id);
397399
self.by_quic_mapped_addr.remove(mapped_addr);
398-
debug!(node_id=%node_id.fmt_short(), ?reason, "removing node");
400+
debug!(node_id=%node_id.fmt_short(), why, "removing node");
399401
entry.remove();
400402
}
401403
}
@@ -840,7 +842,7 @@ mod tests {
840842
}
841843

842844
info!("Pruning addresses");
843-
endpoint.prune_direct_addresses();
845+
endpoint.prune_direct_addresses(Instant::now());
844846

845847
// Half the offline addresses should have been pruned. All the active and alive
846848
// addresses should have been kept.

iroh/src/magicsock/node_map/best_addr.rs

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)