Skip to content

Commit

Permalink
Make tunnel connection errors recoverable
Browse files Browse the repository at this point in the history
  • Loading branch information
kl authored and Pururun committed Nov 28, 2024
1 parent 64a6fcb commit b3c31e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
9 changes: 0 additions & 9 deletions talpid-wireguard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,15 +1087,6 @@ pub enum TunnelError {
#[cfg(daita)]
#[error("Failed to start DAITA - tunnel implemenation does not support DAITA")]
DaitaNotSupported,

/// [connectivity] error.
#[error(transparent)]
Connectivity(#[from] Box<connectivity::Error>),

/// Tunnel seemingly does not serve any traffic
#[cfg(target_os = "android")]
#[error("Tunnel seemingly does not serve any traffic")]
TunnelUp,
}

#[cfg(target_os = "linux")]
Expand Down
9 changes: 6 additions & 3 deletions talpid-wireguard/src/wireguard_go/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(target_os = "android")]
use super::config;
#[cfg(target_os = "android")]
use super::Error;
use super::{
stats::{Stats, StatsMap},
Config, Tunnel, TunnelError,
Expand Down Expand Up @@ -434,14 +436,15 @@ impl WgGoTunnel {
&self,
checker: &mut connectivity::Check<connectivity::Cancellable>,
) -> Result<()> {
let connectivity_err = |e| TunnelError::Connectivity(Box::new(e));
let connection_established = checker
.establish_connectivity(self)
.map_err(connectivity_err)?;
.map_err(|e| TunnelError::RecoverableStartWireguardError(Box::new(e)))?;

// Timed out
if !connection_established {
return Err(TunnelError::TunnelUp);
return Err(TunnelError::RecoverableStartWireguardError(Box::new(
Error::TimeoutError,
)));
}
Ok(())
}
Expand Down

0 comments on commit b3c31e4

Please sign in to comment.