Files
gluetun/internal/publicip/data.go
Quentin McGaw f96448947f 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
2023-09-24 14:55:51 +00:00

25 lines
677 B
Go

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)
}