summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2020-04-16 11:18:48 +0100
committerOdd Stranne <odd@mullvad.net>2020-04-16 15:34:44 +0200
commit8d3a7ce0752a04d74ce4de82c3f6a14055a160fc (patch)
treeb458cecc20c092ed13c9f738751ab2cd501f223d
parent409df5f7e8f3713d74b917d755b5fef198a9acb6 (diff)
downloadmullvadvpn-8d3a7ce0752a04d74ce4de82c3f6a14055a160fc.tar.xz
mullvadvpn-8d3a7ce0752a04d74ce4de82c3f6a14055a160fc.zip
Use tristate for connectivity
-rw-r--r--talpid-core/src/offline/windows.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/talpid-core/src/offline/windows.rs b/talpid-core/src/offline/windows.rs
index cd3eb54248..1b685fe8c9 100644
--- a/talpid-core/src/offline/windows.rs
+++ b/talpid-core/src/offline/windows.rs
@@ -56,7 +56,7 @@ unsafe impl Send for BroadcastListener {}
impl BroadcastListener {
pub fn start(sender: Weak<UnboundedSender<TunnelCommand>>) -> Result<Self, Error> {
let mut system_state = Arc::new(Mutex::new(SystemState {
- network_connectivity: true,
+ network_connectivity: None,
suspended: false,
daemon_channel: sender,
}));
@@ -205,7 +205,7 @@ impl BroadcastListener {
pub fn is_offline(&self) -> bool {
let state = self._system_state.lock();
- state.is_offline_currently()
+ state.is_offline_currently().unwrap_or(false)
}
}
@@ -227,7 +227,7 @@ enum StateChange {
}
struct SystemState {
- network_connectivity: bool,
+ network_connectivity: Option<bool>,
suspended: bool,
daemon_channel: Weak<UnboundedSender<TunnelCommand>>,
}
@@ -237,7 +237,7 @@ impl SystemState {
let old_state = self.is_offline_currently();
match change {
StateChange::NetworkConnectivity(connectivity) => {
- self.network_connectivity = connectivity;
+ self.network_connectivity = Some(connectivity);
}
StateChange::Suspended(suspended) => {
@@ -248,15 +248,17 @@ impl SystemState {
let new_state = self.is_offline_currently();
if old_state != new_state {
if let Some(daemon_channel) = self.daemon_channel.upgrade() {
- if let Err(e) = daemon_channel.unbounded_send(TunnelCommand::IsOffline(new_state)) {
+ if let Err(e) = daemon_channel
+ .unbounded_send(TunnelCommand::IsOffline(new_state.unwrap_or(false)))
+ {
log::error!("Failed to send new offline state to daemon: {}", e);
}
}
}
}
- fn is_offline_currently(&self) -> bool {
- !self.network_connectivity || self.suspended
+ fn is_offline_currently(&self) -> Option<bool> {
+ Some(!self.network_connectivity? || self.suspended)
}
}