control/controlclient: avoid calls to ms.netmap() (#19281)

Instead of generating the full netmap, just fetch the peers out the the
existing peers map.

The extra usage was introduced with netmap caching, but there is no need
to call the netmap to get this information, rather the existing peermap
can be used.

Updates #12639

Signed-off-by: Claus Lensbøl <claus@tailscale.com>
main
Claus Lensbøl 1 week ago committed by GitHub
parent 5341b26328
commit 9e68841939
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      control/controlclient/map.go
  2. 7
      control/controlclient/map_test.go

@ -408,10 +408,9 @@ type updateStats struct {
// removeUnwantedDiscoUpdates goes over the patchified updates and reject items
// where the node is offline and has last been seen before the recorded last seen.
func (ms *mapSession) removeUnwantedDiscoUpdates(resp *tailcfg.MapResponse) {
existingMap := ms.netmap()
if existingMap == nil {
return
}
ms.peersMu.RLock()
defer ms.peersMu.RUnlock()
acceptedDiscoUpdates := resp.PeersChangedPatch[:0]
for _, change := range resp.PeersChangedPatch {
@ -430,14 +429,13 @@ func (ms *mapSession) removeUnwantedDiscoUpdates(resp *tailcfg.MapResponse) {
continue
}
peerIdx := existingMap.PeerIndexByNodeID(change.NodeID)
existingNode, ok := ms.peers[change.NodeID]
// Accept if:
// - Cannot find the peer, don't have enough data
if peerIdx < 0 {
if !ok {
acceptedDiscoUpdates = append(acceptedDiscoUpdates, change)
continue
}
existingNode := existingMap.Peers[peerIdx]
// Accept if:
// - lastSeen moved forward in time.
@ -456,13 +454,12 @@ func (ms *mapSession) removeUnwantedDiscoUpdates(resp *tailcfg.MapResponse) {
// local netmap has a newer key learned via TSMP, overwrite the update with the
// key from TSMP.
func (ms *mapSession) removeUnwantedDiscoUpdatesFromFullNetmapUpdate(resp *tailcfg.MapResponse) {
ms.peersMu.RLock()
defer ms.peersMu.RUnlock()
if len(resp.Peers) == 0 {
return
}
existingMap := ms.netmap()
if existingMap == nil {
return
}
for _, peer := range resp.Peers {
if peer.DiscoKey.IsZero() {
continue
@ -470,14 +467,13 @@ func (ms *mapSession) removeUnwantedDiscoUpdatesFromFullNetmapUpdate(resp *tailc
// Accept if:
// - peer is new
peerIdx := existingMap.PeerIndexByNodeID(peer.ID)
if peerIdx < 0 {
existingNode, ok := ms.peers[peer.ID]
if !ok {
continue
}
// Accept if:
// - disco key has not changed
existingNode := existingMap.Peers[peerIdx]
if existingNode.DiscoKey() == peer.DiscoKey {
continue
}

@ -696,13 +696,12 @@ func TestUpdateDiscoForNode(t *testing.T) {
ms.updateDiscoForNode(node.ID, node.Key, newKey.Public(), tt.updateLastSeen, tt.updateOnline)
<-nu.done
nm := ms.netmap()
peerIdx := nm.PeerIndexByNodeID(node.ID)
if peerIdx == -1 {
peer, ok := ms.peers[node.ID]
if !ok {
t.Fatal("node not found")
}
updated := nm.Peers[peerIdx].DiscoKey().Compare(newKey.Public()) == 0
updated := peer.DiscoKey().Compare(newKey.Public()) == 0
if updated != tt.wantUpdate {
t.Fatalf("Disco key update: %t, wanted update: %t", updated, tt.wantUpdate)
}

Loading…
Cancel
Save