Documentation
¶
Index ¶
- Constants
- Variables
- func AnalysisMsgRegistry() *message.Registry
- func FPCHeartbeatMessageDefinition() *message.Definition
- func HeartBeatMessageDefinition() *message.Definition
- func NewFPCHeartbeatMessage(hb *FPCHeartbeat) ([]byte, error)
- func NewHeartbeatMessage(hb *Heartbeat) ([]byte, error)
- func NewMetricHeartbeatMessage(hb *MetricHeartbeat) ([]byte, error)
- type FPCHeartbeat
- type Heartbeat
- type MetricHeartbeat
Constants ¶
const ( // HeartbeatMaxOutboundPeersCount is the maximum amount of outbound peer IDs a heartbeat packet can contain. HeartbeatMaxOutboundPeersCount = 4 // HeartbeatMaxInboundPeersCount is the maximum amount of inbound peer IDs a heartbeat packet can contain. HeartbeatMaxInboundPeersCount = 4 // HeartbeatPacketPeerIDSize is the byte size of peer IDs within the heartbeat packet. HeartbeatPacketPeerIDSize = sha256.Size // HeartbeatPacketOutboundIDCountSize is the byte size of the counter indicating the amount of outbound IDs. HeartbeatPacketOutboundIDCountSize = 1 // HeartbeatPacketMinSize is the minimum byte size of a heartbeat packet. HeartbeatPacketMinSize = HeartbeatPacketPeerIDSize + HeartbeatPacketOutboundIDCountSize // HeartbeatPacketMaxSize is the maximum size a heartbeat packet can have. HeartbeatPacketMaxSize = HeartbeatPacketPeerIDSize + HeartbeatPacketOutboundIDCountSize + HeartbeatMaxOutboundPeersCount*sha256.Size + HeartbeatMaxInboundPeersCount*sha256.Size )
const ( // MessageTypeHeartbeat defines the Heartbeat msg type. MessageTypeHeartbeat message.Type = iota + 1 // MessageTypeFPCHeartbeat defines the FPC Heartbeat msg type. MessageTypeFPCHeartbeat // MessageTypeMetricHeartbeat defines the Metric Heartbeat msg type. MessageTypeMetricHeartbeat )
Variables ¶
var ( // ErrInvalidFPCHeartbeat is returned for invalid FPC heartbeats. ErrInvalidFPCHeartbeat = errors.New("invalid FPC heartbeat") )
var ( // ErrInvalidHeartbeat is returned for invalid heartbeats. ErrInvalidHeartbeat = errors.New("invalid heartbeat") )
var ( // ErrInvalidMetricHeartbeat is returned for invalid Metric heartbeats. ErrInvalidMetricHeartbeat = errors.New("invalid Metric heartbeat") )
var ( // ErrMalformedPacket is returned when malformed packets are tried to be parsed. ErrMalformedPacket = errors.New("malformed packet") )
var ( // MetricHeartbeatMessageDefinition defines a metric heartbeat message's format. MetricHeartbeatMessageDefinition = &message.Definition{ ID: MessageTypeMetricHeartbeat, MaxBytesLength: 65535, VariableLength: true, } )
Functions ¶
func AnalysisMsgRegistry ¶
AnalysisMsgRegistry gets the analysisMsgRegistry.
func FPCHeartbeatMessageDefinition ¶
func FPCHeartbeatMessageDefinition() *message.Definition
FPCHeartbeatMessageDefinition gets the fpcHeartbeatMessageDefinition.
func HeartBeatMessageDefinition ¶
func HeartBeatMessageDefinition() *message.Definition
HeartBeatMessageDefinition gets the heartbeatMessageDefinition.
func NewFPCHeartbeatMessage ¶
func NewFPCHeartbeatMessage(hb *FPCHeartbeat) ([]byte, error)
NewFPCHeartbeatMessage serializes the given FPC heartbeat into a byte slice and adds a tlv header to the packet. message = tlv header + serialized packet
func NewHeartbeatMessage ¶
NewHeartbeatMessage serializes the given heartbeat into a byte slice and adds a tlv header to the packet. message = tlv header + serialized packet
func NewMetricHeartbeatMessage ¶
func NewMetricHeartbeatMessage(hb *MetricHeartbeat) ([]byte, error)
NewMetricHeartbeatMessage serializes the given Metric heartbeat into a byte slice and adds a TLV header to the packet. message = TLV header + serialized packet.
Types ¶
type FPCHeartbeat ¶
type FPCHeartbeat struct {
// The ID of the node who sent the heartbeat.
// Must be contained when a heartbeat is serialized.
OwnID []byte
// RoundStats contains stats about an FPC round.
RoundStats vote.RoundStats
// Finalized contains the finalized conflicts within the last FPC round.
Finalized map[string]vote.Opinion
}
FPCHeartbeat represents a heartbeat packet.
func ParseFPCHeartbeat ¶
func ParseFPCHeartbeat(data []byte) (*FPCHeartbeat, error)
ParseFPCHeartbeat parses a slice of bytes (serialized packet) into a FPC heartbeat.
func (FPCHeartbeat) Bytes ¶
func (hb FPCHeartbeat) Bytes() ([]byte, error)
Bytes return the FPC heartbeat encoded as bytes
type Heartbeat ¶
type Heartbeat struct {
// The ID of the node who sent the heartbeat.
// Must be contained when a heartbeat is serialized.
OwnID []byte
// The IDs of the outbound peers. Can be empty or nil.
// It must not exceed HeartbeatMaxOutboundPeersCount.
OutboundIDs [][]byte
// The IDs of the inbound peers. Can be empty or nil.
// It must not exceed HeartbeatMaxInboundPeersCount.
InboundIDs [][]byte
}
Heartbeat represents a heartbeat packet.
func ParseHeartbeat ¶
ParseHeartbeat parses a slice of bytes (serialized packet) into a heartbeat.
type MetricHeartbeat ¶
type MetricHeartbeat struct {
// The ID of the node who sent the heartbeat.
// Must be contained when a heartbeat is serialized.
OwnID []byte
// OS defines the operating system of the node.
OS string
// Arch defines the system architecture of the node.
Arch string
// NumCPU defines number of logical cores of the node.
NumCPU int
// CPUUsage defines the CPU usage of the node.
CPUUsage float64
// MemoryUsage defines the memory usage of the node.
MemoryUsage uint64
}
MetricHeartbeat represents a metric heartbeat packet.
func ParseMetricHeartbeat ¶
func ParseMetricHeartbeat(data []byte) (*MetricHeartbeat, error)
ParseMetricHeartbeat parses a slice of bytes (serialized packet) into a Metric heartbeat.
func (MetricHeartbeat) Bytes ¶
func (hb MetricHeartbeat) Bytes() ([]byte, error)
Bytes return the Metric heartbeat encoded as bytes.