Skip to content

Commit 479214f

Browse files
committed
Remove DaemonExecutionState and replace with bool
1 parent 818f001 commit 479214f

File tree

2 files changed

+8
-54
lines changed

2 files changed

+8
-54
lines changed

mullvad-daemon/src/lib.rs

+7-52
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ use std::collections::HashSet;
7070
use std::os::unix::io::RawFd;
7171
use std::{
7272
marker::PhantomData,
73-
mem,
7473
path::PathBuf,
7574
pin::Pin,
7675
sync::{Arc, Weak},
7776
time::Duration,
7877
};
79-
use talpid_core::split_tunnel;
8078
use talpid_core::{
8179
mpsc::Sender,
80+
split_tunnel,
8281
tunnel_state_machine::{self, TunnelCommand, TunnelStateMachineHandle},
8382
};
8483
#[cfg(target_os = "android")]
@@ -435,49 +434,6 @@ impl From<(AccessMethodEvent, oneshot::Sender<()>)> for InternalDaemonEvent {
435434
}
436435
}
437436

438-
#[derive(Clone, Debug, Eq, PartialEq)]
439-
enum DaemonExecutionState {
440-
Running,
441-
Exiting,
442-
Finished,
443-
}
444-
445-
impl DaemonExecutionState {
446-
pub fn shutdown(&mut self, tunnel_state: &TunnelState) {
447-
use self::DaemonExecutionState::*;
448-
449-
match self {
450-
Running => {
451-
match tunnel_state {
452-
TunnelState::Disconnected { .. } => mem::replace(self, Finished),
453-
_ => mem::replace(self, Exiting),
454-
};
455-
}
456-
Exiting | Finished => {}
457-
};
458-
}
459-
460-
pub fn disconnected(&mut self) {
461-
use self::DaemonExecutionState::*;
462-
463-
match self {
464-
Exiting => {
465-
let _ = mem::replace(self, Finished);
466-
}
467-
Running | Finished => {}
468-
};
469-
}
470-
471-
pub fn is_running(&self) -> bool {
472-
use self::DaemonExecutionState::*;
473-
474-
match self {
475-
Running => true,
476-
Exiting | Finished => false,
477-
}
478-
}
479-
}
480-
481437
pub struct DaemonCommandChannel {
482438
sender: DaemonCommandSender,
483439
receiver: mpsc::UnboundedReceiver<InternalDaemonEvent>,
@@ -613,7 +569,7 @@ pub trait EventListener {
613569
pub struct Daemon<L: EventListener> {
614570
tunnel_state: TunnelState,
615571
target_state: PersistentTargetState,
616-
state: DaemonExecutionState,
572+
shutting_down: bool,
617573
#[cfg(target_os = "linux")]
618574
exclude_pids: split_tunnel::PidManager,
619575
rx: mpsc::UnboundedReceiver<InternalDaemonEvent>,
@@ -869,7 +825,7 @@ where
869825
locked_down: settings.block_when_disconnected,
870826
},
871827
target_state,
872-
state: DaemonExecutionState::Running,
828+
shutting_down: false,
873829
#[cfg(target_os = "linux")]
874830
exclude_pids: split_tunnel::PidManager::new().map_err(Error::InitSplitTunneling)?,
875831
rx: internal_event_rx,
@@ -917,7 +873,7 @@ where
917873

918874
while let Some(event) = self.rx.next().await {
919875
self.handle_event(event).await;
920-
if self.state == DaemonExecutionState::Finished {
876+
if self.shutting_down && self.tunnel_state.is_disconnected() {
921877
break;
922878
}
923879
}
@@ -1046,7 +1002,6 @@ where
10461002
}
10471003

10481004
match &tunnel_state {
1049-
TunnelState::Disconnected { .. } => self.state.disconnected(),
10501005
TunnelState::Connecting { .. } => {
10511006
log::debug!("Settings: {}", self.settings.summary());
10521007
}
@@ -1183,7 +1138,7 @@ where
11831138

11841139
async fn handle_command(&mut self, command: DaemonCommand) {
11851140
use self::DaemonCommand::*;
1186-
if !self.state.is_running() {
1141+
if self.shutting_down {
11871142
log::trace!("Dropping daemon command because the daemon is shutting down",);
11881143
return;
11891144
}
@@ -1462,7 +1417,7 @@ where
14621417
tx: oneshot::Sender<bool>,
14631418
new_target_state: TargetState,
14641419
) {
1465-
if self.state.is_running() {
1420+
if !self.shutting_down {
14661421
let state_change_initated = self.set_target_state(new_target_state).await;
14671422
Self::oneshot_send(tx, state_change_initated, "state change initiated");
14681423
} else {
@@ -2692,7 +2647,7 @@ where
26922647
self.send_tunnel_command(TunnelCommand::BlockWhenDisconnected(true, tx));
26932648
}
26942649

2695-
self.state.shutdown(&self.tunnel_state);
2650+
self.shutting_down = true;
26962651
self.disconnect_tunnel();
26972652
}
26982653

mullvad-daemon/src/management_interface.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use mullvad_management_interface::{
88
types::{self, daemon_event, management_service_server::ManagementService},
99
Code, Request, Response, Status,
1010
};
11-
use mullvad_types::settings::DnsOptions;
1211
use mullvad_types::{
1312
account::AccountToken,
1413
relay_constraints::{
1514
BridgeSettings, BridgeState, ObfuscationSettings, RelayOverride, RelaySettings,
1615
},
1716
relay_list::RelayList,
18-
settings::Settings,
17+
settings::{DnsOptions, Settings},
1918
states::{TargetState, TunnelState},
2019
version,
2120
wireguard::{RotationInterval, RotationIntervalError},

0 commit comments

Comments
 (0)