Skip to content

Peer socket over the LAN while Tailscale is down (server 0.3.34, client 0.1.35) - #90

Merged
NickMarcha merged 1 commit into
mainfrom
lan-peer-socket
Nov 23, 2026
Merged

NickMarcha merged 1 commit into
mainfrom
lan-peer-socket

Conversation

@NickMarcha

Copy link
Copy Markdown
Owner

During the 2026-11-21 outage the audio moved to the LAN (bragi#81), but the tray apps' peer socket stayed down. sage switched to one display, the hub never heard about it, and the top right of the desk couldn't be reached until I edited server.conf by hand.

Hub (0.3.34)

  • app/lan_peer.py: with BRAGI_LAN_PEER_PORT set (the packaged unit sets 8443), a second uvicorn server listens on the LAN. It serves only /ws/peer/<name>, over TLS with a self-signed certificate made on first start (openssl, EC P-256), and only with that name's token, HMAC-SHA256(secret, name). Everything else gets a 404, and a socket without the right token is closed (403).
  • The peer socket has no login of its own (Tailscale was the gate), so both checks are needed: the certificate pin keeps a stranger on the LAN from posing as the hub, and the token keeps one from posing as a computer.
  • The hub message gives each tray its token and the certificate's SHA-256, over Tailscale.
  • Runs in-process with signal handling left to the main server; it stopped within a second on SIGTERM in a local run.

Client (0.1.35)

  • Remembers BRAGI_HUB_LAN_PORT, _CERT and _TOKEN.
  • After two failed tries over Tailscale it connects to wss://<hub LAN IP>:8443/ws/peer/<name>, pinning the certificate and sending X-Bragi-Lan-Token.
  • While on the LAN it asks the Tailscale address over HTTPS every 30 s, and drops the LAN connection once that answers.
  • Messages over the LAN don't count as Tailscale being back for the audio fallback, and the hub message there is ignored, so it can't rewrite the audio or Deskflow address.

Tests

  • pytest 498 passed under Linux, with new tests for the token check, the refused paths and the hub message.
  • dotnet test 139 passed, with new tests for parsing, remembering and the pin.
  • A local uvicorn run: the right token gets the normal messages, a wrong one gets 403.

Not yet tried with Tailscale actually down; I'll do that on sagehub after the release.

🤖 Generated with Claude Code

During the 2026-11-21 outage the audio moved to the LAN, but the peer
socket stayed down: sage switched to one display, the hub never heard,
and the top right of the desk couldn't be reached.

Hub (0.3.34): with BRAGI_LAN_PEER_PORT set (the packaged unit sets 8443)
a second uvicorn server on the LAN serves only /ws/peer/<name>, over TLS
with a self-signed certificate made on first start, and only with that
name's token, HMAC(secret, name). The "hub" message gives each tray its
token and the certificate's SHA-256 over Tailscale. Everything else on
that port is refused.

Client (0.1.35): remembers those as BRAGI_HUB_LAN_PORT/_CERT/_TOKEN.
After two failed tries over Tailscale it connects to the LAN socket,
pinning the certificate and sending the token. While there it asks the
Tailscale address every 30 s and moves back once it answers. Messages
over the LAN don't count as Tailscale being back for the audio fallback,
and the hub message there doesn't rewrite the audio or Deskflow address.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@NickMarcha
NickMarcha merged commit 3aea6f1 into main Nov 23, 2026
@NickMarcha
NickMarcha deleted the lan-peer-socket branch November 23, 2026 03:13
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.

1 participant