2019-01-18 13:54:08 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
2019-03-02 15:22:20 +00:00
|
|
|
"net/mail"
|
|
|
|
"net/smtp"
|
2019-01-18 13:54:08 +00:00
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
2019-08-21 16:49:27 +01:00
|
|
|
"gopkg.in/spacemonkeygo/monkit.v2"
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-04-17 11:09:44 +01:00
|
|
|
"storj.io/storj/internal/errs2"
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/internal/post"
|
|
|
|
"storj.io/storj/internal/post/oauth2"
|
2019-04-03 20:13:39 +01:00
|
|
|
"storj.io/storj/internal/version"
|
2019-01-23 19:58:44 +00:00
|
|
|
"storj.io/storj/pkg/auth/grpcauth"
|
2019-01-18 13:54:08 +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-18 13:54:08 +00:00
|
|
|
"storj.io/storj/pkg/server"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/pkg/signing"
|
2019-01-18 13:54:08 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/accounting"
|
|
|
|
"storj.io/storj/satellite/accounting/live"
|
|
|
|
"storj.io/storj/satellite/accounting/rollup"
|
|
|
|
"storj.io/storj/satellite/accounting/tally"
|
2019-06-19 13:02:37 +01:00
|
|
|
"storj.io/storj/satellite/attribution"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2019-01-18 13:54:08 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2019-01-24 16:26:36 +00:00
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
|
|
|
"storj.io/storj/satellite/console/consoleweb"
|
2019-09-04 20:04:18 +01:00
|
|
|
"storj.io/storj/satellite/contact"
|
2019-08-27 18:12:38 +01:00
|
|
|
"storj.io/storj/satellite/dbcleanup"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/discovery"
|
2019-07-24 18:26:43 +01:00
|
|
|
"storj.io/storj/satellite/gc"
|
2019-09-25 18:12:44 +01:00
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
2019-04-02 15:55:58 +01:00
|
|
|
"storj.io/storj/satellite/inspector"
|
2019-03-02 15:22:20 +00:00
|
|
|
"storj.io/storj/satellite/mailservice"
|
|
|
|
"storj.io/storj/satellite/mailservice/simulate"
|
2019-06-24 21:51:54 +01:00
|
|
|
"storj.io/storj/satellite/marketingweb"
|
2019-03-18 10:55:06 +00:00
|
|
|
"storj.io/storj/satellite/metainfo"
|
2019-06-25 11:40:32 +01:00
|
|
|
"storj.io/storj/satellite/nodestats"
|
2019-03-27 10:24:35 +00:00
|
|
|
"storj.io/storj/satellite/orders"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/overlay"
|
|
|
|
"storj.io/storj/satellite/repair/checker"
|
|
|
|
"storj.io/storj/satellite/repair/irreparable"
|
|
|
|
"storj.io/storj/satellite/repair/queue"
|
|
|
|
"storj.io/storj/satellite/repair/repairer"
|
2019-06-24 21:51:54 +01:00
|
|
|
"storj.io/storj/satellite/rewards"
|
2019-05-30 20:52:33 +01:00
|
|
|
"storj.io/storj/satellite/vouchers"
|
2019-01-18 13:54:08 +00:00
|
|
|
)
|
|
|
|
|
2019-06-04 12:55:38 +01:00
|
|
|
var mon = monkit.Package()
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
// DB is the master database for the satellite
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Master Database
|
2019-01-18 13:54:08 +00:00
|
|
|
type DB interface {
|
|
|
|
// CreateTables initializes the database
|
|
|
|
CreateTables() error
|
|
|
|
// Close closes the database
|
|
|
|
Close() error
|
|
|
|
|
2019-02-04 20:37:46 +00:00
|
|
|
// CreateSchema sets the schema
|
|
|
|
CreateSchema(schema string) error
|
2019-01-31 19:17:12 +00:00
|
|
|
// DropSchema drops the schema
|
|
|
|
DropSchema(schema string) error
|
|
|
|
|
2019-08-26 17:49:42 +01:00
|
|
|
// PeerIdentities returns a storage for peer identities
|
|
|
|
PeerIdentities() overlay.PeerIdentities
|
2019-01-18 13:54:08 +00:00
|
|
|
// OverlayCache returns database for caching overlay information
|
|
|
|
OverlayCache() overlay.DB
|
2019-06-19 13:02:37 +01:00
|
|
|
// Attribution returns database for partner keys information
|
|
|
|
Attribution() attribution.DB
|
2019-05-10 20:05:42 +01:00
|
|
|
// StoragenodeAccounting returns database for storing information about storagenode use
|
|
|
|
StoragenodeAccounting() accounting.StoragenodeAccounting
|
|
|
|
// ProjectAccounting returns database for storing information about project data use
|
|
|
|
ProjectAccounting() accounting.ProjectAccounting
|
2019-01-18 13:54:08 +00:00
|
|
|
// RepairQueue returns queue for segments that need repairing
|
|
|
|
RepairQueue() queue.RepairQueue
|
|
|
|
// Irreparable returns database for failed repairs
|
|
|
|
Irreparable() irreparable.DB
|
|
|
|
// Console returns database for satellite console
|
|
|
|
Console() console.DB
|
2019-06-24 21:51:54 +01:00
|
|
|
// returns database for marketing admin GUI
|
|
|
|
Rewards() rewards.DB
|
2019-03-27 10:24:35 +00:00
|
|
|
// Orders returns database for orders
|
|
|
|
Orders() orders.DB
|
2019-05-22 15:50:22 +01:00
|
|
|
// Containment returns database for containment
|
2019-05-23 15:37:23 +01:00
|
|
|
Containment() audit.Containment
|
2019-07-08 23:32:18 +01:00
|
|
|
// Buckets returns the database to interact with buckets
|
|
|
|
Buckets() metainfo.BucketsDB
|
2019-09-25 18:12:44 +01:00
|
|
|
// GracefulExit returns database for graceful exit
|
|
|
|
GracefulExit() gracefulexit.DB
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Config is the global config satellite
|
|
|
|
type Config struct {
|
|
|
|
Identity identity.Config
|
2019-06-21 11:38:40 +01:00
|
|
|
Server server.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
Contact contact.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
Overlay overlay.Config
|
|
|
|
Discovery discovery.Config
|
|
|
|
|
2019-06-06 14:57:58 +01:00
|
|
|
Metainfo metainfo.Config
|
2019-06-21 11:38:40 +01:00
|
|
|
Orders orders.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
|
|
|
|
Checker checker.Config
|
|
|
|
Repairer repairer.Config
|
2019-01-23 19:58:44 +00:00
|
|
|
Audit audit.Config
|
|
|
|
|
2019-07-24 18:26:43 +01:00
|
|
|
GarbageCollection gc.Config
|
|
|
|
|
2019-08-27 18:12:38 +01:00
|
|
|
DBCleanup dbcleanup.Config
|
|
|
|
|
2019-05-10 02:39:21 +01:00
|
|
|
Tally tally.Config
|
|
|
|
Rollup rollup.Config
|
|
|
|
LiveAccounting live.Config
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
Mail mailservice.Config
|
2019-01-24 16:26:36 +00:00
|
|
|
Console consoleweb.Config
|
2019-04-03 20:13:39 +01:00
|
|
|
|
2019-06-11 16:00:59 +01:00
|
|
|
Marketing marketingweb.Config
|
2019-05-30 20:52:33 +01:00
|
|
|
|
2019-04-03 20:13:39 +01:00
|
|
|
Version version.Config
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Peer is the satellite
|
2019-09-10 14:24:16 +01:00
|
|
|
//
|
|
|
|
// architecture: Peer
|
2019-01-18 13:54:08 +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-02-06 12:37:17 +00:00
|
|
|
|
2019-03-07 18:19:37 +00:00
|
|
|
Server *server.Server
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-04-03 20:13:39 +01:00
|
|
|
Version *version.Service
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
// services and endpoints
|
2019-09-04 20:04:18 +01:00
|
|
|
Contact struct {
|
2019-09-19 20:56:34 +01:00
|
|
|
Service *contact.Service
|
|
|
|
Endpoint *contact.Endpoint
|
|
|
|
KEndpoint *contact.KademliaEndpoint
|
2019-09-04 20:04:18 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
Overlay struct {
|
2019-08-06 23:56:12 +01:00
|
|
|
DB overlay.DB
|
2019-08-06 17:35:59 +01:00
|
|
|
Service *overlay.Service
|
2019-01-23 19:58:44 +00:00
|
|
|
Inspector *overlay.Inspector
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Discovery struct {
|
|
|
|
Service *discovery.Discovery
|
|
|
|
}
|
|
|
|
|
|
|
|
Metainfo struct {
|
2019-09-10 14:24:16 +01:00
|
|
|
Database metainfo.PointerDB // TODO: move into pointerDB
|
2019-04-25 09:46:32 +01:00
|
|
|
Service *metainfo.Service
|
2019-03-30 11:21:49 +00:00
|
|
|
Endpoint2 *metainfo.Endpoint
|
2019-07-22 14:34:12 +01:00
|
|
|
Loop *metainfo.Loop
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 15:55:58 +01:00
|
|
|
Inspector struct {
|
|
|
|
Endpoint *inspector.Endpoint
|
|
|
|
}
|
|
|
|
|
2019-03-27 10:24:35 +00:00
|
|
|
Orders struct {
|
|
|
|
Endpoint *orders.Endpoint
|
2019-03-28 20:09:23 +00:00
|
|
|
Service *orders.Service
|
2019-03-27 10:24:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
Repair struct {
|
2019-03-15 20:21:52 +00:00
|
|
|
Checker *checker.Checker
|
|
|
|
Repairer *repairer.Service
|
|
|
|
Inspector *irreparable.Inspector
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
Audit struct {
|
2019-09-11 23:37:01 +01:00
|
|
|
Queue *audit.Queue
|
|
|
|
Worker *audit.Worker
|
|
|
|
Chore *audit.Chore
|
|
|
|
Verifier *audit.Verifier
|
|
|
|
Reporter *audit.Reporter
|
2019-01-23 19:58:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 18:26:43 +01:00
|
|
|
GarbageCollection struct {
|
|
|
|
Service *gc.Service
|
|
|
|
}
|
|
|
|
|
2019-08-27 18:12:38 +01:00
|
|
|
DBCleanup struct {
|
|
|
|
Chore *dbcleanup.Chore
|
|
|
|
}
|
|
|
|
|
2019-01-23 19:58:44 +00:00
|
|
|
Accounting struct {
|
2019-05-28 16:36:52 +01:00
|
|
|
Tally *tally.Service
|
|
|
|
Rollup *rollup.Service
|
|
|
|
ProjectUsage *accounting.ProjectUsage
|
2019-01-23 19:58:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 02:39:21 +01:00
|
|
|
LiveAccounting struct {
|
|
|
|
Service live.Service
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
Mail struct {
|
|
|
|
Service *mailservice.Service
|
|
|
|
}
|
|
|
|
|
2019-05-30 20:52:33 +01:00
|
|
|
Vouchers struct {
|
2019-07-08 12:48:47 +01:00
|
|
|
Endpoint *vouchers.Endpoint
|
2019-05-30 20:52:33 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
Console struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Service *console.Service
|
|
|
|
Endpoint *consoleweb.Server
|
|
|
|
}
|
2019-06-11 16:00:59 +01:00
|
|
|
|
|
|
|
Marketing struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Endpoint *marketingweb.Server
|
|
|
|
}
|
2019-06-25 11:40:32 +01:00
|
|
|
|
|
|
|
NodeStats struct {
|
|
|
|
Endpoint *nodestats.Endpoint
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates a new satellite
|
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-18 13:54:08 +00:00
|
|
|
peer := &Peer{
|
2019-02-11 11:17:32 +00:00
|
|
|
Log: log,
|
|
|
|
Identity: full,
|
|
|
|
DB: db,
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
2019-04-03 20:13:39 +01:00
|
|
|
{
|
|
|
|
test := version.Info{}
|
|
|
|
if test != versionInfo {
|
|
|
|
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-07-31 15:38:44 +01:00
|
|
|
peer.Version = version.NewService(log.Named("version"), config.Version, versionInfo, "Satellite")
|
2019-04-03 20:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
{ // setup listener and server
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Starting 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-18 13:54:08 +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-18 13:54:08 +00:00
|
|
|
|
2019-06-04 13:55:24 +01:00
|
|
|
unaryInterceptor := grpcauth.NewAPIKeyInterceptor()
|
|
|
|
if sc.DebugLogTraffic {
|
|
|
|
unaryInterceptor = server.CombineInterceptors(unaryInterceptor, server.UnaryMessageLoggingInterceptor(log))
|
|
|
|
}
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Server, err = server.New(log.Named("server"), tlsOptions, sc.Address, sc.PrivateAddress, unaryInterceptor)
|
2019-01-18 13:54:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 09:25:13 +00:00
|
|
|
{ // setup overlay
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Starting overlay")
|
2019-02-08 09:25:13 +00:00
|
|
|
|
2019-08-06 23:56:12 +01:00
|
|
|
peer.Overlay.DB = overlay.NewCombinedCache(peer.DB.OverlayCache())
|
|
|
|
peer.Overlay.Service = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, config.Overlay)
|
2019-02-08 09:25:13 +00:00
|
|
|
|
|
|
|
peer.Overlay.Inspector = overlay.NewInspector(peer.Overlay.Service)
|
2019-03-07 18:19:37 +00:00
|
|
|
pb.RegisterOverlayInspectorServer(peer.Server.PrivateGRPC(), peer.Overlay.Inspector)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterOverlayInspector(peer.Server.PrivateDRPC(), peer.Overlay.Inspector)
|
2019-02-08 09:25:13 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
{ // setup contact service
|
|
|
|
log.Debug("Setting up contact service")
|
|
|
|
c := config.Contact
|
|
|
|
if c.ExternalAddress == "" {
|
|
|
|
c.ExternalAddress = peer.Addr()
|
2019-01-18 13:54:08 +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{
|
2019-09-19 20:56:34 +01:00
|
|
|
Address: c.ExternalAddress,
|
2019-04-22 10:07:50 +01:00
|
|
|
},
|
2019-01-18 13:54:08 +00:00
|
|
|
},
|
2019-09-19 20:56:34 +01:00
|
|
|
Type: pb.NodeType_SATELLITE,
|
2019-04-22 10:07:50 +01:00
|
|
|
Version: *pbVersion,
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Contact.Service = contact.NewService(peer.Log.Named("contact:service"), self, peer.Overlay.Service, peer.DB.PeerIdentities(), peer.Dialer)
|
2019-09-06 17:14:03 +01:00
|
|
|
peer.Contact.Endpoint = contact.NewEndpoint(peer.Log.Named("contact:endpoint"), peer.Contact.Service)
|
2019-09-19 20:56:34 +01:00
|
|
|
peer.Contact.KEndpoint = contact.NewKademliaEndpoint(peer.Log.Named("contact:nodes_service_endpoint"))
|
2019-09-06 17:14:03 +01:00
|
|
|
pb.RegisterNodeServer(peer.Server.GRPC(), peer.Contact.Endpoint)
|
2019-09-19 20:56:34 +01:00
|
|
|
pb.RegisterNodesServer(peer.Server.GRPC(), peer.Contact.KEndpoint)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterNode(peer.Server.DRPC(), peer.Contact.Endpoint)
|
2019-09-19 20:56:34 +01:00
|
|
|
pb.DRPCRegisterNodes(peer.Server.DRPC(), peer.Contact.KEndpoint)
|
2019-09-04 20:04:18 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
{ // setup discovery
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Setting up discovery")
|
2019-01-18 13:54:08 +00:00
|
|
|
config := config.Discovery
|
2019-09-19 20:56:34 +01:00
|
|
|
peer.Discovery.Service = discovery.New(peer.Log.Named("discovery"), peer.Overlay.Service, peer.Contact.Service, config)
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 20:52:33 +01:00
|
|
|
{ // setup vouchers
|
|
|
|
log.Debug("Setting up vouchers")
|
2019-07-08 12:48:47 +01:00
|
|
|
pb.RegisterVouchersServer(peer.Server.GRPC(), peer.Vouchers.Endpoint)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterVouchers(peer.Server.DRPC(), peer.Vouchers.Endpoint)
|
2019-05-30 20:52:33 +01:00
|
|
|
}
|
|
|
|
|
2019-05-10 02:39:21 +01:00
|
|
|
{ // setup live accounting
|
|
|
|
log.Debug("Setting up live accounting")
|
|
|
|
config := config.LiveAccounting
|
|
|
|
liveAccountingService, err := live.New(peer.Log.Named("live-accounting"), config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
peer.LiveAccounting.Service = liveAccountingService
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:36:52 +01:00
|
|
|
{ // setup accounting project usage
|
|
|
|
log.Debug("Setting up accounting project usage")
|
|
|
|
peer.Accounting.ProjectUsage = accounting.NewProjectUsage(
|
|
|
|
peer.DB.ProjectAccounting(),
|
|
|
|
peer.LiveAccounting.Service,
|
|
|
|
config.Rollup.MaxAlphaUsage,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-03-28 20:09:23 +00:00
|
|
|
{ // setup orders
|
|
|
|
log.Debug("Setting up orders")
|
|
|
|
satelliteSignee := signing.SigneeFromPeerIdentity(peer.Identity.PeerIdentity())
|
|
|
|
peer.Orders.Endpoint = orders.NewEndpoint(
|
|
|
|
peer.Log.Named("orders:endpoint"),
|
|
|
|
satelliteSignee,
|
2019-07-11 21:51:40 +01:00
|
|
|
peer.DB.Orders(),
|
2019-08-19 14:36:11 +01:00
|
|
|
config.Orders.SettlementBatchSize,
|
2019-03-28 20:09:23 +00:00
|
|
|
)
|
|
|
|
peer.Orders.Service = orders.NewService(
|
|
|
|
peer.Log.Named("orders:service"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DB.Orders(),
|
2019-06-21 11:38:40 +01:00
|
|
|
config.Orders.Expiration,
|
2019-06-21 10:19:52 +01:00
|
|
|
&pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
2019-09-19 20:56:34 +01:00
|
|
|
Address: config.Contact.ExternalAddress,
|
2019-06-21 10:19:52 +01:00
|
|
|
},
|
2019-07-11 23:44:47 +01:00
|
|
|
config.Repairer.MaxExcessRateOptimalThreshold,
|
2019-03-28 20:09:23 +00:00
|
|
|
)
|
|
|
|
pb.RegisterOrdersServer(peer.Server.GRPC(), peer.Orders.Endpoint)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterOrders(peer.Server.DRPC(), peer.Orders.Endpoint.DRPC())
|
2019-03-28 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
{ // setup metainfo
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Setting up metainfo")
|
2019-05-14 16:13:18 +01:00
|
|
|
db, err := metainfo.NewStore(peer.Log.Named("metainfo:store"), config.Metainfo.DatabaseURL)
|
2019-01-18 13:54:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-04-19 14:30:55 +01:00
|
|
|
peer.Metainfo.Database = db // for logging: storelogger.New(peer.Log.Named("pdb"), db)
|
2019-07-08 23:32:18 +01:00
|
|
|
peer.Metainfo.Service = metainfo.NewService(peer.Log.Named("metainfo:service"),
|
|
|
|
peer.Metainfo.Database,
|
|
|
|
peer.DB.Buckets(),
|
|
|
|
)
|
2019-07-22 14:34:12 +01:00
|
|
|
peer.Metainfo.Loop = metainfo.NewLoop(config.Metainfo.Loop, peer.Metainfo.Service)
|
2019-02-05 17:22:17 +00:00
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
peer.Metainfo.Endpoint2 = metainfo.NewEndpoint(
|
|
|
|
peer.Log.Named("metainfo:endpoint"),
|
|
|
|
peer.Metainfo.Service,
|
2019-03-28 20:09:23 +00:00
|
|
|
peer.Orders.Service,
|
2019-03-18 10:55:06 +00:00
|
|
|
peer.Overlay.Service,
|
2019-06-21 20:14:34 +01:00
|
|
|
peer.DB.Attribution(),
|
2019-09-18 14:50:33 +01:00
|
|
|
peer.DB.PeerIdentities(),
|
2019-03-18 10:55:06 +00:00
|
|
|
peer.DB.Console().APIKeys(),
|
2019-05-28 16:36:52 +01:00
|
|
|
peer.Accounting.ProjectUsage,
|
2019-06-21 19:15:58 +01:00
|
|
|
config.Metainfo.RS,
|
2019-07-16 11:39:23 +01:00
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
2019-03-23 08:06:11 +00:00
|
|
|
)
|
2019-03-18 10:55:06 +00:00
|
|
|
|
|
|
|
pb.RegisterMetainfoServer(peer.Server.GRPC(), peer.Metainfo.Endpoint2)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterMetainfo(peer.Server.DRPC(), peer.Metainfo.Endpoint2)
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup datarepair
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Setting up datarepair")
|
2019-01-18 13:54:08 +00:00
|
|
|
// TODO: simplify argument list somehow
|
|
|
|
peer.Repair.Checker = checker.NewChecker(
|
2019-08-01 19:44:32 +01:00
|
|
|
peer.Log.Named("checker"),
|
2019-03-25 22:25:09 +00:00
|
|
|
peer.DB.RepairQueue(),
|
2019-08-01 19:44:32 +01:00
|
|
|
peer.DB.Irreparable(),
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
peer.Metainfo.Loop,
|
|
|
|
peer.Overlay.Service,
|
2019-07-08 23:04:35 +01:00
|
|
|
config.Checker)
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-09-06 20:20:36 +01:00
|
|
|
segmentRepairer := repairer.NewSegmentRepairer(
|
|
|
|
log.Named("repairer"),
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
peer.Orders.Service,
|
|
|
|
peer.Overlay.Service,
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Dialer,
|
2019-09-06 20:20:36 +01:00
|
|
|
config.Repairer.Timeout,
|
|
|
|
config.Repairer.MaxExcessRateOptimalThreshold,
|
|
|
|
signing.SigneeFromPeerIdentity(peer.Identity.PeerIdentity()),
|
|
|
|
)
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
peer.Repair.Repairer = repairer.NewService(
|
2019-07-02 11:08:02 +01:00
|
|
|
peer.Log.Named("repairer"),
|
2019-03-18 10:55:06 +00:00
|
|
|
peer.DB.RepairQueue(),
|
|
|
|
&config.Repairer,
|
2019-09-06 20:20:36 +01:00
|
|
|
segmentRepairer,
|
2019-03-18 10:55:06 +00:00
|
|
|
)
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
peer.Repair.Inspector = irreparable.NewInspector(peer.DB.Irreparable())
|
|
|
|
pb.RegisterIrreparableInspectorServer(peer.Server.PrivateGRPC(), peer.Repair.Inspector)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterIrreparableInspector(peer.Server.PrivateDRPC(), peer.Repair.Inspector)
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup audit
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Setting up audits")
|
2019-01-23 19:58:44 +00:00
|
|
|
config := config.Audit
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
peer.Audit.Queue = &audit.Queue{}
|
|
|
|
|
|
|
|
peer.Audit.Verifier = audit.NewVerifier(log.Named("audit:verifier"),
|
2019-03-28 20:09:23 +00:00
|
|
|
peer.Metainfo.Service,
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Dialer,
|
2019-03-28 20:09:23 +00:00
|
|
|
peer.Overlay.Service,
|
2019-05-23 21:07:19 +01:00
|
|
|
peer.DB.Containment(),
|
2019-09-11 23:37:01 +01:00
|
|
|
peer.Orders.Service,
|
2019-01-23 19:58:44 +00:00
|
|
|
peer.Identity,
|
2019-09-11 23:37:01 +01:00
|
|
|
config.MinBytesPerSecond,
|
|
|
|
config.MinDownloadTimeout,
|
2019-01-23 19:58:44 +00:00
|
|
|
)
|
2019-08-21 16:49:27 +01:00
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
peer.Audit.Reporter = audit.NewReporter(log.Named("audit:reporter"),
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DB.Containment(),
|
|
|
|
config.MaxRetriesStatDB,
|
|
|
|
int32(config.MaxReverifyCount),
|
|
|
|
)
|
2019-09-05 16:40:52 +01:00
|
|
|
|
|
|
|
peer.Audit.Worker, err = audit.NewWorker(peer.Log.Named("audit worker"),
|
|
|
|
peer.Audit.Queue,
|
2019-09-11 23:37:01 +01:00
|
|
|
peer.Audit.Verifier,
|
|
|
|
peer.Audit.Reporter,
|
2019-09-05 16:40:52 +01:00
|
|
|
config,
|
|
|
|
)
|
2019-09-11 23:37:01 +01:00
|
|
|
|
2019-09-05 16:40:52 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
peer.Audit.Chore = audit.NewChore(peer.Log.Named("audit chore"),
|
2019-09-05 16:40:52 +01:00
|
|
|
peer.Audit.Queue,
|
2019-08-21 16:49:27 +01:00
|
|
|
peer.Metainfo.Loop,
|
|
|
|
config,
|
|
|
|
)
|
2019-01-23 19:58:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 18:26:43 +01:00
|
|
|
{ // setup garbage collection
|
|
|
|
log.Debug("Setting up garbage collection")
|
|
|
|
|
|
|
|
peer.GarbageCollection.Service = gc.NewService(
|
|
|
|
peer.Log.Named("garbage collection"),
|
|
|
|
config.GarbageCollection,
|
2019-09-19 05:46:39 +01:00
|
|
|
peer.Dialer,
|
2019-08-06 23:56:12 +01:00
|
|
|
peer.Overlay.DB,
|
2019-07-24 18:26:43 +01:00
|
|
|
peer.Metainfo.Loop,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-08-27 18:12:38 +01:00
|
|
|
{ // setup db cleanup
|
|
|
|
log.Debug("Setting up db cleanup")
|
|
|
|
peer.DBCleanup.Chore = dbcleanup.NewChore(peer.Log.Named("dbcleanup"), peer.DB.Orders(), config.DBCleanup)
|
|
|
|
}
|
|
|
|
|
2019-01-23 19:58:44 +00:00
|
|
|
{ // setup accounting
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Setting up accounting")
|
2019-09-09 17:48:24 +01:00
|
|
|
peer.Accounting.Tally = tally.New(peer.Log.Named("tally"), peer.DB.StoragenodeAccounting(), peer.DB.ProjectAccounting(), peer.LiveAccounting.Service, peer.Metainfo.Service, peer.Overlay.Service, config.Tally.Interval)
|
2019-05-10 20:05:42 +01:00
|
|
|
peer.Accounting.Rollup = rollup.New(peer.Log.Named("rollup"), peer.DB.StoragenodeAccounting(), config.Rollup.Interval, config.Rollup.DeleteTallies)
|
2019-01-23 19:58:44 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 15:55:58 +01:00
|
|
|
{ // setup inspector
|
|
|
|
log.Debug("Setting up inspector")
|
|
|
|
peer.Inspector.Endpoint = inspector.NewEndpoint(
|
|
|
|
peer.Log.Named("inspector"),
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
)
|
|
|
|
|
|
|
|
pb.RegisterHealthInspectorServer(peer.Server.PrivateGRPC(), peer.Inspector.Endpoint)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterHealthInspector(peer.Server.PrivateDRPC(), peer.Inspector.Endpoint)
|
2019-04-02 15:55:58 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
{ // setup mailservice
|
|
|
|
log.Debug("Setting up mail service")
|
|
|
|
// TODO(yar): test multiple satellites using same OAUTH credentials
|
|
|
|
mailConfig := config.Mail
|
|
|
|
|
|
|
|
// validate from mail address
|
|
|
|
from, err := mail.ParseAddress(mailConfig.From)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate smtp server address
|
|
|
|
host, _, err := net.SplitHostPort(mailConfig.SMTPServerAddress)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
var sender mailservice.Sender
|
|
|
|
switch mailConfig.AuthType {
|
|
|
|
case "oauth2":
|
|
|
|
creds := oauth2.Credentials{
|
|
|
|
ClientID: mailConfig.ClientID,
|
|
|
|
ClientSecret: mailConfig.ClientSecret,
|
|
|
|
TokenURI: mailConfig.TokenURI,
|
|
|
|
}
|
2019-06-05 16:03:11 +01:00
|
|
|
token, err := oauth2.RefreshToken(context.TODO(), creds, mailConfig.RefreshToken)
|
2019-03-02 15:22:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
sender = &post.SMTPSender{
|
|
|
|
From: *from,
|
|
|
|
Auth: &oauth2.Auth{
|
|
|
|
UserEmail: from.Address,
|
|
|
|
Storage: oauth2.NewTokenStore(creds, *token),
|
|
|
|
},
|
|
|
|
ServerAddress: mailConfig.SMTPServerAddress,
|
|
|
|
}
|
|
|
|
case "plain":
|
|
|
|
sender = &post.SMTPSender{
|
|
|
|
From: *from,
|
2019-03-24 00:08:41 +00:00
|
|
|
Auth: smtp.PlainAuth("", mailConfig.Login, mailConfig.Password, host),
|
|
|
|
ServerAddress: mailConfig.SMTPServerAddress,
|
|
|
|
}
|
|
|
|
case "login":
|
|
|
|
sender = &post.SMTPSender{
|
|
|
|
From: *from,
|
|
|
|
Auth: post.LoginAuth{
|
|
|
|
Username: mailConfig.Login,
|
|
|
|
Password: mailConfig.Password,
|
|
|
|
},
|
2019-03-02 15:22:20 +00:00
|
|
|
ServerAddress: mailConfig.SMTPServerAddress,
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
sender = &simulate.LinkClicker{}
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Mail.Service, err = mailservice.New(
|
2019-03-26 15:56:16 +00:00
|
|
|
peer.Log.Named("mail:service"),
|
2019-03-02 15:22:20 +00:00
|
|
|
sender,
|
|
|
|
mailConfig.TemplatePath,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 16:26:36 +00:00
|
|
|
{ // setup console
|
2019-02-28 20:12:52 +00:00
|
|
|
log.Debug("Setting up console")
|
2019-03-02 15:22:20 +00:00
|
|
|
consoleConfig := config.Console
|
2019-01-24 16:26:36 +00:00
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
peer.Console.Listener, err = net.Listen("tcp", consoleConfig.Address)
|
2019-01-24 16:26:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-05-28 15:32:51 +01:00
|
|
|
if consoleConfig.AuthTokenSecret == "" {
|
|
|
|
return nil, errs.New("Auth token secret required")
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
peer.Console.Service, err = console.NewService(
|
|
|
|
peer.Log.Named("console:service"),
|
2019-05-28 15:32:51 +01:00
|
|
|
&consoleauth.Hmac{Secret: []byte(consoleConfig.AuthTokenSecret)},
|
2019-02-05 17:31:53 +00:00
|
|
|
peer.DB.Console(),
|
2019-07-02 15:36:54 +01:00
|
|
|
peer.DB.Rewards(),
|
2019-03-02 15:22:20 +00:00
|
|
|
consoleConfig.PasswordCost,
|
2019-02-05 17:31:53 +00:00
|
|
|
)
|
2019-01-24 16:26:36 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:22:20 +00:00
|
|
|
peer.Console.Endpoint = consoleweb.NewServer(
|
|
|
|
peer.Log.Named("console:endpoint"),
|
|
|
|
consoleConfig,
|
2019-01-24 16:26:36 +00:00
|
|
|
peer.Console.Service,
|
2019-03-02 15:22:20 +00:00
|
|
|
peer.Mail.Service,
|
|
|
|
peer.Console.Listener,
|
|
|
|
)
|
2019-01-24 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 16:00:59 +01:00
|
|
|
{ // setup marketing portal
|
|
|
|
log.Debug("Setting up marketing server")
|
|
|
|
marketingConfig := config.Marketing
|
|
|
|
|
|
|
|
peer.Marketing.Listener, err = net.Listen("tcp", marketingConfig.Address)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-06-12 21:27:07 +01:00
|
|
|
peer.Marketing.Endpoint, err = marketingweb.NewServer(
|
2019-06-11 16:00:59 +01:00
|
|
|
peer.Log.Named("marketing:endpoint"),
|
|
|
|
marketingConfig,
|
2019-06-28 15:34:10 +01:00
|
|
|
peer.DB.Rewards(),
|
2019-06-11 16:00:59 +01:00
|
|
|
peer.Marketing.Listener,
|
|
|
|
)
|
2019-06-12 21:27:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-06-11 16:00:59 +01:00
|
|
|
}
|
|
|
|
|
2019-06-25 11:40:32 +01:00
|
|
|
{ // setup node stats endpoint
|
|
|
|
log.Debug("Setting up node stats endpoint")
|
|
|
|
|
|
|
|
peer.NodeStats.Endpoint = nodestats.NewEndpoint(
|
|
|
|
peer.Log.Named("nodestats:endpoint"),
|
2019-08-06 23:56:12 +01:00
|
|
|
peer.Overlay.DB,
|
2019-07-02 11:42:09 +01:00
|
|
|
peer.DB.StoragenodeAccounting())
|
2019-06-25 11:40:32 +01:00
|
|
|
|
|
|
|
pb.RegisterNodeStatsServer(peer.Server.GRPC(), peer.NodeStats.Endpoint)
|
2019-09-12 22:09:46 +01:00
|
|
|
pb.DRPCRegisterNodeStats(peer.Server.DRPC(), peer.NodeStats.Endpoint)
|
2019-06-25 11:40:32 +01:00
|
|
|
}
|
|
|
|
|
2019-01-18 13:54:08 +00:00
|
|
|
return peer, nil
|
|
|
|
}
|
|
|
|
|
2019-06-07 12:40:20 +01:00
|
|
|
// Run runs satellite until it's either closed or it errors.
|
2019-06-04 12:55:38 +01:00
|
|
|
func (peer *Peer) Run(ctx context.Context) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
|
2019-02-06 13:19:14 +00:00
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
2019-01-18 13:54:08 +00:00
|
|
|
|
2019-09-23 20:14:39 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Metainfo.Loop.Run(ctx))
|
|
|
|
})
|
2019-01-18 13:54:08 +00: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-01-18 13:54:08 +00:00
|
|
|
group.Go(func() error {
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Discovery.Service.Run(ctx))
|
2019-01-18 13:54:08 +00:00
|
|
|
})
|
|
|
|
group.Go(func() error {
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Repair.Checker.Run(ctx))
|
2019-01-18 13:54:08 +00:00
|
|
|
})
|
|
|
|
group.Go(func() error {
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Repair.Repairer.Run(ctx))
|
2019-01-18 13:54:08 +00:00
|
|
|
})
|
2019-09-09 17:48:24 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.DBCleanup.Chore.Run(ctx))
|
|
|
|
})
|
2019-01-24 18:44:14 +00:00
|
|
|
group.Go(func() error {
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Accounting.Tally.Run(ctx))
|
2019-01-24 18:44:14 +00:00
|
|
|
})
|
|
|
|
group.Go(func() error {
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Accounting.Rollup.Run(ctx))
|
2019-01-24 18:44:14 +00:00
|
|
|
})
|
2019-08-21 16:49:27 +01:00
|
|
|
group.Go(func() error {
|
2019-09-05 16:40:52 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Audit.Worker.Run(ctx))
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Audit.Chore.Run(ctx))
|
2019-08-21 16:49:27 +01:00
|
|
|
})
|
2019-07-24 18:26:43 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.GarbageCollection.Service.Run(ctx))
|
|
|
|
})
|
2019-01-18 13:54:08 +00:00
|
|
|
group.Go(func() error {
|
2019-01-23 19:58:44 +00:00
|
|
|
// 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-18 13:54:08 +00:00
|
|
|
})
|
2019-01-24 16:26:36 +00:00
|
|
|
group.Go(func() error {
|
2019-04-17 11:09:44 +01:00
|
|
|
return errs2.IgnoreCanceled(peer.Console.Endpoint.Run(ctx))
|
2019-01-24 16:26:36 +00:00
|
|
|
})
|
2019-06-11 16:00:59 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Marketing.Endpoint.Run(ctx))
|
|
|
|
})
|
2019-01-18 13:54:08 +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-24 16:26:36 +00:00
|
|
|
if peer.Console.Endpoint != nil {
|
|
|
|
errlist.Add(peer.Console.Endpoint.Close())
|
2019-05-29 14:14:25 +01:00
|
|
|
} else if peer.Console.Listener != nil {
|
|
|
|
errlist.Add(peer.Console.Listener.Close())
|
2019-01-24 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 13:29:35 +01:00
|
|
|
if peer.Mail.Service != nil {
|
|
|
|
errlist.Add(peer.Mail.Service.Close())
|
|
|
|
}
|
|
|
|
|
2019-06-11 16:00:59 +01:00
|
|
|
if peer.Marketing.Endpoint != nil {
|
|
|
|
errlist.Add(peer.Marketing.Endpoint.Close())
|
|
|
|
} else if peer.Marketing.Listener != nil {
|
|
|
|
errlist.Add(peer.Marketing.Listener.Close())
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:48:24 +01:00
|
|
|
// close services in reverse initialization order
|
|
|
|
|
2019-09-05 16:40:52 +01:00
|
|
|
if peer.Audit.Chore != nil {
|
|
|
|
errlist.Add(peer.Audit.Chore.Close())
|
|
|
|
}
|
|
|
|
if peer.Audit.Worker != nil {
|
|
|
|
errlist.Add(peer.Audit.Worker.Close())
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:48:24 +01:00
|
|
|
if peer.Accounting.Rollup != nil {
|
|
|
|
errlist.Add(peer.Accounting.Rollup.Close())
|
|
|
|
}
|
|
|
|
if peer.Accounting.Tally != nil {
|
|
|
|
errlist.Add(peer.Accounting.Tally.Close())
|
|
|
|
}
|
|
|
|
|
2019-08-27 18:12:38 +01:00
|
|
|
if peer.DBCleanup.Chore != nil {
|
|
|
|
errlist.Add(peer.DBCleanup.Chore.Close())
|
|
|
|
}
|
2019-01-18 13:54:08 +00:00
|
|
|
if peer.Repair.Repairer != nil {
|
|
|
|
errlist.Add(peer.Repair.Repairer.Close())
|
|
|
|
}
|
|
|
|
if peer.Repair.Checker != nil {
|
|
|
|
errlist.Add(peer.Repair.Checker.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
if peer.Metainfo.Database != nil {
|
|
|
|
errlist.Add(peer.Metainfo.Database.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
if peer.Discovery.Service != nil {
|
|
|
|
errlist.Add(peer.Discovery.Service.Close())
|
|
|
|
}
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
if peer.Contact.Service != nil {
|
|
|
|
errlist.Add(peer.Contact.Service.Close())
|
2019-01-18 13:54:08 +00:00
|
|
|
}
|
2019-02-08 09:25:13 +00:00
|
|
|
if peer.Overlay.Service != nil {
|
|
|
|
errlist.Add(peer.Overlay.Service.Close())
|
|
|
|
}
|
2019-09-23 20:14:39 +01:00
|
|
|
if peer.Metainfo.Loop != nil {
|
|
|
|
errlist.Add(peer.Metainfo.Loop.Close())
|
|
|
|
}
|
2019-02-08 09:25:13 +00:00
|
|
|
|
2019-01-18 13:54:08 +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-18 13:54:08 +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() }
|