From e20c65f445f74254a490cc6c6bd6958d752bceef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Fri, 22 Nov 2024 07:59:03 +0100 Subject: [PATCH] Add no-op DNS resolver --- mullvad-api/src/lib.rs | 11 +++++++++++ mullvad-problem-report/src/lib.rs | 5 ++--- mullvad-setup/src/main.rs | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index e204ab43dd4c..1f47d600b30f 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -311,6 +311,7 @@ pub trait DnsResolver: 'static + Send + Sync { async fn resolve(&self, host: String) -> io::Result>; } +/// DNS resolver that relies on `ToSocketAddrs` (`getaddrinfo`). pub struct DefaultDnsResolver; #[async_trait] @@ -326,6 +327,16 @@ impl DnsResolver for DefaultDnsResolver { } } +/// DNS resolver that always returns no results +pub struct NullDnsResolver; + +#[async_trait] +impl DnsResolver for NullDnsResolver { + async fn resolve(&self, _host: String) -> io::Result> { + Ok(vec![]) + } +} + /// A type that helps with the creation of API connections. pub struct Runtime { handle: tokio::runtime::Handle, diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs index 4b5795fb83d4..91b790e5f6fe 100644 --- a/mullvad-problem-report/src/lib.rs +++ b/mullvad-problem-report/src/lib.rs @@ -1,4 +1,4 @@ -use mullvad_api::{proxy::ApiConnectionMode, DefaultDnsResolver}; +use mullvad_api::{proxy::ApiConnectionMode, NullDnsResolver}; use regex::Regex; use std::{ borrow::Cow, @@ -292,8 +292,7 @@ async fn send_problem_report_inner( ) -> Result<(), Error> { let metadata = ProblemReport::parse_metadata(report_content).unwrap_or_else(metadata::collect); let api_runtime = mullvad_api::Runtime::with_cache( - // This is irrelevant since no DNS lookups will be made - DefaultDnsResolver, + NullDnsResolver, cache_dir, false, #[cfg(target_os = "android")] diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs index 507642f2745e..4a444aa63cdc 100644 --- a/mullvad-setup/src/main.rs +++ b/mullvad-setup/src/main.rs @@ -1,7 +1,7 @@ use clap::Parser; use std::{path::PathBuf, process, str::FromStr, sync::LazyLock, time::Duration}; -use mullvad_api::{proxy::ApiConnectionMode, DefaultDnsResolver, DEVICE_NOT_FOUND}; +use mullvad_api::{proxy::ApiConnectionMode, NullDnsResolver, DEVICE_NOT_FOUND}; use mullvad_management_interface::MullvadProxyClient; use mullvad_types::version::ParsedAppVersion; use talpid_core::firewall::{self, Firewall}; @@ -152,7 +152,7 @@ async fn remove_device() -> Result<(), Error> { .await .map_err(Error::ReadDeviceCacheError)?; if let Some(device) = state.into_device() { - let api_runtime = mullvad_api::Runtime::with_cache(DefaultDnsResolver, &cache_path, false) + let api_runtime = mullvad_api::Runtime::with_cache(NullDnsResolver, &cache_path, false) .await .map_err(Error::RpcInitializationError)?;