From b45360b9338c1f2de14162eb78c2adc0b7227e4b Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 11 Jan 2021 14:57:01 +0300 Subject: [PATCH] [#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 --- cmd/neofs-node/main.go | 2 ++ cmd/neofs-node/netmap.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index 430a58c9f..320458ee7 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -64,5 +64,7 @@ func shutdown(c *cfg) { c.log.Info("gRPC server stopped") + goOffline(c) + c.wg.Wait() } diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 3b1a64fa9..3fea962fc 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -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") + } +}