mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-26 03:26:26 -08:00
In kernel mode, each changed peer (Engine.SyncDevicePeer, called for each peer a netmap delta changes) triggered a full sync, walking every peer through magicsock and the peer config source: O(N) per change, so O(N^2) for a netmap of N changes in a big tailnet. Now syncPeer syncs just that peer, adding, updating or removing it as its magicsock path and config say. Full syncs remain for startup, a new private key, and a new config source. magicsock's kernel path hook now also fires when it adds or removes a peer, so a peer magicsock learns of after its SyncDevicePeer still gets synced. A peer that rotates its node key arrives as the old key's removal and the new key's addition, in either order, perhaps in separate syncs, or in a full sync. Both now become one atomic rename in the kernel (tswg.PeerConfig.NewPublicKey), matched by the peer's Tailscale IP: by a map of the pushed peers' addresses, and LocalBackend's peer by IP lookup (now passed to the kernel data plane) for the other order. TestTSWGTailscaledKeyRotation rotates a peer's key and checks that the other node's kernel always has one peer for it, renamed, and that the tunnel works. TestLeanScale (with the agent's POST /scale and TSWG_LAB_MEM) measures the module with up to 50,000 peers. Updates #426 Signed-off-by: Brad Fitzpatrick <[email protected]> Change-Id: I905618034ec7bd84f1c6b14e898507c4139f2684