summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls <emils@mullvad.net>2020-02-21 12:52:20 +0000
committerEmīls <emils@mullvad.net>2020-02-21 12:52:20 +0000
commitb6bab67fbf43ee429a6b27890eda9bc8943efc78 (patch)
treecbf05927a7b68b3669ea4b97eb1fec862429076f
parent98adb9af255d9c8ee12f5f296bba5a9f973775a3 (diff)
parent144874b81cd987b1ca2b336e8350fbcb145bb6d4 (diff)
downloadmullvadvpn-b6bab67fbf43ee429a6b27890eda9bc8943efc78.tar.xz
mullvadvpn-b6bab67fbf43ee429a6b27890eda9bc8943efc78.zip
Merge branch 'small-daemon-fixes'
-rw-r--r--mullvad-daemon/src/lib.rs24
-rw-r--r--mullvad-daemon/src/management_interface.rs6
-rw-r--r--mullvad-daemon/src/relays.rs22
-rw-r--r--mullvad-daemon/src/version_check.rs3
-rw-r--r--mullvad-daemon/src/wireguard.rs11
5 files changed, 32 insertions, 34 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 8174b5c816..f5e76d9b99 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -426,7 +426,7 @@ where
tunnel_parameters_generator,
log_dir,
resource_dir,
- cache_dir.clone(),
+ cache_dir,
IntoSender::from(internal_event_tx.clone()),
#[cfg(target_os = "android")]
android_context,
@@ -454,7 +454,7 @@ where
settings,
account_history,
wg_key_proxy: WireguardKeyProxy::new(rpc_handle.clone()),
- accounts_proxy: AccountsProxy::new(rpc_handle.clone()),
+ accounts_proxy: AccountsProxy::new(rpc_handle),
https_handle,
wireguard_key_manager,
tokio_remote,
@@ -562,7 +562,7 @@ where
TunnelStateTransition::Disconnecting(after_disconnect) => {
TunnelState::Disconnecting(after_disconnect)
}
- TunnelStateTransition::Error(error_state) => TunnelState::Error(error_state.clone()),
+ TunnelStateTransition::Error(error_state) => TunnelState::Error(error_state),
};
self.unschedule_reconnect();
@@ -870,7 +870,7 @@ where
account: account.clone(),
wireguard: None,
});
- account_entry.wireguard = Some(data.clone());
+ account_entry.wireguard = Some(data);
match self.account_history.insert(account_entry) {
Ok(_) => self
.event_listener
@@ -1311,7 +1311,7 @@ where
tx: oneshot::Sender<std::result::Result<(), settings::Error>>,
bridge_state: BridgeState,
) {
- let result = match self.settings.set_bridge_state(bridge_state.clone()) {
+ let result = match self.settings.set_bridge_state(bridge_state) {
Ok(settings_changed) => {
if settings_changed {
self.event_listener.notify_settings(self.settings.clone());
@@ -1402,10 +1402,7 @@ where
.unwrap_or(true)
{
log::info!("Automatically generating new wireguard key for account");
- if let Err(e) = self
- .wireguard_key_manager
- .generate_key_async(account.to_owned())
- {
+ if let Err(e) = self.wireguard_key_manager.generate_key_async(account) {
log::error!(
"{}",
e.display_chain_with_msg("Failed to start generating wireguard key")
@@ -1450,7 +1447,7 @@ where
match gen_result {
Ok(new_data) => {
let public_key = new_data.get_public_key();
- account_entry.wireguard = Some(new_data.clone());
+ account_entry.wireguard = Some(new_data);
self.account_history.insert(account_entry).map_err(|e| {
format!("Failed to add new wireguard key to account data: {}", e)
})?;
@@ -1463,7 +1460,7 @@ where
// update automatic rotation
self.wireguard_key_manager.set_rotation_interval(
&mut self.account_history,
- account_token.clone(),
+ account_token,
self.settings
.get_tunnel_options()
.wireguard
@@ -1526,7 +1523,7 @@ where
let fut = self
.wg_key_proxy
- .check_wg_key(account, public_key.clone())
+ .check_wg_key(account, public_key)
.map(|is_valid| {
Self::oneshot_send(tx, is_valid, "verify_wireguard_key response");
})
@@ -1676,12 +1673,13 @@ impl TunnelParametersGenerator for MullvadTunnelParametersGenerator {
retry_attempt: u32,
) -> std::result::Result<TunnelParameters, ParameterGenerationError> {
let (response_tx, response_rx) = mpsc::channel();
- if let Err(_) = self
+ if self
.tx
.unbounded_send(InternalDaemonEvent::GenerateTunnelParameters(
response_tx,
retry_attempt,
))
+ .is_err()
{
log::error!("Failed to send daemon command to generate tunnel parameters!");
return Err(ParameterGenerationError::NoMatchingRelay);
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs
index 0e4547b42d..22358881ed 100644
--- a/mullvad-daemon/src/management_interface.rs
+++ b/mullvad-daemon/src/management_interface.rs
@@ -497,7 +497,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
log::debug!("set_account");
let (tx, rx) = sync::oneshot::channel();
let future = self
- .send_command_to_daemon(ManagementCommand::SetAccount(tx, account_token.clone()))
+ .send_command_to_daemon(ManagementCommand::SetAccount(tx, account_token))
.and_then(|_| rx.map_err(|_| Error::internal_error()));
Box::new(future)
}
@@ -656,9 +656,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
.and_then(|_| rx.map_err(|_| Error::internal_error()))
.and_then(|settings_result| {
settings_result.map_err(|error| match error {
- settings::Error::InvalidProxyData(reason) => {
- Error::invalid_params(reason.to_owned())
- }
+ settings::Error::InvalidProxyData(reason) => Error::invalid_params(reason),
_ => Error::internal_error(),
})
});
diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs
index 51937e9ecf..89117988e7 100644
--- a/mullvad-daemon/src/relays.rs
+++ b/mullvad-daemon/src/relays.rs
@@ -393,11 +393,11 @@ impl RelaySelector {
relay.tunnels = RelayTunnels {
wireguard: Self::matching_wireguard_tunnels(
&relay.tunnels,
- &constraints.wireguard_constraints,
+ constraints.wireguard_constraints,
),
openvpn: Self::matching_openvpn_tunnels(
&relay.tunnels,
- &constraints.openvpn_constraints,
+ constraints.openvpn_constraints,
),
};
relay
@@ -407,7 +407,7 @@ impl RelaySelector {
relay.tunnels = RelayTunnels {
wireguard: Self::matching_wireguard_tunnels(
&relay.tunnels,
- &constraints.wireguard_constraints,
+ constraints.wireguard_constraints,
),
openvpn: vec![],
};
@@ -419,7 +419,7 @@ impl RelaySelector {
relay.tunnels = RelayTunnels {
openvpn: Self::matching_openvpn_tunnels(
&relay.tunnels,
- &constraints.openvpn_constraints,
+ constraints.openvpn_constraints,
),
wireguard: vec![],
};
@@ -490,7 +490,7 @@ impl RelaySelector {
fn matching_openvpn_tunnels(
tunnels: &RelayTunnels,
- constraints: &OpenVpnConstraints,
+ constraints: OpenVpnConstraints,
) -> Vec<OpenVpnEndpointData> {
tunnels
.openvpn
@@ -502,7 +502,7 @@ impl RelaySelector {
fn matching_wireguard_tunnels(
tunnels: &RelayTunnels,
- constraints: &WireguardConstraints,
+ constraints: WireguardConstraints,
) -> Vec<WireguardEndpointData> {
tunnels
.wireguard
@@ -582,7 +582,7 @@ impl RelaySelector {
self.wg_data_to_endpoint(
relay.ipv4_addr_in.into(),
wg_tunnel,
- &constraints.wireguard_constraints,
+ constraints.wireguard_constraints,
)
}),
#[cfg(target_os = "android")]
@@ -595,7 +595,7 @@ impl RelaySelector {
self.wg_data_to_endpoint(
relay.ipv4_addr_in.into(),
wg_tunnel,
- &WireguardConstraints::default(),
+ WireguardConstraints::default(),
)
}),
#[cfg(target_os = "android")]
@@ -607,9 +607,9 @@ impl RelaySelector {
&mut self,
host: IpAddr,
data: WireguardEndpointData,
- constraints: &WireguardConstraints,
+ constraints: WireguardConstraints,
) -> Option<MullvadEndpoint> {
- let port = self.get_port_for_wireguard_relay(&data, &constraints)?;
+ let port = self.get_port_for_wireguard_relay(&data, constraints)?;
let peer_config = wireguard::PeerConfig {
public_key: data.public_key,
endpoint: SocketAddr::new(host, port),
@@ -625,7 +625,7 @@ impl RelaySelector {
fn get_port_for_wireguard_relay(
&mut self,
data: &WireguardEndpointData,
- constraints: &WireguardConstraints,
+ constraints: WireguardConstraints,
) -> Option<u16> {
match constraints.port {
Constraint::Any => {
diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs
index 33e8fb86af..da24b85ea3 100644
--- a/mullvad-daemon/src/version_check.rs
+++ b/mullvad-daemon/src/version_check.rs
@@ -176,9 +176,10 @@ impl<T: From<AppVersionInfo>> Future for VersionUpdater<T> {
log::debug!("Got new version check: {:?}", app_version_info);
self.next_update_time = Instant::now() + UPDATE_INTERVAL;
if app_version_info != self.last_app_version_info {
- if let Err(_) = self
+ if self
.update_sender
.unbounded_send(app_version_info.clone().into())
+ .is_err()
{
log::warn!(
"Version update receiver is closed, stopping version updater"
diff --git a/mullvad-daemon/src/wireguard.rs b/mullvad-daemon/src/wireguard.rs
index f91a02a977..09c5f01461 100644
--- a/mullvad-daemon/src/wireguard.rs
+++ b/mullvad-daemon/src/wireguard.rs
@@ -71,9 +71,8 @@ impl KeyManager {
}
}
- /// Update automatic key rotation interval (given in minutes)
- /// Passing `None` for the interval will use the default value.
- /// A value of `0` disables automatic key rotation.
+ /// Reset key rotation, cancelling the current one and starting a new one for the specified
+ /// account
pub fn reset_rotation(
&mut self,
account_history: &mut AccountHistory,
@@ -123,7 +122,8 @@ impl KeyManager {
.map_err(Self::map_rpc_error)
}
- pub fn run_future_sync<T: Send + 'static, E: Send + 'static>(
+ /// Run a future on the given tokio remote
+ fn run_future_sync<T: Send + 'static, E: Send + 'static>(
&mut self,
fut: impl Future<Item = T, Error = E> + Send + 'static,
) -> std::result::Result<T, E> {
@@ -137,6 +137,7 @@ impl KeyManager {
rx.wait().unwrap()
}
+ /// Replace a key for an account synchronously
pub fn replace_key(
&mut self,
account: AccountToken,
@@ -153,7 +154,7 @@ impl KeyManager {
}
- /// Generate a new private key asyncronously. The new keys will be sent to the daemon channel.
+ /// Generate a new private key asynchronously. The new keys will be sent to the daemon channel.
pub fn generate_key_async(&mut self, account: AccountToken) -> Result<()> {
self.reset();
let private_key = PrivateKey::new_from_random();