2020-09-22 15:04:08 +00:00
|
|
|
package headsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-11-23 12:59:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2020-09-23 10:53:59 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-09-22 15:04:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-11-19 08:36:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-09-22 15:04:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2020-11-18 13:03:00 +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-22 15:04:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
2020-11-23 11:20:59 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2020-09-23 10:53:59 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-11-23 11:20:59 +00:00
|
|
|
"go.uber.org/zap"
|
2020-09-22 15:04:08 +00:00
|
|
|
)
|
|
|
|
|
2020-09-23 10:53:59 +00:00
|
|
|
type RelationSearcher interface {
|
2020-10-14 18:14:54 +00:00
|
|
|
SearchRelation(context.Context, *objectSDK.Address, *objutil.CommonPrm) (*objectSDK.ID, error)
|
2020-09-23 10:53:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 15:04:08 +00:00
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
cnrSrc container.Source
|
|
|
|
|
|
|
|
netMapSrc netmap.Source
|
|
|
|
|
|
|
|
workerPool util.WorkerPool
|
|
|
|
|
|
|
|
localAddrSrc network.LocalAddressSource
|
2020-09-23 10:53:59 +00:00
|
|
|
|
2020-10-21 09:18:36 +00:00
|
|
|
localHeader localHeader
|
|
|
|
|
|
|
|
remoteHeader RemoteHeader
|
2020-11-23 11:20:59 +00:00
|
|
|
|
|
|
|
log *logger.Logger
|
2020-09-22 15:04:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 09:15:54 +00:00
|
|
|
var ErrNotFound = errors.New("object header not found")
|
|
|
|
|
2020-09-22 15:04:08 +00:00
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
|
|
|
workerPool: new(util.SyncWorkerPool),
|
2020-11-23 11:20:59 +00:00
|
|
|
log: zap.L(),
|
2020-09-22 15:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(opts ...Option) *Service {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) Head(ctx context.Context, prm *Prm) (*Response, error) {
|
2020-12-05 12:29:05 +00:00
|
|
|
return (&distributedHeader{
|
2020-09-22 15:04:08 +00:00
|
|
|
cfg: s.cfg,
|
|
|
|
}).head(ctx, prm)
|
|
|
|
}
|
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
func WithKeyStorage(v *objutil.KeyStorage) Option {
|
2020-09-22 15:04:08 +00:00
|
|
|
return func(c *cfg) {
|
2020-10-21 09:18:36 +00:00
|
|
|
c.remoteHeader.keyStorage = v
|
2020-09-22 15:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 08:36:58 +00:00
|
|
|
func WithLocalStorage(v *engine.StorageEngine) Option {
|
2020-09-22 15:04:08 +00:00
|
|
|
return func(c *cfg) {
|
2020-10-21 09:18:36 +00:00
|
|
|
c.localHeader.storage = v
|
2020-09-22 15:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-23 10:53:59 +00:00
|
|
|
|
2020-11-18 13:03:00 +00:00
|
|
|
func WithClientCache(v *cache.ClientCache) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.remoteHeader.clientCache = v
|
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:20:59 +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.remoteHeader.clientOpts = opts
|
|
|
|
}
|
|
|
|
}
|