2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
|
|
|
"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-09-21 14:31:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/localstore"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MaxSizeSource interface {
|
|
|
|
MaxObjectSize() uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
|
|
|
|
maxSizeSrc MaxSizeSource
|
|
|
|
|
|
|
|
tokenStore *storage.TokenStore
|
|
|
|
|
|
|
|
localStore *localstore.Storage
|
|
|
|
|
|
|
|
cnrSrc container.Source
|
|
|
|
|
|
|
|
netMapSrc netmap.Source
|
|
|
|
|
|
|
|
workerPool util.WorkerPool
|
|
|
|
|
|
|
|
localAddrSrc network.LocalAddressSource
|
2020-09-29 12:38:35 +00:00
|
|
|
|
|
|
|
fmtValidator *object.FormatValidator
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
2020-09-29 12:38:35 +00:00
|
|
|
workerPool: new(util.SyncWorkerPool),
|
|
|
|
fmtValidator: object.NewFormatValidator(),
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(opts ...Option) *Service {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Service) Put(ctx context.Context) (*Streamer, error) {
|
|
|
|
return &Streamer{
|
|
|
|
cfg: p.cfg,
|
|
|
|
ctx: ctx,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithKey(v *ecdsa.PrivateKey) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.key = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMaxSizeSource(v MaxSizeSource) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.maxSizeSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithTokenStorage(v *storage.TokenStore) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.tokenStore = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithLocalStorage(v *localstore.Storage) Option {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|