Skip to content

Module Map

Reference map of all source modules and their responsibilities.

Top-Level

FilePurpose
main.zigCLI entry point, command dispatch, daemon event loop
lib.zigLibrary root — re-exports all modules for embedders
config.zigConfiguration struct with network, discovery, and trust defaults
meshguard_ffi.zigC-ABI FFI surface for mobile embedding (Android JNI)
wg_interop.zigWireGuard interop layer for cross-platform tunnel management

identity/

FilePurpose
keys.zigEd25519 keypair generation, save/load, sign/verify
trust.zigauthorized_keys/ management, key validation, authorization
org.zigOrg keypair generation, NodeCertificate signing/verification

discovery/

FilePurpose
swim.zigSWIM protocol engine: ping/ack loop, gossip propagation, handshake coordination, hole punch triggers
membership.zigMembership table: peer states (alive/suspected/dead), Lamport clocks, suspicion expiry, random peer selection
seed.zigSeed peer resolution: static IP parsing, DNS/mDNS placeholders
lan.zigLAN multicast discovery: UDP beacon broadcast/receive on 239.99.99.1, app ID filtering

wireguard/

FilePurpose
noise.zigNoise_IKpsk2 handshake: initiation, response, key derivation, decryptInitiatorStatic for O(1) routing
device.zigWgDevice peer manager: IndexTable (Fibonacci hash), StaticKeyTable, handshake handling, encrypt/decrypt dispatch
tunnel.zigTransport layer: ChaCha20-Poly1305 encrypt/decrypt, ReplayWindow (2048-bit sliding window), rekey/keepalive timers
ip.zigMesh IP derivation: Blake3(pubkey) → 10.99.X.Y, IP formatting/parsing
crypto.zigHMAC-Blake2s via std.crypto.auth.hmac, HKDF (kdf1/kdf2/kdf3), mixHash
wg_config.zigKernel WireGuard setup: configure peers/keys via Genetlink socket
netlink.zigGenetlink (WG_USERSPACE) socket abstraction
nlsocket.zigRaw netlink socket: send/recv, message builder, attribute helpers
rtnetlink.zigRTNETLINK operations: interface create/delete, IP address assignment, route addition, interface up/down

nat/

FilePurpose
stun.zigSTUN client (RFC 5389): Binding Request/Response encoding, XOR-MAPPED-ADDRESS parsing, NAT type detection
holepunch.zigUDP hole punching: Holepuncher state machine, probe magic (MGHP), rendezvous-mediated exchange, 4 concurrent slots
relay.zigRelay selection: best public-IP peer by RTT, capacity checking, RelayInfo struct
upnp.zigUPnP-IGD port forwarding: SSDP discovery, SOAP AddPortMapping, lease renewal
coordinated_punch.zigToken-based coordinated punch: meshguard connect token exchange for direct peer setup

protocol/

FilePurpose
messages.zigWire message type definitions: Ping, Ack, PingReq, HandshakeInit/Resp, GossipEntry, HolepunchRequest/Response, NatType, Endpoint
codec.zigBinary codec: encode/decode for all message types, gossip entry serialization (89 bytes each)

services/

FilePurpose
control.zigControl socket server (Unix domain socket / Windows named pipe) for meshguard status, down
policy.zigService access control engine: policy file parsing, rule evaluation, packet filtering

crypto/

FilePurpose
sodium.ziglibsodium FFI bindings for AEAD acceleration

net/

FilePurpose
udp.zigNon-blocking UDP socket: bind, sendTo, recvFrom, pollRead
batch_udp.zigBatched UDP I/O: sendmmsg/recvmmsg for high-throughput packet processing
tun.zigLinux TUN device: open, read/write packets, setMtu, setNonBlocking, multi-queue
utun.zigmacOS utun device: PF_SYSTEM socket creation, 4-byte AF header handling
wintun.zigWindows Wintun adapter: DLL loading, ring buffer read/write
darwincfg.zigmacOS interface configuration: ifconfig/route for IP assignment, MTU, routes
wincfg.zigWindows interface configuration: netsh for IP assignment, routes
dns.zigDNS resolver: seed peer discovery via DNS TXT records
offload.zigGSO/GRO offload: IFF_VNET_HDR, segmentation offload for high-throughput paths
pipeline.zigPacket processing pipeline: batched encrypt/decrypt with multi-queue TUN support
io.zigEvent loop abstraction layer
io_uring.zigLinux io_uring integration for async I/O

docker/

FilePurpose
entrypoint.shContainer entrypoint for Docker-based deployments
bench.shBasic Docker-based benchmark (kernel vs userspace)
test-mesh.shDocker-compose mesh connectivity test
lxc-bench.sh2-way LXC benchmark (kernel vs meshguard)
lxc-4way-bench.sh4-way LXC benchmark (kernel vs meshguard vs wireguard-go vs boringtun)

Released under the MIT License.