2020-08-21 15:01:59 +00:00
|
|
|
package main
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2020-08-22 14:17:03 +00:00
|
|
|
"crypto/ecdsa"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-08-24 09:40:32 +00:00
|
|
|
"net"
|
2020-10-29 17:17:42 +00:00
|
|
|
"os"
|
2020-11-19 10:58:27 +00:00
|
|
|
"path"
|
|
|
|
"strconv"
|
2020-09-16 07:45:08 +00:00
|
|
|
"strings"
|
2020-08-22 11:03:45 +00:00
|
|
|
"sync"
|
2020-10-21 09:26:16 +00:00
|
|
|
"time"
|
2020-08-22 14:17:03 +00:00
|
|
|
|
2020-08-22 15:20:47 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2020-10-08 13:16:00 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
2020-11-16 10:26:35 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
2021-01-25 08:23:06 +00:00
|
|
|
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
2020-08-22 14:17:03 +00:00
|
|
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
2020-09-16 07:45:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/misc"
|
2020-09-23 13:55:46 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
|
|
|
netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2020-12-08 07:51:34 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2020-11-19 10:58:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2021-04-06 10:56:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
|
2021-03-16 08:14:56 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/metrics"
|
2020-08-22 15:20:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2021-04-29 05:32:24 +00:00
|
|
|
cntwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
2020-09-24 07:46:47 +00:00
|
|
|
nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
2020-10-21 09:26:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
2021-02-17 12:19:54 +00:00
|
|
|
netmap2 "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
2021-04-15 14:57:29 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
|
2020-09-23 13:31:51 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2021-01-13 13:46:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
2021-03-23 18:54:00 +00:00
|
|
|
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
|
|
|
|
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
|
2020-08-24 15:51:42 +00:00
|
|
|
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
|
2020-10-22 11:07:06 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/util/response"
|
2021-02-16 11:40:06 +00:00
|
|
|
util2 "github.com/nspcc-dev/neofs-node/pkg/util"
|
2020-09-25 12:34:17 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2020-11-09 15:40:06 +00:00
|
|
|
"github.com/panjf2000/ants/v2"
|
2020-09-16 07:45:08 +00:00
|
|
|
"github.com/spf13/viper"
|
2021-01-18 13:04:13 +00:00
|
|
|
"go.etcd.io/bbolt"
|
2021-01-13 13:36:41 +00:00
|
|
|
"go.uber.org/atomic"
|
2020-09-25 12:34:17 +00:00
|
|
|
"go.uber.org/zap"
|
2020-08-22 15:20:47 +00:00
|
|
|
"google.golang.org/grpc"
|
2020-08-22 11:03:45 +00:00
|
|
|
)
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
const (
|
2020-09-25 12:34:17 +00:00
|
|
|
// logger keys
|
2021-05-11 08:17:45 +00:00
|
|
|
cfgLogLevel = "logger.level"
|
2020-09-25 12:34:17 +00:00
|
|
|
|
2020-10-02 13:18:38 +00:00
|
|
|
// pprof keys
|
2021-05-11 22:59:05 +00:00
|
|
|
cfgProfilerAddr = "profiler.address"
|
|
|
|
cfgProfilerShutdownTimeout = "profiler.shutdown_timeout"
|
2020-10-02 13:18:38 +00:00
|
|
|
|
2021-03-15 13:11:40 +00:00
|
|
|
// metrics keys
|
2021-05-11 22:59:05 +00:00
|
|
|
cfgMetricsAddr = "metrics.address"
|
|
|
|
cfgMetricsShutdownTimeout = "metrics.shutdown_timeout"
|
2021-03-15 13:11:40 +00:00
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
// config keys for cfgNodeInfo
|
2020-09-22 11:02:32 +00:00
|
|
|
cfgNodeKey = "node.key"
|
|
|
|
cfgBootstrapAddress = "node.address"
|
|
|
|
cfgNodeAttributePrefix = "node.attribute"
|
2021-05-12 09:29:19 +00:00
|
|
|
cfgNodeRelay = "node.relay"
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
// config keys for cfgGRPC
|
2021-05-12 08:00:46 +00:00
|
|
|
cfgListenAddress = "grpc.endpoint"
|
2021-05-14 09:11:49 +00:00
|
|
|
cfgTLSEnabled = "grpc.tls.enabled"
|
|
|
|
cfgTLSCertFile = "grpc.tls.certificate"
|
|
|
|
cfgTLSKeyFile = "grpc.tls.key"
|
2021-05-12 08:04:51 +00:00
|
|
|
|
|
|
|
// config keys for API client cache
|
|
|
|
cfgAPIClientDialTimeout = "apiclient.dial_timeout"
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
// config keys for cfgMorph
|
2021-01-12 14:22:04 +00:00
|
|
|
cfgMorphRPCAddress = "morph.rpc_endpoint"
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2021-01-12 14:22:04 +00:00
|
|
|
cfgMorphNotifyRPCAddress = "morph.notification_endpoint"
|
|
|
|
cfgMorphNotifyDialTimeout = "morph.dial_timeout"
|
2020-10-21 09:26:16 +00:00
|
|
|
|
2021-05-11 10:24:13 +00:00
|
|
|
cfgMainChainRPCAddress = "mainchain.rpc_endpoint"
|
|
|
|
cfgMainChainDialTimeout = "mainchain.dial_timeout"
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
// config keys for cfgAccounting
|
|
|
|
cfgAccountingContract = "accounting.scripthash"
|
|
|
|
|
|
|
|
// config keys for cfgNetmap
|
2021-05-12 08:28:23 +00:00
|
|
|
cfgNetmapContract = "netmap.scripthash"
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
// config keys for cfgContainer
|
2021-05-12 08:28:23 +00:00
|
|
|
cfgContainerContract = "container.scripthash"
|
2020-09-29 12:38:44 +00:00
|
|
|
|
2021-04-21 05:29:35 +00:00
|
|
|
// config keys for cfgReputation
|
2021-05-12 08:28:23 +00:00
|
|
|
cfgReputationContract = "reputation.scripthash"
|
2021-04-21 05:29:35 +00:00
|
|
|
|
2020-10-21 09:28:42 +00:00
|
|
|
cfgPolicerHeadTimeout = "policer.head_timeout"
|
2020-10-21 11:51:20 +00:00
|
|
|
|
2021-03-13 15:22:24 +00:00
|
|
|
cfgReplicatorPutTimeout = "replicator.put_timeout"
|
2020-10-30 12:57:49 +00:00
|
|
|
|
2021-05-13 09:58:22 +00:00
|
|
|
cfgObjectPutPoolSize = "object.put.pool_size"
|
2020-09-16 07:45:08 +00:00
|
|
|
)
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
const (
|
|
|
|
cfgLocalStorageSection = "storage"
|
|
|
|
cfgStorageShardSection = "shard"
|
|
|
|
|
2020-11-30 17:03:15 +00:00
|
|
|
cfgShardUseWriteCache = "use_write_cache"
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
cfgBlobStorSection = "blobstor"
|
2020-12-01 09:26:19 +00:00
|
|
|
cfgWriteCacheSection = "writecache"
|
2021-04-06 10:56:06 +00:00
|
|
|
cfgWriteCacheMemSize = "mem_size"
|
|
|
|
cfgWriteCacheDBSize = "db_size"
|
|
|
|
cfgWriteCacheSmallSize = "small_size"
|
|
|
|
cfgWriteCacheMaxSize = "max_size"
|
|
|
|
cfgWriteCacheWrkCount = "workers_count"
|
2020-11-19 10:58:27 +00:00
|
|
|
cfgBlobStorCompress = "compress"
|
|
|
|
cfgBlobStorShallowDepth = "shallow_depth"
|
|
|
|
cfgBlobStorTreePath = "path"
|
|
|
|
cfgBlobStorTreePerm = "perm"
|
2020-11-26 07:47:20 +00:00
|
|
|
cfgBlobStorSmallSzLimit = "small_size_limit"
|
2020-11-19 10:58:27 +00:00
|
|
|
|
2020-11-30 15:35:37 +00:00
|
|
|
cfgBlobStorBlzSection = "blobovnicza"
|
|
|
|
cfgBlzSize = "size"
|
|
|
|
cfgBlzShallowDepth = "shallow_depth"
|
|
|
|
cfgBlzShallowWidth = "shallow_width"
|
|
|
|
cfgBlzOpenedCacheSize = "opened_cache_size"
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
cfgMetaBaseSection = "metabase"
|
|
|
|
cfgMetaBasePath = "path"
|
|
|
|
cfgMetaBasePerm = "perm"
|
2021-02-16 11:40:06 +00:00
|
|
|
|
|
|
|
cfgGCSection = "gc"
|
|
|
|
cfgGCRemoverBatchSize = "remover_batch_size"
|
|
|
|
cfgGCRemoverSleepInt = "remover_sleep_interval"
|
2020-11-19 10:58:27 +00:00
|
|
|
)
|
|
|
|
|
2020-10-02 08:01:54 +00:00
|
|
|
const (
|
|
|
|
addressSize = 72 // 32 bytes oid, 32 bytes cid, 8 bytes protobuf encoding
|
|
|
|
)
|
|
|
|
|
2021-05-12 08:00:46 +00:00
|
|
|
const maxMsgSize = 4 << 20 // transport msg limit 4 MiB
|
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
// capacity of the pools of the morph notification handlers
|
|
|
|
// for each contract listener.
|
|
|
|
const notificationHandlerPoolSize = 10
|
|
|
|
|
2020-08-21 15:01:59 +00:00
|
|
|
type cfg struct {
|
2020-08-22 11:03:45 +00:00
|
|
|
ctx context.Context
|
|
|
|
|
2021-01-12 11:05:08 +00:00
|
|
|
ctxCancel func()
|
|
|
|
|
|
|
|
internalErr chan error // channel for internal application errors at runtime
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
viper *viper.Viper
|
|
|
|
|
2020-09-25 12:34:17 +00:00
|
|
|
log *zap.Logger
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
wg *sync.WaitGroup
|
|
|
|
|
2020-08-22 14:17:03 +00:00
|
|
|
key *ecdsa.PrivateKey
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-10-08 13:16:00 +00:00
|
|
|
apiVersion *pkg.Version
|
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
cfgGRPC cfgGRPC
|
|
|
|
|
|
|
|
cfgMorph cfgMorph
|
|
|
|
|
|
|
|
cfgAccounting cfgAccounting
|
2020-08-24 14:07:08 +00:00
|
|
|
|
|
|
|
cfgContainer cfgContainer
|
2020-08-24 15:51:42 +00:00
|
|
|
|
2020-08-31 15:19:21 +00:00
|
|
|
cfgNetmap cfgNetmap
|
|
|
|
|
2020-08-24 15:51:42 +00:00
|
|
|
privateTokenStore *tokenStorage.TokenStore
|
2020-08-31 15:19:21 +00:00
|
|
|
|
|
|
|
cfgNodeInfo cfgNodeInfo
|
2020-09-23 13:31:51 +00:00
|
|
|
|
|
|
|
localAddr *network.Address
|
2020-09-23 13:55:46 +00:00
|
|
|
|
|
|
|
cfgObject cfgObject
|
2020-10-02 13:18:38 +00:00
|
|
|
|
2021-03-16 08:14:56 +00:00
|
|
|
metricsCollector *metrics.StorageMetrics
|
2021-03-15 13:11:40 +00:00
|
|
|
|
2020-10-03 09:57:02 +00:00
|
|
|
workers []worker
|
2020-10-22 11:07:06 +00:00
|
|
|
|
|
|
|
respSvc *response.Service
|
2021-01-13 12:51:05 +00:00
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
cfgControlService cfgControlService
|
2021-01-13 13:36:41 +00:00
|
|
|
|
2021-01-15 10:23:46 +00:00
|
|
|
netStatus *atomic.Int32
|
|
|
|
|
2021-01-13 13:36:41 +00:00
|
|
|
healthStatus *atomic.Int32
|
2021-01-18 08:56:14 +00:00
|
|
|
|
|
|
|
closers []func()
|
2021-03-23 18:54:00 +00:00
|
|
|
|
|
|
|
cfgReputation cfgReputation
|
2021-05-11 10:24:13 +00:00
|
|
|
|
|
|
|
mainChainClient *client.Client
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgGRPC struct {
|
|
|
|
listener net.Listener
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
server *grpc.Server
|
2020-09-30 08:39:45 +00:00
|
|
|
|
|
|
|
maxChunkSize uint64
|
|
|
|
|
|
|
|
maxAddrAmount uint64
|
2021-05-14 09:11:49 +00:00
|
|
|
|
|
|
|
tlsEnabled bool
|
|
|
|
tlsCertFile string
|
|
|
|
tlsKeyFile string
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgMorph struct {
|
|
|
|
client *client.Client
|
2021-04-15 14:57:29 +00:00
|
|
|
|
|
|
|
blockTimers []*timer.BlockTimer // all combined timers
|
|
|
|
eigenTrustTimer *timer.BlockTimer // timer for EigenTrust iterations
|
2020-08-24 09:40:32 +00:00
|
|
|
}
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
type cfgAccounting struct {
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash util.Uint160
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 14:07:08 +00:00
|
|
|
type cfgContainer struct {
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash util.Uint160
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2021-02-01 12:33:58 +00:00
|
|
|
parsers map[event.Type]event.Parser
|
|
|
|
subscribers map[event.Type][]event.Handler
|
2021-04-13 12:15:36 +00:00
|
|
|
workerPool util2.WorkerPool // pool for asynchronous handlers
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 15:19:21 +00:00
|
|
|
type cfgNetmap struct {
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash util.Uint160
|
2020-09-24 07:46:47 +00:00
|
|
|
wrapper *nmwrapper.Wrapper
|
2020-08-31 15:19:21 +00:00
|
|
|
|
2020-10-21 09:26:16 +00:00
|
|
|
parsers map[event.Type]event.Parser
|
|
|
|
|
|
|
|
subscribers map[event.Type][]event.Handler
|
2021-04-13 12:15:36 +00:00
|
|
|
workerPool util2.WorkerPool // pool for asynchronous handlers
|
2020-10-21 15:12:31 +00:00
|
|
|
|
|
|
|
state *networkState
|
2020-10-30 12:57:49 +00:00
|
|
|
|
|
|
|
reBootstrapEnabled bool
|
2021-04-21 13:26:04 +00:00
|
|
|
reBoostrapTurnedOff *atomic.Bool // managed by control service in runtime
|
2021-05-12 09:27:12 +00:00
|
|
|
startEpoch uint64 // epoch number when application is started
|
2020-08-31 15:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type BootstrapType uint32
|
|
|
|
|
|
|
|
type cfgNodeInfo struct {
|
2020-10-08 13:17:50 +00:00
|
|
|
// values from config
|
2020-09-22 11:02:32 +00:00
|
|
|
bootType BootstrapType
|
2020-11-16 10:26:35 +00:00
|
|
|
attributes []*netmap.NodeAttribute
|
2020-10-08 13:17:50 +00:00
|
|
|
|
|
|
|
// values at runtime
|
2021-01-25 08:23:06 +00:00
|
|
|
infoMtx sync.RWMutex
|
|
|
|
info netmap.NodeInfo
|
2020-08-31 15:19:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 13:55:46 +00:00
|
|
|
type cfgObject struct {
|
|
|
|
netMapStorage netmapCore.Source
|
|
|
|
|
|
|
|
cnrStorage container.Source
|
2020-09-29 12:38:44 +00:00
|
|
|
|
2021-04-29 05:32:24 +00:00
|
|
|
cnrClient *cntwrapper.Wrapper
|
2020-11-09 15:40:06 +00:00
|
|
|
|
|
|
|
pool cfgObjectRoutines
|
2020-11-19 10:58:27 +00:00
|
|
|
|
|
|
|
cfgLocalStorage cfgLocalStorage
|
|
|
|
}
|
|
|
|
|
|
|
|
type cfgLocalStorage struct {
|
|
|
|
localStorage *engine.StorageEngine
|
|
|
|
|
|
|
|
shardOpts [][]shard.Option
|
2020-11-09 15:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type cfgObjectRoutines struct {
|
2021-05-13 09:58:22 +00:00
|
|
|
put *ants.Pool
|
2020-09-23 13:55:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
type cfgControlService struct {
|
2021-01-13 12:51:05 +00:00
|
|
|
server *grpc.Server
|
|
|
|
}
|
|
|
|
|
2021-03-23 18:54:00 +00:00
|
|
|
type cfgReputation struct {
|
2021-04-21 05:29:35 +00:00
|
|
|
workerPool util2.WorkerPool // pool for EigenTrust algorithm's iterations
|
|
|
|
|
2021-03-23 18:54:00 +00:00
|
|
|
localTrustStorage *truststorage.Storage
|
|
|
|
|
|
|
|
localTrustCtrl *trustcontroller.Controller
|
2021-04-29 05:32:24 +00:00
|
|
|
|
|
|
|
scriptHash util.Uint160
|
2021-03-23 18:54:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 15:19:21 +00:00
|
|
|
const (
|
|
|
|
_ BootstrapType = iota
|
|
|
|
StorageNode
|
|
|
|
RelayNode
|
|
|
|
)
|
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
func initCfg(path string) *cfg {
|
|
|
|
viperCfg := initViper(path)
|
|
|
|
|
|
|
|
key, err := crypto.LoadPrivateKey(viperCfg.GetString(cfgNodeKey))
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
u160Accounting, err := util.Uint160DecodeStringLE(
|
|
|
|
viperCfg.GetString(cfgAccountingContract))
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
u160Netmap, err := util.Uint160DecodeStringLE(
|
|
|
|
viperCfg.GetString(cfgNetmapContract))
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
u160Container, err := util.Uint160DecodeStringLE(
|
|
|
|
viperCfg.GetString(cfgContainerContract))
|
2020-08-22 14:17:03 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-04-29 05:32:24 +00:00
|
|
|
u160Reputation, err := util.Uint160DecodeStringLE(
|
|
|
|
viperCfg.GetString(cfgReputationContract))
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-11 08:54:59 +00:00
|
|
|
var logPrm logger.Prm
|
|
|
|
|
|
|
|
err = logPrm.SetLevelString(
|
|
|
|
viperCfg.GetString(cfgLogLevel),
|
|
|
|
)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
log, err := logger.NewLogger(logPrm)
|
2020-09-25 12:34:17 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2020-09-24 08:27:14 +00:00
|
|
|
netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress))
|
2020-09-23 13:31:51 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-12 08:00:46 +00:00
|
|
|
maxChunkSize := uint64(maxMsgSize) * 3 / 4 // 25% to meta, 75% to payload
|
|
|
|
maxAddrAmount := uint64(maxChunkSize) / addressSize // each address is about 72 bytes
|
2020-10-02 08:01:54 +00:00
|
|
|
|
2021-05-14 09:11:49 +00:00
|
|
|
var (
|
|
|
|
tlsEnabled bool
|
|
|
|
tlsCertFile string
|
|
|
|
tlsKeyFile string
|
|
|
|
)
|
|
|
|
|
|
|
|
if viperCfg.GetBool(cfgTLSEnabled) {
|
|
|
|
tlsEnabled = true
|
|
|
|
tlsCertFile = viperCfg.GetString(cfgTLSCertFile)
|
|
|
|
tlsKeyFile = viperCfg.GetString(cfgTLSKeyFile)
|
|
|
|
}
|
|
|
|
|
2020-10-22 11:24:08 +00:00
|
|
|
state := newNetworkState()
|
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
containerWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
|
2021-04-13 12:15:36 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
netmapWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
|
2021-04-13 12:15:36 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-12 08:28:23 +00:00
|
|
|
reputationWorkerPool, err := ants.NewPool(notificationHandlerPoolSize)
|
2021-04-21 05:29:35 +00:00
|
|
|
fatalOnErr(err)
|
|
|
|
|
2021-05-12 09:29:19 +00:00
|
|
|
relayOnly := viperCfg.GetBool(cfgNodeRelay)
|
2021-04-27 11:54:02 +00:00
|
|
|
|
2020-09-24 12:32:30 +00:00
|
|
|
c := &cfg{
|
2021-01-12 11:05:08 +00:00
|
|
|
ctx: context.Background(),
|
|
|
|
internalErr: make(chan error),
|
|
|
|
viper: viperCfg,
|
|
|
|
log: log,
|
|
|
|
wg: new(sync.WaitGroup),
|
|
|
|
key: key,
|
|
|
|
apiVersion: pkg.SDKVersion(),
|
2020-08-24 09:40:32 +00:00
|
|
|
cfgAccounting: cfgAccounting{
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash: u160Accounting,
|
2020-08-22 15:20:47 +00:00
|
|
|
},
|
2020-08-24 14:07:08 +00:00
|
|
|
cfgContainer: cfgContainer{
|
2020-09-16 07:45:08 +00:00
|
|
|
scriptHash: u160Container,
|
2021-04-13 12:15:36 +00:00
|
|
|
workerPool: containerWorkerPool,
|
2020-08-24 14:07:08 +00:00
|
|
|
},
|
2020-08-31 15:19:21 +00:00
|
|
|
cfgNetmap: cfgNetmap{
|
2020-10-30 12:57:49 +00:00
|
|
|
scriptHash: u160Netmap,
|
|
|
|
state: state,
|
2021-04-13 12:15:36 +00:00
|
|
|
workerPool: netmapWorkerPool,
|
2021-05-12 09:27:12 +00:00
|
|
|
reBootstrapEnabled: !relayOnly,
|
2021-04-27 11:54:02 +00:00
|
|
|
reBoostrapTurnedOff: atomic.NewBool(relayOnly),
|
2020-08-31 15:19:21 +00:00
|
|
|
},
|
|
|
|
cfgNodeInfo: cfgNodeInfo{
|
2020-09-22 11:02:32 +00:00
|
|
|
bootType: StorageNode,
|
2020-09-22 12:59:09 +00:00
|
|
|
attributes: parseAttributes(viperCfg),
|
2020-08-31 15:19:21 +00:00
|
|
|
},
|
2020-09-30 08:39:45 +00:00
|
|
|
cfgGRPC: cfgGRPC{
|
2021-05-12 08:00:46 +00:00
|
|
|
maxChunkSize: maxChunkSize,
|
|
|
|
maxAddrAmount: maxAddrAmount,
|
2021-05-14 09:11:49 +00:00
|
|
|
tlsEnabled: tlsEnabled,
|
|
|
|
tlsCertFile: tlsCertFile,
|
|
|
|
tlsKeyFile: tlsKeyFile,
|
2020-09-30 08:39:45 +00:00
|
|
|
},
|
2020-09-23 13:31:51 +00:00
|
|
|
localAddr: netAddr,
|
2020-10-22 11:24:08 +00:00
|
|
|
respSvc: response.NewService(
|
|
|
|
response.WithNetworkState(state),
|
|
|
|
),
|
2020-11-09 15:40:06 +00:00
|
|
|
cfgObject: cfgObject{
|
|
|
|
pool: initObjectPool(viperCfg),
|
|
|
|
},
|
2021-01-15 10:23:46 +00:00
|
|
|
netStatus: atomic.NewInt32(int32(control.NetmapStatus_STATUS_UNDEFINED)),
|
|
|
|
healthStatus: atomic.NewInt32(int32(control.HealthStatus_HEALTH_STATUS_UNDEFINED)),
|
2021-04-21 05:29:35 +00:00
|
|
|
cfgReputation: cfgReputation{
|
2021-04-29 05:32:24 +00:00
|
|
|
scriptHash: u160Reputation,
|
2021-04-21 05:29:35 +00:00
|
|
|
workerPool: reputationWorkerPool,
|
|
|
|
},
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
2020-09-24 12:32:30 +00:00
|
|
|
|
2021-05-11 22:59:05 +00:00
|
|
|
if c.viper.GetString(cfgMetricsAddr) != "" {
|
2021-03-16 08:14:56 +00:00
|
|
|
c.metricsCollector = metrics.NewStorageMetrics()
|
|
|
|
}
|
|
|
|
|
2020-09-24 12:32:30 +00:00
|
|
|
initLocalStorage(c)
|
|
|
|
|
|
|
|
return c
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
2020-09-16 07:45:08 +00:00
|
|
|
|
|
|
|
func initViper(path string) *viper.Viper {
|
|
|
|
v := viper.New()
|
|
|
|
|
|
|
|
v.SetEnvPrefix(misc.Prefix)
|
|
|
|
v.AutomaticEnv()
|
|
|
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
|
|
|
|
|
|
defaultConfiguration(v)
|
|
|
|
|
|
|
|
if path != "" {
|
|
|
|
v.SetConfigFile(path)
|
|
|
|
v.SetConfigType("yml")
|
|
|
|
fatalOnErr(v.ReadInConfig())
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func defaultConfiguration(v *viper.Viper) {
|
2021-01-12 13:26:39 +00:00
|
|
|
v.SetDefault(cfgNodeKey, "") // node key
|
|
|
|
v.SetDefault(cfgBootstrapAddress, "") // announced address of the node
|
2021-05-12 09:29:19 +00:00
|
|
|
v.SetDefault(cfgNodeRelay, false)
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2021-01-12 13:25:30 +00:00
|
|
|
v.SetDefault(cfgMorphRPCAddress, []string{})
|
|
|
|
v.SetDefault(cfgMorphNotifyRPCAddress, []string{})
|
2020-10-21 09:26:16 +00:00
|
|
|
v.SetDefault(cfgMorphNotifyDialTimeout, 5*time.Second)
|
2021-01-12 13:26:39 +00:00
|
|
|
|
2020-09-16 07:45:08 +00:00
|
|
|
v.SetDefault(cfgListenAddress, "127.0.0.1:50501") // listen address
|
2021-05-14 09:11:49 +00:00
|
|
|
v.SetDefault(cfgTLSEnabled, false)
|
|
|
|
v.SetDefault(cfgTLSCertFile, "")
|
|
|
|
v.SetDefault(cfgTLSKeyFile, "")
|
2021-05-12 08:04:51 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgAPIClientDialTimeout, 5*time.Second)
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2021-05-13 08:11:35 +00:00
|
|
|
v.SetDefault(cfgAccountingContract, "")
|
2020-09-16 07:45:08 +00:00
|
|
|
|
2021-05-13 08:11:35 +00:00
|
|
|
v.SetDefault(cfgContainerContract, "")
|
2021-04-21 05:29:35 +00:00
|
|
|
|
2021-05-13 08:11:35 +00:00
|
|
|
v.SetDefault(cfgNetmapContract, "")
|
2020-09-25 12:34:17 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgLogLevel, "info")
|
2020-10-02 13:18:38 +00:00
|
|
|
|
2021-05-11 22:59:05 +00:00
|
|
|
v.SetDefault(cfgProfilerShutdownTimeout, "30s")
|
2020-10-05 10:44:28 +00:00
|
|
|
|
2021-05-11 22:59:05 +00:00
|
|
|
v.SetDefault(cfgMetricsShutdownTimeout, "30s")
|
2021-03-15 13:11:40 +00:00
|
|
|
|
2020-10-21 09:28:42 +00:00
|
|
|
v.SetDefault(cfgPolicerHeadTimeout, 5*time.Second)
|
2020-10-21 11:51:20 +00:00
|
|
|
|
|
|
|
v.SetDefault(cfgReplicatorPutTimeout, 5*time.Second)
|
2020-10-30 12:57:49 +00:00
|
|
|
|
2020-11-09 15:40:06 +00:00
|
|
|
v.SetDefault(cfgObjectPutPoolSize, 10)
|
2021-01-13 12:51:05 +00:00
|
|
|
|
2021-01-14 07:48:59 +00:00
|
|
|
v.SetDefault(cfgCtrlSvcAuthorizedKeys, []string{})
|
2020-09-16 07:45:08 +00:00
|
|
|
}
|
2020-09-23 13:31:51 +00:00
|
|
|
|
|
|
|
func (c *cfg) LocalAddress() *network.Address {
|
|
|
|
return c.localAddr
|
|
|
|
}
|
2020-09-24 12:32:30 +00:00
|
|
|
|
|
|
|
func initLocalStorage(c *cfg) {
|
2020-11-19 10:58:27 +00:00
|
|
|
initShardOptions(c)
|
2020-09-24 12:32:30 +00:00
|
|
|
|
2021-03-16 11:19:32 +00:00
|
|
|
engineOpts := []engine.Option{engine.WithLogger(c.log)}
|
|
|
|
if c.metricsCollector != nil {
|
|
|
|
engineOpts = append(engineOpts, engine.WithMetrics(c.metricsCollector))
|
|
|
|
}
|
|
|
|
|
|
|
|
ls := engine.New(engineOpts...)
|
2020-10-29 17:17:42 +00:00
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
for _, opts := range c.cfgObject.cfgLocalStorage.shardOpts {
|
|
|
|
id, err := ls.AddShard(opts...)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
c.log.Info("shard attached to engine",
|
|
|
|
zap.Stringer("id", id),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.cfgObject.cfgLocalStorage.localStorage = ls
|
2021-01-18 09:04:58 +00:00
|
|
|
|
|
|
|
c.onShutdown(func() {
|
|
|
|
c.log.Info("closing components of the storage engine...")
|
|
|
|
|
|
|
|
err := ls.Close()
|
|
|
|
if err != nil {
|
|
|
|
c.log.Info("storage engine closing failure",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
c.log.Info("all components of the storage engine closed successfully")
|
|
|
|
}
|
|
|
|
})
|
2020-11-19 10:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initShardOptions(c *cfg) {
|
|
|
|
var opts [][]shard.Option
|
|
|
|
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
prefix := configPath(
|
|
|
|
cfgLocalStorageSection,
|
|
|
|
cfgStorageShardSection,
|
|
|
|
strconv.Itoa(i),
|
|
|
|
)
|
|
|
|
|
2020-11-30 17:03:15 +00:00
|
|
|
useCache := c.viper.GetBool(
|
|
|
|
configPath(prefix, cfgShardUseWriteCache),
|
|
|
|
)
|
|
|
|
|
2020-12-01 09:26:19 +00:00
|
|
|
writeCachePrefix := configPath(prefix, cfgWriteCacheSection)
|
|
|
|
|
|
|
|
writeCachePath := c.viper.GetString(
|
|
|
|
configPath(writeCachePrefix, cfgBlobStorTreePath),
|
|
|
|
)
|
|
|
|
if useCache && writeCachePath == "" {
|
2020-12-01 14:57:37 +00:00
|
|
|
c.log.Warn("incorrect writeCache path, ignore shard")
|
2020-12-01 09:26:19 +00:00
|
|
|
break
|
|
|
|
}
|
2021-04-06 10:56:06 +00:00
|
|
|
writeCacheMemSize := c.viper.GetUint64(configPath(writeCachePrefix, cfgWriteCacheMemSize))
|
|
|
|
writeCacheDBSize := c.viper.GetUint64(configPath(writeCachePrefix, cfgWriteCacheDBSize))
|
|
|
|
writeCacheSmallSize := c.viper.GetUint64(configPath(writeCachePrefix, cfgWriteCacheSmallSize))
|
|
|
|
writeCacheMaxSize := c.viper.GetUint64(configPath(writeCachePrefix, cfgWriteCacheMaxSize))
|
|
|
|
writeCacheWrkCount := c.viper.GetInt(configPath(writeCachePrefix, cfgWriteCacheWrkCount))
|
2020-12-01 09:26:19 +00:00
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
blobPrefix := configPath(prefix, cfgBlobStorSection)
|
|
|
|
|
|
|
|
blobPath := c.viper.GetString(
|
|
|
|
configPath(blobPrefix, cfgBlobStorTreePath),
|
|
|
|
)
|
|
|
|
if blobPath == "" {
|
2020-12-01 14:57:37 +00:00
|
|
|
c.log.Warn("incorrect blobStor path, ignore shard")
|
2020-11-19 10:58:27 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
compressObjects := c.viper.GetBool(
|
|
|
|
configPath(blobPrefix, cfgBlobStorCompress),
|
|
|
|
)
|
|
|
|
|
|
|
|
blobPerm := os.FileMode(c.viper.GetInt(
|
|
|
|
configPath(blobPrefix, cfgBlobStorTreePerm),
|
|
|
|
))
|
|
|
|
|
|
|
|
shallowDepth := c.viper.GetInt(
|
|
|
|
configPath(blobPrefix, cfgBlobStorShallowDepth),
|
|
|
|
)
|
|
|
|
|
2020-11-26 07:47:20 +00:00
|
|
|
smallSzLimit := c.viper.GetUint64(
|
|
|
|
configPath(blobPrefix, cfgBlobStorSmallSzLimit),
|
|
|
|
)
|
2021-01-18 08:32:07 +00:00
|
|
|
if smallSzLimit == 0 {
|
|
|
|
smallSzLimit = 1 << 20 // 1MB
|
|
|
|
}
|
2021-04-06 10:56:06 +00:00
|
|
|
if writeCacheMaxSize <= 0 {
|
|
|
|
writeCacheSmallSize = smallSzLimit
|
|
|
|
}
|
2020-11-26 07:47:20 +00:00
|
|
|
|
2020-11-30 15:35:37 +00:00
|
|
|
blzPrefix := configPath(blobPrefix, cfgBlobStorBlzSection)
|
|
|
|
|
|
|
|
blzSize := c.viper.GetUint64(
|
|
|
|
configPath(blzPrefix, cfgBlzSize),
|
|
|
|
)
|
2021-01-18 08:32:35 +00:00
|
|
|
if blzSize == 0 {
|
|
|
|
blzSize = 1 << 30 // 1 GB
|
|
|
|
}
|
2020-11-30 15:35:37 +00:00
|
|
|
|
|
|
|
blzShallowDepth := c.viper.GetUint64(
|
|
|
|
configPath(blzPrefix, cfgBlzShallowDepth),
|
|
|
|
)
|
|
|
|
|
|
|
|
blzShallowWidth := c.viper.GetUint64(
|
|
|
|
configPath(blzPrefix, cfgBlzShallowWidth),
|
|
|
|
)
|
|
|
|
|
|
|
|
blzCacheSize := c.viper.GetInt(
|
|
|
|
configPath(blzPrefix, cfgBlzOpenedCacheSize),
|
|
|
|
)
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
metaPrefix := configPath(prefix, cfgMetaBaseSection)
|
|
|
|
|
|
|
|
metaPath := c.viper.GetString(
|
|
|
|
configPath(metaPrefix, cfgMetaBasePath),
|
|
|
|
)
|
|
|
|
|
|
|
|
metaPerm := os.FileMode(c.viper.GetUint32(
|
|
|
|
configPath(metaPrefix, cfgMetaBasePerm),
|
|
|
|
))
|
|
|
|
|
|
|
|
fatalOnErr(os.MkdirAll(path.Dir(metaPath), metaPerm))
|
|
|
|
|
2021-02-16 11:40:06 +00:00
|
|
|
gcPrefix := configPath(prefix, cfgGCSection)
|
|
|
|
|
|
|
|
rmBatchSize := c.viper.GetInt(
|
|
|
|
configPath(gcPrefix, cfgGCRemoverBatchSize),
|
|
|
|
)
|
|
|
|
|
|
|
|
rmSleepInterval := c.viper.GetDuration(
|
|
|
|
configPath(gcPrefix, cfgGCRemoverSleepInt),
|
|
|
|
)
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
opts = append(opts, []shard.Option{
|
|
|
|
shard.WithLogger(c.log),
|
|
|
|
shard.WithBlobStorOptions(
|
2020-12-01 09:50:16 +00:00
|
|
|
blobstor.WithRootPath(blobPath),
|
2020-11-19 10:58:27 +00:00
|
|
|
blobstor.WithCompressObjects(compressObjects, c.log),
|
2020-12-01 09:50:16 +00:00
|
|
|
blobstor.WithRootPerm(blobPerm),
|
2020-11-19 10:58:27 +00:00
|
|
|
blobstor.WithShallowDepth(shallowDepth),
|
2020-11-26 07:47:20 +00:00
|
|
|
blobstor.WithSmallSizeLimit(smallSzLimit),
|
2020-11-30 15:35:37 +00:00
|
|
|
blobstor.WithBlobovniczaSize(blzSize),
|
|
|
|
blobstor.WithBlobovniczaShallowDepth(blzShallowDepth),
|
|
|
|
blobstor.WithBlobovniczaShallowWidth(blzShallowWidth),
|
|
|
|
blobstor.WithBlobovniczaOpenedCacheSize(blzCacheSize),
|
|
|
|
blobstor.WithLogger(c.log),
|
2020-11-19 10:58:27 +00:00
|
|
|
),
|
|
|
|
shard.WithMetaBaseOptions(
|
|
|
|
meta.WithLogger(c.log),
|
2020-11-30 15:35:37 +00:00
|
|
|
meta.WithPath(metaPath),
|
|
|
|
meta.WithPermissions(metaPerm),
|
2021-01-18 13:04:13 +00:00
|
|
|
meta.WithBoltDBOptions(&bbolt.Options{
|
|
|
|
Timeout: 100 * time.Millisecond,
|
|
|
|
}),
|
2020-11-19 10:58:27 +00:00
|
|
|
),
|
2020-11-30 17:03:15 +00:00
|
|
|
shard.WithWriteCache(useCache),
|
2020-12-01 09:26:19 +00:00
|
|
|
shard.WithWriteCacheOptions(
|
2021-04-06 10:56:06 +00:00
|
|
|
writecache.WithPath(writeCachePath),
|
|
|
|
writecache.WithLogger(c.log),
|
|
|
|
writecache.WithMaxMemSize(writeCacheMemSize),
|
|
|
|
writecache.WithMaxObjectSize(writeCacheMaxSize),
|
|
|
|
writecache.WithSmallObjectSize(writeCacheSmallSize),
|
|
|
|
writecache.WithMaxDBSize(writeCacheDBSize),
|
|
|
|
writecache.WithFlushWorkersCount(writeCacheWrkCount),
|
2020-12-01 09:26:19 +00:00
|
|
|
),
|
2021-02-16 11:40:06 +00:00
|
|
|
shard.WithRemoverBatchSize(rmBatchSize),
|
|
|
|
shard.WithGCRemoverSleepInterval(rmSleepInterval),
|
|
|
|
shard.WithGCWorkerPoolInitializer(func(sz int) util2.WorkerPool {
|
|
|
|
pool, err := ants.NewPool(sz)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
return pool
|
|
|
|
}),
|
2021-02-17 12:19:54 +00:00
|
|
|
shard.WithGCEventChannelInitializer(func() <-chan shard.Event {
|
|
|
|
ch := make(chan shard.Event)
|
|
|
|
|
|
|
|
addNewEpochNotificationHandler(c, func(ev event.Event) {
|
|
|
|
ch <- shard.EventNewEpoch(ev.(netmap2.NewEpoch).EpochNumber())
|
|
|
|
})
|
|
|
|
|
|
|
|
return ch
|
|
|
|
}),
|
2020-11-19 10:58:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
c.log.Info("storage shard options",
|
2020-11-30 17:03:15 +00:00
|
|
|
zap.Bool("with write cache", useCache),
|
2020-12-01 09:26:19 +00:00
|
|
|
zap.String("with write cache path", writeCachePath),
|
2020-11-19 10:58:27 +00:00
|
|
|
zap.String("BLOB path", blobPath),
|
|
|
|
zap.Stringer("BLOB permissions", blobPerm),
|
|
|
|
zap.Bool("BLOB compress", compressObjects),
|
|
|
|
zap.Int("BLOB shallow depth", shallowDepth),
|
2020-11-26 07:47:20 +00:00
|
|
|
zap.Uint64("BLOB small size limit", smallSzLimit),
|
2020-11-19 10:58:27 +00:00
|
|
|
zap.String("metabase path", metaPath),
|
|
|
|
zap.Stringer("metabase permissions", metaPerm),
|
2021-02-16 11:40:06 +00:00
|
|
|
zap.Int("GC remover batch size", rmBatchSize),
|
|
|
|
zap.Duration("GC remover sleep interval", rmSleepInterval),
|
2020-11-19 10:58:27 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-01 14:57:37 +00:00
|
|
|
if len(opts) == 0 {
|
|
|
|
fatalOnErr(errors.New("no correctly set up shards, exit"))
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:58:27 +00:00
|
|
|
c.cfgObject.cfgLocalStorage.shardOpts = opts
|
|
|
|
}
|
|
|
|
|
|
|
|
func configPath(sections ...string) string {
|
|
|
|
return strings.Join(sections, ".")
|
2020-09-24 12:32:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 15:40:06 +00:00
|
|
|
func initObjectPool(cfg *viper.Viper) (pool cfgObjectRoutines) {
|
|
|
|
var err error
|
|
|
|
|
2020-11-23 12:09:41 +00:00
|
|
|
optNonBlocking := ants.WithNonblocking(true)
|
|
|
|
|
|
|
|
pool.put, err = ants.NewPool(cfg.GetInt(cfgObjectPutPoolSize), optNonBlocking)
|
2020-11-09 15:40:06 +00:00
|
|
|
if err != nil {
|
|
|
|
fatalOnErr(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return pool
|
|
|
|
}
|
2021-01-25 08:23:06 +00:00
|
|
|
|
|
|
|
func (c *cfg) LocalNodeInfo() (*netmapV2.NodeInfo, error) {
|
|
|
|
ni := c.localNodeInfo()
|
|
|
|
return ni.ToV2(), nil
|
|
|
|
}
|
|
|
|
|
2021-02-03 14:59:57 +00:00
|
|
|
// handleLocalNodeInfo rewrites local node info
|
2021-01-25 08:23:06 +00:00
|
|
|
func (c *cfg) handleLocalNodeInfo(ni *netmap.NodeInfo) {
|
|
|
|
c.cfgNodeInfo.infoMtx.Lock()
|
|
|
|
|
|
|
|
if ni != nil {
|
|
|
|
c.cfgNodeInfo.info = *ni
|
|
|
|
}
|
|
|
|
|
2021-02-03 14:59:57 +00:00
|
|
|
c.updateStatusWithoutLock(ni)
|
|
|
|
|
|
|
|
c.cfgNodeInfo.infoMtx.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleNodeInfoStatus updates node info status without rewriting whole local
|
|
|
|
// node info status
|
|
|
|
func (c *cfg) handleNodeInfoStatus(ni *netmap.NodeInfo) {
|
|
|
|
c.cfgNodeInfo.infoMtx.Lock()
|
|
|
|
|
|
|
|
c.updateStatusWithoutLock(ni)
|
2021-01-25 08:23:06 +00:00
|
|
|
|
|
|
|
c.cfgNodeInfo.infoMtx.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cfg) localNodeInfo() netmap.NodeInfo {
|
|
|
|
c.cfgNodeInfo.infoMtx.RLock()
|
|
|
|
defer c.cfgNodeInfo.infoMtx.RUnlock()
|
|
|
|
|
|
|
|
return c.cfgNodeInfo.info
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cfg) toOnlineLocalNodeInfo() *netmap.NodeInfo {
|
|
|
|
ni := c.localNodeInfo()
|
|
|
|
ni.SetState(netmap.NodeStateOnline)
|
|
|
|
|
|
|
|
return &ni
|
|
|
|
}
|
2021-02-03 14:59:57 +00:00
|
|
|
|
|
|
|
func (c *cfg) updateStatusWithoutLock(ni *netmap.NodeInfo) {
|
|
|
|
var nmState netmap.NodeState
|
|
|
|
|
|
|
|
if ni != nil {
|
|
|
|
nmState = ni.State()
|
|
|
|
} else {
|
|
|
|
nmState = netmap.NodeStateOffline
|
|
|
|
c.cfgNodeInfo.info.SetState(nmState)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch nmState {
|
|
|
|
default:
|
|
|
|
c.setNetmapStatus(control.NetmapStatus_STATUS_UNDEFINED)
|
|
|
|
case netmap.NodeStateOnline:
|
|
|
|
c.setNetmapStatus(control.NetmapStatus_ONLINE)
|
|
|
|
case netmap.NodeStateOffline:
|
|
|
|
c.setNetmapStatus(control.NetmapStatus_OFFLINE)
|
|
|
|
}
|
|
|
|
}
|