diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-12-02 14:23:39 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-12-03 12:30:33 +0000 |
| commit | 7391871673e0640e04a4e2cb0e1d900042d16389 (patch) | |
| tree | 8dfb8d47a905ae2a9eb659f3b8747a35c96a161e | |
| parent | 5f3e7e8903ea40cc0d9cb7e07683d9cd04d6e0c2 (diff) | |
| download | mullvadvpn-7391871673e0640e04a4e2cb0e1d900042d16389.tar.xz mullvadvpn-7391871673e0640e04a4e2cb0e1d900042d16389.zip | |
Remove `TunProvider` and `Tun` traits
Use the types directly.
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 6 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/tun_provider/android.rs | 111 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/tun_provider/mod.rs | 72 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/tun_provider/stub.rs | 27 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/tun_provider/unix.rs | 40 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/tun_provider/windows.rs | 13 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/mod.rs | 11 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/wireguard_go.rs | 39 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/blocked_state.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/connecting_state.rs | 10 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/disconnected_state.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/mod.rs | 10 |
12 files changed, 137 insertions, 206 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index ddf19fcb66..6d167efed3 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -18,7 +18,7 @@ pub mod openvpn; pub mod wireguard; /// A module for low level platform specific tunnel device management. -pub mod tun_provider; +pub(crate) mod tun_provider; const OPENVPN_LOG_FILENAME: &str = "openvpn.log"; const WIREGUARD_LOG_FILENAME: &str = "wireguard.log"; @@ -140,7 +140,7 @@ impl TunnelMonitor { log_dir: &Option<PathBuf>, resource_dir: &Path, on_event: L, - tun_provider: &mut dyn TunProvider, + tun_provider: &mut TunProvider, ) -> Result<Self> where L: Fn(TunnelEvent) + Send + Clone + Sync + 'static, @@ -166,7 +166,7 @@ impl TunnelMonitor { params: &wireguard_types::TunnelParameters, log: Option<PathBuf>, on_event: L, - tun_provider: &mut dyn TunProvider, + tun_provider: &mut TunProvider, ) -> Result<Self> where L: Fn(TunnelEvent) + Send + Sync + Clone + 'static, diff --git a/talpid-core/src/tunnel/tun_provider/android.rs b/talpid-core/src/tunnel/tun_provider/android.rs index 8bf3ed7772..19d4325abf 100644 --- a/talpid-core/src/tunnel/tun_provider/android.rs +++ b/talpid-core/src/tunnel/tun_provider/android.rs @@ -1,4 +1,4 @@ -use super::{Tun, TunConfig, TunProvider}; +use super::TunConfig; use ipnetwork::IpNetwork; use jnix::{ jni::{ @@ -13,7 +13,7 @@ use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr}, os::unix::io::{AsRawFd, FromRawFd, RawFd}, }; -use talpid_types::{android::AndroidContext, BoxedError}; +use talpid_types::android::AndroidContext; /// Errors that occur while setting up VpnService tunnel. @@ -87,6 +87,44 @@ impl AndroidTunProvider { } } + /// Retrieve a tunnel device with the provided configuration. + pub fn get_tun(&mut self, config: TunConfig) -> Result<VpnServiceTun, Error> { + let tun_fd = self.get_tun_fd(config)?; + + let jvm = unsafe { JavaVM::from_raw(self.jvm.get_java_vm_pointer()) } + .map_err(Error::CloneJavaVm)?; + + Ok(VpnServiceTun { + tunnel: tun_fd, + jvm, + class: self.class.clone(), + object: self.object.clone(), + }) + } + + /// Open a tunnel device using the previous or the default configuration. + /// + /// Will open a new tunnel if there is already an active tunnel. The previous tunnel will be + /// closed. + pub fn create_tun(&mut self) -> Result<(), Error> { + self.open_tun(self.last_tun_config.clone()) + } + + /// Open a tunnel device using the previous or the default configuration if there is no + /// currently active tunnel. + pub fn create_tun_if_closed(&mut self) -> Result<(), Error> { + if self.active_tun.is_none() { + self.create_tun()?; + } + + Ok(()) + } + + /// Close currently active tunnel device. + pub fn close_tun(&mut self) { + self.active_tun = None; + } + fn get_tun_fd(&mut self, config: TunConfig) -> Result<RawFd, Error> { if self.active_tun.is_none() || self.last_tun_config != config { self.open_tun(config)?; @@ -140,66 +178,30 @@ impl AndroidTunProvider { } } -impl TunProvider for AndroidTunProvider { - fn get_tun(&mut self, config: TunConfig) -> Result<Box<dyn Tun>, BoxedError> { - let tun_fd = self.get_tun_fd(config).map_err(BoxedError::new)?; - - let jvm = unsafe { JavaVM::from_raw(self.jvm.get_java_vm_pointer()) } - .map_err(|cause| BoxedError::new(Error::CloneJavaVm(cause)))?; - - Ok(Box::new(VpnServiceTun { - tunnel: tun_fd, - jvm, - class: self.class.clone(), - object: self.object.clone(), - })) - } - - fn create_tun(&mut self) -> Result<(), BoxedError> { - self.open_tun(self.last_tun_config.clone()) - .map_err(BoxedError::new) - } - - fn create_tun_if_closed(&mut self) -> Result<(), BoxedError> { - if self.active_tun.is_none() { - self.create_tun()?; - } - - Ok(()) - } - - fn close_tun(&mut self) { - self.active_tun = None; - } -} - -struct VpnServiceTun { +/// Handle to a tunnel device on Android. +pub struct VpnServiceTun { tunnel: RawFd, jvm: JavaVM, class: GlobalRef, object: GlobalRef, } -impl AsRawFd for VpnServiceTun { - fn as_raw_fd(&self) -> RawFd { - self.tunnel - } -} - -impl Tun for VpnServiceTun { - fn interface_name(&self) -> &str { +impl VpnServiceTun { + /// Retrieve the tunnel interface name. + pub fn interface_name(&self) -> &str { "tun" } - fn bypass(&mut self, socket: RawFd) -> Result<(), BoxedError> { + /// Allow a socket to bypass the tunnel. + pub fn bypass(&mut self, socket: RawFd) -> Result<(), Error> { let env = JnixEnv::from( self.jvm .attach_current_thread_as_daemon() - .map_err(|cause| BoxedError::new(Error::AttachJvmToThread(cause)))?, + .map_err(|cause| Error::AttachJvmToThread(cause))?, ); let create_tun_method = env .get_method_id(&self.class, "bypass", "(I)Z") - .map_err(|cause| BoxedError::new(Error::FindMethod("bypass", cause)))?; + .map_err(|cause| Error::FindMethod("bypass", cause))?; let result = env .call_method_unchecked( @@ -208,15 +210,18 @@ impl Tun for VpnServiceTun { JavaType::Primitive(Primitive::Boolean), &[JValue::Int(socket)], ) - .map_err(|cause| BoxedError::new(Error::CallMethod("bypass", cause)))?; + .map_err(|cause| Error::CallMethod("bypass", cause))?; match result { - JValue::Bool(0) => Err(BoxedError::new(Error::Bypass)), + JValue::Bool(0) => Err(Error::Bypass), JValue::Bool(_) => Ok(()), - value => Err(BoxedError::new(Error::InvalidMethodResult( - "bypass", - format!("{:?}", value), - ))), + value => Err(Error::InvalidMethodResult("bypass", format!("{:?}", value))), } } } + +impl AsRawFd for VpnServiceTun { + fn as_raw_fd(&self) -> RawFd { + self.tunnel + } +} diff --git a/talpid-core/src/tunnel/tun_provider/mod.rs b/talpid-core/src/tunnel/tun_provider/mod.rs index fe044ea49f..b4751e019f 100644 --- a/talpid-core/src/tunnel/tun_provider/mod.rs +++ b/talpid-core/src/tunnel/tun_provider/mod.rs @@ -3,85 +3,33 @@ use ipnetwork::IpNetwork; #[cfg(target_os = "android")] use jnix::IntoJava; use std::net::IpAddr; -#[cfg(unix)] -use std::os::unix::io::AsRawFd; -#[cfg(target_os = "android")] -use std::os::unix::io::RawFd; -use talpid_types::BoxedError; cfg_if! { if #[cfg(target_os = "android")] { #[path = "android.rs"] mod imp; - use self::imp::AndroidTunProvider; + use self::imp::{AndroidTunProvider, VpnServiceTun}; + pub use self::imp::Error; - /// Default implementation of `TunProvider` for Android. - pub type PlatformTunProvider = AndroidTunProvider; + pub type Tun = VpnServiceTun; + pub type TunProvider = AndroidTunProvider; } else if #[cfg(all(unix, not(target_os = "android")))] { #[path = "unix.rs"] mod imp; - use self::imp::UnixTunProvider; + use self::imp::{UnixTun, UnixTunProvider}; + pub use self::imp::Error; - /// Default implementation of `TunProvider` for Unix based operating systems. - /// - /// Android has a different mechanism to obtain tunnel interfaces, so it is not supported - /// here. - pub type PlatformTunProvider = UnixTunProvider; + pub type Tun = UnixTun; + pub type TunProvider = UnixTunProvider; } else { mod stub; use self::stub::StubTunProvider; + pub use self::stub::Error; - /// Default stub implementation of `TunProvider` and Windows. - pub type PlatformTunProvider = StubTunProvider; + pub type TunProvider = StubTunProvider; } } -/// Windows tunnel -#[cfg(target_os = "windows")] -pub mod windows; - -/// Generic tunnel device. -/// -/// Must be associated with a platform specific file descriptor representing the device. -#[cfg(unix)] -pub trait Tun: AsRawFd + Send { - /// Retrieve the tunnel interface name. - fn interface_name(&self) -> &str; - - /// Allow a socket to bypass the tunnel. - #[cfg(target_os = "android")] - fn bypass(&mut self, socket: RawFd) -> Result<(), BoxedError>; -} - -/// Stub tunnel device. -#[cfg(windows)] -pub trait Tun: Send { - /// Retrieve the tunnel interface name. - fn interface_name(&self) -> &str; -} - -/// Factory of tunnel devices. -pub trait TunProvider: Send + 'static { - /// Retrieve a tunnel device with the provided configuration. - fn get_tun(&mut self, config: TunConfig) -> Result<Box<dyn Tun>, BoxedError>; - - /// Open a tunnel device using the previous or the default configuration. - /// - /// Will open a new tunnel if there is already an active tunnel. The previous tunnel will be - /// closed. - #[cfg(target_os = "android")] - fn create_tun(&mut self) -> Result<(), BoxedError>; - - /// Open a tunnel device using the previous or the default configuration if there is no - /// currently active tunnel. - #[cfg(target_os = "android")] - fn create_tun_if_closed(&mut self) -> Result<(), BoxedError>; - - /// Close currently active tunnel device. - #[cfg(target_os = "android")] - fn close_tun(&mut self); -} - /// Configuration for creating a tunnel device. #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(target_os = "android", derive(IntoJava))] diff --git a/talpid-core/src/tunnel/tun_provider/stub.rs b/talpid-core/src/tunnel/tun_provider/stub.rs index 76f3f9d05f..ff659210cf 100644 --- a/talpid-core/src/tunnel/tun_provider/stub.rs +++ b/talpid-core/src/tunnel/tun_provider/stub.rs @@ -1,32 +1,17 @@ -use super::{Tun, TunConfig, TunProvider}; -use talpid_types::BoxedError; +use super::TunConfig; + +/// Error stub. +pub enum Error {} /// Factory stub of tunnel devices. pub struct StubTunProvider; impl StubTunProvider { - fn new() -> Self { + pub fn new() -> Self { StubTunProvider } -} - -impl TunProvider for StubTunProvider { - fn get_tun(&mut self, _: TunConfig) -> Result<Box<dyn Tun>, BoxedError> { - unimplemented!(); - } - - #[cfg(target_os = "android")] - fn create_tun(&mut self) -> Result<(), BoxedError> { - unimplemented!(); - } - - #[cfg(target_os = "android")] - fn create_tun_if_closed(&mut self) -> Result<(), BoxedError> { - unimplemented!(); - } - #[cfg(target_os = "android")] - fn close_tun(&mut self) { + pub fn get_tun(&mut self, _: TunConfig) -> Result<(), Error> { unimplemented!(); } } diff --git a/talpid-core/src/tunnel/tun_provider/unix.rs b/talpid-core/src/tunnel/tun_provider/unix.rs index 2c10cd8f28..d8d3b7ce01 100644 --- a/talpid-core/src/tunnel/tun_provider/unix.rs +++ b/talpid-core/src/tunnel/tun_provider/unix.rs @@ -1,7 +1,6 @@ -use super::{Tun, TunConfig, TunProvider}; +use super::TunConfig; use crate::network_interface::{self, NetworkInterface, TunnelDevice}; -use std::net::IpAddr; -use talpid_types::BoxedError; +use std::{net::IpAddr, ops::Deref}; /// Errors that can occur while setting up a tunnel device. #[derive(Debug, err_derive::Error)] @@ -24,32 +23,41 @@ pub enum Error { pub struct UnixTunProvider; impl UnixTunProvider { - fn new() -> Self { + pub fn new() -> Self { UnixTunProvider } -} -impl TunProvider for UnixTunProvider { - fn get_tun(&mut self, config: TunConfig) -> Result<Box<dyn Tun>, BoxedError> { - let mut tunnel_device = TunnelDevice::new() - .map_err(|cause| BoxedError::new(Error::CreateTunnelDevice(cause)))?; + pub fn get_tun(&mut self, config: TunConfig) -> Result<UnixTun, Error> { + let mut tunnel_device = TunnelDevice::new().map_err(Error::CreateTunnelDevice)?; for ip in config.addresses.iter() { tunnel_device .set_ip(*ip) - .map_err(|cause| BoxedError::new(Error::SetIpAddr(*ip, cause)))?; + .map_err(|cause| Error::SetIpAddr(*ip, cause))?; } - tunnel_device - .set_up(true) - .map_err(|cause| BoxedError::new(Error::SetUp(cause)))?; + tunnel_device.set_up(true).map_err(Error::SetUp)?; - Ok(Box::new(tunnel_device)) + Ok(UnixTun(tunnel_device)) } } -impl Tun for TunnelDevice { - fn interface_name(&self) -> &str { +/// Generic tunnel device. +/// +/// Contains the file descriptor representing the device. +pub struct UnixTun(TunnelDevice); + +impl UnixTun { + /// Retrieve the tunnel interface name. + pub fn interface_name(&self) -> &str { self.get_name() } } + +impl Deref for UnixTun { + type Target = TunnelDevice; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} diff --git a/talpid-core/src/tunnel/tun_provider/windows.rs b/talpid-core/src/tunnel/tun_provider/windows.rs deleted file mode 100644 index 9a114bf4b7..0000000000 --- a/talpid-core/src/tunnel/tun_provider/windows.rs +++ /dev/null @@ -1,13 +0,0 @@ -use super::Tun; - -/// Windows tunnel implementation -pub struct WinTun { - /// Name of tunnel interface - pub interface_name: String, -} - -impl Tun for WinTun { - fn interface_name(&self) -> &str { - &self.interface_name - } -} diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs index d45a5676c3..a2c632d36f 100644 --- a/talpid-core/src/tunnel/wireguard/mod.rs +++ b/talpid-core/src/tunnel/wireguard/mod.rs @@ -1,10 +1,12 @@ #![allow(missing_docs)] use self::config::Config; +#[cfg(not(windows))] +use super::tun_provider; use super::{tun_provider::TunProvider, TunnelEvent, TunnelMetadata}; use crate::{ping_monitor, routing}; use std::{collections::HashMap, io, path::Path, sync::mpsc}; -use talpid_types::{BoxedError, ErrorExt}; +use talpid_types::ErrorExt; pub mod config; pub mod wireguard_go; @@ -21,8 +23,9 @@ pub type Result<T> = std::result::Result<T, Error>; #[error(no_from)] pub enum Error { /// Failed to setup a tunnel device. + #[cfg(not(windows))] #[error(display = "Failed to create tunnel device")] - SetupTunnelDeviceError(#[error(source)] BoxedError), + SetupTunnelDeviceError(#[error(source)] tun_provider::Error), /// A recoverable error occurred while starting the wireguard tunnel /// @@ -63,7 +66,7 @@ pub enum Error { /// Failed to configure Wireguard sockets to bypass the tunnel. #[cfg(target_os = "android")] #[error(display = "Failed to configure Wireguard sockets to bypass the tunnel")] - BypassError(#[error(source)] BoxedError), + BypassError(#[error(source)] tun_provider::Error), /// Failed to duplicate tunnel file descriptor for wireguard-go #[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))] @@ -93,7 +96,7 @@ impl WireguardMonitor { config: &Config, log_path: Option<&Path>, on_event: F, - tun_provider: &mut dyn TunProvider, + tun_provider: &mut TunProvider, ) -> Result<WireguardMonitor> { let tunnel = Box::new(WgGoTunnel::start_tunnel( &config, diff --git a/talpid-core/src/tunnel/wireguard/wireguard_go.rs b/talpid-core/src/tunnel/wireguard/wireguard_go.rs index f1570a0a4a..cff7f2f946 100644 --- a/talpid-core/src/tunnel/wireguard/wireguard_go.rs +++ b/talpid-core/src/tunnel/wireguard/wireguard_go.rs @@ -1,23 +1,24 @@ use super::{Config, Error, Result, Tunnel}; -use crate::tunnel::tun_provider::{Tun, TunProvider}; +use crate::tunnel::tun_provider::TunProvider; use ipnetwork::IpNetwork; use std::{ffi::CString, path::Path}; +#[cfg(target_os = "android")] +use crate::tunnel::tun_provider; + #[cfg(not(target_os = "windows"))] use { - crate::tunnel::tun_provider::TunConfig, - std::{net::IpAddr, os::unix::io::RawFd, ptr}, + crate::tunnel::tun_provider::{Tun, TunConfig}, + std::{ + net::IpAddr, + os::unix::io::{AsRawFd, RawFd}, + ptr, + }, }; -#[cfg(target_os = "android")] -use talpid_types::BoxedError; - #[cfg(target_os = "windows")] use { - crate::{ - tunnel::tun_provider::windows::WinTun, - winnet::{self, add_device_ip_addresses}, - }, + crate::winnet::{self, add_device_ip_addresses}, chrono, parking_lot::Mutex, std::{collections::HashMap, fs, io::Write}, @@ -41,7 +42,8 @@ pub struct WgGoTunnel { handle: Option<i32>, // holding on to the tunnel device and the log file ensures that the associated file handles // live long enough and get closed when the tunnel is stopped - _tunnel_device: Box<dyn Tun>, + #[cfg(not(target_os = "windows"))] + _tunnel_device: Tun, // ordinal that maps to fs::File instance, used with logging callback #[cfg(target_os = "windows")] log_context_ordinal: u32, @@ -52,7 +54,7 @@ impl WgGoTunnel { pub fn start_tunnel( config: &Config, log_path: Option<&Path>, - tun_provider: &mut dyn TunProvider, + tun_provider: &mut TunProvider, routes: impl Iterator<Item = IpNetwork>, ) -> Result<Self> { #[cfg_attr(not(target_os = "android"), allow(unused_mut))] @@ -103,7 +105,7 @@ impl WgGoTunnel { pub fn start_tunnel( config: &Config, log_path: Option<&Path>, - _tun_provider: &dyn TunProvider, + _tun_provider: &mut TunProvider, _routes: impl Iterator<Item = IpNetwork>, ) -> Result<Self> { let log_file = prepare_log_file(log_path)?; @@ -145,9 +147,6 @@ impl WgGoTunnel { Ok(WgGoTunnel { interface_name: iface_name.clone(), handle: Some(handle), - _tunnel_device: Box::new(WinTun { - interface_name: iface_name.clone(), - }), log_context_ordinal, }) } @@ -236,9 +235,9 @@ impl WgGoTunnel { #[cfg(target_os = "android")] fn bypass_tunnel_sockets( - tunnel_device: &mut Box<dyn Tun>, + tunnel_device: &mut Tun, handle: i32, - ) -> std::result::Result<(), BoxedError> { + ) -> std::result::Result<(), tun_provider::Error> { let socket_v4 = unsafe { wgGetSocketV4(handle) }; let socket_v6 = unsafe { wgGetSocketV6(handle) }; @@ -260,10 +259,10 @@ impl WgGoTunnel { #[cfg(not(target_os = "windows"))] fn get_tunnel( - tun_provider: &mut dyn TunProvider, + tun_provider: &mut TunProvider, config: &Config, routes: impl Iterator<Item = IpNetwork>, - ) -> Result<(Box<dyn Tun>, RawFd)> { + ) -> Result<(Tun, RawFd)> { let mut last_error = None; let tunnel_config = Self::create_tunnel_config(config, routes); diff --git a/talpid-core/src/tunnel_state_machine/blocked_state.rs b/talpid-core/src/tunnel_state_machine/blocked_state.rs index 6e4fd5caab..bdf054ab2c 100644 --- a/talpid-core/src/tunnel_state_machine/blocked_state.rs +++ b/talpid-core/src/tunnel_state_machine/blocked_state.rs @@ -2,7 +2,7 @@ use super::{ ConnectingState, DisconnectedState, EventConsequence, SharedTunnelStateValues, TunnelCommand, TunnelState, TunnelStateTransition, TunnelStateWrapper, }; -use crate::{firewall::FirewallPolicy, tunnel::tun_provider::TunProvider}; +use crate::firewall::FirewallPolicy; use futures::{sync::mpsc, Stream}; use talpid_types::{tunnel::BlockReason, ErrorExt}; diff --git a/talpid-core/src/tunnel_state_machine/connecting_state.rs b/talpid-core/src/tunnel_state_machine/connecting_state.rs index f87b96382f..67036ea98e 100644 --- a/talpid-core/src/tunnel_state_machine/connecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/connecting_state.rs @@ -15,7 +15,6 @@ use futures::{ }; use log::{debug, error, info, trace, warn}; use std::{ - borrow::BorrowMut, net::IpAddr, path::{Path, PathBuf}, thread, @@ -65,7 +64,7 @@ impl ConnectingState { parameters: TunnelParameters, log_dir: &Option<PathBuf>, resource_dir: &Path, - tun_provider: &mut dyn TunProvider, + tun_provider: &mut TunProvider, retry_attempt: u32, ) -> crate::tunnel::Result<Self> { let (event_tx, event_rx) = mpsc::unbounded(); @@ -351,13 +350,10 @@ impl TunnelState for ConnectingState { ); BlockedState::enter(shared_values, BlockReason::StartTunnelError) } else { - let tun_provider: &mut dyn TunProvider = - shared_values.tun_provider.borrow_mut(); - #[cfg(target_os = "android")] { if retry_attempt > 0 && retry_attempt % MAX_ATTEMPTS_WITH_SAME_TUN == 0 { - if let Err(error) = tun_provider.create_tun() { + if let Err(error) = shared_values.tun_provider.create_tun() { error!( "{}", error.display_chain_with_msg("Failed to recreate tun device") @@ -370,7 +366,7 @@ impl TunnelState for ConnectingState { tunnel_parameters, &shared_values.log_dir, &shared_values.resource_dir, - tun_provider, + &mut shared_values.tun_provider, retry_attempt, ) { Ok(connecting_state) => { diff --git a/talpid-core/src/tunnel_state_machine/disconnected_state.rs b/talpid-core/src/tunnel_state_machine/disconnected_state.rs index 20a93f3947..6b95548ddd 100644 --- a/talpid-core/src/tunnel_state_machine/disconnected_state.rs +++ b/talpid-core/src/tunnel_state_machine/disconnected_state.rs @@ -2,7 +2,7 @@ use super::{ BlockedState, ConnectingState, EventConsequence, SharedTunnelStateValues, TunnelCommand, TunnelState, TunnelStateTransition, TunnelStateWrapper, }; -use crate::{firewall::FirewallPolicy, tunnel::tun_provider::TunProvider}; +use crate::firewall::FirewallPolicy; use futures::{sync::mpsc, Stream}; use talpid_types::ErrorExt; diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index 482e50a952..d81a787f1a 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -19,7 +19,7 @@ use crate::{ firewall::{Firewall, FirewallArguments}, mpsc::IntoSender, offline, - tunnel::tun_provider::PlatformTunProvider, + tunnel::tun_provider::TunProvider, }; use futures::{sync::mpsc, Async, Future, Poll, Stream}; use std::{ @@ -82,7 +82,7 @@ where offline::spawn_monitor(Arc::downgrade(&command_tx)).map_err(Error::OfflineMonitorError)?; let is_offline = offline_monitor.is_offline(); - let tun_provider = PlatformTunProvider::new( + let tun_provider = TunProvider::new( #[cfg(target_os = "android")] android_context, ); @@ -133,7 +133,7 @@ fn create_event_loop<T>( block_when_disconnected: bool, is_offline: bool, tunnel_parameters_generator: impl TunnelParametersGenerator, - tun_provider: PlatformTunProvider, + tun_provider: TunProvider, log_dir: Option<PathBuf>, resource_dir: PathBuf, cache_dir: impl AsRef<Path>, @@ -199,7 +199,7 @@ impl TunnelStateMachine { block_when_disconnected: bool, is_offline: bool, tunnel_parameters_generator: impl TunnelParametersGenerator, - tun_provider: PlatformTunProvider, + tun_provider: TunProvider, log_dir: Option<PathBuf>, resource_dir: PathBuf, cache_dir: impl AsRef<Path>, @@ -313,7 +313,7 @@ struct SharedTunnelStateValues { /// The generator of new `TunnelParameter`s tunnel_parameters_generator: Box<dyn TunnelParametersGenerator>, /// The provider of tunnel devices. - tun_provider: PlatformTunProvider, + tun_provider: TunProvider, /// Directory to store tunnel log file. log_dir: Option<PathBuf>, /// Resource directory path. |
