2018-11-01 16:51:19 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-05 15:23:54 +00:00
|
|
|
package bwagreement
|
2018-11-01 16:51:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-11-15 19:06:09 +00:00
|
|
|
"net/url"
|
2018-11-01 16:51:19 +00:00
|
|
|
|
2018-11-15 19:06:09 +00:00
|
|
|
"github.com/zeebo/errs"
|
2018-11-01 16:51:19 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
2018-11-15 18:36:57 +00:00
|
|
|
|
2018-11-15 19:06:09 +00:00
|
|
|
"storj.io/storj/pkg/bwagreement/database-manager"
|
2018-11-01 16:51:19 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
"storj.io/storj/pkg/provider"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
mon = monkit.Package()
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config is a configuration struct that is everything you need to start an
|
|
|
|
// agreement receiver responsibility
|
|
|
|
type Config struct {
|
2018-11-15 19:06:09 +00:00
|
|
|
DatabaseURL string `help:"the database connection string to use" default:"sqlite3://$CONFDIR/bw.db"`
|
2018-11-01 16:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run implements the provider.Responsibility interface
|
|
|
|
func (c Config) Run(ctx context.Context, server *provider.Provider) (err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2018-11-12 21:59:30 +00:00
|
|
|
k := server.Identity().Leaf.PublicKey
|
|
|
|
|
2018-11-15 19:06:09 +00:00
|
|
|
zap.S().Debug("Starting Bandwidth Agreement Receiver...")
|
|
|
|
|
|
|
|
u, err := url.Parse(c.DatabaseURL)
|
|
|
|
if err != nil {
|
|
|
|
return errs.New("Invalid Database URL: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dbm, err := dbmanager.NewDBManager(u.Scheme, u.Path)
|
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error starting initializing database for Bandwidth Agreement server on satellite: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ns, err := NewServer(dbm, zap.L(), k)
|
2018-11-01 16:51:19 +00:00
|
|
|
if err != nil {
|
2018-11-15 19:06:09 +00:00
|
|
|
return errs.New("Error starting Bandwidth Agreement server on satellite: %+v", err)
|
2018-11-01 16:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pb.RegisterBandwidthServer(server.GRPC(), ns)
|
|
|
|
|
|
|
|
return server.Run(ctx)
|
|
|
|
}
|