Просмотр исходного кода

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 <[email protected]>
David Anderson 4 лет назад
Родитель
Сommit
e7eb46bced
2 измененных файлов с 7 добавлено и 7 удалено
  1. 0 1
      disco/disco.go
  2. 7 6
      wgengine/magicsock/magicsock.go

+ 0 - 1
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.

+ 7 - 6
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