(pubKey key.NodePublic)
| 1084 | var ErrEngineClosing = errors.New("engine closing; no status") |
| 1085 | |
| 1086 | func (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 | |
| 1107 | func (e *userspaceEngine) getPeerStatusLite(pk key.NodePublic) (status ipnstate.PeerStatusLite, ok bool) { |
| 1108 | peer, ok := e.PeerByKey(pk) |
no test coverage detected