2025-06-25 12:34:00
github.com
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.
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.
Iroh uses Quinn to establish QUIC connections between nodes.
This way you get authenticated encryption, concurrent streams with stream priorities, a datagram transport and avoid head-of-line-blocking out of the box.
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
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::builder().discovery_n0().bind().await?;
// Open a connection to the accepting node
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::builder().discovery_n0().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.
If you want to use iroh from other languages, make sure to check out iroh-ffi, the repository for FFI bindings.
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_discovery
for NodeIds, running at dns.iroh.link.iroh-net-report
: Analyzes your host’s networking ability & NAT.
Copyright 2024 N0, INC.
This project is licensed under either of
at your option.
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.
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Help Power Techcratic’s Future – Scan To Support
If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.
As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!
BITCOIN bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge Scan the QR code with your crypto wallet app |
DOGECOIN D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA Scan the QR code with your crypto wallet app |
ETHEREUM 0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a Scan the QR code with your crypto wallet app |
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.