From fa685160f92c40b11fd3f694241a3cc390709b74 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 1 Feb 2021 14:21:24 +0300 Subject: [PATCH] [#328] container/load: Implement Writer on Container contract's client Implement wrapper over Container contract's client on app-side that passes used space values to it. Uses a fixed public key, whose value will be the key of the local storage node. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/container.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 432d744af..9c8ad17d1 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -1,6 +1,7 @@ package main import ( + containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" @@ -8,6 +9,8 @@ import ( containerTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc" containerService "github.com/nspcc-dev/neofs-node/pkg/services/container" containerMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph" + "github.com/nspcc-dev/neofs-node/pkg/util/logger" + "go.uber.org/zap" ) func initContainerService(c *cfg) { @@ -41,3 +44,25 @@ func initContainerService(c *cfg) { ), ) } + +type morphLoadWriter struct { + log *logger.Logger + + cnrMorphClient *wrapper.Wrapper + + key []byte +} + +func (w *morphLoadWriter) Put(a containerSDK.UsedSpaceAnnouncement) error { + w.log.Debug("save used space announcement in contract", + zap.Uint64("epoch", a.Epoch()), + zap.Stringer("cid", a.ContainerID()), + zap.Uint64("size", a.UsedSpace()), + ) + + return w.cnrMorphClient.AnnounceLoad(a, w.key) +} + +func (*morphLoadWriter) Close() error { + return nil +}