[#84] Run netmap service in neofs-node app

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-08 16:17:50 +03:00 committed by Alex Vanin
parent 20c27d0542
commit dee1d81b04
4 changed files with 41 additions and 13 deletions

View file

@ -152,8 +152,12 @@ type cfgNetmap struct {
type BootstrapType uint32
type cfgNodeInfo struct {
// values from config
bootType BootstrapType
attributes []*netmap.Attribute
// values at runtime
info *netmap.NodeInfo
}
type cfgObject struct {

View file

@ -33,6 +33,7 @@ func init_(c *cfg) {
initGRPC(c)
initNetmapService(c)
initAccountingService(c)
initContainerService(c)
initSessionService(c)

View file

@ -1,12 +1,9 @@
package main
import (
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
"github.com/pkg/errors"
)
func initMorphComponents(c *cfg) {
@ -31,13 +28,3 @@ func initMorphComponents(c *cfg) {
c.cfgObject.netMapStorage = wrap
c.cfgNetmap.wrapper = wrap
}
func bootstrapNode(c *cfg) {
peerInfo := new(v2netmap.NodeInfo)
peerInfo.SetAddress(c.localAddr.String())
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
peerInfo.SetAttributes(c.cfgNodeInfo.attributes)
err := c.cfgNetmap.wrapper.AddPeer(peerInfo)
fatalOnErr(errors.Wrap(err, "bootstrap error"))
}

36
cmd/neofs-node/netmap.go Normal file
View file

@ -0,0 +1,36 @@
package main
import (
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
crypto "github.com/nspcc-dev/neofs-crypto"
netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
"github.com/pkg/errors"
)
func initNetmapService(c *cfg) {
peerInfo := new(netmap.NodeInfo)
peerInfo.SetAddress(c.localAddr.String())
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
peerInfo.SetAttributes(c.cfgNodeInfo.attributes)
c.cfgNodeInfo.info = peerInfo
netmapGRPC.RegisterNetmapServiceServer(c.cfgGRPC.server,
netmapTransportGRPC.New(
netmapService.NewSignService(
c.key,
netmapService.NewExecutionService(
c.cfgNodeInfo.info,
c.apiVersion,
),
),
),
)
}
func bootstrapNode(c *cfg) {
err := c.cfgNetmap.wrapper.AddPeer(c.cfgNodeInfo.info)
fatalOnErr(errors.Wrap(err, "bootstrap error"))
}