8858840751
In previous implementation Inner Ring allowed storage nodes with any state to register in the network. According to the current design, only nodes with ONLINE state are allowed to enter the network map. Create new `state` sub-package of `nodevalidation` package of Inner Ring application. Define `state.NetMapCandidateValidator` type and provide `NodeValidator` interface required by the Inner Ring's processor of `Netmap` contract's notification events. Embed new validator into the one used by the Inner Ring application. From now all `AddPeer` notifications with node state other than `ONLINE` will be denied. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
/*
|
|
Package state collects functionality for verifying states of network map members.
|
|
|
|
NetMapCandidateValidator type provides an interface for checking the network
|
|
map candidates.
|
|
*/
|
|
package state
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
)
|
|
|
|
// NetMapCandidateValidator represents tool which checks state of nodes which
|
|
// are going to register in the NeoFS network (enter the network map).
|
|
//
|
|
// NetMapCandidateValidator can be instantiated using built-in var declaration
|
|
// and currently doesn't require any additional initialization.
|
|
//
|
|
// NetMapCandidateValidator implements
|
|
// github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap.NodeValidator.
|
|
type NetMapCandidateValidator struct {
|
|
}
|
|
|
|
// VerifyAndUpdate checks state of the network map candidate described by
|
|
// netmap.NodeInfo parameter. Returns no error if status is correct, otherwise
|
|
// returns an error describing a violation of the rules:
|
|
//
|
|
// status MUST be ONLINE
|
|
//
|
|
// VerifyAndUpdate does not mutate the parameter in a binary format.
|
|
//
|
|
// See also netmap.NodeInfo.IsOnline/SetOnline.
|
|
func (x *NetMapCandidateValidator) VerifyAndUpdate(node *netmap.NodeInfo) error {
|
|
if node.IsOnline() {
|
|
return nil
|
|
}
|
|
|
|
return errors.New("invalid status: MUST be ONLINE")
|
|
}
|