PeerIndexByNodeID returns the index of the peer with the given nodeID in nm.Peers, or -1 if nm is nil or not found. It assumes nm.Peers is sorted by Node.ID.
(nodeID tailcfg.NodeID)
| 236 | // |
| 237 | // It assumes nm.Peers is sorted by Node.ID. |
| 238 | func (nm *NetworkMap) PeerIndexByNodeID(nodeID tailcfg.NodeID) int { |
| 239 | if nm == nil { |
| 240 | return -1 |
| 241 | } |
| 242 | idx, ok := sort.Find(len(nm.Peers), func(i int) int { |
| 243 | return cmp.Compare(nodeID, nm.Peers[i].ID()) |
| 244 | }) |
| 245 | if !ok { |
| 246 | return -1 |
| 247 | } |
| 248 | return idx |
| 249 | } |
| 250 | |
| 251 | // MagicDNSSuffix returns the domain's MagicDNS suffix (even if MagicDNS isn't |
| 252 | // necessarily in use) of the provided Node.Name value. |