packet

package
v0.2.4-0...-2c2ceb1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2020 License: Apache-2.0, BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

View Source
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")
)
View Source
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")
)
View Source
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")
)
View Source
var (
	// ErrMalformedPacket is returned when malformed packets are tried to be parsed.
	ErrMalformedPacket = errors.New("malformed packet")
)
View Source
var (
	// MetricHeartbeatMessageDefinition defines a metric heartbeat message's format.
	MetricHeartbeatMessageDefinition = &message.Definition{
		ID:             MessageTypeMetricHeartbeat,
		MaxBytesLength: 65535,
		VariableLength: true,
	}
)

Functions

func AnalysisMsgRegistry

func AnalysisMsgRegistry() *message.Registry

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

func NewHeartbeatMessage(hb *Heartbeat) ([]byte, error)

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]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 {
	// 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

func ParseHeartbeat(data []byte) (*Heartbeat, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL