2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-06-21 14:13:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/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-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)
|
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
type ClientConstructor interface {
|
2021-09-28 04:46:10 +00:00
|
|
|
Get(client.NodeInfo) (client.Client, error)
|
2021-03-23 18:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
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
|
|
|
|
|
2021-09-24 10:36:54 +00:00
|
|
|
remotePool, localPool util.WorkerPool
|
2020-09-21 14:31:31 +00:00
|
|
|
|
2021-09-06 12:17:14 +00:00
|
|
|
netmapKeys netmap.AnnouncedKeys
|
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
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
clientConstructor ClientConstructor
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
log *logger.Logger
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
2021-10-08 13:29:52 +00:00
|
|
|
remotePool: new(util.PseudoWorkerPool),
|
|
|
|
localPool: new(util.PseudoWorkerPool),
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 10:36:54 +00:00
|
|
|
func WithWorkerPools(remote, local util.WorkerPool) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-09-24 10:36:54 +00:00
|
|
|
c.remotePool, c.localPool = remote, local
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 12:17:14 +00:00
|
|
|
func WithNetmapKeys(v netmap.AnnouncedKeys) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-09-06 12:17:14 +00:00
|
|
|
c.netmapKeys = v
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
2021-02-15 08:28:42 +00:00
|
|
|
c.fmtValidatorOpts = append(c.fmtValidatorOpts, object.WithNetState(v))
|
2020-10-21 15:11:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 13:03:31 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
func WithClientConstructor(v ClientConstructor) Option {
|
2020-11-18 13:03:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-03-23 18:40:36 +00:00
|
|
|
c.clientConstructor = v
|
2020-11-18 13:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
}
|
|
|
|
}
|