fix(publicip): rework run loop and fix restarts
- Clearing IP data on VPN disconnection clears file - More efficient partial updates - Fix loop exit - Validate settings before updating
This commit is contained in:
@@ -3,8 +3,6 @@ package vpn
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
func (l *Loop) cleanup(vpnProvider string) {
|
||||
@@ -15,9 +13,12 @@ func (l *Loop) cleanup(vpnProvider string) {
|
||||
}
|
||||
}
|
||||
|
||||
l.publicip.SetData(models.PublicIP{}) // clear public IP address data
|
||||
err := l.publicip.ClearData()
|
||||
if err != nil {
|
||||
l.logger.Error("clearing public IP data: " + err.Error())
|
||||
}
|
||||
|
||||
err := l.stopPortForwarding(vpnProvider)
|
||||
err = l.stopPortForwarding(vpnProvider)
|
||||
if err != nil {
|
||||
portForwardingAlreadyStopped := errors.Is(err, context.Canceled)
|
||||
if !portForwardingAlreadyStopped {
|
||||
|
||||
@@ -90,7 +90,6 @@ type DNSLoop interface {
|
||||
}
|
||||
|
||||
type PublicIPLoop interface {
|
||||
ApplyStatus(ctx context.Context, status models.LoopStatus) (
|
||||
outcome string, err error)
|
||||
SetData(data models.PublicIP)
|
||||
StartSingleRun()
|
||||
ClearData() (err error)
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ func (l *Loop) onTunnelUp(ctx context.Context, data tunnelUpData) {
|
||||
_, _ = l.dnsLooper.ApplyStatus(ctx, constants.Running)
|
||||
}
|
||||
|
||||
// Runs the Public IP getter job once
|
||||
_, _ = l.publicip.ApplyStatus(ctx, constants.Running)
|
||||
l.publicip.StartSingleRun()
|
||||
|
||||
if l.versionInfo {
|
||||
l.versionInfo = false // only get the version information once
|
||||
message, err := version.GetMessage(ctx, l.buildInfo, l.client)
|
||||
|
||||
Reference in New Issue
Block a user