From f054e164517fd74ffbdd5610cb5d86ee2056205a Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 15 Oct 2021 22:19:27 -0700 Subject: [PATCH] wgengine/magicsock: delete peerMap.endpointForDiscoKey, remove remaining caller The one remaining caller of peerMap.endpointForDiscoKey was making the improper assumption that there's exactly 1 node with a given DiscoKey in the network. That was the cause of #3088. Now that all the other callers have been updated to not use endpointForDiscoKey, there's no need to try to keep maintaining that prone-to-misuse index. Updates #3088 Signed-off-by: Brad Fitzpatrick (cherry picked from commit 695df497ba6ac9a231cababaf6f4a31baa4cccf6) --- wgengine/magicsock/magicsock.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index baef28a41..8c4db1733 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -116,18 +116,6 @@ func (m *peerMap) anyEndpointForDiscoKey(dk tailcfg.DiscoKey) bool { return ok } -// endpointForDiscoKey returns the endpoint for dk, or nil -// if dk is not known to us. -func (m *peerMap) endpointForDiscoKey(dk tailcfg.DiscoKey) (ep *endpoint, ok bool) { - if dk.IsZero() { - return nil, false - } - if info, ok := m.byDiscoKey[dk]; ok && info.ep != nil { - return info.ep, true - } - return nil, false -} - // endpointForNodeKey returns the endpoint for nk, or nil if // nk is not known to us. func (m *peerMap) endpointForNodeKey(nk tailcfg.NodeKey) (ep *endpoint, ok bool) { @@ -2160,23 +2148,10 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) { return } - // For disco-capable peers, update the disco endpoint's state and - // check if the disco key migrated to a new node key. numNoDisco := 0 for _, n := range nm.Peers { if n.DiscoKey.IsZero() { numNoDisco++ - continue - } - if ep, ok := c.peerMap.endpointForDiscoKey(n.DiscoKey); ok && ep.publicKey == n.Key { - ep.updateFromNode(n) - c.peerMap.upsertDiscoEndpoint(ep) // maybe update discokey mappings in peerMap - } else if ep != nil { - // Endpoint no longer belongs to the same node. We'll - // create the new endpoint below. - c.logf("magicsock: disco key %v changed from node key %v to %v", n.DiscoKey, ep.publicKey.ShortString(), n.Key.ShortString()) - ep.stopAndReset() - c.peerMap.deleteDiscoEndpoint(ep) } }