2019-10-03 00:02:47 +01: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-04-15 14:57:14 +01:00
|
|
|
"fmt"
|
2019-10-03 00:02:47 +01:00
|
|
|
"net"
|
|
|
|
"net/mail"
|
|
|
|
"net/smtp"
|
|
|
|
|
2020-03-11 15:36:55 +00:00
|
|
|
monkit "github.com/spacemonkeygo/monkit/v3"
|
2019-10-03 00:02:47 +01: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"
|
2019-10-03 00:02:47 +01:00
|
|
|
"storj.io/storj/pkg/server"
|
2020-01-28 23:13:59 +00:00
|
|
|
"storj.io/storj/private/lifecycle"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/post"
|
|
|
|
"storj.io/storj/private/post/oauth2"
|
|
|
|
"storj.io/storj/private/version/checker"
|
2019-10-03 00:02:47 +01:00
|
|
|
"storj.io/storj/satellite/accounting"
|
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
"storj.io/storj/satellite/console/consoleauth"
|
|
|
|
"storj.io/storj/satellite/console/consoleweb"
|
|
|
|
"storj.io/storj/satellite/contact"
|
2019-10-14 21:01:53 +01:00
|
|
|
"storj.io/storj/satellite/gracefulexit"
|
2020-03-15 22:16:56 +00:00
|
|
|
"storj.io/storj/satellite/heldamount"
|
2019-10-03 00:02:47 +01:00
|
|
|
"storj.io/storj/satellite/inspector"
|
|
|
|
"storj.io/storj/satellite/mailservice"
|
|
|
|
"storj.io/storj/satellite/mailservice/simulate"
|
|
|
|
"storj.io/storj/satellite/marketingweb"
|
|
|
|
"storj.io/storj/satellite/metainfo"
|
2020-03-12 07:03:46 +00:00
|
|
|
"storj.io/storj/satellite/metainfo/piecedeletion"
|
2019-10-03 00:02:47 +01:00
|
|
|
"storj.io/storj/satellite/nodestats"
|
|
|
|
"storj.io/storj/satellite/orders"
|
|
|
|
"storj.io/storj/satellite/overlay"
|
2019-10-23 13:04:54 +01:00
|
|
|
"storj.io/storj/satellite/payments"
|
2019-10-17 15:42:18 +01:00
|
|
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
2019-11-25 21:36:36 +00:00
|
|
|
"storj.io/storj/satellite/referrals"
|
2019-10-03 00:02:47 +01:00
|
|
|
"storj.io/storj/satellite/repair/irreparable"
|
2019-11-05 12:58:09 +00:00
|
|
|
"storj.io/storj/satellite/rewards"
|
2019-10-03 00:02:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// API is the satellite API process
|
|
|
|
//
|
|
|
|
// architecture: Peer
|
|
|
|
type API struct {
|
|
|
|
Log *zap.Logger
|
|
|
|
Identity *identity.FullIdentity
|
|
|
|
DB DB
|
|
|
|
|
2020-01-28 23:13:59 +00:00
|
|
|
Servers *lifecycle.Group
|
|
|
|
Services *lifecycle.Group
|
|
|
|
|
2020-02-21 17:41:54 +00:00
|
|
|
Dialer rpc.Dialer
|
|
|
|
Server *server.Server
|
|
|
|
|
|
|
|
Version struct {
|
|
|
|
Chore *checker.Chore
|
|
|
|
Service *checker.Service
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
|
2020-01-28 17:35:45 +00:00
|
|
|
Debug struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Server *debug.Server
|
|
|
|
}
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
Contact struct {
|
2019-10-14 15:57:01 +01:00
|
|
|
Service *contact.Service
|
|
|
|
Endpoint *contact.Endpoint
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Overlay struct {
|
|
|
|
DB overlay.DB
|
|
|
|
Service *overlay.Service
|
|
|
|
Inspector *overlay.Inspector
|
|
|
|
}
|
|
|
|
|
|
|
|
Orders struct {
|
2020-01-10 18:53:42 +00:00
|
|
|
DB orders.DB
|
2019-10-03 00:02:47 +01:00
|
|
|
Endpoint *orders.Endpoint
|
|
|
|
Service *orders.Service
|
2020-01-10 18:53:42 +00:00
|
|
|
Chore *orders.Chore
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Metainfo struct {
|
2020-03-12 07:03:46 +00:00
|
|
|
Database metainfo.PointerDB
|
|
|
|
Service *metainfo.Service
|
|
|
|
PieceDeletion *piecedeletion.Service
|
|
|
|
Endpoint2 *metainfo.Endpoint
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Inspector struct {
|
|
|
|
Endpoint *inspector.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
Repair struct {
|
|
|
|
Inspector *irreparable.Inspector
|
|
|
|
}
|
|
|
|
|
|
|
|
Accounting struct {
|
2019-11-15 14:27:44 +00:00
|
|
|
ProjectUsage *accounting.Service
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LiveAccounting struct {
|
2019-10-16 17:50:29 +01:00
|
|
|
Cache accounting.Cache
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Mail struct {
|
|
|
|
Service *mailservice.Service
|
|
|
|
}
|
|
|
|
|
2019-10-23 13:04:54 +01:00
|
|
|
Payments struct {
|
2020-05-18 13:21:35 +01:00
|
|
|
Accounts payments.Accounts
|
|
|
|
Version *stripecoinpayments.VersionService
|
2020-05-18 10:17:05 +01:00
|
|
|
Service *stripecoinpayments.Service
|
2020-05-28 12:31:02 +01:00
|
|
|
Stripe stripecoinpayments.StripeClient
|
2019-10-23 13:04:54 +01:00
|
|
|
}
|
|
|
|
|
2019-11-25 21:36:36 +00:00
|
|
|
Referrals struct {
|
|
|
|
Service *referrals.Service
|
|
|
|
}
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
Console struct {
|
|
|
|
Listener net.Listener
|
|
|
|
Service *console.Service
|
|
|
|
Endpoint *consoleweb.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
Marketing struct {
|
2019-11-05 12:58:09 +00:00
|
|
|
PartnersService *rewards.PartnersService
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
Listener net.Listener
|
|
|
|
Endpoint *marketingweb.Server
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeStats struct {
|
|
|
|
Endpoint *nodestats.Endpoint
|
|
|
|
}
|
2019-10-14 21:01:53 +01:00
|
|
|
|
2020-03-15 22:16:56 +00:00
|
|
|
HeldAmount struct {
|
|
|
|
Endpoint *heldamount.Endpoint
|
|
|
|
Service *heldamount.Service
|
|
|
|
DB heldamount.DB
|
|
|
|
}
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
GracefulExit struct {
|
|
|
|
Endpoint *gracefulexit.Endpoint
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// NewAPI creates a new satellite API process.
|
2020-01-17 22:55:53 +00:00
|
|
|
func NewAPI(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
|
|
|
config *Config, versionInfo version.Info, atomicLogLevel *zap.AtomicLevel) (*API, error) {
|
2019-10-03 00:02:47 +01:00
|
|
|
peer := &API{
|
|
|
|
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-10-03 00:02:47 +01: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 = "API"
|
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-10-03 00:02:47 +01:00
|
|
|
var err error
|
|
|
|
|
|
|
|
{
|
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 = checker.NewService(log.Named("version"), config.Version, versionInfo, "Satellite")
|
|
|
|
peer.Version.Chore = 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-10-03 00:02:47 +01: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)
|
|
|
|
|
2020-05-06 11:54:14 +01:00
|
|
|
peer.Server, err = server.New(log.Named("server"), tlsOptions, sc.Address, sc.PrivateAddress)
|
2019-10-03 00:02:47 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Servers.Add(lifecycle.Item{
|
|
|
|
Name: "server",
|
|
|
|
Run: func(ctx context.Context) error {
|
|
|
|
// Don't change the format of this comment, it is used to figure out the node id.
|
2020-04-15 14:57:14 +01:00
|
|
|
peer.Log.Info(fmt.Sprintf("Node %s started", peer.Identity.ID))
|
|
|
|
peer.Log.Info(fmt.Sprintf("Public server started on %s", peer.Addr()))
|
|
|
|
peer.Log.Info(fmt.Sprintf("Private server started on %s", peer.PrivateAddr()))
|
2020-01-28 23:13:59 +00:00
|
|
|
return peer.Server.Run(ctx)
|
|
|
|
},
|
|
|
|
Close: peer.Server.Close,
|
|
|
|
})
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup overlay
|
2020-03-12 18:37:57 +00:00
|
|
|
peer.Overlay.DB = peer.DB.OverlayCache()
|
2020-01-28 23:13:59 +00:00
|
|
|
|
2019-10-03 00:02:47 +01: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-10-03 00:02:47 +01:00
|
|
|
peer.Overlay.Inspector = overlay.NewInspector(peer.Overlay.Service)
|
2020-03-24 17:49:20 +00:00
|
|
|
if err := pb.DRPCRegisterOverlayInspector(peer.Server.PrivateDRPC(), peer.Overlay.Inspector); err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup contact service
|
|
|
|
c := config.Contact
|
|
|
|
if c.ExternalAddress == "" {
|
|
|
|
c.ExternalAddress = peer.Addr()
|
|
|
|
}
|
|
|
|
|
|
|
|
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: c.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)
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Contact.Endpoint = contact.NewEndpoint(peer.Log.Named("contact:endpoint"), peer.Contact.Service)
|
2020-03-24 17:49:20 +00:00
|
|
|
if err := pb.DRPCRegisterNode(peer.Server.DRPC(), peer.Contact.Endpoint); err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "contact:service",
|
|
|
|
Close: peer.Contact.Service.Close,
|
|
|
|
})
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup live accounting
|
2019-10-16 17:50:29 +01:00
|
|
|
peer.LiveAccounting.Cache = liveAccounting
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup accounting project usage
|
2019-11-15 14:27:44 +00:00
|
|
|
peer.Accounting.ProjectUsage = accounting.NewService(
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.DB.ProjectAccounting(),
|
2019-10-16 17:50:29 +01:00
|
|
|
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-10-03 00:02:47 +01: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: "orders:chore",
|
|
|
|
Run: peer.Orders.Chore.Run,
|
|
|
|
Close: peer.Orders.Chore.Close,
|
|
|
|
})
|
2020-01-30 13:06:43 +00:00
|
|
|
peer.Debug.Server.Panel.Add(
|
|
|
|
debug.Cycle("Orders Chore", peer.Orders.Chore.Loop))
|
2020-01-28 23:13:59 +00:00
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
satelliteSignee := signing.SigneeFromPeerIdentity(peer.Identity.PeerIdentity())
|
|
|
|
peer.Orders.Endpoint = orders.NewEndpoint(
|
|
|
|
peer.Log.Named("orders:endpoint"),
|
|
|
|
satelliteSignee,
|
2020-01-10 18:53:42 +00:00
|
|
|
peer.Orders.DB,
|
2020-07-15 18:08:24 +01:00
|
|
|
peer.DB.NodeAPIVersion(),
|
2019-10-03 00:02:47 +01:00
|
|
|
config.Orders.SettlementBatchSize,
|
satellite/orders: 3-phase rollout
This adds a config flag orders.window-endpoint-rollout-phase
that can take on the values phase1, phase2 or phase3.
In phase1, the current orders endpoint continues to work as
usual, and the windowed orders endpoint uses the same backend
as the current one (but also does a bit extra).
In phase2, the current orders endpoint is disabled and the
windowed orders endpoint continues to use the same backend.
In phase3, the current orders endpoint is still disabled and
the windowed orders endpoint uses the new backend that requires
much less database traffic and state.
The intention is to deploy in phase1, roll out code to nodes
to have them use the windowed endpoint, switch to phase2, wait
a couple days for all existing orders to expire, then switch
to phase3.
Additionally, it fixes a bug where a node could submit a bunch
of orders and rack up charges for a bucket.
Change-Id: Ifdc10e09ae1645159cbec7ace687dcb2d594c76d
2020-07-21 17:53:32 +01:00
|
|
|
config.Orders.WindowEndpointRolloutPhase,
|
2019-10-03 00:02:47 +01:00
|
|
|
)
|
2020-07-24 18:13:15 +01:00
|
|
|
var err error
|
|
|
|
peer.Orders.Service, err = orders.NewService(
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Log.Named("orders:service"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
peer.Overlay.Service,
|
2020-01-10 18:53:42 +00:00
|
|
|
peer.Orders.DB,
|
2020-06-25 15:47:44 +01:00
|
|
|
peer.DB.Buckets(),
|
2020-08-27 15:30:04 +01:00
|
|
|
config.Orders,
|
2019-10-03 00:02:47 +01:00
|
|
|
&pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
Address: config.Contact.ExternalAddress,
|
|
|
|
},
|
|
|
|
)
|
2020-07-24 18:13:15 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-05-11 06:20:34 +01:00
|
|
|
if err := pb.DRPCRegisterOrders(peer.Server.DRPC(), peer.Orders.Endpoint); err != nil {
|
2020-03-24 17:49:20 +00:00
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
2019-11-26 11:12:37 +00:00
|
|
|
{ // setup marketing portal
|
|
|
|
peer.Marketing.PartnersService = rewards.NewPartnersService(
|
|
|
|
peer.Log.Named("partners"),
|
|
|
|
rewards.DefaultPartnersDB,
|
|
|
|
[]string{
|
|
|
|
"https://us-central-1.tardigrade.io/",
|
|
|
|
"https://asia-east-1.tardigrade.io/",
|
|
|
|
"https://europe-west-1.tardigrade.io/",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
peer.Marketing.Listener, err = net.Listen("tcp", config.Marketing.Address)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Marketing.Endpoint, err = marketingweb.NewServer(
|
|
|
|
peer.Log.Named("marketing:endpoint"),
|
|
|
|
config.Marketing,
|
|
|
|
peer.DB.Rewards(),
|
|
|
|
peer.Marketing.PartnersService,
|
|
|
|
peer.Marketing.Listener,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Servers.Add(lifecycle.Item{
|
|
|
|
Name: "marketing:endpoint",
|
|
|
|
Run: peer.Marketing.Endpoint.Run,
|
|
|
|
Close: peer.Marketing.Endpoint.Close,
|
|
|
|
})
|
2019-11-26 11:12:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
{ // setup metainfo
|
2019-10-14 21:01:53 +01:00
|
|
|
peer.Metainfo.Database = pointerDB
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Metainfo.Service = metainfo.NewService(peer.Log.Named("metainfo:service"),
|
|
|
|
peer.Metainfo.Database,
|
|
|
|
peer.DB.Buckets(),
|
|
|
|
)
|
2020-01-09 17:09:22 +00:00
|
|
|
|
2020-03-12 07:03:46 +00:00
|
|
|
peer.Metainfo.PieceDeletion, err = piecedeletion.NewService(
|
|
|
|
peer.Log.Named("metainfo:piecedeletion"),
|
2020-01-09 17:09:22 +00:00
|
|
|
peer.Dialer,
|
2020-08-07 19:13:55 +01:00
|
|
|
peer.Overlay.Service,
|
2020-03-12 07:03:46 +00:00
|
|
|
config.Metainfo.PieceDeletion,
|
2020-01-09 17:09:22 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
peer.Services.Add(lifecycle.Item{
|
2020-03-12 07:03:46 +00:00
|
|
|
Name: "metainfo:piecedeletion",
|
|
|
|
Run: peer.Metainfo.PieceDeletion.Run,
|
|
|
|
Close: peer.Metainfo.PieceDeletion.Close,
|
2020-01-28 23:13:59 +00:00
|
|
|
})
|
2020-01-09 17:09:22 +00:00
|
|
|
|
2020-04-09 09:19:16 +01:00
|
|
|
peer.Metainfo.Endpoint2, err = metainfo.NewEndpoint(
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Log.Named("metainfo:endpoint"),
|
|
|
|
peer.Metainfo.Service,
|
2020-03-12 07:03:46 +00:00
|
|
|
peer.Metainfo.PieceDeletion,
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Orders.Service,
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.DB.Attribution(),
|
2019-11-26 11:12:37 +00:00
|
|
|
peer.Marketing.PartnersService,
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.DB.PeerIdentities(),
|
|
|
|
peer.DB.Console().APIKeys(),
|
|
|
|
peer.Accounting.ProjectUsage,
|
2020-01-17 15:01:36 +00:00
|
|
|
peer.DB.Console().Projects(),
|
2019-10-03 00:02:47 +01:00
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
2020-06-03 14:51:02 +01:00
|
|
|
peer.DB.Revocation(),
|
2020-04-01 10:15:24 +01:00
|
|
|
config.Metainfo,
|
2019-10-03 00:02:47 +01:00
|
|
|
)
|
2020-04-09 09:19:16 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:49:20 +00:00
|
|
|
if err := pb.DRPCRegisterMetainfo(peer.Server.DRPC(), peer.Metainfo.Endpoint2); err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "metainfo:endpoint",
|
|
|
|
Close: peer.Metainfo.Endpoint2.Close,
|
|
|
|
})
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup datarepair
|
|
|
|
peer.Repair.Inspector = irreparable.NewInspector(peer.DB.Irreparable())
|
2020-03-24 17:49:20 +00:00
|
|
|
if err := pb.DRPCRegisterIrreparableInspector(peer.Server.PrivateDRPC(), peer.Repair.Inspector); err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup inspector
|
|
|
|
peer.Inspector.Endpoint = inspector.NewEndpoint(
|
|
|
|
peer.Log.Named("inspector"),
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
)
|
2020-03-24 17:49:20 +00:00
|
|
|
if err := pb.DRPCRegisterHealthInspector(peer.Server.PrivateDRPC(), peer.Inspector.Endpoint); err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup mailservice
|
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
token, err := oauth2.RefreshToken(context.TODO(), creds, mailConfig.RefreshToken)
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
ServerAddress: mailConfig.SMTPServerAddress,
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
sender = &simulate.LinkClicker{}
|
|
|
|
}
|
|
|
|
|
|
|
|
peer.Mail.Service, err = mailservice.New(
|
|
|
|
peer.Log.Named("mail:service"),
|
|
|
|
sender,
|
|
|
|
mailConfig.TemplatePath,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "mail:service",
|
|
|
|
Close: peer.Mail.Service.Close,
|
|
|
|
})
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
2019-10-23 13:04:54 +01:00
|
|
|
{ // setup payments
|
2019-11-05 20:26:19 +00:00
|
|
|
pc := config.Payments
|
2019-10-23 13:04:54 +01: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 10:54:25 +00:00
|
|
|
default:
|
2020-07-27 20:43:47 +01:00
|
|
|
stripeClient = stripecoinpayments.NewStripeMock(peer.ID())
|
2019-11-04 10:54:25 +00:00
|
|
|
case "stripecoinpayments":
|
2020-05-18 10:17:05 +01:00
|
|
|
stripeClient = stripecoinpayments.NewStripeClient(log, pc.StripeCoinPayments)
|
|
|
|
}
|
2020-01-28 23:36:54 +00:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
peer.Payments.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,
|
2020-07-10 14:05:17 +01:00
|
|
|
pc.MinCoinPayment,
|
|
|
|
pc.PaywallProportion)
|
2019-11-04 10:54:25 +00:00
|
|
|
|
2020-05-18 10:17:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
2019-11-04 10:54:25 +00:00
|
|
|
}
|
2020-05-18 10:17:05 +01:00
|
|
|
|
2020-05-28 12:31:02 +01:00
|
|
|
peer.Payments.Stripe = stripeClient
|
2020-05-18 10:17:05 +01:00
|
|
|
peer.Payments.Accounts = peer.Payments.Service.Accounts()
|
|
|
|
peer.Payments.Version = stripecoinpayments.NewVersionService(
|
|
|
|
peer.Log.Named("payments.stripe:version"),
|
|
|
|
peer.Payments.Service,
|
|
|
|
pc.StripeCoinPayments.ConversionRatesCycleInterval)
|
|
|
|
|
|
|
|
peer.Services.Add(lifecycle.Item{
|
|
|
|
Name: "payments.stripe:version",
|
|
|
|
Run: peer.Payments.Version.Run,
|
|
|
|
Close: peer.Payments.Version.Close,
|
|
|
|
})
|
2019-10-23 13:04:54 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
{ // setup console
|
|
|
|
consoleConfig := config.Console
|
|
|
|
peer.Console.Listener, err = net.Listen("tcp", consoleConfig.Address)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
if consoleConfig.AuthTokenSecret == "" {
|
|
|
|
return nil, errs.New("Auth token secret required")
|
|
|
|
}
|
2019-10-17 15:42:18 +01:00
|
|
|
|
2019-11-25 21:36:36 +00:00
|
|
|
peer.Referrals.Service = referrals.NewService(
|
|
|
|
peer.Log.Named("referrals:service"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
config.Referrals,
|
|
|
|
peer.Dialer,
|
|
|
|
peer.DB.Console().Users(),
|
|
|
|
consoleConfig.PasswordCost,
|
|
|
|
)
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Console.Service, err = console.NewService(
|
|
|
|
peer.Log.Named("console:service"),
|
|
|
|
&consoleauth.Hmac{Secret: []byte(consoleConfig.AuthTokenSecret)},
|
|
|
|
peer.DB.Console(),
|
2019-11-15 14:27:44 +00:00
|
|
|
peer.DB.ProjectAccounting(),
|
2019-12-12 12:58:15 +00:00
|
|
|
peer.Accounting.ProjectUsage,
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.DB.Rewards(),
|
2019-11-05 12:58:09 +00:00
|
|
|
peer.Marketing.PartnersService,
|
2019-10-23 13:04:54 +01:00
|
|
|
peer.Payments.Accounts,
|
2020-03-11 15:36:55 +00:00
|
|
|
consoleConfig.Config,
|
2020-03-16 19:34:15 +00:00
|
|
|
config.Payments.MinCoinPayment,
|
2019-10-03 00:02:47 +01:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-11-18 11:38:43 +00:00
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Console.Endpoint = consoleweb.NewServer(
|
|
|
|
peer.Log.Named("console:endpoint"),
|
|
|
|
consoleConfig,
|
|
|
|
peer.Console.Service,
|
|
|
|
peer.Mail.Service,
|
2019-11-25 21:36:36 +00:00
|
|
|
peer.Referrals.Service,
|
2020-07-28 15:23:17 +01:00
|
|
|
peer.Marketing.PartnersService,
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Console.Listener,
|
2019-11-18 11:38:43 +00:00
|
|
|
config.Payments.StripeCoinPayments.StripePublicKey,
|
2019-10-03 00:02:47 +01:00
|
|
|
)
|
2020-01-28 23:13:59 +00:00
|
|
|
|
|
|
|
peer.Servers.Add(lifecycle.Item{
|
|
|
|
Name: "console:endpoint",
|
|
|
|
Run: peer.Console.Endpoint.Run,
|
|
|
|
Close: peer.Console.Endpoint.Close,
|
|
|
|
})
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup node stats endpoint
|
|
|
|
peer.NodeStats.Endpoint = nodestats.NewEndpoint(
|
|
|
|
peer.Log.Named("nodestats:endpoint"),
|
|
|
|
peer.Overlay.DB,
|
|
|
|
peer.DB.StoragenodeAccounting(),
|
2020-04-08 11:19:06 +01:00
|
|
|
config.Payments,
|
2019-10-03 00:02:47 +01:00
|
|
|
)
|
2020-03-24 17:49:20 +00:00
|
|
|
if err := pb.DRPCRegisterNodeStats(peer.Server.DRPC(), peer.NodeStats.Endpoint); err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
2020-03-15 22:16:56 +00:00
|
|
|
{ // setup heldamount endpoint
|
|
|
|
peer.HeldAmount.DB = peer.DB.HeldAmount()
|
|
|
|
peer.HeldAmount.Service = heldamount.NewService(
|
|
|
|
peer.Log.Named("heldamount:service"),
|
|
|
|
peer.HeldAmount.DB)
|
|
|
|
peer.HeldAmount.Endpoint = heldamount.NewEndpoint(
|
|
|
|
peer.Log.Named("heldamount:endpoint"),
|
|
|
|
peer.DB.StoragenodeAccounting(),
|
|
|
|
peer.Overlay.DB,
|
|
|
|
peer.HeldAmount.Service)
|
2020-03-24 17:49:20 +00:00
|
|
|
if err := pb.DRPCRegisterHeldAmount(peer.Server.DRPC(), peer.HeldAmount.Endpoint); err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-03-15 22:16:56 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 21:01:53 +01:00
|
|
|
{ // setup graceful exit
|
2019-11-01 14:21:24 +00:00
|
|
|
if config.GracefulExit.Enabled {
|
|
|
|
peer.GracefulExit.Endpoint = gracefulexit.NewEndpoint(
|
|
|
|
peer.Log.Named("gracefulexit:endpoint"),
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
peer.DB.GracefulExit(),
|
|
|
|
peer.Overlay.DB,
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
peer.Orders.Service,
|
|
|
|
peer.DB.PeerIdentities(),
|
|
|
|
config.GracefulExit)
|
|
|
|
|
2020-05-11 06:20:34 +01:00
|
|
|
if err := pb.DRPCRegisterSatelliteGracefulExit(peer.Server.DRPC(), peer.GracefulExit.Endpoint); err != nil {
|
2020-03-24 17:49:20 +00:00
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
2020-01-06 12:34:54 +00:00
|
|
|
} else {
|
|
|
|
peer.Log.Named("gracefulexit").Info("disabled")
|
2019-11-01 14:21:24 +00:00
|
|
|
}
|
2019-10-14 21:01:53 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
return peer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run runs satellite until it's either closed or it errors.
|
|
|
|
func (peer *API) 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)
|
2019-10-03 00:02:47 +01:00
|
|
|
|
|
|
|
return group.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes all the resources.
|
|
|
|
func (peer *API) Close() error {
|
2020-01-28 23:13:59 +00:00
|
|
|
return errs.Combine(
|
|
|
|
peer.Servers.Close(),
|
|
|
|
peer.Services.Close(),
|
|
|
|
)
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the peer ID.
|
|
|
|
func (peer *API) ID() storj.NodeID { return peer.Identity.ID }
|
|
|
|
|
|
|
|
// Addr returns the public address.
|
|
|
|
func (peer *API) Addr() string { return peer.Server.Addr().String() }
|
|
|
|
|
|
|
|
// URL returns the storj.NodeURL.
|
|
|
|
func (peer *API) URL() storj.NodeURL {
|
|
|
|
return storj.NodeURL{ID: peer.ID(), Address: peer.Addr()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrivateAddr returns the private address.
|
|
|
|
func (peer *API) PrivateAddr() string { return peer.Server.PrivateAddr().String() }
|