From 9996b3be01b5c0ab2ce4b05f4a74d42aada192d1 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 26 Apr 2022 18:01:40 +0300 Subject: [PATCH] [#240] container: Support disabling homomorphic hashing Signed-off-by: Pavel Karpy --- container/network.go | 20 ++++++++++++++++++++ container/network_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 container/network.go create mode 100644 container/network_test.go diff --git a/container/network.go b/container/network.go new file mode 100644 index 0000000..68d1b32 --- /dev/null +++ b/container/network.go @@ -0,0 +1,20 @@ +package container + +import ( + "github.com/nspcc-dev/neofs-sdk-go/netmap" +) + +// ApplyNetworkConfig applies network configuration to the +// container. Changes the container if it does not satisfy +// network configuration. +func ApplyNetworkConfig(cnr *Container, cfg netmap.NetworkInfo) { + if cfg.HomomorphicHashingDisabled() { + DisableHomomorphicHashing(cnr) + } +} + +// AssertNetworkConfig checks if a container matches passed +// network configuration. +func AssertNetworkConfig(cnr Container, cfg netmap.NetworkInfo) bool { + return IsHomomorphicHashingDisabled(cnr) == cfg.HomomorphicHashingDisabled() +} diff --git a/container/network_test.go b/container/network_test.go new file mode 100644 index 0000000..6391851 --- /dev/null +++ b/container/network_test.go @@ -0,0 +1,33 @@ +package container_test + +import ( + "testing" + + "github.com/nspcc-dev/neofs-sdk-go/container" + containertest "github.com/nspcc-dev/neofs-sdk-go/container/test" + netmaptest "github.com/nspcc-dev/neofs-sdk-go/netmap/test" + "github.com/stretchr/testify/require" +) + +func TestContainer_NetworkConfig(t *testing.T) { + c := containertest.Container() + nc := netmaptest.NetworkInfo() + + t.Run("default", func(t *testing.T) { + require.False(t, container.IsHomomorphicHashingDisabled(c)) + + res := container.AssertNetworkConfig(c, nc) + + require.True(t, res) + }) + + nc.DisableHomomorphicHashing() + + t.Run("apply", func(t *testing.T) { + require.False(t, container.IsHomomorphicHashingDisabled(c)) + + container.ApplyNetworkConfig(&c, nc) + + require.True(t, container.IsHomomorphicHashingDisabled(c)) + }) +}