From dc9a2909acb442a0ce16caec12d364791fa1920c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 18 Oct 2021 15:31:08 -0700 Subject: [PATCH] wgengine/magicsock: remove peerMap.byDiscoKey map No longer used. Updates #3088 Change-Id: I0ced3f87baa4053d3838d3c4a828ed0293923825 Signed-off-by: Brad Fitzpatrick (cherry picked from commit c30fa5903d2e85add7e7fa4af61a85146baaa081) --- wgengine/magicsock/magicsock.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 5a0fb5acd..3cc6c8ffa 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -92,9 +92,8 @@ func newPeerInfo(ep *endpoint) *peerInfo { // // Doesn't do any locking, all access must be done with Conn.mu held. type peerMap struct { - byDiscoKey map[tailcfg.DiscoKey]*peerInfo - byNodeKey map[tailcfg.NodeKey]*peerInfo - byIPPort map[netaddr.IPPort]*peerInfo + byNodeKey map[tailcfg.NodeKey]*peerInfo + byIPPort map[netaddr.IPPort]*peerInfo // nodesOfDisco are contains the set of nodes that are using a // DiscoKey. Usually those sets will be just one node. @@ -103,7 +102,6 @@ type peerMap struct { func newPeerMap() peerMap { return peerMap{ - byDiscoKey: map[tailcfg.DiscoKey]*peerInfo{}, byNodeKey: map[tailcfg.NodeKey]*peerInfo{}, byIPPort: map[netaddr.IPPort]*peerInfo{}, nodesOfDisco: map[tailcfg.DiscoKey]map[tailcfg.NodeKey]bool{}, @@ -118,8 +116,7 @@ func (m *peerMap) nodeCount() int { // anyEndpointForDiscoKey reports whether there exists any // peers in the netmap with dk as their DiscoKey. func (m *peerMap) anyEndpointForDiscoKey(dk tailcfg.DiscoKey) bool { - _, ok := m.byDiscoKey[dk] - return ok + return len(m.nodesOfDisco[dk]) > 0 } // endpointForNodeKey returns the endpoint for nk, or nil if @@ -179,12 +176,10 @@ func (m *peerMap) upsertEndpoint(ep *endpoint) { old := pi.ep pi.ep = ep if old.discoKey != ep.discoKey { - delete(m.byDiscoKey, old.discoKey) delete(m.nodesOfDisco[old.discoKey], ep.publicKey) } } if !ep.discoKey.IsZero() { - m.byDiscoKey[ep.discoKey] = pi set := m.nodesOfDisco[ep.discoKey] if set == nil { set = map[tailcfg.NodeKey]bool{} @@ -219,7 +214,6 @@ func (m *peerMap) deleteEndpoint(ep *endpoint) { } ep.stopAndReset() pi := m.byNodeKey[ep.publicKey] - delete(m.byDiscoKey, ep.discoKey) delete(m.nodesOfDisco[ep.discoKey], ep.publicKey) delete(m.byNodeKey, ep.publicKey) if pi == nil {