Skip to content
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

(potentially) fix cli bugs #1136

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions iroh-net/src/hp/magicsock/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Endpoint {
}
}
None => {
let (addr, should_ping) = self.get_candidate_udp_addr(now);
let (addr, should_ping) = self.get_candidate_udp_addr();

// provide backup derp addr if no known latency or no addr
let derp_addr = if should_ping || addr.is_none() {
Expand All @@ -152,13 +152,14 @@ impl Endpoint {
None
};

debug!("using candidate addr {addr:?}, derp addr: {derp_addr:?}");
(addr, derp_addr, should_ping)
}
}
}

/// Determines a potential best addr for this endpoint. And if the endpoint needs a ping.
fn get_candidate_udp_addr(&mut self, now: &Instant) -> (Option<SocketAddr>, bool) {
fn get_candidate_udp_addr(&mut self) -> (Option<SocketAddr>, bool) {
let mut lowest_latency = Duration::from_secs(60 * 60);
let mut last_pong = None;
for (ipp, state) in self.endpoint_state.iter() {
Expand Down Expand Up @@ -192,14 +193,6 @@ impl Endpoint {
.keys()
.choose_stable(&mut rand::thread_rng())
.copied();
if let Some(addr) = udp_addr {
self.best_addr = Some(AddrLatency {
addr,
latency: None,
});

self.trust_best_addr_until = Some(*now + Duration::from_secs(15));
}

(udp_addr, udp_addr.is_some())
}
Expand Down
12 changes: 7 additions & 5 deletions iroh/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn make_partial_download(out_dir: &Path) -> anyhow::Result<Hash> {
}

#[test]
fn cli_provide_one_file() -> Result<()> {
fn cli_provide_one_file_basic() -> Result<()> {
let dir = testdir!();
let path = dir.join("foo");
make_rand_file(1000, &path)?;
Expand Down Expand Up @@ -376,8 +376,12 @@ fn test_provide_get_loop(path: &Path, input: Input, output: Output) -> Result<()
.stderr_capture();

// test get stderr output
let get_output = cmd.run()?;
let get_output = cmd.unchecked().run()?;
drop(provider);

// checking the output first, so you can still view any logging
assert!(!get_output.stderr.is_empty());
match_get_stderr(get_output.stderr)?;
assert!(get_output.status.success());

// test output
Expand All @@ -389,9 +393,7 @@ fn test_provide_get_loop(path: &Path, input: Input, output: Output) -> Result<()
}
Some(out) => compare_files(path, out)?,
};

assert!(!get_output.stderr.is_empty());
match_get_stderr(get_output.stderr)
Ok(())
}

/// Test the provide and get loop for success, stderr output, and file contents.
Expand Down