2021-01-13 13:46:39 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
|
2021-06-01 13:34:14 +00:00
|
|
|
controlconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/control"
|
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"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-01-13 13:46:39 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func initControlService(c *cfg) {
|
2021-06-22 16:27:47 +00:00
|
|
|
endpoint := controlconfig.GRPC(c.appCfg).Endpoint()
|
|
|
|
if endpoint == controlconfig.GRPCEndpointDefault {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-31 08:55:38 +00:00
|
|
|
pubs := controlconfig.AuthorizedKeys(c.appCfg)
|
|
|
|
rawPubs := make([][]byte, 0, len(pubs)+1) // +1 for node key
|
2021-01-13 13:46:39 +00:00
|
|
|
|
2021-05-31 08:55:38 +00:00
|
|
|
rawPubs = append(rawPubs, c.key.PublicKey().Bytes())
|
2021-01-13 13:46:39 +00:00
|
|
|
|
2021-05-31 08:55:38 +00:00
|
|
|
for i := range pubs {
|
|
|
|
rawPubs = append(rawPubs, pubs[i].Bytes())
|
2021-01-13 13:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctlSvc := controlSvc.New(
|
2021-05-31 08:55:38 +00:00
|
|
|
controlSvc.WithKey(&c.key.PrivateKey),
|
|
|
|
controlSvc.WithAuthorizedKeys(rawPubs),
|
2021-01-13 13:46:39 +00:00
|
|
|
controlSvc.WithHealthChecker(c),
|
2022-03-29 13:52:12 +00:00
|
|
|
controlSvc.WithNetMapSource(c.netMapSource),
|
2021-01-15 11:53:41 +00:00
|
|
|
controlSvc.WithNodeState(c),
|
2022-05-31 17:00:41 +00:00
|
|
|
controlSvc.WithDeletedObjectHandler(func(addrList []oid.Address) error {
|
2022-05-23 13:12:32 +00:00
|
|
|
var prm engine.DeletePrm
|
|
|
|
prm.WithAddresses(addrList...)
|
2022-05-31 20:11:42 +00:00
|
|
|
prm.WithForceRemoval()
|
2021-02-21 08:30:32 +00:00
|
|
|
|
|
|
|
_, err := c.cfgObject.cfgLocalStorage.localStorage.Delete(prm)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}),
|
2021-12-17 15:55:59 +00:00
|
|
|
controlSvc.WithLocalStorage(c.cfgObject.cfgLocalStorage.localStorage),
|
2021-01-13 13:46:39 +00:00
|
|
|
)
|
|
|
|
|
2021-06-22 16:27:47 +00:00
|
|
|
lis, err := net.Listen("tcp", endpoint)
|
|
|
|
fatalOnErr(err)
|
2021-01-13 13:46:39 +00:00
|
|
|
|
2021-06-22 16:27:47 +00:00
|
|
|
c.cfgControlService.server = grpc.NewServer()
|
2021-01-13 13:46:39 +00:00
|
|
|
|
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) {
|
2022-05-25 16:18:36 +00:00
|
|
|
runAndLog(c, "control", false, func(c *cfg) {
|
|
|
|
fatalOnErr(c.cfgControlService.server.Serve(lis))
|
|
|
|
})
|
2021-01-13 13:46:39 +00:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|