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 e3151f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 3 additions & 5 deletions talpid-wireguard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Mutex<TunProvider>>,
Expand All @@ -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
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 e3151f7

Please sign in to comment.