mirror of
https://github.com/tailscale/tailscale.git
synced 2026-04-04 06:36:01 -04:00
Add a sync.Map cache on the Server that tracks destination keys not connected to this server. When a packet arrives for a cached absent destination, the payload is discarded via bufio.Reader.Discard without allocating a buffer, taking the server mutex, or looking up the client map. Cache entries expire after a configurable TTL (10s) and are invalidated in registerClient when a peer connects. Move the cache check into recvPacket so handleFrameSendPacket does not need to duplicate the frame validation and key reading logic. When the cache is hit, recvPacket returns nil contents and the caller returns early. Increase peerGoneLim from 3/sec to 50/sec per client. The not-here cache now provides per-destination rate limiting, so the per-client limiter serves only as a safety backstop against clients sending to many unique absent destinations. ``` name old ns/op new ns/op delta HandleFrameSendPacketAbsent/same_key 570 131 -77% HandleFrameSendPacketAbsent/unique_keys 559 145 -74% (0 B/op, 0 allocs/op on cache hits; was 280 B/op, 8 allocs/op) ``` Updates #38509