From 87d83174d93669b807ed87fa712582bf3bb436ff Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 19 May 2021 15:18:07 +0300 Subject: [PATCH] [#505] ir/container: Implement simplified handling of SetEACL event Implement `handleSetEACL` method similar to other handling methods in Container processor. To begin with, the validation logic is skipped, and all tables will be sent to the contract. In the future, the necessary checks will be implemented. Listening for events in the IR node will also be added. Signed-off-by: Leonard Lyubich --- .../processors/container/handlers.go | 19 ++++++++++ .../processors/container/process_eacl.go | 37 +++++++++++++++++++ .../processors/container/processor.go | 2 + 3 files changed, 58 insertions(+) create mode 100644 pkg/innerring/processors/container/process_eacl.go diff --git a/pkg/innerring/processors/container/handlers.go b/pkg/innerring/processors/container/handlers.go index a294456769..3fabdb1578 100644 --- a/pkg/innerring/processors/container/handlers.go +++ b/pkg/innerring/processors/container/handlers.go @@ -42,3 +42,22 @@ func (cp *Processor) handleDelete(ev event.Event) { zap.Int("capacity", cp.pool.Cap())) } } + +func (cp *Processor) handleSetEACL(ev event.Event) { + e := ev.(containerEvent.SetEACL) + + cp.log.Info("notification", + zap.String("type", "set EACL"), + ) + + // send event to the worker pool + + err := cp.pool.Submit(func() { + cp.processSetEACL(e) + }) + if err != nil { + // there system can be moved into controlled degradation stage + cp.log.Warn("container processor worker pool drained", + zap.Int("capacity", cp.pool.Cap())) + } +} diff --git a/pkg/innerring/processors/container/process_eacl.go b/pkg/innerring/processors/container/process_eacl.go new file mode 100644 index 0000000000..9c014605c7 --- /dev/null +++ b/pkg/innerring/processors/container/process_eacl.go @@ -0,0 +1,37 @@ +package container + +import ( + "github.com/nspcc-dev/neofs-node/pkg/morph/event/container" + "go.uber.org/zap" +) + +func (cp *Processor) processSetEACL(e container.SetEACL) { + if !cp.alphabetState.IsAlphabet() { + cp.log.Info("non alphabet mode, ignore set EACL") + return + } + + err := cp.checkSetEACL(e) + if err != nil { + cp.log.Error("set EACL check failed", + zap.String("error", err.Error()), + ) + + return + } + + cp.approveSetEACL(e) +} + +func (cp *Processor) checkSetEACL(e container.SetEACL) error { + return nil +} + +func (cp *Processor) approveSetEACL(e container.SetEACL) { + err := cp.cnrClient.PutEACLBinary(e.Table(), e.PublicKey(), e.Signature()) + if err != nil { + cp.log.Error("could not approve set EACL", + zap.String("error", err.Error()), + ) + } +} diff --git a/pkg/innerring/processors/container/processor.go b/pkg/innerring/processors/container/processor.go index c37c50e937..de664754e6 100644 --- a/pkg/innerring/processors/container/processor.go +++ b/pkg/innerring/processors/container/processor.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/innerring/config" "github.com/nspcc-dev/neofs-node/pkg/morph/client" + "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/event" containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container" "github.com/panjf2000/ants/v2" @@ -27,6 +28,7 @@ type ( morphClient *client.Client alphabetState AlphabetState feeProvider *config.FeeConfig + cnrClient *wrapper.Wrapper } // Params of the processor constructor.