From a8e9d15f3f75382f984cdcf43877dba7df79ca6d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 3 Nov 2020 13:02:39 +0300 Subject: [PATCH] [#85] inner-ring/container: Check container format in process Put Signed-off-by: Leonard Lyubich --- .../processors/container/process_container.go | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go index 96253e4fd..9879f937d 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -1,6 +1,11 @@ package container import ( + "github.com/golang/protobuf/proto" + containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" + v2container "github.com/nspcc-dev/neofs-api-go/v2/container" + containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" + "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/innerring/invoke" containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container" "go.uber.org/zap" @@ -14,10 +19,36 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) { return } + cnrData := put.Container() + + // unmarshal container structure + // FIXME: temp solution, replace after neofs-api-go#168 + cnrProto := new(containerGRPC.Container) + if err := proto.Unmarshal(cnrData, cnrProto); err != nil { + cp.log.Info("could not unmarshal container structure", + zap.String("error", err.Error()), + ) + + return + } + + cnr := containerSDK.NewContainerFromV2( + v2container.ContainerFromGRPCMessage(cnrProto), + ) + + // perform format check + if err := container.CheckFormat(cnr); err != nil { + cp.log.Info("container with incorrect format detected", + zap.String("error", err.Error()), + ) + + return + } + err := invoke.RegisterContainer(cp.morphClient, cp.containerContract, &invoke.ContainerParams{ Key: put.PublicKey(), - Container: put.Container(), + Container: cnrData, Signature: put.Signature(), }) if err != nil {