[#306] Rename Private service to Control service

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-13 16:46:39 +03:00 committed by Alex Vanin
parent df3746fa68
commit abd9952e46
16 changed files with 124 additions and 124 deletions

View file

@ -66,7 +66,7 @@ protoc:
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \ @for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
echo "⇒ Processing $$f "; \ echo "⇒ Processing $$f "; \
protoc \ protoc \
--proto_path=.:./vendor:./vendor/github.com/nspcc-dev/neofs-api-go:/usr/local/include:./pkg/services/private \ --proto_path=.:./vendor:./vendor/github.com/nspcc-dev/neofs-api-go:/usr/local/include:./pkg/services/control \
--gofast_out=plugins=grpc,paths=source_relative:. $$f; \ --gofast_out=plugins=grpc,paths=source_relative:. $$f; \
done done
rm -rf vendor rm -rf vendor

View file

@ -5,13 +5,13 @@ import (
"github.com/nspcc-dev/neofs-api-go/util/signature" "github.com/nspcc-dev/neofs-api-go/util/signature"
"github.com/nspcc-dev/neofs-api-go/v2/client" "github.com/nspcc-dev/neofs-api-go/v2/client"
"github.com/nspcc-dev/neofs-node/pkg/services/private" "github.com/nspcc-dev/neofs-node/pkg/services/control"
privateSvc "github.com/nspcc-dev/neofs-node/pkg/services/private/server" controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var privateCmd = &cobra.Command{ var controlCmd = &cobra.Command{
Use: "private", Use: "control",
Short: "Operations with storage node", Short: "Operations with storage node",
Long: `Operations with storage node`, Long: `Operations with storage node`,
} }
@ -24,9 +24,9 @@ var healthCheckCmd = &cobra.Command{
} }
func init() { func init() {
rootCmd.AddCommand(privateCmd) rootCmd.AddCommand(controlCmd)
privateCmd.AddCommand(healthCheckCmd) controlCmd.AddCommand(healthCheckCmd)
} }
func healthCheck(cmd *cobra.Command, _ []string) error { func healthCheck(cmd *cobra.Command, _ []string) error {
@ -35,11 +35,11 @@ func healthCheck(cmd *cobra.Command, _ []string) error {
return err return err
} }
req := new(private.HealthCheckRequest) req := new(control.HealthCheckRequest)
req.SetBody(new(private.HealthCheckRequest_Body)) req.SetBody(new(control.HealthCheckRequest_Body))
if err := privateSvc.SignMessage(key, req); err != nil { if err := controlSvc.SignMessage(key, req); err != nil {
return err return err
} }
@ -60,7 +60,7 @@ func healthCheck(cmd *cobra.Command, _ []string) error {
return err return err
} }
cli := private.NewPrivateServiceClient(con) cli := control.NewControlServiceClient(con)
resp, err := cli.HealthCheck(context.Background(), req) resp, err := cli.HealthCheck(context.Background(), req)
if err != nil { if err != nil {

View file

@ -28,7 +28,7 @@ import (
nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/network"
"github.com/nspcc-dev/neofs-node/pkg/services/private" "github.com/nspcc-dev/neofs-node/pkg/services/control"
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
"github.com/nspcc-dev/neofs-node/pkg/services/util/response" "github.com/nspcc-dev/neofs-node/pkg/services/util/response"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
@ -182,7 +182,7 @@ type cfg struct {
respSvc *response.Service respSvc *response.Service
cfgPrivateService cfgPrivateService cfgControlService cfgControlService
healthStatus *atomic.Int32 healthStatus *atomic.Int32
} }
@ -264,7 +264,7 @@ type cfgObjectRoutines struct {
get, head, put, search, rng, rngHash *ants.Pool get, head, put, search, rng, rngHash *ants.Pool
} }
type cfgPrivateService struct { type cfgControlService struct {
server *grpc.Server server *grpc.Server
} }
@ -342,7 +342,7 @@ func initCfg(path string) *cfg {
cfgObject: cfgObject{ cfgObject: cfgObject{
pool: initObjectPool(viperCfg), pool: initObjectPool(viperCfg),
}, },
healthStatus: atomic.NewInt32(int32(private.HealthStatus_STATUS_UNDEFINED)), healthStatus: atomic.NewInt32(int32(control.HealthStatus_STATUS_UNDEFINED)),
} }
initLocalStorage(c) initLocalStorage(c)
@ -424,7 +424,7 @@ func defaultConfiguration(v *viper.Viper) {
v.SetDefault(cfgObjectRangePoolSize, 10) v.SetDefault(cfgObjectRangePoolSize, 10)
v.SetDefault(cfgObjectRangeHashPoolSize, 10) v.SetDefault(cfgObjectRangeHashPoolSize, 10)
v.SetDefault(cfgPrivateSvcAllowedKeys, []string{}) v.SetDefault(cfgCtrlSvcAllowedKeys, []string{})
} }
func (c *cfg) LocalAddress() *network.Address { func (c *cfg) LocalAddress() *network.Address {

76
cmd/neofs-node/control.go Normal file
View file

@ -0,0 +1,76 @@
package main
import (
"context"
"encoding/hex"
"net"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
const (
cfgCtrlSvcSection = "control"
cfgCtrlSvcAllowedKeys = cfgCtrlSvcSection + ".permitted_keys"
cfgCtrlSvcGRPCSection = cfgCtrlSvcSection + ".grpc"
cfgCtrlGRPCEndpoint = cfgCtrlSvcGRPCSection + ".endpoint"
)
func initControlService(c *cfg) {
strKeys := c.viper.GetStringSlice(cfgCtrlSvcAllowedKeys)
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 {
fatalOnErr(errors.Errorf("invalid permitted key for Control service %s", strKeys[i]))
}
keys = append(keys, key)
}
ctlSvc := controlSvc.New(
controlSvc.WithKey(c.key),
controlSvc.WithAllowedKeys(keys),
controlSvc.WithHealthChecker(c),
)
var (
err error
lis net.Listener
endpoint = c.viper.GetString(cfgCtrlGRPCEndpoint)
)
if endpoint == "" || endpoint == c.viper.GetString(cfgListenAddress) {
lis = c.cfgGRPC.listener
c.cfgControlService.server = c.cfgGRPC.server
} else {
lis, err = net.Listen("tcp", endpoint)
fatalOnErr(err)
c.cfgControlService.server = grpc.NewServer()
}
control.RegisterControlServiceServer(c.cfgControlService.server, ctlSvc)
c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
fatalOnErr(c.cfgControlService.server.Serve(lis))
}))
}
func (c *cfg) setHealthStatus(st control.HealthStatus) {
c.healthStatus.Store(int32(st))
}
func (c *cfg) HealthStatus() control.HealthStatus {
return control.HealthStatus(c.healthStatus.Load())
}

View file

@ -5,7 +5,7 @@ import (
"flag" "flag"
"log" "log"
"github.com/nspcc-dev/neofs-node/pkg/services/private" "github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/nspcc-dev/neofs-node/pkg/util/grace" "github.com/nspcc-dev/neofs-node/pkg/util/grace"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -42,7 +42,7 @@ func initApp(c *cfg) {
initSessionService(c) initSessionService(c)
initObjectService(c) initObjectService(c)
initProfiler(c) initProfiler(c)
initPrivateService(c) initControlService(c)
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open()) fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open())
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init()) fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init())
@ -56,7 +56,7 @@ func bootUp(c *cfg) {
bootstrapNode(c) bootstrapNode(c)
startWorkers(c) startWorkers(c)
c.setHealthStatus(private.HealthStatus_ONLINE) c.setHealthStatus(control.HealthStatus_ONLINE)
} }
func wait(c *cfg) { func wait(c *cfg) {
@ -75,7 +75,7 @@ func wait(c *cfg) {
func shutdown(c *cfg) { func shutdown(c *cfg) {
c.cfgGRPC.server.GracefulStop() c.cfgGRPC.server.GracefulStop()
c.cfgPrivateService.server.GracefulStop() c.cfgControlService.server.GracefulStop()
c.log.Info("gRPC server stopped") c.log.Info("gRPC server stopped")

View file

@ -7,8 +7,8 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc" netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap" netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/private"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/atomic" "go.uber.org/atomic"
"go.uber.org/zap" "go.uber.org/zap"
@ -117,7 +117,7 @@ func addNewEpochNotificationHandler(c *cfg, h event.Handler) {
} }
func goOffline(c *cfg) { func goOffline(c *cfg) {
c.setHealthStatus(private.HealthStatus_OFFLINE) c.setHealthStatus(control.HealthStatus_OFFLINE)
err := c.cfgNetmap.wrapper.UpdatePeerState( err := c.cfgNetmap.wrapper.UpdatePeerState(
crypto.MarshalPublicKey(&c.key.PublicKey), crypto.MarshalPublicKey(&c.key.PublicKey),

View file

@ -1,76 +0,0 @@
package main
import (
"context"
"encoding/hex"
"net"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/services/private"
privateSvc "github.com/nspcc-dev/neofs-node/pkg/services/private/server"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
const (
cfgPrivateSvcSection = "private"
cfgPrivateSvcAllowedKeys = cfgPrivateSvcSection + ".permitted_keys"
cfgPrivateSvcGRPCSection = cfgPrivateSvcSection + ".grpc"
cfgPrivateGRPCEndpoint = cfgPrivateSvcGRPCSection + ".endpoint"
)
func initPrivateService(c *cfg) {
strKeys := c.viper.GetStringSlice(cfgPrivateSvcAllowedKeys)
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 {
fatalOnErr(errors.Errorf("invalid permitted key for private service %s", strKeys[i]))
}
keys = append(keys, key)
}
privSvc := privateSvc.New(
privateSvc.WithKey(c.key),
privateSvc.WithAllowedKeys(keys),
privateSvc.WithHealthChecker(c),
)
var (
err error
lis net.Listener
endpoint = c.viper.GetString(cfgPrivateGRPCEndpoint)
)
if endpoint == "" || endpoint == c.viper.GetString(cfgListenAddress) {
lis = c.cfgGRPC.listener
c.cfgPrivateService.server = c.cfgGRPC.server
} else {
lis, err = net.Listen("tcp", endpoint)
fatalOnErr(err)
c.cfgPrivateService.server = grpc.NewServer()
}
private.RegisterPrivateServiceServer(c.cfgPrivateService.server, privSvc)
c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
fatalOnErr(c.cfgPrivateService.server.Serve(lis))
}))
}
func (c *cfg) setHealthStatus(st private.HealthStatus) {
c.healthStatus.Store(int32(st))
}
func (c *cfg) HealthStatus() private.HealthStatus {
return private.HealthStatus(c.healthStatus.Load())
}

View file

@ -1,9 +1,9 @@
package private package control
import ( import (
"context" "context"
"github.com/nspcc-dev/neofs-node/pkg/services/private" "github.com/nspcc-dev/neofs-node/pkg/services/control"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
) )
@ -11,16 +11,16 @@ import (
// HealthCheck returns health status of the local node. // HealthCheck returns health status of the local node.
// //
// If request is unsigned or signed by disallowed key, permission error returns. // If request is unsigned or signed by disallowed key, permission error returns.
func (s *Server) HealthCheck(_ context.Context, req *private.HealthCheckRequest) (*private.HealthCheckResponse, error) { func (s *Server) HealthCheck(_ context.Context, req *control.HealthCheckRequest) (*control.HealthCheckResponse, error) {
// verify request // verify request
if err := s.isValidRequest(req); err != nil { if err := s.isValidRequest(req); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error()) return nil, status.Error(codes.PermissionDenied, err.Error())
} }
// create and fill response // create and fill response
resp := new(private.HealthCheckResponse) resp := new(control.HealthCheckResponse)
body := new(private.HealthCheckResponse_Body) body := new(control.HealthCheckResponse_Body)
resp.SetBody(body) resp.SetBody(body)
body.SetStatus(s.healthChecker.HealthStatus()) body.SetStatus(s.healthChecker.HealthStatus())

View file

@ -1,13 +1,13 @@
package private package control
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"github.com/nspcc-dev/neofs-node/pkg/services/private" "github.com/nspcc-dev/neofs-node/pkg/services/control"
) )
// Server is an entity that serves // Server is an entity that serves
// Private service on storage node. // Control service on storage node.
type Server struct { type Server struct {
*cfg *cfg
} }
@ -18,8 +18,8 @@ type HealthChecker interface {
// Must calculate and return current node health status. // Must calculate and return current node health status.
// //
// If status can not be calculated for any reason, // If status can not be calculated for any reason,
// private.HealthStatus_STATUS_UNDEFINED should be returned. // control.HealthStatus_STATUS_UNDEFINED should be returned.
HealthStatus() private.HealthStatus HealthStatus() control.HealthStatus
} }
// Option of the Server's constructor. // Option of the Server's constructor.
@ -59,7 +59,7 @@ func WithKey(key *ecdsa.PrivateKey) Option {
} }
// WithAllowedKeys returns option to add list of public // WithAllowedKeys returns option to add list of public
// keys that have rights to use private service. // keys that have rights to use Control service.
func WithAllowedKeys(keys [][]byte) Option { func WithAllowedKeys(keys [][]byte) Option {
return func(c *cfg) { return func(c *cfg) {
c.allowedKeys = append(c.allowedKeys, keys...) c.allowedKeys = append(c.allowedKeys, keys...)

View file

@ -1,4 +1,4 @@
package private package control
import ( import (
"bytes" "bytes"
@ -6,14 +6,14 @@ import (
"errors" "errors"
"github.com/nspcc-dev/neofs-api-go/util/signature" "github.com/nspcc-dev/neofs-api-go/util/signature"
"github.com/nspcc-dev/neofs-node/pkg/services/private" "github.com/nspcc-dev/neofs-node/pkg/services/control"
) )
// SignedMessage is an interface of Private service message. // SignedMessage is an interface of Control service message.
type SignedMessage interface { type SignedMessage interface {
signature.DataSource signature.DataSource
GetSignature() *private.Signature GetSignature() *control.Signature
SetSignature(*private.Signature) SetSignature(*control.Signature)
} }
var errDisallowedKey = errors.New("key is not in the allowed list") var errDisallowedKey = errors.New("key is not in the allowed list")
@ -42,10 +42,10 @@ func (s *Server) isValidRequest(req SignedMessage) error {
}) })
} }
// SignMessage signs Private service message with private key. // SignMessage signs Control service message with private key.
func SignMessage(key *ecdsa.PrivateKey, msg SignedMessage) error { func SignMessage(key *ecdsa.PrivateKey, msg SignedMessage) error {
return signature.SignDataWithHandler(key, msg, func(key []byte, sig []byte) { return signature.SignDataWithHandler(key, msg, func(key []byte, sig []byte) {
s := new(private.Signature) s := new(control.Signature)
s.SetKey(key) s.SetKey(key)
s.SetSign(sig) s.SetSign(sig)

View file

@ -1,4 +1,4 @@
package private package control
// SetBody sets health check request body. // SetBody sets health check request body.
func (m *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) { func (m *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) {

View file

@ -1,13 +1,13 @@
syntax = "proto3"; syntax = "proto3";
package private; package control;
import "types.proto"; import "types.proto";
option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/private"; option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/control";
// `PrivateService` provides an interface for internal work with the storage node. // `ControlService` provides an interface for internal work with the storage node.
service PrivateService { service ControlService {
// Performs health check of the storage node. // Performs health check of the storage node.
rpc HealthCheck (HealthCheckRequest) returns (HealthCheckResponse); rpc HealthCheck (HealthCheckRequest) returns (HealthCheckResponse);
} }

View file

@ -1,4 +1,4 @@
package private package control
// SetKey sets public key used for signing. // SetKey sets public key used for signing.
func (m *Signature) SetKey(v []byte) { func (m *Signature) SetKey(v []byte) {

View file

@ -1,8 +1,8 @@
syntax = "proto3"; syntax = "proto3";
package private; package control;
option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/private"; option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/control";
// Signature of some message. // Signature of some message.
message Signature { message Signature {