2022-04-22 13:30:20 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2022-12-14 16:28:44 +00:00
|
|
|
"time"
|
2022-04-22 13:30:20 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
2024-05-02 17:26:06 +00:00
|
|
|
frostfsidcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/frostfsid"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2024-04-11 15:10:33 +00:00
|
|
|
policyengine "git.frostfs.info/TrueCloudLab/policy-engine/pkg/engine"
|
2022-05-26 12:40:44 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2022-04-22 13:30:20 +00:00
|
|
|
)
|
|
|
|
|
2022-10-18 21:33:45 +00:00
|
|
|
type ContainerSource interface {
|
|
|
|
container.Source
|
2023-08-18 14:20:30 +00:00
|
|
|
|
|
|
|
DeletionInfo(cid.ID) (*container.DelInfo, error)
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// List must return list of all the containers in the FrostFS network
|
2022-10-18 21:33:45 +00:00
|
|
|
// at the moment of a call and any error that does not allow fetching
|
|
|
|
// container information.
|
|
|
|
List() ([]cid.ID, error)
|
|
|
|
}
|
|
|
|
|
2022-04-22 13:30:20 +00:00
|
|
|
type cfg struct {
|
2024-04-15 14:04:34 +00:00
|
|
|
log *logger.Logger
|
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
rawPub []byte
|
2024-05-29 08:18:31 +00:00
|
|
|
state netmap.State
|
2024-04-15 14:04:34 +00:00
|
|
|
nmSource netmap.Source
|
|
|
|
cnrSource ContainerSource
|
2024-05-02 17:26:06 +00:00
|
|
|
frostfsidSubjectProvider frostfsidcore.SubjectProvider
|
2024-04-15 14:04:34 +00:00
|
|
|
eaclSource container.EACLSource
|
|
|
|
forest pilorama.Forest
|
2022-07-19 08:03:13 +00:00
|
|
|
// replication-related parameters
|
|
|
|
replicatorChannelCapacity int
|
|
|
|
replicatorWorkerCount int
|
2022-12-14 16:28:44 +00:00
|
|
|
replicatorTimeout time.Duration
|
2022-07-19 08:03:13 +00:00
|
|
|
containerCacheSize int
|
2023-06-23 08:25:08 +00:00
|
|
|
authorizedKeys [][]byte
|
2023-05-24 07:01:50 +00:00
|
|
|
|
2024-07-01 15:42:15 +00:00
|
|
|
localOverrideStorage policyengine.LocalOverrideStorage
|
|
|
|
morphChainStorage policyengine.MorphRuleChainStorageReader
|
2024-04-11 15:10:33 +00:00
|
|
|
|
2023-05-24 07:01:50 +00:00
|
|
|
metrics MetricsRegister
|
2022-04-22 13:30:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents configuration option for a tree service.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
// WithContainerSource sets a container source for a tree service.
|
|
|
|
// This option is required.
|
2022-10-18 21:33:45 +00:00
|
|
|
func WithContainerSource(src ContainerSource) Option {
|
2022-04-22 13:30:20 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.cnrSource = src
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 17:26:06 +00:00
|
|
|
func WithFrostfsidSubjectProvider(provider frostfsidcore.SubjectProvider) Option {
|
2024-04-15 14:04:34 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.frostfsidSubjectProvider = provider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-08 12:44:27 +00:00
|
|
|
// WithEACLSource sets a eACL table source for a tree service.
|
|
|
|
// This option is required.
|
|
|
|
func WithEACLSource(src container.EACLSource) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.eaclSource = src
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 13:30:20 +00:00
|
|
|
// WithNetmapSource sets a netmap source for a tree service.
|
|
|
|
// This option is required.
|
|
|
|
func WithNetmapSource(src netmap.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.nmSource = src
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithPrivateKey sets a netmap source for a tree service.
|
|
|
|
// This option is required.
|
|
|
|
func WithPrivateKey(key *ecdsa.PrivateKey) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.key = key
|
2022-05-26 12:40:44 +00:00
|
|
|
c.rawPub = (*keys.PublicKey)(&key.PublicKey).Bytes()
|
2022-04-22 13:30:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLogger sets logger for a tree service.
|
2022-09-28 07:41:01 +00:00
|
|
|
func WithLogger(log *logger.Logger) Option {
|
2022-04-22 13:30:20 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = log
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithStorage sets tree storage for a service.
|
|
|
|
func WithStorage(s pilorama.Forest) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.forest = s
|
|
|
|
}
|
|
|
|
}
|
2022-07-19 08:03:13 +00:00
|
|
|
|
|
|
|
func WithReplicationChannelCapacity(n int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
if n > 0 {
|
|
|
|
c.replicatorChannelCapacity = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithReplicationWorkerCount(n int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
if n > 0 {
|
|
|
|
c.replicatorWorkerCount = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithContainerCacheSize(n int) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
if n > 0 {
|
|
|
|
c.containerCacheSize = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-14 16:28:44 +00:00
|
|
|
|
|
|
|
func WithReplicationTimeout(t time.Duration) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
if t > 0 {
|
|
|
|
c.replicatorTimeout = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-24 07:01:50 +00:00
|
|
|
|
|
|
|
func WithMetrics(v MetricsRegister) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.metrics = v
|
|
|
|
}
|
|
|
|
}
|
2023-06-23 08:25:08 +00:00
|
|
|
|
|
|
|
// WithAuthorizedKeys returns option to add list of public
|
|
|
|
// keys that have rights to use Tree service.
|
|
|
|
func WithAuthorizedKeys(keys keys.PublicKeys) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.authorizedKeys = nil
|
|
|
|
for _, key := range keys {
|
|
|
|
c.authorizedKeys = append(c.authorizedKeys, key.Bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-11 15:10:33 +00:00
|
|
|
|
2024-07-01 15:42:15 +00:00
|
|
|
func WithAPELocalOverrideStorage(localOverrideStorage policyengine.LocalOverrideStorage) Option {
|
2024-04-11 15:10:33 +00:00
|
|
|
return func(c *cfg) {
|
2024-07-01 15:42:15 +00:00
|
|
|
c.localOverrideStorage = localOverrideStorage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAPEMorphRuleStorage(morphRuleStorage policyengine.MorphRuleChainStorageReader) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.morphChainStorage = morphRuleStorage
|
2024-04-11 15:10:33 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-29 08:18:31 +00:00
|
|
|
|
|
|
|
func WithNetmapState(state netmap.State) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.state = state
|
|
|
|
}
|
|
|
|
}
|