All checks were successful
Vulncheck / Vulncheck (push) Successful in 1m12s
Pre-commit hooks / Pre-commit (push) Successful in 1m41s
Build / Build Components (push) Successful in 1m54s
Tests and linters / Run gofumpt (push) Successful in 3m35s
Tests and linters / Lint (push) Successful in 4m5s
Tests and linters / Staticcheck (push) Successful in 4m9s
Tests and linters / gopls check (push) Successful in 4m29s
Tests and linters / Tests (push) Successful in 4m52s
OCI image / Build container images (push) Successful in 5m9s
Tests and linters / Tests with -race (push) Successful in 6m14s
Applicable for both cases: when node uses local cache for netmap and when it disabled. Change-Id: I3050f537e20312a4b39e944aca763b77bd1e74c4 Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
173 lines
5 KiB
Go
173 lines
5 KiB
Go
package morphconfig
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
)
|
|
|
|
const (
|
|
subsection = "morph"
|
|
|
|
// DialTimeoutDefault is a default dial timeout of morph chain client connection.
|
|
DialTimeoutDefault = 5 * time.Second
|
|
|
|
// PriorityDefault is a default endpoint priority for the morph client.
|
|
PriorityDefault = 1
|
|
|
|
// CacheTTLDefault is a default value for cached values TTL.
|
|
// It is 0, because actual default depends on block time.
|
|
CacheTTLDefault = time.Duration(0)
|
|
|
|
// SwitchIntervalDefault is a default Neo RPCs switch interval.
|
|
SwitchIntervalDefault = 2 * time.Minute
|
|
|
|
// APEChainCacheSizeDefault is a default value of APE chain cache.
|
|
APEChainCacheSizeDefault = 10_000
|
|
|
|
// FrostfsIDCacheSizeDefault is a default value of APE chain cache.
|
|
FrostfsIDCacheSizeDefault = 10_000
|
|
|
|
// ContainerCacheSizeDefault represents the default size for the container cache.
|
|
ContainerCacheSizeDefault = 100
|
|
|
|
// PollCandidatesTimeoutDefault is a default poll timeout for netmap candidates.
|
|
PollCandidatesTimeoutDefault = 20 * time.Second
|
|
)
|
|
|
|
var errNoMorphEndpoints = errors.New("no morph chain RPC endpoints, see `morph.rpc_endpoint` section")
|
|
|
|
// RPCEndpoint returns list of the values of "rpc_endpoint" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Throws panic if list is empty.
|
|
func RPCEndpoint(c *config.Config) []client.Endpoint {
|
|
var es []client.Endpoint
|
|
|
|
sub := c.Sub(subsection).Sub("rpc_endpoint")
|
|
for i := 0; ; i++ {
|
|
s := sub.Sub(strconv.FormatInt(int64(i), 10))
|
|
addr := config.StringSafe(s, "address")
|
|
if addr == "" {
|
|
break
|
|
}
|
|
|
|
priority := int(config.IntSafe(s, "priority"))
|
|
if priority <= 0 {
|
|
priority = PriorityDefault
|
|
}
|
|
|
|
var mtlsConfig *client.MTLSConfig
|
|
rootCAs := config.StringSliceSafe(s, "trusted_ca_list")
|
|
if len(rootCAs) != 0 {
|
|
mtlsConfig = &client.MTLSConfig{
|
|
TrustedCAList: rootCAs,
|
|
KeyFile: config.StringSafe(s, "key"),
|
|
CertFile: config.StringSafe(s, "certificate"),
|
|
}
|
|
}
|
|
|
|
es = append(es, client.Endpoint{
|
|
Address: addr,
|
|
Priority: priority,
|
|
MTLSConfig: mtlsConfig,
|
|
})
|
|
}
|
|
|
|
if len(es) == 0 {
|
|
panic(errNoMorphEndpoints)
|
|
}
|
|
return es
|
|
}
|
|
|
|
// DialTimeout returns the value of "dial_timeout" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Returns DialTimeoutDefault if the value is not positive duration.
|
|
func DialTimeout(c *config.Config) time.Duration {
|
|
v := config.DurationSafe(c.Sub(subsection), "dial_timeout")
|
|
if v > 0 {
|
|
return v
|
|
}
|
|
|
|
return DialTimeoutDefault
|
|
}
|
|
|
|
// CacheTTL returns the value of "cache_ttl" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Returns CacheTTLDefault if value is zero or invalid. Supports negative durations.
|
|
func CacheTTL(c *config.Config) time.Duration {
|
|
res := config.DurationSafe(c.Sub(subsection), "cache_ttl")
|
|
if res != 0 {
|
|
return res
|
|
}
|
|
|
|
return CacheTTLDefault
|
|
}
|
|
|
|
// ContainerCacheSize returns the value of "container_cache_size" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Returns 0 if the value is not positive integer.
|
|
// Returns ContainerCacheSizeDefault if the value is missing.
|
|
func ContainerCacheSize(c *config.Config) uint32 {
|
|
if c.Sub(subsection).Value("container_cache_size") == nil {
|
|
return ContainerCacheSizeDefault
|
|
}
|
|
return config.Uint32Safe(c.Sub(subsection), "container_cache_size")
|
|
}
|
|
|
|
// SwitchInterval returns the value of "switch_interval" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Returns SwitchIntervalDefault if value is not positive duration.
|
|
func SwitchInterval(c *config.Config) time.Duration {
|
|
res := config.DurationSafe(c.Sub(subsection), "switch_interval")
|
|
if res != 0 {
|
|
return res
|
|
}
|
|
|
|
return SwitchIntervalDefault
|
|
}
|
|
|
|
// APEChainCacheSize returns the value of "ape_chain_cache_size" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Returns 0 if the value is not positive integer.
|
|
// Returns APEChainCacheSizeDefault if the value is missing.
|
|
func APEChainCacheSize(c *config.Config) uint32 {
|
|
if c.Sub(subsection).Value("ape_chain_cache_size") == nil {
|
|
return APEChainCacheSizeDefault
|
|
}
|
|
return config.Uint32Safe(c.Sub(subsection), "ape_chain_cache_size")
|
|
}
|
|
|
|
// FrostfsIDCacheSize returns the value of "frostfsid_cache_size" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Returns 0 if the value is not positive integer.
|
|
// Returns FrostfsIDCacheSizeDefault if the value is missing.
|
|
func FrostfsIDCacheSize(c *config.Config) uint32 {
|
|
if c.Sub(subsection).Value("frostfsid_cache_size") == nil {
|
|
return FrostfsIDCacheSizeDefault
|
|
}
|
|
return config.Uint32Safe(c.Sub(subsection), "frostfsid_cache_size")
|
|
}
|
|
|
|
// NetmapCandidatesPollInterval returns the value of "netmap.candidates.poll_interval" config parameter
|
|
// from "morph" section.
|
|
//
|
|
// Returns PollCandidatesTimeoutDefault if the value is not positive duration.
|
|
func NetmapCandidatesPollInterval(c *config.Config) time.Duration {
|
|
v := config.DurationSafe(c.Sub(subsection).
|
|
Sub("netmap").Sub("candidates"), "poll_interval")
|
|
if v > 0 {
|
|
return v
|
|
}
|
|
|
|
return PollCandidatesTimeoutDefault
|
|
}
|