wgengine/magicsock: simplify peerMap.upsertEndpoint

We can do the "maybe delete" check unilaterally:
In the case of an insert, both oldDiscoKey
and ep.discoKey will be the zero value.

And since we don't use pi again, we can skip
giving it a name, which makes scoping clearer.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
pull/3328/head
Josh Bleecher Snyder 3 years ago committed by Josh Bleecher Snyder
parent 9da22dac3d
commit 773af7292b

@ -169,14 +169,11 @@ func (m *peerMap) forEachEndpointWithDiscoKey(dk key.DiscoPublic, f func(ep *end
// ep.publicKey, and updates indexes. m must already have a
// tailcfg.Node for ep.publicKey.
func (m *peerMap) upsertEndpoint(ep *endpoint, oldDiscoKey key.DiscoPublic) {
pi := m.byNodeKey[ep.publicKey]
if pi == nil {
pi = newPeerInfo(ep)
m.byNodeKey[ep.publicKey] = pi
} else {
if oldDiscoKey != ep.discoKey {
delete(m.nodesOfDisco[oldDiscoKey], ep.publicKey)
}
if m.byNodeKey[ep.publicKey] == nil {
m.byNodeKey[ep.publicKey] = newPeerInfo(ep)
}
if oldDiscoKey != ep.discoKey {
delete(m.nodesOfDisco[oldDiscoKey], ep.publicKey)
}
if !ep.discoKey.IsZero() {
set := m.nodesOfDisco[ep.discoKey]

Loading…
Cancel
Save