[#15] Add bootstrap routine to node application

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-08-31 18:20:02 +03:00
parent 73b8ed4203
commit a76a97ec01
2 changed files with 27 additions and 1 deletions

View file

@ -38,6 +38,7 @@ func init_(c *cfg) {
func bootUp(c *cfg) { func bootUp(c *cfg) {
serveGRPC(c) serveGRPC(c)
bootstrapNode(c)
} }
func wait(c *cfg) { func wait(c *cfg) {

View file

@ -1,13 +1,38 @@
package main package main
import ( import (
"github.com/nspcc-dev/neo-go/pkg/util"
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"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
) )
func initMorphComponents(c *cfg) { func initMorphComponents(c *cfg) {
var err error var err error
c.cfgMorph.client, err = client.New(c.key, c.cfgMorph.endpoint) c.cfgMorph.client, err = client.New(c.key, c.cfgMorph.endpoint)
fatalOnErr(err) fatalOnErr(err)
} }
func bootstrapNode(c *cfg) {
if c.cfgNodeInfo.bootType == StorageNode {
u160, err := util.Uint160DecodeStringLE(c.cfgNetmap.scriptHash)
fatalOnErr(err)
staticClient, err := client.NewStatic(c.cfgMorph.client, u160, c.cfgContainer.fee)
fatalOnErr(err)
cli, err := netmap.New(staticClient)
fatalOnErr(err)
peerInfo := new(netmap.PeerInfo)
peerInfo.SetAddress(c.cfgNodeInfo.address)
peerInfo.SetPublicKey(crypto.MarshalPublicKey(&c.key.PublicKey))
// todo: add attributes as opts
args := new(netmap.AddPeerArgs)
args.SetInfo(*peerInfo)
err = cli.AddPeer(*args)
fatalOnErr(err)
}
}