Documentation ¶
Index ¶
- Variables
- type Duration
- type Heartbeat
- type HeartbeatDTO
- type HeartbeatStorageHandler
- type MessageHandler
- type MessageProcessor
- type Monitor
- func (m *Monitor) GetHeartbeats() []PubKeyHeartbeat
- func (m *Monitor) IsInterfaceNil() bool
- func (m *Monitor) ProcessReceivedMessage(message p2p.MessageP2P, _ func(buffToSend []byte)) error
- func (m *Monitor) SaveMultipleHeartbeatMessageInfos(pubKeysToSave map[string]*heartbeatMessageInfo)
- func (m *Monitor) SetAppStatusHandler(ash core.AppStatusHandler) error
- type PeerMessenger
- type PubKeyHeartbeat
- type RealTimer
- type Sender
- type Timer
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyPublicKeysMap = errors.New("nil or empty public keys map")
ErrEmptyPublicKeysMap signals that a nil or empty public keys map has been provided
var ErrFetchGenesisTimeFromDb = errors.New("monitor: can't get genesis time from db")
ErrFetchGenesisTimeFromDb signals that the genesis time cannot be fetched from db
var ErrInvalidMaxDurationPeerUnresponsive = errors.New("invalid max duration to declare the peer unresponsive")
ErrInvalidMaxDurationPeerUnresponsive signals that the duration provided is invalid
var ErrMarshalGenesisTime = errors.New("monitor: can't marshal genesis time")
ErrMarshalGenesisTime signals that the marshaling of the genesis time didn't work
var ErrNilAppStatusHandler = errors.New("nil AppStatusHandler")
ErrNilAppStatusHandler defines the error for setting a nil AppStatusHandler
var ErrNilDataToProcess = errors.New("nil data to process")
ErrNilDataToProcess signals that nil data was provided
var ErrNilHeartbeatStorer = errors.New("nil heartbeat storer")
ErrNilHeartbeatStorer signals that the provided heartbeat storer is nil
var ErrNilKeyGenerator = errors.New("key generator is nil")
ErrNilKeyGenerator is raised when a valid key generator is expected but nil used
var ErrNilMarshalizer = errors.New("nil marshalizer")
ErrNilMarshalizer signals that a nil marshalizer has been provided
var ErrNilMessage = errors.New("nil message")
ErrNilMessage signals that a nil message has been received
var ErrNilMessageHandler = errors.New("nil message handler")
ErrNilMessageHandler signals that the provided message handler is nil
var ErrNilMessenger = errors.New("nil P2P Messenger")
ErrNilMessenger signals that a nil p2p messenger has been provided
var ErrNilMonitorDb = errors.New("nil monitor db")
ErrNilMonitorDb signals that a nil monitor db was provided
var ErrNilPrivateKey = errors.New("nil private key")
ErrNilPrivateKey signals that a nil private key has been provided
var ErrNilShardCoordinator = errors.New("nil shard coordinator")
ErrNilShardCoordinator signals that an operation has been attempted to or with a nil shard coordinator
var ErrNilSingleSigner = errors.New("nil single signer")
ErrNilSingleSigner signals that a nil single signer has been provided
var ErrNilTimer = errors.New("nil time getter handler")
ErrNilTimer signals that a nil time getter handler has been provided
var ErrPropertyTooLong = errors.New("property too long in Heartbeat")
ErrPropertyTooLong signals that one of the properties is too long
var ErrStoreGenesisTimeToDb = errors.New("monitor: can't store genesis time")
ErrStoreGenesisTimeToDb signals that the genesis time cannot be store to db
var ErrUnmarshalGenesisTime = errors.New("monitor: can't unmarshal genesis time")
ErrUnmarshalGenesisTime signals that the unmarshaling of the genesis time didn't work
Functions ¶
This section is empty.
Types ¶
type Duration ¶
Duration is a wrapper of the original Duration struct that has JSON marshal and unmarshal capabilities golang issue: https://github.com/golang/go/issues/10275
func (Duration) MarshalJSON ¶
MarshalJSON is called when a json marshal is triggered on this field
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON is called when a json unmarshal is triggered on this field
type Heartbeat ¶
type Heartbeat struct { Payload []byte Pubkey []byte Signature []byte ShardID uint32 VersionNumber string NodeDisplayName string }
Heartbeat represents the heartbeat message that is sent between peers
type HeartbeatDTO ¶
type HeartbeatDTO struct { LastUptimeDowntime time.Time GenesisTime time.Time TimeStamp time.Time VersionNumber string NodeDisplayName string MaxDurationPeerUnresponsive time.Duration MaxInactiveTime Duration TotalUpTime Duration TotalDownTime Duration ReceivedShardID uint32 ComputedShardID uint32 IsValidator bool IsActive bool }
HeartbeatDTO is the struct used for handling DB operations for heartbeatMessageInfo struct
type HeartbeatStorageHandler ¶
type HeartbeatStorageHandler interface { LoadGenesisTime() (time.Time, error) UpdateGenesisTime(genesisTime time.Time) error LoadHbmiDTO(pubKey string) (*HeartbeatDTO, error) SavePubkeyData(pubkey []byte, heartbeat *HeartbeatDTO) error LoadKeys() ([][]byte, error) SaveKeys(peersSlice [][]byte) error IsInterfaceNil() bool }
HeartbeatStorageHandler defines what a heartbeat's storer should do
type MessageHandler ¶
type MessageHandler interface { CreateHeartbeatFromP2pMessage(message p2p.MessageP2P) (*Heartbeat, error) IsInterfaceNil() bool }
MessageHandler defines what a message processor for heartbeat should do
type MessageProcessor ¶
type MessageProcessor struct {
// contains filtered or unexported fields
}
MessageProcessor is the struct that will handle heartbeat message verifications and conversion between heartbeatMessageInfo and HeartbeatDTO
func NewMessageProcessor ¶
func NewMessageProcessor( singleSigner crypto.SingleSigner, keygen crypto.KeyGenerator, marshalizer marshal.Marshalizer, ) (*MessageProcessor, error)
NewMessageProcessor will return a new instance of MessageProcessor
func (*MessageProcessor) CreateHeartbeatFromP2pMessage ¶ added in v1.0.23
func (mp *MessageProcessor) CreateHeartbeatFromP2pMessage(message p2p.MessageP2P) (*Heartbeat, error)
CreateHeartbeatFromP2pMessage will return a heartbeat if all the checks pass
func (*MessageProcessor) IsInterfaceNil ¶
func (mp *MessageProcessor) IsInterfaceNil() bool
IsInterfaceNil returns true if there is no value under the interface
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor represents the heartbeat component that processes received heartbeat messages
func NewMonitor ¶
func NewMonitor( marshalizer marshal.Marshalizer, maxDurationPeerUnresponsive time.Duration, pubKeysMap map[uint32][]string, genesisTime time.Time, messageHandler MessageHandler, storer HeartbeatStorageHandler, timer Timer, ) (*Monitor, error)
NewMonitor returns a new monitor instance
func (*Monitor) GetHeartbeats ¶
func (m *Monitor) GetHeartbeats() []PubKeyHeartbeat
GetHeartbeats returns the heartbeat status
func (*Monitor) IsInterfaceNil ¶
IsInterfaceNil returns true if there is no value under the interface
func (*Monitor) ProcessReceivedMessage ¶
func (m *Monitor) ProcessReceivedMessage(message p2p.MessageP2P, _ func(buffToSend []byte)) error
ProcessReceivedMessage satisfies the p2p.MessageProcessor interface so it can be called by the p2p subsystem each time a new heartbeat message arrives
func (*Monitor) SaveMultipleHeartbeatMessageInfos ¶
SaveMultipleHeartbeatMessageInfos stores all heartbeatMessageInfos to the storer
func (*Monitor) SetAppStatusHandler ¶
func (m *Monitor) SetAppStatusHandler(ash core.AppStatusHandler) error
SetAppStatusHandler will set the AppStatusHandler which will be used for monitoring
type PeerMessenger ¶
PeerMessenger defines a subset of the p2p.Messenger interface
type PubKeyHeartbeat ¶
type PubKeyHeartbeat struct { TimeStamp time.Time `json:"timeStamp"` HexPublicKey string `json:"hexPublicKey"` VersionNumber string `json:"versionNumber"` NodeDisplayName string `json:"nodeDisplayName"` TotalUpTime int `json:"totalUpTimeSec"` TotalDownTime int `json:"totalDownTimeSec"` MaxInactiveTime Duration `json:"maxInactiveTime"` ReceivedShardID uint32 `json:"receivedShardID"` ComputedShardID uint32 `json:"computedShardID"` IsValidator bool `json:"isValidator"` IsActive bool `json:"isActive"` }
PubKeyHeartbeat returns the heartbeat status for a public key
type RealTimer ¶
type RealTimer struct { }
RealTimer is an implementation of Timer and uses real time.now
func (*RealTimer) IsInterfaceNil ¶
IsInterfaceNil verifies if the interface is nil
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender periodically sends heartbeat messages on a pubsub topic
func NewSender ¶
func NewSender( peerMessenger PeerMessenger, singleSigner crypto.SingleSigner, privKey crypto.PrivateKey, marshalizer marshal.Marshalizer, topic string, shardCoordinator sharding.Coordinator, versionNumber string, nodeDisplayName string, ) (*Sender, error)
NewSender will create a new sender instance
func (*Sender) SendHeartbeat ¶
SendHeartbeat broadcasts a new heartbeat message