summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2021-11-24 15:18:03 +0100
committerDavid Lönnhager <david.l@mullvad.net>2021-11-26 10:42:45 +0100
commitdfadebf2c86474b4ae33bce37bfcd934a0bcce1f (patch)
tree79910b25de2b334c43d7e01ef3a07404b083dbee
parent9bfca257349dad9cde2aac9b1516e71f33f25a23 (diff)
downloadmullvadvpn-dfadebf2c86474b4ae33bce37bfcd934a0bcce1f.tar.xz
mullvadvpn-dfadebf2c86474b4ae33bce37bfcd934a0bcce1f.zip
Don't pass tokio runtime handles to async functions
-rw-r--r--mullvad-daemon/src/lib.rs9
-rw-r--r--mullvad-problem-report/src/lib.rs1
-rw-r--r--mullvad-rpc/src/lib.rs2
-rw-r--r--mullvad-setup/src/main.rs11
-rw-r--r--talpid-core/src/routing/unix.rs9
-rw-r--r--talpid-core/src/routing/windows.rs14
-rw-r--r--talpid-core/src/tunnel_state_machine/mod.rs8
7 files changed, 16 insertions, 38 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 9d64a67bea..80a8061fc8 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -629,7 +629,6 @@ where
};
let mut rpc_runtime = mullvad_rpc::MullvadRpcRuntime::with_cache(
- runtime.clone(),
Some(&resource_dir),
&cache_dir,
true,
@@ -649,7 +648,6 @@ where
let (offline_state_tx, offline_state_rx) = mpsc::unbounded();
let tunnel_command_tx = tunnel_state_machine::spawn(
- runtime.clone(),
tunnel_state_machine::InitialTunnelState {
allow_lan: settings.allow_lan,
block_when_disconnected: settings.block_when_disconnected,
@@ -691,7 +689,7 @@ where
let rpc_handle = rpc_runtime.mullvad_rest_handle();
- Self::forward_offline_state(&runtime, api_availability.clone(), offline_state_rx).await;
+ Self::forward_offline_state(api_availability.clone(), offline_state_rx).await;
let relay_list_listener = event_listener.clone();
let on_relay_list_update = move |relay_list: &RelayList| {
@@ -2427,7 +2425,7 @@ where
) -> Option<mpsc::Sender<mullvad_rpc::SocketBypassRequest>> {
let (bypass_tx, mut bypass_rx) = mpsc::channel(1);
let daemon_tx = event_sender.to_specialized_sender();
- tokio::runtime::Handle::current().spawn(async move {
+ tokio::spawn(async move {
while let Some((raw_fd, done_tx)) = bypass_rx.next().await {
if let Err(_) = daemon_tx.send(DaemonCommand::BypassSocket(raw_fd, done_tx)) {
log::error!("Can't send socket bypass request to daemon");
@@ -2439,7 +2437,6 @@ where
}
async fn forward_offline_state(
- runtime: &tokio::runtime::Handle,
api_availability: ApiAvailabilityHandle,
mut offline_state_rx: mpsc::UnboundedReceiver<bool>,
) {
@@ -2448,7 +2445,7 @@ where
.await
.expect("missing initial offline state");
api_availability.set_offline(initial_state);
- runtime.spawn(async move {
+ tokio::spawn(async move {
while let Some(is_offline) = offline_state_rx.next().await {
api_availability.set_offline(is_offline);
}
diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs
index 9a5bca1a61..56bcb0cdfb 100644
--- a/mullvad-problem-report/src/lib.rs
+++ b/mullvad-problem-report/src/lib.rs
@@ -279,7 +279,6 @@ pub fn send_problem_report(
let mut rpc_manager = runtime
.block_on(mullvad_rpc::MullvadRpcRuntime::with_cache(
- runtime.handle().clone(),
None,
cache_dir,
false,
diff --git a/mullvad-rpc/src/lib.rs b/mullvad-rpc/src/lib.rs
index 61654cab1c..956db21e9d 100644
--- a/mullvad-rpc/src/lib.rs
+++ b/mullvad-rpc/src/lib.rs
@@ -128,12 +128,12 @@ impl MullvadRpcRuntime {
/// Try to use the cache directory first, and fall back on the resource directory
/// if it fails.
pub async fn with_cache(
- handle: tokio::runtime::Handle,
resource_dir: Option<&Path>,
cache_dir: &Path,
write_changes: bool,
#[cfg(target_os = "android")] socket_bypass_tx: Option<mpsc::Sender<SocketBypassRequest>>,
) -> Result<Self, Error> {
+ let handle = tokio::runtime::Handle::current();
#[cfg(feature = "api-override")]
if *DISABLE_ADDRESS_ROTATION {
return Self::new_inner(
diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs
index eb09513a1f..8b9df4b154 100644
--- a/mullvad-setup/src/main.rs
+++ b/mullvad-setup/src/main.rs
@@ -173,14 +173,9 @@ async fn remove_wireguard_key() -> Result<(), Error> {
if let Some(token) = settings.get_account_token() {
if let Some(wg_data) = settings.get_wireguard() {
- let mut rpc_runtime = MullvadRpcRuntime::with_cache(
- tokio::runtime::Handle::current(),
- None,
- &cache_path,
- false,
- )
- .await
- .map_err(Error::RpcInitializationError)?;
+ let mut rpc_runtime = MullvadRpcRuntime::with_cache(None, &cache_path, false)
+ .await
+ .map_err(Error::RpcInitializationError)?;
let mut key_proxy =
mullvad_rpc::WireguardKeyProxy::new(rpc_runtime.mullvad_rest_handle());
retry_future_n(
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(