From 1654df4d97f208b3a81006c89302e6a6e8fb3fd7 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 1 Oct 2020 14:42:17 +0300 Subject: [PATCH] [#61] Update to latest neofs-api-go changes Signed-off-by: Leonard Lyubich --- go.mod | 2 +- go.sum | Bin 58620 -> 58865 bytes pkg/core/object/fmt.go | 19 +++++++----------- pkg/core/object/object.go | 13 ++++++++++++ pkg/services/object/head/service.go | 3 +-- pkg/services/object/search/local.go | 3 +-- pkg/services/object/search/query/v1/v1.go | 2 +- .../object_manager/transformer/fmt.go | 2 +- .../object_manager/transformer/transformer.go | 11 +++++----- 9 files changed, 31 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index ec5a47e8d..b182e8998 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2 github.com/multiformats/go-multihash v0.0.13 // indirect github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78 - github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200929122641-420d9560625b + github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201001070630-cf70026c7e42 github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/nspcc-dev/tzhash v1.4.0 github.com/panjf2000/ants/v2 v2.3.0 diff --git a/go.sum b/go.sum index 7005c8c7f18565cade5c25c1d2ea55941a6837f4..7501e1c3a77b2750ce2e595f2a5cb9e386681a87 100644 GIT binary patch delta 121 zcmex!lKJCl<_!ljCZA3haWgb9Ff=eXFf%sLO-?g6FfcMpHcvG%Qphm0D$R5+GY!%A z%L{P|am_1B@^$piE652-*LLzYE>Chc3eC?Cvxv$oEAS1RY?v-J**-&D9EWk6b2IvD E0KhCJ@Bjb+ delta 18 acmex(n)%O3<_!ljCZEgV+Ppv0s0ILJdkMY( diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index 931e65be2..b6365cae1 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -37,19 +37,14 @@ func (v *FormatValidator) Validate(obj *Object) error { return errNilCID } - if err := v.validateSignatureKey(obj); err != nil { - return errors.Wrapf(err, "(%T) could not validate signature key", v) - } + for ; obj != nil; obj = obj.GetParent() { + if err := v.validateSignatureKey(obj); err != nil { + return errors.Wrapf(err, "(%T) could not validate signature key", v) + } - if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { - return errors.Wrapf(err, "(%T) could not validate header fields", v) - } - - par := NewFromSDK(obj.GetParent()) - - // validate parent object header - if par.GetID() != nil && len(obj.GetChildren()) == 0 { - return v.Validate(par) + if err := object.CheckHeaderVerificationFields(obj.SDK()); err != nil { + return errors.Wrapf(err, "(%T) could not validate header fields", v) + } } return nil diff --git a/pkg/core/object/object.go b/pkg/core/object/object.go index 66ca0749f..4ee263ad6 100644 --- a/pkg/core/object/object.go +++ b/pkg/core/object/object.go @@ -67,3 +67,16 @@ func FromBytes(data []byte) (*Object, error) { Object: o, }, nil } + +// GetParent returns parent object. +func (o *Object) GetParent() *Object { + if o != nil { + if par := o.Object.GetParent(); par != nil { + return &Object{ + Object: par, + } + } + } + + return nil +} diff --git a/pkg/services/object/head/service.go b/pkg/services/object/head/service.go index f404497f4..409ed9a22 100644 --- a/pkg/services/object/head/service.go +++ b/pkg/services/object/head/service.go @@ -6,7 +6,6 @@ import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/localstore" "github.com/nspcc-dev/neofs-node/pkg/network" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" @@ -87,7 +86,7 @@ func (s *Service) Head(ctx context.Context, prm *Prm) (*Response, error) { // TODO: check if received parent has requested address return &Response{ - hdr: object.NewFromSDK(rightChild.GetParent()), + hdr: rightChild.GetParent(), rightChild: rightChild, }, nil } diff --git a/pkg/services/object/search/local.go b/pkg/services/object/search/local.go index 8853df4fb..9c09beb13 100644 --- a/pkg/services/object/search/local.go +++ b/pkg/services/object/search/local.go @@ -4,7 +4,6 @@ import ( "context" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" - "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/bucket" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/localstore" "github.com/nspcc-dev/neofs-node/pkg/services/object/search/query" @@ -47,7 +46,7 @@ func (s *localStream) stream(ctx context.Context, ch chan<- []*objectSDK.ID) err func (f *searchQueryFilter) Pass(ctx context.Context, meta *localstore.ObjectMeta) *localstore.FilterResult { loop: - for obj := meta.Head(); obj.GetID() != nil; obj = object.NewFromSDK(obj.GetParent()) { + for obj := meta.Head(); obj != nil; obj = obj.GetParent() { if !f.query.Match(obj) { continue } diff --git a/pkg/services/object/search/query/v1/v1.go b/pkg/services/object/search/query/v1/v1.go index 3066d8f95..6dbb9f6e4 100644 --- a/pkg/services/object/search/query/v1/v1.go +++ b/pkg/services/object/search/query/v1/v1.go @@ -100,7 +100,7 @@ func headerEqual(obj *object.Object, key, value string) bool { case keyNoChildrenField: return len(obj.GetChildren()) == 0 case keyParentIDField: - return idValue(obj.GetParent().GetID()) == value + return idValue(obj.GetParentID()) == value case keyParentField: return len(obj.GetChildren()) > 0 // TODO: add other headers diff --git a/pkg/services/object_manager/transformer/fmt.go b/pkg/services/object_manager/transformer/fmt.go index 2ee3565b1..af3678005 100644 --- a/pkg/services/object_manager/transformer/fmt.go +++ b/pkg/services/object_manager/transformer/fmt.go @@ -61,7 +61,7 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { var parID *objectSDK.ID - if par := f.obj.GetParent(); par != nil && par.ToV2().GetHeader() != nil { + if par := f.obj.GetParent(); par != nil { rawPar := objectSDK.NewRawFromV2(par.ToV2()) rawPar.SetSessionToken(f.token) diff --git a/pkg/services/object_manager/transformer/transformer.go b/pkg/services/object_manager/transformer/transformer.go index 9fae70e5e..3b521a0ee 100644 --- a/pkg/services/object_manager/transformer/transformer.go +++ b/pkg/services/object_manager/transformer/transformer.go @@ -76,6 +76,7 @@ func (s *payloadSizeLimiter) initialize() { // initialize parent object once (after 1st object) if ln == 1 { s.parent = s.current + s.parent.ResetRelations() s.parentHashers = s.currentHashers s.current = fromObject(s.parent) } @@ -206,19 +207,19 @@ func writeHashes(hashers []*payloadChecksumHasher) { } func (s *payloadSizeLimiter) initializeLinking() { - id := s.current.GetParent().GetID() - par := objectSDK.NewRaw() - par.SetID(id) + id := s.current.GetParentID() s.current = fromObject(s.current) + s.current.SetParentID(id) s.current.SetChildren(s.previous...) - - s.current.SetParent(par.Object()) } func (s *payloadSizeLimiter) writeChunk(chunk []byte) error { // statement is true if the previous write of bytes reached exactly the boundary. if s.written > 0 && s.written%s.maxSize == 0 { + // initialize blank split header + s.current.InitRelations() + // we need to release current object if _, err := s.release(false); err != nil { return errors.Wrap(err, "could not release object")