From ee475715c3c5df75fff2df155f4f72d169c85aed Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Wed, 28 Apr 2021 14:59:59 +0900 Subject: [PATCH] client: make install step a bit more resilient change private keys on client earlier to avoid race conditions, and attempt the fetch call multiple times to avoid spurious issues, while also not failing the entire command if fetch doesn't succeed. --- client/src/main.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index 15929bf..377a614 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -237,7 +237,16 @@ fn install(invite: &Path, hosts_file: Option, opts: InstallOpts) -> Res e })?; - fetch(&iface, false, hosts_file)?; + let mut fetch_success = false; + for _ in 0..3 { + if fetch(&iface, false, hosts_file).is_ok() { + fetch_success = true; + break; + } + } + if !fetch_success { + println!("{} Failed to fetch peers from server, you will need to manually run the 'up' command.", "[!]".red()); + } if opts.delete_invite || Confirm::with_theme(&*prompts::THEME) @@ -319,15 +328,15 @@ fn redeem_invite( "[*]".dimmed(), target_conf.to_string_lossy().yellow() ); + println!( - "{} Waiting for server's WireGuard interface to transition to new key.", + "{} Changing keys and waiting for server's WireGuard interface to transition.", "[*]".dimmed(), ); - thread::sleep(*REDEEM_TRANSITION_WAIT); - DeviceConfigBuilder::new() .set_private_key(keypair.private) .apply(&iface)?; + thread::sleep(*REDEEM_TRANSITION_WAIT); Ok(()) }