frostfs-node/cmd/neofs-node/morph.go
Alex Vanin 86b9aefcae [#28] Make storage node configurable
To run storage node at dev-env environment it should have
configurable parameters. To keep `cfg` structures we can
read configuration from env and yml config file with viper
and parse values such as script hashes, fees, keys into
`cfg` structures.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2020-10-02 11:25:35 +03:00

40 lines
985 B
Go

package main
import (
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"
)
func initMorphComponents(c *cfg) {
var err error
c.cfgMorph.client, err = client.New(c.key, c.viper.GetString(cfgMorphRPCAddress))
fatalOnErr(err)
}
func bootstrapNode(c *cfg) {
if c.cfgNodeInfo.bootType == StorageNode {
staticClient, err := client.NewStatic(
c.cfgMorph.client,
c.cfgNetmap.scriptHash,
c.cfgContainer.fee,
)
fatalOnErr(err)
cli, err := netmap.New(staticClient)
fatalOnErr(err)
cliWrapper, err := wrapper.New(cli)
fatalOnErr(err)
peerInfo := new(netmap.NodeInfo)
peerInfo.SetAddress(c.viper.GetString(cfgBootstrapAddress))
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
// todo: add attributes as opts
err = cliWrapper.AddPeer(peerInfo)
fatalOnErr(err)
}
}