diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index da8317306..256343f6d 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 f3ab71104..243d45443 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 5ac84d1a1..f83ae19c4 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 000000000..8164ef433 --- /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")) +}