Skip to content

Commit

Permalink
Show correct endpoint in CLI for custom relays
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Oct 17, 2023
1 parent aee7561 commit 1c903ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion mullvad-cli/src/cmds/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ impl Relay {
let relay_settings = settings.relay_settings;

match relay_settings {
RelaySettings::CustomTunnelEndpoint(endpoint) => {
RelaySettings::CustomTunnelEndpoint(mut endpoint) => {
if let Err(error) = endpoint.resolve_host() {
eprintln!("Failed to resolve custom endpoint: {error}");
return Ok(());
}
println!("Custom endpoint: {endpoint}")
}

Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl InnerParametersGenerator {
async fn generate(&mut self, retry_attempt: u32) -> Result<TunnelParameters, Error> {
let _data = self.device().await?;
match self.relay_selector.get_relay(retry_attempt) {
Ok((SelectedRelay::Custom(custom_relay), _bridge, _obfsucator)) => {
Ok((SelectedRelay::Custom(mut custom_relay), _bridge, _obfsucator)) => {
self.last_generated_relays = None;
custom_relay
// TODO: generate proxy settings for custom tunnels
Expand Down
18 changes: 11 additions & 7 deletions mullvad-types/src/custom_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ impl CustomTunnelEndpoint {
}
}

pub fn resolve_host(&mut self) -> Result<(), Error> {
let ip = resolve_to_ip(&self.host)?;
self.config.set_ip(ip);
Ok(())
}

pub fn to_tunnel_parameters(
&self,
&mut self,
tunnel_options: TunnelOptions,
proxy: Option<openvpn::ProxySettings>,
) -> Result<TunnelParameters, Error> {
let ip = resolve_to_ip(&self.host)?;
let mut config = self.config.clone();
config.set_ip(ip);
self.resolve_host()?;

let parameters = match config {
let parameters = match &self.config {
ConnectionConfig::OpenVpn(config) => openvpn::TunnelParameters {
config,
config: config.clone(),
options: tunnel_options.openvpn,
generic_options: tunnel_options.generic,
proxy,
Expand All @@ -59,7 +63,7 @@ impl CustomTunnelEndpoint {
}
.into(),
ConnectionConfig::Wireguard(connection) => wireguard::TunnelParameters {
connection,
connection: connection.clone(),
options: tunnel_options.wireguard.into_talpid_tunnel_options(),
generic_options: tunnel_options.generic,
obfuscation: None,
Expand Down

0 comments on commit 1c903ef

Please sign in to comment.