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

Method PeerByKey

wgengine/userspace.go:1086–1105  ·  view source on GitHub ↗
(pubKey key.NodePublic)

Source from the content-addressed store, hash-verified

1084var ErrEngineClosing = errors.New("engine closing; no status")
1085
1086func (e *userspaceEngine) PeerByKey(pubKey key.NodePublic) (_ wgint.Peer, ok bool) {
1087 e.wgLock.Lock()
1088 dev := e.wgdev
1089 e.wgLock.Unlock()
1090
1091 if dev == nil {
1092 return wgint.Peer{}, false
1093 }
1094 // Use LookupActivePeer (not LookupPeer) to avoid triggering on-demand
1095 // peer creation via PeerLookupFunc. PeerByKey is called from status
1096 // polling paths (getStatus, getPeerStatusLite) which iterate every peer
1097 // in the netmap; using LookupPeer would lazily create a wireguard-go
1098 // peer for every single netmap peer on each status poll, leaking
1099 // memory via per-peer queues and goroutines.
1100 peer, ok := dev.LookupActivePeer(pubKey.Raw32())
1101 if !ok {
1102 return wgint.Peer{}, false
1103 }
1104 return wgint.PeerOf(peer), true
1105}
1106
1107func (e *userspaceEngine) getPeerStatusLite(pk key.NodePublic) (status ipnstate.PeerStatusLite, ok bool) {
1108 peer, ok := e.PeerByKey(pk)

Callers 1

getPeerStatusLiteMethod · 0.95

Calls 4

PeerOfFunction · 0.92
LockMethod · 0.65
UnlockMethod · 0.65
Raw32Method · 0.45

Tested by

no test coverage detected