From 21170fb1756a80ad7ff99fff0416224ea254a52d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 20 Aug 2023 14:55:07 -0700 Subject: [PATCH] control/controlclient: scope a variable tighter, de-pointer a *time.Time Just misc cleanups. Updates #1909 Change-Id: I9d64cb6c46d634eb5fdf725c13a6c5e514e02e9a Signed-off-by: Brad Fitzpatrick --- control/controlclient/direct.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 3fa29d660..b5f431073 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -93,7 +93,7 @@ type Direct struct { persist persist.PersistView authKey string tryingNewKey key.NodePrivate - expiry *time.Time + expiry time.Time // or zero value if none/unknown hostinfo *tailcfg.Hostinfo // always non-nil netinfo *tailcfg.NetInfo endpoints []tailcfg.Endpoint @@ -438,7 +438,7 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new authKey, isWrapped, wrappedSig, wrappedKey := decodeWrappedAuthkey(c.authKey, c.logf) hi := c.hostInfoLocked() backendLogID := hi.BackendLogID - expired := c.expiry != nil && !c.expiry.IsZero() && c.expiry.Before(c.clock.Now()) + expired := !c.expiry.IsZero() && c.expiry.Before(c.clock.Now()) c.mu.Unlock() machinePrivKey, err := c.getMachinePrivKey() @@ -1077,17 +1077,16 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap metricMapResponseMapDelta.Add(1) } - hasDebug := resp.Debug != nil - if hasDebug { - if code := resp.Debug.Exit; code != nil { + if debug := resp.Debug; debug != nil { + if code := debug.Exit; code != nil { c.logf("exiting process with status %v per controlplane", *code) os.Exit(*code) } - if resp.Debug.DisableLogTail { + if debug.DisableLogTail { logtail.Disable() envknob.SetNoLogsNoSupport() } - if sleep := time.Duration(resp.Debug.SleepSeconds * float64(time.Second)); sleep > 0 { + if sleep := time.Duration(debug.SleepSeconds * float64(time.Second)); sleep > 0 { if err := sleepAsRequested(ctx, c.logf, timeoutReset, sleep, c.clock); err != nil { return err } @@ -1134,7 +1133,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap c.persist = newPersist.View() persist = c.persist } - c.expiry = &nm.Expiry + c.expiry = nm.Expiry c.mu.Unlock() nu.UpdateFullNetmap(nm)