2021-01-28 23:26:09 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package server_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/common/peertls/tlsopts"
|
2021-08-03 04:25:41 +01:00
|
|
|
"storj.io/common/rpc"
|
|
|
|
_ "storj.io/common/rpc/quic"
|
2021-01-28 23:26:09 +00:00
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHybridConnector_Basic(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 0,
|
|
|
|
UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
dialer := planet.Uplinks[0].Dialer
|
|
|
|
|
2021-08-03 04:25:41 +01:00
|
|
|
dialer.Connector = rpc.NewHybridConnector()
|
2021-01-28 23:26:09 +00:00
|
|
|
|
2021-05-03 23:40:30 +01:00
|
|
|
conn, err := dialer.Connector.DialContext(ctx, dialer.TLSOptions.ClientTLSConfig(sat.ID()), sat.Addr())
|
2021-01-28 23:26:09 +00:00
|
|
|
require.NoError(t, err)
|
2021-05-03 23:40:30 +01:00
|
|
|
require.NoError(t, conn.Close())
|
2021-01-28 23:26:09 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHybridConnector_QUICOnly(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 0,
|
|
|
|
UplinkCount: 0,
|
|
|
|
Reconfigure: testplanet.DisableTCP,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
identity, err := planet.NewIdentity()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tlsOptions, err := tlsopts.NewOptions(identity, tlsopts.Config{
|
|
|
|
PeerIDVersions: strconv.Itoa(int(storj.LatestIDVersion().Number)),
|
|
|
|
}, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-08-03 04:25:41 +01:00
|
|
|
connector := rpc.NewHybridConnector()
|
2021-01-28 23:26:09 +00:00
|
|
|
|
|
|
|
conn, err := connector.DialContext(ctx, tlsOptions.ClientTLSConfig(sat.ID()), sat.Addr())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "udp", conn.LocalAddr().Network())
|
2021-05-03 23:40:30 +01:00
|
|
|
require.NoError(t, conn.Close())
|
2021-01-28 23:26:09 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHybridConnector_TCPOnly(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1,
|
|
|
|
StorageNodeCount: 0,
|
|
|
|
UplinkCount: 0,
|
|
|
|
Reconfigure: testplanet.DisableQUIC,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
sat := planet.Satellites[0]
|
|
|
|
identity, err := planet.NewIdentity()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tlsOptions, err := tlsopts.NewOptions(identity, tlsopts.Config{
|
|
|
|
PeerIDVersions: strconv.Itoa(int(storj.LatestIDVersion().Number)),
|
|
|
|
}, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-08-03 04:25:41 +01:00
|
|
|
connector := rpc.NewHybridConnector()
|
2021-01-28 23:26:09 +00:00
|
|
|
|
|
|
|
conn, err := connector.DialContext(ctx, tlsOptions.ClientTLSConfig(sat.ID()), sat.Addr())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "tcp", conn.LocalAddr().Network())
|
2021-05-03 23:40:30 +01:00
|
|
|
require.NoError(t, conn.Close())
|
2021-01-28 23:26:09 +00:00
|
|
|
})
|
|
|
|
}
|