[#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 <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2021-01-15 14:53:41 +03:00 committed by Alex Vanin
parent 619f8826e1
commit fa0ea35f83
2 changed files with 18 additions and 0 deletions

View File

@ -43,6 +43,7 @@ func initControlService(c *cfg) {
controlSvc.WithAuthorizedKeys(keys),
controlSvc.WithHealthChecker(c),
controlSvc.WithNetMapSource(c.cfgNetmap.wrapper),
controlSvc.WithNodeState(c),
)
var (

View File

@ -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,
)
}