Skip to content

Commit

Permalink
Make start_tunnel async on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Jan 24, 2025
1 parent 49a7342 commit 56058e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
10 changes: 3 additions & 7 deletions talpid-wireguard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ impl WireguardMonitor {
#[cfg(target_os = "windows")]
let (setup_done_tx, setup_done_rx) = mpsc::channel(0);
let tunnel = Self::open_tunnel(
args.runtime.clone(),
&config,
log_path,
#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -632,7 +631,6 @@ impl WireguardMonitor {
#[allow(unused_variables)]
#[cfg(not(target_os = "android"))]
fn open_tunnel(
runtime: tokio::runtime::Handle,
config: &Config,
log_path: Option<&Path>,
#[cfg(windows)] resource_dir: &Path,
Expand Down Expand Up @@ -698,7 +696,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,
Expand Down Expand Up @@ -736,7 +733,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<Mutex<TunProvider>>,
Expand All @@ -755,9 +751,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
Expand Down
13 changes: 5 additions & 8 deletions talpid-wireguard/src/wireguard_go/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
}
Expand Down

0 comments on commit 56058e4

Please sign in to comment.