diff options
| author | Emīls <emils@mullvad.net> | 2022-03-28 11:45:29 +0100 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2022-03-28 14:38:08 +0100 |
| commit | 8d156280895239741fc506f93c7eb4c0f65ecf78 (patch) | |
| tree | 3200f43bf81e63745c283e03e4a17e303d634643 | |
| parent | 73c1e22f9e3c18bbb67a339c84b9fa92a6c13b32 (diff) | |
| download | mullvadvpn-8d156280895239741fc506f93c7eb4c0f65ecf78.tar.xz mullvadvpn-8d156280895239741fc506f93c7eb4c0f65ecf78.zip | |
Cleanup Android specific code
| -rw-r--r-- | talpid-core/src/ping_monitor/android.rs (renamed from talpid-core/src/ping_monitor/unix.rs) | 32 | ||||
| -rw-r--r-- | talpid-core/src/ping_monitor/mod.rs | 6 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/connectivity_check.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/mod.rs | 2 |
4 files changed, 10 insertions, 34 deletions
diff --git a/talpid-core/src/ping_monitor/unix.rs b/talpid-core/src/ping_monitor/android.rs index b93678a22b..9263dbac79 100644 --- a/talpid-core/src/ping_monitor/unix.rs +++ b/talpid-core/src/ping_monitor/android.rs @@ -15,17 +15,15 @@ pub enum Error { /// A pinger that sends ICMP requests without waiting for responses pub struct Pinger { addr: Ipv4Addr, - interface_name: String, processes: Vec<duct::Handle>, } impl Pinger { /// Creates a new pinger that will send ICMP requests only through the specified interface - pub fn new(addr: Ipv4Addr, interface_name: String) -> Result<Self, Error> { + pub fn new(addr: Ipv4Addr) -> Result<Self, Error> { Ok(Self { processes: vec![], addr, - interface_name, }) } @@ -45,7 +43,7 @@ impl super::Pinger for Pinger { fn send_icmp(&mut self) -> Result<(), Error> { self.try_deplete_process_list(); - let cmd = ping_cmd(self.addr, 1, &self.interface_name); + let cmd = ping_cmd(self.addr, 1); let handle = cmd.start().map_err(Error::PingError)?; self.processes.push(handle); Ok(()) @@ -77,32 +75,10 @@ impl Drop for Pinger { } } -fn ping_cmd(ip: Ipv4Addr, timeout_secs: u16, interface: &str) -> duct::Expression { - let mut args = vec!["-n", "-i", "1"]; - - let timeout_flag = if cfg!(target_os = "linux") || cfg!(target_os = "android") { - "-w" - } else { - "-t" - }; +fn ping_cmd(ip: Ipv4Addr, timeout_secs: u16) -> duct::Expression { let timeout_secs = timeout_secs.to_string(); - - args.extend_from_slice(&[timeout_flag, &timeout_secs]); - - let interface_flag = if cfg!(target_os = "linux") { - Some("-I") - } else if cfg!(target_os = "macos") { - Some("-b") - } else { - None - }; - - if let Some(interface_flag) = interface_flag { - args.extend_from_slice(&[interface_flag, interface]); - } - let ip = ip.to_string(); - args.push(&ip); + let args = ["-n", "-i", "1", "-w", &timeout_secs, &ip]; duct::cmd("ping", args) .stdin_null() diff --git a/talpid-core/src/ping_monitor/mod.rs b/talpid-core/src/ping_monitor/mod.rs index 597ab293a0..9b105a50dc 100644 --- a/talpid-core/src/ping_monitor/mod.rs +++ b/talpid-core/src/ping_monitor/mod.rs @@ -1,5 +1,5 @@ #[cfg(any(target_os = "android"))] -#[path = "unix.rs"] +#[path = "android.rs"] mod imp; #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] @@ -19,11 +19,11 @@ pub trait Pinger: Send { /// Create a new pinger pub fn new_pinger( addr: std::net::Ipv4Addr, - #[cfg(not(target_os = "windows"))] interface_name: String, + #[cfg(any(target_os = "linux", target_os = "macos"))] interface_name: String, ) -> Result<Box<dyn Pinger>, Error> { Ok(Box::new(imp::Pinger::new( addr, - #[cfg(not(target_os = "windows"))] + #[cfg(any(target_os = "linux", target_os = "macos"))] interface_name, )?)) } diff --git a/talpid-core/src/tunnel/wireguard/connectivity_check.rs b/talpid-core/src/tunnel/wireguard/connectivity_check.rs index 162fb248a3..d6bb61a5fc 100644 --- a/talpid-core/src/tunnel/wireguard/connectivity_check.rs +++ b/talpid-core/src/tunnel/wireguard/connectivity_check.rs @@ -81,13 +81,13 @@ pub struct ConnectivityMonitor { impl ConnectivityMonitor { pub(super) fn new( addr: Ipv4Addr, - #[cfg(not(target_os = "windows"))] interface: String, + #[cfg(any(target_os = "macos", target_os = "linux"))] interface: String, tunnel_handle: Weak<Mutex<Option<Box<dyn Tunnel>>>>, close_receiver: mpsc::Receiver<()>, ) -> Result<Self, Error> { let pinger = new_pinger( addr, - #[cfg(not(target_os = "windows"))] + #[cfg(any(target_os = "macos", target_os = "linux"))] interface, ) .map_err(Error::PingError)?; diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs index 817ad74eea..80c8e2ae8e 100644 --- a/talpid-core/src/tunnel/wireguard/mod.rs +++ b/talpid-core/src/tunnel/wireguard/mod.rs @@ -229,7 +229,7 @@ impl WireguardMonitor { let gateway = config.ipv4_gateway; let mut connectivity_monitor = connectivity_check::ConnectivityMonitor::new( gateway, - #[cfg(not(target_os = "windows"))] + #[cfg(any(target_os = "macos", target_os = "linux"))] iface_name.clone(), Arc::downgrade(&monitor.tunnel), pinger_rx, |
