MCPcopy Index your code
hub / github.com/tailscale/tailscale / setPeer

Method setPeer

client/web/web.go:556–574  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

554var contextKeyPeer = ctxkey.New("peer-capabilities", peerCapabilities{})
555
556func (s *Server) setPeer(r *http.Request) (*http.Request, error) {
557 // TODO(tailscale/corp#16695,sonia): We also call StatusWithoutPeers and
558 // WhoIs when originally checking for a session from authorizeRequest.
559 // Would be nice if we could pipe those through to here so we don't end
560 // up having to re-call them to grab the peer capabilities.
561 status, err := s.lc.StatusWithoutPeers(r.Context())
562 if err != nil {
563 return nil, err
564 }
565 whois, err := s.lc.WhoIs(r.Context(), r.RemoteAddr)
566 if err != nil {
567 return nil, err
568 }
569 peer, err := toPeerCapabilities(status, whois)
570 if err != nil {
571 return nil, err
572 }
573 return r.WithContext(contextKeyPeer.WithValue(r.Context(), peer)), nil
574}
575
576func (s *Server) getPeer(ctx context.Context) peerCapabilities {
577 return contextKeyPeer.Value(ctx)

Callers 1

serveAPIMethod · 0.95

Calls 5

toPeerCapabilitiesFunction · 0.85
WithValueMethod · 0.80
StatusWithoutPeersMethod · 0.65
ContextMethod · 0.65
WhoIsMethod · 0.65

Tested by

no test coverage detected