peerForIP is the [wgengine.Engine.SetPeerForIPFunc] callback, mapping a tailcat IPv6 address to its node in the network map. The engine uses it to find the peer for [wgengine.Engine.Ping].
(ip netip.Addr)
| 1057 | // mapping a tailcat IPv6 address to its node in the network map. The |
| 1058 | // engine uses it to find the peer for [wgengine.Engine.Ping]. |
| 1059 | func (b *locoBackend) peerForIP(ip netip.Addr) (_ wgengine.PeerForIP, ok bool) { |
| 1060 | var zero wgengine.PeerForIP |
| 1061 | b.mu.Lock() |
| 1062 | defer b.mu.Unlock() |
| 1063 | if b.nm == nil { |
| 1064 | return zero, false |
| 1065 | } |
| 1066 | if nodeHasAddr(b.nm.SelfNode, ip) { |
| 1067 | return wgengine.PeerForIP{Node: b.nm.SelfNode, IsSelf: true}, true |
| 1068 | } |
| 1069 | for _, p := range b.nm.Peers { |
| 1070 | if nodeHasAddr(p, ip) { |
| 1071 | return wgengine.PeerForIP{Node: p}, true |
| 1072 | } |
| 1073 | } |
| 1074 | return zero, false |
| 1075 | } |
| 1076 | |
| 1077 | // onEngineStatus is the wgengine status callback. It watches for |
| 1078 | // changes to our magicsock UDP endpoints (learned via STUN and from |
nothing calls this directly
no test coverage detected