2020-08-25 13:37:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-09-28 05:44:40 +00:00
|
|
|
"bytes"
|
2020-08-25 14:44:41 +00:00
|
|
|
"context"
|
2022-05-16 13:15:31 +00:00
|
|
|
"errors"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-08-25 14:44:41 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-08-25 13:37:10 +00:00
|
|
|
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
|
2021-06-02 12:36:39 +00:00
|
|
|
policerconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/policer"
|
|
|
|
replicatorconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/replicator"
|
2021-06-21 14:56:19 +00:00
|
|
|
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
2022-06-22 10:55:31 +00:00
|
|
|
containercore "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
2021-02-17 12:32:04 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-10-03 10:14:09 +00:00
|
|
|
objectCore "github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2021-03-23 10:32:18 +00:00
|
|
|
morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2022-01-31 13:34:01 +00:00
|
|
|
cntClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
2022-01-31 11:58:55 +00:00
|
|
|
nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
2020-08-25 13:37:10 +00:00
|
|
|
objectTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
|
|
|
|
objectService "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
2020-10-02 11:41:29 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl"
|
2022-02-11 12:25:05 +00:00
|
|
|
v2 "github.com/nspcc-dev/neofs-node/pkg/services/object/acl/v2"
|
2020-09-23 13:55:46 +00:00
|
|
|
deletesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/delete"
|
|
|
|
deletesvcV2 "github.com/nspcc-dev/neofs-node/pkg/services/object/delete/v2"
|
|
|
|
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
|
|
|
|
getsvcV2 "github.com/nspcc-dev/neofs-node/pkg/services/object/get/v2"
|
|
|
|
headsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/head"
|
|
|
|
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
|
|
|
|
putsvcV2 "github.com/nspcc-dev/neofs-node/pkg/services/object/put/v2"
|
|
|
|
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
|
|
|
searchsvcV2 "github.com/nspcc-dev/neofs-node/pkg/services/object/search/v2"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
2020-10-21 09:28:42 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/policer"
|
2020-10-21 11:51:20 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/replicator"
|
2021-03-23 18:59:31 +00:00
|
|
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
2022-02-25 09:20:49 +00:00
|
|
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
2021-11-10 07:08:33 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl"
|
2022-03-15 19:46:43 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2022-07-04 13:24:51 +00:00
|
|
|
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
|
2022-05-17 13:59:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
2020-10-22 14:21:28 +00:00
|
|
|
"go.uber.org/zap"
|
2020-08-25 13:37:10 +00:00
|
|
|
)
|
|
|
|
|
2020-09-23 13:42:50 +00:00
|
|
|
type objectSvc struct {
|
2020-09-23 13:55:46 +00:00
|
|
|
put *putsvcV2.Service
|
2020-09-23 13:42:50 +00:00
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
search *searchsvcV2.Service
|
2020-09-23 13:42:50 +00:00
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
get *getsvcV2.Service
|
|
|
|
|
|
|
|
delete *deletesvcV2.Service
|
2020-09-23 13:42:50 +00:00
|
|
|
}
|
2020-08-25 14:44:41 +00:00
|
|
|
|
2020-10-22 14:21:28 +00:00
|
|
|
func (c *cfg) MaxObjectSize() uint64 {
|
|
|
|
sz, err := c.cfgNetmap.wrapper.MaxObjectSize()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Error("could not get max object size value",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
2020-09-23 13:35:40 +00:00
|
|
|
|
2020-10-22 14:21:28 +00:00
|
|
|
return sz
|
2020-09-23 13:35:40 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 10:53:08 +00:00
|
|
|
func (s *objectSvc) Put(ctx context.Context) (objectService.PutObjectStream, error) {
|
2020-09-23 13:42:50 +00:00
|
|
|
return s.put.Put(ctx)
|
2020-08-25 15:45:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 13:42:50 +00:00
|
|
|
func (s *objectSvc) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
|
2020-12-09 10:32:33 +00:00
|
|
|
return s.get.Head(ctx, req)
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (s *objectSvc) Search(req *object.SearchRequest, stream objectService.SearchStream) error {
|
|
|
|
return s.search.Search(req, stream)
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *objectSvc) Get(req *object.GetRequest, stream objectService.GetObjectStream) error {
|
|
|
|
return s.get.Get(req, stream)
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
func (s *objectSvc) Delete(ctx context.Context, req *object.DeleteRequest) (*object.DeleteResponse, error) {
|
|
|
|
return s.delete.Delete(ctx, req)
|
2020-08-25 15:58:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
func (s *objectSvc) GetRange(req *object.GetRangeRequest, stream objectService.GetObjectRangeStream) error {
|
|
|
|
return s.get.GetRange(req, stream)
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
func (s *objectSvc) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
2020-12-08 16:18:24 +00:00
|
|
|
return s.get.GetRangeHash(ctx, req)
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:23:28 +00:00
|
|
|
type localObjectInhumer struct {
|
|
|
|
storage *engine.StorageEngine
|
|
|
|
|
|
|
|
log *logger.Logger
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (r *localObjectInhumer) DeleteObjects(ts oid.Address, addr ...oid.Address) error {
|
2022-05-23 13:12:32 +00:00
|
|
|
var prm engine.InhumePrm
|
2022-02-16 15:49:19 +00:00
|
|
|
prm.WithTarget(ts, addr...)
|
2020-12-01 11:23:28 +00:00
|
|
|
|
2022-02-16 15:49:19 +00:00
|
|
|
_, err := r.storage.Inhume(prm)
|
|
|
|
return err
|
2020-11-19 10:58:27 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 12:32:04 +00:00
|
|
|
type delNetInfo struct {
|
|
|
|
netmap.State
|
|
|
|
tsLifetime uint64
|
2021-11-08 12:10:49 +00:00
|
|
|
|
|
|
|
cfg *cfg
|
2021-02-17 12:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i *delNetInfo) TombstoneLifetime() (uint64, error) {
|
|
|
|
return i.tsLifetime, nil
|
|
|
|
}
|
|
|
|
|
2021-11-08 12:10:49 +00:00
|
|
|
// returns node owner ID calculated from configured private key.
|
|
|
|
//
|
|
|
|
// Implements method needed for Object.Delete service.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (i *delNetInfo) LocalNodeID() user.ID {
|
|
|
|
return i.cfg.ownerIDFromKey
|
2021-11-08 12:10:49 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 20:59:39 +00:00
|
|
|
type innerRingFetcherWithNotary struct {
|
2021-03-23 10:32:18 +00:00
|
|
|
sidechain *morphClient.Client
|
|
|
|
}
|
|
|
|
|
2021-07-20 20:59:39 +00:00
|
|
|
func (fn *innerRingFetcherWithNotary) InnerRingKeys() ([][]byte, error) {
|
|
|
|
keys, err := fn.sidechain.NeoFSAlphabetList()
|
2021-03-23 10:32:18 +00:00
|
|
|
if err != nil {
|
2021-07-20 20:59:39 +00:00
|
|
|
return nil, fmt.Errorf("can't get inner ring keys from alphabet role: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
result := make([][]byte, 0, len(keys))
|
|
|
|
for i := range keys {
|
|
|
|
result = append(result, keys[i].Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type innerRingFetcherWithoutNotary struct {
|
2022-01-31 11:58:55 +00:00
|
|
|
nm *nmClient.Client
|
2021-07-20 20:59:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *innerRingFetcherWithoutNotary) InnerRingKeys() ([][]byte, error) {
|
|
|
|
keys, err := f.nm.GetInnerRingList()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("can't get inner ring keys from netmap contract: %w", err)
|
2021-03-23 10:32:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result := make([][]byte, 0, len(keys))
|
|
|
|
for i := range keys {
|
|
|
|
result = append(result, keys[i].Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2021-06-21 14:13:08 +00:00
|
|
|
type coreClientConstructor reputationClientConstructor
|
|
|
|
|
2022-01-13 15:01:50 +00:00
|
|
|
func (x *coreClientConstructor) Get(info coreclient.NodeInfo) (coreclient.MultiAddressClient, error) {
|
2021-09-28 04:46:10 +00:00
|
|
|
c, err := (*reputationClientConstructor)(x).Get(info)
|
2021-06-22 16:04:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-06-21 14:13:08 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 15:01:50 +00:00
|
|
|
return c.(coreclient.MultiAddressClient), nil
|
2021-06-22 11:12:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
func initObjectService(c *cfg) {
|
|
|
|
ls := c.cfgObject.cfgLocalStorage.localStorage
|
2021-10-25 12:19:50 +00:00
|
|
|
keyStorage := util.NewKeyStorage(&c.key.PrivateKey, c.privateTokenStore, c.cfgNetmap.state)
|
2020-09-23 13:55:46 +00:00
|
|
|
|
2021-03-23 18:59:31 +00:00
|
|
|
clientConstructor := &reputationClientConstructor{
|
|
|
|
log: c.log,
|
2022-03-29 13:52:12 +00:00
|
|
|
nmSrc: c.netMapSource,
|
2021-03-23 18:59:31 +00:00
|
|
|
netState: c.cfgNetmap.state,
|
|
|
|
trustStorage: c.cfgReputation.localTrustStorage,
|
2021-07-13 11:12:23 +00:00
|
|
|
basicConstructor: c.clientCache,
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2021-06-21 14:13:08 +00:00
|
|
|
coreConstructor := (*coreClientConstructor)(clientConstructor)
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
var irFetcher v2.InnerRingFetcher
|
2021-07-20 20:59:39 +00:00
|
|
|
|
|
|
|
if c.cfgMorph.client.ProbeNotary() {
|
|
|
|
irFetcher = &innerRingFetcherWithNotary{
|
|
|
|
sidechain: c.cfgMorph.client,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
irFetcher = &innerRingFetcherWithoutNotary{
|
|
|
|
nm: c.cfgNetmap.wrapper,
|
|
|
|
}
|
2021-03-23 10:32:18 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 11:23:28 +00:00
|
|
|
objInhumer := &localObjectInhumer{
|
|
|
|
storage: ls,
|
|
|
|
log: c.log,
|
|
|
|
}
|
|
|
|
|
2022-09-19 10:57:59 +00:00
|
|
|
c.replicator = replicator.New(
|
2020-10-21 11:51:20 +00:00
|
|
|
replicator.WithLogger(c.log),
|
|
|
|
replicator.WithPutTimeout(
|
2021-06-02 12:36:39 +00:00
|
|
|
replicatorconfig.PutTimeout(c.appCfg),
|
2020-10-21 11:51:20 +00:00
|
|
|
),
|
|
|
|
replicator.WithLocalStorage(ls),
|
|
|
|
replicator.WithRemoteSender(
|
2021-06-22 12:31:13 +00:00
|
|
|
putsvc.NewRemoteSender(keyStorage, coreConstructor),
|
2020-10-21 11:51:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2020-10-21 09:28:42 +00:00
|
|
|
pol := policer.New(
|
|
|
|
policer.WithLogger(c.log),
|
|
|
|
policer.WithLocalStorage(ls),
|
2021-07-29 15:57:53 +00:00
|
|
|
policer.WithContainerSource(c.cfgObject.cnrSource),
|
2020-10-21 09:28:42 +00:00
|
|
|
policer.WithPlacementBuilder(
|
2022-03-29 13:52:12 +00:00
|
|
|
placement.NewNetworkMapSourceBuilder(c.netMapSource),
|
2020-10-21 09:28:42 +00:00
|
|
|
),
|
|
|
|
policer.WithRemoteHeader(
|
2021-06-22 16:04:49 +00:00
|
|
|
headsvc.NewRemoteHeader(keyStorage, clientConstructor),
|
2020-10-21 09:28:42 +00:00
|
|
|
),
|
2021-09-06 12:17:14 +00:00
|
|
|
policer.WithNetmapKeys(c),
|
2020-10-21 09:28:42 +00:00
|
|
|
policer.WithHeadTimeout(
|
2021-06-02 12:36:39 +00:00
|
|
|
policerconfig.HeadTimeout(c.appCfg),
|
2020-10-21 09:28:42 +00:00
|
|
|
),
|
2022-09-19 10:57:59 +00:00
|
|
|
policer.WithReplicator(c.replicator),
|
2022-05-31 17:00:41 +00:00
|
|
|
policer.WithRedundantCopyCallback(func(addr oid.Address) {
|
2022-05-23 13:12:32 +00:00
|
|
|
var inhumePrm engine.InhumePrm
|
|
|
|
inhumePrm.MarkAsGarbage(addr)
|
|
|
|
|
|
|
|
_, err := ls.Inhume(inhumePrm)
|
2021-02-19 15:23:21 +00:00
|
|
|
if err != nil {
|
|
|
|
c.log.Warn("could not inhume mark redundant copy as garbage",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}),
|
2021-11-10 08:34:00 +00:00
|
|
|
policer.WithMaxCapacity(c.cfgObject.pool.putRemoteCapacity),
|
|
|
|
policer.WithPool(c.cfgObject.pool.replication),
|
|
|
|
policer.WithNodeLoader(c),
|
2020-10-21 09:28:42 +00:00
|
|
|
)
|
|
|
|
|
2022-03-29 13:52:12 +00:00
|
|
|
traverseGen := util.NewTraverserGenerator(c.netMapSource, c.cfgObject.cnrSource, c)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2020-10-21 09:28:42 +00:00
|
|
|
c.workers = append(c.workers, pol)
|
|
|
|
|
2022-03-15 19:46:43 +00:00
|
|
|
var os putsvc.ObjectStorage
|
|
|
|
if c.cfgNotifications.enabled {
|
|
|
|
os = engineWithNotifications{
|
|
|
|
e: ls,
|
|
|
|
nw: c.cfgNotifications.nw,
|
|
|
|
ns: c.cfgNetmap.state,
|
|
|
|
defaultTopic: c.cfgNotifications.defaultTopic,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os = engineWithoutNotifications{
|
|
|
|
e: ls,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
sPut := putsvc.NewService(
|
|
|
|
putsvc.WithKeyStorage(keyStorage),
|
2021-06-22 12:31:13 +00:00
|
|
|
putsvc.WithClientConstructor(coreConstructor),
|
2022-06-14 12:56:03 +00:00
|
|
|
putsvc.WithMaxSizeSource(newCachedMaxObjectSizeSource(c)),
|
2022-03-15 19:46:43 +00:00
|
|
|
putsvc.WithObjectStorage(os),
|
2021-07-29 15:57:53 +00:00
|
|
|
putsvc.WithContainerSource(c.cfgObject.cnrSource),
|
2022-03-29 13:52:12 +00:00
|
|
|
putsvc.WithNetworkMapSource(c.netMapSource),
|
2021-09-06 12:17:14 +00:00
|
|
|
putsvc.WithNetmapKeys(c),
|
2020-10-03 10:14:09 +00:00
|
|
|
putsvc.WithFormatValidatorOpts(
|
2020-12-01 11:23:28 +00:00
|
|
|
objectCore.WithDeleteHandler(objInhumer),
|
2022-02-16 15:49:19 +00:00
|
|
|
objectCore.WithLocker(ls),
|
2020-10-03 10:14:09 +00:00
|
|
|
),
|
2020-10-21 15:12:31 +00:00
|
|
|
putsvc.WithNetworkState(c.cfgNetmap.state),
|
2021-10-08 13:34:39 +00:00
|
|
|
putsvc.WithWorkerPools(c.cfgObject.pool.putRemote),
|
2020-11-23 11:22:32 +00:00
|
|
|
putsvc.WithLogger(c.log),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
sPutV2 := putsvcV2.NewService(
|
|
|
|
putsvcV2.WithInternalService(sPut),
|
2021-05-28 13:26:32 +00:00
|
|
|
putsvcV2.WithKeyStorage(keyStorage),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
sSearch := searchsvc.New(
|
2020-11-23 11:25:57 +00:00
|
|
|
searchsvc.WithLogger(c.log),
|
2020-12-10 12:26:40 +00:00
|
|
|
searchsvc.WithLocalStorageEngine(ls),
|
2021-06-22 12:31:13 +00:00
|
|
|
searchsvc.WithClientConstructor(coreConstructor),
|
2020-12-10 12:26:40 +00:00
|
|
|
searchsvc.WithTraverserGenerator(
|
|
|
|
traverseGen.WithTraverseOptions(
|
|
|
|
placement.WithoutSuccessTracking(),
|
|
|
|
),
|
|
|
|
),
|
2022-03-29 13:52:12 +00:00
|
|
|
searchsvc.WithNetMapSource(c.netMapSource),
|
2021-10-26 13:02:46 +00:00
|
|
|
searchsvc.WithKeyStorage(keyStorage),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
sSearchV2 := searchsvcV2.NewService(
|
|
|
|
searchsvcV2.WithInternalService(sSearch),
|
2020-12-10 12:26:40 +00:00
|
|
|
searchsvcV2.WithKeyStorage(keyStorage),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
sGet := getsvc.New(
|
|
|
|
getsvc.WithLogger(c.log),
|
|
|
|
getsvc.WithLocalStorageEngine(ls),
|
2021-06-22 12:31:13 +00:00
|
|
|
getsvc.WithClientConstructor(coreConstructor),
|
2020-12-02 23:45:25 +00:00
|
|
|
getsvc.WithTraverserGenerator(
|
|
|
|
traverseGen.WithTraverseOptions(
|
|
|
|
placement.SuccessAfter(1),
|
|
|
|
),
|
|
|
|
),
|
2022-03-29 13:52:12 +00:00
|
|
|
getsvc.WithNetMapSource(c.netMapSource),
|
2021-10-26 13:02:46 +00:00
|
|
|
getsvc.WithKeyStorage(keyStorage),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
|
|
|
|
2022-04-19 18:01:49 +00:00
|
|
|
*c.cfgObject.getSvc = *sGet // need smth better
|
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
sGetV2 := getsvcV2.NewService(
|
|
|
|
getsvcV2.WithInternalService(sGet),
|
2020-12-02 23:45:25 +00:00
|
|
|
getsvcV2.WithKeyStorage(keyStorage),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
sDelete := deletesvc.New(
|
2020-11-23 11:19:49 +00:00
|
|
|
deletesvc.WithLogger(c.log),
|
2020-12-11 08:04:04 +00:00
|
|
|
deletesvc.WithHeadService(sGet),
|
|
|
|
deletesvc.WithSearchService(sSearch),
|
|
|
|
deletesvc.WithPutService(sPut),
|
2021-02-17 12:32:04 +00:00
|
|
|
deletesvc.WithNetworkInfo(&delNetInfo{
|
|
|
|
State: c.cfgNetmap.state,
|
2021-05-12 09:30:52 +00:00
|
|
|
tsLifetime: 5,
|
2021-11-08 12:10:49 +00:00
|
|
|
|
|
|
|
cfg: c,
|
2021-02-17 12:32:04 +00:00
|
|
|
}),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
sDeleteV2 := deletesvcV2.NewService(
|
|
|
|
deletesvcV2.WithInternalService(sDelete),
|
2020-12-11 08:04:04 +00:00
|
|
|
deletesvcV2.WithKeyStorage(keyStorage),
|
2020-09-23 13:55:46 +00:00
|
|
|
)
|
2020-08-25 14:44:41 +00:00
|
|
|
|
2021-03-15 09:12:49 +00:00
|
|
|
// build service pipeline
|
2022-03-15 16:54:21 +00:00
|
|
|
// grpc | <metrics> | signature | response | acl | split
|
2021-03-15 09:12:49 +00:00
|
|
|
|
|
|
|
splitSvc := objectService.NewTransportSplitter(
|
|
|
|
c.cfgGRPC.maxChunkSize,
|
|
|
|
c.cfgGRPC.maxAddrAmount,
|
|
|
|
&objectSvc{
|
|
|
|
put: sPutV2,
|
|
|
|
search: sSearchV2,
|
|
|
|
get: sGetV2,
|
|
|
|
delete: sDeleteV2,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2022-02-11 12:25:05 +00:00
|
|
|
aclSvc := v2.New(
|
|
|
|
v2.WithLogger(c.log),
|
2022-03-29 13:25:03 +00:00
|
|
|
v2.WithIRFetcher(newCachedIRFetcher(irFetcher)),
|
2022-03-29 13:52:12 +00:00
|
|
|
v2.WithNetmapSource(c.netMapSource),
|
2022-02-11 12:25:05 +00:00
|
|
|
v2.WithContainerSource(
|
2021-07-29 15:57:53 +00:00
|
|
|
c.cfgObject.cnrSource,
|
2021-03-15 09:12:49 +00:00
|
|
|
),
|
2022-02-11 12:25:05 +00:00
|
|
|
v2.WithNextService(splitSvc),
|
|
|
|
v2.WithEACLChecker(
|
|
|
|
acl.NewChecker(new(acl.CheckerPrm).
|
|
|
|
SetNetmapState(c.cfgNetmap.state).
|
|
|
|
SetEACLSource(c.cfgObject.eaclSource).
|
|
|
|
SetValidator(eaclSDK.NewValidator()).
|
|
|
|
SetLocalStorage(ls),
|
|
|
|
),
|
|
|
|
),
|
2021-03-15 09:12:49 +00:00
|
|
|
)
|
|
|
|
|
2022-01-10 07:49:30 +00:00
|
|
|
respSvc := objectService.NewResponseService(
|
|
|
|
aclSvc,
|
|
|
|
c.respSvc,
|
|
|
|
)
|
|
|
|
|
|
|
|
signSvc := objectService.NewSignService(
|
|
|
|
&c.key.PrivateKey,
|
|
|
|
respSvc,
|
|
|
|
)
|
|
|
|
|
|
|
|
var firstSvc objectService.ServiceServer = signSvc
|
2021-03-16 08:14:56 +00:00
|
|
|
if c.metricsCollector != nil {
|
2022-01-10 07:49:30 +00:00
|
|
|
firstSvc = objectService.NewMetricCollector(signSvc, c.metricsCollector)
|
2021-03-15 13:11:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:25:18 +00:00
|
|
|
server := objectTransportGRPC.New(firstSvc)
|
|
|
|
|
|
|
|
for _, srv := range c.cfgGRPC.servers {
|
|
|
|
objectGRPC.RegisterObjectServiceServer(srv, server)
|
|
|
|
}
|
2020-08-25 13:37:10 +00:00
|
|
|
}
|
2021-03-04 08:09:23 +00:00
|
|
|
|
2021-07-29 15:57:53 +00:00
|
|
|
type morphEACLFetcher struct {
|
2022-01-31 13:34:01 +00:00
|
|
|
w *cntClient.Client
|
2021-03-04 08:09:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
func (s *morphEACLFetcher) GetEACL(cnr cid.ID) (*containercore.EACL, error) {
|
|
|
|
eaclInfo, err := s.w.GetEACL(cnr)
|
2021-03-04 08:09:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
binTable, err := eaclInfo.Value.Marshal()
|
2022-05-16 13:15:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshal eACL table: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
if !eaclInfo.Signature.Verify(binTable) {
|
2022-05-16 13:15:31 +00:00
|
|
|
// TODO(@cthulhu-rider): #1387 use "const" error
|
|
|
|
return nil, errors.New("invalid signature of the eACL table")
|
2021-03-04 08:09:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 10:55:31 +00:00
|
|
|
return eaclInfo, nil
|
2021-03-04 08:09:23 +00:00
|
|
|
}
|
2021-03-23 18:59:31 +00:00
|
|
|
|
|
|
|
type reputationClientConstructor struct {
|
|
|
|
log *logger.Logger
|
|
|
|
|
|
|
|
nmSrc netmap.Source
|
|
|
|
|
|
|
|
netState netmap.State
|
|
|
|
|
|
|
|
trustStorage *truststorage.Storage
|
|
|
|
|
|
|
|
basicConstructor interface {
|
2022-01-13 15:01:50 +00:00
|
|
|
Get(coreclient.NodeInfo) (coreclient.Client, error)
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type reputationClient struct {
|
2022-01-13 15:01:50 +00:00
|
|
|
coreclient.MultiAddressClient
|
2021-03-23 18:59:31 +00:00
|
|
|
|
|
|
|
prm truststorage.UpdatePrm
|
|
|
|
|
|
|
|
cons *reputationClientConstructor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) submitResult(err error) {
|
2021-03-01 19:01:45 +00:00
|
|
|
currEpoch := c.cons.netState.CurrentEpoch()
|
|
|
|
sat := err == nil
|
|
|
|
|
|
|
|
c.cons.log.Debug(
|
|
|
|
"writing local reputation values",
|
|
|
|
zap.Uint64("epoch", currEpoch),
|
|
|
|
zap.Bool("satisfactory", sat),
|
|
|
|
)
|
|
|
|
|
2021-03-23 18:59:31 +00:00
|
|
|
prm := c.prm
|
2021-03-01 19:01:45 +00:00
|
|
|
prm.SetSatisfactory(sat)
|
|
|
|
prm.SetEpoch(currEpoch)
|
2021-03-23 18:59:31 +00:00
|
|
|
|
|
|
|
c.cons.trustStorage.Update(prm)
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (c *reputationClient) ObjectPutInit(ctx context.Context, prm client.PrmObjectPutInit) (*client.ObjectWriter, error) {
|
|
|
|
res, err := c.MultiAddressClient.ObjectPutInit(ctx, prm)
|
2021-03-23 18:59:31 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
// FIXME: (neofs-node#1193) here we submit only initialization errors, writing errors are not processed
|
2021-03-23 18:59:31 +00:00
|
|
|
c.submitResult(err)
|
|
|
|
|
2021-11-06 11:13:04 +00:00
|
|
|
return res, err
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (c *reputationClient) ObjectDelete(ctx context.Context, prm client.PrmObjectDelete) (*client.ResObjectDelete, error) {
|
|
|
|
res, err := c.MultiAddressClient.ObjectDelete(ctx, prm)
|
|
|
|
if err != nil {
|
|
|
|
c.submitResult(err)
|
|
|
|
} else {
|
|
|
|
c.submitResult(apistatus.ErrFromStatus(res.Status()))
|
|
|
|
}
|
2021-03-23 18:59:31 +00:00
|
|
|
|
2021-11-06 11:13:04 +00:00
|
|
|
return res, err
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (c *reputationClient) GetObjectInit(ctx context.Context, prm client.PrmObjectGet) (*client.ObjectReader, error) {
|
|
|
|
res, err := c.MultiAddressClient.ObjectGetInit(ctx, prm)
|
2021-03-23 18:59:31 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
// FIXME: (neofs-node#1193) here we submit only initialization errors, reading errors are not processed
|
2021-03-23 18:59:31 +00:00
|
|
|
c.submitResult(err)
|
|
|
|
|
2021-11-06 11:13:04 +00:00
|
|
|
return res, err
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (c *reputationClient) ObjectHead(ctx context.Context, prm client.PrmObjectHead) (*client.ResObjectHead, error) {
|
|
|
|
res, err := c.MultiAddressClient.ObjectHead(ctx, prm)
|
2021-03-23 18:59:31 +00:00
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
2021-11-06 11:13:04 +00:00
|
|
|
return res, err
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (c *reputationClient) ObjectHash(ctx context.Context, prm client.PrmObjectHash) (*client.ResObjectHash, error) {
|
|
|
|
res, err := c.MultiAddressClient.ObjectHash(ctx, prm)
|
2021-03-23 18:59:31 +00:00
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
2021-11-06 11:13:04 +00:00
|
|
|
return res, err
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
func (c *reputationClient) ObjectSearchInit(ctx context.Context, prm client.PrmObjectSearch) (*client.ObjectListReader, error) {
|
|
|
|
res, err := c.MultiAddressClient.ObjectSearchInit(ctx, prm)
|
2021-03-23 18:59:31 +00:00
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
// FIXME: (neofs-node#1193) here we submit only initialization errors, reading errors are not processed
|
2021-03-23 18:59:31 +00:00
|
|
|
c.submitResult(err)
|
|
|
|
|
2021-11-06 11:13:04 +00:00
|
|
|
return res, err
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 15:01:50 +00:00
|
|
|
func (c *reputationClientConstructor) Get(info coreclient.NodeInfo) (coreclient.Client, error) {
|
2021-09-28 04:46:10 +00:00
|
|
|
cl, err := c.basicConstructor.Get(info)
|
2021-03-23 18:59:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
nm, err := netmap.GetLatestNetworkMap(c.nmSrc)
|
|
|
|
if err == nil {
|
2021-09-28 05:44:40 +00:00
|
|
|
key := info.PublicKey()
|
2021-09-28 04:46:10 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
nmNodes := nm.Nodes()
|
2022-07-04 13:24:51 +00:00
|
|
|
var peer apireputation.PeerID
|
2022-06-08 23:18:26 +00:00
|
|
|
|
|
|
|
for i := range nmNodes {
|
|
|
|
if bytes.Equal(nmNodes[i].PublicKey(), key) {
|
2022-07-04 13:24:51 +00:00
|
|
|
peer.SetPublicKey(nmNodes[i].PublicKey())
|
|
|
|
|
2021-09-28 05:44:40 +00:00
|
|
|
prm := truststorage.UpdatePrm{}
|
2022-07-04 13:24:51 +00:00
|
|
|
prm.SetPeer(peer)
|
2021-09-28 05:44:40 +00:00
|
|
|
|
|
|
|
return &reputationClient{
|
2022-01-13 15:01:50 +00:00
|
|
|
MultiAddressClient: cl.(coreclient.MultiAddressClient),
|
|
|
|
prm: prm,
|
|
|
|
cons: c,
|
2021-09-28 05:44:40 +00:00
|
|
|
}, nil
|
2021-03-23 18:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.log.Warn("could not get latest network map to overload the client",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cl, nil
|
|
|
|
}
|
2022-03-15 19:46:43 +00:00
|
|
|
|
|
|
|
type engineWithNotifications struct {
|
|
|
|
e *engine.StorageEngine
|
|
|
|
nw notificationWriter
|
|
|
|
ns netmap.State
|
|
|
|
|
|
|
|
defaultTopic string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e engineWithNotifications) Put(o *objectSDK.Object) error {
|
|
|
|
if err := engine.Put(e.e, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ni, err := o.NotificationInfo()
|
|
|
|
if err == nil {
|
|
|
|
if epoch := ni.Epoch(); epoch == 0 || epoch == e.ns.CurrentEpoch() {
|
|
|
|
topic := ni.Topic()
|
|
|
|
|
|
|
|
if topic == "" {
|
|
|
|
topic = e.defaultTopic
|
|
|
|
}
|
|
|
|
|
|
|
|
e.nw.Notify(topic, objectCore.AddressOf(o))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type engineWithoutNotifications struct {
|
|
|
|
e *engine.StorageEngine
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e engineWithoutNotifications) Put(o *objectSDK.Object) error {
|
|
|
|
return engine.Put(e.e, o)
|
|
|
|
}
|