satellite/satellitedb: update SelectAllStorageNodes* to set country code
Methods SelectAllStorageNodesUpload and SelectAllStorageNodesDownload are not returning full info with overlay.SelectedNode because its missing CountryCode. Change-Id: Ie3cb396bf28d7ec4c6ab8927e5bb560236036aa6
This commit is contained in:
parent
403f5eff81
commit
c48bd81e5f
@ -304,6 +304,7 @@ func (node *SelectedNode) Clone() *SelectedNode {
|
||||
Address: copy.Address,
|
||||
LastNet: node.LastNet,
|
||||
LastIPPort: node.LastIPPort,
|
||||
CountryCode: node.CountryCode,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ func (cache *overlaycache) selectAllStorageNodesUpload(ctx context.Context, sele
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
query := `
|
||||
SELECT id, address, last_net, last_ip_port, vetted_at, country_code, noise_proto, noise_public_key, debounce_limit
|
||||
SELECT id, address, last_net, last_ip_port, vetted_at, country_code, noise_proto, noise_public_key, debounce_limit, country_code
|
||||
FROM nodes
|
||||
` + cache.db.impl.AsOfSystemInterval(selectionCfg.AsOfSystemTime.Interval()) + `
|
||||
WHERE disqualified IS NULL
|
||||
@ -102,7 +102,8 @@ func (cache *overlaycache) selectAllStorageNodesUpload(ctx context.Context, sele
|
||||
var lastIPPort sql.NullString
|
||||
var vettedAt *time.Time
|
||||
var noise noiseScanner
|
||||
err = rows.Scan(&node.ID, &node.Address.Address, &node.LastNet, &lastIPPort, &vettedAt, &node.CountryCode, &noise.Proto, &noise.PublicKey, &node.Address.DebounceLimit)
|
||||
err = rows.Scan(&node.ID, &node.Address.Address, &node.LastNet, &lastIPPort, &vettedAt, &node.CountryCode, &noise.Proto,
|
||||
&noise.PublicKey, &node.Address.DebounceLimit, &node.CountryCode)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -141,7 +142,7 @@ func (cache *overlaycache) selectAllStorageNodesDownload(ctx context.Context, on
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
query := `
|
||||
SELECT id, address, last_net, last_ip_port, noise_proto, noise_public_key, debounce_limit
|
||||
SELECT id, address, last_net, last_ip_port, noise_proto, noise_public_key, debounce_limit, country_code
|
||||
FROM nodes
|
||||
` + cache.db.impl.AsOfSystemInterval(asOfConfig.Interval()) + `
|
||||
WHERE disqualified IS NULL
|
||||
@ -165,7 +166,8 @@ func (cache *overlaycache) selectAllStorageNodesDownload(ctx context.Context, on
|
||||
node.Address = &pb.NodeAddress{}
|
||||
var lastIPPort sql.NullString
|
||||
var noise noiseScanner
|
||||
err = rows.Scan(&node.ID, &node.Address.Address, &node.LastNet, &lastIPPort, &noise.Proto, &noise.PublicKey, &node.Address.DebounceLimit)
|
||||
err = rows.Scan(&node.ID, &node.Address.Address, &node.LastNet, &lastIPPort, &noise.Proto,
|
||||
&noise.PublicKey, &node.Address.DebounceLimit, &node.CountryCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
|
||||
"storj.io/common/pb"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/storj/location"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/private/version"
|
||||
@ -358,3 +359,62 @@ func TestGetNodesNetwork(t *testing.T) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestOverlayCache_SelectAllStorageNodesDownloadUpload(t *testing.T) {
|
||||
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
||||
cache := db.OverlayCache()
|
||||
const netMask = 28
|
||||
mask := net.CIDRMask(netMask, 32)
|
||||
|
||||
infos := make([]overlay.NodeCheckInInfo, 5)
|
||||
|
||||
for n := range infos {
|
||||
id := testrand.NodeID()
|
||||
ip := net.IP{0, 0, 1, byte(n)}
|
||||
lastNet := ip.Mask(mask).String()
|
||||
|
||||
infos[n] = overlay.NodeCheckInInfo{
|
||||
IsUp: true,
|
||||
Address: &pb.NodeAddress{Address: ip.String()},
|
||||
LastNet: lastNet,
|
||||
LastIPPort: "0.0.0.0:0",
|
||||
Version: &pb.NodeVersion{Version: "v0.0.0"},
|
||||
NodeID: id,
|
||||
CountryCode: location.Canada,
|
||||
}
|
||||
err := cache.UpdateCheckIn(ctx, infos[n], time.Now().UTC(), overlay.NodeSelectionConfig{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
checkNodes := func(selectedNodes []*overlay.SelectedNode) {
|
||||
selectedNodesMap := map[storj.NodeID]*overlay.SelectedNode{}
|
||||
for _, node := range selectedNodes {
|
||||
selectedNodesMap[node.ID] = node
|
||||
}
|
||||
|
||||
for _, info := range infos {
|
||||
selectedNode, ok := selectedNodesMap[info.NodeID]
|
||||
require.True(t, ok)
|
||||
|
||||
require.Equal(t, info.NodeID, selectedNode.ID)
|
||||
require.Equal(t, info.Address, selectedNode.Address)
|
||||
require.Equal(t, info.CountryCode, selectedNode.CountryCode)
|
||||
require.Equal(t, info.LastIPPort, selectedNode.LastIPPort)
|
||||
require.Equal(t, info.LastNet, selectedNode.LastNet)
|
||||
}
|
||||
}
|
||||
|
||||
selectedNodes, err := cache.SelectAllStorageNodesDownload(ctx, time.Minute, overlay.AsOfSystemTimeConfig{})
|
||||
require.NoError(t, err)
|
||||
|
||||
checkNodes(selectedNodes)
|
||||
|
||||
reputableNodes, newNodes, err := cache.SelectAllStorageNodesUpload(ctx, overlay.NodeSelectionConfig{
|
||||
OnlineWindow: time.Minute,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
checkNodes(append(reputableNodes, newNodes...))
|
||||
})
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user