From b627814dd83ad1381040851ec32303f956a76fdc Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 21 Oct 2020 18:11:19 +0300 Subject: [PATCH] [#60] object/transformer: Set creation epoch number in new objects Set value of CreationEpoch object field to the value from network State. Signed-off-by: Leonard Lyubich --- pkg/services/object_manager/transformer/fmt.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/services/object_manager/transformer/fmt.go b/pkg/services/object_manager/transformer/fmt.go index 5336228cf..2bab28616 100644 --- a/pkg/services/object_manager/transformer/fmt.go +++ b/pkg/services/object_manager/transformer/fmt.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/token" + "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/pkg/errors" ) @@ -25,6 +26,8 @@ type FormatterParams struct { NextTarget ObjectTarget SessionToken *token.SessionToken + + NetworkState netmap.State } // NewFormatTarget returns ObjectTarget instance that finalizes object structure @@ -36,6 +39,7 @@ type FormatterParams struct { // - sets version to current SDK version; // - sets payload size to the total length of all written chunks; // - sets session token; +// - sets number of creation epoch; // - calculates and sets verification fields (ID, Signature). func NewFormatTarget(p *FormatterParams) ObjectTarget { return &formatter{ @@ -58,9 +62,12 @@ func (f *formatter) Write(p []byte) (n int, err error) { } func (f *formatter) Close() (*AccessIdentifiers, error) { + curEpoch := f.prm.NetworkState.CurrentEpoch() + f.obj.SetVersion(pkg.SDKVersion()) f.obj.SetPayloadSize(f.sz) f.obj.SetSessionToken(f.prm.SessionToken) + f.obj.SetCreationEpoch(curEpoch) var parID *objectSDK.ID @@ -68,6 +75,7 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { rawPar := objectSDK.NewRawFromV2(par.ToV2()) rawPar.SetSessionToken(f.prm.SessionToken) + rawPar.SetCreationEpoch(curEpoch) if err := objectSDK.SetIDWithSignature(f.prm.Key, rawPar); err != nil { return nil, errors.Wrap(err, "could not finalize parent object")