-
Notifications
You must be signed in to change notification settings - Fork 330
feat: implement rtt hints for nat traversal #3784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat-multipath
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ use crate::{ | |
| remote_map::Private, | ||
| transports::{self, OwnedTransmit, TransportsSender}, | ||
| }, | ||
| net_report::Report, | ||
| util::MaybeFuture, | ||
| }; | ||
|
|
||
|
|
@@ -190,6 +191,9 @@ pub(super) struct RemoteStateActor { | |
| // | ||
| /// Stream of discovery results, or always pending if discovery is not running. | ||
| discovery_stream: DiscoveryStream, | ||
|
|
||
| /// Last Net Report | ||
| last_report: Option<Report>, | ||
| } | ||
|
|
||
| impl RemoteStateActor { | ||
|
|
@@ -220,6 +224,7 @@ impl RemoteStateActor { | |
| scheduled_open_path: None, | ||
| pending_open_paths: VecDeque::new(), | ||
| discovery_stream: Either::Left(n0_future::stream::pending()), | ||
| last_report: None, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -368,6 +373,9 @@ impl RemoteStateActor { | |
| }; | ||
| tx.send(info).ok(); | ||
| } | ||
| RemoteStateMessage::NetworkChange(report) => { | ||
| self.last_report.replace(report); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -707,7 +715,26 @@ impl RemoteStateActor { | |
| .map(|daddr| daddr.addr) | ||
| .collect::<BTreeSet<_>>(); | ||
|
|
||
| match conn.initiate_nat_traversal_round() { | ||
| let all_rtts = self.calculate_path_rtts(); | ||
| let relay_mapped_addrs = self.relay_mapped_addrs.clone(); | ||
| let relay_latencies = self.last_report.as_ref().map(|r| r.relay_latency.clone()); | ||
| let rtt_hints = |addr: &SocketAddr| { | ||
| let addr = relay_mapped_addrs.to_transport_addr(*addr)?; | ||
| match addr { | ||
| transports::Addr::Relay(url, _id) => { | ||
| // Relay case, grab the latency from net_report | ||
| relay_latencies.as_ref().and_then(|l| l.get(&url)) | ||
| } | ||
| addr @ transports::Addr::Ip(_) => { | ||
| // IP case, grab the worst latency we currently have | ||
| all_rtts | ||
| .get(&addr) | ||
| .and_then(|rtts| rtts.iter().max().copied()) | ||
|
Comment on lines
+729
to
+732
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, IIUC, this won't help broken paths, right? You only have a single connection in the RemoteState, and the remote address that doesn't work for holepunching won't have an RTT estimate. So you're back to having a 333ms initial RTT estimate for remote addresses that don't work. Am I missing something?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the probes will timeout faster for broken paths, that’s the whole point of this PR
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But... the way the code is written, I don't see how that's going to be the case? |
||
| } | ||
| } | ||
| }; | ||
|
|
||
| match conn.initiate_nat_traversal_round(rtt_hints) { | ||
| Ok(remote_candidates) => { | ||
| let remote_candidates = remote_candidates | ||
| .iter() | ||
|
|
@@ -766,6 +793,21 @@ impl RemoteStateActor { | |
| .private_socket_addr(), | ||
| }; | ||
|
|
||
| let rtt_hint = match &open_addr { | ||
| transports::Addr::Relay(url, _) => { | ||
| // Relay case, grab the latency from net_report | ||
| self.last_report | ||
| .as_ref() | ||
| .and_then(|r| r.relay_latency.get(url)) | ||
| } | ||
| addr @ transports::Addr::Ip(_) => { | ||
| let all_rtts = self.calculate_path_rtts(); | ||
| all_rtts | ||
| .get(addr) | ||
| .and_then(|rtts| rtts.iter().max().copied()) | ||
| } | ||
| }; | ||
|
|
||
| for (conn_id, conn_state) in self.connections.iter_mut() { | ||
| if conn_state.path_ids.contains_key(open_addr) { | ||
| continue; | ||
|
|
@@ -776,7 +818,8 @@ impl RemoteStateActor { | |
| if conn.side().is_server() { | ||
| continue; | ||
| } | ||
| let fut = conn.open_path_ensure(quic_addr, path_status); | ||
|
|
||
| let fut = conn.open_path_ensure(quic_addr, path_status, rtt_hint); | ||
| match fut.path_id() { | ||
| Some(path_id) => { | ||
| trace!(?conn_id, ?path_id, "opening new path"); | ||
|
|
@@ -905,6 +948,20 @@ impl RemoteStateActor { | |
| } | ||
| } | ||
|
|
||
| fn calculate_path_rtts(&self) -> FxHashMap<transports::Addr, Vec<Duration>> { | ||
| let mut rtts: FxHashMap<transports::Addr, Vec<Duration>> = FxHashMap::default(); | ||
| for conn_state in self.connections.values() { | ||
| let Some(conn) = conn_state.handle.upgrade() else { | ||
| continue; | ||
| }; | ||
| for (path_id, addr) in conn_state.open_paths.iter() { | ||
| if let Some(stats) = conn.path_stats(*path_id) { | ||
| rtts.entry(addr.clone()).or_default().push(stats.rtt); | ||
| } | ||
| } | ||
| } | ||
| rtts | ||
| } | ||
| /// Selects the path with the lowest RTT, prefers direct paths. | ||
| /// | ||
| /// If there are direct paths, this selects the direct path with the lowest RTT. If | ||
|
|
@@ -914,22 +971,9 @@ impl RemoteStateActor { | |
| /// direct paths are closed for all connections. | ||
| #[instrument(skip_all)] | ||
| fn select_path(&mut self) { | ||
| let all_path_rtts = self.calculate_path_rtts(); | ||
| // Find the lowest RTT across all connections for each open path. The long way, so | ||
| // we get to log *all* RTTs. | ||
| let mut all_path_rtts: FxHashMap<transports::Addr, Vec<Duration>> = FxHashMap::default(); | ||
| for conn_state in self.connections.values() { | ||
| let Some(conn) = conn_state.handle.upgrade() else { | ||
| continue; | ||
| }; | ||
| for (path_id, addr) in conn_state.open_paths.iter() { | ||
| if let Some(stats) = conn.path_stats(*path_id) { | ||
| all_path_rtts | ||
| .entry(addr.clone()) | ||
| .or_default() | ||
| .push(stats.rtt); | ||
| } | ||
| } | ||
| } | ||
| trace!(?all_path_rtts, "dumping all path RTTs"); | ||
| let path_rtts: FxHashMap<transports::Addr, Duration> = all_path_rtts | ||
| .into_iter() | ||
|
|
@@ -1175,6 +1219,7 @@ pub(crate) enum RemoteStateMessage { | |
| /// | ||
| /// This currently only includes a list of all known transport addresses for the remote. | ||
| RemoteInfo(oneshot::Sender<RemoteInfo>), | ||
| NetworkChange(Report), | ||
| } | ||
|
|
||
| /// A handle to a [`RemoteStateActor`]. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relay latency is not the same thing as the RTT to the peer via the relay, because that depends on the (potentially two!) relays involved in going back and forth.
Besides, I don't think we need an RTT hint for any relay addresses, because they will/should never be used in holepunching.