[#85] inner-ring/container: Check container format in process Put

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-03 13:02:39 +03:00 committed by Leonard Lyubich
parent 766eea4c8c
commit a8e9d15f3f

View file

@ -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 {