go-iroh

module
v0.0.0-...-1d7e402 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: MIT

README

go-iroh

go-iroh is a Go implementation of iroh. It provides peer-to-peer QUIC endpoints identified by ed25519 public keys, with direct paths, relay fallback, QUIC Retry, multipath, QAD observed addresses, and QNT NAT traversal support, plus Rust-compatible ports of the iroh protocol stack: blobs, gossip, and docs.

The module is a clean-room Go port targeting wire compatibility with upstream Rust iroh. It is not affiliated with the n0 team.

Packages

Connectivity layer:

Package Purpose
iroh Endpoint, Conn, Router, address lookup
key endpoint IDs, Ed25519 keys, signatures
netaddr endpoint addresses, transport addresses, relay URLs
dns pkarr TXT encoding and stdlib/DoH/DoT lookupers
pkarr pkarr signed DNS packet codec
relay public relay maps and relay configuration
metrics small OpenMetrics registry
watch small generic watch values

Protocols (Rust-compatible ports):

Package Purpose
blobs content-addressed blob tickets, identifiers, and BAO transfer
gossip iroh-gossip pub/sub mesh (HyParView membership, PlumTree broadcast)
docs iroh-docs multi-writer key-value documents and range sync
endpointticket Rust-compatible endpoint ticket codec
postcard Rust-compatible postcard wire codec (shared with sibling modules)
http3 adapts iroh connections for HTTP/3 implementations

Commands:

Command Purpose
cmd/iroh utility for iroh identities and addresses (keys, endpoint info)
cmd/iroh-relay small, self-hostable relay server
cmd/iroh-dns-server pkarr HTTP and DNS server for discovery
cmd/wasmrelaytest browser smoke test for the js/wasm relay-only transport

The transport internals live under internal/: relay protocol/client/server, net reports, socket path management, RFC 7250 TLS, the postcard and pkarr implementations, the gossip proto state machine, and qng, the quic-go fork used for iroh/noq compatibility.

Install

go get github.com/tmc/go-iroh

This module currently declares Go 1.26 in go.mod.

Use

The iroh package is the main entry point:

ep, err := iroh.Bind(ctx, iroh.WithALPNs("example/1"))
if err != nil {
	return err
}
defer ep.Shutdown(ctx)

conn, err := ep.Connect(ctx, peerAddr, "example/1")
if err != nil {
	return err
}
defer conn.CloseWithError(0, "")

ALPN means Application-Layer Protocol Negotiation. It is the TLS extension that lets peers agree which application protocol a QUIC connection will carry, such as "example/1" or "n0/iroh/transfer/example/1". go-iroh uses ALPN values to route incoming connections to handlers.

The API takes ALPN values as Go strings. TLS ALPN values are byte strings on the wire; Go strings preserve arbitrary bytes, while keeping the common printable ASCII case simple.

See iroh/example_test.go for runnable direct-loopback Router and Endpoint examples.

Wire Compatibility

Relay, pkarr, DoH, and DoT connections use standard WebPKI TLS. Direct peer-to-peer QUIC uses TLS 1.3 Raw Public Keys (RFC 7250) with mutual endpoint authentication. Go's standard crypto/tls does not support RFC 7250, so this repository carries internal/itls/tls and drives it from internal/qng.

internal/qng is a quic-go v0.59.1 fork extended for the iroh/noq transport surface: multipath, QAD observed-address reporting, QNT NAT traversal, and pre-connection QUIC Retry admission. The fork-local READMEs document when those forks can be removed.

Validation

Run the local suite:

go test ./...

For a repeatable local check:

go test ./... -count=1

For loopback stream/datagram latency and throughput, with raw TCP and UDP baselines:

GOMAXPROCS=4 go test ./iroh -run '^$' -bench 'Benchmark(Conn|RawTCP|RawUDP)' -benchtime=5s -count=5

BenchmarkRawUDPMagicQueuedPingPong is the closest raw UDP latency baseline for the magic-socket path: it uses the same receive queue depth, pooled receive buffers, caller-buffer copy, and separate write queue shape as the direct IP transport.

Live Rust interop gates are opt-in because they require a checked-out and built Rust iroh tree:

GO_IROH_LIVE_RUST_INTEROP=1 \
IROH_RUST_REPO=/path/to/n0-computer/iroh \
go test ./internal/compat -run 'TestLiveRust' -count=1 -v

GO_IROH_LIVE_RUST_INTEROP=1 \
IROH_RUST_REPO=/path/to/n0-computer/iroh \
go test ./iroh -run TestLiveRustTransferFetchPingDirectPath -count=1 -v

The gossip stack has its own opt-in live gate that builds a Rust iroh-gossip helper (from gossip/testdata/rust-gossip-interop) and exchanges membership and broadcast with it over /iroh-gossip/1. It requires cargo:

GO_IROH_LIVE_RUST_GOSSIP=1 go test ./gossip -run TestLiveRustGossipInterop -count=1 -v

Status

The connectivity layer is a wire-compatible iroh endpoint. The protocol packages (blobs, gossip, docs) port the corresponding Rust crates, sharing the postcard and pkarr wire codecs; gossip carries the full HyParView and PlumTree state machine with a postcard discovery channel.

The normal local suite covers the public packages, qng transport extensions, and local relay/direct behavior. The opt-in Rust gates cover live echo, Rust transfer provider/upload, direct-path selection, qlog evidence for QNT frames, and Go↔Rust gossip membership and broadcast, when the host environment provides the required binaries and network topology.

GOOS=js/GOARCH=wasm builds compile. Browser runtime support is limited by the platform: the relay WebSocket client has a js-specific dial path, but direct UDP QUIC, direct paths, and NAT traversal are not available in browser WebAssembly.

License

go-iroh is licensed under the MIT License. See LICENSE.

The forked quic-go code under internal/qng retains its upstream license notice in internal/qng/LICENSE.

Directories

Path Synopsis
Package blobs defines Rust-compatible iroh blob tickets, blob identifiers, and transfer helpers.
Package blobs defines Rust-compatible iroh blob tickets, blob identifiers, and transfer helpers.
cmd
iroh command
Command iroh is a small utility for working with iroh identities and addresses: generating and inspecting keys, and parsing endpoint info.
Command iroh is a small utility for working with iroh identities and addresses: generating and inspecting keys, and parsing endpoint info.
iroh-dns-server command
Command iroh-dns-server runs the pkarr HTTP and DNS surfaces used by iroh discovery.
Command iroh-dns-server runs the pkarr HTTP and DNS surfaces used by iroh discovery.
iroh-relay command
Command iroh-relay runs a small, self-hostable iroh relay server.
Command iroh-relay runs a small, self-hostable iroh relay server.
wasmrelaytest command
Package dns provides DNS-based endpoint discovery for go-iroh: publishing and resolving endpoint addressing information via DNS using the pkarr signed packet format.
Package dns provides DNS-based endpoint discovery for go-iroh: publishing and resolving endpoint addressing information via DNS using the pkarr signed packet format.
Package dnsserver implements an embeddable iroh DNS and pkarr relay server.
Package dnsserver implements an embeddable iroh DNS and pkarr relay server.
Package docs implements Rust-compatible iroh-docs data and sync protocols.
Package docs implements Rust-compatible iroh-docs data and sync protocols.
Package endpointticket encodes and decodes Rust-compatible iroh endpoint tickets.
Package endpointticket encodes and decodes Rust-compatible iroh endpoint tickets.
Package gossip provides Rust-compatible iroh-gossip transport helpers.
Package gossip provides Rust-compatible iroh-gossip transport helpers.
Package http3 adapts iroh connections for HTTP/3 implementations.
Package http3 adapts iroh connections for HTTP/3 implementations.
internal
compat
Package compat holds cross-implementation parity tests comparing go-iroh against the reference Rust iroh implementation.
Package compat holds cross-implementation parity tests comparing go-iroh against the reference Rust iroh implementation.
gossipproto
Package gossipproto defines the Rust-compatible iroh-gossip wire messages.
Package gossipproto defines the Rust-compatible iroh-gossip wire messages.
itls/shim/boring
Package boring is a minimal shim for the GOROOT-private crypto/internal/boring.
Package boring is a minimal shim for the GOROOT-private crypto/internal/boring.
itls/shim/byteorder
Package byteorder is a minimal shim for the GOROOT-private internal/byteorder, providing just the little-endian uint32 reader that the vendored crypto/tls uses.
Package byteorder is a minimal shim for the GOROOT-private internal/byteorder, providing just the little-endian uint32 reader that the vendored crypto/tls uses.
itls/shim/cpu
Package cpu is a minimal shim for the GOROOT-private internal/cpu, exposing just the feature flags the vendored crypto/tls reads.
Package cpu is a minimal shim for the GOROOT-private internal/cpu, exposing just the feature flags the vendored crypto/tls reads.
itls/shim/fips140deps_byteorder
Package byteorder is a minimal shim for crypto/internal/fips140deps/byteorder.
Package byteorder is a minimal shim for crypto/internal/fips140deps/byteorder.
itls/shim/fips140tls
Package fips140tls is a shim for crypto/tls/internal/fips140tls.
Package fips140tls is a shim for crypto/tls/internal/fips140tls.
itls/shim/fipsaes
Package fipsaes is a shim for crypto/internal/fips140/aes, exposing just the Block type and constructor the vendored crypto/tls casts to.
Package fipsaes is a shim for crypto/internal/fips140/aes, exposing just the Block type and constructor the vendored crypto/tls casts to.
itls/shim/fipsgcm
Package fipsgcm is a shim for crypto/internal/fips140/aes/gcm, providing the TLS GCM constructors the vendored crypto/tls uses.
Package fipsgcm is a shim for crypto/internal/fips140/aes/gcm, providing the TLS GCM constructors the vendored crypto/tls uses.
itls/shim/fipstls12
Package fipstls12 implements the TLS 1.2 PRF and extended-master-secret derivation (RFC 5246 §5, RFC 7627).
Package fipstls12 implements the TLS 1.2 PRF and extended-master-secret derivation (RFC 5246 §5, RFC 7627).
itls/shim/fipstls13
Package tls13 implements the TLS 1.3 Key Schedule as specified in RFC 8446, Section 7.1 and allowed by FIPS 140-3 IG 2.4.B Resolution 7.
Package tls13 implements the TLS 1.3 Key Schedule as specified in RFC 8446, Section 7.1 and allowed by FIPS 140-3 IG 2.4.B Resolution 7.
itls/shim/godebug
Package godebug is a minimal shim for the GOROOT-private internal/godebug, providing just the Setting API that the vendored crypto/tls uses.
Package godebug is a minimal shim for the GOROOT-private internal/godebug, providing just the Setting API that the vendored crypto/tls uses.
itls/shim/hkdf
Package hkdf is a minimal shim for crypto/internal/fips140/hkdf, implementing HKDF (RFC 5869) generically over hash.Hash, matching the API the vendored crypto/tls key schedule uses.
Package hkdf is a minimal shim for crypto/internal/fips140/hkdf, implementing HKDF (RFC 5869) generically over hash.Hash, matching the API the vendored crypto/tls key schedule uses.
itls/tls
Package tls partially implements TLS 1.2, as specified in RFC 5246, and TLS 1.3, as specified in RFC 8446.
Package tls partially implements TLS 1.2, as specified in RFC 5246, and TLS 1.3, as specified in RFC 8446.
netreport
Package netreport probes the local network environment to build a Report describing relay latencies and (where available) the public reflexive address of the host.
Package netreport probes the local network environment to build a Report describing relay latencies and (where available) the public reflexive address of the host.
pkarr
Package pkarr implements the pkarr (https://pkarr.org) signed DNS packet format used by iroh for endpoint discovery.
Package pkarr implements the pkarr (https://pkarr.org) signed DNS packet format used by iroh for endpoint discovery.
portmapper
Package portmapper is a minimal NAT-PMP (RFC 6886) client for requesting a UDP port mapping from a home gateway.
Package portmapper is a minimal NAT-PMP (RFC 6886) client for requesting a UDP port mapping from a home gateway.
postcard
Package postcard encodes and decodes the Rust postcard wire format.
Package postcard encodes and decodes the Rust postcard wire format.
qng
qng/cmd/qngregen command
Command qngregen regenerates internal/qng from the quic-go module pinned in go.mod.
Command qngregen regenerates internal/qng from the quic-go module pinned in go.mod.
qng/internal/monotime
Package monotime provides a monotonic time representation that is useful for measuring elapsed time.
Package monotime provides a monotonic time representation that is useful for measuring elapsed time.
qng/internal/utils/linkedlist
Package list implements a doubly linked list.
Package list implements a doubly linked list.
qng/qlogwriter/jsontext
Package jsontext provides a fast JSON encoder providing only the necessary features for qlog encoding.
Package jsontext provides a fast JSON encoder providing only the necessary features for qlog encoding.
relayclient
Package relayclient implements the client side of an iroh relay connection.
Package relayclient implements the client side of an iroh relay connection.
relayproto
Package relayproto implements the iroh relay wire protocol: the framing, datagram, and handshake messages exchanged between a relay client and server.
Package relayproto implements the iroh relay wire protocol: the framing, datagram, and handshake messages exchanged between a relay client and server.
socket
Package socket implements iroh's "magic socket": a single net.PacketConn, driven by quic-go, that multiplexes datagrams across several transports (direct UDP, relay, custom).
Package socket implements iroh's "magic socket": a single net.PacketConn, driven by quic-go, that multiplexes datagrams across several transports (direct UDP, relay, custom).
Package iroh provides peer-to-peer QUIC connectivity between endpoints identified by ed25519 public keys, interoperable with the Rust iroh project (https://github.com/n0-computer/iroh).
Package iroh provides peer-to-peer QUIC connectivity between endpoints identified by ed25519 public keys, interoperable with the Rust iroh project (https://github.com/n0-computer/iroh).
mdns
Package mdns provides local-network endpoint discovery for go-iroh.
Package mdns provides local-network endpoint discovery for go-iroh.
Package irpc provides small postcard-framed RPC helpers for iroh streams.
Package irpc provides small postcard-framed RPC helpers for iroh streams.
Package key provides Ed25519 keys, signatures, and endpoint identifiers for go-iroh.
Package key provides Ed25519 keys, signatures, and endpoint identifiers for go-iroh.
Package metrics provides a small OpenMetrics registry for go-iroh metrics.
Package metrics provides a small OpenMetrics registry for go-iroh metrics.
Package netaddr provides endpoint and transport addresses for go-iroh.
Package netaddr provides endpoint and transport addresses for go-iroh.
Package pkarr exposes go-iroh's pkarr signed DNS packet codec.
Package pkarr exposes go-iroh's pkarr signed DNS packet codec.
Package postcard exposes go-iroh's Rust-compatible postcard wire codec.
Package postcard exposes go-iroh's Rust-compatible postcard wire codec.
Package relay provides the public configuration types for iroh relay servers: relay URLs grouped into a Map, per-relay Config, and the Mode selecting which relays an endpoint uses.
Package relay provides the public configuration types for iroh relay servers: relay URLs grouped into a Map, per-relay Config, and the Mode selecting which relays an endpoint uses.
Package relayserver implements the server side of the iroh relay protocol.
Package relayserver implements the server side of the iroh relay protocol.
Package watch provides an observable value: a Value that can be updated and one or more Observer handles that observe its changes.
Package watch provides an observable value: a Value that can be updated and one or more Observer handles that observe its changes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL