2019-11-04 19:01:02 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-29 23:04:30 +00:00
|
|
|
"errors"
|
2020-01-28 17:35:45 +00:00
|
|
|
"net"
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2019-11-04 19:01:02 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/identity"
|
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/peertls/extensions"
|
|
|
|
"storj.io/common/peertls/tlsopts"
|
|
|
|
"storj.io/common/rpc"
|
|
|
|
"storj.io/common/signing"
|
|
|
|
"storj.io/common/storj"
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/debug"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2020-01-28 23:13:59 +00:00
|
|
|
"storj.io/storj/private/lifecycle"
|
2019-11-14 19:46:15 +00:00
|
|
|
version_checker "storj.io/storj/private/version/checker"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/accounting"
|
2020-07-07 15:48:09 +01:00
|
|
|
"storj.io/storj/satellite/accounting/projectbwcleanup"
|
2020-01-15 21:45:17 +00:00
|
|
|
"storj.io/storj/satellite/accounting/reportedrollup"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/accounting/rollup"
|
|
|
|
"storj.io/storj/satellite/accounting/tally"
|
|
|
|
"storj.io/storj/satellite/audit"
|
2019-12-30 19:42:10 +00:00
|
|
|
"storj.io/storj/satellite/contact"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/dbcleanup"
|
2019-12-30 19:42:10 +00:00
|
|
|
"storj.io/storj/satellite/downtime"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/gc"
|
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
|
|
|
"storj.io/storj/satellite/metainfo"
|
2020-04-15 20:20:16 +01:00
|
|
|
"storj.io/storj/satellite/metainfo/expireddeletion"
|
2019-11-04 19:01:02 +00:00
|
|
|
"storj.io/storj/satellite/metrics"
|
|
|
|
"storj.io/storj/satellite/orders"
|
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
"storj.io/storj/satellite/payments"
|
|
|
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
|
|
|
"storj.io/storj/satellite/repair/checker"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Core is the satellite core process that runs chores
|
|
|
|
//
|
|
|
|
// architecture: Peer
|
|
|
|
type Core struct {
|
|
|
|
// core dependencies
|
|
|
|
Log *zap.Logger
|
|
|
|
Identity *identity.FullIdentity
|
|
|
|
DB DB
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
Servers *lifecycle.Group
|
|
|
|
Services *lifecycle.Group
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Dialer rpc.Dialer
|
|
|
|
|
2020-02-21 17:41:54 +00:00
|
|
|
Version struct {
|
|
|
|
Chore *version_checker.Chore
|
|
|
|
Service *version_checker.Service
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
Debug struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Server *debug.Server
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
// services and endpoints
|
2019-12-30 19:42:10 +00:00
|
|
|
Contact struct {
|
|
|
|
Service *contact.Service
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
Overlay struct {
|
|
|
|
DB overlay.DB
|
|
|
|
Service *overlay.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
Metainfo struct {
|
|
|
|
Database metainfo.PointerDB // TODO: move into pointerDB
|
|
|
|
Service *metainfo.Service
|
|
|
|
Loop *metainfo.Loop
|
|
|
|
}
|
|
|
|
|
|
|
|
Orders struct {
|
2020-01-10 18:53:42 +00:00
|
|
|
DB orders.DB
|
2019-11-04 19:01:02 +00:00
|
|
|
Service *orders.Service
|
2020-01-10 18:53:42 +00:00
|
|
|
Chore *orders.Chore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Repair struct {
|
2020-01-29 01:02:30 +00:00
|
|
|
Checker *checker.Checker
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
Audit struct {
|
|
|
|
Queue *audit.Queue
|
|
|
|
Worker *audit.Worker
|
|
|
|
Chore *audit.Chore
|
|
|
|
Verifier *audit.Verifier
|
|
|
|
Reporter *audit.Reporter
|
|
|
|
}
|
|
|
|
|
|
|
|
GarbageCollection struct {
|
|
|
|
Service *gc.Service
|
|
|
|
}
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
ExpiredDeletion struct {
|
|
|
|
Chore *expireddeletion.Chore
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
DBCleanup struct {
|
|
|
|
Chore *dbcleanup.Chore
|
|
|
|
}
|
|
|
|
|
|
|
|
Accounting struct {
|
2020-07-07 15:48:09 +01:00
|
|
|
Tally *tally.Service
|
|
|
|
Rollup *rollup.Service
|
|
|
|
ProjectUsage *accounting.Service
|
|
|
|
ReportedRollupChore *reportedrollup.Chore
|
|
|
|
ProjectBWCleanupChore *projectbwcleanup.Chore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LiveAccounting struct {
|
|
|
|
Cache accounting.Cache
|
|
|
|
}
|
|
|
|
|
|
|
|
Payments struct {
|
|
|
|
Accounts payments.Accounts
|
2019-11-05 13:16:02 +00:00
|
|
|
Chore *stripecoinpayments.Chore
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GracefulExit struct {
|
|
|
|
Chore *gracefulexit.Chore
|
|
|
|
}
|
|
|
|
|
|
|
|
Metrics struct {
|
|
|
|
Chore *metrics.Chore
|
|
|
|
}
|
2019-12-30 19:42:10 +00:00
|
|
|
|
|
|
|
DowntimeTracking struct {
|
2020-01-07 21:34:48 +00:00
|
|
|
DetectionChore *downtime.DetectionChore
|
|
|
|
EstimationChore *downtime.EstimationChore
|
|
|
|
Service *downtime.Service
|
2019-12-30 19:42:10 +00:00
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// New creates a new satellite.
|
2020-01-17 22:55:53 +00:00
|
|
|
func New(log *zap.Logger, full *identity.FullIdentity, db DB,
|
|
|
|
pointerDB metainfo.PointerDB, revocationDB extensions.RevocationDB, liveAccounting accounting.Cache,
|
|
|
|
rollupsWriteCache *orders.RollupsWriteCache,
|
2020-05-12 20:10:32 +01:00
|
|
|
versionInfo version.Info, config *Config, atomicLogLevel *zap.AtomicLevel) (*Core, error) {
|
2019-11-04 19:01:02 +00:00
|
|
|
peer := &Core{
|
|
|
|
Log: log,
|
|
|
|
Identity: full,
|
|
|
|
DB: db,
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
Servers: lifecycle.NewGroup(log.Named("servers")),
|
|
|
|
Services: lifecycle.NewGroup(log.Named("services")),
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
{ // setup debug
|
|
|
|
var err error
|
|
|
|
if config.Debug.Address != "" {
|
|
|
|
peer.Debug.Listener, err = net.Listen("tcp", config.Debug.Address)
|
|
|
|
if err != nil {
|
2020-01-29 23:04:30 +00:00
|
|
|
withoutStack := errors.New(err.Error())
|
|
|
|
peer.Log.Debug("failed to start debug endpoints", zap.Error(withoutStack))
|
|
|
|
err = nil
|
2020-01-28 17:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-30 12:49:40 +00:00
|
|
|
debugConfig := config.Debug
|
|
|
|
debugConfig.ControlTitle = "Core"
|
2020-05-12 20:10:32 +01:00
|
|
|
peer.Debug.Server = debug.NewServerWithAtomicLevel(log.Named("debug"), peer.Debug.Listener, monkit.Default, debugConfig, atomicLogLevel)
|
2020-01-28 17:35:45 +00:00
|
|
|
peer.Servers.Add(lifecycle.Item{
|
|
|
|
Name: "debug",
|
|
|
|
Run: peer.Debug.Server.Run,
|
|
|
|
Close: peer.Debug.Server.Close,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
{ // setup version control
|
2020-04-15 20:32:22 +01:00
|
|
|
peer.Log.Info("Version info",
|
|
|
|
zap.Stringer("Version", versionInfo.Version.Version),
|
|
|
|
zap.String("Commit Hash", versionInfo.CommitHash),
|
|
|
|
zap.Stringer("Build Timestamp", versionInfo.Timestamp),
|
|
|
|
zap.Bool("Release Build", versionInfo.Release),
|
|
|
|
)
|
2020-02-21 17:41:54 +00:00
|
|
|
peer.Version.Service = version_checker.NewService(log.Named("version"), config.Version, versionInfo, "Satellite")
|
|
|
|
peer.Version.Chore = version_checker.NewChore(peer.Version.Service, config.Version.CheckInterval)
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "version",
|
2020-02-21 17:41:54 +00:00
|
|
|
Run: peer.Version.Chore.Run,
|
2020-01-28 23:13:59 +00:00
|
|
|
})
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup listener and server
|
|
|
|
sc := config.Server
|
|
|
|
|
|
|
|
tlsOptions, err := tlsopts.NewOptions(peer.Identity, sc.Config, revocationDB)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Dialer = rpc.NewDefaultDialer(tlsOptions)
|
|
|
|
}
|
|
|
|
|
2019-12-30 19:42:10 +00:00
|
|
|
{ // setup contact service
|
|
|
|
pbVersion, err := versionInfo.Proto()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
self := &overlay.NodeDossier{
|
|
|
|
Node: pb.Node{
|
|
|
|
Id: peer.ID(),
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Address: config.Contact.ExternalAddress,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Type: pb.NodeType_SATELLITE,
|
|
|
|
Version: *pbVersion,
|
|
|
|
}
|
2020-04-02 21:44:51 +01:00
|
|
|
peer.Contact.Service = contact.NewService(peer.Log.Named("contact:service"), self, peer.Overlay.Service, peer.DB.PeerIdentities(), peer.Dialer, config.Contact.Timeout)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "contact:service",
|
|
|
|
Close: peer.Contact.Service.Close,
|
|
|
|
})
|
2019-12-30 19:42:10 +00:00
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
{ // setup overlay
|
2020-03-12 18:37:57 +00:00
|
|
|
peer.Overlay.DB = peer.DB.OverlayCache()
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Overlay.Service = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, config.Overlay)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "overlay",
|
|
|
|
Close: peer.Overlay.Service.Close,
|
|
|
|
})
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup live accounting
|
|
|
|
peer.LiveAccounting.Cache = liveAccounting
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup accounting project usage
|
2019-11-15 14:27:44 +00:00
|
|
|
peer.Accounting.ProjectUsage = accounting.NewService(
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.DB.ProjectAccounting(),
|
|
|
|
peer.LiveAccounting.Cache,
|
2020-06-30 22:49:29 +01:00
|
|
|
config.Metainfo.ProjectLimits.DefaultMaxUsage,
|
|
|
|
config.Metainfo.ProjectLimits.DefaultMaxBandwidth,
|
2020-06-02 00:19:10 +01:00
|
|
|
config.LiveAccounting.BandwidthCacheTTL,
|
2019-11-04 19:01:02 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup orders
|
2020-01-17 22:55:53 +00:00
|
|
|
peer.Orders.DB = rollupsWriteCache
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Orders.Chore = orders.NewChore(log.Named("orders:chore"), rollupsWriteCache, config.Orders)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "overlay",
|
|
|
|
Run: peer.Orders.Chore.Run,
|
|
|
|
Close: peer.Orders.Chore.Close,
|
|
|
|
})
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Orders.Service = orders.NewService(
|
|
|
|
peer.Log.Named("orders:service"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
peer.Overlay.Service,
|
2020-01-10 18:53:42 +00:00
|
|
|
peer.Orders.DB,
|
2019-11-04 19:01:02 +00:00
|
|
|
config.Orders.Expiration,
|
|
|
|
&pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
Address: config.Contact.ExternalAddress,
|
|
|
|
},
|
|
|
|
config.Repairer.MaxExcessRateOptimalThreshold,
|
2020-01-18 17:16:39 +00:00
|
|
|
config.Orders.NodeStatusLogging,
|
2019-11-04 19:01:02 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup metainfo
|
|
|
|
peer.Metainfo.Database = pointerDB // for logging: storelogger.New(peer.Log.Named("pdb"), db)
|
|
|
|
peer.Metainfo.Service = metainfo.NewService(peer.Log.Named("metainfo:service"),
|
|
|
|
peer.Metainfo.Database,
|
|
|
|
peer.DB.Buckets(),
|
|
|
|
)
|
|
|
|
peer.Metainfo.Loop = metainfo.NewLoop(config.Metainfo.Loop, peer.Metainfo.Database)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "metainfo:loop",
|
|
|
|
Run: peer.Metainfo.Loop.Run,
|
|
|
|
Close: peer.Metainfo.Loop.Close,
|
|
|
|
})
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup datarepair
|
|
|
|
// TODO: simplify argument list somehow
|
|
|
|
peer.Repair.Checker = checker.NewChecker(
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Log.Named("repair:checker"),
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.DB.RepairQueue(),
|
|
|
|
peer.DB.Irreparable(),
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
peer.Metainfo.Loop,
|
|
|
|
peer.Overlay.Service,
|
|
|
|
config.Checker)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "repair:checker",
|
|
|
|
Run: peer.Repair.Checker.Run,
|
|
|
|
Close: peer.Repair.Checker.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Repair Checker", peer.Repair.Checker.Loop))
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Repair Checker Irreparable", peer.Repair.Checker.IrreparableLoop))
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup audit
|
|
|
|
config := config.Audit
|
|
|
|
|
|
|
|
peer.Audit.Queue = &audit.Queue{}
|
|
|
|
|
|
|
|
peer.Audit.Verifier = audit.NewVerifier(log.Named("audit:verifier"),
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
peer.Dialer,
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DB.Containment(),
|
|
|
|
peer.Orders.Service,
|
|
|
|
peer.Identity,
|
|
|
|
config.MinBytesPerSecond,
|
|
|
|
config.MinDownloadTimeout,
|
|
|
|
)
|
|
|
|
|
|
|
|
peer.Audit.Reporter = audit.NewReporter(log.Named("audit:reporter"),
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DB.Containment(),
|
|
|
|
config.MaxRetriesStatDB,
|
|
|
|
int32(config.MaxReverifyCount),
|
|
|
|
)
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Audit.Worker, err = audit.NewWorker(peer.Log.Named("audit:worker"),
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Audit.Queue,
|
|
|
|
peer.Audit.Verifier,
|
|
|
|
peer.Audit.Reporter,
|
|
|
|
config,
|
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "audit:worker",
|
|
|
|
Run: peer.Audit.Worker.Run,
|
|
|
|
Close: peer.Audit.Worker.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Audit Worker", peer.Audit.Worker.Loop))
|
2019-11-04 19:01:02 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Audit.Chore = audit.NewChore(peer.Log.Named("audit:chore"),
|
2019-11-04 19:01:02 +00:00
|
|
|
peer.Audit.Queue,
|
|
|
|
peer.Metainfo.Loop,
|
|
|
|
config,
|
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "audit:chore",
|
|
|
|
Run: peer.Audit.Chore.Run,
|
|
|
|
Close: peer.Audit.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Audit Chore", peer.Audit.Chore.Loop))
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 15:40:22 +00:00
|
|
|
{ // setup garbage collection if configured to run with the core
|
|
|
|
if config.GarbageCollection.RunInCore {
|
|
|
|
peer.GarbageCollection.Service = gc.NewService(
|
|
|
|
peer.Log.Named("core-garbage-collection"),
|
|
|
|
config.GarbageCollection,
|
|
|
|
peer.Dialer,
|
|
|
|
peer.Overlay.DB,
|
|
|
|
peer.Metainfo.Loop,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "core-garbage-collection",
|
|
|
|
Run: peer.GarbageCollection.Service.Run,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Core Garbage Collection", peer.GarbageCollection.Service.Loop))
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 20:20:16 +01:00
|
|
|
{ // setup expired segment cleanup
|
|
|
|
peer.ExpiredDeletion.Chore = expireddeletion.NewChore(
|
|
|
|
peer.Log.Named("core-expired-deletion"),
|
|
|
|
config.ExpiredDeletion,
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
peer.Metainfo.Loop,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "expireddeletion:chore",
|
|
|
|
Run: peer.ExpiredDeletion.Chore.Run,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Expired Segments Chore", peer.ExpiredDeletion.Chore.Loop))
|
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
{ // setup db cleanup
|
|
|
|
peer.DBCleanup.Chore = dbcleanup.NewChore(peer.Log.Named("dbcleanup"), peer.DB.Orders(), config.DBCleanup)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "dbcleanup",
|
|
|
|
Run: peer.DBCleanup.Chore.Run,
|
|
|
|
Close: peer.DBCleanup.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("DB Cleanup Serials", peer.DBCleanup.Chore.Serials))
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup accounting
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Accounting.Tally = tally.New(peer.Log.Named("accounting:tally"), peer.DB.StoragenodeAccounting(), peer.DB.ProjectAccounting(), peer.LiveAccounting.Cache, peer.Metainfo.Loop, config.Tally.Interval)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:tally",
|
|
|
|
Run: peer.Accounting.Tally.Run,
|
|
|
|
Close: peer.Accounting.Tally.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Tally", peer.Accounting.Tally.Loop))
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Accounting.Rollup = rollup.New(peer.Log.Named("accounting:rollup"), peer.DB.StoragenodeAccounting(), config.Rollup.Interval, config.Rollup.DeleteTallies)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:rollup",
|
|
|
|
Run: peer.Accounting.Rollup.Run,
|
|
|
|
Close: peer.Accounting.Rollup.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Rollup", peer.Accounting.Rollup.Loop))
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Accounting.ReportedRollupChore = reportedrollup.NewChore(peer.Log.Named("accounting:reported-rollup"), peer.DB.Orders(), config.ReportedRollup)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:reported-rollup",
|
|
|
|
Run: peer.Accounting.ReportedRollupChore.Run,
|
|
|
|
Close: peer.Accounting.ReportedRollupChore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Reported Rollup", peer.Accounting.ReportedRollupChore.Loop))
|
2020-07-07 15:48:09 +01:00
|
|
|
|
|
|
|
peer.Accounting.ProjectBWCleanupChore = projectbwcleanup.NewChore(peer.Log.Named("accounting:chore"), peer.DB.ProjectAccounting(), config.ProjectBWCleanup)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "accounting:project-bw-rollup",
|
|
|
|
Run: peer.Accounting.ProjectBWCleanupChore.Run,
|
|
|
|
Close: peer.Accounting.ProjectBWCleanupChore.Close,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Accounting Project Bandwidth Rollup", peer.Accounting.ProjectBWCleanupChore.Loop))
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove in future, should be in API
|
|
|
|
{ // setup payments
|
2019-11-05 20:26:19 +00:00
|
|
|
pc := config.Payments
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
var stripeClient stripecoinpayments.StripeClient
|
2019-11-05 20:26:19 +00:00
|
|
|
switch pc.Provider {
|
2019-11-04 19:01:02 +00:00
|
|
|
default:
|
2020-05-18 10:17:05 +01:00
|
|
|
stripeClient = stripecoinpayments.NewStripeMock()
|
2019-11-04 19:01:02 +00:00
|
|
|
case "stripecoinpayments":
|
2020-05-18 10:17:05 +01:00
|
|
|
stripeClient = stripecoinpayments.NewStripeClient(log, pc.StripeCoinPayments)
|
|
|
|
}
|
2019-11-04 19:01:02 +00:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
service, err := stripecoinpayments.NewService(
|
|
|
|
peer.Log.Named("payments.stripe:service"),
|
|
|
|
stripeClient,
|
|
|
|
pc.StripeCoinPayments,
|
|
|
|
peer.DB.StripeCoinPayments(),
|
|
|
|
peer.DB.Console().Projects(),
|
|
|
|
peer.DB.ProjectAccounting(),
|
|
|
|
pc.StorageTBPrice,
|
|
|
|
pc.EgressTBPrice,
|
|
|
|
pc.ObjectPrice,
|
|
|
|
pc.BonusRate,
|
|
|
|
pc.CouponValue,
|
|
|
|
pc.CouponDuration,
|
|
|
|
pc.CouponProjectLimit,
|
|
|
|
pc.MinCoinPayment)
|
2019-11-05 13:16:02 +00:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
2020-05-18 10:17:05 +01:00
|
|
|
|
|
|
|
peer.Payments.Accounts = service.Accounts()
|
|
|
|
|
|
|
|
peer.Payments.Chore = stripecoinpayments.NewChore(
|
|
|
|
peer.Log.Named("payments.stripe:clearing"),
|
|
|
|
service,
|
|
|
|
pc.StripeCoinPayments.TransactionUpdateInterval,
|
|
|
|
pc.StripeCoinPayments.AccountBalanceUpdateInterval,
|
|
|
|
)
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "payments.stripe:service",
|
|
|
|
Run: peer.Payments.Chore.Run,
|
|
|
|
})
|
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Payments Stripe Transactions", peer.Payments.Chore.TransactionCycle),
|
|
|
|
debug.Cycle("Payments Stripe Account Balance", peer.Payments.Chore.AccountBalanceCycle),
|
|
|
|
)
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup graceful exit
|
|
|
|
if config.GracefulExit.Enabled {
|
2020-01-06 12:34:54 +00:00
|
|
|
peer.GracefulExit.Chore = gracefulexit.NewChore(peer.Log.Named("gracefulexit"), peer.DB.GracefulExit(), peer.Overlay.DB, peer.Metainfo.Loop, config.GracefulExit)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "gracefulexit",
|
|
|
|
Run: peer.GracefulExit.Chore.Run,
|
|
|
|
Close: peer.GracefulExit.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Graceful Exit", peer.GracefulExit.Chore.Loop))
|
2020-01-06 12:34:54 +00:00
|
|
|
} else {
|
|
|
|
peer.Log.Named("gracefulexit").Info("disabled")
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup metrics service
|
|
|
|
peer.Metrics.Chore = metrics.NewChore(
|
|
|
|
peer.Log.Named("metrics"),
|
|
|
|
config.Metrics,
|
|
|
|
peer.Metainfo.Loop,
|
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "metrics",
|
|
|
|
Run: peer.Metrics.Chore.Run,
|
|
|
|
Close: peer.Metrics.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Metrics", peer.Metrics.Chore.Loop))
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 19:42:10 +00:00
|
|
|
{ // setup downtime tracking
|
|
|
|
peer.DowntimeTracking.Service = downtime.NewService(peer.Log.Named("downtime"), peer.Overlay.Service, peer.Contact.Service)
|
2020-01-02 20:41:18 +00:00
|
|
|
|
|
|
|
peer.DowntimeTracking.DetectionChore = downtime.NewDetectionChore(
|
|
|
|
peer.Log.Named("downtime:detection"),
|
|
|
|
config.Downtime,
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DowntimeTracking.Service,
|
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "downtime:detection",
|
|
|
|
Run: peer.DowntimeTracking.DetectionChore.Run,
|
|
|
|
Close: peer.DowntimeTracking.DetectionChore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Downtime Detection", peer.DowntimeTracking.DetectionChore.Loop))
|
2020-01-07 21:34:48 +00:00
|
|
|
|
|
|
|
peer.DowntimeTracking.EstimationChore = downtime.NewEstimationChore(
|
|
|
|
peer.Log.Named("downtime:estimation"),
|
|
|
|
config.Downtime,
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DowntimeTracking.Service,
|
|
|
|
peer.DB.DowntimeTracking(),
|
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "downtime:estimation",
|
|
|
|
Run: peer.DowntimeTracking.EstimationChore.Run,
|
|
|
|
Close: peer.DowntimeTracking.EstimationChore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Downtime Estimation", peer.DowntimeTracking.EstimationChore.Loop))
|
2019-12-30 19:42:10 +00:00
|
|
|
}
|
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
return peer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs satellite until it's either closed or it errors.
|
|
|
|
func (peer *Core) Run(ctx context.Context) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Servers.Run(ctx, group)
|
|
|
|
peer.Services.Run(ctx, group)
|
2020-01-07 21:34:48 +00:00
|
|
|
|
2019-11-04 19:01:02 +00:00
|
|
|
return group.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes all the resources.
|
|
|
|
func (peer *Core) Close() error {
|
2020-01-28 23:13:59 +00:00
|
|
|
return errs.Combine(
|
|
|
|
peer.Servers.Close(),
|
|
|
|
peer.Services.Close(),
|
|
|
|
)
|
2019-11-04 19:01:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the peer ID.
|
|
|
|
func (peer *Core) ID() storj.NodeID { return peer.Identity.ID }
|