Skip to content

Commit 7b03147

Browse files
committed
Cleanup
1 parent e2e9708 commit 7b03147

File tree

4 files changed

+20
-51
lines changed

4 files changed

+20
-51
lines changed

iroh/src/magicsock/node_map/node_state.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,12 +1511,6 @@ mod tests {
15111511
udp_paths: NodeUdpPaths::from_parts(
15121512
endpoint_state,
15131513
UdpSendAddr::Valid(ip_port.into()),
1514-
// BestAddr::from_parts(
1515-
// ip_port.into(),
1516-
// latency,
1517-
// now,
1518-
// now + Duration::from_secs(100), //TODO(matheus23): Is the 100s validity needed for the test?
1519-
// ),
15201514
),
15211515
sent_pings: HashMap::new(),
15221516
last_used: Some(now),
@@ -1582,7 +1576,6 @@ mod tests {
15821576
// endpoint w/ expired best addr and relay w/ latency
15831577
let (d_endpoint, d_socket_addr) = {
15841578
let socket_addr: SocketAddr = "0.0.0.0:7".parse().unwrap();
1585-
let expired = now.checked_sub(Duration::from_secs(100)).unwrap();
15861579
let key = SecretKey::generate(rand::thread_rng());
15871580
let node_id = key.public();
15881581
let endpoint_state = BTreeMap::from([(
@@ -1607,8 +1600,6 @@ mod tests {
16071600
udp_paths: NodeUdpPaths::from_parts(
16081601
endpoint_state,
16091602
UdpSendAddr::Outdated(socket_addr),
1610-
// TODO(matheus23): Test might need adjustments
1611-
// BestAddr::from_parts(socket_addr, Duration::from_millis(80), now, expired),
16121603
),
16131604
sent_pings: HashMap::new(),
16141605
last_used: Some(now),

iroh/src/magicsock/node_map/path_state.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//! The state kept for each network path to a remote node.
22
3-
use std::{
4-
collections::{BTreeMap, HashMap},
5-
net::SocketAddr,
6-
};
3+
use std::collections::{BTreeMap, HashMap};
74

85
use iroh_base::NodeId;
96
use iroh_relay::protos::stun;
@@ -87,13 +84,6 @@ impl PathState {
8784
}
8885
}
8986

90-
pub(super) fn udp_addr(&self) -> Option<SocketAddr> {
91-
match self.path {
92-
SendAddr::Udp(addr) => Some(addr),
93-
SendAddr::Relay(_) => None,
94-
}
95-
}
96-
9787
pub(super) fn with_last_payload(
9888
node_id: NodeId,
9989
path: SendAddr,

iroh/src/magicsock/node_map/path_validity.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ use n0_future::time::{Duration, Instant};
22

33
use crate::magicsock::node_map::node_state::PongReply;
44

5-
/// How long we trust a UDP address as the exclusive path (without using relay) without having heard a Pong reply.
5+
/// How long we trust a UDP address as the exclusive path (i.e. without also sending via the relay).
6+
///
7+
/// Trust for a UDP address begins when we receive a DISCO UDP pong on that address.
8+
/// It is then further extended by this duration every time we receive QUIC payload data while it's
9+
/// currently trusted.
10+
///
11+
/// If trust goes away, it can be brought back with another valid DISCO UDP pong.
612
const TRUST_UDP_ADDR_DURATION: Duration = Duration::from_millis(6500);
713

814
/// Tracks a path's validity.
@@ -30,9 +36,9 @@ pub(super) enum Source {
3036

3137
#[derive(Debug, Clone, Copy)]
3238
pub enum ClearReason {
33-
Reset,
39+
// Reset, // TODO(matheus23): unused
3440
Inactive,
35-
PongTimeout,
41+
// PongTimeout,
3642
MatchesOurLocalAddr,
3743
}
3844

@@ -117,9 +123,9 @@ impl PathValidity {
117123
}
118124

119125
// TODO(matheus23): Use this to bias the choice of best outdated addr maybe?
120-
pub(super) fn confirmed_at(&self) -> Option<Instant> {
121-
self.0.as_ref().map(|inner| inner.confirmed_at)
122-
}
126+
// pub(super) fn confirmed_at(&self) -> Option<Instant> {
127+
// self.0.as_ref().map(|inner| inner.confirmed_at)
128+
// }
123129
}
124130

125131
impl Inner {

iroh/src/magicsock/node_map/udp_paths.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,6 @@ impl UdpSendAddr {
5959
UdpSendAddr::None => None,
6060
}
6161
}
62-
63-
pub fn is_better_than(&self, other: &Self) -> bool {
64-
match (other, self) {
65-
// Other being valid, we'll never be better
66-
(UdpSendAddr::Valid(_), _) => false,
67-
// Anything anything above outdated is better
68-
(UdpSendAddr::Outdated(_), UdpSendAddr::Valid(_)) => true,
69-
(UdpSendAddr::Outdated(_), _) => false,
70-
// Anything above unconfirmed is better
71-
(UdpSendAddr::Unconfirmed(_), UdpSendAddr::Valid(_)) => true,
72-
(UdpSendAddr::Unconfirmed(_), UdpSendAddr::Outdated(_)) => true,
73-
(UdpSendAddr::Unconfirmed(_), _) => false,
74-
// None compared to none is equally bad
75-
(UdpSendAddr::None, UdpSendAddr::None) => false,
76-
// Anything above none is better
77-
(UdpSendAddr::None, _) => true,
78-
}
79-
}
8062
}
8163

8264
/// The UDP paths for a single node.
@@ -103,7 +85,10 @@ pub(super) struct NodeUdpPaths {
10385
/// - the current send addr is not a validated path anymore or
10486
/// - we received a pong with lower latency.
10587
pub(super) best: UdpSendAddr,
106-
pub(super) best_non_ipv6: UdpSendAddr,
88+
/// The current best address to send on from all IPv4 addresses we have available.
89+
///
90+
/// Follows the same logic as `best` above, but doesn't include any IPv6 addresses.
91+
pub(super) best_ipv4: UdpSendAddr,
10792
}
10893

10994
impl NodeUdpPaths {
@@ -115,24 +100,21 @@ impl NodeUdpPaths {
115100
pub(super) fn from_parts(paths: BTreeMap<IpPort, PathState>, best: UdpSendAddr) -> Self {
116101
Self {
117102
paths,
118-
best_non_ipv6: best,
103+
best_ipv4: best, // we only use ipv4 addrs in tests
119104
best,
120105
}
121106
}
122107

123108
/// Returns the current UDP address to send on.
124109
pub(super) fn send_addr(&self, have_ipv6: bool) -> &UdpSendAddr {
125110
if !have_ipv6 {
126-
return &self.best_non_ipv6;
127-
}
128-
if self.best_non_ipv6.is_better_than(&self.best) {
129-
return &self.best_non_ipv6;
111+
return &self.best_ipv4;
130112
}
131113
&self.best
132114
}
133115

134116
pub(super) fn update_to_best_addr(&mut self, now: Instant) {
135-
self.best_non_ipv6 = self.best_addr(false, now);
117+
self.best_ipv4 = self.best_addr(false, now);
136118
self.best = self.best_addr(true, now);
137119
}
138120

0 commit comments

Comments
 (0)