2020-09-03 14:04:04 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-09-03 14:04:04 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
|
2020-09-03 14:04:04 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2021-09-09 11:55:01 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2020-09-03 14:04:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type UpdatePeer struct {
|
2023-04-27 14:57:27 +00:00
|
|
|
PubKey *keys.PublicKey
|
2022-06-08 23:18:26 +00:00
|
|
|
|
2023-04-27 14:57:27 +00:00
|
|
|
State netmap.NodeState
|
2021-09-09 11:55:01 +00:00
|
|
|
|
|
|
|
// For notary notifications only.
|
|
|
|
// Contains raw transactions of notary request.
|
2023-04-27 14:57:27 +00:00
|
|
|
Request *payload.P2PNotaryRequest
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (UpdatePeer) MorphEvent() {}
|
|
|
|
|
2022-09-19 16:21:35 +00:00
|
|
|
// Online returns true if node's state is requested to be switched
|
|
|
|
// to "online".
|
2022-06-08 23:18:26 +00:00
|
|
|
func (s UpdatePeer) Online() bool {
|
2023-04-27 14:57:27 +00:00
|
|
|
return s.State == netmap.NodeStateOnline
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
2022-09-19 16:21:35 +00:00
|
|
|
// Maintenance returns true if node's state is requested to be switched
|
|
|
|
// to "maintenance".
|
|
|
|
func (s UpdatePeer) Maintenance() bool {
|
2023-04-27 14:57:27 +00:00
|
|
|
return s.State == netmap.NodeStateMaintenance
|
2022-09-19 16:21:35 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 14:04:04 +00:00
|
|
|
func (s UpdatePeer) PublicKey() *keys.PublicKey {
|
2023-04-27 14:57:27 +00:00
|
|
|
return s.PubKey
|
2020-09-03 14:04:04 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 11:55:01 +00:00
|
|
|
// NotaryRequest returns raw notary request if notification
|
|
|
|
// was received via notary service. Otherwise, returns nil.
|
|
|
|
func (s UpdatePeer) NotaryRequest() *payload.P2PNotaryRequest {
|
2023-04-27 14:57:27 +00:00
|
|
|
return s.Request
|
2021-09-09 11:55:01 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 11:34:28 +00:00
|
|
|
func (s *UpdatePeer) decodeState(state int64) error {
|
2023-04-27 14:57:27 +00:00
|
|
|
switch s.State = netmap.NodeState(state); s.State {
|
2022-09-28 11:34:28 +00:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("unsupported node state %d", state)
|
|
|
|
case
|
|
|
|
netmap.NodeStateOffline,
|
|
|
|
netmap.NodeStateOnline,
|
|
|
|
netmap.NodeStateMaintenance:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 11:55:01 +00:00
|
|
|
const expectedItemNumUpdatePeer = 2
|