frostfs-api-go/container/grpc/attributes.go
Airat Arifullin 2511f4ca70
All checks were successful
Tests and linters / Tests (1.19) (pull_request) Successful in 1m39s
Tests and linters / Lint (pull_request) Successful in 1m46s
Tests and linters / Tests with -race (pull_request) Successful in 3m12s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m6s
[#40] types: Generate StableMarshaler/StableSize methods for protobufs
* Add plugin option for protogen in Makefile
* Fix the generator for the plugin in util/protogen
* Erase convertable types, move helpful methods to gRPC protobufs
* Erase helpers for convertations
* Generate StableMarshlal/StableSize for protobufs by the protoc plugin

Signed-off-by: Airat Arifullin a.arifullin@yadro.com
2023-07-10 15:29:21 +03:00

91 lines
3 KiB
Go

package container
// SysAttributePrefix is a prefix of key to system attribute.
const SysAttributePrefix = "__SYSTEM__"
const (
// SysAttributeName is a string of human-friendly container name registered as the domain in NNS contract.
SysAttributeName = SysAttributePrefix + "NAME"
// SysAttributeZone is a string of zone for container name.
SysAttributeZone = SysAttributePrefix + "ZONE"
// SysAttributeHomomorphicHashing is a container's homomorphic hashing state.
SysAttributeHomomorphicHashing = SysAttributePrefix + "DISABLE_HOMOMORPHIC_HASHING"
)
// SysAttributePrefixNeoFS is a prefix of key to system attribute.
// Deprecated: use SysAttributePrefix.
const SysAttributePrefixNeoFS = "__NEOFS__"
const (
// SysAttributeNameNeoFS is a string of human-friendly container name registered as the domain in NNS contract.
// Deprecated: use SysAttributeName.
SysAttributeNameNeoFS = SysAttributePrefixNeoFS + "NAME"
// SysAttributeZoneNeoFS is a string of zone for container name.
// Deprecated: use SysAttributeZone.
SysAttributeZoneNeoFS = SysAttributePrefixNeoFS + "ZONE"
// SysAttributeHomomorphicHashingNeoFS is a container's homomorphic hashing state.
// Deprecated: use SysAttributeHomomorphicHashing.
SysAttributeHomomorphicHashingNeoFS = SysAttributePrefixNeoFS + "DISABLE_HOMOMORPHIC_HASHING"
)
// SysAttributeZoneDefault is a default value for SysAttributeZone attribute.
const SysAttributeZoneDefault = "container"
const disabledHomomorphicHashingValue = "true"
// HomomorphicHashingState returns container's homomorphic
// hashing state:
// - true if hashing is enabled;
// - false if hashing is disabled.
//
// All container's attributes must be unique, otherwise behavior
// is undefined.
//
// See also SetHomomorphicHashingState.
func (c *Container) HomomorphicHashingState() bool {
for i := range c.Attributes {
if c.Attributes[i].GetKey() == SysAttributeHomomorphicHashing || c.Attributes[i].GetKey() == SysAttributeHomomorphicHashingNeoFS {
return c.Attributes[i].GetValue() != disabledHomomorphicHashingValue
}
}
return true
}
// SetHomomorphicHashingState sets homomorphic hashing state for
// container.
//
// All container's attributes must be unique, otherwise behavior
// is undefined.
//
// See also HomomorphicHashingState.
func (c *Container) SetHomomorphicHashingState(enable bool) {
attributes := c.GetAttributes()
for _, attr := range attributes {
if attr.GetKey() == SysAttributeHomomorphicHashing || attr.GetKey() == SysAttributeHomomorphicHashingNeoFS {
if enable {
// approach without allocation/waste
// coping works since the attributes
// order is not important
attr = attributes[len(attributes)-1]
c.SetAttributes(attributes[:len(attributes)-1])
} else {
attr.SetValue(disabledHomomorphicHashingValue)
}
return
}
}
if !enable {
attr := new(Container_Attribute)
attr.SetKey(SysAttributeHomomorphicHashing)
attr.SetValue(disabledHomomorphicHashingValue)
c.SetAttributes(append(c.Attributes, attr))
}
}