From 98b82486bdbb1314d478584628ba966706e58233 Mon Sep 17 00:00:00 2001 From: Kaloyan Raev Date: Tue, 21 Mar 2023 17:04:17 +0200 Subject: [PATCH] satellite/overlay: update country code on every node check-in We have a specific issue that a user uploaded a file to a bucket geo-fenced to EU and one of the pieces appeared to be on a node in the US. The country code of this node is set to SE (Sweden) in the satellite DB. It turns out that some time ago MaxMind changed the country code of this node's IP from Sweden to US, but this change hasn't been reflected in the satellite's database. So far the satellite updates the country code of a node only if its IP changes. It was assumed that if the IP does not change, its country code shouldn't change too. This turned to be a wrong assumption. With this change, the satellite will look up the MaxMindDB on every check-in to see if the country code of the node's IP has changed. Change-Id: Icdf659b09be9fc6ad14601902032b35ba5ea78c4 --- satellite/geoip/example_testplanet_test.go | 19 +++++++++++++++++++ satellite/overlay/service.go | 18 +++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) 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 != "" {