diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-11-24 15:18:03 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-11-26 10:42:45 +0100 |
| commit | dfadebf2c86474b4ae33bce37bfcd934a0bcce1f (patch) | |
| tree | 79910b25de2b334c43d7e01ef3a07404b083dbee /talpid-core/src | |
| parent | 9bfca257349dad9cde2aac9b1516e71f33f25a23 (diff) | |
| download | mullvadvpn-dfadebf2c86474b4ae33bce37bfcd934a0bcce1f.tar.xz mullvadvpn-dfadebf2c86474b4ae33bce37bfcd934a0bcce1f.zip | |
Don't pass tokio runtime handles to async functions
Diffstat (limited to 'talpid-core/src')
| -rw-r--r-- | talpid-core/src/routing/unix.rs | 9 | ||||
| -rw-r--r-- | talpid-core/src/routing/windows.rs | 14 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/mod.rs | 8 |
3 files changed, 9 insertions, 22 deletions
diff --git a/talpid-core/src/routing/unix.rs b/talpid-core/src/routing/unix.rs index 989ec7ad24..2631acbc89 100644 --- a/talpid-core/src/routing/unix.rs +++ b/talpid-core/src/routing/unix.rs @@ -173,16 +173,13 @@ impl RouteManager { /// Constructs a RouteManager and applies the required routes. /// Takes a set of network destinations and network nodes as an argument, and applies said /// routes. - pub async fn new( - runtime: tokio::runtime::Handle, - required_routes: HashSet<RequiredRoute>, - ) -> Result<Self, Error> { + pub async fn new(required_routes: HashSet<RequiredRoute>) -> Result<Self, Error> { let (manage_tx, manage_rx) = mpsc::unbounded(); let manager = imp::RouteManagerImpl::new(required_routes).await?; - runtime.spawn(manager.run(manage_rx)); + tokio::spawn(manager.run(manage_rx)); Ok(Self { - runtime, + runtime: tokio::runtime::Handle::current(), manage_tx: Some(manage_tx), }) } diff --git a/talpid-core/src/routing/windows.rs b/talpid-core/src/routing/windows.rs index be812ff99a..ec17d4feae 100644 --- a/talpid-core/src/routing/windows.rs +++ b/talpid-core/src/routing/windows.rs @@ -36,7 +36,6 @@ pub type Result<T> = std::result::Result<T, Error>; /// Manages routes by calling into WinNet pub struct RouteManager { - runtime: tokio::runtime::Handle, manage_tx: Option<UnboundedSender<RouteManagerCommand>>, } @@ -66,19 +65,15 @@ pub enum RouteManagerCommand { impl RouteManager { /// Creates a new route manager that will apply the provided routes and ensure they exist until /// it's stopped. - pub async fn new( - runtime: tokio::runtime::Handle, - required_routes: HashSet<RequiredRoute>, - ) -> Result<Self> { + pub async fn new(required_routes: HashSet<RequiredRoute>) -> Result<Self> { if !winnet::activate_routing_manager() { return Err(Error::FailedToStartManager); } let (manage_tx, manage_rx) = mpsc::unbounded(); let manager = Self { - runtime: runtime.clone(), manage_tx: Some(manage_tx), }; - runtime.spawn(RouteManager::listen(manage_rx)); + tokio::spawn(RouteManager::listen(manage_rx)); manager.add_routes(required_routes).await?; Ok(manager) @@ -93,11 +88,6 @@ impl RouteManager { } } - /// Retrieve handle for the tokio runtime. - pub fn runtime_handle(&self) -> tokio::runtime::Handle { - self.runtime.clone() - } - async fn listen(mut manage_rx: UnboundedReceiver<RouteManagerCommand>) { while let Some(command) = manage_rx.next().await { match command { diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index fbc3e05622..509ddd499d 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -97,7 +97,6 @@ pub struct InitialTunnelState { /// Spawn the tunnel state machine thread, returning a channel for sending tunnel commands. pub async fn spawn( - runtime: tokio::runtime::Handle, initial_settings: InitialTunnelState, tunnel_parameters_generator: impl TunnelParametersGenerator, log_dir: Option<PathBuf>, @@ -123,9 +122,9 @@ pub async fn spawn( let (startup_result_tx, startup_result_rx) = sync_mpsc::channel(); let weak_command_tx = Arc::downgrade(&command_tx); + let runtime = tokio::runtime::Handle::current(); std::thread::spawn(move || { let state_machine = runtime.block_on(TunnelStateMachine::new( - runtime.clone(), initial_settings, weak_command_tx, offline_state_listener, @@ -213,7 +212,6 @@ struct TunnelStateMachine { impl TunnelStateMachine { async fn new( - runtime: tokio::runtime::Handle, settings: InitialTunnelState, command_tx: std::sync::Weak<mpsc::UnboundedSender<TunnelCommand>>, offline_state_tx: mpsc::UnboundedSender<bool>, @@ -224,6 +222,8 @@ impl TunnelStateMachine { commands_rx: mpsc::UnboundedReceiver<TunnelCommand>, #[cfg(target_os = "android")] android_context: AndroidContext, ) -> Result<Self, Error> { + let runtime = tokio::runtime::Handle::current(); + #[cfg(windows)] let split_tunnel = split_tunnel::SplitTunnel::new(runtime.clone(), command_tx.clone()) .map_err(Error::InitSplitTunneling)?; @@ -235,7 +235,7 @@ impl TunnelStateMachine { }; let firewall = Firewall::new(args).map_err(Error::InitFirewallError)?; - let route_manager = RouteManager::new(runtime.clone(), HashSet::new()) + let route_manager = RouteManager::new(HashSet::new()) .await .map_err(Error::InitRouteManagerError)?; let dns_monitor = DnsMonitor::new( |
