2020-08-25 13:37:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-08-25 14:44:41 +00:00
|
|
|
"context"
|
2021-03-23 18:59:31 +00:00
|
|
|
"crypto/sha256"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-08-25 14:44:41 +00:00
|
|
|
|
2021-03-04 08:09:23 +00:00
|
|
|
eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
2020-11-23 12:59:30 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2021-03-04 08:09:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2020-11-19 10:58:27 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-09-23 13:55:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
2021-03-04 08:09:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/util/signature"
|
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-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"
|
2021-03-04 08:09:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
2020-10-21 09:28:42 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
2021-03-23 18:59:31 +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-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-10-03 07:46:57 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/acl/eacl"
|
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"
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *localObjectInhumer) DeleteObjects(ts *objectSDK.Address, addr ...*objectSDK.Address) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *delNetInfo) TombstoneLifetime() (uint64, error) {
|
|
|
|
return i.tsLifetime, nil
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:18 +00:00
|
|
|
type innerRingFetcher struct {
|
|
|
|
sidechain *morphClient.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *innerRingFetcher) InnerRingKeys() ([][]byte, error) {
|
|
|
|
keys, err := n.sidechain.NeoFSAlphabetList()
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("can't get inner ring keys: %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
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
func initObjectService(c *cfg) {
|
|
|
|
ls := c.cfgObject.cfgLocalStorage.localStorage
|
2020-09-23 13:55:46 +00:00
|
|
|
keyStorage := util.NewKeyStorage(c.key, c.privateTokenStore)
|
|
|
|
nodeOwner := owner.NewID()
|
|
|
|
|
|
|
|
neo3Wallet, err := owner.NEO3WalletFromPublicKey(&c.key.PublicKey)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
nodeOwner.SetNeo3Wallet(neo3Wallet)
|
|
|
|
|
2021-03-13 15:22:24 +00:00
|
|
|
clientCache := cache.NewSDKClientCache(
|
2021-05-12 08:04:51 +00:00
|
|
|
client.WithDialTimeout(c.viper.GetDuration(cfgAPIClientDialTimeout)))
|
2020-11-18 13:03:00 +00:00
|
|
|
|
2021-03-23 18:59:31 +00:00
|
|
|
clientConstructor := &reputationClientConstructor{
|
|
|
|
log: c.log,
|
|
|
|
nmSrc: c.cfgObject.netMapStorage,
|
|
|
|
netState: c.cfgNetmap.state,
|
|
|
|
trustStorage: c.cfgReputation.localTrustStorage,
|
|
|
|
basicConstructor: clientCache,
|
|
|
|
}
|
|
|
|
|
2021-03-23 10:32:18 +00:00
|
|
|
irFetcher := &innerRingFetcher{
|
|
|
|
sidechain: c.cfgMorph.client,
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
c.viper.GetDuration(cfgReplicatorPutTimeout),
|
|
|
|
),
|
|
|
|
replicator.WithLocalStorage(ls),
|
|
|
|
replicator.WithRemoteSender(
|
2021-03-23 18:59:31 +00:00
|
|
|
putsvc.NewRemoteSender(keyStorage, clientConstructor),
|
2020-10-21 11:51:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
c.workers = append(c.workers, repl)
|
|
|
|
|
2020-10-21 09:28:42 +00:00
|
|
|
ch := make(chan *policer.Task, 1)
|
|
|
|
|
|
|
|
pol := policer.New(
|
|
|
|
policer.WithLogger(c.log),
|
|
|
|
policer.WithLocalStorage(ls),
|
|
|
|
policer.WithContainerSource(c.cfgObject.cnrStorage),
|
|
|
|
policer.WithPlacementBuilder(
|
|
|
|
placement.NewNetworkMapSourceBuilder(c.cfgObject.netMapStorage),
|
|
|
|
),
|
2021-05-12 08:46:29 +00:00
|
|
|
policer.WithWorkScope(100),
|
|
|
|
policer.WithExpansionRate(10),
|
2020-10-21 09:28:42 +00:00
|
|
|
policer.WithTrigger(ch),
|
|
|
|
policer.WithRemoteHeader(
|
2021-03-23 18:59:31 +00:00
|
|
|
headsvc.NewRemoteHeader(keyStorage, clientConstructor),
|
2020-10-21 09:28:42 +00:00
|
|
|
),
|
|
|
|
policer.WithLocalAddressSource(c),
|
|
|
|
policer.WithHeadTimeout(
|
|
|
|
c.viper.GetDuration(cfgPolicerHeadTimeout),
|
|
|
|
),
|
2020-10-21 11:51:20 +00:00
|
|
|
policer.WithReplicator(repl),
|
2021-02-19 15:23:21 +00:00
|
|
|
policer.WithRedundantCopyCallback(func(addr *objectSDK.Address) {
|
|
|
|
_, 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()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}),
|
2020-10-21 09:28:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
addNewEpochNotificationHandler(c, func(ev event.Event) {
|
|
|
|
select {
|
|
|
|
case ch <- new(policer.Task):
|
|
|
|
case <-c.ctx.Done():
|
|
|
|
close(ch)
|
|
|
|
default:
|
|
|
|
c.log.Info("policer is busy")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
traverseGen := util.NewTraverserGenerator(c.cfgObject.netMapStorage, c.cfgObject.cnrStorage, c)
|
|
|
|
|
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-03-23 18:59:31 +00:00
|
|
|
putsvc.WithClientConstructor(clientConstructor),
|
2020-10-22 14:21:28 +00:00
|
|
|
putsvc.WithMaxSizeSource(c),
|
2020-09-23 13:55:46 +00:00
|
|
|
putsvc.WithLocalStorage(ls),
|
|
|
|
putsvc.WithContainerSource(c.cfgObject.cnrStorage),
|
|
|
|
putsvc.WithNetworkMapSource(c.cfgObject.netMapStorage),
|
|
|
|
putsvc.WithLocalAddressSource(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),
|
2020-11-09 15:40:06 +00:00
|
|
|
putsvc.WithWorkerPool(c.cfgObject.pool.put),
|
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),
|
|
|
|
)
|
|
|
|
|
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-03-23 18:59:31 +00:00
|
|
|
searchsvc.WithClientConstructor(clientConstructor),
|
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),
|
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-03-23 18:59:31 +00:00
|
|
|
getsvc.WithClientConstructor(clientConstructor),
|
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),
|
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-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,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
respSvc := objectService.NewResponseService(
|
|
|
|
splitSvc,
|
|
|
|
c.respSvc,
|
|
|
|
)
|
|
|
|
|
|
|
|
signSvc := objectService.NewSignService(
|
|
|
|
c.key,
|
|
|
|
respSvc,
|
|
|
|
)
|
|
|
|
|
|
|
|
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(
|
|
|
|
c.cfgObject.cnrStorage,
|
|
|
|
),
|
|
|
|
acl.WithNextService(signSvc),
|
|
|
|
acl.WithLocalStorage(ls),
|
|
|
|
acl.WithEACLValidatorOptions(
|
|
|
|
eacl.WithEACLStorage(newCachedEACLStorage(&morphEACLStorage{
|
|
|
|
w: c.cfgObject.cnrClient,
|
|
|
|
})),
|
|
|
|
eacl.WithLogger(c.log),
|
|
|
|
),
|
|
|
|
acl.WithNetmapState(c.cfgNetmap.state),
|
|
|
|
)
|
|
|
|
|
2021-03-15 13:11:40 +00:00
|
|
|
var firstSvc objectService.ServiceServer = aclSvc
|
2021-03-16 08:14:56 +00:00
|
|
|
if c.metricsCollector != nil {
|
|
|
|
firstSvc = objectService.NewMetricCollector(aclSvc, c.metricsCollector)
|
2021-03-15 13:11:40 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:12:49 +00:00
|
|
|
objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server,
|
2021-03-15 13:11:40 +00:00
|
|
|
objectTransportGRPC.New(firstSvc),
|
2020-08-25 13:37:10 +00:00
|
|
|
)
|
|
|
|
}
|
2021-03-04 08:09:23 +00:00
|
|
|
|
|
|
|
type morphEACLStorage struct {
|
|
|
|
w *wrapper.Wrapper
|
|
|
|
}
|
|
|
|
|
|
|
|
type signedEACLTable eaclSDK.Table
|
|
|
|
|
|
|
|
func (s *signedEACLTable) ReadSignedData(buf []byte) ([]byte, error) {
|
|
|
|
return (*eaclSDK.Table)(s).Marshal(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signedEACLTable) SignedDataSize() int {
|
|
|
|
// TODO: add eacl.Table.Size method
|
|
|
|
return (*eaclSDK.Table)(s).ToV2().StableSize()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *morphEACLStorage) GetEACL(cid *container.ID) (*eaclSDK.Table, error) {
|
|
|
|
table, sig, err := s.w.GetEACL(cid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
Get(string) (client.Client, error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type reputationClient struct {
|
|
|
|
client.Client
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) PutObject(ctx context.Context, prm *client.PutObjectParams, opts ...client.CallOption) (*objectSDK.ID, error) {
|
|
|
|
id, err := c.Client.PutObject(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return id, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) DeleteObject(ctx context.Context, prm *client.DeleteObjectParams, opts ...client.CallOption) error {
|
|
|
|
err := c.Client.DeleteObject(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) GetObject(ctx context.Context, prm *client.GetObjectParams, opts ...client.CallOption) (*objectSDK.Object, error) {
|
|
|
|
obj, err := c.Client.GetObject(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return obj, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) GetObjectHeader(ctx context.Context, prm *client.ObjectHeaderParams, opts ...client.CallOption) (*objectSDK.Object, error) {
|
|
|
|
obj, err := c.Client.GetObjectHeader(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return obj, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) ObjectPayloadRangeData(ctx context.Context, prm *client.RangeDataParams, opts ...client.CallOption) ([]byte, error) {
|
|
|
|
rng, err := c.Client.ObjectPayloadRangeData(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return rng, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) ObjectPayloadRangeSHA256(ctx context.Context, prm *client.RangeChecksumParams, opts ...client.CallOption) ([][sha256.Size]byte, error) {
|
|
|
|
hashes, err := c.Client.ObjectPayloadRangeSHA256(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return hashes, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) ObjectPayloadRangeTZ(ctx context.Context, prm *client.RangeChecksumParams, opts ...client.CallOption) ([][client.TZSize]byte, error) {
|
|
|
|
hashes, err := c.Client.ObjectPayloadRangeTZ(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return hashes, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClient) SearchObject(ctx context.Context, prm *client.SearchObjectParams, opts ...client.CallOption) ([]*objectSDK.ID, error) {
|
|
|
|
ids, err := c.Client.SearchObject(ctx, prm, opts...)
|
|
|
|
|
|
|
|
c.submitResult(err)
|
|
|
|
|
|
|
|
return ids, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *reputationClientConstructor) Get(addr string) (client.Client, error) {
|
|
|
|
cl, err := c.basicConstructor.Get(addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
nm, err := netmap.GetLatestNetworkMap(c.nmSrc)
|
|
|
|
if err == nil {
|
|
|
|
for i := range nm.Nodes {
|
2021-05-17 12:04:32 +00:00
|
|
|
hostAddr, err := network.HostAddrFromMultiaddr(nm.Nodes[i].Address())
|
2021-03-23 18:59:31 +00:00
|
|
|
if err == nil {
|
2021-05-17 12:04:32 +00:00
|
|
|
if hostAddr == addr {
|
2021-03-23 18:59:31 +00:00
|
|
|
prm := truststorage.UpdatePrm{}
|
|
|
|
prm.SetPeer(reputation.PeerIDFromBytes(nm.Nodes[i].PublicKey()))
|
|
|
|
|
|
|
|
return &reputationClient{
|
|
|
|
Client: cl,
|
|
|
|
prm: prm,
|
|
|
|
cons: c,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c.log.Warn("could not get latest network map to overload the client",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cl, nil
|
|
|
|
}
|