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