2021-07-23 20:46:57 +00:00
|
|
|
package openvpn
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
)
|
|
|
|
|
|
2021-07-24 19:14:49 +00:00
|
|
|
func (l *Loop) signalOrSetStatus(status models.LoopStatus) {
|
2021-07-23 20:46:57 +00:00
|
|
|
if l.userTrigger {
|
|
|
|
|
l.userTrigger = false
|
|
|
|
|
select {
|
|
|
|
|
case l.running <- status:
|
|
|
|
|
default: // receiver calling ApplyStatus dropped out
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
l.statusManager.SetStatus(status)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-24 19:14:49 +00:00
|
|
|
func (l *Loop) logAndWait(ctx context.Context, err error) {
|
2021-07-23 20:46:57 +00:00
|
|
|
if err != nil {
|
|
|
|
|
l.logger.Error(err.Error())
|
|
|
|
|
}
|
|
|
|
|
l.logger.Info("retrying in " + l.backoffTime.String())
|
|
|
|
|
timer := time.NewTimer(l.backoffTime)
|
|
|
|
|
l.backoffTime *= 2
|
|
|
|
|
select {
|
|
|
|
|
case <-timer.C:
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
if !timer.Stop() {
|
|
|
|
|
<-timer.C
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|