2022-04-22 13:30:20 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
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
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
log *zap.Logger
|
|
|
|
key *ecdsa.PrivateKey
|
2022-05-26 12:40:44 +00:00
|
|
|
rawPub []byte
|
2022-04-22 13:30:20 +00:00
|
|
|
nmSource netmap.Source
|
|
|
|
cnrSource container.Source
|
|
|
|
forest pilorama.Forest
|
2022-07-19 08:03:13 +00:00
|
|
|
// replication-related parameters
|
|
|
|
replicatorChannelCapacity int
|
|
|
|
replicatorWorkerCount int
|
|
|
|
containerCacheSize int
|
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.
|
|
|
|
func WithContainerSource(src container.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.cnrSource = src
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func WithLogger(log *zap.Logger) Option {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|