mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-09 16:11:23 +00:00
net/netmon: factor out debounce loop, simplify polling impl
This simplifies some netmon code in prep for other changes. It breaks up Monitor.debounce into a helper method so locking is easier to read and things unindent, and then it simplifies the polling netmon implementation to remove the redundant stuff that the caller (the Monitor.debounce loop) was already basically doing. Updates #9040 Change-Id: Idcfb45201d00ae64017042a7bdee6ef86ad37a9f Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
9ea3942b1a
commit
e881c1caec
@@ -13,7 +13,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"tailscale.com/net/interfaces"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
@@ -68,22 +67,18 @@ func (pm *pollingMon) Receive() (message, error) {
|
||||
// so this can go very slowly there, to save battery.
|
||||
// https://github.com/tailscale/tailscale/issues/1427
|
||||
d = 10 * time.Minute
|
||||
}
|
||||
if pm.isCloudRun() {
|
||||
} else if pm.isCloudRun() {
|
||||
// Cloud Run routes never change at runtime. the containers are killed within
|
||||
// 15 minutes by default, set the interval long enough to be effectively infinite.
|
||||
pm.logf("monitor polling: Cloud Run detected, reduce polling interval to 24h")
|
||||
d = 24 * time.Hour
|
||||
}
|
||||
ticker := time.NewTicker(d)
|
||||
defer ticker.Stop()
|
||||
base := pm.m.InterfaceState()
|
||||
timer := time.NewTimer(d)
|
||||
defer timer.Stop()
|
||||
for {
|
||||
if cur, err := pm.m.interfaceStateUncached(); err == nil && !cur.EqualFiltered(base, interfaces.UseInterestingInterfaces, interfaces.UseInterestingIPs) {
|
||||
return unspecifiedMessage{}, nil
|
||||
}
|
||||
select {
|
||||
case <-ticker.C:
|
||||
case <-timer.C:
|
||||
return unspecifiedMessage{}, nil
|
||||
case <-pm.stop:
|
||||
return nil, errors.New("stopped")
|
||||
}
|
||||
|
Reference in New Issue
Block a user