diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-05-29 17:31:52 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-06-10 21:42:33 +0000 |
| commit | 76de34848a130d44831d5e57ddb56f13fb570bea (patch) | |
| tree | 9ffd9efb92a1ddd5528514b614e01674378fb21c | |
| parent | 361811fde05c8d7d948b4ce1ffd33ae34934fb60 (diff) | |
| download | mullvadvpn-76de34848a130d44831d5e57ddb56f13fb570bea.tar.xz mullvadvpn-76de34848a130d44831d5e57ddb56f13fb570bea.zip | |
Enable Wireguard on Android
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index 62bc165ed6..a8c601b724 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -9,7 +9,7 @@ use std::{ }; #[cfg(not(target_os = "android"))] use talpid_types::net::openvpn as openvpn_types; -#[cfg(any(target_os = "linux", target_os = "macos"))] +#[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] use talpid_types::net::wireguard as wireguard_types; use talpid_types::net::{GenericTunnelOptions, TunnelParameters}; @@ -17,7 +17,7 @@ use talpid_types::net::{GenericTunnelOptions, TunnelParameters}; #[cfg(not(target_os = "android"))] pub mod openvpn; -#[cfg(any(target_os = "linux", target_os = "macos"))] +#[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] pub mod wireguard; /// A module for low level platform specific tunnel device management. @@ -45,7 +45,7 @@ pub enum Error { RotateLogError(#[error(cause)] crate::logging::RotateLogError), /// Failure to build Wireguard configuration. - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] #[error(display = "Failed to configure Wireguard with the given parameters")] WireguardConfigError(#[error(cause)] self::wireguard::config::Error), @@ -55,7 +55,7 @@ pub enum Error { OpenVpnTunnelMonitoringError(#[error(cause)] openvpn::Error), /// There was an error listening for events from the Wireguard tunnel - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] #[error(display = "Failed while listening for events from the Wireguard tunnel")] WirguardTunnelMonitoringError(#[error(cause)] wireguard::Error), } @@ -158,18 +158,19 @@ impl TunnelMonitor { TunnelParameters::OpenVpn(config) => { Self::start_openvpn_tunnel(&config, log_file, resource_dir, on_event) } - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(target_os = "android")] + TunnelParameters::OpenVpn(_) => Err(Error::UnsupportedPlatform), + + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] TunnelParameters::Wireguard(config) => { Self::start_wireguard_tunnel(&config, log_file, on_event, tun_provider) } - #[cfg(target_os = "android")] - TunnelParameters::OpenVpn(_) => Err(Error::UnsupportedPlatform), - #[cfg(any(windows, target_os = "android"))] + #[cfg(windows)] TunnelParameters::Wireguard(_) => Err(Error::UnsupportedPlatform), } } - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] fn start_wireguard_tunnel<L>( params: &wireguard_types::TunnelParameters, log: Option<PathBuf>, @@ -252,7 +253,7 @@ pub enum CloseHandle { #[cfg(not(target_os = "android"))] /// OpenVpn close handle OpenVpn(openvpn::OpenVpnCloseHandle), - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] /// Wireguard close handle Wireguard(wireguard::CloseHandle), } @@ -260,13 +261,10 @@ pub enum CloseHandle { impl CloseHandle { /// Closes the underlying tunnel, making the `TunnelMonitor::wait` method return. pub fn close(self) -> io::Result<()> { - #[cfg(target_os = "android")] - unimplemented!(); - - #[cfg(not(target_os = "android"))] match self { + #[cfg(not(target_os = "android"))] CloseHandle::OpenVpn(handle) => handle.close(), - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] CloseHandle::Wireguard(mut handle) => { handle.close(); Ok(()) @@ -278,28 +276,25 @@ impl CloseHandle { enum InternalTunnelMonitor { #[cfg(not(target_os = "android"))] OpenVpn(openvpn::OpenVpnMonitor), - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] Wireguard(wireguard::WireguardMonitor), } impl InternalTunnelMonitor { fn close_handle(&self) -> CloseHandle { - #[cfg(not(target_os = "android"))] match self { + #[cfg(not(target_os = "android"))] InternalTunnelMonitor::OpenVpn(tun) => CloseHandle::OpenVpn(tun.close_handle()), - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] InternalTunnelMonitor::Wireguard(tun) => CloseHandle::Wireguard(tun.close_handle()), } - - #[cfg(target_os = "android")] - unimplemented!(); } fn wait(self) -> Result<()> { - #[cfg(not(target_os = "android"))] match self { + #[cfg(not(target_os = "android"))] InternalTunnelMonitor::OpenVpn(tun) => tun.wait()?, - #[cfg(any(target_os = "linux", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] InternalTunnelMonitor::Wireguard(tun) => tun.wait()?, } |
