2021-01-13 13:46:39 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
|
2021-02-21 08:30:32 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
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"
|
|
|
|
"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),
|
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
|
|
|
)
|
|
|
|
|
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) {
|
|
|
|
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
|
|
|
}
|