2019-06-21 14:39:43 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package testplanet
|
|
|
|
|
|
|
|
import (
|
2019-09-23 20:36:46 +01:00
|
|
|
"context"
|
2019-06-21 14:39:43 +01:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-10-29 11:58:36 +00:00
|
|
|
"runtime/pprof"
|
2019-06-21 14:39:43 +01:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2019-08-19 23:10:38 +01:00
|
|
|
"github.com/zeebo/errs"
|
2020-10-29 11:58:36 +00:00
|
|
|
"go.uber.org/zap"
|
2019-08-19 23:10:38 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/peertls/extensions"
|
|
|
|
"storj.io/common/peertls/tlsopts"
|
|
|
|
"storj.io/common/storj"
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/debug"
|
2019-08-19 23:10:38 +01:00
|
|
|
"storj.io/storj/pkg/revocation"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/pkg/server"
|
2020-04-14 13:39:42 +01:00
|
|
|
"storj.io/storj/storage/filestore"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/storagenode"
|
2019-07-29 15:07:52 +01:00
|
|
|
"storj.io/storj/storagenode/bandwidth"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/storagenode/collector"
|
|
|
|
"storj.io/storj/storagenode/console/consoleserver"
|
2019-09-06 17:14:03 +01:00
|
|
|
"storj.io/storj/storagenode/contact"
|
2019-10-15 16:29:47 +01:00
|
|
|
"storj.io/storj/storagenode/gracefulexit"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/storagenode/monitor"
|
2019-08-08 14:47:04 +01:00
|
|
|
"storj.io/storj/storagenode/nodestats"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/storagenode/orders"
|
2020-04-14 13:39:42 +01:00
|
|
|
"storj.io/storj/storagenode/pieces"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/storagenode/piecestore"
|
2020-01-10 01:58:59 +00:00
|
|
|
"storj.io/storj/storagenode/preflight"
|
2019-08-19 19:52:47 +01:00
|
|
|
"storj.io/storj/storagenode/retain"
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/storagenode/storagenodedb"
|
2019-11-16 00:59:32 +00:00
|
|
|
"storj.io/storj/storagenode/trust"
|
2019-06-21 14:39:43 +01:00
|
|
|
)
|
|
|
|
|
2020-03-27 14:46:40 +00:00
|
|
|
// StorageNode contains all the processes needed to run a full StorageNode setup.
|
|
|
|
type StorageNode struct {
|
2020-10-29 11:58:36 +00:00
|
|
|
Name string
|
2020-03-27 14:46:40 +00:00
|
|
|
Config storagenode.Config
|
|
|
|
*storagenode.Peer
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
// Label returns name for debugger.
|
|
|
|
func (system *StorageNode) Label() string { return system.Name }
|
|
|
|
|
2020-04-16 13:12:46 +01:00
|
|
|
// URL returns the node url as a string.
|
|
|
|
func (system *StorageNode) URL() string { return system.NodeURL().String() }
|
|
|
|
|
|
|
|
// NodeURL returns the storj.NodeURL.
|
|
|
|
func (system *StorageNode) NodeURL() storj.NodeURL {
|
|
|
|
return storj.NodeURL{ID: system.Peer.ID(), Address: system.Peer.Addr()}
|
2020-03-27 14:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// newStorageNodes initializes storage nodes.
|
2020-10-29 11:58:36 +00:00
|
|
|
func (planet *Planet) newStorageNodes(ctx context.Context, count int, whitelistedSatellites storj.NodeURLs) ([]*StorageNode, error) {
|
2019-11-16 00:59:32 +00:00
|
|
|
var sources []trust.Source
|
|
|
|
for _, u := range whitelistedSatellites {
|
|
|
|
source, err := trust.NewStaticURLSource(u.String())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
sources = append(sources, source)
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
var xs []*StorageNode
|
2019-06-21 14:39:43 +01:00
|
|
|
for i := 0; i < count; i++ {
|
2020-10-29 11:58:36 +00:00
|
|
|
index := i
|
|
|
|
prefix := "storage" + strconv.Itoa(index)
|
2019-06-21 14:39:43 +01:00
|
|
|
log := planet.log.Named(prefix)
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
var system *StorageNode
|
|
|
|
var err error
|
|
|
|
pprof.Do(ctx, pprof.Labels("peer", prefix), func(ctx context.Context) {
|
|
|
|
system, err = planet.newStorageNode(ctx, prefix, index, count, log, sources)
|
|
|
|
})
|
2019-06-21 14:39:43 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
log.Debug("id=" + system.ID().String() + " addr=" + system.Addr())
|
|
|
|
xs = append(xs, system)
|
|
|
|
planet.peers = append(planet.peers, newClosablePeer(system))
|
|
|
|
}
|
|
|
|
return xs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (planet *Planet) newStorageNode(ctx context.Context, prefix string, index, count int, log *zap.Logger, sources []trust.Source) (*StorageNode, error) {
|
|
|
|
storageDir := filepath.Join(planet.directory, prefix)
|
|
|
|
if err := os.MkdirAll(storageDir, 0700); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
identity, err := planet.NewIdentity()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
config := storagenode.Config{
|
|
|
|
Server: server.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
|
|
|
PrivateAddress: "127.0.0.1:0",
|
|
|
|
|
|
|
|
Config: tlsopts.Config{
|
|
|
|
RevocationDBURL: "bolt://" + filepath.Join(storageDir, "revocation.db"),
|
|
|
|
UsePeerCAWhitelist: true,
|
|
|
|
PeerCAWhitelistPath: planet.whitelistPath,
|
|
|
|
PeerIDVersions: "*",
|
|
|
|
Extensions: extensions.Config{
|
|
|
|
Revocation: false,
|
|
|
|
WhitelistSignedLeaf: false,
|
2019-11-16 00:59:32 +00:00
|
|
|
},
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
},
|
|
|
|
Debug: debug.Config{
|
|
|
|
Address: "",
|
|
|
|
},
|
|
|
|
Preflight: preflight.Config{
|
|
|
|
LocalTimeCheck: false,
|
|
|
|
},
|
|
|
|
Operator: storagenode.OperatorConfig{
|
2021-01-18 14:33:13 +00:00
|
|
|
Email: prefix + "@mail.test",
|
|
|
|
Wallet: "0x" + strings.Repeat("00", 20),
|
|
|
|
WalletFeatures: nil,
|
2020-10-29 11:58:36 +00:00
|
|
|
},
|
|
|
|
Storage: piecestore.OldConfig{
|
|
|
|
Path: filepath.Join(storageDir, "pieces/"),
|
|
|
|
AllocatedDiskSpace: 1 * memory.GB,
|
|
|
|
KBucketRefreshInterval: defaultInterval,
|
|
|
|
},
|
|
|
|
Collector: collector.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
},
|
|
|
|
Nodestats: nodestats.Config{
|
|
|
|
MaxSleep: 0,
|
|
|
|
ReputationSync: defaultInterval,
|
|
|
|
StorageSync: defaultInterval,
|
|
|
|
},
|
|
|
|
Console: consoleserver.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
|
|
|
StaticDir: filepath.Join(developmentRoot, "web/storagenode/"),
|
|
|
|
},
|
|
|
|
Storage2: piecestore.Config{
|
|
|
|
CacheSyncInterval: defaultInterval,
|
|
|
|
ExpirationGracePeriod: 0,
|
|
|
|
MaxConcurrentRequests: 100,
|
|
|
|
OrderLimitGracePeriod: time.Hour,
|
|
|
|
StreamOperationTimeout: time.Hour,
|
|
|
|
ReportCapacityThreshold: 100 * memory.MB,
|
|
|
|
DeleteQueueSize: 10000,
|
|
|
|
DeleteWorkers: 1,
|
|
|
|
Orders: orders.Config{
|
|
|
|
SenderInterval: defaultInterval,
|
|
|
|
SenderTimeout: 10 * time.Minute,
|
|
|
|
CleanupInterval: defaultInterval,
|
|
|
|
ArchiveTTL: time.Hour,
|
|
|
|
MaxSleep: 0,
|
|
|
|
Path: filepath.Join(storageDir, "orders"),
|
2019-07-29 15:07:52 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
Monitor: monitor.Config{
|
|
|
|
MinimumDiskSpace: 100 * memory.MB,
|
|
|
|
NotifyLowDiskCooldown: defaultInterval,
|
|
|
|
VerifyDirReadableInterval: defaultInterval,
|
|
|
|
VerifyDirWritableInterval: defaultInterval,
|
2019-09-06 17:14:03 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
Trust: trust.Config{
|
|
|
|
Sources: sources,
|
|
|
|
CachePath: filepath.Join(storageDir, "trust-cache.json"),
|
|
|
|
RefreshInterval: defaultInterval,
|
2019-10-15 16:29:47 +01:00
|
|
|
},
|
2020-10-29 11:58:36 +00:00
|
|
|
MaxUsedSerialsSize: memory.MiB,
|
|
|
|
},
|
|
|
|
Pieces: pieces.DefaultConfig,
|
|
|
|
Filestore: filestore.DefaultConfig,
|
|
|
|
Retain: retain.Config{
|
|
|
|
MaxTimeSkew: 10 * time.Second,
|
|
|
|
Status: retain.Enabled,
|
|
|
|
Concurrency: 5,
|
|
|
|
},
|
|
|
|
Version: planet.NewVersionConfig(),
|
|
|
|
Bandwidth: bandwidth.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
},
|
|
|
|
Contact: contact.Config{
|
|
|
|
Interval: defaultInterval,
|
|
|
|
},
|
|
|
|
GracefulExit: gracefulexit.Config{
|
|
|
|
ChoreInterval: defaultInterval,
|
|
|
|
NumWorkers: 3,
|
|
|
|
NumConcurrentTransfers: 1,
|
|
|
|
MinBytesPerSecond: 128 * memory.B,
|
|
|
|
MinDownloadTimeout: 2 * time.Minute,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if planet.config.Reconfigure.StorageNode != nil {
|
|
|
|
planet.config.Reconfigure.StorageNode(index, &config)
|
|
|
|
}
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
newIPCount := planet.config.Reconfigure.UniqueIPCount
|
|
|
|
if newIPCount > 0 {
|
|
|
|
if index >= count-newIPCount {
|
|
|
|
config.Server.Address = fmt.Sprintf("127.0.%d.1:0", index+1)
|
|
|
|
config.Server.PrivateAddress = fmt.Sprintf("127.0.%d.1:0", index+1)
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
}
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
verisonInfo := planet.NewVersionInfo()
|
2019-08-07 15:52:00 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
var db storagenode.DB
|
|
|
|
db, err = storagenodedb.OpenNew(ctx, log.Named("db"), config.DatabaseConfig())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-08-07 15:52:00 +01:00
|
|
|
|
2020-11-06 18:45:58 +00:00
|
|
|
if err := db.Pieces().CreateVerificationFile(identity.ID); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
if planet.config.Reconfigure.StorageNodeDB != nil {
|
|
|
|
db, err = planet.config.Reconfigure.StorageNodeDB(index, db, planet.log)
|
2019-08-19 23:10:38 +01:00
|
|
|
if err != nil {
|
2020-10-29 11:58:36 +00:00
|
|
|
return nil, err
|
2019-08-19 23:10:38 +01:00
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
}
|
2019-08-19 23:10:38 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
revocationDB, err := revocation.OpenDBFromCfg(ctx, config.Server.Config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, revocationDB)
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
peer, err := storagenode.New(log, identity, db, revocationDB, config, verisonInfo, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-28 22:57:29 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
// Mark the peer's PieceDeleter as in testing mode, so it is easy to wait on the deleter
|
|
|
|
peer.Storage2.PieceDeleter.SetupTest()
|
2019-08-07 15:52:00 +01:00
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
err = db.MigrateToLatest(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|
2020-10-29 11:58:36 +00:00
|
|
|
planet.databases = append(planet.databases, db)
|
|
|
|
return &StorageNode{
|
|
|
|
Name: prefix,
|
|
|
|
Config: config,
|
|
|
|
Peer: peer,
|
|
|
|
}, nil
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|