From 8585e147d03e8d6c3d853e3392ecf6808e2ef8c3 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 24 Sep 2020 10:46:47 +0300 Subject: [PATCH] [#43] cmd/neofs-node: Use morph wrappers as data sources Morph wrappers are being uses as sources for containers and snapshots of network map. Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 2 ++ cmd/neofs-node/container.go | 6 ++++++ cmd/neofs-node/morph.go | 43 +++++++++++++++++++------------------ 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index f30321839..ef7973888 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -14,6 +14,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/container" netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/client" + nmwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" "github.com/nspcc-dev/neofs-node/pkg/network" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" "github.com/nspcc-dev/neofs-node/pkg/util/logger" @@ -108,6 +109,7 @@ type cfgContainer struct { type cfgNetmap struct { scriptHash util.Uint160 + wrapper *nmwrapper.Wrapper fee util.Fixed8 } diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 40618eaf3..6eacdcd6d 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" + "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" containerTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc" containerService "github.com/nspcc-dev/neofs-node/pkg/services/container" containerMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph" @@ -21,6 +22,11 @@ func initContainerService(c *cfg) { cnrClient, err := container.New(staticClient) fatalOnErr(err) + wrap, err := wrapper.New(cnrClient) + fatalOnErr(err) + + c.cfgObject.cnrStorage = wrap // use RPC node as source of containers + metaHdr := new(session.ResponseMetaHeader) xHdr := new(session.XHeader) xHdr.SetKey("test X-Header key") diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index c9c0df2b6..5ac84d1a1 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -14,29 +14,30 @@ func initMorphComponents(c *cfg) { c.cfgMorph.client, err = client.New(c.key, c.viper.GetString(cfgMorphRPCAddress)) fatalOnErr(err) + + staticClient, err := client.NewStatic( + c.cfgMorph.client, + c.cfgNetmap.scriptHash, + c.cfgContainer.fee, + ) + fatalOnErr(err) + + cli, err := netmap.New(staticClient) + fatalOnErr(err) + + wrap, err := wrapper.New(cli) + fatalOnErr(err) + + c.cfgObject.netMapStorage = wrap + c.cfgNetmap.wrapper = wrap } func bootstrapNode(c *cfg) { - if c.cfgNodeInfo.bootType == StorageNode { - staticClient, err := client.NewStatic( - c.cfgMorph.client, - c.cfgNetmap.scriptHash, - c.cfgContainer.fee, - ) - fatalOnErr(err) + peerInfo := new(v2netmap.NodeInfo) + peerInfo.SetAddress(c.localAddr.String()) + peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey)) + peerInfo.SetAttributes(c.cfgNodeInfo.attributes) - cli, err := netmap.New(staticClient) - fatalOnErr(errors.Wrap(err, "bootstrap error")) - - cliWrapper, err := wrapper.New(cli) - fatalOnErr(errors.Wrap(err, "bootstrap error")) - - peerInfo := new(v2netmap.NodeInfo) - peerInfo.SetAddress(c.viper.GetString(cfgBootstrapAddress)) - peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey)) - peerInfo.SetAttributes(c.cfgNodeInfo.attributes) - - err = cliWrapper.AddPeer(peerInfo) - fatalOnErr(errors.Wrap(err, "bootstrap error")) - } + err := c.cfgNetmap.wrapper.AddPeer(peerInfo) + fatalOnErr(errors.Wrap(err, "bootstrap error")) }