summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-11-14 05:46:16 +0100
committerLinus Färnstrand <linus@mullvad.net>2017-11-14 06:10:44 +0100
commit8ffc579063547e028dbcffb12007716d1a490de8 (patch)
tree81dced748be2bb01116b1f27d51eca5af8acf2eb
parent3068edb2ecb9d7440dbcd7523434400294b1e8de (diff)
downloadmullvadvpn-8ffc579063547e028dbcffb12007716d1a490de8.tar.xz
mullvadvpn-8ffc579063547e028dbcffb12007716d1a490de8.zip
Change TunnelEndpoint to another design
-rw-r--r--talpid-core/src/tunnel/mod.rs16
-rw-r--r--talpid-types/src/net.rs52
2 files changed, 50 insertions, 18 deletions
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs
index 0e12d89287..68846402c2 100644
--- a/talpid-core/src/tunnel/mod.rs
+++ b/talpid-core/src/tunnel/mod.rs
@@ -11,7 +11,7 @@ use std::io::{self, Write};
use std::net::Ipv4Addr;
use std::path::{Path, PathBuf};
-use talpid_types::net::{Endpoint, TunnelEndpoint};
+use talpid_types::net::{Endpoint, TunnelEndpoint, TunnelEndpointData};
/// A module for all OpenVPN related tunnel management.
pub mod openvpn;
@@ -38,8 +38,8 @@ mod errors {
description("Running on an unsupported operating system")
}
/// This type of VPN tunnel is not supported.
- UnsupportedTunnelTechnology {
- description("This tunnel technology is not supported")
+ UnsupportedTunnelProtocol {
+ description("This tunnel protocol is not supported")
}
}
}
@@ -111,7 +111,7 @@ impl TunnelMonitor {
/// Creates a new `TunnelMonitor` that connects to the given remote and notifies `on_event`
/// on tunnel state changes.
pub fn new<L>(
- remote: TunnelEndpoint,
+ tunnel_endpoint: TunnelEndpoint,
account_token: &str,
log: Option<&Path>,
resource_dir: &Path,
@@ -120,10 +120,10 @@ impl TunnelMonitor {
where
L: Fn(TunnelEvent) + Send + Sync + 'static,
{
- let remote = match remote {
- TunnelEndpoint::OpenVpn(endpoint) => endpoint,
- _ => bail!(ErrorKind::UnsupportedTunnelTechnology),
- };
+ match tunnel_endpoint.tunnel {
+ TunnelEndpointData::OpenVpn(_) => (),
+ TunnelEndpointData::Wireguard(_) => bail!(ErrorKind::UnsupportedTunnelProtocol),
+ }
let user_pass_file = Self::create_user_pass_file(account_token)
.chain_err(|| ErrorKind::CredentialsWriteError)?;
let cmd = Self::create_openvpn_cmd(
diff --git a/talpid-types/src/net.rs b/talpid-types/src/net.rs
index a293592f18..93238211fc 100644
--- a/talpid-types/src/net.rs
+++ b/talpid-types/src/net.rs
@@ -5,26 +5,58 @@ use std::str::FromStr;
/// Represents one tunnel endpoint. Tunnel technology plus address.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub enum TunnelEndpoint {
- /// An OpenVPN tunnel endpoint.
- OpenVpn(Endpoint),
- /// A Wireguard tunnel endpoint.
- Wireguard(SocketAddr),
+pub struct TunnelEndpoint {
+ pub address: IpAddr,
+ pub tunnel: TunnelEndpointData,
}
impl TunnelEndpoint {
/// Returns this tunnel endpoint as an `Endpoint`.
pub fn to_endpoint(&self) -> Endpoint {
+ Endpoint::new(
+ self.address,
+ self.tunnel.port(),
+ self.tunnel.transport_protocol(),
+ )
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
+pub enum TunnelEndpointData {
+ /// An OpenVPN tunnel endpoint.
+ OpenVpn(OpenVpnEndpoint),
+ /// A Wireguard tunnel endpoint.
+ Wireguard(WireguardEndpoint),
+}
+
+impl TunnelEndpointData {
+ pub fn port(&self) -> u16 {
match *self {
- TunnelEndpoint::OpenVpn(endpoint) => endpoint,
- TunnelEndpoint::Wireguard(address) => Endpoint {
- address,
- protocol: TransportProtocol::Udp,
- },
+ TunnelEndpointData::OpenVpn(metadata) => metadata.port,
+ TunnelEndpointData::Wireguard(metadata) => metadata.port,
+ }
+ }
+
+ pub fn transport_protocol(&self) -> TransportProtocol {
+ match *self {
+ TunnelEndpointData::OpenVpn(metadata) => metadata.protocol,
+ TunnelEndpointData::Wireguard(_) => TransportProtocol::Udp,
}
}
}
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)]
+pub struct OpenVpnEndpoint {
+ pub port: u16,
+ pub protocol: TransportProtocol,
+}
+
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)]
+pub struct WireguardEndpoint {
+ pub port: u16,
+}
+
+
/// Represents a network layer IP address together with the transport layer protocol and port.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Endpoint {