From e7eb46bced277c76bfd3c64fe6b724cae0de25b7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 18 Oct 2021 13:05:12 -0700 Subject: [PATCH] wgengine/magicsock: add an explicit else branch to peerMap update. Clarifies that the replace+delete of peerinfo data is only when peerInfo already exists. Signed-off-by: David Anderson --- disco/disco.go | 1 - wgengine/magicsock/magicsock.go | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/disco/disco.go b/disco/disco.go index ffd69e581..e7a629492 100644 --- a/disco/disco.go +++ b/disco/disco.go @@ -112,7 +112,6 @@ type Ping struct { // NodeKey is allegedly the ping sender's wireguard public key. // Old clients (~1.16.0 and earlier) don't send this field. - // It shouldn't be trusted by itself, but can be combined with // netmap data to reduce the discokey:nodekey relation from 1:N to // 1:1. diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 4230d8723..5ee2004b4 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -172,12 +172,13 @@ func (m *peerMap) upsertEndpoint(ep *endpoint) { if pi == nil { pi = newPeerInfo(ep) m.byNodeKey[ep.publicKey] = pi - } - old := pi.ep - pi.ep = ep - if old != nil && old.discoKey != ep.discoKey { - delete(m.byDiscoKey, old.discoKey) - delete(m.nodesOfDisco[old.discoKey], ep.publicKey) + } else { + old := pi.ep + pi.ep = ep + if old != nil && 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