Network Architecture
Table of Contents
- Topology
- Traffic Planes
- Userspace Dataplane
- Client Connection Flow
- Private API Delivery
- Server-to-Server Traffic
- Security Transport
- DNS Discovery
- NAT Traversal
- SDK Client
Topology
Internet
|
┌──────────────────┼──────────────────┐
| | |
[Server A] [Server B] [Server C]
us-west eu-west ap-south
pub: <ip-a> pub: <ip-b> pub: <ip-c>
tun: 10.64.252.a tun: 10.64.253.b tun: 10.64.254.c
bb: 172.16.0.a bb: 172.16.1.b bb: 172.16.2.c
| | |
└──── Server backbone (172.16.0.0/22) ────┘
| | |
[clients] [clients] [clients]
client plane (10.64.0.0/10)
Both the client plane and the server backbone are virtual addresses that exist only inside each daemon (userspace netstack). There is no kernel WireGuard interface and no TUN device on the server.
Each server has its own tunnel address. It is 10.64.252.0 plus the offset
of the server’s backbone address, so the two addresses of a server end in the
same offset (see IP Ranges).
Traffic Planes
Public internet
| Traffic | Port | Purpose |
|---|---|---|
| Public HTTPS API | TCP 9100 |
Discovery, health, auth, join, onboarding. HTTPS or withheld — never plaintext. TCP 443 is mapped to it as an alias; the SDK falls back to 443 when the advertised port gets no response. |
| Mesh + hole punching (BoringTun) | UDP 51940 |
Client tunnels, server backbone, and NAT traversal — one shared socket |
| Gossip + security protocol | UDP 9102 |
Signed server messages; state sync; security envelopes |
| STUN | UDP 3478 |
External address discovery |
| Relay | UDP 9103 |
Fallback mesh forwarding when direct P2P fails |
| DNS | UDP+TCP 5335 local / 53 advertised |
Authoritative SEIP zone (DNS-serving nodes; 53 is NAT-mapped) |
Over the mesh (client plane 10.64.x.x)
| Traffic | Port | Purpose |
|---|---|---|
| Private HTTPS API | TCP 9101 |
Tree, IPAM, mesh, routing, relay, certs, onboarding administration — via the in-process netstack to a loopback bridge |
Server backbone (172.16.x.x)
| Traffic | Purpose |
|---|---|
| Private API (server-to-server) | Cross-server operations on the same virtual 9101 |
| Mesh data | Encrypted server-to-server traffic over the same UDP socket |
All public services listen on the wildcard address. The private API listens on loopback plus the virtual tunnel/backbone addresses only.
Userspace Dataplane
The server terminates WireGuard entirely in userspace: BoringTun Noise sessions plus an in-process smoltcp netstack. Consequences:
- The daemon needs no root and no capabilities. Every port it binds is
unprivileged (9100, 9101, 51940, 9102, 3478, 9103, 5335). Public
53and443are reached by firewall/NAT mapping, not by binding. - Tunnel keys and decrypted plaintext never leave the process.
- Traffic addressed to the virtual addresses is delivered to in-process listeners; traffic for other peers is re-encrypted and forwarded in userspace.
- The netstack answers ICMP echo requests at the server’s tunnel address. A client probes the tunnel with echo requests of several sizes when its dataplane comes up and sizes its own MTU, and so the segment size it advertises, to the largest one answered (docs/Client-SDK.md).
Client Connection Flow
1. DNS discovery
Client -> system DNS -> ns1..ns9 glue -> <region>.seip.<domain>
A record -> server public IP
_config TXT -> ports, region, load, host FQDN
2. Public API (TCP 9100, verified HTTPS)
POST /api/auth/challenge -> Ed25519 nonce
POST /api/auth -> identity authentication
POST /api/join -> node creation, tunnel IP, mesh config, session JWT
3. Mesh tunnel (UDP 51940)
BoringTun handshake -> client 10.65.x.x <-> server 10.64.252.0/22 address
4. Private API (TCP 9101, via the mesh)
Tree, mesh, IPAM, routing, relay, certs
POST /api/join is the composite bootstrap: its response carries the session
JWT, node_id, tunnel_ip, the server tunnel IP, the mesh server public key,
the mesh endpoint, the private API port, the mesh FQDNs, and the mesh DNS
servers.
The client selects the best server client-side after a health probe of each discovered candidate (latency plus load scoring), with region fallback.
Endpoint selection
A device reaches a peer over the first path that answers, in this order:
- A LAN endpoint, when the peer is on the same network (
local_endpoints). - The peer’s published endpoint, dialed directly or by hole punching. The published endpoint is the router mapping while its lease is live, else the STUN reflexive address.
- The relay (UDP
9103), when neither direct path answers.
Hole punching fails behind a symmetric NAT, which corporate gateways such as
Zscaler use: the gateway assigns a new public port for every destination, so
the port that STUN saw is not the port a peer must dial. A mapped endpoint
fixes this because the far side dials out: a mapping on one side gives the
other side a fixed port to send to, and the symmetric NAT lets that outbound
flow through. The SDK asks the default gateway for the mapping with PCP first
and NAT-PMP second (see Client SDK).
A gateway that offers neither changes nothing: the reflexive address stays
published. The server needs no change, because the heartbeat’s endpoint
field already carries whichever endpoint the device publishes to its peers.
Private API Delivery
The delivery pattern (server side):
- httplib binds a real socket on
127.0.0.1:9101only. - The netstack adds TCP forwards so virtual connections to
<tunnel_ip>:9101(client plane) or the backbone IP are bridged into that loopback listener. - Every private route is JWT-gated. The private listener uses the
private.<id>.<region>.seip.<domain>certificate.
If a server has no tunnel address, no private listener is created and the private routes are registered on the public server instead. The server logs a security warning; authentication still applies, network isolation does not.
Server-to-Server Traffic
Server A (us-west) Server B (eu-west)
172.16.0.x 172.16.0.x
| |
|---- Gossip (UDP 9102, public) ----->|
| ServerHello: signed certificate |
| (with mesh pubkey), advertised |
| endpoint cross-checked against |
| the observed UDP source |
| security envelopes (0x16) |
| |
|---- Mesh backbone (UDP 51940) ----->|
| same socket as the client mesh; |
| the backbone IP is a second |
| virtual address on the same |
| dataplane. Carries gossip on |
| virtual UDP 9102: tree sync, |
| DNS catch-up, account envelopes |
Gossip messages are Ed25519-signed. State-mutating gossip ingress requires the sender to hold a root-signed, non-revoked peer certificate; the authentication binds to the signer, never to the NAT-able endpoint.
Gossip that replicates member data travels only on the backbone, on virtual
UDP from one backbone address to the other at the gossip port: permission
tree sync (Digest, DeltaRequest, DeltaResponse), DNS catch-up
(SyncDigest, SyncRequest), and account group-key envelopes
(AccountEnvelopeSync). The BoringTun dataplane encrypts it. A server
refuses these types on the public socket, and accepts them only from the
signer’s own backbone address. Tree records carry members’ mesh public keys,
tunnel and private addresses, and permission assignments, so they must not
cross the internet in the clear.
All other gossip and security envelopes are sent to the peer’s public
gossip endpoint (advertised public_ip:gossip_port when confirmed against
the observed source, otherwise the observed source). This includes
ServerHello, peer exchange, backbone claims, live DNS deltas, ACL deltas and
NS slot claims, which are signed but not encrypted. A server reaches the
backbone only after the public exchange gives it the peer’s backbone claim
and mesh key.
Security Transport
Security-protocol messages (attestation challenge/evidence, HotStuff
proposal/vote/timeout, DKG broadcast/pairwise, FROST commitment/signature
share, epoch announcements, sync, and genesis/founding records) travel in a
single gossip wire type, SecurityEnvelope (0x16):
- Authenticated (signature) and size-bounded before any parse; never relayed.
- The router applies per-peer message budgets, deduplication, ruleset and network checks, and epoch-window validation, then hands the envelope to the one security service.
- Sensitive pairwise DKG round-2 payloads are additionally sealed to the recipient identity (X25519 sealed box) inside the envelope.
- Wire types
0x07–0x10are retired and reserved forever;0x15is a logged refusal.
Security messages are not all carried inside WireGuard: the gossip plane on
9102 is a signed UDP transport with its own authentication and bounds.
DNS Discovery
See DNS Discovery for the full record layout. In short:
<id>.<region>.seip.<domain> A -> public IP
_config.<id>.<region>.seip.<domain> TXT -> v=sp1 http= udp= gossip= stun= relay= dns= private_http= region= load= [host=]
private.<id>.<region>.seip.<domain> A -> tunnel IP
backend.<id>.<region>.seip.<domain> A -> backbone IP
tier1|tier2.<region>.seip.<domain> A -> onboarding/seed discovery
ns1..ns9.<domain> A -> bootstrap nameservers
private.<node_id>.ep.<domain> A -> client tunnel IP
NAT Traversal
Hole punching shares the mesh UDP port 51940 — there is no separate
signaling port. Coordination runs over the private routing API
(/api/routing/*), with the server as rendezvous coordinator:
Client A (NAT) Server (coordinator) Client B (NAT)
| | |
|-- routing/request ------>| |
| (B's identifier + |<--- endpoint/register ----|
| A's candidates) | |
| | candidates marked "verified"
| | when they match the observed
| | control-connection source
|<-- directive: B -------|- directive: A -->|
| punch_at = now+1s | punch_at = now+1s |
| | |
|=== simultaneous handshake on UDP 51940 ===============>|
|<=== direct P2P encrypted mesh tunnel =================>|
Path selection is DirectP2P when both sides offered a usable candidate;
otherwise it selects Relay. The routing coordinator does not allocate a
relay session for a routing-layer connection: its directive carries an empty
relay_endpoint. STUN (3478) supplies reflexive candidates.
Mesh dataplane peers do not use the routing coordinator. Each SDK client
learns its reflexive address with a STUN query sent from its BoringTun
dataplane socket to the session server (3478), and publishes it with the
mesh heartbeat. Authorized peers receive it in GET /api/mesh/peers from
their verified Tier 1 server and send BoringTun handshake initiations to it
from their own dataplane socket. Both sides probe at the same wall-clock slot,
which each side computes from the two public keys, so no signaling message is
needed. A probe changes no state; only a valid handshake answer moves the peer
to the probed address.
The heartbeat answer’s peers_revision changes when a device’s peer list
changes, so the other side fetches a new or moved peer’s endpoint within one
heartbeat (3 seconds) and punches back at once, instead of at its next
30-second peer refresh; its devices_revision reports a device list change
the same way. The SDK also holds an event socket open to its
session server (GET /api/events, a WebSocket on the private API). The
server sends the device’s peers_revision and devices_revision when the
socket opens and as soon as either changes: when a tree change commits, a
LAN endpoint list changes, or a listed peer goes online or offline. A peer
on the same Tier 1 server, and a change to the device list, are therefore
seen without waiting for a heartbeat. A server without the socket gets the
peer list long-poll instead (GET /api/mesh/peers/<node_id>?wait_revision=,
up to 25 seconds), which the server answers as soon as the revision changes.
Each server wakes only the requests that it holds; a change that arrives
through consensus or through shared presence wakes them on every Tier 1
server.
Device presence is shared. A device is present at a server while it sends
authenticated heartbeats or holds its own event socket open there. Each
Tier 1 server sends the presence it heard itself to the other Tier 1
servers every 3 seconds, and at once when a device arrives (gossip type
PresenceSync, backbone only, Tier 1 to Tier 1). The peer list reports
is_online while the latest presence from any Tier 1 server is less than
10 seconds old, and last_seen as that time. A phone on one Tier 1 server
and a home server on another therefore see each other online. Presence is a
hint for display and path choice; it grants nothing.
The heartbeat also carries the device’s private LAN addresses with its
dataplane port (local_endpoints). The server keeps them in memory with the
device’s presence, and PresenceSync carries them to the other Tier 1
servers, so a peer whose session is on another server gets them too. Each
server validates a received list as it validates a heartbeat, and lists it
only to the peers that already list the device. A device probes
the LAN endpoints of a peer on its own network (the same public address, or
a shared subnet) together with the peer’s public endpoint, so two devices
behind a router that does not hairpin UDP still connect directly over the
LAN.
When no direct handshake arrives within 3 seconds (1.5 seconds for a peer
reachable only on the LAN), the SDK relay fallback
takes over (UDP 9103): each peer requests its own relay ticket from its
verified Tier 1 server, and the relay pairs the two peers’ Allocate
requests. A relayed peer keeps getting upgrade probes and moves back to the
direct path when one succeeds. See
Client SDK,
Client SDK, and
Security.
SDK Client
LemonadeNexusSDK mirrors the server’s userspace design on the client:
join_networkauthenticates (Ed25519 challenge-response with the client identity; password is a deprecated fallback stub), calls/api/join, and brings the BoringTun dataplane up in-process — no TUN device, no admin rights. The mesh keypair is derived from the authenticated identity.- Private-API calls ride an egress bridge: the netstack binds an ephemeral
127.0.0.1listener and bridges accepted connections to a virtual TCP stream toward the server’s<tunnel_ip>:9101. - A background orchestrator refreshes peers, learns and publishes the reflexive address (STUN), sends heartbeats, punches direct paths, falls back to relays, and tracks liveness.
- Local service publishing is now exposed:
expose_service(vport, target)publishes a local service to mesh peers (the daemon bridgesour-mesh-IP:vportto, e.g.,tcp:127.0.0.1:PORT), andopen_egress(dst_ip, dst_port)opens a loopback bridge to a mesh peer’s service. Both exist in the C++ API and the C ABI (ln_mesh_expose_service,ln_mesh_open_egress). - Session tokens are per-server JWTs; surviving a dead server means fresh DNS discovery plus re-join with the preserved identity.