diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-09-30 12:24:34 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-09-30 14:50:37 +0100 |
| commit | 3164047b1eae8ce7fb4e10f89f86c4a39158576b (patch) | |
| tree | 4794bc08a6c56cad12412e1701c95388f947ee81 | |
| parent | 83ad5ef5334e5d3eddaa09a115aaa4e85952fe5b (diff) | |
| download | mullvadvpn-3164047b1eae8ce7fb4e10f89f86c4a39158576b.tar.xz mullvadvpn-3164047b1eae8ce7fb4e10f89f86c4a39158576b.zip | |
Improve interface for ping_monitor
| -rw-r--r-- | talpid-core/src/ping_monitor/unix.rs | 18 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/mod.rs | 5 |
2 files changed, 14 insertions, 9 deletions
diff --git a/talpid-core/src/ping_monitor/unix.rs b/talpid-core/src/ping_monitor/unix.rs index 9af4c3c8b1..5336bc7f2c 100644 --- a/talpid-core/src/ping_monitor/unix.rs +++ b/talpid-core/src/ping_monitor/unix.rs @@ -1,6 +1,8 @@ +#[allow(dead_code)] +// TODO: remove the lint exemption above when ping monitor is used use std::{ io, - net::IpAddr, + net::Ipv4Addr, sync::mpsc, thread, time::{Duration, Instant}, @@ -16,14 +18,14 @@ pub enum Error { } pub fn monitor_ping( - ip: IpAddr, + ip: Ipv4Addr, timeout_secs: u16, interface: &str, close_receiver: mpsc::Receiver<()>, ) -> Result<(), Error> { while let Err(mpsc::TryRecvError::Empty) = close_receiver.try_recv() { let start = Instant::now(); - ping(ip, timeout_secs, &interface, false)?; + internal_ping(ip, timeout_secs, &interface, false)?; if let Some(remaining) = Duration::from_secs(timeout_secs.into()).checked_sub(start.elapsed()) { @@ -34,8 +36,12 @@ pub fn monitor_ping( Ok(()) } -pub fn ping( - ip: IpAddr, +pub fn ping(ip: Ipv4Addr, timeout_secs: u16, interface: &str) -> Result<(), Error> { + internal_ping(ip, timeout_secs, interface, true) +} + +fn internal_ping( + ip: Ipv4Addr, timeout_secs: u16, interface: &str, exit_on_first_reply: bool, @@ -51,7 +57,7 @@ pub fn ping( } fn ping_cmd( - ip: IpAddr, + ip: Ipv4Addr, timeout_secs: u16, interface: &str, exit_on_first_reply: bool, diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs index 024bab2a91..80d5a14187 100644 --- a/talpid-core/src/tunnel/wireguard/mod.rs +++ b/talpid-core/src/tunnel/wireguard/mod.rs @@ -2,12 +2,11 @@ use self::config::Config; use super::{tun_provider::TunProvider, TunnelEvent, TunnelMetadata}; -use crate::routing; +use crate::{ping_monitor, routing}; use std::{collections::HashMap, io, path::Path, sync::mpsc}; use talpid_types::{BoxedError, ErrorExt}; pub mod config; -mod ping_monitor; pub mod wireguard_go; pub use self::wireguard_go::WgGoTunnel; @@ -120,7 +119,7 @@ impl WireguardMonitor { let close_sender = monitor.close_msg_sender.clone(); std::thread::spawn(move || { - match ping_monitor::ping(gateway, PING_TIMEOUT, &iface_name, true) { + match ping_monitor::ping(gateway, PING_TIMEOUT, &iface_name) { Ok(()) => { (on_event)(TunnelEvent::Up(metadata)); |
