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

Method PeerIndexByNodeID

types/netmap/netmap.go:238–249  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

236//
237// It assumes nm.Peers is sorted by Node.ID.
238func (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.

Callers 1

TestPeerIndexByNodeIDFunction · 0.95

Calls 2

CompareMethod · 0.45
IDMethod · 0.45

Tested by 1

TestPeerIndexByNodeIDFunction · 0.76