MCPcopy Index your code
hub / github.com/tailscale/tailscale / updateRoutine

Method updateRoutine

control/controlclient/auto.go:57–101  ·  view source on GitHub ↗

updateRoutine is responsible for informing the server of worthy changes to our local state. It runs in its own goroutine.

()

Source from the content-addressed store, hash-verified

55// updateRoutine is responsible for informing the server of worthy changes to
56// our local state. It runs in its own goroutine.
57func (c *Auto) updateRoutine() {
58 defer close(c.updateDone)
59 bo := backoff.NewBackoff("updateRoutine", c.logf, 30*time.Second)
60
61 // lastUpdateGenInformed is the value of lastUpdateAt that we've successfully
62 // informed the server of.
63 var lastUpdateGenInformed updateGen
64
65 for {
66 if !c.waitUnpause("updateRoutine") {
67 c.logf("updateRoutine: exiting")
68 return
69 }
70 c.mu.Lock()
71 gen := c.lastUpdateGen
72 ctx := c.mapCtx
73 needUpdate := gen > 0 && gen != lastUpdateGenInformed && c.loggedIn
74 c.mu.Unlock()
75
76 if !needUpdate {
77 // Nothing to do, wait for a signal.
78 select {
79 case <-ctx.Done():
80 continue
81 case <-c.updateCh:
82 continue
83 }
84 }
85
86 t0 := c.clock.Now()
87 err := c.direct.SendUpdate(ctx)
88 d := time.Since(t0).Round(time.Millisecond)
89 if err != nil {
90 if ctx.Err() == nil {
91 c.direct.logf("lite map update error after %v: %v", d, err)
92 }
93 bo.BackOff(ctx, err)
94 continue
95 }
96 bo.Reset()
97 c.direct.logf("[v1] successful lite map update in %v", d)
98
99 lastUpdateGenInformed = gen
100 }
101}
102
103// atomicGen is an atomic int64 generator. It is used to generate monotonically
104// increasing numbers for updateGen.

Callers 1

startMethod · 0.95

Calls 12

waitUnpauseMethod · 0.95
BackOffMethod · 0.95
ResetMethod · 0.95
NewBackoffFunction · 0.92
SendUpdateMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
DoneMethod · 0.65
NowMethod · 0.65
SinceMethod · 0.65
logfMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected