From fa0ea35f83e08e7a3c08d7f1066d3c0c14233df7 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 15 Jan 2021 14:53:41 +0300 Subject: [PATCH] [#315] cmd/node: Implement node status updating in application Call Netmap contract on SetNetmapStatus rpc of Control service (AddPeer method if new status is ONLINE, UpdatePeerState method otherwise). Signed-off-by: Leonard Lyubich --- cmd/neofs-node/control.go | 1 + cmd/neofs-node/netmap.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cmd/neofs-node/control.go b/cmd/neofs-node/control.go index 0b09ff8e4..ed9a69894 100644 --- a/cmd/neofs-node/control.go +++ b/cmd/neofs-node/control.go @@ -43,6 +43,7 @@ func initControlService(c *cfg) { controlSvc.WithAuthorizedKeys(keys), controlSvc.WithHealthChecker(c), controlSvc.WithNetMapSource(c.cfgNetmap.wrapper), + controlSvc.WithNodeState(c), ) var ( diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 2e1d2acb2..f97b63cbd 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -178,3 +178,20 @@ func goOffline(c *cfg) { c.log.Info("request to go offline successfully sent") } } + +func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error { + if st == control.NetmapStatus_ONLINE { + return c.cfgNetmap.wrapper.AddPeer(c.cfgNodeInfo.info) + } + + var apiState netmap.NodeState + + if st == control.NetmapStatus_OFFLINE { + apiState = netmap.NodeStateOffline + } + + return c.cfgNetmap.wrapper.UpdatePeerState( + crypto.MarshalPublicKey(&c.key.PublicKey), + apiState, + ) +}