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:
Quentin McGaw
2023-09-24 14:55:51 +00:00
parent e64e5af4c3
commit f96448947f
21 changed files with 308 additions and 380 deletions

24
internal/publicip/data.go Normal file
View File

@@ -0,0 +1,24 @@
package publicip
import "github.com/qdm12/gluetun/internal/models"
// GetData returns the public IP data obtained from the last
// fetch. It is notably used by the HTTP control server.
func (l *Loop) GetData() (data models.PublicIP) {
l.ipDataMutex.RLock()
defer l.ipDataMutex.RUnlock()
return l.ipData
}
// ClearData is used when the VPN connection goes down
// and the public IP is not known anymore.
func (l *Loop) ClearData() (err error) {
l.ipDataMutex.Lock()
defer l.ipDataMutex.Unlock()
l.ipData = models.PublicIP{}
l.settingsMutex.RLock()
filepath := *l.settings.IPFilepath
l.settingsMutex.RUnlock()
return persistPublicIP(filepath, "", l.puid, l.pgid)
}