diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-03-12 11:44:21 +0000 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-03-13 11:13:34 +0000 |
| commit | 6f9cad434cc73442184790efc46a71ffd32a953a (patch) | |
| tree | b9c29ac8430167cc328196280691beaa4ab82bc9 | |
| parent | 0a68c13474728660b936f37abc283c1d1aeb1780 (diff) | |
| download | mullvadvpn-6f9cad434cc73442184790efc46a71ffd32a953a.tar.xz mullvadvpn-6f9cad434cc73442184790efc46a71ffd32a953a.zip | |
Send a ping packet every second rather than once every 5 seconds
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/mod.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/ping_monitor.rs | 43 |
2 files changed, 32 insertions, 14 deletions
diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs index 65897d9d23..5a9ff34128 100644 --- a/talpid-core/src/tunnel/wireguard/mod.rs +++ b/talpid-core/src/tunnel/wireguard/mod.rs @@ -76,15 +76,16 @@ impl WireguardMonitor { close_msg_receiver, }; monitor.setup_routing(&config)?; - monitor.start_pinger(&config); monitor.tunnel_up(&config); ping_monitor::ping( config.ipv4_gateway.into(), PING_TIMEOUT, &monitor.tunnel.get_interface_name().to_string(), + true, ) .chain_err(|| ErrorKind::PingTimeoutError)?; + monitor.start_pinger(&config); Ok(monitor) } diff --git a/talpid-core/src/tunnel/wireguard/ping_monitor.rs b/talpid-core/src/tunnel/wireguard/ping_monitor.rs index 58f2904c88..e6cdd1b033 100644 --- a/talpid-core/src/tunnel/wireguard/ping_monitor.rs +++ b/talpid-core/src/tunnel/wireguard/ping_monitor.rs @@ -20,7 +20,7 @@ pub fn spawn_ping_monitor<F: FnOnce() + Send + 'static>( ) { thread::spawn(move || loop { let start = time::Instant::now(); - if let Err(e) = ping(ip, timeout_secs, &interface) { + if let Err(e) = ping(ip, timeout_secs, &interface, false) { log::debug!("ping failed - {}", e); on_fail(); return; @@ -33,8 +33,13 @@ pub fn spawn_ping_monitor<F: FnOnce() + Send + 'static>( }); } -pub fn ping(ip: IpAddr, timeout_secs: u16, interface: &str) -> Result<()> { - let output = ping_cmd(ip, timeout_secs, interface) +pub fn ping( + ip: IpAddr, + timeout_secs: u16, + interface: &str, + exit_on_first_reply: bool, +) -> Result<()> { + let output = ping_cmd(ip, timeout_secs, interface, exit_on_first_reply) .run() .chain_err(|| ErrorKind::PingError)?; if !output.status.success() { @@ -43,7 +48,12 @@ pub fn ping(ip: IpAddr, timeout_secs: u16, interface: &str) -> Result<()> { Ok(()) } -fn ping_cmd(ip: IpAddr, timeout_secs: u16, interface: &str) -> duct::Expression { +fn ping_cmd( + ip: IpAddr, + timeout_secs: u16, + interface: &str, + exit_on_first_reply: bool, +) -> duct::Expression { let interface_flag = if cfg!(target_os = "linux") { "-I" } else { @@ -54,18 +64,25 @@ fn ping_cmd(ip: IpAddr, timeout_secs: u16, interface: &str) -> duct::Expression } else { "-t" }; - duct::cmd!( - "ping", + + let timeout_secs = timeout_secs.to_string(); + let ip = ip.to_string(); + + let mut args = vec![ "-n", - "-c", + "-i", "1", &interface_flag, &interface, timeout_flag, - &timeout_secs.to_string(), - ip.to_string() - ) - .stdin_null() - .stdout_null() - .unchecked() + &timeout_secs, + &ip, + ]; + if exit_on_first_reply { + args.push("-o"); + } + duct::cmd("ping", args) + .stdin_null() + .stdout_null() + .unchecked() } |
