Skip to content

Conversation

Frando
Copy link
Member

@Frando Frando commented Mar 22, 2024

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::TokioAsyncResolver part of the public API surface of iroh-net.

Change checklist

  • Self-review.
  • Documentation updates if relevant.
  • Tests if relevant.

@Frando Frando added this pull request to the merge queue Mar 23, 2024
Merged via the queue into main with commit 8dcb196 Mar 23, 2024
@dignifiedquire dignifiedquire deleted the refactor/dns-resolver branch March 23, 2024 12:24
@Frando Frando mentioned this pull request Sep 29, 2025
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants