mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-27 11:41:14 +00:00
ipn/ipnlocal: plumb logf into nodeBackend
Updates #cleanup Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -501,7 +501,7 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
|
||||
needsCaptiveDetection: make(chan bool),
|
||||
}
|
||||
|
||||
nb := newNodeBackend(ctx, b.sys.Bus.Get())
|
||||
nb := newNodeBackend(ctx, b.logf, b.sys.Bus.Get())
|
||||
b.currentNodeAtomic.Store(nb)
|
||||
nb.ready()
|
||||
|
||||
@@ -629,7 +629,7 @@ func (b *LocalBackend) currentNode() *nodeBackend {
|
||||
if v := b.currentNodeAtomic.Load(); v != nil || !testenv.InTest() {
|
||||
return v
|
||||
}
|
||||
v := newNodeBackend(cmp.Or(b.ctx, context.Background()), b.sys.Bus.Get())
|
||||
v := newNodeBackend(cmp.Or(b.ctx, context.Background()), b.logf, b.sys.Bus.Get())
|
||||
if b.currentNodeAtomic.CompareAndSwap(nil, v) {
|
||||
v.ready()
|
||||
}
|
||||
@@ -4890,7 +4890,7 @@ func (b *LocalBackend) authReconfig() {
|
||||
hasPAC := b.prevIfState.HasPAC()
|
||||
disableSubnetsIfPAC := cn.SelfHasCap(tailcfg.NodeAttrDisableSubnetsIfPAC)
|
||||
dohURL, dohURLOK := cn.exitNodeCanProxyDNS(prefs.ExitNodeID())
|
||||
dcfg := cn.dnsConfigForNetmap(prefs, b.keyExpired, b.logf, version.OS())
|
||||
dcfg := cn.dnsConfigForNetmap(prefs, b.keyExpired, version.OS())
|
||||
// If the current node is an app connector, ensure the app connector machine is started
|
||||
b.reconfigAppConnectorLocked(nm, prefs)
|
||||
closing := b.shutdownCalled
|
||||
@@ -6797,7 +6797,7 @@ func (b *LocalBackend) resetForProfileChangeLockedOnEntry(unlock unlockOnce) err
|
||||
// down, so no need to do any work.
|
||||
return nil
|
||||
}
|
||||
newNode := newNodeBackend(b.ctx, b.sys.Bus.Get())
|
||||
newNode := newNodeBackend(b.ctx, b.logf, b.sys.Bus.Get())
|
||||
if oldNode := b.currentNodeAtomic.Swap(newNode); oldNode != nil {
|
||||
oldNode.shutdown(errNodeContextChanged)
|
||||
}
|
||||
|
||||
@@ -4904,7 +4904,7 @@ func TestSuggestExitNode(t *testing.T) {
|
||||
allowList = set.SetOf(tt.allowPolicy)
|
||||
}
|
||||
|
||||
nb := newNodeBackend(t.Context(), eventbus.New())
|
||||
nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())
|
||||
defer nb.shutdown(errShutdown)
|
||||
nb.SetNetMap(tt.netMap)
|
||||
|
||||
@@ -5357,7 +5357,7 @@ func TestSuggestExitNodeTrafficSteering(t *testing.T) {
|
||||
tt.netMap.AllCaps = set.SetOf(slices.Collect(caps))
|
||||
}
|
||||
|
||||
nb := newNodeBackend(t.Context(), eventbus.New())
|
||||
nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())
|
||||
defer nb.shutdown(errShutdown)
|
||||
nb.SetNetMap(tt.netMap)
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ import (
|
||||
// Even if they're tied to the local node, instead of moving them here, we should extract the entire feature
|
||||
// into a separate package and have it install proper hooks.
|
||||
type nodeBackend struct {
|
||||
logf logger.Logf
|
||||
|
||||
ctx context.Context // canceled by [nodeBackend.shutdown]
|
||||
ctxCancel context.CancelCauseFunc // cancels ctx
|
||||
|
||||
@@ -104,9 +106,10 @@ type nodeBackend struct {
|
||||
nodeByAddr map[netip.Addr]tailcfg.NodeID
|
||||
}
|
||||
|
||||
func newNodeBackend(ctx context.Context, bus *eventbus.Bus) *nodeBackend {
|
||||
func newNodeBackend(ctx context.Context, logf logger.Logf, bus *eventbus.Bus) *nodeBackend {
|
||||
ctx, ctxCancel := context.WithCancelCause(ctx)
|
||||
nb := &nodeBackend{
|
||||
logf: logf,
|
||||
ctx: ctx,
|
||||
ctxCancel: ctxCancel,
|
||||
eventClient: bus.Client("ipnlocal.nodeBackend"),
|
||||
@@ -520,10 +523,10 @@ func (nb *nodeBackend) setFilter(f *filter.Filter) {
|
||||
nb.filterPub.Publish(magicsock.FilterUpdate{Filter: f})
|
||||
}
|
||||
|
||||
func (nb *nodeBackend) dnsConfigForNetmap(prefs ipn.PrefsView, selfExpired bool, logf logger.Logf, versionOS string) *dns.Config {
|
||||
func (nb *nodeBackend) dnsConfigForNetmap(prefs ipn.PrefsView, selfExpired bool, versionOS string) *dns.Config {
|
||||
nb.mu.Lock()
|
||||
defer nb.mu.Unlock()
|
||||
return dnsConfigForNetmap(nb.netMap, nb.peers, prefs, selfExpired, logf, versionOS)
|
||||
return dnsConfigForNetmap(nb.netMap, nb.peers, prefs, selfExpired, nb.logf, versionOS)
|
||||
}
|
||||
|
||||
func (nb *nodeBackend) exitNodeCanProxyDNS(exitNodeID tailcfg.StableNodeID) (dohURL string, ok bool) {
|
||||
|
||||
@@ -9,11 +9,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"tailscale.com/tstest"
|
||||
"tailscale.com/util/eventbus"
|
||||
)
|
||||
|
||||
func TestNodeBackendReadiness(t *testing.T) {
|
||||
nb := newNodeBackend(t.Context(), eventbus.New())
|
||||
nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())
|
||||
|
||||
// The node backend is not ready until [nodeBackend.ready] is called,
|
||||
// and [nodeBackend.Wait] should fail with [context.DeadlineExceeded].
|
||||
@@ -44,7 +45,7 @@ func TestNodeBackendReadiness(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeBackendShutdown(t *testing.T) {
|
||||
nb := newNodeBackend(t.Context(), eventbus.New())
|
||||
nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())
|
||||
|
||||
shutdownCause := errors.New("test shutdown")
|
||||
|
||||
@@ -82,7 +83,7 @@ func TestNodeBackendShutdown(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeBackendReadyAfterShutdown(t *testing.T) {
|
||||
nb := newNodeBackend(t.Context(), eventbus.New())
|
||||
nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())
|
||||
|
||||
shutdownCause := errors.New("test shutdown")
|
||||
nb.shutdown(shutdownCause)
|
||||
@@ -94,7 +95,7 @@ func TestNodeBackendReadyAfterShutdown(t *testing.T) {
|
||||
|
||||
func TestNodeBackendParentContextCancellation(t *testing.T) {
|
||||
ctx, cancelCtx := context.WithCancel(context.Background())
|
||||
nb := newNodeBackend(ctx, eventbus.New())
|
||||
nb := newNodeBackend(ctx, tstest.WhileTestRunningLogger(t), eventbus.New())
|
||||
|
||||
cancelCtx()
|
||||
|
||||
@@ -111,7 +112,7 @@ func TestNodeBackendParentContextCancellation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNodeBackendConcurrentReadyAndShutdown(t *testing.T) {
|
||||
nb := newNodeBackend(t.Context(), eventbus.New())
|
||||
nb := newNodeBackend(t.Context(), tstest.WhileTestRunningLogger(t), eventbus.New())
|
||||
|
||||
// Calling [nodeBackend.ready] and [nodeBackend.shutdown] concurrently
|
||||
// should not cause issues, and [nodeBackend.Wait] should unblock,
|
||||
|
||||
Reference in New Issue
Block a user