Franz Heinzmann eebb60fef9 refactor!: Mark more items as non-exhaustive (#4226)
## Description

Adds `#[non_exhaustive]` to more public structs and enums, so that
fields and variants can be added without a breaking change.

For each struct that has at least one field without a reasonable default
a `new()` constructor is added that takes those required values and
leaves the rest at their defaults. Remaining fields are then assigned
through their public field directly. Structs that already had a
`Default` impl keep it.

Internal callers (the `iroh-relay` binary, `iroh::test_utils`, and the
patchbay integration tests) are updated to use the new constructors and
field assignment instead of struct literals.

## Breaking changes

`iroh-base`:

- `iroh_base::endpoint_addr::CustomAddrParseError` is now
`#[non_exhaustive]`.

`iroh`: 

- `iroh::endpoint::BeforeConnectOutcome` is now `#[non_exhaustive]`.
- `iroh::endpoint::AfterHandshakeOutcome` is now `#[non_exhaustive]`.

`iroh-relay`:

- `iroh_relay::server::ServerConfig` is now `#[non_exhaustive]`. Already
had a `Default` impl; construct via `ServerConfig::default()` and assign
fields, e.g. `let mut c = ServerConfig::default(); c.relay =
Some(...);`.
- `iroh_relay::server::RelayConfig` is now `#[non_exhaustive]`. Added
`RelayConfig::new(http_bind_addr: impl Into<SocketAddr>) -> Self`, which
leaves `tls = None`, `limits = Limits::default()`, `key_cache_capacity =
None`, and `access = AccessConfig::Everyone`.
- `iroh_relay::server::AccessConfig` is now `#[non_exhaustive]`.
- `iroh_relay::server::QuicConfig` is now `#[non_exhaustive]`. Added
`QuicConfig::new(bind_addr: impl Into<SocketAddr>) -> Self`.
- `iroh_relay::server::TlsConfig` is now `#[non_exhaustive]`. Added
`TlsConfig::new(https_bind_addr: impl Into<SocketAddr>, cert:
CertConfig) -> Self`.
- `iroh_relay::server::Limits` is now `#[non_exhaustive]`. Use the
`Default` impl and then set fields as needed.
- `iroh_relay::server::ClientRateLimit` is now `#[non_exhaustive]`.
Added `ClientRateLimit::new(bytes_per_second: NonZeroU32) -> Self`,
which leaves `max_burst_bytes = None`.
- `iroh_relay::server::CertConfig` is now `#[non_exhaustive]`.
- `iroh_relay::server::client::Config<S>` is now `#[non_exhaustive]`.
Added `Config::new(endpoint_id: EndpointId, stream: RelayedStream<S>,
protocol_version: ProtocolVersion) -> Self`, which fills `write_timeout`
from `defaults::timeouts::SERVER_WRITE_TIMEOUT` and `channel_capacity`
from `protos::relay::PER_CLIENT_SEND_QUEUE_DEPTH`.
- `iroh_relay::http::ProtocolVersion` is now `#[non_exhaustive]`.
- `iroh_relay::protos::handshake::Mechanism` (cfg `server`) is now
`#[non_exhaustive]`.

`iroh-dns-server`:

- `iroh_dns_server::config::DnsConfig` is now `#[non_exhaustive]`. Added
`DnsConfig::new(port: u16, default_soa: String, default_ttl: u32,
origins: Vec<String>) -> Self`, which leaves `bind_addr = None` and the
apex `rr_a`, `rr_aaaa`, `rr_ns` records at `None`. There is no `Default`
impl: SOA, origins and port are deployment-specific and have no neutral
default.

## Change checklist

- [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.
- [x] All breaking changes documented.
2026-05-05 12:02:44 +02:00
2026-04-07 18:38:38 +02:00
2024-04-29 10:08:12 +00:00
2026-04-02 10:21:54 +02:00
2024-01-23 14:36:54 +00:00
2026-04-20 14:22:35 +02:00
2023-11-08 11:47:24 +01:00
2024-01-23 14:36:54 +00:00

iroh

less net work for networks

Documentation Crates.io downloads Chat Youtube License: MIT License: Apache 2.0 CI


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.

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 like Hash, key types or RelayUrl.
  • iroh-dns-server: DNS server implementation powering the n0_discovery for 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

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.

S
Description
IP addresses break, dial keys instead. A library that adds QUIC + NAT Traversal to your apps.
Readme
435 MiB
Languages
Rust 99.6%
Shell 0.3%