control/controlclient: clean up a few little things

De-pointer a *time.Time type, move it after the mutex which guard is,
rename two test-only methods with our conventional "ForTest" suffix.

Updates #cleanup

Change-Id: I4f4d1acd9c2de33d9c3cb6465d7349ed051aa9f9
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2023-08-28 22:19:23 -07:00 committed by Brad Fitzpatrick
parent 3bce9632d9
commit 6b882a1511

View File

@ -141,7 +141,6 @@ type Auto struct {
direct *Direct // our interface to the server APIs direct *Direct // our interface to the server APIs
clock tstime.Clock clock tstime.Clock
logf logger.Logf logf logger.Logf
expiry *time.Time
closed bool closed bool
updateCh chan struct{} // readable when we should inform the server of a change updateCh chan struct{} // readable when we should inform the server of a change
newMapCh chan struct{} // readable when we must restart a map request newMapCh chan struct{} // readable when we must restart a map request
@ -151,6 +150,8 @@ type Auto struct {
mu sync.Mutex // mutex guards the following fields mu sync.Mutex // mutex guards the following fields
expiry time.Time
// lastUpdateGen is the gen of last update we had an update worth sending to // lastUpdateGen is the gen of last update we had an update worth sending to
// the server. // the server.
lastUpdateGen updateGen lastUpdateGen updateGen
@ -456,17 +457,17 @@ func (c *Auto) authRoutine() {
} }
} }
// Expiry returns the credential expiration time, or the zero time if // ExpiryForTests returns the credential expiration time, or the zero value if
// the expiration time isn't known. Used in tests only. // the expiration time isn't known. It's used in tests only.
func (c *Auto) Expiry() *time.Time { func (c *Auto) ExpiryForTests() time.Time {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
return c.expiry return c.expiry
} }
// Direct returns the underlying direct client object. Used in tests // DirectForTest returns the underlying direct client object.
// only. // It's used in tests only.
func (c *Auto) Direct() *Direct { func (c *Auto) DirectForTest() *Direct {
return c.direct return c.direct
} }
@ -496,7 +497,7 @@ func (mrs mapRoutineState) UpdateFullNetmap(nm *netmap.NetworkMap) {
if c.loggedIn { if c.loggedIn {
c.state = StateSynchronized c.state = StateSynchronized
} }
c.expiry = ptr.To(nm.Expiry) c.expiry = nm.Expiry
stillAuthed := c.loggedIn stillAuthed := c.loggedIn
c.logf("[v1] mapRoutine: netmap received: %s", c.state) c.logf("[v1] mapRoutine: netmap received: %s", c.state)
c.mu.Unlock() c.mu.Unlock()