2019-09-06 17:14:03 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact_test
|
|
|
|
|
|
|
|
import (
|
2019-09-10 17:05:07 +01:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
|
|
|
"net"
|
2019-09-06 17:14:03 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/rpc/rpcpeer"
|
2022-01-13 22:51:40 +00:00
|
|
|
"storj.io/common/rpc/rpcstatus"
|
2021-04-21 19:20:36 +01:00
|
|
|
"storj.io/common/storj"
|
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-03-24 18:30:27 +00:00
|
|
|
"storj.io/storj/storagenode"
|
2019-09-06 17:14:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSatelliteContactEndpoint(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2020-05-20 14:40:25 +01:00
|
|
|
nodeInfo := planet.StorageNodes[0].Contact.Service.Local()
|
2019-09-10 17:05:07 +01:00
|
|
|
ident := planet.StorageNodes[0].Identity
|
2019-09-06 17:14:03 +01:00
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
peer := rpcpeer.Peer{
|
2019-09-10 17:05:07 +01:00
|
|
|
Addr: &net.TCPAddr{
|
2020-05-20 14:40:25 +01:00
|
|
|
IP: net.ParseIP(nodeInfo.Address),
|
2019-09-10 17:05:07 +01:00
|
|
|
Port: 5,
|
|
|
|
},
|
2019-09-19 05:46:39 +01:00
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
2019-09-10 17:05:07 +01:00
|
|
|
},
|
|
|
|
}
|
2019-09-19 05:46:39 +01:00
|
|
|
peerCtx := rpcpeer.NewContext(ctx, &peer)
|
2019-09-14 01:37:32 +01:00
|
|
|
resp, err := planet.Satellites[0].Contact.Endpoint.CheckIn(peerCtx, &pb.CheckInRequest{
|
2020-05-20 14:40:25 +01:00
|
|
|
Address: nodeInfo.Address,
|
|
|
|
Version: &nodeInfo.Version,
|
|
|
|
Capacity: &nodeInfo.Capacity,
|
|
|
|
Operator: &nodeInfo.Operator,
|
2019-09-06 17:14:03 +01:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2019-09-10 17:05:07 +01:00
|
|
|
require.NotNil(t, resp)
|
2021-03-24 18:30:27 +00:00
|
|
|
require.True(t, resp.PingNodeSuccess)
|
|
|
|
require.True(t, resp.PingNodeSuccessQuic)
|
|
|
|
|
|
|
|
peerID, err := planet.Satellites[0].DB.PeerIdentities().Get(ctx, nodeInfo.ID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, ident.PeerIdentity(), peerID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-21 19:20:36 +01:00
|
|
|
func TestSatelliteContactEndpoint_QUIC_Unreachable(t *testing.T) {
|
2021-03-24 18:30:27 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
|
|
|
StorageNode: func(index int, config *storagenode.Config) {
|
2021-04-21 19:20:36 +01:00
|
|
|
config.Server.DisableQUIC = true
|
2021-03-24 18:30:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeInfo := planet.StorageNodes[0].Contact.Service.Local()
|
|
|
|
ident := planet.StorageNodes[0].Identity
|
|
|
|
|
|
|
|
peer := rpcpeer.Peer{
|
|
|
|
Addr: &net.TCPAddr{
|
|
|
|
IP: net.ParseIP(nodeInfo.Address),
|
|
|
|
Port: 5,
|
|
|
|
},
|
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
peerCtx := rpcpeer.NewContext(ctx, &peer)
|
|
|
|
resp, err := planet.Satellites[0].Contact.Endpoint.CheckIn(peerCtx, &pb.CheckInRequest{
|
|
|
|
Address: nodeInfo.Address,
|
|
|
|
Version: &nodeInfo.Version,
|
|
|
|
Capacity: &nodeInfo.Capacity,
|
|
|
|
Operator: &nodeInfo.Operator,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, resp)
|
2021-04-21 19:20:36 +01:00
|
|
|
require.True(t, resp.PingNodeSuccess)
|
2021-03-24 18:30:27 +00:00
|
|
|
require.False(t, resp.PingNodeSuccessQuic)
|
|
|
|
|
|
|
|
peerID, err := planet.Satellites[0].DB.PeerIdentities().Get(ctx, nodeInfo.ID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, ident.PeerIdentity(), peerID)
|
|
|
|
})
|
|
|
|
}
|
2021-04-21 19:20:36 +01:00
|
|
|
|
|
|
|
func TestSatellitePingBack_Failure(t *testing.T) {
|
2021-03-24 18:30:27 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-04-21 19:20:36 +01:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0,
|
2021-03-24 18:30:27 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2021-04-21 19:20:36 +01:00
|
|
|
pingNodeSuccess, pingNodeSuccessQUIC, pingErrorMessage, err := planet.Satellites[0].Contact.Service.PingBack(ctx, storj.NodeURL{})
|
2019-09-12 17:33:04 +01:00
|
|
|
|
|
|
|
require.NoError(t, err)
|
2021-04-21 19:20:36 +01:00
|
|
|
require.NotEmpty(t, pingErrorMessage)
|
|
|
|
require.False(t, pingNodeSuccess)
|
|
|
|
require.False(t, pingNodeSuccessQUIC)
|
2019-09-06 17:14:03 +01:00
|
|
|
})
|
|
|
|
}
|
2022-01-13 22:51:40 +00:00
|
|
|
|
|
|
|
func TestSatellitePingMeEndpoint(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeInfo := planet.StorageNodes[0].Contact.Service.Local()
|
|
|
|
ident := planet.StorageNodes[0].Identity
|
|
|
|
|
|
|
|
peer := rpcpeer.Peer{
|
|
|
|
Addr: &net.TCPAddr{
|
|
|
|
IP: net.ParseIP(nodeInfo.Address),
|
|
|
|
Port: 5,
|
|
|
|
},
|
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
peerCtx := rpcpeer.NewContext(ctx, &peer)
|
|
|
|
resp, err := planet.Satellites[0].Contact.Endpoint.PingMe(peerCtx, &pb.PingMeRequest{
|
2023-01-30 20:01:32 +00:00
|
|
|
Address: nodeInfo.Address,
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_RPC,
|
2022-01-13 22:51:40 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, resp)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSatellitePingMeEndpoint_QUIC(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
nodeInfo := planet.StorageNodes[0].Contact.Service.Local()
|
|
|
|
ident := planet.StorageNodes[0].Identity
|
|
|
|
|
|
|
|
peer := rpcpeer.Peer{
|
|
|
|
Addr: &net.TCPAddr{
|
|
|
|
IP: net.ParseIP(nodeInfo.Address),
|
|
|
|
Port: 5,
|
|
|
|
},
|
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
peerCtx := rpcpeer.NewContext(ctx, &peer)
|
|
|
|
resp, err := planet.Satellites[0].Contact.Endpoint.PingMe(peerCtx, &pb.PingMeRequest{
|
2023-01-30 20:01:32 +00:00
|
|
|
Address: nodeInfo.Address,
|
|
|
|
Transport: pb.NodeTransport_QUIC_RPC,
|
2022-01-13 22:51:40 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, resp)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSatellitePingMe_Failure(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
resp, err := planet.Satellites[0].Contact.Endpoint.PingMe(ctx, &pb.PingMeRequest{})
|
|
|
|
|
|
|
|
require.NotNil(t, err)
|
|
|
|
require.Equal(t, rpcstatus.Code(err), rpcstatus.Unknown)
|
|
|
|
require.Nil(t, resp)
|
|
|
|
})
|
|
|
|
}
|