refactor(iroh-net): allow to set a custom DNS resolver on the magic endpoint#2116
Merged
refactor(iroh-net): allow to set a custom DNS resolver on the magic endpoint#2116
Conversation
dignifiedquire
approved these changes
Mar 22, 2024
11 tasks
github-merge-queue bot
pushed a commit
that referenced
this pull request
Sep 30, 2025
## Description Replaces #2116 Fixes #3468 This adds a `Resolver` trait to abstract over DNS resolution. It contains methods to resolve IPv4 or IPv6 addresses, and TXT records. Because the trait needs to be dyn-compatible for our usage (we don't want to have a generic for the DNS resolver on the Endpoint), all methods return boxed futures that contain boxed iterators. To not pay the cost of boxing when using the default hickory-based resolver, the iroh `DnsResolver` internally contains an enum which is either the default resolver or the boxed custom resolver. Users can implement the `Resolver` trait on whatever struct to use a completely custom DNS resolver. ## Breaking Changes Changes in `iroh_relay::dns` (reexported from `iroh::dns`): * `DnsResolver::lookup_txt` now returns `impl Iterator<Item = TxtRecord>` * `TxtLookup` and `TXT` are removed. Changes in `iroh_relay::node_info` (reexported from `iroh::discovery`): * `NodeInfo::from_txt_lookup` now takes `domain_name: String, lookup: impl Iterator<Item = crate::dns::TxtRecordData>` Moved items: * `iroh_relay::node_info::LookupError` was moved to `iroh_relay::dns::LookupError` ## Notes & open questions We likely want to still add a builder for our DnsResolver to allow setting a few more of the common options on the hickory resolver. But with this, people that want to use some completely custom way of resolving DNS records can do so. <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist <!-- Remove any that are not relevant. --> - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [x] All breaking changes documented. - [ ] List all breaking changes in the above "Breaking Changes" section. - [ ] Open an issue or PR on any number0 repos that are affected by this breaking change. Give guidance on how the updates should be handled or do the actual updates themselves. The major ones are: - [ ] [`quic-rpc`](https://github.com/n0-computer/quic-rpc) - [ ] [`iroh-gossip`](https://github.com/n0-computer/iroh-gossip) - [ ] [`iroh-blobs`](https://github.com/n0-computer/iroh-blobs) - [ ] [`dumbpipe`](https://github.com/n0-computer/dumbpipe) - [ ] [`sendme`](https://github.com/n0-computer/sendme)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This makes the DNS resolver to be used in the context of a MagicEndpoint configurable. Up to now, we used a single, global, unconfigurable DNS resolver, stored in a per-process global static. This PR changes this so that we can set a DNS resolver in the builder of the MagicEndpoint. This resolver is passed through to all places where we need a DNS resolver - which is all places where we need to resolve relay URLs.
The default is unchanged: A single, shared DNS resolver is used for all endpoints. However, this default can now be changed per-endpoint. The global resolver is only used as a default in the endpoint builder if no custom resolver is set, and in the doctor, and in tests.
This change will make testing things that use DNS - prominently: #2045 - much easier. And we now have the means in place for people to customize the DNS resolving, if needed.
Notes & open questions
This makes the
hickory_resolver::TokioAsyncResolverpart of the public API surface ofiroh-net.Change checklist