Fix netenv resolver interaction

Also fix endless loop in tcp resolver when network is down
This commit is contained in:
Daniel
2020-06-26 22:50:35 +02:00
parent 111e324d26
commit 881a757667
4 changed files with 71 additions and 11 deletions

View File

@@ -106,6 +106,8 @@ var (
captivePortalURL string
captivePortalLock sync.Mutex
waitForever = make(chan time.Time)
)
func init() {
@@ -200,12 +202,14 @@ func triggerOnlineStatusInvestigation() {
}
func monitorOnlineStatus(ctx context.Context) error {
triggerOnlineStatusInvestigation()
for {
// wait for trigger
select {
case <-ctx.Done():
return nil
case <-onlineStatusInvestigationTrigger:
case <-getDynamicStatusTrigger():
}
// enable waiting
@@ -221,6 +225,21 @@ func monitorOnlineStatus(ctx context.Context) error {
}
}
func getDynamicStatusTrigger() <-chan time.Time {
switch GetOnlineStatus() {
case StatusOffline:
return time.After(10 * time.Second)
case StatusLimited, StatusPortal:
return time.After(1 * time.Minute)
case StatusSemiOnline:
return time.After(5 * time.Minute)
case StatusOnline:
return waitForever
default: // unknown status
return time.After(5 * time.Minute)
}
}
func checkOnlineStatus(ctx context.Context) {
// TODO: implement more methods
/*status, err := getConnectivityStateFromDbus()