diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-06-04 16:36:50 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-06-05 13:16:04 +0100 |
| commit | 70d424f40b0e9881832ea314bada5800a4e634a0 (patch) | |
| tree | 5424a1cde9b7ab023d7798232ea761bd50ee9d5b | |
| parent | 7618e831837bbed460b41282f70de45164b1946b (diff) | |
| download | mullvadvpn-70d424f40b0e9881832ea314bada5800a4e634a0.tar.xz mullvadvpn-70d424f40b0e9881832ea314bada5800a4e634a0.zip | |
Add Option<ProxyEndpoint> to TunnelEndpoint
| -rw-r--r-- | talpid-core/src/tunnel/openvpn.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/connected_state.rs | 8 | ||||
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/connecting_state.rs | 2 | ||||
| -rw-r--r-- | talpid-types/src/net/mod.rs | 24 | ||||
| -rw-r--r-- | talpid-types/src/net/openvpn.rs | 29 | ||||
| -rw-r--r-- | talpid-types/src/net/proxy.rs | 32 | ||||
| -rw-r--r-- | talpid-types/src/net/wireguard.rs | 14 |
7 files changed, 82 insertions, 29 deletions
diff --git a/talpid-core/src/tunnel/openvpn.rs b/talpid-core/src/tunnel/openvpn.rs index f067a3908b..3e64545f44 100644 --- a/talpid-core/src/tunnel/openvpn.rs +++ b/talpid-core/src/tunnel/openvpn.rs @@ -454,7 +454,7 @@ impl<C: OpenVpnBuilder + 'static> OpenVpnMonitor<C> { .compat() .map_err(Error::IpRouteNotFound)?, ); - cmd.remote(params.config.get_tunnel_endpoint().endpoint) + cmd.remote(params.config.endpoint) .user_pass(user_pass_file) .tunnel_options(¶ms.options) .enable_ipv6(params.generic_options.enable_ipv6) diff --git a/talpid-core/src/tunnel_state_machine/connected_state.rs b/talpid-core/src/tunnel_state_machine/connected_state.rs index bc1ca6d4af..7421ef42eb 100644 --- a/talpid-core/src/tunnel_state_machine/connected_state.rs +++ b/talpid-core/src/tunnel_state_machine/connected_state.rs @@ -61,11 +61,11 @@ impl ConnectedState { fn get_endpoint_from_params(&self) -> Endpoint { match self.tunnel_parameters { - TunnelParameters::OpenVpn(ref config) => match config.proxy { - Some(ref proxy_settings) => proxy_settings.get_endpoint(), - None => self.tunnel_parameters.get_tunnel_endpoint().endpoint, + TunnelParameters::OpenVpn(ref params) => match params.proxy { + Some(ref proxy_settings) => proxy_settings.get_endpoint().endpoint, + None => params.config.endpoint, }, - _ => self.tunnel_parameters.get_tunnel_endpoint().endpoint, + TunnelParameters::Wireguard(ref params) => params.connection.get_endpoint(), } } diff --git a/talpid-core/src/tunnel_state_machine/connecting_state.rs b/talpid-core/src/tunnel_state_machine/connecting_state.rs index c82ad27f73..94eebdf818 100644 --- a/talpid-core/src/tunnel_state_machine/connecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/connecting_state.rs @@ -48,7 +48,7 @@ impl ConnectingState { let endpoint = params.get_tunnel_endpoint().endpoint; let peer_endpoint = match proxy { - Some(proxy_settings) => proxy_settings.get_endpoint(), + Some(proxy_settings) => proxy_settings.get_endpoint().endpoint, None => endpoint, }; diff --git a/talpid-types/src/net/mod.rs b/talpid-types/src/net/mod.rs index 6fffd88828..915ab5c49a 100644 --- a/talpid-types/src/net/mod.rs +++ b/talpid-types/src/net/mod.rs @@ -7,6 +7,7 @@ use std::{ }; pub mod openvpn; +pub mod proxy; pub mod wireguard; /// TunnelParameters are used to encapsulate all the data needed to start a tunnel. This is enum @@ -22,8 +23,16 @@ pub enum TunnelParameters { impl TunnelParameters { pub fn get_tunnel_endpoint(&self) -> TunnelEndpoint { match self { - TunnelParameters::OpenVpn(params) => params.config.get_tunnel_endpoint(), - TunnelParameters::Wireguard(params) => params.connection.get_tunnel_endpoint(), + TunnelParameters::OpenVpn(params) => TunnelEndpoint { + tunnel_type: TunnelType::OpenVpn, + endpoint: params.config.endpoint, + proxy: params.proxy.as_ref().map(|proxy| proxy.get_endpoint()), + }, + TunnelParameters::Wireguard(params) => TunnelEndpoint { + tunnel_type: TunnelType::Wireguard, + endpoint: params.connection.get_endpoint(), + proxy: None, + }, } } @@ -75,11 +84,20 @@ pub struct TunnelEndpoint { pub endpoint: Endpoint, /// Type of the tunnel pub tunnel_type: TunnelType, + pub proxy: Option<proxy::ProxyEndpoint>, } impl fmt::Display for TunnelEndpoint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "{} - {}", self.tunnel_type, self.endpoint,) + write!(f, "{} - {}", self.tunnel_type, self.endpoint)?; + if let Some(ref proxy) = self.proxy { + write!( + f, + " via {} {} over {}", + proxy.proxy_type, proxy.endpoint.address, proxy.endpoint.protocol + )?; + } + Ok(()) } } diff --git a/talpid-types/src/net/openvpn.rs b/talpid-types/src/net/openvpn.rs index a763b01b12..d9c31ed92b 100644 --- a/talpid-types/src/net/openvpn.rs +++ b/talpid-types/src/net/openvpn.rs @@ -1,4 +1,7 @@ -use crate::net::{Endpoint, GenericTunnelOptions, TransportProtocol, TunnelEndpoint, TunnelType}; +use crate::net::{ + proxy::{ProxyEndpoint, ProxyType}, + Endpoint, GenericTunnelOptions, TransportProtocol, +}; use serde::{Deserialize, Serialize}; use std::net::SocketAddr; @@ -25,12 +28,6 @@ impl ConnectionConfig { password, } } - pub fn get_tunnel_endpoint(&self) -> TunnelEndpoint { - TunnelEndpoint { - tunnel_type: TunnelType::OpenVpn, - endpoint: self.endpoint, - } - } } /// TunnelOptions contains options for an openvpn tunnel that should be applied @@ -54,12 +51,22 @@ pub enum ProxySettings { Shadowsocks(ShadowsocksProxySettings), } + impl ProxySettings { - pub fn get_endpoint(&self) -> Endpoint { + pub fn get_endpoint(&self) -> ProxyEndpoint { match self { - ProxySettings::Local(settings) => settings.get_endpoint(), - ProxySettings::Remote(settings) => settings.get_endpoint(), - ProxySettings::Shadowsocks(settings) => settings.get_endpoint(), + ProxySettings::Local(settings) => ProxyEndpoint { + endpoint: settings.get_endpoint(), + proxy_type: ProxyType::Custom, + }, + ProxySettings::Remote(settings) => ProxyEndpoint { + endpoint: settings.get_endpoint(), + proxy_type: ProxyType::Custom, + }, + ProxySettings::Shadowsocks(settings) => ProxyEndpoint { + endpoint: settings.get_endpoint(), + proxy_type: ProxyType::Shadowsocks, + }, } } } diff --git a/talpid-types/src/net/proxy.rs b/talpid-types/src/net/proxy.rs new file mode 100644 index 0000000000..d2960932c6 --- /dev/null +++ b/talpid-types/src/net/proxy.rs @@ -0,0 +1,32 @@ +use crate::net::Endpoint; +use serde::{Deserialize, Serialize}; +use std::fmt; + +/// Types of bridges that can be used to proxy a connection to a tunnel +#[serde(rename_all = "snake_case")] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum ProxyType { + /// Shadowsocks + Shadowsocks, + /// Custom bridge + Custom, +} + +impl fmt::Display for ProxyType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + let bridge = match self { + ProxyType::Shadowsocks => "Shadowsocks", + ProxyType::Custom => "custom bridge", + }; + write!(f, "{}", bridge) + } +} + + +/// Bridge endpoint, broadcast as part of TunnelEndpoint +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct ProxyEndpoint { + #[serde(flatten)] + pub endpoint: Endpoint, + pub proxy_type: ProxyType, +} diff --git a/talpid-types/src/net/wireguard.rs b/talpid-types/src/net/wireguard.rs index 2a2da501bb..d803197ebb 100644 --- a/talpid-types/src/net/wireguard.rs +++ b/talpid-types/src/net/wireguard.rs @@ -1,4 +1,4 @@ -use crate::net::{Endpoint, GenericTunnelOptions, TransportProtocol, TunnelEndpoint, TunnelType}; +use crate::net::{Endpoint, GenericTunnelOptions, TransportProtocol}; use ipnetwork::IpNetwork; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::{ @@ -26,14 +26,10 @@ pub struct ConnectionConfig { } impl ConnectionConfig { - pub fn get_tunnel_endpoint(&self) -> TunnelEndpoint { - let host = self.peer.endpoint; - TunnelEndpoint { - tunnel_type: TunnelType::Wireguard, - endpoint: Endpoint { - address: host, - protocol: TransportProtocol::Udp, - }, + pub fn get_endpoint(&self) -> Endpoint { + Endpoint { + address: self.peer.endpoint, + protocol: TransportProtocol::Udp, } } } |
