[#493] node: Abolish non-usable gRPC server configurations

Reflect service is disabled, max message size frozen by constant.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-12 11:00:46 +03:00 committed by Leonard Lyubich
parent 6d7fff1870
commit 31eb6617fc
2 changed files with 9 additions and 21 deletions

View file

@ -67,10 +67,8 @@ const (
cfgNodeAttributePrefix = "node.attribute" cfgNodeAttributePrefix = "node.attribute"
// config keys for cfgGRPC // config keys for cfgGRPC
cfgListenAddress = "grpc.endpoint" cfgListenAddress = "grpc.endpoint"
cfgMaxMsgSize = "grpc.maxmessagesize" cfgDialTimeout = "grpc.dial_timeout"
cfgReflectService = "grpc.enable_reflect_service"
cfgDialTimeout = "grpc.dial_timeout"
// config keys for cfgMorph // config keys for cfgMorph
cfgMorphRPCAddress = "morph.rpc_endpoint" cfgMorphRPCAddress = "morph.rpc_endpoint"
@ -166,6 +164,8 @@ const (
addressSize = 72 // 32 bytes oid, 32 bytes cid, 8 bytes protobuf encoding addressSize = 72 // 32 bytes oid, 32 bytes cid, 8 bytes protobuf encoding
) )
const maxMsgSize = 4 << 20 // transport msg limit 4 MiB
type cfg struct { type cfg struct {
ctx context.Context ctx context.Context
@ -228,8 +228,6 @@ type cfgGRPC struct {
maxChunkSize uint64 maxChunkSize uint64
maxAddrAmount uint64 maxAddrAmount uint64
enableReflectService bool
} }
type cfgMorph struct { type cfgMorph struct {
@ -364,8 +362,8 @@ func initCfg(path string) *cfg {
netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress)) netAddr, err := network.AddressFromString(viperCfg.GetString(cfgBootstrapAddress))
fatalOnErr(err) fatalOnErr(err)
maxChunkSize := viperCfg.GetUint64(cfgMaxMsgSize) * 3 / 4 // 25% to meta, 75% to payload maxChunkSize := uint64(maxMsgSize) * 3 / 4 // 25% to meta, 75% to payload
maxAddrAmount := maxChunkSize / addressSize // each address is about 72 bytes maxAddrAmount := uint64(maxChunkSize) / addressSize // each address is about 72 bytes
state := newNetworkState() state := newNetworkState()
@ -413,9 +411,8 @@ func initCfg(path string) *cfg {
attributes: parseAttributes(viperCfg), attributes: parseAttributes(viperCfg),
}, },
cfgGRPC: cfgGRPC{ cfgGRPC: cfgGRPC{
maxChunkSize: maxChunkSize, maxChunkSize: maxChunkSize,
maxAddrAmount: maxAddrAmount, maxAddrAmount: maxAddrAmount,
enableReflectService: viperCfg.GetBool(cfgReflectService),
}, },
localAddr: netAddr, localAddr: netAddr,
respSvc: response.NewService( respSvc: response.NewService(
@ -468,8 +465,6 @@ func defaultConfiguration(v *viper.Viper) {
v.SetDefault(cfgMorphNotifyDialTimeout, 5*time.Second) v.SetDefault(cfgMorphNotifyDialTimeout, 5*time.Second)
v.SetDefault(cfgListenAddress, "127.0.0.1:50501") // listen address v.SetDefault(cfgListenAddress, "127.0.0.1:50501") // listen address
v.SetDefault(cfgMaxMsgSize, 4<<20) // transport msg limit 4 MiB
v.SetDefault(cfgReflectService, false)
v.SetDefault(cfgDialTimeout, 5*time.Second) v.SetDefault(cfgDialTimeout, 5*time.Second)
v.SetDefault(cfgAccountingContract, "1aeefe1d0dfade49740fff779c02cd4a0538ffb1") v.SetDefault(cfgAccountingContract, "1aeefe1d0dfade49740fff779c02cd4a0538ffb1")

View file

@ -7,7 +7,6 @@ import (
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/reflection"
) )
func initGRPC(c *cfg) { func initGRPC(c *cfg) {
@ -17,7 +16,7 @@ func initGRPC(c *cfg) {
fatalOnErr(err) fatalOnErr(err)
c.cfgGRPC.server = grpc.NewServer( c.cfgGRPC.server = grpc.NewServer(
grpc.MaxSendMsgSize(c.viper.GetInt(cfgMaxMsgSize)), grpc.MaxSendMsgSize(maxMsgSize),
) )
c.onShutdown(func() { c.onShutdown(func() {
@ -33,12 +32,6 @@ func serveGRPC(c *cfg) {
c.wg.Done() c.wg.Done()
}() }()
// read more about reflect service at
// https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md
if c.cfgGRPC.enableReflectService {
reflection.Register(c.cfgGRPC.server)
}
if err := c.cfgGRPC.server.Serve(c.cfgGRPC.listener); err != nil { if err := c.cfgGRPC.server.Serve(c.cfgGRPC.listener); err != nil {
fmt.Println("gRPC server error", err) fmt.Println("gRPC server error", err)
} }