Repository navigation
feat(machines): add a PC through the relay with the code it shows - #2952
Conversation
Settings > Remote PCs > Add a PC through the relay now also takes the ten-character code the other PC shows under Show a code to type. This PC's server runs the device side of the typed-code exchange (moved to shared/relay-code-offer.ts), keeps the offer it found, and answers only the PC's ID for the person to match before the PC is added. Fixes #2810
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
…ng window holds Another driving client could add the PC by naming its public ID; two windows finding PCs at once undid each other; a find kept running after its request ended.
Review round (Codex terra xhigh, omo)omo at 2f81440: CLEAR. Codex at 2f81440, all fixed in f8dc4a8:
Codex re-review at f8dc4a8: the three are fixed; one new LOW, left as is: the ticket is spent before pairing starts, so a pairing that fails (relay down at that moment) needs a new code on the other PC. That is the same one-try-per-code rule the phone's code screen keeps.
|
|
Local merge gate (owner-approved): origin/main merged (clean), |
Fixes #2810
What
#2829 added Settings → Remote PCs → Add a PC through the relay, which pairs this PC with another one by its pasted pairing link: no SSH, no open port, no Tailscale, end-to-end encrypted, B's key pinned, revocation on either side ending it, offline/reconnect through the remote-PC backoff, and a phone paired with A seeing B through A. The piece of #2810 still missing was the typed code: a desktop has no camera for the QR code, and copying a link from one PC to another needs some channel between them.
The same row now takes either the link or the ten-character code the other PC shows under Settings → Phone & devices → Show a code to type (#2883):
A pasted link still adds the PC in one step, as before.
How
src/lib/relay/pairCode.ts(the device side of the typed-code exchange: one CPace exchange per call, offer key checked against its id, offer must carry a pairing code) moves toshared/relay-code-offer.ts, so the server can run it too (server code may not importsrc/).pairCode.tsre-exports it, so the hosted app is unchanged. The only code changes in the moved file: the forged-offer check callsderiveServerId(importPublicKey(...))directly instead ofshellState.forgedOffer, the socket type isRelaySocket, and the answer frame is sent as anArrayBuffer.POST /api/machines/relay/code { code }→ 200{ ticket, server_id, name }, ortyped_code_<failure>(not-a-code400,no-pc404,wrong400,expired410,busy409,unreachable502,forged502). Same guards as every PC change (same origin,X-Herdr-Machine: 1, HTTPS or localhost, watch devices refused).MachineManagerkeeps each found offer in memory under a random 32-byte ticket that only the asking window gets (at most 8, 10 minutes each, B's own pairing-code lifetime);POST /api/machines/relay { found: <ticket> }takes it once. Another client that knows B's public ID gets nothing. The find also stops when its request is aborted.addRelayruns unchanged: the pairing, key storage and reconnects are feat(machines): add a PC through the relay, without SSH #2829's.codeFailureText(the code screen's failure sentences) moves out ofRelayShell.tsxintosrc/components/codeFailureText.ts, so both screens word failures the same. Those keys move from the relay dictionary part to the base dictionaries, since two features now use them.Wire changes (additive)
POST /api/machines/relay/code.POST /api/machines/relayacceptsfoundinstead oflink.UI
The design follows GitHub's device sign-in (one screen shows a short code, the other asks for it in a single field), as #2883 does. One input takes a link or a code, so the row stays one control. The ID comparison reuses the phone's wording and
KeyId. Screenshots at 390 and 1280, light and dark, from the demo build with the two API answers stubbed in the page: entry row, ID comparison, and a wrong-code message. There is no sideways scroll at either width, and It matches is 44 px tall on the phone.Validation
server/relay-pc.contract.test.ts"finds a PC by the code it shows, keeps its offer while its ID is compared, and adds it once that ID is confirmed" uses two isolated servers (mkdtemp state, port 0) and a local Bun relay. B mints a code, and A checks a non-code (400), a code no PC holds (404), the real code (a ticket, the ID and the name, with no pairing code in the answer), the spent code (404),foundset to B's public ID instead of the ticket (400), the ticket (201, connected), and the same ticket again (400). On origin/main's server it fails at its first request (404). With the change, all 4 tests in the file pass.src/components/AddRelayPc.test.tsx: a code goes to/relay/codeand leaves the field; the ID shows; It matches posts{ found }; atyped_code_wronganswer shows the code screen's sentence; a link still posts{ link }in one step.bun test src/lib/i18n.test.ts src/components/conventions.test.ts src/lib/relay src/components/RelayShell.test.tsx shared/relay-pair-code.test.ts server/conventions.test.ts: pass.bun run typecheck: pass.bun run check fastat f8dc4a8 (origin/main merged in), on old-desktop through the heavy runner: workflow syntax, generated types/themes, typecheck, build and unit tests ok (11917 pass, 0 fail, 46 skip).bun run check full, browser/e2e, native Windows (CI runs them). The changelog fragment of feat(machines): add a PC through the relay, without SSH #2829 (relay-remote-pcs.md, unreleased) is extended rather than adding another.Not in this PR