Skip to content

fix(p2p): carry local network addresses in invite links - #13420

Merged
mudler merged 1 commit into
masterfrom
fix/p2p-lan-invite
Nov 23, 2026
Merged

mudler merged 1 commit into
masterfrom
fix/p2p-lan-invite

Conversation

@mudler-agent

Copy link
Copy Markdown
Collaborator

What

An invite link now carries the private (LAN) addresses of the server, so a LAN-only invite redeems with no internet, no relay and no multicast discovery.

Why

The default invite (localai://pair?...) kept only public addresses. With no public address and no relay, the link held just the peer ID and the code. Redeem worked between two share-mode instances only because mDNS found the server. A redeeming instance in connect mode runs no mDNS (it has no listen address), so the redeem failed with 504 failed to dial ... no addresses. local-ai p2p pair builds its host without mDNS or DHT, so it failed the same way. A link with a hand-added &a=/ip4/<lan ip>/tcp/<port> already worked in all three cases, because the parser accepts private addresses; the product just never wrote them.

Changes

  • The invite adds up to two private addresses after the public ones, TCP first (IsLANAddr: RFC 1918 and ULA; loopback, link-local and unspecified are excluded; circuit addresses are skipped).
  • The parser accepts up to four a= values (was two). The mint takes at most two public addresses as before, then fills up to four. Link format version is unchanged; only more a= values appear. An older client that only accepts two a= values refuses a link with three or four.
  • Privacy: private addresses show the layout of the server's network to whoever holds the link. They are on by default so an invite works on a LAN without extra steps; POST /api/p2p/invites takes "omit_lan_addrs": true to leave them out. There is no UI toggle in this PR.
  • The no_public_addr warning still fires when the link has no public address and no relay, even when it has LAN addresses.
  • A paired remote already stores the addresses of its link, so with these addresses it can reconnect after a restart with no multicast. No schema change was needed.
  • A link with no address and no relay now yields pairclient.ErrNoRoute (wrapped with ErrUnreachable) and a message that no longer advises "ask for an invite with a relay". The generic unreachable message is also reworded.
  • Docs: docs/content/administration/p2p.md.

Testing

Run:

  • go vet on the touched packages (the core/application vet reports existing copylocks warnings in files this PR does not touch)
  • go test -race for core/services/p2ppair, core/services/p2pnet, core/services/p2ppair/pairclient, core/http/endpoints/p2p (tags nosqlite,purego_utp) and core/application with -tags auth and focus P2P
  • golangci-lint run on the same packages: 0 issues
  • New specs: link round trip with four addresses, mint with LAN addresses (order, cap, dedupe, omit option, warning), IsLANAddr table, ErrNoRoute, and an application spec where a host with no listener and no discovery redeems using only the minted link. The test host listens on loopback, which the spec treats as the LAN address through a test seam.
  • Manual: two real local-ai processes in separate network namespaces joined by one veth pair, no route out, multicast dropped in both, mDNS and public DHT off. A connect-mode instance added the share instance as a remote from a link with no hand-added address (redeem in about 0.3 s, direct path). local-ai p2p pair --invite from the same namespace paired as well.

Not tested: IPv6 ULA on a real network, several interfaces, a QR scan of a four-address link, the React UI (no UI change), swagger files (generated, not regenerated here).

An invite carried only public addresses and relays. On a network with
no internet, no relay and no public address, the link held just the peer
ID and the code. A redeeming device found the server only through mDNS,
which a server in connect mode and the "local-ai p2p pair" command do not
run, so the redeem failed with "no addresses".

The invite now also carries up to two private addresses (RFC 1918 and
unique local IPv6, never loopback or link-local) after the public ones,
TCP first. The parser accepts up to four "a" values; the link format
version is unchanged. A paired remote already stores the addresses of
its link, so it can reconnect without multicast discovery.

The private addresses show the layout of the server's network to whoever
holds the link, so POST /api/p2p/invites takes "omit_lan_addrs" to leave
them out. They are included by default so that an invite works on a
local network without extra steps.

A link with no address and no relay now gives its own error that no
longer advises asking for a relay.

Assisted-by: Claude:claude-sonnet-5-5 golangci-lint go-test
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
@mudler
mudler merged commit 7c10850 into master Nov 23, 2026
71 of 77 checks passed
@mudler
mudler deleted the fix/p2p-lan-invite branch November 23, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants