Skip to content

Commit 238c895

Browse files
start tracking path events
1 parent 530df49 commit 238c895

File tree

6 files changed

+39
-84
lines changed

6 files changed

+39
-84
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ netwatch = { git = "https://github.com/n0-computer/net-tools", branch = "feat-mu
5151
# iroh-quinn-proto = { path = "../iroh-quinn/quinn-proto" }
5252
# iroh-quinn-udp = { path = "../iroh-quinn/quinn-udp" }
5353

54-
# iroh-quinn = { git = "https://github.com//n0-computer/quinn", branch = "multipath-misc" }
55-
# iroh-quinn-proto = { git = "https://github.com//n0-computer/quinn", branch = "multipath-misc" }
56-
# iroh-quinn-udp = { git = "https://github.com//n0-computer/quinn", branch = "multipath-misc" }
54+
# iroh-quinn = { git = "https://github.com//n0-computer/quinn", branch = "flub/quinn-path-events-status" }
55+
# iroh-quinn-proto = { git = "https://github.com//n0-computer/quinn", branch = "flub/quinn-path-events-status" }
56+
# iroh-quinn-udp = { git = "https://github.com//n0-computer/quinn", branch = "flub/quinn-path-events-status" }

iroh/src/endpoint.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,13 +1768,20 @@ impl Future for Connecting {
17681768
let conn = Connection { inner };
17691769

17701770
// Grab the remote identity and register this connection
1771-
17721771
if let Some(remote) = *this.remote_node_id {
17731772
let weak_handle = conn.inner.weak_handle();
1774-
this.ep.msock.register_connection(remote, weak_handle);
1773+
let path_events = conn.inner.path_events();
1774+
this.ep
1775+
.msock
1776+
.register_connection(remote, weak_handle, path_events);
17751777
} else if let Ok(remote) = conn.remote_node_id() {
17761778
let weak_handle = conn.inner.weak_handle();
1777-
this.ep.msock.register_connection(remote, weak_handle);
1779+
let path_events = conn.inner.path_events();
1780+
this.ep
1781+
.msock
1782+
.register_connection(remote, weak_handle, path_events);
1783+
} else {
1784+
warn!("unable to determine node id for the remote");
17781785
}
17791786

17801787
try_send_rtt_msg(&conn, this.ep, *this.remote_node_id);

iroh/src/magicsock.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use netwatch::netmon;
4343
#[cfg(not(wasm_browser))]
4444
use netwatch::{ip::LocalAddresses, UdpSocket};
4545
use quinn::{AsyncUdpSocket, ServerConfig, WeakConnectionHandle};
46+
use quinn_proto::PathEvent;
4647
use rand::Rng;
4748
use smallvec::SmallVec;
4849
use snafu::{ResultExt, Snafu};
@@ -293,8 +294,29 @@ impl MagicSock {
293294
self.local_addrs_watch.get().expect("disconnected")
294295
}
295296

296-
pub(crate) fn register_connection(&self, remote: NodeId, conn: WeakConnectionHandle) {
297+
pub(crate) fn register_connection(
298+
&self,
299+
remote: NodeId,
300+
conn: WeakConnectionHandle,
301+
mut path_events: tokio::sync::broadcast::Receiver<PathEvent>,
302+
) {
297303
self.connection_map.insert(remote, conn);
304+
305+
// TODO: track task
306+
// TODO: find a good home for this
307+
task::spawn(async move {
308+
loop {
309+
match path_events.recv().await {
310+
Ok(event) => {
311+
info!(remote = %remote, "path event: {:?}", event);
312+
}
313+
Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => {
314+
warn!("lagged path events");
315+
}
316+
Err(tokio::sync::broadcast::error::RecvError::Closed) => break,
317+
}
318+
}
319+
});
298320
}
299321

300322
#[cfg(not(wasm_browser))]

iroh/src/magicsock/node_map/node_state.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -533,12 +533,6 @@ impl NodeState {
533533
.replace(now);
534534
}
535535

536-
// Zero out all the last_ping times to force send_pings to send new ones, even if
537-
// it's been less than 5 seconds ago. Also clear pongs for direct addresses not
538-
// included in the updated set.
539-
for (_ipp, st) in self.udp_paths.paths.iter_mut() {
540-
st.last_ping = None;
541-
}
542536
// Clear trust on our best_addr if it is not included in the updated set. Also
543537
// clear the last call-me-maybe send time so we will send one again.
544538
if let Some(addr) = self.udp_paths.best_addr.addr() {
@@ -594,21 +588,6 @@ impl NodeState {
594588
self.last_used = Some(now);
595589
}
596590

597-
pub(super) fn last_ping(&self, addr: &SendAddr) -> Option<Instant> {
598-
match addr {
599-
SendAddr::Udp(addr) => self
600-
.udp_paths
601-
.paths
602-
.get(&(*addr).into())
603-
.and_then(|ep| ep.last_ping),
604-
SendAddr::Relay(url) => self
605-
.relay_url
606-
.as_ref()
607-
.filter(|(home_url, _state)| home_url == url)
608-
.and_then(|(_home_url, state)| state.last_ping),
609-
}
610-
}
611-
612591
/// Checks if this `Endpoint` is currently actively being used.
613592
pub(super) fn is_active(&self, now: &Instant) -> bool {
614593
match self.last_used {

iroh/src/magicsock/node_map/path_state.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ use super::{
1414
};
1515
use crate::disco::SendAddr;
1616

17-
/// The minimum time between pings to an endpoint.
18-
///
19-
/// Except in the case of CallMeMaybe frames resetting the counter, as the first pings
20-
/// likely didn't through the firewall.
21-
const DISCO_PING_INTERVAL: Duration = Duration::from_secs(5);
22-
2317
/// State about a particular path to another [`NodeState`].
2418
///
2519
/// This state is used for both the relay path and any direct UDP paths.
@@ -31,13 +25,6 @@ pub(super) struct PathState {
3125
node_id: NodeId,
3226
/// The path this applies for.
3327
path: SendAddr,
34-
/// The last (outgoing) ping time.
35-
pub(super) last_ping: Option<Instant>,
36-
37-
/// If non-zero, means that this was an endpoint that we learned about at runtime (from an
38-
/// incoming ping). If so, we keep the time updated and use it to discard old candidates.
39-
// NOTE: tx_id Originally added in tailscale due to <https://github.com/tailscale/tailscale/issues/7078>.
40-
last_got_ping: Option<(Instant, stun_rs::TransactionId)>,
4128

4229
/// The time this endpoint was last advertised via a call-me-maybe DISCO message.
4330
pub(super) call_me_maybe_time: Option<Instant>,
@@ -61,8 +48,6 @@ impl PathState {
6148
Self {
6249
node_id,
6350
path,
64-
last_ping: None,
65-
last_got_ping: None,
6651
call_me_maybe_time: None,
6752
last_payload_msg: None,
6853
sources,
@@ -87,8 +72,6 @@ impl PathState {
8772
PathState {
8873
node_id,
8974
path,
90-
last_ping: None,
91-
last_got_ping: None,
9275
call_me_maybe_time: None,
9376
last_payload_msg: Some(now),
9477
sources,
@@ -109,11 +92,6 @@ impl PathState {
10992
.unwrap_or(false)
11093
}
11194

112-
/// Returns the instant the last incoming ping was received.
113-
pub(super) fn last_incoming_ping(&self) -> Option<&Instant> {
114-
self.last_got_ping.as_ref().map(|(time, _tx_id)| time)
115-
}
116-
11795
/// Reports the last instant this path was considered alive.
11896
///
11997
/// Alive means the path is considered in use by the remote endpoint. Either because we
@@ -130,15 +108,13 @@ impl PathState {
130108
.as_ref()
131109
.into_iter()
132110
.chain(self.call_me_maybe_time.as_ref())
133-
.chain(self.last_incoming_ping())
134111
.max()
135112
.copied()
136113
}
137114

138115
/// The last control or DISCO message **about** this path.
139116
///
140117
/// This is the most recent instant among:
141-
/// - when last pong was received.
142118
/// - when this path was last advertised in a received CallMeMaybe message.
143119
/// - when the last ping from them was received.
144120
///
@@ -149,41 +125,18 @@ impl PathState {
149125
.call_me_maybe_time
150126
.as_ref()
151127
.map(|call_me| (*call_me, ControlMsg::CallMeMaybe));
152-
let last_ping = self
153-
.last_incoming_ping()
154-
.map(|ping| (*ping, ControlMsg::Ping));
155128

156129
last_call_me_maybe
157130
.into_iter()
158-
.chain(last_ping)
159131
.max_by_key(|(instant, _kind)| *instant)
160132
.map(|(instant, kind)| (now.duration_since(instant), kind))
161133
}
162134

163-
pub(super) fn needs_ping(&self, now: &Instant) -> bool {
164-
match self.last_ping {
165-
None => true,
166-
Some(last_ping) => {
167-
let elapsed = now.duration_since(last_ping);
168-
169-
// TODO: remove!
170-
// This logs "ping is too new" for each send whenever the endpoint does *not* need
171-
// a ping. Pretty sure this is not a useful log, but maybe there was a reason?
172-
// if !needs_ping {
173-
// debug!("ping is too new: {}ms", elapsed.as_millis());
174-
// }
175-
elapsed > DISCO_PING_INTERVAL
176-
}
177-
}
178-
}
179-
180135
pub(super) fn add_source(&mut self, source: Source, now: Instant) {
181136
self.sources.insert(source, now);
182137
}
183138

184139
pub(super) fn clear(&mut self) {
185-
self.last_ping = None;
186-
self.last_got_ping = None;
187140
self.call_me_maybe_time = None;
188141
}
189142

@@ -192,12 +145,6 @@ impl PathState {
192145
if self.is_active() {
193146
write!(w, "active ")?;
194147
}
195-
if let Some(when) = self.last_incoming_ping() {
196-
write!(w, "ping-received({:?} ago) ", when.elapsed())?;
197-
}
198-
if let Some(ref when) = self.last_ping {
199-
write!(w, "ping-sent({:?} ago) ", when.elapsed())?;
200-
}
201148
if let Some(last_source) = self.sources.iter().max_by_key(|&(_, instant)| instant) {
202149
write!(
203150
w,

0 commit comments

Comments
 (0)