summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-10-30 09:48:36 +0100
committerLinus Färnstrand <linus@mullvad.net>2018-10-30 09:48:36 +0100
commit4943f4433799f7981f151efa5e705817effeb5d1 (patch)
tree52a27abeb3f967a44d577bd621fdf3ab4aab2ca6 /mullvad-daemon
parentbf92da29c67e457a4edf542922a0bd33ebe11203 (diff)
parent7e4eb3711be85e084dfbf65d090b94f482f084c1 (diff)
downloadmullvadvpn-4943f4433799f7981f151efa5e705817effeb5d1.tar.xz
mullvadvpn-4943f4433799f7981f151efa5e705817effeb5d1.zip
Merge branch 'no-more-macro-use'
Diffstat (limited to 'mullvad-daemon')
-rw-r--r--mullvad-daemon/src/account_history.rs6
-rw-r--r--mullvad-daemon/src/cli.rs2
-rw-r--r--mullvad-daemon/src/lib.rs5
-rw-r--r--mullvad-daemon/src/main.rs4
-rw-r--r--mullvad-daemon/src/management_interface.rs65
-rw-r--r--mullvad-daemon/src/relays.rs1
-rw-r--r--mullvad-daemon/src/rpc_uniqueness_check.rs7
-rw-r--r--mullvad-daemon/src/shutdown.rs4
-rw-r--r--mullvad-daemon/src/system_service.rs29
9 files changed, 62 insertions, 61 deletions
diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs
index 486c258177..51b677e675 100644
--- a/mullvad-daemon/src/account_history.rs
+++ b/mullvad-daemon/src/account_history.rs
@@ -45,7 +45,7 @@ impl AccountHistory {
pub fn load(&mut self) -> Result<()> {
match File::open(&self.cache_path).map(io::BufReader::new) {
Ok(mut file) => {
- info!(
+ log::info!(
"Loading account history from {}",
&self.cache_path.display()
);
@@ -53,7 +53,7 @@ impl AccountHistory {
Ok(())
}
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
- info!("No account history file at {}", &self.cache_path.display());
+ log::info!("No account history file at {}", &self.cache_path.display());
Ok(())
}
Err(e) => Err(e).chain_err(|| ErrorKind::ReadError(self.cache_path.clone())),
@@ -93,7 +93,7 @@ impl AccountHistory {
/// Serializes the account history and saves it to the file it was loaded from.
fn save(&self) -> Result<()> {
- debug!("Writing account history to {}", self.cache_path.display());
+ log::debug!("Writing account history to {}", self.cache_path.display());
let mut file = File::create(&self.cache_path)
.map(io::BufWriter::new)
.chain_err(|| ErrorKind::WriteError(self.cache_path.clone()))?;
diff --git a/mullvad-daemon/src/cli.rs b/mullvad-daemon/src/cli.rs
index 573236d797..d1dcd66a73 100644
--- a/mullvad-daemon/src/cli.rs
+++ b/mullvad-daemon/src/cli.rs
@@ -1,4 +1,4 @@
-use clap::{App, Arg};
+use clap::{crate_authors, crate_description, crate_name, App, Arg};
use log;
use version;
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 541d904875..13ae19e7a7 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -12,7 +12,6 @@ extern crate error_chain;
extern crate futures;
#[cfg(unix)]
extern crate libc;
-#[macro_use]
extern crate log;
#[macro_use]
@@ -20,9 +19,8 @@ extern crate serde;
extern crate serde_json;
extern crate jsonrpc_core;
-#[macro_use]
-extern crate jsonrpc_macros;
extern crate jsonrpc_ipc_server;
+extern crate jsonrpc_macros;
extern crate jsonrpc_pubsub;
extern crate rand;
extern crate tokio_core;
@@ -49,6 +47,7 @@ use futures::{
sync::{mpsc::UnboundedSender, oneshot},
Future, Sink,
};
+use log::{debug, error, info, warn};
use management_interface::{BoxFuture, ManagementCommand, ManagementInterfaceServer};
use mullvad_rpc::{AccountsProxy, AppVersionProxy, HttpHandle};
use mullvad_types::{
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index d06f0101e1..26a67824ae 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -7,13 +7,11 @@
//! the License, or (at your option) any later version.
extern crate chrono;
-#[macro_use]
extern crate clap;
#[macro_use]
extern crate error_chain;
#[cfg(unix)]
extern crate libc;
-#[macro_use]
extern crate log;
extern crate log_panics;
extern crate mullvad_daemon;
@@ -21,10 +19,10 @@ extern crate mullvad_paths;
extern crate talpid_core;
#[cfg(windows)]
-#[macro_use]
extern crate windows_service;
use error_chain::ChainedError;
+use log::{debug, error, info, warn};
use mullvad_daemon::Daemon;
use std::{thread, time::Duration};
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs
index 43d3ebca83..07fd603e2a 100644
--- a/mullvad-daemon/src/management_interface.rs
+++ b/mullvad-daemon/src/management_interface.rs
@@ -3,13 +3,12 @@ use jsonrpc_core::futures::sync::oneshot::Sender as OneshotSender;
use jsonrpc_core::futures::{future, sync, Future};
use jsonrpc_core::{Error, ErrorCode, MetaIoHandler, Metadata};
use jsonrpc_ipc_server;
-use jsonrpc_macros::pubsub;
+use jsonrpc_macros::{build_rpc_trait, metadata, pubsub};
use jsonrpc_pubsub::{PubSubHandler, PubSubMetadata, Session, SubscriptionId};
+use mullvad_paths;
use mullvad_rpc;
use mullvad_types::account::{AccountData, AccountToken};
use mullvad_types::location::GeoIpLocation;
-
-use mullvad_paths;
use mullvad_types::relay_constraints::RelaySettingsUpdate;
use mullvad_types::relay_list::RelayList;
use mullvad_types::settings::Settings;
@@ -245,7 +244,7 @@ pub struct EventBroadcaster {
impl EventBroadcaster {
/// Sends a new state update to all `new_state` subscribers of the management interface.
pub fn notify_new_state(&self, new_state: TunnelStateTransition) {
- debug!("Broadcasting new state to listeners: {:?}", new_state);
+ log::debug!("Broadcasting new state to listeners: {:?}", new_state);
self.notify(&self.subscriptions.new_state_subscriptions, new_state);
}
@@ -292,7 +291,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterface<T> {
let id = SubscriptionId::String(uuid::Uuid::new_v4().to_string());
if let Entry::Vacant(entry) = subscriptions.entry(id.clone()) {
if let Ok(sink) = subscriber.assign_id(id.clone()) {
- debug!("Accepting new subscription with id {:?}", id);
+ log::debug!("Accepting new subscription with id {:?}", id);
entry.insert(sink);
}
break;
@@ -306,7 +305,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterface<T> {
) -> BoxFuture<(), Error> {
let was_removed = subscriptions_lock.write().unwrap().remove(&id).is_some();
let result = if was_removed {
- debug!("Unsubscribing id {:?}", id);
+ log::debug!("Unsubscribing id {:?}", id);
future::ok(())
} else {
future::err(Error {
@@ -361,14 +360,14 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
_: Self::Metadata,
account_token: AccountToken,
) -> BoxFuture<AccountData, Error> {
- debug!("get_account_data");
+ log::debug!("get_account_data");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::GetAccountData(tx, account_token))
.and_then(|_| rx.map_err(|_| Error::internal_error()))
.and_then(|rpc_future| {
rpc_future.map_err(|error: mullvad_rpc::Error| {
- error!(
+ log::error!(
"Unable to get account data from API: {}",
error.display_chain()
);
@@ -379,7 +378,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn get_relay_locations(&self, _: Self::Metadata) -> BoxFuture<RelayList, Error> {
- debug!("get_relay_locations");
+ log::debug!("get_relay_locations");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::GetRelayLocations(tx))
@@ -392,7 +391,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
_: Self::Metadata,
account_token: Option<AccountToken>,
) -> BoxFuture<(), Error> {
- debug!("set_account");
+ log::debug!("set_account");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::SetAccount(tx, account_token.clone()))
@@ -402,7 +401,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
if let Err(e) = self.load_history().and_then(|mut account_history| {
account_history.add_account_token(new_account_token)
}) {
- error!(
+ log::error!(
"Unable to add an account into the account history: {}",
e.display_chain()
);
@@ -417,7 +416,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
_: Self::Metadata,
constraints_update: RelaySettingsUpdate,
) -> BoxFuture<(), Error> {
- debug!("update_relay_settings");
+ log::debug!("update_relay_settings");
let (tx, rx) = sync::oneshot::channel();
let message = ManagementCommand::UpdateRelaySettings(tx, constraints_update);
@@ -428,7 +427,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn set_allow_lan(&self, _: Self::Metadata, allow_lan: bool) -> BoxFuture<(), Error> {
- debug!("set_allow_lan({})", allow_lan);
+ log::debug!("set_allow_lan({})", allow_lan);
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::SetAllowLan(tx, allow_lan))
@@ -437,7 +436,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn set_auto_connect(&self, _: Self::Metadata, auto_connect: bool) -> BoxFuture<(), Error> {
- debug!("set_auto_connect({})", auto_connect);
+ log::debug!("set_auto_connect({})", auto_connect);
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::SetAutoConnect(tx, auto_connect))
@@ -446,7 +445,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn connect(&self, _: Self::Metadata) -> BoxFuture<(), Error> {
- debug!("connect");
+ log::debug!("connect");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::SetTargetState(tx, TargetState::Secured))
@@ -463,7 +462,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn disconnect(&self, _: Self::Metadata) -> BoxFuture<(), Error> {
- debug!("disconnect");
+ log::debug!("disconnect");
let (tx, _) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::SetTargetState(
@@ -475,7 +474,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn get_state(&self, _: Self::Metadata) -> BoxFuture<TunnelStateTransition, Error> {
- debug!("get_state");
+ log::debug!("get_state");
let (state_tx, state_rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::GetState(state_tx))
@@ -484,7 +483,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn get_current_location(&self, _: Self::Metadata) -> BoxFuture<GeoIpLocation, Error> {
- debug!("get_current_location");
+ log::debug!("get_current_location");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::GetCurrentLocation(tx))
@@ -493,17 +492,17 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn shutdown(&self, _: Self::Metadata) -> BoxFuture<(), Error> {
- debug!("shutdown");
+ log::debug!("shutdown");
self.send_command_to_daemon(ManagementCommand::Shutdown)
}
fn get_account_history(&self, _: Self::Metadata) -> BoxFuture<Vec<AccountToken>, Error> {
- debug!("get_account_history");
+ log::debug!("get_account_history");
Box::new(future::result(
self.load_history()
.map(|history| history.get_accounts().to_vec())
.map_err(|error| {
- error!("Unable to get account history: {}", error.display_chain());
+ log::error!("Unable to get account history: {}", error.display_chain());
Error::internal_error()
}),
))
@@ -514,12 +513,12 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
_: Self::Metadata,
account_token: AccountToken,
) -> BoxFuture<(), Error> {
- debug!("remove_account_from_history");
+ log::debug!("remove_account_from_history");
Box::new(future::result(
self.load_history()
.and_then(|mut history| history.remove_account_token(&account_token))
.map_err(|error| {
- error!(
+ log::error!(
"Unable to remove account from history: {}",
error.display_chain()
);
@@ -529,7 +528,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn set_openvpn_mssfix(&self, _: Self::Metadata, mssfix: Option<u16>) -> BoxFuture<(), Error> {
- debug!("set_openvpn_mssfix({:?})", mssfix);
+ log::debug!("set_openvpn_mssfix({:?})", mssfix);
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::SetOpenVpnMssfix(tx, mssfix))
@@ -539,7 +538,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn set_enable_ipv6(&self, _: Self::Metadata, enable_ipv6: bool) -> BoxFuture<(), Error> {
- debug!("set_enable_ipv6({})", enable_ipv6);
+ log::debug!("set_enable_ipv6({})", enable_ipv6);
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::SetEnableIpv6(tx, enable_ipv6))
@@ -549,7 +548,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn get_settings(&self, _: Self::Metadata) -> BoxFuture<Settings, Error> {
- debug!("get_settings");
+ log::debug!("get_settings");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::GetSettings(tx))
@@ -558,7 +557,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn get_current_version(&self, _: Self::Metadata) -> BoxFuture<String, Error> {
- debug!("get_current_version");
+ log::debug!("get_current_version");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::GetCurrentVersion(tx))
@@ -568,14 +567,14 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
fn get_version_info(&self, _: Self::Metadata) -> BoxFuture<version::AppVersionInfo, Error> {
- debug!("get_version_info");
+ log::debug!("get_version_info");
let (tx, rx) = sync::oneshot::channel();
let future = self
.send_command_to_daemon(ManagementCommand::GetVersionInfo(tx))
.and_then(|_| rx.map_err(|_| Error::internal_error()))
.and_then(|version_future| {
version_future.map_err(|error| {
- error!(
+ log::error!(
"Unable to get version data from API: {}",
error.display_chain()
);
@@ -591,22 +590,22 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
_: Self::Metadata,
subscriber: pubsub::Subscriber<TunnelStateTransition>,
) {
- debug!("new_state_subscribe");
+ log::debug!("new_state_subscribe");
Self::subscribe(subscriber, &self.subscriptions.new_state_subscriptions);
}
fn new_state_unsubscribe(&self, id: SubscriptionId) -> BoxFuture<(), Error> {
- debug!("new_state_unsubscribe");
+ log::debug!("new_state_unsubscribe");
Self::unsubscribe(&id, &self.subscriptions.new_state_subscriptions)
}
fn settings_subscribe(&self, _: Self::Metadata, subscriber: pubsub::Subscriber<Settings>) {
- debug!("settings_subscribe");
+ log::debug!("settings_subscribe");
Self::subscribe(subscriber, &self.subscriptions.settings_subscriptions);
}
fn settings_unsubscribe(&self, id: SubscriptionId) -> BoxFuture<(), Error> {
- debug!("settings_unsubscribe");
+ log::debug!("settings_unsubscribe");
Self::unsubscribe(&id, &self.subscriptions.settings_subscriptions)
}
}
diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs
index c3c1a967ed..dab1b50407 100644
--- a/mullvad-daemon/src/relays.rs
+++ b/mullvad-daemon/src/relays.rs
@@ -20,6 +20,7 @@ use std::sync::{mpsc, Arc, Mutex, MutexGuard};
use std::time::{self, Duration, SystemTime};
use std::{io, thread};
+use log::{debug, error, info, trace, warn};
use rand::{self, Rng, ThreadRng};
use tokio_timer::{TimeoutError, Timer};
diff --git a/mullvad-daemon/src/rpc_uniqueness_check.rs b/mullvad-daemon/src/rpc_uniqueness_check.rs
index c73ec0980f..297d11609d 100644
--- a/mullvad-daemon/src/rpc_uniqueness_check.rs
+++ b/mullvad-daemon/src/rpc_uniqueness_check.rs
@@ -1,6 +1,5 @@
use error_chain::ChainedError;
-use log::Level;
use mullvad_ipc_client::new_standalone_ipc_client;
use mullvad_paths;
@@ -15,10 +14,10 @@ pub fn is_another_instance_running() -> bool {
Err(error) => {
let msg =
"Failed to locate/connect to another daemon instance, assuming there isn't one";
- if log_enabled!(Level::Trace) {
- trace!("{}\n{}", msg, error.display_chain());
+ if log::log_enabled!(log::Level::Trace) {
+ log::trace!("{}\n{}", msg, error.display_chain());
} else {
- debug!("{}", msg);
+ log::debug!("{}", msg);
}
false
}
diff --git a/mullvad-daemon/src/shutdown.rs b/mullvad-daemon/src/shutdown.rs
index 41b454bab5..4433984429 100644
--- a/mullvad-daemon/src/shutdown.rs
+++ b/mullvad-daemon/src/shutdown.rs
@@ -12,7 +12,7 @@ mod platform {
F: Fn() + 'static + Send,
{
simple_signal::set_handler(&[Signal::Term, Signal::Int], move |s| {
- debug!("Process received signal: {:?}", s);
+ log::debug!("Process received signal: {:?}", s);
f();
});
Ok(())
@@ -30,7 +30,7 @@ mod platform {
F: Fn() + 'static + Send,
{
ctrlc::set_handler(move || {
- debug!("Process received Ctrl-c");
+ log::debug!("Process received Ctrl-c");
f();
})
.chain_err(|| "Unable to attach ctrl-c handler")
diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs
index 6a2d54b326..57e4cba00c 100644
--- a/mullvad-daemon/src/system_service.rs
+++ b/mullvad-daemon/src/system_service.rs
@@ -1,11 +1,14 @@
-use std::ffi::OsString;
-use std::sync::atomic::{AtomicUsize, Ordering};
-use std::sync::{mpsc, Arc};
-use std::time::Duration;
-use std::{env, io, thread};
-
use cli;
use error_chain::ChainedError;
+use std::{
+ env,
+ ffi::OsString,
+ io,
+ sync::atomic::{AtomicUsize, Ordering},
+ sync::{mpsc, Arc},
+ thread,
+ time::Duration,
+};
use windows_service::service::{
ServiceAccess, ServiceControl, ServiceControlAccept, ServiceDependency, ServiceErrorControl,
ServiceExitCode, ServiceInfo, ServiceStartType, ServiceState, ServiceStatus, ServiceType,
@@ -31,13 +34,13 @@ pub fn run() -> Result<()> {
.chain_err(|| "Failed to start a service dispatcher")
}
-define_windows_service!(service_main, handle_service_main);
+windows_service::define_windows_service!(service_main, handle_service_main);
pub fn handle_service_main(_arguments: Vec<OsString>) {
- info!("Service started.");
+ log::info!("Service started.");
match run_service() {
- Ok(()) => info!("Service stopped."),
- Err(error) => error!("{}", error.display_chain()),
+ Ok(()) => log::info!("Service stopped."),
+ Err(error) => log::error!("{}", error.display_chain()),
};
}
@@ -188,9 +191,11 @@ impl PersistentServiceStatus {
wait_hint: wait_hint,
};
- debug!(
+ log::debug!(
"Update service status: {:?}, checkpoint: {}, wait_hint: {:?}",
- service_status.current_state, service_status.checkpoint, service_status.wait_hint
+ service_status.current_state,
+ service_status.checkpoint,
+ service_status.wait_hint
);
self.status_handle.set_service_status(service_status)