Skip to content

Commit

Permalink
ipn/ipnlocal: centralize assignments to cc + ccAuto in new method
Browse files Browse the repository at this point in the history
cc vs ccAuto is a mess. It needs to go. But this is a baby step towards
getting there.

Updates tailscale#11649

Change-Id: I34f33934844e580bd823a7d8f2b945cf26c87b3b
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
  • Loading branch information
bradfitz committed Apr 13, 2024
1 parent 970b1e2 commit 68043a1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ipn/ipnlocal/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -1838,8 +1838,7 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
if prevCC != nil {
defer prevCC.Shutdown() // must be called after b.mu is unlocked
}
b.cc = cc
b.ccAuto, _ = cc.(*controlclient.Auto)
b.setControlClientLocked(cc)
endpoints := b.endpoints

if err := b.initTKALocked(); err != nil {
Expand Down Expand Up @@ -4567,6 +4566,15 @@ func (b *LocalBackend) requestEngineStatusAndWait() {
b.statusLock.Unlock()
}

// setControlClientLocked sets the control client to cc,
// which may be nil.
//
// b.mu must be held.
func (b *LocalBackend) setControlClientLocked(cc controlclient.Client) {
b.cc = cc
b.ccAuto, _ = cc.(*controlclient.Auto)
}

// resetControlClientLocked sets b.cc to nil and returns the old value. If the
// returned value is non-nil, the caller must call Shutdown on it after
// releasing b.mu.
Expand All @@ -4589,8 +4597,7 @@ func (b *LocalBackend) resetControlClientLocked() controlclient.Client {
b.numClientStatusCalls.Add(1)
}
prev := b.cc
b.cc = nil
b.ccAuto = nil
b.setControlClientLocked(nil)
return prev
}

Expand Down

0 comments on commit 68043a1

Please sign in to comment.