From 8a2460286f5b5c521da213fa75c6892a6aec32c9 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 16 May 2022 10:46:24 +0300 Subject: [PATCH] [#435] Sync homomorphic hash disabling with network config Signed-off-by: Alex Vanin --- internal/neofs/neofs.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/internal/neofs/neofs.go b/internal/neofs/neofs.go index 8b059a5..1071d18 100644 --- a/internal/neofs/neofs.go +++ b/internal/neofs/neofs.go @@ -11,6 +11,7 @@ import ( "strconv" "time" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs" "github.com/nspcc-dev/neofs-s3-gw/authmate" @@ -136,6 +137,16 @@ func (x *NeoFS) CreateContainer(ctx context.Context, prm neofs.PrmContainerCreat cnrOptions = append(cnrOptions, container.WithAttribute(attr[0], attr[1])) } + // https://github.com/nspcc-dev/neofs-s3-gw/issues/435 + // environment without hh disabling feature will ignore this attribute + // environment with hh disabling feature will set disabling = true if network config says so + if hhDisabled, err := isHomomorphicHashDisabled(ctx, x.pool); err != nil { + return nil, err + } else if hhDisabled { + cnrOptions = append(cnrOptions, container.WithAttribute( + "__NEOFS__DISABLE_HOMOMORPHIC_HASHING", "true")) + } + cnr := container.New(cnrOptions...) cnr.SetSessionToken(prm.SessionToken) @@ -575,3 +586,23 @@ func (x *AuthmateNeoFS) CreateObject(ctx context.Context, prm tokens.PrmObjectCr Payload: bytes.NewReader(prm.Payload), }) } + +func isHomomorphicHashDisabled(ctx context.Context, p *pool.Pool) (res bool, err error) { + ni, err := p.NetworkInfo(ctx) + if err != nil { + return false, err + } + + var expectedParamKey = []byte("HomomorphicHashingDisabled") + + ni.NetworkConfig().IterateParameters(func(p *netmap.NetworkParameter) bool { + if bytes.Equal(p.Key(), expectedParamKey) { + arr := stackitem.NewByteArray(p.Value()) + res, err = arr.TryBool() + return true + } + return false + }) + + return res, nil +}