diff --git a/satellite/geoip/example_testplanet_test.go b/satellite/geoip/example_testplanet_test.go index 7c5b08f94..b68817eee 100644 --- a/satellite/geoip/example_testplanet_test.go +++ b/satellite/geoip/example_testplanet_test.go @@ -16,6 +16,7 @@ import ( "storj.io/common/testcontext" "storj.io/storj/private/testplanet" "storj.io/storj/satellite" + "storj.io/storj/satellite/geoip" "storj.io/storj/storagenode" ) @@ -54,6 +55,24 @@ func TestGeoIPMock(t *testing.T) { require.NoError(t, err) assert.Equal(t, countryCodes[i], dossier.CountryCode) } + + // change country in the mock GeoIP service from US to CA + planet.Satellites[0].Overlay.Service.GeoIP = geoip.NewMockIPToCountry([]string{"CA", "GB"}) + + // wait for storage nodes checked in again with satellite + for _, node := range planet.StorageNodes { + node.Contact.Chore.TriggerWait(ctx) + } + + // adjust expected country codes for node 1 + countryCodes[1] = location.Canada + + // check the country code for each storage nodes + for i, node := range planet.StorageNodes { + dossier, err := planet.Satellites[0].API.Overlay.DB.Get(ctx, node.ID()) + require.NoError(t, err) + assert.Equal(t, countryCodes[i], dossier.CountryCode) + } }, ) } diff --git a/satellite/overlay/service.go b/satellite/overlay/service.go index 48ab26b0f..402f99633 100644 --- a/satellite/overlay/service.go +++ b/satellite/overlay/service.go @@ -692,17 +692,13 @@ func (service *Service) UpdateCheckIn(ctx context.Context, node NodeCheckInInfo, spaceChanged := (node.Capacity == nil && oldInfo.Capacity.FreeDisk != 0) || (node.Capacity != nil && node.Capacity.FreeDisk != oldInfo.Capacity.FreeDisk) - if oldInfo.CountryCode == location.CountryCode(0) || oldInfo.LastIPPort != node.LastIPPort { - node.CountryCode, err = service.GeoIP.LookupISOCountryCode(node.LastIPPort) - if err != nil { - failureMeter.Mark(1) - service.log.Debug("failed to resolve country code for node", - zap.String("node address", node.Address.Address), - zap.Stringer("Node ID", node.NodeID), - zap.Error(err)) - } - } else { - node.CountryCode = oldInfo.CountryCode + node.CountryCode, err = service.GeoIP.LookupISOCountryCode(node.LastIPPort) + if err != nil { + failureMeter.Mark(1) + service.log.Debug("failed to resolve country code for node", + zap.String("node address", node.Address.Address), + zap.Stringer("Node ID", node.NodeID), + zap.Error(err)) } if service.config.SendNodeEmails && service.config.Node.MinimumVersion != "" {