From dee1d81b04eb6ee18bf0e173eceeb3cd1d0bb740 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 8 Oct 2020 16:17:50 +0300 Subject: [PATCH] [#84] Run netmap service in neofs-node app Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 4 ++++ cmd/neofs-node/main.go | 1 + cmd/neofs-node/morph.go | 13 ------------- cmd/neofs-node/netmap.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 cmd/neofs-node/netmap.go diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index da831730..256343f6 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -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 { diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index f3ab7110..243d4544 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -33,6 +33,7 @@ func init_(c *cfg) { initGRPC(c) + initNetmapService(c) initAccountingService(c) initContainerService(c) initSessionService(c) diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 5ac84d1a..f83ae19c 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -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")) -} diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go new file mode 100644 index 00000000..8164ef43 --- /dev/null +++ b/cmd/neofs-node/netmap.go @@ -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")) +}