## Description `DnsResolver::reset` was `async` and awaited a write lock on the inner `RwLock<dyn Resolver>`. The socket actor's network-change handler awaited it, blocking the actor for the duration of the reset. This means we would potentially block the main actor loop for network IO because the write lock can only be acquired once all reads are done, and the reads are blocked for the duration of a DNS lookup (limited to `2s` usually). This change stores the resolver in `ArcSwap<Box<dyn Resolver>>` instead of `RwLock`. The `reset` call can now become synchronous - we build a fresh resolver and atomically swap it in via `compare_and_swap`. A `tokio::sync::Notify` wakes any in-flight lookup so it retries against the new resolver. Lookups go through an internal `op` helper that races the lookup future, the reset notification, and a per-attempt timeout in a biased `select!`. The `notified` future is enabled before the resolver is loaded, which together with the swap-then-notify ordering in `reset` ensures that in case of a reset all running futures are aborted and restarted against the new resolver. Under concurrent `reset` calls only the first CAS lands and only the winner notifies. Losers drop their freshly-built resolver. This is fine, and won't happen in practice because `reset` calls are serialized through the socket actor loop. ## Breaking Changes - changed: `iroh_relay::dns::Resolver::reset` signature changed from `fn reset(&mut self)` to `fn reset(&self) -> Box<dyn Resolver>`. Implementations now return a fresh resolver rather than mutating in place. - changed: `iroh_relay::dns::DnsResolver::reset` and `DnsResolver::clear_cache` are no longer `async`. - changed: `DnsError::Timeout` no longer carries a `tokio::time::error::Elapsed` source. The `From<tokio::time::error::Elapsed>` impl is removed. ## Notes & open questions The `op` timeout is per-attempt: a reset-triggered retry starts a fresh `sleep(timeout)`. This is intentional, since a fresh attempt against a just-changed network should not inherit the previous attempt's remaining time, but it does mean the wall-clock total can exceed `timeout`. I think this is fine and preferable. ## Change checklist - [x] Self-review. - [x] Documentation updates. - [ ] Tests if relevant. - [x] All breaking changes documented. --------- Co-authored-by: Friedel Ziegelmayer <me@dignifiedquire.com>
less net work for networks
What is iroh?
Iroh gives you an API for dialing by public key. You say “connect to that phone”, iroh will find & maintain the fastest connection for you, regardless of where it is.
Hole-punching
The fastest route is a direct connection, so if necessary, iroh tries to hole-punch. Should this fail, it can fall back to an open ecosystem of public relay servers. To ensure these connections are as fast as possible, we continuously measure iroh.
Built on QUIC
Iroh uses noq to establish QUIC connections between endpoints. This way you get authenticated encryption, concurrent streams with stream priorities, a datagram transport and avoid head-of-line-blocking out of the box.
Compose Protocols
Use pre-existing protocols built on iroh instead of writing your own:
- iroh-blobs for BLAKE3-based content-addressed blob transfer scaling from kilobytes to terabytes
- iroh-gossip for establishing publish-subscribe overlay networks that scale, requiring only resources that your average phone can handle
- iroh-docs for an eventually-consistent key-value store of iroh-blobs blobs
- iroh-willow for an (in-construction) implementation of the willow protocol
Getting Started
Rust Library
It's easiest to use iroh from rust.
Install it using cargo add iroh, then on the connecting side:
const ALPN: &[u8] = b"iroh-example/echo/0";
let endpoint = Endpoint::bind().await?;
// Open a connection to the accepting endpoint
let conn = endpoint.connect(addr, ALPN).await?;
// Open a bidirectional QUIC stream
let (mut send, mut recv) = conn.open_bi().await?;
// Send some data to be echoed
send.write_all(b"Hello, world!").await?;
send.finish()?;
// Receive the echo
let response = recv.read_to_end(1000).await?;
assert_eq!(&response, b"Hello, world!");
// As the side receiving the last application data - say goodbye
conn.close(0u32.into(), b"bye!");
// Close the endpoint and all its connections
endpoint.close().await;
And on the accepting side:
let endpoint = Endpoint::bind().await?;
let router = Router::builder(endpoint)
.accept(ALPN.to_vec(), Arc::new(Echo))
.spawn()
.await?;
// The protocol definition:
#[derive(Debug, Clone)]
struct Echo;
impl ProtocolHandler for Echo {
async fn accept(&self, connection: Connection) -> Result<()> {
let (mut send, mut recv) = connection.accept_bi().await?;
// Echo any bytes received back directly.
let bytes_sent = tokio::io::copy(&mut recv, &mut send).await?;
send.finish()?;
connection.closed().await;
Ok(())
}
}
The full example code with more comments can be found at echo.rs.
Or use one of the pre-existing protocols, e.g. iroh-blobs or iroh-gossip.
Other Languages
If you want to use iroh from other languages, make sure to check out iroh-ffi, the repository for FFI bindings.
Links
Repository Structure
This repository contains a workspace of crates:
iroh: The core library for hole-punching & communicating with relays.iroh-relay: The relay server implementation. This is the code we run in production (and you can, too!).iroh-base: Common types likeHash, key types orRelayUrl.iroh-dns-server: DNS server implementation powering then0_discoveryfor EndpointIds, running at dns.iroh.link.iroh-net-report: Analyzes your host's networking ability & NAT.
License
Copyright 2025 N0, INC.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.