Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ADR-0004: Discovery: mDNS _tether._tcp, UDP beacon, manual address, QR

  • Status: accepted
  • Date: 2026-11-08
  • Deciders: maintainer, after the November 2026 research round
  • Tags: protocol, android, linux, networking

Context

Before pairing, a phone and a desktop on the same network must find each other with zero configuration. After pairing, they must re-find each other every time the phone’s IP changes, the desktop reboots or Wi-Fi flaps, without user action.

Home and office networks are hostile to every single discovery mechanism:

  • mDNS/DNS-SD is the standard (Bonjour, Avahi, Android NsdManager) and is what printers and Chromecasts use, so routers mostly let it through. But many access points drop or throttle multicast in power-save mode, “AP isolation” and guest networks block it entirely, and Android’s NsdManager has a history of flaky resolution on some OEM Wi-Fi drivers.
  • UDP broadcast (KDE Connect’s only mechanism) is simple and works on networks that mangle multicast, but it does not cross subnets either and Android drops broadcast/multicast frames when the screen is off unless the app holds a multicast lock.
  • Manual addresses always work when the user knows the IP, and they are the only option on networks that block both of the above or when the two devices are on different subnets (VLANs, Tailscale, a relay-less VPN).
  • A QR code can carry the desktop’s addresses as a side effect of pairing (ADR-0003), covering the first-contact case even when discovery is blocked.

On Linux, avahi-daemon already owns UDP 5353 on every Ubuntu/Mint/Debian desktop; a second mDNS responder in our process would conflict with it and double-answer queries. Avahi exposes publish/browse/resolve over D-Bus.

Both peers listen on TCP 7360 and either may dial (ADR-0002), because the phone may be unreachable for inbound connections while dozing and the desktop may be asleep when the phone comes home. Two simultaneous dials must therefore collapse to one session deterministically.

Decision

  • mDNS/DNS-SD service type _tether._tcp.local, port 7360, TXT records id=<device id>, name=<display name>, kind=desktop|phone|tablet, pv=<protocol version>.
    • Linux: publish and browse through Avahi’s D-Bus API (org.freedesktop.Avahi.Server, EntryGroup, ServiceBrowser, ServiceResolver) via zbus proxies. No in-process mDNS stack. avahi-daemon is a hard package dependency.
    • Android: NsdManager registration and discovery (API 34 registerServiceInfoCallback for TXT/address resolution).
  • UDP beacon fallback: protobuf Beacon{device_id, name, kind, tcp_port, protocol_version} sent to 255.255.255.255:7360 and the subnet broadcast every 5 s while discoverable. Desktop: always while running. Phone: while the app is in the foreground or for 60 s after the screen turns on, holding a WifiManager.MulticastLock only during that window (CHANGE_WIFI_MULTICAST_STATE). Beacons are hints: receivers dial the sender’s TCP port; nothing is trusted from the datagram itself.
  • Manual address: host[:port] entered on either side; stored per device and dialled on every reconnect attempt alongside discovered addresses.
  • QR carries the desktop’s current addresses (a= parameters) so a phone that scanned it can connect without any discovery.
  • Reconnect policy: each side keeps a per-peer address list (discovered, beacon, manual, last-connected) and dials them with exponential backoff 1 s to 60 s; a peer is Reachable if seen by any discovery mechanism in the last 30 s.
  • Dedupe rule: if two connections to the same peer exist, keep the one dialled by the device with the lexicographically smaller device id; the other side closes its dialled connection quietly after seeing Hello. Both sides implement the rule identically; there is no negotiation.

Consequences

Positive

  • At least one mechanism works on nearly every network we have seen; the user is guided to the manual path only when all automatic ones fail (see docs/how-to/troubleshoot.md).
  • Using Avahi makes Tether visible to avahi-browse, which doubles as a support tool, and avoids fighting the system responder for port 5353.
  • The beacon shares port 7360 with TCP, so the firewall profile is still one entry (7360/tcp|7360/udp).

Negative / risks

  • Hard dependency on avahi-daemon on Linux. Acceptable on the target distros (installed by default); Flatpak (ADR-0008) will need --talk-name=org.freedesktop.Avahi.
  • NsdManager reliability varies by OEM. Mitigation: the beacon and manual paths; and the desktop advertises aggressively (always-on beacon) so the phone usually finds it.
  • Multicast locks cost battery; we hold them only in short windows and never in the background.
  • Beacons and mDNS leak the device name and id to the LAN. Accepted: the id is a public key hash, the name is user-chosen, and Discoverable can be turned off (paired devices still reconnect via remembered addresses).
  • The dedupe rule must be bit-identical on both sides or sessions flap. Mitigation: documented in protocol.md, exercised by the in-process handshake test with both dial orders.

Alternatives considered

  • mDNS only: fails on too many real networks and on Android power-save paths.
  • UDP broadcast only (KDE Connect): works on more networks than mDNS alone but is invisible to standard tooling and equally dead across subnets; also blocked when Android screen is off. Kept as fallback, not as primary.
  • Own Rust mDNS responder (mdns-sd, libmdns): conflicts with Avahi on 5353 and would need its own interface tracking. Rejected on Linux; revisit for non-Avahi systems.
  • Bluetooth LE advertising: works without Wi-Fi and is how Phone Link bootstraps Instant Hotspot; requires BT on both sides and BlueZ LE advertising code. Deferred to M3/M5 where BlueZ is already in play.
  • Cloud rendezvous: solves cross-network discovery but is exactly what the relay (ADR-0010) will do, self-hosted. Not for M1.
  • Only the desktop listens (phone always dials): simpler dedupe, but the desktop could not wake a sleeping phone’s connection and the roles would be asymmetric for the relay. Rejected.