How zig-libp2p layers fit together. The on-disk layout mirrors this model after the repository rationalization (phases 0–5).
┌─────────────────────────────────────────────────────────────┐
│ Embedder (zeam, examples/host_quic_node, interop nodes) │
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────┐
│ core/ Host, Swarm, ConnectionManager, peer events │
└───────────────────────────┬─────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────────┐
│ protocols/ │ │ transport/ │ │ security/ │
│ gossipsub │ │ quic/, tcp, ws│ │ libp2p TLS, noise │
│ req_resp │ │ yamux, mplex │ └───────────────────┘
│ kad_dht, … │ └───────────────┘
└───────────────┘
│
▼
┌───────────────┐
│ primitives/ │ identity, varint, multistream, protobuf wire
└───────────────┘
- Embedder creates a
Host(core/host.zig) with local key material fromprimitives/identity.zig. - Transport (
transport/quic/runtime.zig, withconfig.zig+conn_table.zig) owns UDP listen/dial, TLS handshake, and per-connection stream I/O. - Multistream-select (
transport/stream_multistream.zig) negotiates protocol IDs on each stream. - Protocol handlers dispatch to
protocols/*(ping, identify, gossipsub RPC, req/resp, AutoNAT, relay, DCUtR, DHT). - Swarm (
core/swarm.zig) surfaces connection and discovery events; ConnectionManager tracks dial/backoff policy.
Consumers import a single module:
const zig_libp2p = @import("zig_libp2p");src/root.zig re-exports the flat names used today (host, gossipsub, kad_dht, …). Canonical
nested paths are also available:
zig_libp2p.core.hostzig_libp2p.primitives.identityzig_libp2p.protocols.kad_dht(via the flatkad_dhtalias today)
Legacy shim files under src/*.zig, src/<protocol>/, and src/transport/quic_*.zig forward to
the new locations so internal imports keep working during migration.
build.zig delegates to build/deps.zig (module wiring), build/examples.zig (example table +
smoke runs), build/fuzz.zig, build/soak.zig (zig build soak-test), and build/interop.zig.
internal/wire_boundaries.zig— fuzz/smoke helpers for wire parsers (not part of the embedder API).vendor/at repo root — vendoredzquic_tls/zquic_rsatrees (outsidesrc/to avoid Zig 0.16 duplicate module path errors when bothzquicandzig_libp2pcompile the same TLS tree).src/vendor/zquic_tls/root.zigis a shim for any legacy import path.
Cross-impl conformance lives outside src/ in harness/; it exercises the
same wire paths as production nodes but is not linked into the library package.