Identify tailnet callers once per connection; list processes via sysctl

This commit is contained in:
Ian Gulliver
2026-10-23 11:22:16 -07:00
parent 69848a2c6e
commit 0a094aaa72
6 changed files with 58 additions and 31 deletions
+37
View File
@@ -0,0 +1,37 @@
package peer
import (
"context"
"net"
"net/http"
"sync"
"tailscale.com/client/local"
"tailscale.com/client/tailscale/apitype"
)
type key struct{}
type peer struct {
mu sync.Mutex
who *apitype.WhoIsResponse
}
func ConnContext(ctx context.Context, _ net.Conn) context.Context {
return context.WithValue(ctx, key{}, &peer{})
}
func WhoIs(r *http.Request, lc *local.Client) (*apitype.WhoIsResponse, error) {
p := r.Context().Value(key{}).(*peer)
p.mu.Lock()
defer p.mu.Unlock()
if p.who != nil {
return p.who, nil
}
who, err := lc.WhoIs(r.Context(), r.RemoteAddr)
if err != nil {
return nil, err
}
p.who = who
return who, nil
}