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 // HeartbeatPacketNetworkIDBytesCountSize is byte size of the counter indicating the amount of networkID bytes. HeartbeatPacketNetworkIDBytesCountSize = 1 // HeartbeatPacketMaxNetworkIDBytesSize is the maximum length of network ID string in bytes. // 10 bytes should be enough for vXX.XX.XXX HeartbeatPacketMaxNetworkIDBytesSize = 10 // HeartbeatPacketMinSize is the minimum byte size of a heartbeat packet. HeartbeatPacketMinSize = HeartbeatPacketNetworkIDBytesCountSize + HeartbeatPacketPeerIDSize + HeartbeatPacketOutboundIDCountSize // HeartbeatPacketMaxSize is the maximum size a heartbeat packet can have. HeartbeatPacketMaxSize = HeartbeatPacketNetworkIDBytesCountSize + HeartbeatPacketMaxNetworkIDBytesSize + 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") // ErrInvalidFPCHeartbeatVersion is returned for invalid FPC heartbeat versions. ErrInvalidFPCHeartbeatVersion = errors.New("invalid FPC heartbeat version") )
var ( // ErrInvalidHeartbeat is returned for invalid heartbeats. ErrInvalidHeartbeat = errors.New("invalid heartbeat") // ErrEmptyNetworkVersion is returned for packets not containing a network ID. ErrEmptyNetworkVersion = errors.New("empty network version in heartbeat") // ErrInvalidHeartbeatNetworkVersion is returned for malformed network version. ErrInvalidHeartbeatNetworkVersion = errors.New("wrong or missing network version in packet") )
var ( // ErrInvalidMetricHeartbeat is returned for invalid Metric heartbeats. ErrInvalidMetricHeartbeat = errors.New("invalid Metric heartbeat") // ErrInvalidMetricHeartbeatVersion is returned for invalid Metric heartbeat versions. ErrInvalidMetricHeartbeatVersion = errors.New("invalid Metric heartbeat version") )
var ErrMalformedPacket = errors.New("malformed packet")
ErrMalformedPacket is returned when malformed packets are tried to be parsed.
var MetricHeartbeatMessageDefinition = &message.Definition{ ID: MessageTypeMetricHeartbeat, MaxBytesLength: 65535, VariableLength: true, }
MetricHeartbeatMessageDefinition defines a metric heartbeat message's format.
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 version of GoShimmer. Version string // 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]opinion.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 { // NetworkID is the id of the network the node participates in. For example, "v0.2.2". NetworkID []byte // 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 version of GoShimmer. Version string // 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.