forked from TrueCloudLab/frostfs-node
[#306] cmd/node: Serve private node service in storage node app
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
c1b8a4815f
commit
f3cac6cc31
3 changed files with 77 additions and 0 deletions
|
@ -179,6 +179,8 @@ type cfg struct {
|
|||
workers []worker
|
||||
|
||||
respSvc *response.Service
|
||||
|
||||
cfgPrivateService cfgPrivateService
|
||||
}
|
||||
|
||||
type cfgGRPC struct {
|
||||
|
@ -258,6 +260,10 @@ type cfgObjectRoutines struct {
|
|||
get, head, put, search, rng, rngHash *ants.Pool
|
||||
}
|
||||
|
||||
type cfgPrivateService struct {
|
||||
server *grpc.Server
|
||||
}
|
||||
|
||||
const (
|
||||
_ BootstrapType = iota
|
||||
StorageNode
|
||||
|
@ -412,6 +418,8 @@ func defaultConfiguration(v *viper.Viper) {
|
|||
v.SetDefault(cfgObjectSearchPoolSize, 10)
|
||||
v.SetDefault(cfgObjectRangePoolSize, 10)
|
||||
v.SetDefault(cfgObjectRangeHashPoolSize, 10)
|
||||
|
||||
v.SetDefault(cfgPrivateSvcAllowedKeys, []string{})
|
||||
}
|
||||
|
||||
func (c *cfg) LocalAddress() *network.Address {
|
||||
|
|
|
@ -41,6 +41,7 @@ func initApp(c *cfg) {
|
|||
initSessionService(c)
|
||||
initObjectService(c)
|
||||
initProfiler(c)
|
||||
initPrivateService(c)
|
||||
|
||||
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open())
|
||||
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init())
|
||||
|
@ -71,6 +72,7 @@ func wait(c *cfg) {
|
|||
|
||||
func shutdown(c *cfg) {
|
||||
c.cfgGRPC.server.GracefulStop()
|
||||
c.cfgPrivateService.server.GracefulStop()
|
||||
|
||||
c.log.Info("gRPC server stopped")
|
||||
|
||||
|
|
67
cmd/neofs-node/private.go
Normal file
67
cmd/neofs-node/private.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
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),
|
||||
)
|
||||
|
||||
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))
|
||||
}))
|
||||
}
|
Loading…
Reference in a new issue