Skip to content

Commit

Permalink
Add no-op DNS resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Nov 22, 2024
1 parent b84f655 commit e20c65f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 11 additions & 0 deletions mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ pub trait DnsResolver: 'static + Send + Sync {
async fn resolve(&self, host: String) -> io::Result<Vec<IpAddr>>;
}

/// DNS resolver that relies on `ToSocketAddrs` (`getaddrinfo`).
pub struct DefaultDnsResolver;

#[async_trait]
Expand All @@ -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<Vec<IpAddr>> {
Ok(vec![])
}
}

/// A type that helps with the creation of API connections.
pub struct Runtime {
handle: tokio::runtime::Handle,
Expand Down
5 changes: 2 additions & 3 deletions mullvad-problem-report/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use mullvad_api::{proxy::ApiConnectionMode, DefaultDnsResolver};
use mullvad_api::{proxy::ApiConnectionMode, NullDnsResolver};
use regex::Regex;
use std::{
borrow::Cow,
Expand Down Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions mullvad-setup/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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)?;

Expand Down

0 comments on commit e20c65f

Please sign in to comment.