wgengine/magicsock: remove peerMap.byDiscoKey map

No longer used.

Updates #3088

Change-Id: I0ced3f87baa4053d3838d3c4a828ed0293923825
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/3139/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 3552d86525
commit c30fa5903d

@ -92,9 +92,8 @@ func newPeerInfo(ep *endpoint) *peerInfo {
// //
// Doesn't do any locking, all access must be done with Conn.mu held. // Doesn't do any locking, all access must be done with Conn.mu held.
type peerMap struct { type peerMap struct {
byDiscoKey map[tailcfg.DiscoKey]*peerInfo byNodeKey map[tailcfg.NodeKey]*peerInfo
byNodeKey map[tailcfg.NodeKey]*peerInfo byIPPort map[netaddr.IPPort]*peerInfo
byIPPort map[netaddr.IPPort]*peerInfo
// nodesOfDisco are contains the set of nodes that are using a // nodesOfDisco are contains the set of nodes that are using a
// DiscoKey. Usually those sets will be just one node. // DiscoKey. Usually those sets will be just one node.
@ -103,7 +102,6 @@ type peerMap struct {
func newPeerMap() peerMap { func newPeerMap() peerMap {
return peerMap{ return peerMap{
byDiscoKey: map[tailcfg.DiscoKey]*peerInfo{},
byNodeKey: map[tailcfg.NodeKey]*peerInfo{}, byNodeKey: map[tailcfg.NodeKey]*peerInfo{},
byIPPort: map[netaddr.IPPort]*peerInfo{}, byIPPort: map[netaddr.IPPort]*peerInfo{},
nodesOfDisco: map[tailcfg.DiscoKey]map[tailcfg.NodeKey]bool{}, nodesOfDisco: map[tailcfg.DiscoKey]map[tailcfg.NodeKey]bool{},
@ -118,8 +116,7 @@ func (m *peerMap) nodeCount() int {
// anyEndpointForDiscoKey reports whether there exists any // anyEndpointForDiscoKey reports whether there exists any
// peers in the netmap with dk as their DiscoKey. // peers in the netmap with dk as their DiscoKey.
func (m *peerMap) anyEndpointForDiscoKey(dk tailcfg.DiscoKey) bool { func (m *peerMap) anyEndpointForDiscoKey(dk tailcfg.DiscoKey) bool {
_, ok := m.byDiscoKey[dk] return len(m.nodesOfDisco[dk]) > 0
return ok
} }
// endpointForNodeKey returns the endpoint for nk, or nil if // endpointForNodeKey returns the endpoint for nk, or nil if
@ -179,12 +176,10 @@ func (m *peerMap) upsertEndpoint(ep *endpoint) {
old := pi.ep old := pi.ep
pi.ep = ep pi.ep = ep
if old.discoKey != ep.discoKey { if old.discoKey != ep.discoKey {
delete(m.byDiscoKey, old.discoKey)
delete(m.nodesOfDisco[old.discoKey], ep.publicKey) delete(m.nodesOfDisco[old.discoKey], ep.publicKey)
} }
} }
if !ep.discoKey.IsZero() { if !ep.discoKey.IsZero() {
m.byDiscoKey[ep.discoKey] = pi
set := m.nodesOfDisco[ep.discoKey] set := m.nodesOfDisco[ep.discoKey]
if set == nil { if set == nil {
set = map[tailcfg.NodeKey]bool{} set = map[tailcfg.NodeKey]bool{}
@ -219,7 +214,6 @@ func (m *peerMap) deleteEndpoint(ep *endpoint) {
} }
ep.stopAndReset() ep.stopAndReset()
pi := m.byNodeKey[ep.publicKey] pi := m.byNodeKey[ep.publicKey]
delete(m.byDiscoKey, ep.discoKey)
delete(m.nodesOfDisco[ep.discoKey], ep.publicKey) delete(m.nodesOfDisco[ep.discoKey], ep.publicKey)
delete(m.byNodeKey, ep.publicKey) delete(m.byNodeKey, ep.publicKey)
if pi == nil { if pi == nil {

Loading…
Cancel
Save