From 014eb95eacd154720cec70c2e176c128cf9727ee Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 13 Apr 2022 11:04:08 +0200 Subject: [PATCH] Reset device locations when network changes --- netenv/location.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/netenv/location.go b/netenv/location.go index 75da8c87..6245ab45 100644 --- a/netenv/location.go +++ b/netenv/location.go @@ -216,6 +216,10 @@ func SetInternetLocation(ip net.IP, source DeviceLocationSource) (dl *DeviceLoca log.Warningf("netenv: failed to get geolocation data of %s (from %s): %s", ip, source, err) return nil, false } + // Only use location if there is data for it. + if geoLoc.Country.ISOCode == "" { + return nil, false + } loc.Location = geoLoc addLocation(loc) @@ -271,6 +275,13 @@ func GetInternetLocation() (deviceLocations *DeviceLocations, ok bool) { } locationNetworkChangedFlag.Refresh() + // Reset locations. + func() { + locationsLock.Lock() + defer locationsLock.Unlock() + locations = &DeviceLocations{} + }() + // Get all assigned addresses. v4s, v6s, err := GetAssignedAddresses() if err != nil {