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:
24
internal/publicip/data.go
Normal file
24
internal/publicip/data.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user