About Discovery¶
A spoke cannot try a direct path to a peer without knowing the peer's public IPv6 address. Roaming sites change that address. Discovery is how spokes learn it: the hub publishes the endpoints it sees, and spokes fetch them.
Why the hub knows¶
Every spoke has the hub as a wg_mesh peer with a fixed endpoint and a persistent keepalive. The keepalive means each spoke sends the hub a packet over IPv6 at least every 25 seconds or so. WireGuard on the hub records the source address of each valid packet as that peer's endpoint. So the hub's own wg_mesh peer table always holds each spoke's current public IPv6 address and port, with no extra protocol.
The hub side of wgpathd simply reads that table once per cycle and keeps a snapshot of the peers whose endpoint is an IPv6 address that could be a direct path. It publishes the snapshot as JSON on GET /peers. It keeps no other state.
sequenceDiagram
participant B as spoke-b (roamer)
participant H as hub
participant A as spoke-a
B->>H: wg_mesh keepalive over IPv6
Note over H: kernel records spoke-b's<br/>endpoint [2001:db8:b::20]:51820
loop every cycle
H->>H: read wg_mesh peers,<br/>keep usable IPv6 endpoints
end
A->>H: GET /peers over wg_hub
H-->>A: { spoke-b key: { direct, handshake_age } }
Note over A: spoke-b's direct candidate is now<br/>[2001:db8:b::20]:51820
Note over A,B: only a candidate: the probes and a trial<br/>decide whether the direct path works
The hub reads wg_mesh but serves on its wg_hub address. That split matters. wg_mesh is where the IPv6 endpoints live, so it is the only table worth reading. wg_hub is the tunnel that stays up when the mesh is broken, so serving there means discovery works exactly when it is needed.
Soft state, never in the way¶
Discovery supplies where to probe. The probes and the trial decide whether the path works. Nothing the hub says can commit a peer to DIRECT on its own.
Because of that, discovery is allowed to be stale or missing:
- A spoke fetches on its first cycle and then every
discovery_interval(60 seconds by default). When a peer sits in RELAY with no evidence, the spoke asks for an early refresh, at most every 10 seconds. That is how a spoke picks up a peer that moved while the direct path was down. - The fetch runs in the background. The cycle never waits for it, so a dead hub never slows a fallback to relay.
- A good payload replaces the known map and is saved to
/var/run/wgpathd/cache.json. A failed fetch keeps the last map. On startup the spoke loads the cache, so it can probe before the first fetch succeeds. - The cache lives in
/var/run, which is in memory. It survives a restart or an upgrade of the daemon, but not a reboot: after a reboot a spoke remembers no addresses until it reaches the hub again. It is kept out of the router's flash on purpose, to spare it a write after every fetch. The relay endpoint never comes from discovery, so an empty cache only means a spoke stays on the relay until the hub answers.
Strict about what it accepts¶
The spoke treats the payload as untrusted input. One malformed entry rejects the whole payload, which then counts as a failed fetch. The limits are listed in the discovery HTTP API reference. Rejecting everything rather than filtering keeps a buggy or hostile hub to one effect: spokes stop learning new addresses. See the trust model for why that is the worst it can do.
A well-formed entry is a different matter when its address simply cannot be a direct path: loopback, link-local, multicast, an IPv4 address in IPv6 clothing, and the like. That is one peer's address, not a broken payload, so the spoke leaves out that entry alone and keeps the rest; the hub does not publish such an address in the first place. Unique local addresses are kept, since a private mesh over ULA is as direct as one over the internet. Then, every cycle, the spoke refuses a candidate that is right for the internet but wrong for this router: one of its own addresses, the peer's relay or tunnel address, or an address routed into wg_mesh or wg_hub, where a WireGuard endpoint would loop into a tunnel. Either way the peer just has no candidate and stays on the relay, and a probe never leaves toward such an address.
Entries for keys the spoke does not manage are ignored. The hub publishes every peer it sees, including the spoke itself; each spoke looks up only the wg_mesh public keys of its own managed peers.
Only the roamer really needs it¶
A spoke with a stable public address could, in principle, be configured statically. wgpathd does not bother. Discovery publishes every peer with a usable IPv6 endpoint, stable or not, so all spokes can share one identical wgpathd configuration. The per-peer facts that must not come from the hub, the relay address and the tunnel address, live in the static network configuration next to each peer's key.
Further reading¶
- Discovery HTTP API for the exact request, response and limits.
- Trust model for why the relay endpoint and the tunnel address never come from the hub.