go-iroh

module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT

README

go-iroh

Go Reference

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.

Wire compatibility and Go API stability are separate promises. The wire protocol tracks pinned upstream releases; the Go API is not stable before v1 and may change in any v0 release.

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
relayserver embeddable relay server (backs cmd/iroh-relay)
dnsserver embeddable DNS and pkarr server (backs cmd/iroh-dns-server)
metrics small OpenMetrics registry
watch small generic watch values

Protocols (Rust-compatible ports):

Package Purpose
blobs content-addressed blob tickets, identifiers, blob stores, 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
irpc postcard-framed RPC helpers for iroh streams
postcard Rust-compatible postcard wire codec (shared with sibling modules)
quicconn adapts iroh connections to a QUIC-like surface

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.

Ecosystem

Repository Contents
go-iroh-examples 40+ runnable example programs, from hello-world dial-up to gossip meshes
go-iroh-tools command-line tools built on go-iroh
go-iroh-experiments experimental modules layered on go-iroh

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

Run the focused wire-parser fuzz targets for one minute each:

go test -run '^$' -fuzz '^FuzzReadObserveItem$' -fuzztime 1m ./blobs
go test -run '^$' -fuzz '^FuzzUnmarshal$' -fuzztime 1m ./internal/postcard
go test -run '^$' -fuzz '^FuzzFromBytes$' -fuzztime 1m ./internal/pkarr
go test -run '^$' -fuzz '^FuzzParseRelayFrames$' -fuzztime 1m ./internal/relayproto
go test -run '^$' -fuzz '^FuzzKeyMaterialClientAuthHeader$' -fuzztime 1m ./internal/relayproto

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 runs through the compatibility harness on the compat-harness branch, which drives unmodified upstream iroh binaries in pinned Docker images against go-iroh and renders COMPATIBILITY.md. It requires only Go and Docker:

git checkout compat-harness
cd iroh-compat-harness && make parity

Debugging

Every endpoint installs the qlog connection tracer, so setting QLOGDIR records a qlog trace of every QUIC connection the process opens or accepts, with no code change:

QLOGDIR=./qlog go run ./cmd/...

Each connection writes <odcid>_client.sqlog or <odcid>_server.sqlog, in JSON-seq, one event per line. The two files for a single connection share the original destination connection id, so a dial and the accept that answers it pair up by filename. Traces carry frame metadata, loss and congestion events, and the handshake — not payload bytes:

jq -c 'select(.name == "quic:packet_sent") | .data.frames[]' qlog/*_client.sqlog

QLOGDIR is read once per connection and applies process-wide, so a process running several endpoints interleaves their traces in one directory, keyed only by connection id. iroh.WithQLOG replaces it for one endpoint: the sink is called once per connection and returns the io.WriteCloser for that trace, so endpoints in one process can be traced separately, or somewhere other than a file. iroh.QLOGDir builds a sink with the same file layout as QLOGDIR.

Payload bytes

qlog stops at frame metadata. To see the bytes a stream carried, log the TLS traffic secrets with iroh.WithKeyLogWriter, capture the UDP flow, and let Wireshark decrypt it:

keys, _ := os.Create("keys.txt")
ep, _ := iroh.Bind(ctx, iroh.WithKeyLogWriter(keys)) // debugging only
tshark -r cap.pcap -o tls.keylog_file:keys.txt -Y quic.stream_data -T fields -e quic.stream_data

Writing those secrets compromises the confidentiality of every connection the endpoint makes, so this is a debugging tool, not a deployment option. Three things stay dark:

  • Relayed traffic. Relay paths are an encrypted websocket to the relay, not the QUIC flow, so a capture of a relayed connection decrypts nothing.
  • 0-RTT. No early-traffic secret is written, so resumed connections' early data is not decryptable.
  • The reverse direction after connection-id rotation. Only the direction that keeps its connection id stays readable for the whole capture.

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. Live Go↔Rust coverage — handshakes, transport semantics, relay, discovery, and gossip against pinned upstream releases — runs in the compatibility harness and is summarized in COMPATIBILITY.md.

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.
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.
fuzztape
Package fuzztape adapts go test -fuzz for typed and stateful testing.
Package fuzztape adapts go test -fuzz for typed and stateful testing.
fuzztape/faults
Package faults provides tape-driven fault injection for fuzztape machines.
Package faults provides tape-driven fault injection for fuzztape machines.
fuzztape/model
Package model checks a system under test against a reference model.
Package model checks a system under test against a reference model.
fuzztape/splice
Package splice builds new fuzz seeds by cutting corpus inputs at operation boundaries.
Package splice builds new fuzz seeds by cutting corpus inputs at operation boundaries.
fuzztape/stats
Package stats counts how often a fuzztape machine's ops actually run.
Package stats counts how often a fuzztape machine's ops actually run.
fuzztape/trace
Package trace turns a failing input into a test you can paste.
Package trace turns a failing input into a test you can paste.
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.
pprofserver
Package pprofserver serves Go runtime profiles on a dedicated HTTP listener.
Package pprofserver serves Go runtime profiles on a dedicated HTTP listener.
qng
Package quic is a fork of quic-go, copied into go-iroh so that it can be built against RFC 7250 raw-public-key TLS.
Package quic is a fork of quic-go, copied into go-iroh so that it can be built against RFC 7250 raw-public-key TLS.
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 quicconn adapts iroh connections to a QUIC-like surface.
Package quicconn adapts iroh connections to a QUIC-like surface.
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