mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
control/controlclient: do not alias peer CapMap
Updates #cleanup Change-Id: I10fd5e04310cdd7894a3caa3045b86eb0a06b6a0 Signed-off-by: Adrian Dewhurst <adrian@tailscale.com>
This commit is contained in:
parent
067ed0bf6f
commit
2f7e7be2ea
@ -8,6 +8,7 @@
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net"
|
||||
"reflect"
|
||||
"slices"
|
||||
@ -668,14 +669,14 @@ func peerChangeDiff(was tailcfg.NodeView, n *tailcfg.Node) (_ *tailcfg.PeerChang
|
||||
if n.CapMap == nil {
|
||||
pc().CapMap = make(tailcfg.NodeCapMap)
|
||||
} else {
|
||||
pc().CapMap = n.CapMap
|
||||
pc().CapMap = maps.Clone(n.CapMap)
|
||||
}
|
||||
break
|
||||
}
|
||||
was.CapMap().Range(func(k tailcfg.NodeCapability, v views.Slice[tailcfg.RawMessage]) bool {
|
||||
nv, ok := n.CapMap[k]
|
||||
if !ok || !views.SliceEqual(v, views.SliceOf(nv)) {
|
||||
pc().CapMap = n.CapMap
|
||||
pc().CapMap = maps.Clone(n.CapMap)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
@ -865,6 +865,11 @@ func TestPeerChangeDiff(t *testing.T) {
|
||||
a: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{tailcfg.CapabilityAdmin: nil}},
|
||||
b: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{}},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, CapMap: tailcfg.NodeCapMap{}},
|
||||
}, {
|
||||
name: "patch-capmap-remove-as-nil",
|
||||
a: &tailcfg.Node{ID: 1, CapMap: tailcfg.NodeCapMap{tailcfg.CapabilityAdmin: nil}},
|
||||
b: &tailcfg.Node{ID: 1},
|
||||
want: &tailcfg.PeerChange{NodeID: 1, CapMap: tailcfg.NodeCapMap{}},
|
||||
}, {
|
||||
name: "patch-capmap-add-key-to-empty-map",
|
||||
a: &tailcfg.Node{ID: 1},
|
||||
|
Loading…
Reference in New Issue
Block a user