mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-25 18:51:01 +00:00
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>
This commit is contained in:
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
|
// ep.publicKey, and updates indexes. m must already have a
|
||||||
// tailcfg.Node for ep.publicKey.
|
// tailcfg.Node for ep.publicKey.
|
||||||
func (m *peerMap) upsertEndpoint(ep *endpoint, oldDiscoKey key.DiscoPublic) {
|
func (m *peerMap) upsertEndpoint(ep *endpoint, oldDiscoKey key.DiscoPublic) {
|
||||||
pi := m.byNodeKey[ep.publicKey]
|
if m.byNodeKey[ep.publicKey] == nil {
|
||||||
if pi == nil {
|
m.byNodeKey[ep.publicKey] = newPeerInfo(ep)
|
||||||
pi = newPeerInfo(ep)
|
}
|
||||||
m.byNodeKey[ep.publicKey] = pi
|
if oldDiscoKey != ep.discoKey {
|
||||||
} else {
|
delete(m.nodesOfDisco[oldDiscoKey], ep.publicKey)
|
||||||
if oldDiscoKey != ep.discoKey {
|
|
||||||
delete(m.nodesOfDisco[oldDiscoKey], ep.publicKey)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !ep.discoKey.IsZero() {
|
if !ep.discoKey.IsZero() {
|
||||||
set := m.nodesOfDisco[ep.discoKey]
|
set := m.nodesOfDisco[ep.discoKey]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user