forked from TrueCloudLab/frostfs-node
[#1680] morph/netmap: Pre-refactor processing of node states
New network status of storage nodes is going to be introduced. To simplify the addition, it would be useful to prepare the code for this. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
4c94faac67
commit
42fb40e841
4 changed files with 30 additions and 10 deletions
|
@ -7,11 +7,17 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
// TODO: enum can become redundant after neofs-contract#270
|
||||
const (
|
||||
stateOffline int8 = iota
|
||||
stateOnline
|
||||
)
|
||||
|
||||
// UpdatePeerPrm groups parameters of UpdatePeerState operation.
|
||||
type UpdatePeerPrm struct {
|
||||
key []byte
|
||||
|
||||
online bool
|
||||
state int8 // state enum value
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
@ -21,9 +27,11 @@ func (u *UpdatePeerPrm) SetKey(key []byte) {
|
|||
u.key = key
|
||||
}
|
||||
|
||||
// SetState sets node state.
|
||||
// SetOnline marks node to be switched into "online" state.
|
||||
//
|
||||
// Zero UpdatePeerPrm marks node as "offline".
|
||||
func (u *UpdatePeerPrm) SetOnline() {
|
||||
u.online = true
|
||||
u.state = stateOnline
|
||||
}
|
||||
|
||||
// UpdatePeerState changes peer status through Netmap contract call.
|
||||
|
@ -37,8 +45,14 @@ func (c *Client) UpdatePeerState(p UpdatePeerPrm) error {
|
|||
method += "IR"
|
||||
}
|
||||
|
||||
state := netmap.OfflineState
|
||||
if p.online {
|
||||
state := netmap.OfflineState // pre-assign since type of value is unexported
|
||||
|
||||
switch p.state {
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected node's state value %v", p.state))
|
||||
case stateOffline:
|
||||
// already set above
|
||||
case stateOnline:
|
||||
state = netmap.OnlineState
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue