Add accept-time node identity backed by a netmap-mirror cache#50
Merged
Conversation
Inbound TCP/TLS accepts and Http.bind requests now carry the calling node's identity (conn.identity / request.identity), resolved at accept time without a per-accept LocalAPI round-trip. Three connected changes: - Fix LocalAPI loopback latency. local.Client.DoLocalRequest forks `lsof` per request (safesocket.readMacosSameUserProof) hunting a macOS GUI credential file an embedded tsnet process never has. Setting OmitAuth skips it, cutting whois() from ~40ms to ~0.3ms end to end (Dart-facing). A gated diagnostic test (loopback_latency_diag_test.go) localizes the cost and asserts the direction of the win without pinning numbers. - Add a netmap-mirror identity cache (identity_cache.go). The state watcher rebuilds an addr->identity index on every netmap tick; the accept path reads it in ~79ns/0-alloc instead of a live WhoIs. Cold or post-StopWatch lookups fall back to the authoritative loopback WhoIs, so identity is never stale: at worst one netmap behind, never an IP misattribution. Teardown is race-free: the watcher applies each rebuild under watchMu only while its context is live, and stopLocked routes through StopWatch, so an in-flight tick can't re-warm a torn-down cache. WhoIs and the cache share one mapper (nodeIdentityFromView) so they cannot drift. - Attach identity to inbound HTTP requests (Http.bind) via the same cache-backed lookup, exposed as TailscaleHttpRequest.identity -- the in-process twin of serve.forward's Tailscale-User-Login headers. Identity is correctly absent on outbound tcp.dial, public Funnel callers, and UDP. The user-facing whois() stays on the live (now-fast) loopback. A warm-cache miss is authoritative (no fallback) to keep the accept path O(1) and non-DoS-able; *nodeIdentity values are immutable once built since they are aliased across cache keys and read by concurrent accepts. Tests: Go unit (cache builder + lookup semantics + WhoIs mapping), Go bench (loopback vs cached vs map floor), race detector over the watcher and teardown paths, and e2e over Headscale for both inbound TCP and inbound HTTP identity. Full e2e suite green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
b0502f4 to
aeae68b
Compare
Accept-time node identity (TCP/TLS conn.identity, Http.bind request.identity) plus the LocalAPI loopback latency fix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Inbound TCP/TLS accepts and
Http.bindrequests now carry the calling node's identity —conn.identity/request.identity— resolved at accept time without a per-accept LocalAPI round-trip.Three connected changes
1. Fix LocalAPI loopback latency (~350×).
local.Client.DoLocalRequestforkslsofper request (safesocket.readMacosSameUserProof) hunting a macOS GUI credential file that an embedded tsnet process never has. SettingOmitAuthskips it, cuttingwhois()from ~40 ms to ~230 µs. This was slowing every LocalAPI call (status/prefs/ping), not just whois. A gated diagnostic test (loopback_latency_diag_test.go) localizes the cost and asserts the direction of the win without pinning machine-specific numbers.2. Netmap-mirror identity cache. The state watcher rebuilds an
addr → identityindex on every netmap tick; the accept path reads it in ~79 ns / 0 allocs instead of a live WhoIs.Safety: cold or post-
StopWatchlookups fall back to the authoritative loopback WhoIs, so identity is never stale — at worst one netmap behind, never an IP misattribution. WhoIs and the cache share one mapper (nodeIdentityFromView) so they can't drift.3. HTTP request identity.
TailscaleHttpRequest.identity, attached via the same cache-backed lookup — the in-process twin ofserve.forward'sTailscale-User-Loginheaders.Identity is correctly absent on outbound
tcp.dial(caller chose the target), public Funnel callers (no tailnet node), and UDP (connectionless). The user-facingwhois()stays on the live — now fast — loopback.Testing
dart analyzeclean;go vetclean.🤖 Generated with Claude Code