-
Notifications
You must be signed in to change notification settings - Fork 38
/
server.go
127 lines (101 loc) · 2.85 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package control
import (
"crypto/ecdsa"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
)
// Server is an entity that serves
// Control service on storage node.
type Server struct {
*cfg
}
// HealthChecker is component interface for calculating
// the current health status of a node.
type HealthChecker interface {
// Must calculate and return current status of the node in NeoFS network map.
//
// If status can not be calculated for any reason,
// control.netmapStatus_STATUS_UNDEFINED should be returned.
NetmapStatus() control.NetmapStatus
// 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
}
// NodeState is an interface of storage node network state.
type NodeState interface {
SetNetmapStatus(control.NetmapStatus) error
}
// Option of the Server's constructor.
type Option func(*cfg)
type cfg struct {
key *ecdsa.PrivateKey
allowedKeys [][]byte
healthChecker HealthChecker
netMapSrc netmap.Source
nodeState NodeState
delObjHandler DeletedObjectHandler
s *engine.StorageEngine
}
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
}
}
// WithAuthorizedKeys returns option to add list of public
// keys that have rights to use Control service.
func WithAuthorizedKeys(keys [][]byte) Option {
return func(c *cfg) {
c.allowedKeys = append(c.allowedKeys, keys...)
}
}
// WithHealthChecker returns option to set component
// to calculate node health status.
func WithHealthChecker(hc HealthChecker) Option {
return func(c *cfg) {
c.healthChecker = hc
}
}
// WithNetMapSource returns option to set network map storage.
func WithNetMapSource(netMapSrc netmap.Source) Option {
return func(c *cfg) {
c.netMapSrc = netMapSrc
}
}
// WithNodeState returns option to set node network state component.
func WithNodeState(state NodeState) Option {
return func(c *cfg) {
c.nodeState = state
}
}
// WithDeletedObjectHandler returns option to function
// which is called on the objects being deleted.
func WithDeletedObjectHandler(h DeletedObjectHandler) Option {
return func(c *cfg) {
c.delObjHandler = h
}
}
// WithLocalStorage returns option to set local storage engine that
// contains information about shards.
func WithLocalStorage(engine *engine.StorageEngine) Option {
return func(c *cfg) {
c.s = engine
}
}