From 0d3732667b90ca5c75f3dbe22d23d425dbb98097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Fri, 24 Jan 2025 11:21:47 +0100 Subject: [PATCH] Fix connection loop --- talpid-wireguard/src/wireguard_go/mod.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/talpid-wireguard/src/wireguard_go/mod.rs b/talpid-wireguard/src/wireguard_go/mod.rs index b91f3c464a4c..caf2af195f17 100644 --- a/talpid-wireguard/src/wireguard_go/mod.rs +++ b/talpid-wireguard/src/wireguard_go/mod.rs @@ -144,11 +144,30 @@ impl WgGoTunnel { } WgGoTunnel::Singlehop(mut state) => { state.set_config(config.clone())?; - Ok(WgGoTunnel::Singlehop(state)) + + // HACK: Check if the tunnel is working by sending a ping in the tunnel. + let mut connectivity_checker = state + .connectivity_checker + .take() + .expect("connectivity checker unexpectedly dropped"); + let mut new_state = WgGoTunnel::Singlehop(state); + new_state.ensure_tunnel_is_running(&mut connectivity_checker)?; + new_state.as_state_mut().connectivity_checker = Some(connectivity_checker); + Ok(new_state) } WgGoTunnel::Multihop(mut state) => { state.set_config(config.clone())?; - Ok(WgGoTunnel::Multihop(state)) + + // HACK: Check if the tunnel is working by sending a ping in the tunnel. + let mut connectivity_checker = state + .connectivity_checker + .take() + .expect("connectivity checker unexpectedly dropped"); + let mut new_state = WgGoTunnel::Multihop(state); + new_state.ensure_tunnel_is_running(&mut connectivity_checker)?; + new_state.as_state_mut().connectivity_checker = Some(connectivity_checker); + + Ok(new_state) } } }