Skip to content

Commit

Permalink
Add env var to disable offline detection
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkisemils committed Jan 7, 2021
1 parent 79ba258 commit 26c08fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Line wrap the file at 100 chars. Th
### Added
- Add header containing OS version to version-check API call to enable OS specific compatibility and
vulnerability checks.
- Add `TALPID_DISABLE_OFFLINE_MONITOR` environment variable to allow users to disable offline
detection.

#### Android
- Allow to configure the tunnel to use custom DNS servers.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ echo "org.gradle.jvmargs=-Xmx4608M" >> ~/.gradle/gradle.properties
* `TALPID_FORCE_USERSPACE_WIREGUARD` - Forces the daemon to use the userspace implementation of
WireGuard on Linux.

* `TALPID_DISABLE_OFFLINE_MONITOR` - Forces the daemon to always assume the host is online.


## Building and running the desktop Electron GUI app

Expand Down
34 changes: 25 additions & 9 deletions talpid-core/src/offline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,42 @@ mod imp;
#[path = "android.rs"]
mod imp;

lazy_static::lazy_static! {
/// Disables offline monitor
static ref FORCE_DISABLE_OFFLINE_MONITOR: bool = std::env::var("TALPID_FORCE_USERSPACE_WIREGUARD")
.map(|v| v != "0")
.unwrap_or(false);
}

pub use self::imp::Error;

pub struct MonitorHandle(imp::MonitorHandle);
pub struct MonitorHandle(Option<imp::MonitorHandle>);

impl MonitorHandle {
pub async fn is_offline(&mut self) -> bool {
self.0.is_offline().await
match self.0.as_mut() {
Some(monitor) => monitor.is_offline().await,
None => false,
}
}
}

pub async fn spawn_monitor(
sender: Weak<UnboundedSender<TunnelCommand>>,
#[cfg(target_os = "android")] android_context: AndroidContext,
) -> Result<MonitorHandle, Error> {
Ok(MonitorHandle(
imp::spawn_monitor(
sender,
#[cfg(target_os = "android")]
android_context,
let monitor = if !*FORCE_DISABLE_OFFLINE_MONITOR {
Some(
imp::spawn_monitor(
sender,
#[cfg(target_os = "android")]
android_context,
)
.await?,
)
.await?,
))
} else {
None
};

Ok(MonitorHandle(monitor))
}

0 comments on commit 26c08fd

Please sign in to comment.