From e3151f748d1864e686b676cf8c22516fc09811fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Fri, 24 Jan 2025 16:11:53 +0100 Subject: [PATCH] Make start_tunnel async on Windows --- talpid-wireguard/src/lib.rs | 8 +++----- talpid-wireguard/src/wireguard_go/mod.rs | 13 +++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/talpid-wireguard/src/lib.rs b/talpid-wireguard/src/lib.rs index ea3207f12da2..330a2c76cf9d 100644 --- a/talpid-wireguard/src/lib.rs +++ b/talpid-wireguard/src/lib.rs @@ -698,7 +698,6 @@ impl WireguardMonitor { log::debug!("Using userspace WireGuard implementation"); let tunnel = runtime .block_on(Self::open_wireguard_go_tunnel( - runtime, config, log_path, setup_done_tx, @@ -736,7 +735,6 @@ impl WireguardMonitor { #[cfg(wireguard_go)] #[allow(clippy::unused_async)] async fn open_wireguard_go_tunnel( - #[cfg(windows)] runtime: tokio::runtime::Handle, config: &Config, log_path: Option<&Path>, #[cfg(unix)] tun_provider: Arc>, @@ -755,9 +753,9 @@ impl WireguardMonitor { .map_err(Error::TunnelError)?; #[cfg(target_os = "windows")] - let tunnel = - WgGoTunnel::start_tunnel(runtime, config, log_path, route_manager, setup_done_tx) - .map_err(Error::TunnelError)?; + let tunnel = WgGoTunnel::start_tunnel(config, log_path, route_manager, setup_done_tx) + .await + .map_err(Error::TunnelError)?; // Android uses multihop implemented in Mullvad's wireguard-go fork. When negotiating // with an ephemeral peer, this multihop strategy require us to restart the tunnel diff --git a/talpid-wireguard/src/wireguard_go/mod.rs b/talpid-wireguard/src/wireguard_go/mod.rs index 0e64797ad537..1c6fc41fd34c 100644 --- a/talpid-wireguard/src/wireguard_go/mod.rs +++ b/talpid-wireguard/src/wireguard_go/mod.rs @@ -260,8 +260,7 @@ impl WgGoTunnel { } #[cfg(target_os = "windows")] - pub fn start_tunnel( - runtime: tokio::runtime::Handle, + pub async fn start_tunnel( config: &Config, log_path: Option<&Path>, route_manager: talpid_routing::RouteManagerHandle, @@ -275,12 +274,10 @@ impl WgGoTunnel { .map(|ordinal| LoggingContext::new(ordinal, log_path.map(Path::to_owned))) .map_err(TunnelError::LoggingError)?; - let socket_update_cb = - runtime - .block_on(route_manager.add_default_route_change_callback(Box::new( - Self::default_route_changed_callback, - ))) - .ok(); + let socket_update_cb = route_manager + .add_default_route_change_callback(Box::new(Self::default_route_changed_callback)) + .await + .ok(); if socket_update_cb.is_none() { log::warn!("Failed to register default route callback"); }