diff --git a/iroh-net/src/discovery/dns.rs b/iroh-net/src/discovery/dns.rs index 939972b220..ada51944d5 100644 --- a/iroh-net/src/discovery/dns.rs +++ b/iroh-net/src/discovery/dns.rs @@ -6,7 +6,6 @@ use crate::{ }; use anyhow::Result; use futures::{future::FutureExt, stream::BoxStream, StreamExt}; -use hickory_resolver::TokioAsyncResolver; use crate::dns; @@ -29,25 +28,12 @@ pub const N0_TESTDNS_NODE_ORIGIN: &str = "testdns.iroh.link"; #[derive(Debug)] pub struct DnsDiscovery { node_origin: String, - resolver: Option, } impl DnsDiscovery { /// Create a new DNS discovery with `node_origin` appended to all lookups. pub fn new(node_origin: String) -> Self { - Self { - node_origin, - resolver: None, - } - } - - /// Create a new DNS discovery with `node_origin` appended to all lookups, and a custom DNS - /// resolver instance - pub fn with_resolver(resolver: TokioAsyncResolver, node_origin: String) -> Self { - Self { - node_origin, - resolver: Some(resolver), - } + Self { node_origin } } /// Create a new DNS discovery which uses the n0 testdns origin. @@ -59,16 +45,13 @@ impl DnsDiscovery { impl Discovery for DnsDiscovery { fn resolve( &self, - _ep: MagicEndpoint, + ep: MagicEndpoint, node_id: NodeId, ) -> Option>> { + let resolver = ep.dns_resolver().clone(); let fut = async move { - let resolver = match &self.resolver { - Some(resolver) => resolver, - None => dns::resolver(), - }; let node_addr = - dns::node_info::lookup_by_id(resolver, &node_id, &self.node_origin).await?; + dns::node_info::lookup_by_id(&resolver, &node_id, &self.node_origin).await?; Ok(DiscoveryItem { provenance: "iroh-dns", last_updated: None, diff --git a/iroh-net/src/magic_endpoint.rs b/iroh-net/src/magic_endpoint.rs index 6301fd695d..4a2c6f3d29 100644 --- a/iroh-net/src/magic_endpoint.rs +++ b/iroh-net/src/magic_endpoint.rs @@ -505,6 +505,11 @@ impl MagicEndpoint { Ok(()) } + /// Get a reference to the DNS resolver used in this [`MagicEndpoint`]. + pub fn dns_resolver(&self) -> &DnsResolver { + &self.msock.dns_resolver() + } + /// Close the QUIC endpoint and the magic socket. /// /// This will close all open QUIC connections with the provided error_code and reason. See diff --git a/iroh-net/src/magicsock.rs b/iroh-net/src/magicsock.rs index b6302b44db..40f2897b77 100644 --- a/iroh-net/src/magicsock.rs +++ b/iroh-net/src/magicsock.rs @@ -1362,6 +1362,11 @@ impl MagicSock { self.inner.node_map.add_node_addr(addr); } + /// Get a reference to the DNS resolver used in this [`MagicSock`]. + pub fn dns_resolver(&self) -> &DnsResolver { + &self.inner.dns_resolver + } + /// Closes the connection. /// /// Only the first close does anything. Any later closes return nil.