Skip to content

Commit b08df6a

Browse files
committed
Remove unused structs/variants, rename Source::Udp -> Source::QuicPayload
1 parent 7b03147 commit b08df6a

File tree

4 files changed

+14
-39
lines changed

4 files changed

+14
-39
lines changed

iroh/src/magicsock/node_map.rs

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

14-
use self::{
15-
node_state::{NodeState, Options, PingHandled},
16-
path_validity::ClearReason,
17-
};
14+
use self::node_state::{NodeState, Options, PingHandled};
1815
use super::{metrics::Metrics, ActorMessage, DiscoMessageSource, NodeIdMappedAddr};
1916
#[cfg(any(test, feature = "test-utils"))]
2017
use crate::endpoint::PathSelection;
@@ -395,22 +392,22 @@ impl NodeMapInner {
395392
now: Instant,
396393
) {
397394
for addr in discovered {
398-
self.remove_by_ipp(addr.into(), ClearReason::MatchesOurLocalAddr, now)
395+
self.remove_by_ipp(addr.into(), now, "matches our local addr")
399396
}
400397
}
401398

402399
/// Removes a direct address from a node.
403-
fn remove_by_ipp(&mut self, ipp: IpPort, reason: ClearReason, now: Instant) {
400+
fn remove_by_ipp(&mut self, ipp: IpPort, now: Instant, why: &'static str) {
404401
if let Some(id) = self.by_ip_port.remove(&ipp) {
405402
if let Entry::Occupied(mut entry) = self.by_id.entry(id) {
406403
let node = entry.get_mut();
407-
node.remove_direct_addr(&ipp, reason, now);
404+
node.remove_direct_addr(&ipp, now, why);
408405
if node.direct_addresses().count() == 0 {
409406
let node_id = node.public_key();
410407
let mapped_addr = node.quic_mapped_addr();
411408
self.by_node_key.remove(node_id);
412409
self.by_quic_mapped_addr.remove(mapped_addr);
413-
debug!(node_id=%node_id.fmt_short(), ?reason, "removing node");
410+
debug!(node_id=%node_id.fmt_short(), why, "removing node");
414411
entry.remove();
415412
}
416413
}

iroh/src/magicsock/node_map/node_state.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use tracing::{debug, event, info, instrument, trace, warn, Level};
1818

1919
use super::{
2020
path_state::{summarize_node_paths, PathState},
21-
path_validity::ClearReason,
2221
udp_paths::{NodeUdpPaths, UdpSendAddr},
2322
IpPort, Source,
2423
};
@@ -372,19 +371,14 @@ impl NodeState {
372371
/// Removes a direct address for this node.
373372
///
374373
/// If this is also the best address, it will be cleared as well.
375-
pub(super) fn remove_direct_addr(
376-
&mut self,
377-
ip_port: &IpPort,
378-
reason: ClearReason,
379-
now: Instant,
380-
) {
374+
pub(super) fn remove_direct_addr(&mut self, ip_port: &IpPort, now: Instant, why: &'static str) {
381375
let Some(state) = self.udp_paths.paths.remove(ip_port) else {
382376
return;
383377
};
384378

385379
match state.last_alive().map(|instant| instant.elapsed()) {
386-
Some(last_alive) => debug!(%ip_port, ?last_alive, ?reason, "pruning address"),
387-
None => debug!(%ip_port, last_seen=%"never", ?reason, "pruning address"),
380+
Some(last_alive) => debug!(%ip_port, ?last_alive, why, "pruning address"),
381+
None => debug!(%ip_port, last_seen=%"never", why, "pruning address"),
388382
}
389383

390384
self.udp_paths.update_to_best_addr(now);
@@ -873,7 +867,7 @@ impl NodeState {
873867
prune_candidates.sort_unstable_by_key(|(_ip_port, last_alive)| *last_alive);
874868
prune_candidates.truncate(prune_count);
875869
for (ip_port, _last_alive) in prune_candidates.into_iter() {
876-
self.remove_direct_addr(&ip_port, ClearReason::Inactive, now);
870+
self.remove_direct_addr(&ip_port, now, "inactive");
877871
}
878872
debug!(
879873
paths = %summarize_node_paths(&self.udp_paths.paths),

iroh/src/magicsock/node_map/path_state.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,10 @@ pub(super) struct PathState {
4747
/// The time this endpoint was last advertised via a call-me-maybe DISCO message.
4848
pub(super) call_me_maybe_time: Option<Instant>,
4949

50-
// /// The most recent [`PongReply`].
51-
// ///
52-
// /// Previous replies are cleared when they are no longer relevant to determine whether
53-
// /// this path can still be used to reach the remote node.
54-
// pub(super) recent_pong: Option<PongReply>,
5550
/// Tracks whether this path is valid.
5651
///
52+
/// Also stores the latest [`PongReply`], if there is one.
53+
///
5754
/// See [`PathValidity`] docs.
5855
pub(super) validity: PathValidity,
5956
/// When the last payload data was **received** via this path.
@@ -134,10 +131,8 @@ impl PathState {
134131

135132
pub(super) fn receive_payload(&mut self, now: Instant) {
136133
self.last_payload_msg = Some(now);
137-
// TODO(matheus23): It's not necessarily UDP. Kinda weird to have this thing
138-
// Also, it all results in the same 6.5s timeout anyways, maybe we just remove it?
139134
self.validity
140-
.receive_payload(now, path_validity::Source::Udp);
135+
.receive_payload(now, path_validity::Source::QuicPayload);
141136
}
142137

143138
#[cfg(test)]

iroh/src/magicsock/node_map/path_validity.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,14 @@ struct Inner {
3030
#[derive(Debug)]
3131
pub(super) enum Source {
3232
ReceivedPong,
33-
// BestCandidate,
34-
Udp,
35-
}
36-
37-
#[derive(Debug, Clone, Copy)]
38-
pub enum ClearReason {
39-
// Reset, // TODO(matheus23): unused
40-
Inactive,
41-
// PongTimeout,
42-
MatchesOurLocalAddr,
33+
QuicPayload,
4334
}
4435

4536
impl Source {
4637
fn trust_duration(&self) -> Duration {
4738
match self {
4839
Source::ReceivedPong => TRUST_UDP_ADDR_DURATION,
49-
// // TODO: Fix time
50-
// Source::BestCandidate => Duration::from_secs(60 * 60),
51-
Source::Udp => TRUST_UDP_ADDR_DURATION,
40+
Source::QuicPayload => TRUST_UDP_ADDR_DURATION,
5241
}
5342
}
5443
}

0 commit comments

Comments
 (0)