Peer-to-peer protocols
Unlike HTTP’s client/server model where one side only sends requests and the other only responds, peer-to-peer protocols typically support both initiating and accepting connections on the same endpoint. This means:- Any peer can request data from any other peer
- Any peer can offer data to any other peer
- Roles can change over time (today’s client is tomorrow’s server)
Building blocks, not a framework
iroh is designed as a set of composable building blocks. The coreiroh crate
gives you endpoints and connections. From there, you choose:
Use existing protocols - Pick from protocols built by the iroh community:
iroh-blobs- Content-addressed blob storage and transferiroh-docs- Collaborative key-value documents with CRDTsiroh-gossip- Topic-based message broadcasting in swarmsiroh-automerge- Automerge document sync (experimental)
- Raw QUIC streams via iroh’s connection API (most common approach)
- RPC frameworks like
irpcwithiroh-irpc
How protocols work
ALPN identifiers
Protocols use Application-Layer Protocol Negotiation (ALPN) strings to identify themselves. When an endpoint accepts a connection, it uses the ALPN to route to the correct protocol handler. For example,iroh-blobs uses the ALPN /iroh-bytes/VERSION. When a peer connects
with this ALPN, the endpoint knows to handle it as a blobs request.
You can also use multiple ALPN identifiers for version negotiation. A connecting
peer might offer /my-protocol/2 and /my-protocol/1, letting the accepting
peer respond with whichever version it supports.
The accept loop
When your endpoint receives an incoming connection, it checks the requested ALPN and routes to the appropriate protocol handler. This is similar to HTTP routing, but happens at the connection level rather than per-request. You can handle this routing yourself by accepting connections directly, or use iroh’sRouter
to automatically route connections to registered protocol handlers.
Learn more
Ready to start building with protocols? Using existing protocols:- Blob storage with iroh-blobs
- Document collaboration with iroh-docs
- Message broadcasting with iroh-gossip