2019-10-03 00:02:47 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
"net/mail"
|
|
|
|
"net/smtp"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/errs2"
|
|
|
|
"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"
|
2019-10-03 00:02:47 +01:00
|
|
|
"storj.io/storj/pkg/auth/grpcauth"
|
|
|
|
"storj.io/storj/pkg/server"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/post"
|
|
|
|
"storj.io/storj/private/post/oauth2"
|
|
|
|
"storj.io/storj/private/version"
|
|
|
|
"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"
|
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"
|
|
|
|
"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-11-04 10:54:25 +00:00
|
|
|
"storj.io/storj/satellite/payments/mockpayments"
|
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
|
|
|
"storj.io/storj/satellite/vouchers"
|
|
|
|
)
|
|
|
|
|
2020-01-09 17:09:22 +00:00
|
|
|
// TODO: orange/v3-3406 this value may change once it's used in production
|
|
|
|
const metainfoDeletePiecesConcurrencyLimit = 100
|
|
|
|
|
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
|
|
|
|
|
|
|
|
Dialer rpc.Dialer
|
|
|
|
Server *server.Server
|
2019-10-20 08:56:23 +01:00
|
|
|
Version *checker.Service
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
Vouchers struct {
|
|
|
|
Endpoint *vouchers.Endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-09 17:09:22 +00:00
|
|
|
Database metainfo.PointerDB
|
|
|
|
Service *metainfo.Service
|
|
|
|
DeletePiecesService *metainfo.DeletePiecesService
|
|
|
|
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 {
|
2019-11-05 13:16:02 +00:00
|
|
|
Accounts payments.Accounts
|
|
|
|
Inspector *stripecoinpayments.Endpoint
|
2019-11-15 14:59:39 +00:00
|
|
|
Version *stripecoinpayments.VersionService
|
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
|
|
|
|
|
|
|
GracefulExit struct {
|
|
|
|
Endpoint *gracefulexit.Endpoint
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAPI creates a new satellite API process
|
2019-10-16 17:50:29 +01:00
|
|
|
func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metainfo.PointerDB, revocationDB extensions.RevocationDB, liveAccounting accounting.Cache, config *Config, versionInfo version.Info) (*API, error) {
|
2019-10-03 00:02:47 +01:00
|
|
|
peer := &API{
|
|
|
|
Log: log,
|
|
|
|
Identity: full,
|
|
|
|
DB: db,
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
{
|
2019-10-21 11:50:59 +01:00
|
|
|
if !versionInfo.IsZero() {
|
2019-10-03 00:02:47 +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, "Satellite")
|
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)
|
|
|
|
|
|
|
|
unaryInterceptor := grpcauth.NewAPIKeyInterceptor()
|
|
|
|
if sc.DebugLogTraffic {
|
|
|
|
unaryInterceptor = server.CombineInterceptors(unaryInterceptor, server.UnaryMessageLoggingInterceptor(log))
|
|
|
|
}
|
|
|
|
peer.Server, err = server.New(log.Named("server"), tlsOptions, sc.Address, sc.PrivateAddress, unaryInterceptor)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup overlay
|
|
|
|
peer.Overlay.DB = overlay.NewCombinedCache(peer.DB.OverlayCache())
|
|
|
|
peer.Overlay.Service = overlay.NewService(peer.Log.Named("overlay"), peer.Overlay.DB, config.Overlay)
|
|
|
|
peer.Overlay.Inspector = overlay.NewInspector(peer.Overlay.Service)
|
|
|
|
pb.RegisterOverlayInspectorServer(peer.Server.PrivateGRPC(), peer.Overlay.Inspector)
|
|
|
|
pb.DRPCRegisterOverlayInspector(peer.Server.PrivateDRPC(), peer.Overlay.Inspector)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // 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,
|
|
|
|
}
|
|
|
|
peer.Contact.Service = contact.NewService(peer.Log.Named("contact:service"), self, peer.Overlay.Service, peer.DB.PeerIdentities(), peer.Dialer)
|
|
|
|
peer.Contact.Endpoint = contact.NewEndpoint(peer.Log.Named("contact:endpoint"), peer.Contact.Service)
|
|
|
|
pb.RegisterNodeServer(peer.Server.GRPC(), peer.Contact.Endpoint)
|
|
|
|
pb.DRPCRegisterNode(peer.Server.DRPC(), peer.Contact.Endpoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup vouchers
|
|
|
|
pb.RegisterVouchersServer(peer.Server.GRPC(), peer.Vouchers.Endpoint)
|
|
|
|
pb.DRPCRegisterVouchers(peer.Server.DRPC(), peer.Vouchers.Endpoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // 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,
|
2019-10-03 00:02:47 +01:00
|
|
|
config.Rollup.MaxAlphaUsage,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup orders
|
2020-01-10 18:53:42 +00:00
|
|
|
ordersWriteCache := orders.NewRollupsWriteCache(log, peer.DB.Orders(), config.Orders.FlushBatchSize)
|
|
|
|
peer.Orders.DB = ordersWriteCache
|
|
|
|
peer.Orders.Chore = orders.NewChore(log.Named("orders chore"), ordersWriteCache, config.Orders)
|
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,
|
2019-10-03 00:02:47 +01:00
|
|
|
config.Orders.SettlementBatchSize,
|
|
|
|
)
|
|
|
|
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-10-03 00:02:47 +01: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-10-03 00:02:47 +01:00
|
|
|
)
|
|
|
|
pb.RegisterOrdersServer(peer.Server.GRPC(), peer.Orders.Endpoint)
|
|
|
|
pb.DRPCRegisterOrders(peer.Server.DRPC(), peer.Orders.Endpoint.DRPC())
|
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
peer.Metainfo.DeletePiecesService, err = metainfo.NewDeletePiecesService(
|
|
|
|
peer.Log.Named("metainfo:DeletePiecesService"),
|
|
|
|
peer.Dialer,
|
|
|
|
metainfoDeletePiecesConcurrencyLimit,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Combine(err, peer.Close())
|
|
|
|
}
|
|
|
|
|
2019-10-03 00:02:47 +01:00
|
|
|
peer.Metainfo.Endpoint2 = metainfo.NewEndpoint(
|
|
|
|
peer.Log.Named("metainfo:endpoint"),
|
|
|
|
peer.Metainfo.Service,
|
2020-01-09 17:09:22 +00:00
|
|
|
peer.Metainfo.DeletePiecesService,
|
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
|
|
|
config.Metainfo.RS,
|
|
|
|
signing.SignerFromFullIdentity(peer.Identity),
|
|
|
|
config.Metainfo.MaxCommitInterval,
|
2020-01-17 15:01:36 +00:00
|
|
|
config.Metainfo.RateLimiter,
|
2019-10-03 00:02:47 +01:00
|
|
|
)
|
|
|
|
pb.RegisterMetainfoServer(peer.Server.GRPC(), peer.Metainfo.Endpoint2)
|
|
|
|
pb.DRPCRegisterMetainfo(peer.Server.DRPC(), peer.Metainfo.Endpoint2)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup datarepair
|
|
|
|
peer.Repair.Inspector = irreparable.NewInspector(peer.DB.Irreparable())
|
|
|
|
pb.RegisterIrreparableInspectorServer(peer.Server.PrivateGRPC(), peer.Repair.Inspector)
|
|
|
|
pb.DRPCRegisterIrreparableInspector(peer.Server.PrivateDRPC(), peer.Repair.Inspector)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup inspector
|
|
|
|
peer.Inspector.Endpoint = inspector.NewEndpoint(
|
|
|
|
peer.Log.Named("inspector"),
|
|
|
|
peer.Overlay.Service,
|
|
|
|
peer.Metainfo.Service,
|
|
|
|
)
|
|
|
|
pb.RegisterHealthInspectorServer(peer.Server.PrivateGRPC(), peer.Inspector.Endpoint)
|
|
|
|
pb.DRPCRegisterHealthInspector(peer.Server.PrivateDRPC(), peer.Inspector.Endpoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // 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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-11-05 20:26:19 +00:00
|
|
|
switch pc.Provider {
|
2019-11-04 10:54:25 +00:00
|
|
|
default:
|
|
|
|
peer.Payments.Accounts = mockpayments.Accounts()
|
|
|
|
case "stripecoinpayments":
|
|
|
|
service := stripecoinpayments.NewService(
|
2020-01-06 12:34:54 +00:00
|
|
|
peer.Log.Named("payments.stripe:service"),
|
2019-11-05 20:26:19 +00:00
|
|
|
pc.StripeCoinPayments,
|
2019-11-05 13:16:02 +00:00
|
|
|
peer.DB.StripeCoinPayments(),
|
2019-11-15 14:27:44 +00:00
|
|
|
peer.DB.Console().Projects(),
|
|
|
|
peer.DB.ProjectAccounting(),
|
|
|
|
pc.PerObjectPrice,
|
|
|
|
pc.EgressPrice,
|
|
|
|
pc.TbhPrice)
|
2019-11-04 10:54:25 +00:00
|
|
|
|
|
|
|
peer.Payments.Accounts = service.Accounts()
|
2019-11-05 13:16:02 +00:00
|
|
|
peer.Payments.Inspector = stripecoinpayments.NewEndpoint(service)
|
|
|
|
|
2019-11-15 14:59:39 +00:00
|
|
|
peer.Payments.Version = stripecoinpayments.NewVersionService(
|
2020-01-06 12:34:54 +00:00
|
|
|
peer.Log.Named("payments.stripe:service"),
|
2019-11-15 14:59:39 +00:00
|
|
|
service,
|
|
|
|
pc.StripeCoinPayments.ConversionRatesCycleInterval)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
pb.RegisterPaymentsServer(peer.Server.PrivateGRPC(), peer.Payments.Inspector)
|
|
|
|
pb.DRPCRegisterPayments(peer.Server.PrivateDRPC(), peer.Payments.Inspector)
|
2019-11-04 10:54:25 +00:00
|
|
|
}
|
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,
|
2019-10-03 00:02:47 +01:00
|
|
|
consoleConfig.PasswordCost,
|
|
|
|
)
|
|
|
|
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,
|
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
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // setup node stats endpoint
|
|
|
|
peer.NodeStats.Endpoint = nodestats.NewEndpoint(
|
|
|
|
peer.Log.Named("nodestats:endpoint"),
|
|
|
|
peer.Overlay.DB,
|
|
|
|
peer.DB.StoragenodeAccounting(),
|
|
|
|
)
|
|
|
|
pb.RegisterNodeStatsServer(peer.Server.GRPC(), peer.NodeStats.Endpoint)
|
|
|
|
pb.DRPCRegisterNodeStats(peer.Server.DRPC(), peer.NodeStats.Endpoint)
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
pb.RegisterSatelliteGracefulExitServer(peer.Server.GRPC(), peer.GracefulExit.Endpoint)
|
|
|
|
pb.DRPCRegisterSatelliteGracefulExit(peer.Server.DRPC(), peer.GracefulExit.Endpoint.DRPC())
|
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)
|
|
|
|
|
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Version.Run(ctx))
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
|
|
|
// 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)
|
|
|
|
peer.Log.Sugar().Infof("Public server started on %s", peer.Addr())
|
|
|
|
peer.Log.Sugar().Infof("Private server started on %s", peer.PrivateAddr())
|
|
|
|
return errs2.IgnoreCanceled(peer.Server.Run(ctx))
|
|
|
|
})
|
2019-11-15 14:59:39 +00:00
|
|
|
if peer.Payments.Version != nil {
|
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Payments.Version.Run(ctx))
|
|
|
|
})
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Console.Endpoint.Run(ctx))
|
|
|
|
})
|
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Marketing.Endpoint.Run(ctx))
|
|
|
|
})
|
2020-01-10 18:53:42 +00:00
|
|
|
group.Go(func() error {
|
|
|
|
return errs2.IgnoreCanceled(peer.Orders.Chore.Run(ctx))
|
|
|
|
})
|
2019-10-03 00:02:47 +01:00
|
|
|
|
|
|
|
return group.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes all the resources.
|
|
|
|
func (peer *API) Close() error {
|
|
|
|
var errlist errs.Group
|
|
|
|
|
|
|
|
// close servers, to avoid new connections to closing subsystems
|
|
|
|
if peer.Server != nil {
|
|
|
|
errlist.Add(peer.Server.Close())
|
|
|
|
}
|
|
|
|
if peer.Marketing.Endpoint != nil {
|
|
|
|
errlist.Add(peer.Marketing.Endpoint.Close())
|
|
|
|
} else if peer.Marketing.Listener != nil {
|
|
|
|
errlist.Add(peer.Marketing.Listener.Close())
|
|
|
|
}
|
|
|
|
if peer.Console.Endpoint != nil {
|
|
|
|
errlist.Add(peer.Console.Endpoint.Close())
|
|
|
|
} else if peer.Console.Listener != nil {
|
|
|
|
errlist.Add(peer.Console.Listener.Close())
|
|
|
|
}
|
|
|
|
if peer.Mail.Service != nil {
|
|
|
|
errlist.Add(peer.Mail.Service.Close())
|
|
|
|
}
|
2019-11-15 14:59:39 +00:00
|
|
|
if peer.Payments.Version != nil {
|
|
|
|
errlist.Add(peer.Payments.Version.Close())
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
if peer.Metainfo.Endpoint2 != nil {
|
|
|
|
errlist.Add(peer.Metainfo.Endpoint2.Close())
|
|
|
|
}
|
|
|
|
if peer.Contact.Service != nil {
|
|
|
|
errlist.Add(peer.Contact.Service.Close())
|
|
|
|
}
|
|
|
|
if peer.Overlay.Service != nil {
|
|
|
|
errlist.Add(peer.Overlay.Service.Close())
|
|
|
|
}
|
2020-01-10 18:53:42 +00:00
|
|
|
if peer.Orders.Chore.Loop != nil {
|
|
|
|
errlist.Add(peer.Orders.Chore.Close())
|
|
|
|
}
|
2020-01-09 17:09:22 +00:00
|
|
|
if peer.Metainfo.DeletePiecesService != nil {
|
|
|
|
errlist.Add(peer.Metainfo.DeletePiecesService.Close())
|
|
|
|
}
|
2019-10-03 00:02:47 +01:00
|
|
|
return errlist.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID returns the peer ID.
|
|
|
|
func (peer *API) ID() storj.NodeID { return peer.Identity.ID }
|
|
|
|
|
|
|
|
// Local returns the peer local node info.
|
|
|
|
func (peer *API) Local() overlay.NodeDossier { return peer.Contact.Service.Local() }
|
|
|
|
|
|
|
|
// 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() }
|