From a76a97ec014c81692fa165f37c55f30253fee141 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 31 Aug 2020 18:20:02 +0300 Subject: [PATCH] [#15] Add bootstrap routine to node application Signed-off-by: Alex Vanin --- cmd/neofs-node/main.go | 1 + cmd/neofs-node/morph.go | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 400ab91c2..e6fd51c37 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -38,6 +38,7 @@ func init_(c *cfg) { func bootUp(c *cfg) { serveGRPC(c) + bootstrapNode(c) } func wait(c *cfg) { diff --git a/cmd/neofs-node/morph.go b/cmd/neofs-node/morph.go index 4c924c47b..41448d6b2 100644 --- a/cmd/neofs-node/morph.go +++ b/cmd/neofs-node/morph.go @@ -1,13 +1,38 @@ package main 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/netmap" ) func initMorphComponents(c *cfg) { var err error c.cfgMorph.client, err = client.New(c.key, c.cfgMorph.endpoint) - 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) + } +}