2019-02-05 17:57:56 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package kademlia_test
|
|
|
|
|
|
|
|
import (
|
2019-03-22 17:09:37 +00:00
|
|
|
"context"
|
2019-02-05 17:57:56 +00:00
|
|
|
"testing"
|
2019-03-22 17:09:37 +00:00
|
|
|
"time"
|
2019-02-05 17:57:56 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-03-22 17:09:37 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-02-05 17:57:56 +00:00
|
|
|
|
2019-03-22 17:09:37 +00:00
|
|
|
"storj.io/storj/internal/memory"
|
2019-02-05 17:57:56 +00:00
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
2019-03-22 17:09:37 +00:00
|
|
|
"storj.io/storj/pkg/kademlia"
|
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
"storj.io/storj/pkg/peertls/tlsopts"
|
|
|
|
"storj.io/storj/pkg/transport"
|
2019-02-05 17:57:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFetchPeerIdentity(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
peerID, err := planet.StorageNodes[0].Kademlia.Service.FetchPeerIdentity(ctx, sat.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, sat.ID(), peerID.ID)
|
|
|
|
require.True(t, sat.Identity.Leaf.Equal(peerID.Leaf))
|
|
|
|
require.True(t, sat.Identity.CA.Equal(peerID.CA))
|
|
|
|
})
|
|
|
|
}
|
2019-02-25 18:41:51 +00:00
|
|
|
|
|
|
|
func TestRequestInfo(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]
|
2019-03-02 07:34:08 +00:00
|
|
|
info, err := planet.Satellites[0].Kademlia.Service.FetchInfo(ctx, node.Local())
|
2019-02-25 18:41:51 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, node.Local().Type, info.GetType())
|
|
|
|
require.Equal(t, node.Local().Metadata.GetEmail(), info.GetOperator().GetEmail())
|
|
|
|
require.Equal(t, node.Local().Metadata.GetWallet(), info.GetOperator().GetWallet())
|
|
|
|
require.Equal(t, node.Local().Restrictions.GetFreeDisk(), info.GetCapacity().GetFreeDisk())
|
|
|
|
require.Equal(t, node.Local().Restrictions.GetFreeBandwidth(), info.GetCapacity().GetFreeBandwidth())
|
|
|
|
})
|
|
|
|
}
|
2019-03-22 17:09:37 +00:00
|
|
|
|
|
|
|
func TestPingTimeout(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
|
|
|
|
self := planet.StorageNodes[0]
|
|
|
|
routingTable := self.Kademlia.RoutingTable
|
|
|
|
|
|
|
|
tlsOpts, err := tlsopts.NewOptions(self.Identity, tlsopts.Config{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
self.Transport = transport.NewClientWithTimeout(tlsOpts, 1*time.Millisecond)
|
|
|
|
|
|
|
|
network := &transport.SimulatedNetwork{
|
|
|
|
DialLatency: 300 * time.Second,
|
|
|
|
BytesPerSecond: 1 * memory.KB,
|
|
|
|
}
|
|
|
|
|
|
|
|
slowClient := network.NewClient(self.Transport)
|
|
|
|
require.NotNil(t, slowClient)
|
|
|
|
|
|
|
|
node := pb.Node{
|
|
|
|
Id: self.ID(),
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
newService, err := kademlia.NewService(zaptest.NewLogger(t), node, slowClient, routingTable, kademlia.Config{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
target := pb.Node{
|
|
|
|
Id: planet.StorageNodes[2].ID(),
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
Address: planet.StorageNodes[2].Addr(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = newService.Ping(ctx, target)
|
|
|
|
require.Error(t, err, context.DeadlineExceeded)
|
|
|
|
require.True(t, kademlia.NodeErr.Has(err) && transport.Error.Has(err))
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|