2021-01-13 13:46:39 +00:00
|
|
|
package control
|
2021-01-13 12:49:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2021-01-13 13:34:59 +00:00
|
|
|
|
2021-01-14 16:32:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2021-01-13 13:46:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
2021-01-13 12:49:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server is an entity that serves
|
2021-01-13 13:46:39 +00:00
|
|
|
// Control service on storage node.
|
2021-01-13 12:49:46 +00:00
|
|
|
type Server struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
2021-01-13 13:34:59 +00:00
|
|
|
// HealthChecker is component interface for calculating
|
|
|
|
// the current health status of a node.
|
|
|
|
type HealthChecker interface {
|
2021-01-15 09:42:31 +00:00
|
|
|
// Must calculate and return current status of the node in NeoFS network map.
|
2021-01-13 13:34:59 +00:00
|
|
|
//
|
|
|
|
// If status can not be calculated for any reason,
|
2021-01-15 10:22:44 +00:00
|
|
|
// control.netmapStatus_STATUS_UNDEFINED should be returned.
|
2021-01-15 09:42:31 +00:00
|
|
|
NetmapStatus() control.NetmapStatus
|
2021-01-15 10:22:44 +00:00
|
|
|
|
|
|
|
// Must calculate and return current health status of the node application.
|
|
|
|
//
|
|
|
|
// If status can not be calculated for any reason,
|
|
|
|
// control.HealthStatus_HEALTH_STATUS_UNDEFINED should be returned.
|
|
|
|
HealthStatus() control.HealthStatus
|
2021-01-13 13:34:59 +00:00
|
|
|
}
|
|
|
|
|
2021-01-13 12:49:46 +00:00
|
|
|
// Option of the Server's constructor.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
|
|
|
|
allowedKeys [][]byte
|
2021-01-13 13:34:59 +00:00
|
|
|
|
|
|
|
healthChecker HealthChecker
|
2021-01-14 16:32:23 +00:00
|
|
|
|
|
|
|
netMapSrc netmap.Source
|
2021-01-13 12:49:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns new Server instance.
|
|
|
|
func New(opts ...Option) *Server {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Server{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithKey returns option to set private key
|
|
|
|
// used for signing responses.
|
|
|
|
func WithKey(key *ecdsa.PrivateKey) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.key = key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 07:47:18 +00:00
|
|
|
// WithAuthorizedKeys returns option to add list of public
|
2021-01-13 13:46:39 +00:00
|
|
|
// keys that have rights to use Control service.
|
2021-01-14 07:47:18 +00:00
|
|
|
func WithAuthorizedKeys(keys [][]byte) Option {
|
2021-01-13 12:49:46 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.allowedKeys = append(c.allowedKeys, keys...)
|
|
|
|
}
|
|
|
|
}
|
2021-01-13 13:34:59 +00:00
|
|
|
|
|
|
|
// WithHealthChecker returns option to set component
|
|
|
|
// to calculate node health status.
|
|
|
|
func WithHealthChecker(hc HealthChecker) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.healthChecker = hc
|
|
|
|
}
|
|
|
|
}
|
2021-01-14 16:32:23 +00:00
|
|
|
|
|
|
|
// WithNetMapSource returns option to set network map storage.
|
|
|
|
func WithNetMapSource(netMapSrc netmap.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netMapSrc = netMapSrc
|
|
|
|
}
|
|
|
|
}
|