2019-01-10 13:13:27 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package storagenode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-06-20 12:52:32 +01:00
|
|
|
"net"
|
2019-10-08 09:52:19 +01:00
|
|
|
"net/http"
|
2019-11-26 16:25:21 +00:00
|
|
|
"time"
|
2019-01-10 13:13:27 +00:00
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
2019-09-19 20:56:34 +01:00
|
|
|
"gopkg.in/spacemonkeygo/monkit.v2"
|
2019-01-10 13:13:27 +00:00
|
|
|
|
|
|
|
"storj.io/storj/pkg/identity"
|
|
|
|
"storj.io/storj/pkg/pb"
|
2019-08-19 23:10:38 +01:00
|
|
|
"storj.io/storj/pkg/peertls/extensions"
|
2019-02-11 11:17:32 +00:00
|
|
|
"storj.io/storj/pkg/peertls/tlsopts"
|
2019-09-19 05:46:39 +01:00
|
|
|
"storj.io/storj/pkg/rpc"
|
2019-01-10 13:13:27 +00:00
|
|
|
"storj.io/storj/pkg/server"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/pkg/signing"
|
2019-01-10 13:13:27 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/errs2"
|
|
|
|
"storj.io/storj/private/version"
|
|
|
|
"storj.io/storj/private/version/checker"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
2019-01-10 13:13:27 +00:00
|
|
|
"storj.io/storj/storage"
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/storagenode/bandwidth"
|
2019-05-08 12:11:59 +01:00
|
|
|
"storj.io/storj/storagenode/collector"
|
2019-06-20 12:52:32 +01:00
|
|
|
"storj.io/storj/storagenode/console"
|
2019-10-08 09:52:19 +01:00
|
|
|
"storj.io/storj/storagenode/console/consoleassets"
|
2019-06-20 12:52:32 +01:00
|
|
|
"storj.io/storj/storagenode/console/consoleserver"
|
2019-09-04 20:04:18 +01:00
|
|
|
"storj.io/storj/storagenode/contact"
|
2019-10-11 14:58:12 +01:00
|
|
|
"storj.io/storj/storagenode/gracefulexit"
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/storagenode/inspector"
|
|
|
|
"storj.io/storj/storagenode/monitor"
|
2019-06-26 19:55:22 +01:00
|
|
|
"storj.io/storj/storagenode/nodestats"
|
2019-12-16 17:59:01 +00:00
|
|
|
"storj.io/storj/storagenode/notifications"
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/storagenode/orders"
|
|
|
|
"storj.io/storj/storagenode/pieces"
|
|
|
|
"storj.io/storj/storagenode/piecestore"
|
2019-08-08 14:47:04 +01:00
|
|
|
"storj.io/storj/storagenode/reputation"
|
2019-08-19 19:52:47 +01:00
|
|
|
"storj.io/storj/storagenode/retain"
|
2019-10-01 15:34:03 +01:00
|
|
|
"storj.io/storj/storagenode/satellites"
|
2019-08-08 14:47:04 +01:00
|
|
|
"storj.io/storj/storagenode/storageusage"
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/storagenode/trust"
|
2019-01-10 13:13:27 +00:00
|
|
|
)
|
|
|
|
|
2019-06-04 13:31:39 +01:00
|
|
|
var (
|
|
|
|
mon = monkit.Package()
|
|
|
|
)
|
|
|
|
|
2019-01-10 13:13:27 +00:00
|
|
|
// DB is the master database for Storage Node
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Master Database
|
2019-01-10 13:13:27 +00:00
|
|
|
type DB interface {
|
2019-01-24 20:28:06 +00:00
|
|
|
// CreateTables initializes the database
|
2019-09-23 20:36:46 +01:00
|
|
|
CreateTables(ctx context.Context) error
|
2019-01-24 20:28:06 +00:00
|
|
|
// Close closes the database
|
|
|
|
Close() error
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
Pieces() storage.Blobs
|
|
|
|
|
|
|
|
Orders() orders.DB
|
2019-08-08 02:47:30 +01:00
|
|
|
V0PieceInfo() pieces.V0PieceInfoDB
|
|
|
|
PieceExpirationDB() pieces.PieceExpirationDB
|
2019-08-12 22:43:05 +01:00
|
|
|
PieceSpaceUsedDB() pieces.PieceSpaceUsedDB
|
2019-03-18 10:55:06 +00:00
|
|
|
Bandwidth() bandwidth.DB
|
|
|
|
UsedSerials() piecestore.UsedSerials
|
2019-08-08 14:47:04 +01:00
|
|
|
Reputation() reputation.DB
|
|
|
|
StorageUsage() storageusage.DB
|
2019-10-01 15:34:03 +01:00
|
|
|
Satellites() satellites.DB
|
2019-12-16 17:59:01 +00:00
|
|
|
Notifications() notifications.DB
|
2019-01-10 13:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Config is all the configuration parameters for a Storage Node
|
|
|
|
type Config struct {
|
2019-01-25 14:54:54 +00:00
|
|
|
Identity identity.Config
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
Server server.Config
|
|
|
|
|
|
|
|
Contact contact.Config
|
2019-10-01 00:33:00 +01:00
|
|
|
Operator OperatorConfig
|
2019-03-18 10:55:06 +00:00
|
|
|
|
2019-05-08 12:11:59 +01:00
|
|
|
// TODO: flatten storage config and only keep the new one
|
|
|
|
Storage piecestore.OldConfig
|
|
|
|
Storage2 piecestore.Config
|
|
|
|
Collector collector.Config
|
2019-04-03 20:13:39 +01:00
|
|
|
|
2019-08-19 19:52:47 +01:00
|
|
|
Retain retain.Config
|
|
|
|
|
2019-08-08 14:47:04 +01:00
|
|
|
Nodestats nodestats.Config
|
|
|
|
|
2019-06-20 12:52:32 +01:00
|
|
|
Console consoleserver.Config
|
|
|
|
|
2019-10-20 08:56:23 +01:00
|
|
|
Version checker.Config
|
2019-07-29 15:07:52 +01:00
|
|
|
|
|
|
|
Bandwidth bandwidth.Config
|
2019-10-15 16:29:47 +01:00
|
|
|
|
|
|
|
GracefulExit gracefulexit.Config
|
2019-01-10 13:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify verifies whether configuration is consistent and acceptable.
|
2019-01-23 10:39:03 +00:00
|
|
|
func (config *Config) Verify(log *zap.Logger) error {
|
2019-10-01 00:33:00 +01:00
|
|
|
return config.Operator.Verify(log)
|
2019-01-10 13:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Peer is the representation of a Storage Node.
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Peer
|
2019-01-10 13:13:27 +00:00
|
|
|
type Peer struct {
|
|
|
|
// core dependencies
|
|
|
|
Log *zap.Logger
|
|
|
|
Identity *identity.FullIdentity
|
|
|
|
DB DB
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
Dialer rpc.Dialer
|
2019-01-23 10:39:03 +00:00
|
|
|
|
2019-03-07 18:19:37 +00:00
|
|
|
Server *server.Server
|
2019-01-10 13:13:27 +00:00
|
|
|
|
2019-10-20 08:56:23 +01:00
|
|
|
Version *checker.Service
|
2019-04-03 20:13:39 +01:00
|
|
|
|
2019-01-10 13:13:27 +00:00
|
|
|
// services and endpoints
|
2019-11-04 19:01:02 +00:00
|
|
|
// TODO: similar grouping to satellite.Core
|
2019-01-10 13:13:27 +00:00
|
|
|
|
2019-09-04 20:04:18 +01:00
|
|
|
Contact struct {
|
2019-09-19 20:56:34 +01:00
|
|
|
Service *contact.Service
|
2019-09-06 17:14:03 +01:00
|
|
|
Chore *contact.Chore
|
2019-09-19 20:56:34 +01:00
|
|
|
Endpoint *contact.Endpoint
|
2019-09-06 17:14:03 +01:00
|
|
|
PingStats *contact.PingStats
|
2019-09-04 20:04:18 +01:00
|
|
|
}
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
Storage2 struct {
|
2019-05-08 12:11:59 +01:00
|
|
|
// TODO: lift things outside of it to organize better
|
2019-08-19 19:52:47 +01:00
|
|
|
Trust *trust.Pool
|
|
|
|
Store *pieces.Store
|
2019-11-26 16:25:21 +00:00
|
|
|
TrashChore *pieces.TrashChore
|
2019-08-19 19:52:47 +01:00
|
|
|
BlobsCache *pieces.BlobsUsageCache
|
|
|
|
CacheService *pieces.CacheService
|
|
|
|
RetainService *retain.Service
|
|
|
|
Endpoint *piecestore.Endpoint
|
|
|
|
Inspector *inspector.Endpoint
|
|
|
|
Monitor *monitor.Service
|
2019-08-22 15:33:14 +01:00
|
|
|
Orders *orders.Service
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
2019-05-08 12:11:59 +01:00
|
|
|
|
|
|
|
Collector *collector.Service
|
2019-06-20 12:52:32 +01:00
|
|
|
|
2019-08-08 14:47:04 +01:00
|
|
|
NodeStats struct {
|
|
|
|
Service *nodestats.Service
|
|
|
|
Cache *nodestats.Cache
|
|
|
|
}
|
2019-06-26 19:55:22 +01:00
|
|
|
|
2019-06-20 12:52:32 +01:00
|
|
|
// Web server with web UI
|
|
|
|
Console struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Service *console.Service
|
|
|
|
Endpoint *consoleserver.Server
|
|
|
|
}
|
2019-07-29 15:07:52 +01:00
|
|
|
|
2019-10-11 14:58:12 +01:00
|
|
|
GracefulExit struct {
|
|
|
|
Endpoint *gracefulexit.Endpoint
|
2019-10-15 16:29:47 +01:00
|
|
|
Chore *gracefulexit.Chore
|
2019-10-11 14:58:12 +01:00
|
|
|
}
|
|
|
|
|
2019-07-29 15:07:52 +01:00
|
|
|
Bandwidth *bandwidth.Service
|
2019-01-10 13:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates a new Storage Node.
|
2019-08-20 16:04:17 +01:00
|
|
|
func New(log *zap.Logger, full *identity.FullIdentity, db DB, revocationDB extensions.RevocationDB, config Config, versionInfo version.Info) (*Peer, error) {
|
2019-01-10 13:13:27 +00:00
|
|
|
peer := &Peer{
|
2019-02-11 11:17:32 +00:00
|
|
|
Log: log,
|
|
|
|
Identity: full,
|
|
|
|
DB: db,
|
2019-01-10 13:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
2019-04-03 20:13:39 +01:00
|
|
|
{
|
2019-10-21 11:50:59 +01:00
|
|
|
if !versionInfo.IsZero() {
|
2019-04-03 20:13:39 +01:00
|
|
|
peer.Log.Sugar().Debugf("Binary Version: %s with CommitHash %s, built at %s as Release %v",
|
|
|
|
versionInfo.Version.String(), versionInfo.CommitHash, versionInfo.Timestamp.String(), versionInfo.Release)
|
|
|
|
}
|
2019-10-20 08:56:23 +01:00
|
|
|
peer.Version = checker.NewService(log.Named("version"), config.Version, versionInfo, "Storagenode")
|
2019-04-03 20:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 13:13:27 +00:00
|
|
|
{ // setup listener and server
|
2019-03-07 18:19:37 +00:00
|
|
|
sc := config.Server
|
2019-08-19 23:10:38 +01:00
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
tlsOptions, err := tlsopts.NewOptions(peer.Identity, sc.Config, revocationDB)
|
2019-01-10 13:13:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Dialer = rpc.NewDefaultDialer(tlsOptions)
|
2019-01-10 13:13:27 +00:00
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Server, err = server.New(log.Named("server"), tlsOptions, sc.Address, sc.PrivateAddress, nil)
|
2019-01-10 13:13:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
{ // setup trust pool
|
2019-11-16 00:59:32 +00:00
|
|
|
peer.Storage2.Trust, err = trust.NewPool(log.Named("trust"), trust.Dialer(peer.Dialer), config.Storage2.Trust)
|
2019-08-09 10:21:41 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
{ // setup contact service
|
|
|
|
c := config.Contact
|
|
|
|
if c.ExternalAddress == "" {
|
|
|
|
c.ExternalAddress = peer.Addr()
|
2019-01-10 13:13:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 07:04:24 +01:00
|
|
|
pbVersion, err := versionInfo.Proto()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-04-22 10:07:50 +01:00
|
|
|
self := &overlay.NodeDossier{
|
|
|
|
Node: pb.Node{
|
|
|
|
Id: peer.ID(),
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
2019-09-19 20:56:34 +01:00
|
|
|
Address: c.ExternalAddress,
|
2019-04-22 10:07:50 +01:00
|
|
|
},
|
2019-01-10 13:13:27 +00:00
|
|
|
},
|
2019-04-22 10:07:50 +01:00
|
|
|
Type: pb.NodeType_STORAGE,
|
|
|
|
Operator: pb.NodeOperator{
|
2019-10-01 00:33:00 +01:00
|
|
|
Email: config.Operator.Email,
|
|
|
|
Wallet: config.Operator.Wallet,
|
2019-01-10 13:13:27 +00:00
|
|
|
},
|
2019-04-22 10:07:50 +01:00
|
|
|
Version: *pbVersion,
|
2019-01-10 13:13:27 +00:00
|
|
|
}
|
2019-09-19 20:56:34 +01:00
|
|
|
peer.Contact.PingStats = new(contact.PingStats)
|
|
|
|
peer.Contact.Service = contact.NewService(peer.Log.Named("contact:service"), self)
|
2019-10-11 21:44:18 +01:00
|
|
|
peer.Contact.Chore = contact.NewChore(peer.Log.Named("contact:chore"), config.Contact.Interval, peer.Storage2.Trust, peer.Dialer, peer.Contact.Service)
|
2019-09-06 17:14:03 +01:00
|
|
|
peer.Contact.Endpoint = contact.NewEndpoint(peer.Log.Named("contact:endpoint"), peer.Contact.PingStats)
|
|
|
|
pb.RegisterContactServer(peer.Server.GRPC(), peer.Contact.Endpoint)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterContact(peer.Server.DRPC(), peer.Contact.Endpoint)
|
2019-09-04 20:04:18 +01:00
|
|
|
}
|
|
|
|
|
2019-05-08 12:11:59 +01:00
|
|
|
{ // setup storage
|
2019-08-12 22:43:05 +01:00
|
|
|
peer.Storage2.BlobsCache = pieces.NewBlobsUsageCache(peer.DB.Pieces())
|
|
|
|
|
|
|
|
peer.Storage2.Store = pieces.NewStore(peer.Log.Named("pieces"),
|
|
|
|
peer.Storage2.BlobsCache,
|
|
|
|
peer.DB.V0PieceInfo(),
|
|
|
|
peer.DB.PieceExpirationDB(),
|
|
|
|
peer.DB.PieceSpaceUsedDB(),
|
|
|
|
)
|
|
|
|
|
2019-11-26 16:25:21 +00:00
|
|
|
peer.Storage2.TrashChore = pieces.NewTrashChore(
|
|
|
|
log.Named("pieces:trashchore"),
|
|
|
|
24*time.Hour, // choreInterval: how often to run the chore
|
|
|
|
7*24*time.Hour, // trashExpiryInterval: when items in the trash should be deleted
|
|
|
|
peer.Storage2.Trust,
|
|
|
|
peer.Storage2.Store,
|
|
|
|
)
|
|
|
|
|
2019-08-12 22:43:05 +01:00
|
|
|
peer.Storage2.CacheService = pieces.NewService(
|
|
|
|
log.Named("piecestore:cacheUpdate"),
|
|
|
|
peer.Storage2.BlobsCache,
|
|
|
|
peer.Storage2.Store,
|
|
|
|
config.Storage2.CacheSyncInterval,
|
|
|
|
)
|
2019-03-18 10:55:06 +00:00
|
|
|
|
2019-04-15 11:12:22 +01:00
|
|
|
peer.Storage2.Monitor = monitor.NewService(
|
|
|
|
log.Named("piecestore:monitor"),
|
|
|
|
peer.Storage2.Store,
|
2019-09-19 20:56:34 +01:00
|
|
|
peer.Contact.Service,
|
2019-04-15 11:12:22 +01:00
|
|
|
peer.DB.Bandwidth(),
|
|
|
|
config.Storage.AllocatedDiskSpace.Int64(),
|
|
|
|
config.Storage.AllocatedBandwidth.Int64(),
|
|
|
|
//TODO use config.Storage.Monitor.Interval, but for some reason is not set
|
|
|
|
config.Storage.KBucketRefreshInterval,
|
2019-06-10 11:14:50 +01:00
|
|
|
config.Storage2.Monitor,
|
2019-04-15 11:12:22 +01:00
|
|
|
)
|
|
|
|
|
2019-08-19 19:52:47 +01:00
|
|
|
peer.Storage2.RetainService = retain.NewService(
|
|
|
|
peer.Log.Named("retain"),
|
|
|
|
peer.Storage2.Store,
|
|
|
|
config.Retain,
|
|
|
|
)
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
peer.Storage2.Endpoint, err = piecestore.NewEndpoint(
|
|
|
|
peer.Log.Named("piecestore"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
peer.Storage2.Trust,
|
2019-04-15 11:12:22 +01:00
|
|
|
peer.Storage2.Monitor,
|
2019-08-19 19:52:47 +01:00
|
|
|
peer.Storage2.RetainService,
|
2019-10-03 19:31:39 +01:00
|
|
|
peer.Contact.PingStats,
|
2019-03-18 10:55:06 +00:00
|
|
|
peer.Storage2.Store,
|
|
|
|
peer.DB.Orders(),
|
|
|
|
peer.DB.Bandwidth(),
|
|
|
|
peer.DB.UsedSerials(),
|
|
|
|
config.Storage2,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
pb.RegisterPiecestoreServer(peer.Server.GRPC(), peer.Storage2.Endpoint)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterPiecestore(peer.Server.DRPC(), peer.Storage2.Endpoint.DRPC())
|
2019-03-18 10:55:06 +00:00
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
// TODO workaround for custom timeout for order sending request (read/write)
|
2019-09-02 12:24:02 +01:00
|
|
|
sc := config.Server
|
2019-09-19 05:46:39 +01:00
|
|
|
|
|
|
|
tlsOptions, err := tlsopts.NewOptions(peer.Identity, sc.Config, revocationDB)
|
2019-09-02 12:24:02 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
dialer := rpc.NewDefaultDialer(tlsOptions)
|
|
|
|
dialer.DialTimeout = config.Storage2.Orders.SenderDialTimeout
|
2019-09-02 12:24:02 +01:00
|
|
|
|
2019-08-22 15:33:14 +01:00
|
|
|
peer.Storage2.Orders = orders.NewService(
|
|
|
|
log.Named("orders"),
|
2019-09-19 05:46:39 +01:00
|
|
|
dialer,
|
2019-03-27 10:24:35 +00:00
|
|
|
peer.DB.Orders(),
|
2019-07-18 18:15:09 +01:00
|
|
|
peer.Storage2.Trust,
|
2019-08-22 15:33:14 +01:00
|
|
|
config.Storage2.Orders,
|
2019-03-27 10:24:35 +00:00
|
|
|
)
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 19:55:22 +01:00
|
|
|
{ // setup node stats service
|
2019-08-08 14:47:04 +01:00
|
|
|
peer.NodeStats.Service = nodestats.NewService(
|
|
|
|
peer.Log.Named("nodestats:service"),
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Dialer,
|
2019-08-08 14:47:04 +01:00
|
|
|
peer.Storage2.Trust)
|
|
|
|
|
|
|
|
peer.NodeStats.Cache = nodestats.NewCache(
|
|
|
|
peer.Log.Named("nodestats:cache"),
|
|
|
|
config.Nodestats,
|
|
|
|
nodestats.CacheStorage{
|
|
|
|
Reputation: peer.DB.Reputation(),
|
|
|
|
StorageUsage: peer.DB.StorageUsage(),
|
|
|
|
},
|
|
|
|
peer.NodeStats.Service,
|
|
|
|
peer.Storage2.Trust)
|
2019-06-26 19:55:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup storage node operator dashboard
|
2019-06-20 12:52:32 +01:00
|
|
|
peer.Console.Service, err = console.NewService(
|
|
|
|
peer.Log.Named("console:service"),
|
|
|
|
peer.DB.Bandwidth(),
|
2019-08-08 02:47:30 +01:00
|
|
|
peer.Storage2.Store,
|
2019-06-20 12:52:32 +01:00
|
|
|
peer.Version,
|
|
|
|
config.Storage.AllocatedBandwidth,
|
|
|
|
config.Storage.AllocatedDiskSpace,
|
2019-10-01 00:33:00 +01:00
|
|
|
config.Operator.Wallet,
|
2019-08-14 13:17:11 +01:00
|
|
|
versionInfo,
|
|
|
|
peer.Storage2.Trust,
|
|
|
|
peer.DB.Reputation(),
|
2019-09-11 21:41:43 +01:00
|
|
|
peer.DB.StorageUsage(),
|
|
|
|
peer.Contact.PingStats,
|
2019-09-19 20:56:34 +01:00
|
|
|
peer.Contact.Service)
|
2019-06-20 12:52:32 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Console.Listener, err = net.Listen("tcp", config.Console.Address)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-10-08 09:52:19 +01:00
|
|
|
assets := consoleassets.FileSystem
|
|
|
|
if config.Console.StaticDir != "" {
|
|
|
|
// a specific directory has been configured. use it
|
|
|
|
assets = http.Dir(config.Console.StaticDir)
|
|
|
|
}
|
|
|
|
|
2019-06-20 12:52:32 +01:00
|
|
|
peer.Console.Endpoint = consoleserver.NewServer(
|
|
|
|
peer.Log.Named("console:endpoint"),
|
2019-10-08 09:52:19 +01:00
|
|
|
assets,
|
2019-06-20 12:52:32 +01:00
|
|
|
peer.Console.Service,
|
|
|
|
peer.Console.Listener,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-06 14:40:58 +01:00
|
|
|
{ // setup storage inspector
|
|
|
|
peer.Storage2.Inspector = inspector.NewEndpoint(
|
|
|
|
peer.Log.Named("pieces:inspector"),
|
2019-08-08 02:47:30 +01:00
|
|
|
peer.Storage2.Store,
|
2019-09-19 20:56:34 +01:00
|
|
|
peer.Contact.Service,
|
2019-09-11 21:41:43 +01:00
|
|
|
peer.Contact.PingStats,
|
2019-07-06 14:40:58 +01:00
|
|
|
peer.DB.Bandwidth(),
|
|
|
|
config.Storage,
|
|
|
|
peer.Console.Listener.Addr(),
|
2019-09-19 20:56:34 +01:00
|
|
|
config.Contact.ExternalAddress,
|
2019-07-06 14:40:58 +01:00
|
|
|
)
|
|
|
|
pb.RegisterPieceStoreInspectorServer(peer.Server.PrivateGRPC(), peer.Storage2.Inspector)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterPieceStoreInspector(peer.Server.PrivateDRPC(), peer.Storage2.Inspector)
|
2019-07-06 14:40:58 +01:00
|
|
|
}
|
|
|
|
|
2019-10-11 14:58:12 +01:00
|
|
|
{ // setup graceful exit service
|
|
|
|
peer.GracefulExit.Endpoint = gracefulexit.NewEndpoint(
|
|
|
|
peer.Log.Named("gracefulexit:endpoint"),
|
|
|
|
peer.Storage2.Trust,
|
|
|
|
peer.DB.Satellites(),
|
|
|
|
peer.Storage2.BlobsCache,
|
|
|
|
)
|
|
|
|
pb.RegisterNodeGracefulExitServer(peer.Server.PrivateGRPC(), peer.GracefulExit.Endpoint)
|
|
|
|
pb.DRPCRegisterNodeGracefulExit(peer.Server.PrivateDRPC(), peer.GracefulExit.Endpoint)
|
2019-10-15 16:29:47 +01:00
|
|
|
|
|
|
|
peer.GracefulExit.Chore = gracefulexit.NewChore(
|
|
|
|
peer.Log.Named("gracefulexit:chore"),
|
|
|
|
config.GracefulExit,
|
2019-10-22 21:42:21 +01:00
|
|
|
peer.Storage2.Store,
|
|
|
|
peer.Storage2.Trust,
|
|
|
|
peer.Dialer,
|
2019-10-15 16:29:47 +01:00
|
|
|
peer.DB.Satellites(),
|
|
|
|
)
|
2019-10-11 14:58:12 +01:00
|
|
|
}
|
|
|
|
|
2019-08-08 02:47:30 +01:00
|
|
|
peer.Collector = collector.NewService(peer.Log.Named("collector"), peer.Storage2.Store, peer.DB.UsedSerials(), config.Collector)
|
2019-05-08 12:11:59 +01:00
|
|
|
|
2019-07-29 15:07:52 +01:00
|
|
|
peer.Bandwidth = bandwidth.NewService(peer.Log.Named("bandwidth"), peer.DB.Bandwidth(), config.Bandwidth)
|
|
|
|
|
2019-01-10 13:13:27 +00:00
|
|
|
return peer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs storage node until it's either closed or it errors.
|
2019-06-04 13:31:39 +01:00
|
|
|
func (peer *Peer) Run(ctx context.Context) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2019-11-16 00:59:32 +00:00
|
|
|
// Refresh the trust pool first. It will be updated periodically via
|
|
|
|
// Run() below.
|
|
|
|
if err := peer.Storage2.Trust.Refresh(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-06 13:19:14 +00:00
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
2019-01-10 13:13:27 +00:00
|
|
|
|
2019-04-03 20:13:39 +01:00
|
|
|
group.Go(func() error {
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Version.Run(ctx))
|
2019-04-03 20:13:39 +01:00
|
|
|
})
|
2019-10-14 15:57:01 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Storage2.Monitor.Run(ctx))
|
|
|
|
})
|
2019-01-10 13:13:27 +00:00
|
|
|
group.Go(func() error {
|
2019-09-19 20:56:34 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Contact.Chore.Run(ctx))
|
2019-01-10 13:13:27 +00:00
|
|
|
})
|
2019-05-08 12:11:59 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Collector.Run(ctx))
|
|
|
|
})
|
2019-03-27 10:24:35 +00:00
|
|
|
group.Go(func() error {
|
2019-08-22 15:33:14 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Storage2.Orders.Run(ctx))
|
2019-03-27 10:24:35 +00:00
|
|
|
})
|
2019-08-12 22:43:05 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Storage2.CacheService.Run(ctx))
|
|
|
|
})
|
2019-08-19 19:52:47 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Storage2.RetainService.Run(ctx))
|
|
|
|
})
|
2019-11-26 16:25:21 +00:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Storage2.TrashChore.Run(ctx))
|
|
|
|
})
|
2019-07-29 15:07:52 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Bandwidth.Run(ctx))
|
|
|
|
})
|
2019-11-16 00:59:32 +00:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Storage2.Trust.Run(ctx))
|
|
|
|
})
|
2019-07-16 15:58:58 +01:00
|
|
|
|
2019-01-23 10:39:03 +00:00
|
|
|
group.Go(func() error {
|
|
|
|
// TODO: move the message into Server instead
|
2019-03-07 18:19:37 +00:00
|
|
|
// Don't change the format of this comment, it is used to figure out the node id.
|
|
|
|
peer.Log.Sugar().Infof("Node %s started", peer.Identity.ID)
|
2019-03-18 17:02:37 +00:00
|
|
|
peer.Log.Sugar().Infof("Public server started on %s", peer.Addr())
|
|
|
|
peer.Log.Sugar().Infof("Private server started on %s", peer.PrivateAddr())
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Server.Run(ctx))
|
2019-01-10 13:13:27 +00:00
|
|
|
})
|
|
|
|
|
2019-08-08 14:47:04 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.NodeStats.Cache.Run(ctx))
|
|
|
|
})
|
2019-06-20 12:52:32 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Console.Endpoint.Run(ctx))
|
|
|
|
})
|
|
|
|
|
2019-10-15 16:29:47 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.GracefulExit.Chore.Run(ctx))
|
|
|
|
})
|
|
|
|
|
2019-01-10 13:13:27 +00:00
|
|
|
return group.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes all the resources.
|
|
|
|
func (peer *Peer) Close() error {
|
|
|
|
var errlist errs.Group
|
|
|
|
|
|
|
|
// TODO: ensure that Close can be called on nil-s that way this code won't need the checks.
|
|
|
|
|
2019-01-28 19:04:42 +00:00
|
|
|
// close servers, to avoid new connections to closing subsystems
|
2019-03-07 18:19:37 +00:00
|
|
|
if peer.Server != nil {
|
|
|
|
errlist.Add(peer.Server.Close())
|
2019-01-28 19:04:42 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 13:13:27 +00:00
|
|
|
// close services in reverse initialization order
|
2019-10-15 16:29:47 +01:00
|
|
|
if peer.GracefulExit.Chore != nil {
|
|
|
|
errlist.Add(peer.GracefulExit.Chore.Close())
|
|
|
|
}
|
2019-09-06 17:14:03 +01:00
|
|
|
if peer.Contact.Chore != nil {
|
|
|
|
errlist.Add(peer.Contact.Chore.Close())
|
|
|
|
}
|
2019-07-31 14:30:36 +01:00
|
|
|
if peer.Bandwidth != nil {
|
2019-07-29 15:07:52 +01:00
|
|
|
errlist.Add(peer.Bandwidth.Close())
|
|
|
|
}
|
2019-11-26 16:25:21 +00:00
|
|
|
if peer.Storage2.TrashChore != nil {
|
|
|
|
errlist.Add(peer.Storage2.TrashChore.Close())
|
|
|
|
}
|
2019-08-28 21:35:25 +01:00
|
|
|
if peer.Storage2.RetainService != nil {
|
|
|
|
errlist.Add(peer.Storage2.RetainService.Close())
|
|
|
|
}
|
2019-05-08 12:11:59 +01:00
|
|
|
if peer.Storage2.Monitor != nil {
|
|
|
|
errlist.Add(peer.Storage2.Monitor.Close())
|
|
|
|
}
|
2019-08-22 15:33:14 +01:00
|
|
|
if peer.Storage2.Orders != nil {
|
|
|
|
errlist.Add(peer.Storage2.Orders.Close())
|
2019-05-08 12:11:59 +01:00
|
|
|
}
|
2019-08-12 22:43:05 +01:00
|
|
|
if peer.Storage2.CacheService != nil {
|
|
|
|
errlist.Add(peer.Storage2.CacheService.Close())
|
|
|
|
}
|
2019-05-08 12:11:59 +01:00
|
|
|
if peer.Collector != nil {
|
|
|
|
errlist.Add(peer.Collector.Close())
|
|
|
|
}
|
|
|
|
|
2019-06-24 16:15:31 +01:00
|
|
|
if peer.Console.Endpoint != nil {
|
|
|
|
errlist.Add(peer.Console.Endpoint.Close())
|
|
|
|
} else if peer.Console.Listener != nil {
|
|
|
|
errlist.Add(peer.Console.Listener.Close())
|
|
|
|
}
|
2019-01-10 13:13:27 +00:00
|
|
|
|
2019-08-08 14:47:04 +01:00
|
|
|
if peer.NodeStats.Cache != nil {
|
|
|
|
errlist.Add(peer.NodeStats.Cache.Close())
|
|
|
|
}
|
|
|
|
|
2019-01-10 13:13:27 +00:00
|
|
|
return errlist.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the peer ID.
|
|
|
|
func (peer *Peer) ID() storj.NodeID { return peer.Identity.ID }
|
|
|
|
|
|
|
|
// Local returns the peer local node info.
|
2019-09-19 20:56:34 +01:00
|
|
|
func (peer *Peer) Local() overlay.NodeDossier { return peer.Contact.Service.Local() }
|
2019-01-10 13:13:27 +00:00
|
|
|
|
|
|
|
// Addr returns the public address.
|
2019-03-07 18:19:37 +00:00
|
|
|
func (peer *Peer) Addr() string { return peer.Server.Addr().String() }
|
|
|
|
|
2019-07-03 18:29:18 +01:00
|
|
|
// URL returns the storj.NodeURL.
|
|
|
|
func (peer *Peer) URL() storj.NodeURL { return storj.NodeURL{ID: peer.ID(), Address: peer.Addr()} }
|
|
|
|
|
2019-03-07 18:19:37 +00:00
|
|
|
// PrivateAddr returns the private address.
|
|
|
|
func (peer *Peer) PrivateAddr() string { return peer.Server.PrivateAddr().String() }
|