2021-01-13 13:46:39 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/hex"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2021-01-13 13:46:39 +00:00
|
|
|
"net"
|
|
|
|
|
2021-02-21 08:30:32 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2021-01-13 13:46:39 +00:00
|
|
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
2021-06-01 13:34:14 +00:00
|
|
|
controlconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/control"
|
2021-06-01 18:53:31 +00:00
|
|
|
grpcconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/grpc"
|
2021-02-21 08:30:32 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2021-01-13 13:46:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
|
|
|
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func initControlService(c *cfg) {
|
2021-06-01 13:34:14 +00:00
|
|
|
strKeys := controlconfig.AuthorizedKeysString(c.appCfg)
|
2021-01-13 13:46:39 +00:00
|
|
|
keys := make([][]byte, 0, len(strKeys)+1) // +1 for node key
|
|
|
|
|
|
|
|
keys = append(keys, crypto.MarshalPublicKey(&c.key.PublicKey))
|
|
|
|
|
|
|
|
for i := range strKeys {
|
|
|
|
key, err := hex.DecodeString(strKeys[i])
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
if crypto.UnmarshalPublicKey(key) == nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
fatalOnErr(fmt.Errorf("invalid permitted key for Control service %s", strKeys[i]))
|
2021-01-13 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctlSvc := controlSvc.New(
|
|
|
|
controlSvc.WithKey(c.key),
|
2021-01-14 07:47:18 +00:00
|
|
|
controlSvc.WithAuthorizedKeys(keys),
|
2021-01-13 13:46:39 +00:00
|
|
|
controlSvc.WithHealthChecker(c),
|
2021-01-14 16:32:23 +00:00
|
|
|
controlSvc.WithNetMapSource(c.cfgNetmap.wrapper),
|
2021-01-15 11:53:41 +00:00
|
|
|
controlSvc.WithNodeState(c),
|
2021-02-21 08:30:32 +00:00
|
|
|
controlSvc.WithDeletedObjectHandler(func(addrList []*object.Address) error {
|
|
|
|
prm := new(engine.DeletePrm).WithAddresses(addrList...)
|
|
|
|
|
|
|
|
_, err := c.cfgObject.cfgLocalStorage.localStorage.Delete(prm)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}),
|
2021-01-13 13:46:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
lis net.Listener
|
2021-06-01 13:34:14 +00:00
|
|
|
endpoint = controlconfig.GRPC(c.appCfg).Endpoint()
|
2021-01-13 13:46:39 +00:00
|
|
|
)
|
|
|
|
|
2021-06-01 18:53:31 +00:00
|
|
|
if endpoint == "" || endpoint == grpcconfig.Endpoint(c.appCfg) {
|
2021-01-13 13:46:39 +00:00
|
|
|
lis = c.cfgGRPC.listener
|
|
|
|
c.cfgControlService.server = c.cfgGRPC.server
|
|
|
|
} else {
|
|
|
|
lis, err = net.Listen("tcp", endpoint)
|
|
|
|
fatalOnErr(err)
|
|
|
|
|
|
|
|
c.cfgControlService.server = grpc.NewServer()
|
|
|
|
}
|
|
|
|
|
2021-01-18 08:56:14 +00:00
|
|
|
c.onShutdown(func() {
|
|
|
|
stopGRPC("NeoFS Control API", c.cfgControlService.server, c.log)
|
|
|
|
})
|
|
|
|
|
2021-01-13 13:46:39 +00:00
|
|
|
control.RegisterControlServiceServer(c.cfgControlService.server, ctlSvc)
|
|
|
|
|
|
|
|
c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
|
|
|
|
fatalOnErr(c.cfgControlService.server.Serve(lis))
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-01-15 09:42:31 +00:00
|
|
|
func (c *cfg) NetmapStatus() control.NetmapStatus {
|
2021-06-11 10:55:11 +00:00
|
|
|
return c.cfgNetmap.state.controlNetmapStatus()
|
2021-01-15 10:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cfg) setHealthStatus(st control.HealthStatus) {
|
|
|
|
c.healthStatus.Store(int32(st))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cfg) HealthStatus() control.HealthStatus {
|
|
|
|
return control.HealthStatus(c.healthStatus.Load())
|
2021-01-13 13:46:39 +00:00
|
|
|
}
|