2019-09-06 17:14:03 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-09-20 21:02:23 +01:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2019-09-06 17:14:03 +01:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
"storj.io/storj/pkg/pb"
|
2019-09-20 21:02:23 +01:00
|
|
|
"storj.io/storj/storagenode"
|
2019-09-06 17:14:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoragenodeContactEndpoint(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeDossier := planet.StorageNodes[0].Local()
|
|
|
|
pingStats := planet.StorageNodes[0].Contact.PingStats
|
|
|
|
|
|
|
|
conn, err := planet.Satellites[0].Transport.DialNode(ctx, &nodeDossier.Node)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(conn.Close)
|
|
|
|
|
|
|
|
resp, err := pb.NewContactClient(conn).PingNode(ctx, &pb.ContactPingRequest{})
|
|
|
|
require.NotNil(t, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
firstPing, _, _ := pingStats.WhenLastPinged()
|
|
|
|
|
|
|
|
resp, err = pb.NewContactClient(conn).PingNode(ctx, &pb.ContactPingRequest{})
|
|
|
|
require.NotNil(t, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
secondPing, _, _ := pingStats.WhenLastPinged()
|
|
|
|
|
|
|
|
require.True(t, secondPing.After(firstPing))
|
|
|
|
})
|
|
|
|
}
|
2019-09-13 12:53:48 +01:00
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
func TestNodeInfoUpdated(t *testing.T) {
|
2019-09-13 12:53:48 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
|
|
|
|
node.Contact.Chore.Loop.Pause()
|
|
|
|
|
|
|
|
oldInfo, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
oldCapacity := oldInfo.Capacity
|
|
|
|
|
|
|
|
newCapacity := pb.NodeCapacity{
|
|
|
|
FreeBandwidth: 0,
|
|
|
|
FreeDisk: 0,
|
|
|
|
}
|
|
|
|
require.NotEqual(t, oldCapacity, newCapacity)
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
node.Contact.Service.UpdateSelf(&newCapacity)
|
2019-09-13 12:53:48 +01:00
|
|
|
|
|
|
|
node.Contact.Chore.Loop.TriggerWait()
|
|
|
|
|
|
|
|
newInfo, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
firstUptime := oldInfo.Reputation.LastContactSuccess
|
|
|
|
secondUptime := newInfo.Reputation.LastContactSuccess
|
|
|
|
require.True(t, secondUptime.After(firstUptime))
|
|
|
|
|
|
|
|
require.Equal(t, newCapacity, newInfo.Capacity)
|
|
|
|
})
|
|
|
|
}
|
2019-09-19 20:56:34 +01:00
|
|
|
|
2019-09-20 21:02:23 +01:00
|
|
|
func TestRequestInfoEndpointTrustedSatellite(t *testing.T) {
|
2019-09-19 20:56:34 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-09-20 21:02:23 +01:00
|
|
|
SatelliteCount: 2, StorageNodeCount: 1, UplinkCount: 0,
|
2019-09-19 20:56:34 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeDossier := planet.StorageNodes[0].Local()
|
|
|
|
|
|
|
|
// Satellite Trusted
|
|
|
|
conn, err := planet.Satellites[0].Transport.DialNode(ctx, &nodeDossier.Node)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(conn.Close)
|
|
|
|
|
|
|
|
resp, err := pb.NewNodesClient(conn).RequestInfo(ctx, &pb.InfoRequest{})
|
|
|
|
require.NotNil(t, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, nodeDossier.Type, resp.Type)
|
|
|
|
require.Equal(t, &nodeDossier.Operator, resp.Operator)
|
|
|
|
require.Equal(t, &nodeDossier.Capacity, resp.Capacity)
|
2019-09-20 21:02:23 +01:00
|
|
|
require.Equal(t, nodeDossier.Version.GetVersion(), resp.Version.GetVersion())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRequestInfoEndpointUntrustedSatellite(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 2, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
StorageNode: func(index int, config *storagenode.Config) {
|
|
|
|
config.Storage.WhitelistedSatellites = nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeDossier := planet.StorageNodes[0].Local()
|
|
|
|
|
|
|
|
// Satellite Untrusted
|
|
|
|
conn, err := planet.Satellites[0].Transport.DialNode(ctx, &nodeDossier.Node)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(conn.Close)
|
|
|
|
|
|
|
|
resp, err := pb.NewNodesClient(conn).RequestInfo(ctx, &pb.InfoRequest{})
|
|
|
|
require.Nil(t, resp)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Equal(t, status.Errorf(codes.PermissionDenied, "untrusted peer %v", planet.Satellites[0].Local().Id), err)
|
2019-09-19 20:56:34 +01:00
|
|
|
})
|
|
|
|
}
|