mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-01 17:49:02 +00:00
ipn/ipnlocal: replace log.Printf with logf (#18045)
Updates #cleanup Signed-off-by: Simon Law <sfllaw@tailscale.com>
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"math"
|
"math"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"net"
|
"net"
|
||||||
@@ -544,7 +543,7 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
|
|||||||
netMon := sys.NetMon.Get()
|
netMon := sys.NetMon.Get()
|
||||||
b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf, logID, netMon, sys.HealthTracker.Get(), sys.Bus.Get())
|
b.sockstatLogger, err = sockstatlog.NewLogger(logpolicy.LogsDir(logf), logf, logID, netMon, sys.HealthTracker.Get(), sys.Bus.Get())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error setting up sockstat logger: %v", err)
|
logf("error setting up sockstat logger: %v", err)
|
||||||
}
|
}
|
||||||
// Enable sockstats logs only on non-mobile unstable builds
|
// Enable sockstats logs only on non-mobile unstable builds
|
||||||
if version.IsUnstableBuild() && !version.IsMobile() && b.sockstatLogger != nil {
|
if version.IsUnstableBuild() && !version.IsMobile() && b.sockstatLogger != nil {
|
||||||
@@ -7259,7 +7258,12 @@ func (b *LocalBackend) refreshAllowedSuggestions() {
|
|||||||
}
|
}
|
||||||
b.allowedSuggestedExitNodesMu.Lock()
|
b.allowedSuggestedExitNodesMu.Lock()
|
||||||
defer b.allowedSuggestedExitNodesMu.Unlock()
|
defer b.allowedSuggestedExitNodesMu.Unlock()
|
||||||
b.allowedSuggestedExitNodes = fillAllowedSuggestions(b.polc)
|
|
||||||
|
var err error
|
||||||
|
b.allowedSuggestedExitNodes, err = fillAllowedSuggestions(b.polc)
|
||||||
|
if err != nil {
|
||||||
|
b.logf("error refreshing allowed suggestions: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// selectRegionFunc returns a DERP region from the slice of candidate regions.
|
// selectRegionFunc returns a DERP region from the slice of candidate regions.
|
||||||
@@ -7271,20 +7275,19 @@ type selectRegionFunc func(views.Slice[int]) int
|
|||||||
// choice.
|
// choice.
|
||||||
type selectNodeFunc func(nodes views.Slice[tailcfg.NodeView], last tailcfg.StableNodeID) tailcfg.NodeView
|
type selectNodeFunc func(nodes views.Slice[tailcfg.NodeView], last tailcfg.StableNodeID) tailcfg.NodeView
|
||||||
|
|
||||||
func fillAllowedSuggestions(polc policyclient.Client) set.Set[tailcfg.StableNodeID] {
|
func fillAllowedSuggestions(polc policyclient.Client) (set.Set[tailcfg.StableNodeID], error) {
|
||||||
nodes, err := polc.GetStringArray(pkey.AllowedSuggestedExitNodes, nil)
|
nodes, err := polc.GetStringArray(pkey.AllowedSuggestedExitNodes, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("fillAllowedSuggestions: unable to look up %q policy: %v", pkey.AllowedSuggestedExitNodes, err)
|
return nil, fmt.Errorf("fillAllowedSuggestions: unable to look up %q policy: %w", pkey.AllowedSuggestedExitNodes, err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if nodes == nil {
|
if nodes == nil {
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
s := make(set.Set[tailcfg.StableNodeID], len(nodes))
|
s := make(set.Set[tailcfg.StableNodeID], len(nodes))
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
s.Add(tailcfg.StableNodeID(n))
|
s.Add(tailcfg.StableNodeID(n))
|
||||||
}
|
}
|
||||||
return s
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// suggestExitNode returns a suggestion for reasonably good exit node based on
|
// suggestExitNode returns a suggestion for reasonably good exit node based on
|
||||||
|
|||||||
@@ -5590,7 +5590,10 @@ func TestFillAllowedSuggestions(t *testing.T) {
|
|||||||
var pol policytest.Config
|
var pol policytest.Config
|
||||||
pol.Set(pkey.AllowedSuggestedExitNodes, tt.allowPolicy)
|
pol.Set(pkey.AllowedSuggestedExitNodes, tt.allowPolicy)
|
||||||
|
|
||||||
got := fillAllowedSuggestions(pol)
|
got, err := fillAllowedSuggestions(pol)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if got == nil {
|
if got == nil {
|
||||||
if tt.want == nil {
|
if tt.want == nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user