Skip to content

Commit e20c65f

Browse files
committed
Add no-op DNS resolver
1 parent b84f655 commit e20c65f

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

mullvad-api/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ pub trait DnsResolver: 'static + Send + Sync {
311311
async fn resolve(&self, host: String) -> io::Result<Vec<IpAddr>>;
312312
}
313313

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

316317
#[async_trait]
@@ -326,6 +327,16 @@ impl DnsResolver for DefaultDnsResolver {
326327
}
327328
}
328329

330+
/// DNS resolver that always returns no results
331+
pub struct NullDnsResolver;
332+
333+
#[async_trait]
334+
impl DnsResolver for NullDnsResolver {
335+
async fn resolve(&self, _host: String) -> io::Result<Vec<IpAddr>> {
336+
Ok(vec![])
337+
}
338+
}
339+
329340
/// A type that helps with the creation of API connections.
330341
pub struct Runtime {
331342
handle: tokio::runtime::Handle,

mullvad-problem-report/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use mullvad_api::{proxy::ApiConnectionMode, DefaultDnsResolver};
1+
use mullvad_api::{proxy::ApiConnectionMode, NullDnsResolver};
22
use regex::Regex;
33
use std::{
44
borrow::Cow,
@@ -292,8 +292,7 @@ async fn send_problem_report_inner(
292292
) -> Result<(), Error> {
293293
let metadata = ProblemReport::parse_metadata(report_content).unwrap_or_else(metadata::collect);
294294
let api_runtime = mullvad_api::Runtime::with_cache(
295-
// This is irrelevant since no DNS lookups will be made
296-
DefaultDnsResolver,
295+
NullDnsResolver,
297296
cache_dir,
298297
false,
299298
#[cfg(target_os = "android")]

mullvad-setup/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::Parser;
22
use std::{path::PathBuf, process, str::FromStr, sync::LazyLock, time::Duration};
33

4-
use mullvad_api::{proxy::ApiConnectionMode, DefaultDnsResolver, DEVICE_NOT_FOUND};
4+
use mullvad_api::{proxy::ApiConnectionMode, NullDnsResolver, DEVICE_NOT_FOUND};
55
use mullvad_management_interface::MullvadProxyClient;
66
use mullvad_types::version::ParsedAppVersion;
77
use talpid_core::firewall::{self, Firewall};
@@ -152,7 +152,7 @@ async fn remove_device() -> Result<(), Error> {
152152
.await
153153
.map_err(Error::ReadDeviceCacheError)?;
154154
if let Some(device) = state.into_device() {
155-
let api_runtime = mullvad_api::Runtime::with_cache(DefaultDnsResolver, &cache_path, false)
155+
let api_runtime = mullvad_api::Runtime::with_cache(NullDnsResolver, &cache_path, false)
156156
.await
157157
.map_err(Error::RpcInitializationError)?;
158158

0 commit comments

Comments
 (0)