iroh README

The project's README from github.com/n0-computer/iroh. As one markdown file: README.md.

iroh

less net work for networks

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

Docs Site | Rust Docs


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:

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:

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.

iroh (n0-computer/iroh)

Searching Database…

12.8K ·GitHub
这是什么?Iroh 是一个 Rust 库,让你可以通过对方的公钥而不是 IP 地址来连接其他设备;它会自动找到并保持最快的连接,可以是通过打洞(hole-punching)建立的直连,也可以在失败时退回到中继服务器(relay)。它底层基于 QUIC。
它是完整的网络协议栈,还是只是一个连接库?它是一个核心 Rust 库,负责端点连通性(打洞加中继)。iroh-blobs、iroh-gossip 和 iroh-docs 等独立的协议 crate 构建在它之上,分别用于文件传输、发布订阅和键值存储。
我怎么把它加到 Rust 项目里?运行 cargo add iroh,然后在发起连接的一端通过公钥拨号,在另一端接受连接。完整的可运行示例在 echo.rs 中。
我能在 Rust 以外的语言里使用 iroh 吗?可以。通过 iroh-ffi 仓库即可,它提供 FFI 绑定,让 iroh 能在其他语言中使用。
它总能建立直连吗?不一定。Iroh 会先尝试通过打洞建立直连路径;如果失败,就退回到由公共中继服务器组成的开放生态,以保持连接。
iroh-relay 这个 crate 是做什么用的?它是 N0 在生产环境中为公共中继服务器运行的中继客户端和服务端实现,你也可以自行部署。
连接是怎么保证安全的?Iroh 通过 noq crate 建立 QUIC 连接,开箱即提供认证加密、并发的带优先级数据流以及数据报传输。
iroh-dns-server 是什么?它是 DNS 服务器实现,为 EndpointIds 提供 DNS/Pkarr 地址查询,并在 dns.iroh.link 上生产运行。
iroh 能高效传输大量数据吗?iroh-blobs 协议基于 BLAKE3 提供内容寻址的 blob 传输,可从 KB 级扩展到 TB 级。
Size
366.5 MB
Stars
12.8K
Age
4y
Commits · 90 Days