types/netmap, all: make NetworkMap.SelfNode a tailcfg.NodeView

Updates #1909

Change-Id: I8c470cbc147129a652c1d58eac9b790691b87606
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-08-21 10:53:57 -07:00
committed by Brad Fitzpatrick
parent 699f9699ca
commit 84b94b3146
26 changed files with 90 additions and 90 deletions

View File

@@ -6,11 +6,11 @@
package logknob
import (
"slices"
"sync/atomic"
"tailscale.com/envknob"
"tailscale.com/types/logger"
"tailscale.com/types/views"
)
// TODO(andrew-d): should we have a package-global registry of logknobs? It
@@ -58,7 +58,7 @@ func (lk *LogKnob) Set(v bool) {
// about; we use this rather than a concrete type to avoid a circular
// dependency.
type NetMap interface {
SelfCapabilities() []string
SelfCapabilities() views.Slice[string]
}
// UpdateFromNetMap will enable logging if the SelfNode in the provided NetMap
@@ -68,7 +68,7 @@ func (lk *LogKnob) UpdateFromNetMap(nm NetMap) {
return
}
lk.cap.Store(slices.Contains(nm.SelfCapabilities(), lk.capName))
lk.cap.Store(views.SliceContains(nm.SelfCapabilities(), lk.capName))
}
// Do will call log with the provided format and arguments if any of the

View File

@@ -63,11 +63,11 @@ func TestLogKnob(t *testing.T) {
}
testKnob.UpdateFromNetMap(&netmap.NetworkMap{
SelfNode: &tailcfg.Node{
SelfNode: (&tailcfg.Node{
Capabilities: []string{
"https://tailscale.com/cap/testing",
},
},
}).View(),
})
if !testKnob.shouldLog() {
t.Errorf("expected shouldLog()=true")