summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2019-01-14 13:29:16 +0000
committerEmīls Piņķis <emils@mullvad.net>2019-01-30 13:41:31 +0000
commit7a99bd987ee258ee54a8cb28ab4f580ac03ffe86 (patch)
tree0d7fa957b2b321c89a33bbb2382f16e5068e4333 /mullvad-daemon/src
parent4e2b2ff81704fdab21b269948c3ebf2a9f65b07c (diff)
downloadmullvadvpn-7a99bd987ee258ee54a8cb28ab4f580ac03ffe86.tar.xz
mullvadvpn-7a99bd987ee258ee54a8cb28ab4f580ac03ffe86.zip
Refactor mullvad types
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/lib.rs44
-rw-r--r--mullvad-daemon/src/management_interface.rs8
-rw-r--r--mullvad-daemon/src/relays.rs14
3 files changed, 42 insertions, 24 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 63dee4e536..eeb0f5755a 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -29,6 +29,7 @@ use log::{debug, error, info, warn};
use mullvad_rpc::{AccountsProxy, AppVersionProxy, HttpHandle};
use mullvad_types::{
account::{AccountData, AccountToken},
+ endpoint::MullvadEndpoint,
location::GeoIpLocation,
relay_constraints::{
Constraint, OpenVpnConstraints, RelayConstraintsUpdate, RelaySettings, RelaySettingsUpdate,
@@ -42,10 +43,10 @@ use mullvad_types::{
use std::{mem, path::PathBuf, sync::mpsc, thread, time::Duration};
use talpid_core::{
mpsc::IntoSender,
- tunnel_state_machine::{self, TunnelCommand, TunnelParameters, TunnelParametersGenerator},
+ tunnel_state_machine::{self, TunnelCommand, TunnelParametersGenerator},
};
use talpid_types::{
- net::{OpenVpnProxySettings, TransportProtocol},
+ net::{openvpn, TransportProtocol, TunnelParameters},
tunnel::{BlockReason, TunnelStateTransition},
};
@@ -58,6 +59,9 @@ error_chain! {
DaemonIsAlreadyRunning {
description("Another instance of the daemon is already running")
}
+ UnsupportedTunnel {
+ description("Unsupported tunnel")
+ }
ManagementInterfaceError(msg: &'static str) {
description("Error in the management interface")
display("Management interface error: {}", msg)
@@ -340,24 +344,20 @@ impl Daemon {
.map(|account_token| {
match self.settings.get_relay_settings() {
RelaySettings::CustomTunnelEndpoint(custom_relay) => custom_relay
- .to_tunnel_endpoint()
+ .to_tunnel_parameters(self.settings.get_tunnel_options().clone())
.chain_err(|| "Custom tunnel endpoint could not be resolved"),
RelaySettings::Normal(constraints) => self
.relay_selector
.get_tunnel_endpoint(&constraints, retry_attempt)
.chain_err(|| "No valid relay servers match the current settings")
- .map(|(relay, endpoint)| {
+ .and_then(|(relay, endpoint)| {
self.last_generated_relay = Some(relay);
- endpoint
+ self.create_tunnel_parameters(endpoint, account_token)
}),
}
- .map(|endpoint| {
+ .map(|tunnel_params| {
tunnel_parameters_tx
- .send(TunnelParameters {
- endpoint,
- options: self.settings.get_tunnel_options().clone(),
- username: account_token,
- })
+ .send(tunnel_params)
.map_err(|_| Error::from("Tunnel parameters receiver stopped listening"))
})
});
@@ -366,6 +366,26 @@ impl Daemon {
}
}
+ fn create_tunnel_parameters(
+ &self,
+ endpoint: MullvadEndpoint,
+ account_token: String,
+ ) -> Result<TunnelParameters> {
+ let tunnel_options = self.settings.get_tunnel_options().clone();
+ match endpoint {
+ MullvadEndpoint::OpenVpn(endpoint) => Ok(openvpn::TunnelParameters {
+ config: openvpn::ConnectionConfig::new(endpoint, account_token, "-".to_string()),
+ options: tunnel_options.openvpn,
+ generic_options: tunnel_options.generic,
+ }
+ .into()),
+ MullvadEndpoint::Wireguard {
+ peer: _,
+ gateway: _,
+ } => Err(ErrorKind::UnsupportedTunnel.into()),
+ }
+ }
+
fn schedule_reconnect(&mut self, delay: Duration) {
let tunnel_command_tx = self.tx.clone();
let (tx, rx) = mpsc::channel();
@@ -639,7 +659,7 @@ impl Daemon {
fn on_set_openvpn_proxy(
&mut self,
tx: oneshot::Sender<::std::result::Result<(), settings::Error>>,
- proxy: Option<OpenVpnProxySettings>,
+ proxy: Option<openvpn::ProxySettings>,
) {
let constraints_result = match proxy {
Some(_) => self.apply_proxy_constraints(),
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs
index c68c8ff967..cea4d6a75d 100644
--- a/mullvad-daemon/src/management_interface.rs
+++ b/mullvad-daemon/src/management_interface.rs
@@ -30,7 +30,7 @@ use std::{
};
use talpid_core::mpsc::IntoSender;
use talpid_ipc;
-use talpid_types::{net::OpenVpnProxySettings, tunnel::TunnelStateTransition};
+use talpid_types::{net::openvpn, tunnel::TunnelStateTransition};
use uuid;
/// FIXME(linus): This is here just because the futures crate has deprecated it and jsonrpc_core
@@ -115,7 +115,7 @@ build_rpc_trait! {
/// Sets proxy details for OpenVPN
#[rpc(meta, name = "set_openvpn_proxy")]
- fn set_openvpn_proxy(&self, Self::Metadata, Option<OpenVpnProxySettings>) -> BoxFuture<(), Error>;
+ fn set_openvpn_proxy(&self, Self::Metadata, Option<openvpn::ProxySettings>) -> BoxFuture<(), Error>;
/// Set if IPv6 is enabled in the tunnel
#[rpc(meta, name = "set_enable_ipv6")]
@@ -194,7 +194,7 @@ pub enum ManagementCommand {
/// Set proxy details for OpenVPN
SetOpenVpnProxy(
OneshotSender<Result<(), settings::Error>>,
- Option<OpenVpnProxySettings>,
+ Option<openvpn::ProxySettings>,
),
/// Set if IPv6 should be enabled in the tunnel
SetEnableIpv6(OneshotSender<()>, bool),
@@ -587,7 +587,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
fn set_openvpn_proxy(
&self,
_: Self::Metadata,
- proxy: Option<OpenVpnProxySettings>,
+ proxy: Option<openvpn::ProxySettings>,
) -> BoxFuture<(), Error> {
log::debug!("set_openvpn_proxy({:?})", proxy);
let (tx, rx) = sync::oneshot::channel();
diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs
index 0dba9dd9a3..11c0d49930 100644
--- a/mullvad-daemon/src/relays.rs
+++ b/mullvad-daemon/src/relays.rs
@@ -4,6 +4,7 @@ use futures::Future;
use mullvad_rpc::{HttpHandle, RelayListProxy};
use mullvad_types::{
+ endpoint::{MullvadEndpoint, TunnelEndpointData},
location::Location,
relay_constraints::{
Constraint, LocationConstraint, Match, OpenVpnConstraints, RelayConstraints,
@@ -14,12 +15,11 @@ use mullvad_types::{
use serde_json;
-use talpid_types::net::{TransportProtocol, TunnelEndpoint, TunnelEndpointData};
+use talpid_types::net::TransportProtocol;
use std::{
fs::File,
io,
- net::IpAddr,
path::{Path, PathBuf},
sync::{mpsc, Arc, Mutex, MutexGuard},
thread,
@@ -196,7 +196,7 @@ impl RelaySelector {
&mut self,
constraints: &RelayConstraints,
retry_attempt: u32,
- ) -> Result<(Relay, TunnelEndpoint)> {
+ ) -> Result<(Relay, MullvadEndpoint)> {
let preferred_constraints = Self::preferred_constraints(constraints, retry_attempt);
if let Some((relay, endpoint)) = self.get_tunnel_endpoint_internal(&preferred_constraints) {
debug!(
@@ -264,7 +264,7 @@ impl RelaySelector {
fn get_tunnel_endpoint_internal(
&mut self,
constraints: &RelayConstraints,
- ) -> Option<(Relay, TunnelEndpoint)> {
+ ) -> Option<(Relay, MullvadEndpoint)> {
let matching_relays: Vec<Relay> = self
.lock_parsed_relays()
.relays()
@@ -280,10 +280,8 @@ impl RelaySelector {
);
self.get_random_tunnel(&selected_relay.tunnels)
.map(|tunnel_parameters| {
- let endpoint = TunnelEndpoint {
- address: IpAddr::V4(selected_relay.ipv4_addr_in),
- tunnel: tunnel_parameters,
- };
+ let endpoint = tunnel_parameters
+ .to_mullvad_endpoint(selected_relay.ipv4_addr_in.into());
(selected_relay.clone(), endpoint)
})
})