Skip to content

refactor(iroh-dns): use n0-dns-resolver instead of hickory-resolver#4419

Open
Frando wants to merge 11 commits into
mainfrom
refactor/n0-dns
Open

refactor(iroh-dns): use n0-dns-resolver instead of hickory-resolver#4419
Frando wants to merge 11 commits into
mainfrom
refactor/n0-dns

Conversation

@Frando

@Frando Frando commented Jul 16, 2026

Copy link
Copy Markdown
Member

Description

This replaces our use of hickory-resolver with a new crate, n0-dns-resolver. It is more lightweight, yet should cover all features we need. Being owned by us, it will also allow to tune things for our usecases better, if needed.

The DNS resolver in n0-dns-resolver was built in a PR to iroh initially, see #4036. This PR supersedes #4036, which has the history of the new resolver. n0-dns-resolver has since been expanded slightly.

It adds one feature: We now allow to configure a FallbackMode:
On main, we would unconditionally fall back to using Google's nameservers if reading the system config fails. I never liked this, because it means that there's no way to configure iroh's DNS resolver to use system config, but never fall back to Google. So this adds a configuration (which is natively supported by n0-dns-resolver, which also includes a static list of DNS servers from Google, Cloudflare, Quad9): Use fallback only if system config cannot be loaded for whatever reason, or never use fallback, or use fallback as a deferred second tier of nameservers (if primary tier from system conf doesnt reply, use the fallback). The latter is the default now, and will make DNS resolution more reliable, as iroh will now survive a badly configured host system as long as IP connectivity to the fallback servers (UDP or TCP) exists.

Breaking Changes

None, this is all internal.

Notes & open questions

n0-dns-resolver still needs review scrutiny. It is reasonably small:

Type Code Blank Doc comments Comments Total
Main 2116 299 888 147 3450
Tests 1998 235 219 61 2513
Sum 4114 534 1107 208 5963

i.e. around 6k lines in total, with 2.1k lines of Rust code (rest is tests, blanks, comments).

simple-dns is the main dependency, but it is in our tree regardless.
It has 6k rust code, 12k total. So both combined have 8k rust code, 18k total.

Whereas hickory-resolver, hickory-net, hickory-proto combined have about 28k rust, 78k total, which explains the binary size reduction.

Binary size savings

Size comparison for a size-optimized release, a simple binary with iroh and tokio as only dependencies:

[profile.release]
strip = true
opt-level = "z"  # Optimize for size.
lto = true
panic = "abort"

5.4MB for iroh on main
4.8MB for iroh patched to this PR

So binary size savings of about 600KB or more than 10%.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.
  • This PR was created by a human that thought critically about the
    proposed change and wrote an as clear and concise description as
    they could.
  • This PR isn't slop, and is carefully crafted to do have the
    intented effect.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 9905cad

@n0bot n0bot Bot added this to iroh Jul 16, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Jul 16, 2026
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/4419/docs/iroh/

Last updated: 2026-07-22T08:42:31Z

@dignifiedquire

Copy link
Copy Markdown
Contributor

lol android failing

Frando added 4 commits July 17, 2026 09:51
New error variants were inserted before InvalidResponse, shifting its
discriminant from 5 to 8 and failing the semver check. Append the new
variants after it instead so no existing discriminant moves.
@Frando
Frando force-pushed the refactor/n0-dns branch from ed9f566 to 3d21cea Compare July 17, 2026 07:52
Frando added 7 commits July 17, 2026 10:06
The endpoint's default DNS resolver was built with
`DnsResolver::builder().tls_client_config(..).build()`, which does not
opt into the system DNS configuration, so it never read /etc/resolv.conf
and only queried the public fallback resolvers. In sandboxed setups where
the system resolver is the only reachable one (e.g. patchbay's lab DNS,
which serves relay.test), every lookup failed and fell through to the
unreachable fallback, timing out the tests.

Add `.with_system_defaults()` so the default resolver reads the system
nameservers, as it did before the n0-dns-resolver migration.
@Frando

Frando commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

I'm marking this as ready for review. The main review target should be https://github.com/n0-computer/n0-dns-resolver. So if someone is up for reviewing this, that would be great. Can just open issues over there with findings.

We'd then release n0-dns-resolver 0.10 once happy, and update this branch to use it. Deferring publishing though until we have some review.

@Frando
Frando marked this pull request as ready for review July 22, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🚑 Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants