diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-04-28 12:46:44 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-04-29 12:17:20 +0200 |
| commit | b63304495277695dddd142b33b3d5cdf70c591c9 (patch) | |
| tree | 9a6d315b806be44191a8d9d39ce2670d2f43fc55 | |
| parent | ccacc8ea7a53c600417981a8abd6fa8e70c5f7de (diff) | |
| download | mullvadvpn-b63304495277695dddd142b33b3d5cdf70c591c9.tar.xz mullvadvpn-b63304495277695dddd142b33b3d5cdf70c591c9.zip | |
Implement From for TunnelEndpoint
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 25 | ||||
| -rw-r--r-- | mullvad-management-interface/src/types.rs | 23 |
2 files changed, 25 insertions, 23 deletions
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index d9e77f556b..203f723fb6 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -800,13 +800,13 @@ fn convert_state(state: TunnelState) -> types::TunnelState { Disconnected => ProtoState::Disconnected(tunnel_state::Disconnected {}), Connecting { endpoint, location } => ProtoState::Connecting(tunnel_state::Connecting { relay_info: Some(types::TunnelStateRelayInfo { - tunnel_endpoint: Some(convert_endpoint(endpoint)), + tunnel_endpoint: Some(types::TunnelEndpoint::from(endpoint)), location: location.map(convert_geoip_location), }), }), Connected { endpoint, location } => ProtoState::Connected(tunnel_state::Connected { relay_info: Some(types::TunnelStateRelayInfo { - tunnel_endpoint: Some(convert_endpoint(endpoint)), + tunnel_endpoint: Some(types::TunnelEndpoint::from(endpoint)), location: location.map(convert_geoip_location), }), }), @@ -878,27 +878,6 @@ fn convert_state(state: TunnelState) -> types::TunnelState { types::TunnelState { state: Some(state) } } -fn convert_endpoint(endpoint: talpid_types::net::TunnelEndpoint) -> types::TunnelEndpoint { - use talpid_types::net; - - types::TunnelEndpoint { - address: endpoint.endpoint.address.to_string(), - protocol: i32::from(types::TransportProtocol::from(endpoint.endpoint.protocol)), - tunnel_type: match endpoint.tunnel_type { - net::TunnelType::Wireguard => i32::from(types::TunnelType::Wireguard), - net::TunnelType::OpenVpn => i32::from(types::TunnelType::Openvpn), - }, - proxy: endpoint.proxy.map(|proxy_ep| types::ProxyEndpoint { - address: proxy_ep.endpoint.address.to_string(), - protocol: i32::from(types::TransportProtocol::from(proxy_ep.endpoint.protocol)), - proxy_type: match proxy_ep.proxy_type { - net::proxy::ProxyType::Shadowsocks => i32::from(types::ProxyType::Shadowsocks), - net::proxy::ProxyType::Custom => i32::from(types::ProxyType::Custom), - }, - }), - } -} - fn convert_geoip_location(geoip: GeoIpLocation) -> types::GeoIpLocation { types::GeoIpLocation { ipv4: geoip.ipv4.map(|ip| ip.to_string()).unwrap_or_default(), diff --git a/mullvad-management-interface/src/types.rs b/mullvad-management-interface/src/types.rs index 4c058bac89..ae3d94f29c 100644 --- a/mullvad-management-interface/src/types.rs +++ b/mullvad-management-interface/src/types.rs @@ -5,6 +5,29 @@ use std::convert::TryFrom; tonic::include_proto!("mullvad_daemon.management_interface"); +impl From<talpid_types::net::TunnelEndpoint> for TunnelEndpoint { + fn from(endpoint: talpid_types::net::TunnelEndpoint) -> Self { + use talpid_types::net; + + TunnelEndpoint { + address: endpoint.endpoint.address.to_string(), + protocol: i32::from(TransportProtocol::from(endpoint.endpoint.protocol)), + tunnel_type: match endpoint.tunnel_type { + net::TunnelType::Wireguard => i32::from(TunnelType::Wireguard), + net::TunnelType::OpenVpn => i32::from(TunnelType::Openvpn), + }, + proxy: endpoint.proxy.map(|proxy_ep| ProxyEndpoint { + address: proxy_ep.endpoint.address.to_string(), + protocol: i32::from(TransportProtocol::from(proxy_ep.endpoint.protocol)), + proxy_type: match proxy_ep.proxy_type { + net::proxy::ProxyType::Shadowsocks => i32::from(ProxyType::Shadowsocks), + net::proxy::ProxyType::Custom => i32::from(ProxyType::Custom), + }, + }), + } + } +} + impl From<mullvad_types::wireguard::KeygenEvent> for KeygenEvent { fn from(event: mullvad_types::wireguard::KeygenEvent) -> Self { use keygen_event::KeygenEvent as Event; |
