2019-09-06 17:14:03 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact_test
|
|
|
|
|
|
|
|
import (
|
2021-04-30 19:40:59 +01:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
2019-09-06 17:14:03 +01:00
|
|
|
"testing"
|
2019-10-28 14:04:31 +00:00
|
|
|
"time"
|
2019-09-06 17:14:03 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2021-06-15 17:32:12 +01:00
|
|
|
"go.uber.org/zap"
|
2019-09-27 16:47:57 +01:00
|
|
|
"golang.org/x/sync/errgroup"
|
2019-09-06 17:14:03 +01:00
|
|
|
|
2021-04-30 19:40:59 +01:00
|
|
|
"storj.io/common/identity/testidentity"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
2021-04-30 19:40:59 +01:00
|
|
|
"storj.io/common/rpc/rpcpeer"
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2021-06-15 17:32:12 +01:00
|
|
|
"storj.io/storj/satellite"
|
2022-01-25 10:51:40 +00:00
|
|
|
"storj.io/storj/storagenode/contact"
|
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) {
|
|
|
|
pingStats := planet.StorageNodes[0].Contact.PingStats
|
|
|
|
|
2020-05-19 16:49:13 +01:00
|
|
|
conn, err := planet.Satellites[0].Dialer.DialNodeURL(ctx, planet.StorageNodes[0].NodeURL())
|
2019-09-06 17:14:03 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(conn.Close)
|
|
|
|
|
2020-03-25 12:15:27 +00:00
|
|
|
resp, err := pb.NewDRPCContactClient(conn).PingNode(ctx, &pb.ContactPingRequest{})
|
2019-09-06 17:14:03 +01:00
|
|
|
require.NotNil(t, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-03 19:31:39 +01:00
|
|
|
firstPing := pingStats.WhenLastPinged()
|
2019-09-06 17:14:03 +01:00
|
|
|
|
2020-10-13 13:47:55 +01:00
|
|
|
time.Sleep(time.Second) // HACKFIX: windows has large time granularity
|
2019-10-28 14:04:31 +00:00
|
|
|
|
2020-03-25 12:15:27 +00:00
|
|
|
resp, err = pb.NewDRPCContactClient(conn).PingNode(ctx, &pb.ContactPingRequest{})
|
2019-09-06 17:14:03 +01:00
|
|
|
require.NotNil(t, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-03 19:31:39 +01:00
|
|
|
secondPing := pingStats.WhenLastPinged()
|
2019-09-06 17:14:03 +01:00
|
|
|
|
|
|
|
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,
|
2021-06-15 17:32:12 +01:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Overlay.NodeCheckInWaitPeriod = 0
|
|
|
|
},
|
|
|
|
},
|
2019-09-13 12:53:48 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
|
2020-02-19 18:32:53 +00:00
|
|
|
node.Contact.Chore.Pause(ctx)
|
2019-09-13 12:53:48 +01:00
|
|
|
oldInfo, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
oldCapacity := oldInfo.Capacity
|
|
|
|
|
|
|
|
newCapacity := pb.NodeCapacity{
|
2020-02-12 21:19:42 +00:00
|
|
|
FreeDisk: 0,
|
2019-09-13 12:53:48 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2020-02-19 18:32:53 +00:00
|
|
|
node.Contact.Chore.TriggerWait(ctx)
|
2019-09-13 12:53:48 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-02-26 02:39:44 +00:00
|
|
|
func TestServicePingSatellites(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 2, StorageNodeCount: 1, UplinkCount: 0,
|
2021-06-15 17:32:12 +01:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
|
|
|
config.Overlay.NodeCheckInWaitPeriod = 0
|
|
|
|
},
|
|
|
|
},
|
2020-02-26 02:39:44 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
node.Contact.Chore.Pause(ctx)
|
|
|
|
|
|
|
|
newCapacity := pb.NodeCapacity{
|
2020-03-23 20:24:11 +00:00
|
|
|
FreeDisk: 0,
|
2020-02-26 02:39:44 +00:00
|
|
|
}
|
|
|
|
for _, satellite := range planet.Satellites {
|
|
|
|
info, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEqual(t, newCapacity, info.Capacity)
|
|
|
|
}
|
|
|
|
|
|
|
|
node.Contact.Service.UpdateSelf(&newCapacity)
|
|
|
|
err := node.Contact.Service.PingSatellites(ctx, 10*time.Second)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, satellite := range planet.Satellites {
|
|
|
|
info, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, newCapacity, info.Capacity)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-30 19:40:59 +01:00
|
|
|
func TestEndpointPingNode_UnTrust(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
node.Contact.Chore.Pause(ctx)
|
|
|
|
|
|
|
|
// make sure a trusted satellite is able to ping node
|
|
|
|
info, err := planet.Satellites[0].Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, node.ID(), info.Id)
|
|
|
|
|
|
|
|
// an untrusted peer shouldn't be able to ping node successfully
|
|
|
|
ident, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
state := tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
|
|
|
}
|
|
|
|
peerCtx := rpcpeer.NewContext(ctx, &rpcpeer.Peer{
|
|
|
|
Addr: node.Server.Addr(),
|
|
|
|
State: state,
|
|
|
|
})
|
|
|
|
_, err = node.Contact.Endpoint.PingNode(peerCtx, &pb.ContactPingRequest{})
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-27 16:47:57 +01:00
|
|
|
func TestLocalAndUpdateSelf(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
var group errgroup.Group
|
|
|
|
group.Go(func() error {
|
|
|
|
_ = node.Contact.Service.Local()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
node.Contact.Service.UpdateSelf(&pb.NodeCapacity{})
|
|
|
|
_ = group.Wait()
|
|
|
|
})
|
|
|
|
}
|
2022-01-12 14:34:32 +00:00
|
|
|
|
|
|
|
func TestServiceRequestPingMeQUIC(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 2, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
node.Contact.Chore.Pause(ctx)
|
|
|
|
|
2022-01-25 10:51:40 +00:00
|
|
|
quicStats, err := node.Contact.Service.RequestPingMeQUIC(ctx)
|
2022-01-12 14:34:32 +00:00
|
|
|
require.NoError(t, err)
|
2022-01-25 10:51:40 +00:00
|
|
|
require.Equal(t, contact.NetworkStatusOk, quicStats.Status())
|
2022-01-12 14:34:32 +00:00
|
|
|
})
|
|
|
|
}
|