diff --git a/netmap/node_info.go b/netmap/node_info.go index 46892116..242807a0 100644 --- a/netmap/node_info.go +++ b/netmap/node_info.go @@ -558,3 +558,21 @@ func (x *NodeInfo) SetOnline() { func (x NodeInfo) IsOnline() bool { return x.m.GetState() == netmap.Online } + +// SetMaintenance sets the state of the node to "maintenance". When a node updates +// information about itself in the network map, this +// state declares temporal unavailability for a node. +// +// See also IsMaintenance. +func (x *NodeInfo) SetMaintenance() { + x.m.SetState(netmap.Maintenance) +} + +// IsMaintenance checks if the node is in the "maintenance" state. +// +// Zero NodeInfo has undefined state. +// +// See also SetMaintenance. +func (x NodeInfo) IsMaintenance() bool { + return x.m.GetState() == netmap.Maintenance +} diff --git a/netmap/node_info_test.go b/netmap/node_info_test.go index 76194b7e..f475132a 100644 --- a/netmap/node_info_test.go +++ b/netmap/node_info_test.go @@ -22,3 +22,26 @@ func TestNodeInfo_SetAttribute(t *testing.T) { n.SetAttribute(key, val) require.Equal(t, val, n.Attribute(key)) } + +func TestNodeInfo_Status(t *testing.T) { + var n NodeInfo + + require.False(t, n.IsOnline()) + require.False(t, n.IsOffline()) + require.False(t, n.IsMaintenance()) + + n.SetOnline() + require.True(t, n.IsOnline()) + require.False(t, n.IsOffline()) + require.False(t, n.IsMaintenance()) + + n.SetOffline() + require.True(t, n.IsOffline()) + require.False(t, n.IsOnline()) + require.False(t, n.IsMaintenance()) + + n.SetMaintenance() + require.True(t, n.IsMaintenance()) + require.False(t, n.IsOnline()) + require.False(t, n.IsOffline()) +}