Skip to content

Commit

Permalink
fix(iroh-net): Ensure netcheck finishes once it has results (n0-compu…
Browse files Browse the repository at this point in the history
…ter#2027)

## Description

Once netcheck has managed to establish an external IP address there is
no need to further wait on the portmapper.  The results are already
useful.  If later the portmapper manages to get something done the
magicsock will react to that and make use of it.

## Notes & open questions

Fixes n0-computer#2021

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- [x] Tests if relevant.
  • Loading branch information
flub authored and fubuloubu committed Feb 21, 2024
1 parent 77bd0cf commit 73b5822
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions iroh-net/src/netcheck/reportgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ struct Actor {
last_report: Option<Arc<Report>>,
/// The portmapper client, if there is one.
port_mapper: Option<portmapper::Client>,
/// Whether the actor should try to reach things other than localhost.
///
/// This is set to true in tests to avoid probing the local LAN's router etc.
///
/// TODO: currently this only skips the portmapper, but still does STUN, HTTP and ICMP
/// probes. Furthermore none of our tests actually use this feature.
skip_external_network: bool,
/// The DERP configuration.
derp_map: DerpMap,
Expand Down Expand Up @@ -268,7 +274,6 @@ impl Actor {
self.report.portmap_probe = pm;
port_mapping.inner = None;
self.outstanding_tasks.port_mapper = false;
trace!("portmapper future done");
}

// Check for probes finishing.
Expand Down Expand Up @@ -420,10 +425,11 @@ impl Actor {
// duration of the slowest derp. For initial ones, double that.
let enough_derps = std::cmp::min(self.derp_map.len(), ENOUGH_NODES);
if self.report.derp_latency.len() == enough_derps {
let mut timeout = self.report.derp_latency.max_latency();
if !self.incremental {
timeout *= 2;
}
let timeout = self.report.derp_latency.max_latency();
let timeout = match self.incremental {
true => timeout,
false => timeout * 2,
};
let reportcheck = self.addr();
debug!(
reports=self.report.derp_latency.len(),
Expand Down Expand Up @@ -476,12 +482,13 @@ impl Actor {
/// Stops further probes.
///
/// This makes sure that no further probes are run and also cancels the captive portal
/// task if there were successful probes. Be sure to only handle this after all the
/// required [`ProbeReport`]s have been processed.
/// and portmapper tasks if there were successful probes. Be sure to only handle this
/// after all the required [`ProbeReport`]s have been processed.
fn handle_abort_probes(&mut self) {
trace!("handle abort probes");
self.outstanding_tasks.probes = false;
if self.report.udp {
self.outstanding_tasks.port_mapper = false;
self.outstanding_tasks.captive_task = false;
}
}
Expand Down

0 comments on commit 73b5822

Please sign in to comment.