diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go index 584747bff..28b91ddb5 100644 --- a/cmd/tailscale/cli/status.go +++ b/cmd/tailscale/cli/status.go @@ -78,6 +78,13 @@ func runStatus(ctx context.Context, args []string) error { return err } if statusArgs.json { + if statusArgs.active { + for peer, ps := range st.Peer { + if !peerActive(ps) { + delete(st.Peer, peer) + } + } + } j, err := json.MarshalIndent(st, "", " ") if err != nil { return err @@ -122,8 +129,7 @@ func runStatus(ctx context.Context, args []string) error { f := func(format string, a ...interface{}) { fmt.Fprintf(&buf, format, a...) } for _, peer := range st.Peers() { ps := st.Peer[peer] - // TODO: let server report this active bool instead - active := !ps.LastWrite.IsZero() && time.Since(ps.LastWrite) < 2*time.Minute + active := peerActive(ps) if statusArgs.active && !active { continue } @@ -157,3 +163,10 @@ func runStatus(ctx context.Context, args []string) error { os.Stdout.Write(buf.Bytes()) return nil } + +// peerActive reports whether ps has recent activity. +// +// TODO: have the server report this bool instead. +func peerActive(ps *ipnstate.PeerStatus) bool { + return !ps.LastWrite.IsZero() && time.Since(ps.LastWrite) < 2*time.Minute +} diff --git a/ipn/local.go b/ipn/local.go index 43a406077..3b9bef3d1 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -526,6 +526,8 @@ func (b *LocalBackend) send(n Notify) { if notify != nil { n.Version = version.LONG notify(n) + } else { + b.logf("nil notify callback; dropping %+v", n) } } @@ -1037,7 +1039,7 @@ func (b *LocalBackend) RequestEngineStatus() { // RequestStatus implements Backend. func (b *LocalBackend) RequestStatus() { st := b.Status() - b.notify(Notify{Status: st}) + b.send(Notify{Status: st}) } // stateMachine updates the state machine state based on other things