feat(network): implement Phase 6 LAN discovery and session signaling

Add mDNS/DNS-SD discovery and JSON session negotiation so two peers on
a LAN connect without hard-coded addresses.

- Discovery (Avahi threaded-poll client): the receiver announces
  _screencast._tcp with its signaling port; senders browse and resolve
  peers. Strict lock ordering (poll lock before state mutex) keeps the
  callbacks deadlock-free; name collisions rename via
  avahi_alternative_service_name.
- Signaling: one JSON object per newline-terminated TCP line. The
  receiver hosts a server (port 5005) and answers session offers with
  its RTP port; senders connect, offer, and stream to the negotiated
  endpoint. WebSocket was deferred: no WS library is installed, the
  skill permits plain TCP, and the wire format is transport-agnostic.
- Dual-stack transports: this machine resolves its own services over
  IPv6, so getaddrinfo now runs AF_UNSPEC and listeners bind IPv6 with
  IPV6_V6ONLY=0 (IPv4 fallback), covering UDP and TCP alike. The
  signaling client shutdown now uses shutdown() so a reader blocked in
  recv() cannot hang the join (a plain close() does not wake it).
- CLI: --discover lists receivers (deduped to one entry per host);
  --send auto-disovers when exactly one receiver is found; --peer
  targets a receiver directly; --signaling-port overrides the default.

Validation: meson test 5/5 (new signaling round-trip test), valgrind
clean. End-to-end over loopback: --discover finds the announced
receiver, a probe negotiated a session and streamed 60 frames over
both IPv4 and IPv6, and the receiver reported stream started. mDNS
resolution was verified against avahi-browse as an independent
reference.
This commit is contained in:
2026-09-07 12:16:34 +02:00
parent dcbcde6410
commit 7be8d59d07
17 changed files with 1395 additions and 66 deletions
+26 -2
View File
@@ -1,10 +1,34 @@
# Project Memory — screen_cast
Last updated: Phase 5 implemented and automated tests green; manual windowed
loopback validation pending. See bottom for the run commands.
Last updated: Phase 6 (discovery + signaling) complete and validated over
loopback; current phase is Phase 7.
## Project state
- **Phase 6 done**: Avahi mDNS discovery (`_screencast._tcp` — receiver
announces its signaling port via a threaded-poll Avahi client; senders
browse+resolve) plus JSON session signaling (offer/answer) over TCP with
a signaling server on the receiver (port 5005). `--send` auto-discovers
when exactly one receiver is found; `--discover` lists receivers;
`--peer` targets a receiver directly. `meson test` 5/5, valgrind clean.
- **Signaling is newline-delimited JSON over TCP**, not WebSocket: no WS
library was installed and the rtp-networking skill permits plain TCP.
The wire format (one JSON object per line: offer/answer with session id,
codec, rtp port) is transport-agnostic; Phase 7 adds the WS dependency if
needed.
- **Dual-stack everywhere**: this machine resolves its own services over
IPv6 (ULA + link-local), so the UDP transport, signaling client, and both
listeners now support both families (IPv6 sockets with IPV6_V6ONLY=0 for
dual-stack listening; AF_UNSPEC getaddrinfo for peers). Validated over
both 127.0.0.1 and ::1.
- **Discovery dedupe**: one entry per (service_name, signaling_port) — a
host with many interfaces otherwise registers dozens of address variants.
- **mDNS operational lesson (hit during validation)**: `kill -9` on a
process holding an avahi registration leaves stale daemon records; the
service then browses but never resolves (timeout for every peer) until
records expire (~75 min). `systemctl restart avahi-daemon` clears it.
Recorded in RUNBOOK; always stop with SIGTERM.
- **Phase 5 (local UDP sender→receiver loopback) is implemented**:
- `UdpRtpTransport` (src/network/udp_transport.cpp): raw POSIX sockets,
AF_INET, IPv4 via getaddrinfo; port 0 skips binding (sender side); stop()