Repository navigation
fix(p2p): carry local network addresses in invite links - #13420
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inconnectmode runs no mDNS (it has no listen address), so the redeem failed with504 failed to dial ... no addresses.local-ai p2p pairbuilds 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
IsLANAddr: RFC 1918 and ULA; loopback, link-local and unspecified are excluded; circuit addresses are skipped).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 morea=values appear. An older client that only accepts twoa=values refuses a link with three or four.POST /api/p2p/invitestakes"omit_lan_addrs": trueto leave them out. There is no UI toggle in this PR.no_public_addrwarning still fires when the link has no public address and no relay, even when it has LAN addresses.pairclient.ErrNoRoute(wrapped withErrUnreachable) and a message that no longer advises "ask for an invite with a relay". The generic unreachable message is also reworded.docs/content/administration/p2p.md.Testing
Run:
go veton the touched packages (thecore/applicationvet reports existing copylocks warnings in files this PR does not touch)go test -raceforcore/services/p2ppair,core/services/p2pnet,core/services/p2ppair/pairclient,core/http/endpoints/p2p(tagsnosqlite,purego_utp) andcore/applicationwith-tags authand focusP2Pgolangci-lint runon the same packages: 0 issuesIsLANAddrtable,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.local-aiprocesses in separate network namespaces joined by one veth pair, no route out, multicast dropped in both, mDNS and public DHT off. Aconnect-mode instance added theshareinstance as a remote from a link with no hand-added address (redeem in about 0.3 s, direct path).local-ai p2p pair --invitefrom 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).