2021-01-28 23:26:09 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package server_test
|
|
|
|
|
|
|
|
import (
|
2023-01-31 13:59:04 +00:00
|
|
|
"context"
|
2023-02-01 10:29:43 +00:00
|
|
|
"net"
|
2023-01-31 13:59:04 +00:00
|
|
|
"os"
|
2021-01-28 23:26:09 +00:00
|
|
|
"strconv"
|
2023-01-31 13:59:04 +00:00
|
|
|
"strings"
|
2021-01-28 23:26:09 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-02-01 10:29:43 +00:00
|
|
|
"github.com/zeebo/errs"
|
2023-01-31 13:59:04 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2021-01-28 23:26:09 +00:00
|
|
|
|
2023-01-31 13:59:04 +00:00
|
|
|
"storj.io/common/errs2"
|
|
|
|
"storj.io/common/identity/testidentity"
|
2021-01-28 23:26:09 +00:00
|
|
|
"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"
|
2023-02-01 10:29:43 +00:00
|
|
|
"storj.io/common/sync2"
|
2021-01-28 23:26:09 +00:00
|
|
|
"storj.io/common/testcontext"
|
2023-01-31 13:59:04 +00:00
|
|
|
"storj.io/storj/private/server"
|
2021-01-28 23:26:09 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
|
|
|
)
|
|
|
|
|
2023-01-31 13:59:04 +00:00
|
|
|
func TestServer(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
log := zaptest.NewLogger(t)
|
|
|
|
identity := testidentity.MustPregeneratedIdentity(0, storj.LatestIDVersion())
|
|
|
|
|
|
|
|
host := "127.0.0.1"
|
|
|
|
if hostlist := os.Getenv("STORJ_TEST_HOST"); hostlist != "" {
|
|
|
|
host, _, _ = strings.Cut(hostlist, ";")
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsOptions, err := tlsopts.NewOptions(identity, tlsopts.Config{
|
|
|
|
PeerIDVersions: "latest",
|
|
|
|
}, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
instance, err := server.New(log.Named("server"), tlsOptions, server.Config{
|
|
|
|
Address: host + ":0",
|
|
|
|
PrivateAddress: host + ":0",
|
|
|
|
TCPFastOpen: true,
|
|
|
|
TCPFastOpenQueue: 256,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() {
|
|
|
|
require.NoError(t, instance.Close())
|
|
|
|
}()
|
|
|
|
|
2023-02-01 10:29:43 +00:00
|
|
|
serverCtx, serverCancel := context.WithCancel(ctx)
|
2023-01-31 13:59:04 +00:00
|
|
|
defer serverCancel()
|
|
|
|
|
2023-02-01 10:29:43 +00:00
|
|
|
require.Empty(t, sync2.Concurrently(
|
|
|
|
func() error {
|
|
|
|
err = instance.Run(serverCtx)
|
|
|
|
return errs2.IgnoreCanceled(err)
|
|
|
|
},
|
|
|
|
func() (err error) {
|
|
|
|
defer serverCancel()
|
|
|
|
|
|
|
|
dialer := net.Dialer{}
|
|
|
|
conn, err := dialer.DialContext(ctx, "tcp", instance.PrivateAddr().String())
|
|
|
|
if err != nil {
|
|
|
|
return errs.Wrap(err)
|
|
|
|
}
|
|
|
|
defer func() { err = errs.Combine(err, conn.Close()) }()
|
|
|
|
|
|
|
|
_, err = conn.Write([]byte{1})
|
|
|
|
return errs.Wrap(err)
|
|
|
|
},
|
|
|
|
))
|
2023-01-31 13:59:04 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 23:26:09 +00:00
|
|
|
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) {
|
2023-08-10 13:20:14 +01:00
|
|
|
t.Skip("QUIC is currently broken")
|
|
|
|
|
2021-01-28 23:26:09 +00:00
|
|
|
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
|
|
|
})
|
|
|
|
}
|