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"
|
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"
|
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"
|
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
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
|
|
|
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-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/util/signature"
|
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-01-26 12:11:13 +00:00
|
|
|
func (r *localObjectInhumer) DeleteObjects(ts *addressSDK.Address, addr ...*addressSDK.Address) {
|
2020-12-01 11:23:28 +00:00
|
|
|
prm := new(engine.InhumePrm)
|
|
|
|
|
|
|
|
for _, a := range addr {
|
2021-02-19 14:01:01 +00:00
|
|
|
prm.WithTarget(ts, a)
|
2020-12-01 11:23:28 +00:00
|
|
|
|
|
|
|
if _, err := r.storage.Inhume(prm); err != nil {
|
2020-11-19 10:58:27 +00:00
|
|
|
r.log.Error("could not delete object",
|
|
|
|
zap.Stringer("address", a),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
func (i *delNetInfo) LocalNodeID() *owner.ID {
|
|
|
|
return i.cfg.ownerIDFromKey
|
|
|
|
}
|
|
|
|
|
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,
|
2021-07-29 15:57:53 +00:00
|
|
|
nmSrc: c.cfgObject.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)
|
|
|
|
|
2021-07-20 20:59:39 +00:00
|
|
|
var irFetcher acl.InnerRingFetcher
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2020-10-21 11:51:20 +00:00
|
|
|
repl := replicator.New(
|
|
|
|
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
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
c.workers = append(c.workers, repl)
|
|
|
|
|
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(
|
2021-07-29 15:57:53 +00:00
|
|
|
placement.NewNetworkMapSourceBuilder(c.cfgObject.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
|
|
|
),
|
2020-10-21 11:51:20 +00:00
|
|
|
policer.WithReplicator(repl),
|
2022-01-26 12:11:13 +00:00
|
|
|
policer.WithRedundantCopyCallback(func(addr *addressSDK.Address) {
|
2021-02-19 15:23:21 +00:00
|
|
|
_, err := ls.Inhume(new(engine.InhumePrm).MarkAsGarbage(addr))
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2021-07-29 15:57:53 +00:00
|
|
|
traverseGen := util.NewTraverserGenerator(c.cfgObject.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)
|
|
|
|
|
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),
|
2020-10-22 14:21:28 +00:00
|
|
|
putsvc.WithMaxSizeSource(c),
|
2020-09-23 13:55:46 +00:00
|
|
|
putsvc.WithLocalStorage(ls),
|
2021-07-29 15:57:53 +00:00
|
|
|
putsvc.WithContainerSource(c.cfgObject.cnrSource),
|
|
|
|
putsvc.WithNetworkMapSource(c.cfgObject.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),
|
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(),
|
|
|
|
),
|
|
|
|
),
|
2021-01-12 14:55:02 +00:00
|
|
|
searchsvc.WithNetMapSource(c.cfgNetmap.wrapper),
|
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),
|
|
|
|
),
|
|
|
|
),
|
2021-01-12 14:55:02 +00:00
|
|
|
getsvc.WithNetMapSource(c.cfgNetmap.wrapper),
|
2021-10-26 13:02:46 +00:00
|
|
|
getsvc.WithKeyStorage(keyStorage),
|
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
|
2021-03-15 13:11:40 +00:00
|
|
|
// grpc | <metrics> | acl | signature | response | 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,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
aclSvc := acl.New(
|
|
|
|
acl.WithSenderClassifier(
|
|
|
|
acl.NewSenderClassifier(
|
|
|
|
c.log,
|
2021-03-23 10:32:18 +00:00
|
|
|
irFetcher,
|
2021-03-15 09:12:49 +00:00
|
|
|
c.cfgNetmap.wrapper,
|
2020-08-25 13:37:10 +00:00
|
|
|
),
|
|
|
|
),
|
2021-03-15 09:12:49 +00:00
|
|
|
acl.WithContainerSource(
|
2021-07-29 15:57:53 +00:00
|
|
|
c.cfgObject.cnrSource,
|
2021-03-15 09:12:49 +00:00
|
|
|
),
|
2022-01-10 07:49:30 +00:00
|
|
|
acl.WithNextService(splitSvc),
|
2021-03-15 09:12:49 +00:00
|
|
|
acl.WithLocalStorage(ls),
|
2022-01-20 09:45:58 +00:00
|
|
|
acl.WithEACLSource(c.cfgObject.eaclSource),
|
2021-03-15 09:12:49 +00:00
|
|
|
acl.WithNetmapState(c.cfgNetmap.state),
|
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
type signedEACLTable eaclSDK.Table
|
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
func (s *signedEACLTable) ReadSignedData(_ []byte) ([]byte, error) {
|
|
|
|
return (*eaclSDK.Table)(s).Marshal()
|
2021-03-04 08:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signedEACLTable) SignedDataSize() int {
|
2022-02-07 13:34:02 +00:00
|
|
|
// TODO: #1147 add eacl.Table.Size method
|
2021-03-04 08:09:23 +00:00
|
|
|
return (*eaclSDK.Table)(s).ToV2().StableSize()
|
|
|
|
}
|
|
|
|
|
2021-07-29 15:57:53 +00:00
|
|
|
func (s *morphEACLFetcher) GetEACL(cid *cid.ID) (*eaclSDK.Table, error) {
|
2021-05-25 15:18:32 +00:00
|
|
|
table, err := s.w.GetEACL(cid)
|
2021-03-04 08:09:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:18:32 +00:00
|
|
|
sig := table.Signature()
|
|
|
|
|
2021-03-04 08:09:23 +00:00
|
|
|
if err := signature.VerifyDataWithSource(
|
|
|
|
(*signedEACLTable)(table),
|
|
|
|
func() ([]byte, []byte) {
|
|
|
|
return sig.Key(), sig.Sign()
|
|
|
|
},
|
|
|
|
signature.SignWithRFC6979(),
|
|
|
|
); err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("incorrect signature: %w", err)
|
2021-03-04 08:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return table, nil
|
|
|
|
}
|
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) {
|
|
|
|
prm := c.prm
|
|
|
|
prm.SetSatisfactory(err == nil)
|
|
|
|
prm.SetEpoch(c.cons.netState.CurrentEpoch())
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-03-23 18:59:31 +00:00
|
|
|
for i := range nm.Nodes {
|
2021-09-28 05:44:40 +00:00
|
|
|
if bytes.Equal(nm.Nodes[i].PublicKey(), key) {
|
|
|
|
prm := truststorage.UpdatePrm{}
|
|
|
|
prm.SetPeer(reputation.PeerIDFromBytes(nm.Nodes[i].PublicKey()))
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|