wgengine/magicsock: don't check always-non-nil endpoint for nil-ness

Continuation of 2aa5df7ac1, remove nil
check because it can never be nil. (It previously was able to be nil.)

Change-Id: I59cd9ad611dbdcbfba680ed9b22e841b00c9d5e6
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-10-18 14:27:39 -07:00 committed by Brad Fitzpatrick
parent e7eb46bced
commit 11fdb14c53

View File

@ -128,7 +128,7 @@ func (m *peerMap) endpointForNodeKey(nk tailcfg.NodeKey) (ep *endpoint, ok bool)
if nk.IsZero() { if nk.IsZero() {
return nil, false return nil, false
} }
if info, ok := m.byNodeKey[nk]; ok && info.ep != nil { if info, ok := m.byNodeKey[nk]; ok {
return info.ep, true return info.ep, true
} }
return nil, false return nil, false
@ -137,7 +137,7 @@ func (m *peerMap) endpointForNodeKey(nk tailcfg.NodeKey) (ep *endpoint, ok bool)
// endpointForIPPort returns the endpoint for the peer we // endpointForIPPort returns the endpoint for the peer we
// believe to be at ipp, or nil if we don't know of any such peer. // believe to be at ipp, or nil if we don't know of any such peer.
func (m *peerMap) endpointForIPPort(ipp netaddr.IPPort) (ep *endpoint, ok bool) { func (m *peerMap) endpointForIPPort(ipp netaddr.IPPort) (ep *endpoint, ok bool) {
if info, ok := m.byIPPort[ipp]; ok && info.ep != nil { if info, ok := m.byIPPort[ipp]; ok {
return info.ep, true return info.ep, true
} }
return nil, false return nil, false
@ -146,9 +146,7 @@ func (m *peerMap) endpointForIPPort(ipp netaddr.IPPort) (ep *endpoint, ok bool)
// forEachEndpoint invokes f on every endpoint in m. // forEachEndpoint invokes f on every endpoint in m.
func (m *peerMap) forEachEndpoint(f func(ep *endpoint)) { func (m *peerMap) forEachEndpoint(f func(ep *endpoint)) {
for _, pi := range m.byNodeKey { for _, pi := range m.byNodeKey {
if pi.ep != nil { f(pi.ep)
f(pi.ep)
}
} }
} }
@ -158,7 +156,7 @@ func (m *peerMap) forEachEndpointWithDiscoKey(dk tailcfg.DiscoKey, f func(ep *en
// TODO(bradfitz): once byDiscoKey is a set of endpoints, then range // TODO(bradfitz): once byDiscoKey is a set of endpoints, then range
// over that instead. // over that instead.
for _, pi := range m.byNodeKey { for _, pi := range m.byNodeKey {
if pi.ep != nil && pi.ep.discoKey == dk { if pi.ep.discoKey == dk {
f(pi.ep) f(pi.ep)
} }
} }
@ -175,7 +173,7 @@ func (m *peerMap) upsertEndpoint(ep *endpoint) {
} else { } else {
old := pi.ep old := pi.ep
pi.ep = ep pi.ep = ep
if old != nil && old.discoKey != ep.discoKey { if old.discoKey != ep.discoKey {
delete(m.byDiscoKey, old.discoKey) delete(m.byDiscoKey, old.discoKey)
delete(m.nodesOfDisco[old.discoKey], ep.publicKey) delete(m.nodesOfDisco[old.discoKey], ep.publicKey)
} }