Fix netenv resolver interaction
Also fix endless loop in tcp resolver when network is down
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user