Skip to content

Commit

Permalink
satellite/overlay: update country code on every node check-in
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kaloyan-raev committed Mar 22, 2023
1 parent 58f465c commit 98b8248
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
19 changes: 19 additions & 0 deletions satellite/geoip/example_testplanet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
},
)
}
18 changes: 7 additions & 11 deletions satellite/overlay/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down

0 comments on commit 98b8248

Please sign in to comment.