mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-09 02:53:09 -05:00
Apple and Android both implement their own login orchestration, coordinating preference updates, backend startup, and interative login. This requires the clients to understand details about the backend lifecycle and has led to duplicated logic and ordering issues. Android needs to avoid setting WantRunning=true via EditPrefs before calling Start, because doing so triggers Login on the existing control client, which Start then tears down, potentially canceling an in-flight registration before an authentication URL is returned (see https://github.com/tailscale/tailscale-android/commit/83057865e13b8f116a0871a3c6d6adf46f5c3d32). Apple has similar orchestration, including separate handling for auth keys, custom control servers, and reauth. This adds a LocalBackend helper that accepts optional masked prefs and an auth key, prepares the desired startup prefs, and initiates or resumes auth. This avoids unnecessary control client resets, preserves the existing control client and auth url when the login configuration hasn't changed, and ensures WantRunning is applied as part of Start when restarting the backend. This can be used for: -first time login with a custom control url or auth key -resuming an existing interactive login without losing auth url -retrying login without unnecessarily resetting the control client -reauth without restarting the backend A followup will expose this through localapi. Updates tailscale/tailscale#18304 Signed-off-by: kari-ts <kari@tailscale.com>