ipn: !WantRunning + !LoggedOut should not be idle on startup.

There was logic that would make a "down" tailscale backend (ie.
!WantRunning) refuse to do any network activity. Unfortunately, this
makes the macOS and iOS UI unable to render correctly if they start
while !WantRunning.

Now that we have Prefs.LoggedOut, use that instead. So `tailscale down`
will still allow the controlclient to connect its authroutine, but
pause the maproutine. `tailscale logout` will entirely stop all
activity.

This new behaviour is not obviously correct; it's a bit annoying that
`tailsale down` doesn't terminate all activity like you might expect.
Maybe we should redesign the UI code to render differently when
disconnected, and then revert this change.

Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
This commit is contained in:
Avery Pennarun
2021-04-30 05:27:37 -04:00
parent 4f3315f3da
commit 4ef207833b
2 changed files with 26 additions and 21 deletions

View File

@@ -809,17 +809,13 @@ func (b *LocalBackend) Start(opts ipn.Options) error {
b.send(ipn.Notify{BackendLogID: &blid})
b.send(ipn.Notify{Prefs: prefs})
if wantRunning && !loggedOut {
if !loggedOut && b.hasNodeKey() {
// Even if !WantRunning, we should verify our key, if there
// is one. If you want tailscaled to be completely idle,
// use logout instead.
cc.Login(nil, controlclient.LoginDefault)
b.mu.Lock()
b.state = ipn.Starting
b.mu.Unlock()
b.send(ipn.Notify{State: &b.state})
} else {
b.stateMachine()
}
b.stateMachine()
return nil
}
@@ -2125,6 +2121,15 @@ func (b *LocalBackend) enterState(newState ipn.State) {
}
func (b *LocalBackend) hasNodeKey() bool {
// we can't use b.Prefs(), because it strips the keys, oops!
b.mu.Lock()
p := b.prefs
b.mu.Unlock()
return p.Persist != nil && !p.Persist.PrivateNodeKey.IsZero()
}
// nextState returns the state the backend seems to be in, based on
// its internal state.
func (b *LocalBackend) nextState() ipn.State {
@@ -2136,13 +2141,11 @@ func (b *LocalBackend) nextState() ipn.State {
state = b.state
wantRunning = b.prefs.WantRunning
loggedOut = b.prefs.LoggedOut
hasNodeKey = b.prefs.Persist != nil &&
!b.prefs.Persist.PrivateNodeKey.IsZero()
)
b.mu.Unlock()
switch {
case !wantRunning && !loggedOut && hasNodeKey:
case !wantRunning && !loggedOut && b.hasNodeKey():
return ipn.Stopped
case netMap == nil:
if cc.AuthCantContinue() || loggedOut {