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"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2019-08-19 23:10:38 +01:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2019-06-21 14:39:43 +01:00
|
|
|
"storj.io/storj/internal/memory"
|
|
|
|
"storj.io/storj/pkg/peertls/extensions"
|
|
|
|
"storj.io/storj/pkg/peertls/tlsopts"
|
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"
|
2019-07-03 18:29:18 +01:00
|
|
|
"storj.io/storj/pkg/storj"
|
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-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"
|
|
|
|
"storj.io/storj/storagenode/piecestore"
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// newStorageNodes initializes storage nodes
|
2019-07-03 18:29:18 +01:00
|
|
|
func (planet *Planet) newStorageNodes(count int, whitelistedSatellites storj.NodeURLs) ([]*storagenode.Peer, error) {
|
2019-06-21 14:39:43 +01:00
|
|
|
var xs []*storagenode.Peer
|
|
|
|
defer func() {
|
|
|
|
for _, x := range xs {
|
|
|
|
planet.peers = append(planet.peers, closablePeer{peer: x})
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
prefix := "storage" + strconv.Itoa(i)
|
|
|
|
log := planet.log.Named(prefix)
|
|
|
|
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-10-01 00:33:00 +01:00
|
|
|
Operator: storagenode.OperatorConfig{
|
|
|
|
Email: prefix + "@mail.test",
|
|
|
|
Wallet: "0x" + strings.Repeat("00", 20),
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
|
|
|
Storage: piecestore.OldConfig{
|
2019-08-07 15:52:00 +01:00
|
|
|
Path: filepath.Join(storageDir, "pieces/"),
|
2019-06-21 14:39:43 +01:00
|
|
|
AllocatedDiskSpace: 1 * memory.GB,
|
|
|
|
AllocatedBandwidth: memory.TB,
|
2019-09-25 16:41:24 +01:00
|
|
|
KBucketRefreshInterval: defaultInterval,
|
2019-07-03 18:29:18 +01:00
|
|
|
WhitelistedSatellites: whitelistedSatellites,
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
|
|
|
Collector: collector.Config{
|
2019-09-25 16:41:24 +01:00
|
|
|
Interval: defaultInterval,
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
2019-08-08 14:47:04 +01:00
|
|
|
Nodestats: nodestats.Config{
|
2019-08-09 12:12:32 +01:00
|
|
|
MaxSleep: 0,
|
2019-09-25 16:41:24 +01:00
|
|
|
ReputationSync: defaultInterval,
|
|
|
|
StorageSync: defaultInterval,
|
2019-08-08 14:47:04 +01:00
|
|
|
},
|
2019-06-21 14:39:43 +01:00
|
|
|
Console: consoleserver.Config{
|
|
|
|
Address: "127.0.0.1:0",
|
2019-09-12 13:20:52 +01:00
|
|
|
StaticDir: filepath.Join(developmentRoot, "web/storagenode/"),
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
|
|
|
Storage2: piecestore.Config{
|
2019-09-25 16:41:24 +01:00
|
|
|
CacheSyncInterval: defaultInterval,
|
2019-07-03 14:47:55 +01:00
|
|
|
ExpirationGracePeriod: 0,
|
|
|
|
MaxConcurrentRequests: 100,
|
2019-07-09 22:16:30 +01:00
|
|
|
OrderLimitGracePeriod: time.Hour,
|
2019-08-22 15:33:14 +01:00
|
|
|
Orders: orders.Config{
|
2019-09-25 16:41:24 +01:00
|
|
|
SenderInterval: defaultInterval,
|
|
|
|
SenderTimeout: 10 * time.Minute,
|
|
|
|
CleanupInterval: defaultInterval,
|
2019-08-22 15:33:14 +01:00
|
|
|
ArchiveTTL: time.Hour,
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
|
|
|
Monitor: monitor.Config{
|
|
|
|
MinimumBandwidth: 100 * memory.MB,
|
|
|
|
MinimumDiskSpace: 100 * memory.MB,
|
|
|
|
},
|
2019-08-19 19:52:47 +01:00
|
|
|
},
|
|
|
|
Retain: retain.Config{
|
2019-08-28 21:35:25 +01:00
|
|
|
Status: retain.Enabled,
|
|
|
|
Concurrency: 5,
|
2019-06-21 14:39:43 +01:00
|
|
|
},
|
|
|
|
Version: planet.NewVersionConfig(),
|
2019-07-29 15:07:52 +01:00
|
|
|
Bandwidth: bandwidth.Config{
|
2019-09-25 16:41:24 +01:00
|
|
|
Interval: defaultInterval,
|
2019-07-29 15:07:52 +01:00
|
|
|
},
|
2019-09-06 17:14:03 +01:00
|
|
|
Contact: contact.Config{
|
2019-09-25 16:41:24 +01:00
|
|
|
Interval: defaultInterval,
|
2019-09-06 17:14:03 +01:00
|
|
|
MaxSleep: 0 * time.Second,
|
|
|
|
},
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|
|
|
|
if planet.config.Reconfigure.StorageNode != nil {
|
|
|
|
planet.config.Reconfigure.StorageNode(i, &config)
|
|
|
|
}
|
|
|
|
|
|
|
|
newIPCount := planet.config.Reconfigure.NewIPCount
|
|
|
|
if newIPCount > 0 {
|
|
|
|
if i >= count-newIPCount {
|
2019-06-24 16:33:18 +01:00
|
|
|
config.Server.Address = fmt.Sprintf("127.0.%d.1:0", i+1)
|
|
|
|
config.Server.PrivateAddress = fmt.Sprintf("127.0.%d.1:0", i+1)
|
2019-06-21 14:39:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-22 12:40:15 +01:00
|
|
|
verisonInfo := planet.NewVersionInfo()
|
2019-06-21 14:39:43 +01:00
|
|
|
|
2019-08-07 15:52:00 +01:00
|
|
|
storageConfig := storagenodedb.Config{
|
2019-09-19 20:56:34 +01:00
|
|
|
Storage: config.Storage.Path,
|
|
|
|
Info: filepath.Join(config.Storage.Path, "piecestore.db"),
|
|
|
|
Info2: filepath.Join(config.Storage.Path, "info.db"),
|
|
|
|
Pieces: config.Storage.Path,
|
2019-08-07 15:52:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var db storagenode.DB
|
|
|
|
db, err = storagenodedb.New(log.Named("db"), storageConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if planet.config.Reconfigure.NewStorageNodeDB != nil {
|
|
|
|
db, err = planet.config.Reconfigure.NewStorageNodeDB(i, db, planet.log)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-20 16:04:17 +01:00
|
|
|
revocationDB, err := revocation.NewDBFromCfg(config.Server.Config)
|
2019-08-19 23:10:38 +01:00
|
|
|
if err != nil {
|
2019-08-20 16:04:17 +01:00
|
|
|
return xs, errs.Wrap(err)
|
2019-08-19 23:10:38 +01:00
|
|
|
}
|
2019-08-20 16:04:17 +01:00
|
|
|
planet.databases = append(planet.databases, revocationDB)
|
2019-08-19 23:10:38 +01:00
|
|
|
|
2019-08-22 12:40:15 +01:00
|
|
|
peer, err := storagenode.New(log, identity, db, revocationDB, config, verisonInfo)
|
2019-06-21 14:39:43 +01:00
|
|
|
if err != nil {
|
|
|
|
return xs, err
|
|
|
|
}
|
|
|
|
|
2019-09-23 20:36:46 +01:00
|
|
|
err = db.CreateTables(context.TODO())
|
2019-08-07 15:52:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
planet.databases = append(planet.databases, db)
|
|
|
|
|
2019-06-21 14:39:43 +01:00
|
|
|
log.Debug("id=" + peer.ID().String() + " addr=" + peer.Addr())
|
|
|
|
xs = append(xs, peer)
|
|
|
|
}
|
|
|
|
return xs, nil
|
|
|
|
}
|