2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-11-23 12:59:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2020-09-21 14:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-09-29 12:38:35 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-11-19 08:29:38 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-09-21 14:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2020-11-18 13:03:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network/cache"
|
2020-09-29 16:44:59 +00:00
|
|
|
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
2020-09-21 14:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
2020-11-23 11:22:32 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
|
|
"go.uber.org/zap"
|
2020-09-21 14:31:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MaxSizeSource interface {
|
2020-10-22 14:20:59 +00:00
|
|
|
// MaxObjectSize returns maximum payload size
|
|
|
|
// of physically stored object in system.
|
|
|
|
//
|
|
|
|
// Must return 0 if value can not be obtained.
|
2020-09-21 14:31:31 +00:00
|
|
|
MaxObjectSize() uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
2020-09-29 16:44:59 +00:00
|
|
|
keyStorage *objutil.KeyStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
maxSizeSrc MaxSizeSource
|
|
|
|
|
2020-11-19 08:29:38 +00:00
|
|
|
localStore *engine.StorageEngine
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
cnrSrc container.Source
|
|
|
|
|
|
|
|
netMapSrc netmap.Source
|
|
|
|
|
|
|
|
workerPool util.WorkerPool
|
|
|
|
|
|
|
|
localAddrSrc network.LocalAddressSource
|
2020-09-29 12:38:35 +00:00
|
|
|
|
|
|
|
fmtValidator *object.FormatValidator
|
2020-10-03 10:14:09 +00:00
|
|
|
|
|
|
|
fmtValidatorOpts []object.FormatValidatorOption
|
2020-10-21 15:11:50 +00:00
|
|
|
|
|
|
|
networkState netmap.State
|
2020-11-18 13:03:31 +00:00
|
|
|
|
|
|
|
clientCache *cache.ClientCache
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
log *logger.Logger
|
2020-11-23 12:59:06 +00:00
|
|
|
|
|
|
|
clientOpts []client.Option
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
2020-10-03 10:14:09 +00:00
|
|
|
workerPool: new(util.SyncWorkerPool),
|
2020-11-23 11:22:32 +00:00
|
|
|
log: zap.L(),
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(opts ...Option) *Service {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
2020-10-03 10:14:09 +00:00
|
|
|
c.fmtValidator = object.NewFormatValidator(c.fmtValidatorOpts...)
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Service) Put(ctx context.Context) (*Streamer, error) {
|
|
|
|
return &Streamer{
|
|
|
|
cfg: p.cfg,
|
|
|
|
ctx: ctx,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
func WithKeyStorage(v *objutil.KeyStorage) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2020-09-29 16:44:59 +00:00
|
|
|
c.keyStorage = v
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMaxSizeSource(v MaxSizeSource) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.maxSizeSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 08:29:38 +00:00
|
|
|
func WithLocalStorage(v *engine.StorageEngine) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.localStore = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithContainerSource(v container.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.cnrSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithNetworkMapSource(v netmap.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netMapSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithWorkerPool(v util.WorkerPool) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.workerPool = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithLocalAddressSource(v network.LocalAddressSource) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.localAddrSrc = v
|
|
|
|
}
|
|
|
|
}
|
2020-10-03 10:14:09 +00:00
|
|
|
|
|
|
|
func WithFormatValidatorOpts(v ...object.FormatValidatorOption) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.fmtValidatorOpts = v
|
|
|
|
}
|
|
|
|
}
|
2020-10-21 15:11:50 +00:00
|
|
|
|
|
|
|
func WithNetworkState(v netmap.State) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.networkState = v
|
|
|
|
}
|
|
|
|
}
|
2020-11-18 13:03:31 +00:00
|
|
|
|
|
|
|
func WithClientCache(v *cache.ClientCache) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.clientCache = v
|
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
}
|
|
|
|
}
|
2020-11-23 12:59:06 +00:00
|
|
|
|
|
|
|
func WithClientOptions(opts ...client.Option) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.clientOpts = opts
|
|
|
|
}
|
|
|
|
}
|