summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-05-17 10:31:15 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-05-17 10:31:15 -0300
commitfc7f384bf0c145b531a32b3a01682027b286e55a (patch)
tree62831451b228c2c697978a9ef622bb4614edc73f
parentca00ab4b57f2bc89393a6bc67d011182c8706ca3 (diff)
parentc80ab2aad7b97f88214bdb358751cc0c16e12408 (diff)
downloadmullvadvpn-fc7f384bf0c145b531a32b3a01682027b286e55a.tar.xz
mullvadvpn-fc7f384bf0c145b531a32b3a01682027b286e55a.zip
Merge branch 'easier-to-use-daemon-as-library'
-rw-r--r--mullvad-daemon/src/lib.rs24
-rw-r--r--mullvad-daemon/src/main.rs4
2 files changed, 24 insertions, 4 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index aab7f406f7..37d6e7f6d5 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -14,11 +14,14 @@ extern crate serde;
mod account_history;
mod geoip;
+pub mod logging;
mod management_interface;
mod relays;
mod rpc_uniqueness_check;
+pub mod version;
-use crate::management_interface::{BoxFuture, ManagementCommand, ManagementInterfaceServer};
+pub use crate::management_interface::ManagementCommand;
+use crate::management_interface::{BoxFuture, ManagementInterfaceServer};
use futures::{
future,
sync::{mpsc::UnboundedSender, oneshot},
@@ -57,6 +60,9 @@ pub enum Error {
#[error(display = "Another instance of the daemon is already running")]
DaemonIsAlreadyRunning,
+ #[error(display = "Failed to send command to daemon because it is not running")]
+ DaemonUnavailable,
+
#[error(display = "Unable to initialize network event loop")]
InitIoEventLoop(#[error(cause)] io::Error),
@@ -160,6 +166,17 @@ impl DaemonExecutionState {
}
}
+pub struct DaemonCommandSender(IntoSender<ManagementCommand, InternalDaemonEvent>);
+
+impl DaemonCommandSender {
+ pub(crate) fn new(internal_event_sender: mpsc::Sender<InternalDaemonEvent>) -> Self {
+ DaemonCommandSender(IntoSender::from(internal_event_sender))
+ }
+
+ pub fn send(&self, command: ManagementCommand) -> Result<()> {
+ self.0.send(command).map_err(|_| Error::DaemonUnavailable)
+ }
+}
pub struct Daemon {
tunnel_command_tx: SyncUnboundedSender<TunnelCommand>,
@@ -307,6 +324,11 @@ impl Daemon {
});
}
+ /// Retrieve a channel for sending daemon commands.
+ pub fn command_sender(&self) -> DaemonCommandSender {
+ DaemonCommandSender::new(self.tx.clone())
+ }
+
/// Consume the `Daemon` and run the main event loop. Blocks until an error happens or a
/// shutdown event is received.
pub fn run(mut self) -> Result<()> {
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index e9346405d9..8deae9f489 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -9,16 +9,14 @@
#![deny(rust_2018_idioms)]
use log::{debug, error, info, warn};
-use mullvad_daemon::Daemon;
+use mullvad_daemon::{logging, version, Daemon};
use std::{path::PathBuf, thread, time::Duration};
use talpid_types::ErrorExt;
mod cli;
-mod logging;
mod shutdown;
#[cfg(windows)]
mod system_service;
-mod version;
const DAEMON_LOG_FILENAME: &str = "daemon.log";