[#298] cmd/node: Go offline on application shutdown
Transfer the state of the node to offline when the application is shut down. Updating the state is done by calling UpdateState method of Netmap contract. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
159351fd55
commit
b45360b933
2 changed files with 18 additions and 0 deletions
|
@ -64,5 +64,7 @@ func shutdown(c *cfg) {
|
|||
|
||||
c.log.Info("gRPC server stopped")
|
||||
|
||||
goOffline(c)
|
||||
|
||||
c.wg.Wait()
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||
netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
|
||||
|
@ -114,3 +115,18 @@ func initState(c *cfg) {
|
|||
func addNewEpochNotificationHandler(c *cfg, h event.Handler) {
|
||||
addNetmapNotificationHandler(c, newEpochNotification, h)
|
||||
}
|
||||
|
||||
func goOffline(c *cfg) {
|
||||
err := c.cfgNetmap.wrapper.UpdatePeerState(
|
||||
crypto.MarshalPublicKey(&c.key.PublicKey),
|
||||
wrapper.StateOffline,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
c.log.Error("could not go offline",
|
||||
zap.String("error", err.Error()),
|
||||
)
|
||||
} else {
|
||||
c.log.Info("request to go offline successfully sent")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue