2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2021-10-26 13:02:46 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
|
2021-06-21 14:13:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/client"
|
2021-01-12 14:55:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-11-19 08:24:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-12-10 12:26:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
2020-11-23 11:25:57 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2021-11-10 07:08:33 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-01-26 12:11:13 +00:00
|
|
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
2020-11-23 11:25:57 +00:00
|
|
|
"go.uber.org/zap"
|
2020-09-22 06:51:47 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// Service is an utility serving requests
|
|
|
|
// of Object.Search service.
|
2020-09-22 06:51:47 +00:00
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// Option is a Service's constructor option.
|
2020-09-22 06:51:47 +00:00
|
|
|
type Option func(*cfg)
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
type searchClient interface {
|
2022-03-15 12:11:35 +00:00
|
|
|
searchObjects(*execCtx, client.NodeInfo) ([]oidSDK.ID, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
type ClientConstructor interface {
|
2022-01-13 15:01:50 +00:00
|
|
|
Get(client.NodeInfo) (client.MultiAddressClient, error)
|
2021-03-23 18:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
type cfg struct {
|
|
|
|
log *logger.Logger
|
2020-11-18 13:04:09 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
localStorage interface {
|
2022-03-15 12:11:35 +00:00
|
|
|
search(*execCtx) ([]oidSDK.ID, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2020-11-23 11:25:57 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
clientConstructor interface {
|
2021-09-28 04:46:10 +00:00
|
|
|
get(client.NodeInfo) (searchClient, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2020-11-23 12:59:06 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
traverserGenerator interface {
|
2021-05-31 11:03:17 +00:00
|
|
|
generateTraverser(*cid.ID, uint64) (*placement.Traverser, error)
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentEpochReceiver interface {
|
|
|
|
currentEpoch() (uint64, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2021-10-26 13:02:46 +00:00
|
|
|
|
|
|
|
keyStore interface {
|
|
|
|
GetKey(token *session.Token) (*ecdsa.PrivateKey, error)
|
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
2021-03-23 18:40:36 +00:00
|
|
|
log: zap.L(),
|
|
|
|
clientConstructor: new(clientConstructorWrapper),
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// New creates, initializes and returns utility serving
|
|
|
|
// Object.Get service requests.
|
|
|
|
func New(opts ...Option) *Service {
|
2020-09-22 06:51:47 +00:00
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// WithLogger returns option to specify Get service's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
2020-09-22 06:51:47 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-10 12:26:40 +00:00
|
|
|
c.log = l.With(zap.String("component", "Object.Get service"))
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// WithLocalStorageEngine returns option to set local storage
|
|
|
|
// instance.
|
|
|
|
func WithLocalStorageEngine(e *engine.StorageEngine) Option {
|
2020-09-22 06:51:47 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-10 12:26:40 +00:00
|
|
|
c.localStorage = (*storageEngineWrapper)(e)
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 13:04:09 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
// WithClientConstructor returns option to set constructor of remote node clients.
|
|
|
|
func WithClientConstructor(v ClientConstructor) Option {
|
2020-11-18 13:04:09 +00:00
|
|
|
return func(c *cfg) {
|
2021-03-23 18:40:36 +00:00
|
|
|
c.clientConstructor.(*clientConstructorWrapper).constructor = v
|
2020-11-18 13:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:25:57 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// WithTraverserGenerator returns option to set generator of
|
|
|
|
// placement traverser to get the objects from containers.
|
|
|
|
func WithTraverserGenerator(t *util.TraverserGenerator) Option {
|
2020-11-23 12:59:06 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-10 12:26:40 +00:00
|
|
|
c.traverserGenerator = (*traverseGeneratorWrapper)(t)
|
2020-11-23 12:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
// WithNetMapSource returns option to set network
|
|
|
|
// map storage to receive current network state.
|
|
|
|
func WithNetMapSource(nmSrc netmap.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.currentEpochReceiver = &nmSrcWrapper{
|
|
|
|
nmSrc: nmSrc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-26 13:02:46 +00:00
|
|
|
|
|
|
|
// WithKeyStorage returns option to set private
|
|
|
|
// key storage for session tokens and node key.
|
|
|
|
func WithKeyStorage(store *util.KeyStorage) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.keyStore = store
|
|
|
|
}
|
|
|
|
}
|