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.
@@ -169,15 +169,12 @@ 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 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]
if set == nil {
