Skip to content

Commit

Permalink
WIP Call waitForRoutes from Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Jan 23, 2025
1 parent ebe027c commit 3123c6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 19 additions & 0 deletions talpid-core/src/tunnel_state_machine/connecting_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ impl ConnectingState {
&shared_values.route_manager,
retry_attempt,
);

// HACK: Wait for routes to come up. We only need to do this on Android because ..
// If we time out waiting for the appropriate routes to come up, we should tear
// down the newly set-up tunnel and enter the error state, since we can't guarantee
// the tunnel to work properly.
#[cfg(target_os = "android")]
{
// TODO: Investigate if it's a problem to call this function blockingly
//android.wait_for_routes();
let wait_for_routes: std::result::Result<(), ()> = Err(());
if let Err(_) = wait_for_routes {
drop(connecting_state);
return ErrorState::enter(
shared_values,
ErrorStateCause::RoutesTimedOut,
);
}
}

let params = connecting_state.tunnel_parameters.clone();
(
Box::new(connecting_state),
Expand Down
12 changes: 5 additions & 7 deletions talpid-types/src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ pub enum ErrorStateCause {
/// Android has rejected one or more DNS server addresses.
#[cfg(target_os = "android")]
InvalidDnsServers(Vec<IpAddr>),
/// Android routes for tunnel interface never came up.
#[cfg(target_os = "android")]
RoutesTimedOut,
/// Failed to create tunnel device.
#[cfg(target_os = "windows")]
CreateTunnelDevice { os_error: Option<i32> },
Expand All @@ -111,6 +108,9 @@ pub enum ErrorStateCause {
/// Missing permissions required by macOS split tunneling.
#[cfg(target_os = "macos")]
NeedFullDiskPermissions,
/// Timed out while waiting for routes to come up.
#[cfg(target_os = "android")]
RoutesTimedOut,
}

impl ErrorStateCause {
Expand Down Expand Up @@ -197,10 +197,6 @@ impl fmt::Display for ErrorStateCause {
.join(", ")
);
}
#[cfg(target_os = "android")]
RoutesTimedOut => {
return write!(f, "Setting up routes times out",);
}
StartTunnelError => "Failed to start connection to remote server",
#[cfg(target_os = "windows")]
CreateTunnelDevice {
Expand All @@ -224,6 +220,8 @@ impl fmt::Display for ErrorStateCause {
OtherAlwaysOnApp { app_name: _ } => "Another app is set as always on",
#[cfg(target_os = "android")]
OtherLegacyAlwaysOnVpn => "Another legacy vpn profile is set as always on",
#[cfg(target_os = "android")]
RoutesTimedOut => "Setting up routes timed out",
};

write!(f, "{description}")
Expand Down

0 comments on commit 3123c6d

Please sign in to comment.