packet

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 1

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 blk type.
	MessageTypeHeartbeat message.Type = iota + 1
	// MessageTypeMetricHeartbeat defines the Metric Heartbeat blk type.
	MessageTypeMetricHeartbeat
)

Variables

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 = errors.New("malformed packet")

ErrMalformedPacket is returned when malformed packets are tried to be parsed.

View Source
var MetricHeartbeatBlockDefinition = &message.Definition{
	ID:             MessageTypeMetricHeartbeat,
	MaxBytesLength: 65535,
	VariableLength: true,
}

MetricHeartbeatBlockDefinition defines a metric heartbeat block's format.

Functions

func AnalysisBlkRegistry added in v0.9.2

func AnalysisBlkRegistry() *message.Registry

AnalysisBlkRegistry gets the analysisBlkRegistry.

func HeartBeatBlockDefinition added in v0.9.2

func HeartBeatBlockDefinition() *message.Definition

HeartBeatBlockDefinition gets the heartbeatBlockDefinition.

func NewHeartbeatBlock added in v0.9.2

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

NewHeartbeatBlock serializes the given heartbeat into a byte slice and adds a tlv header to the packet. block = tlv header + serialized packet

func NewMetricHeartbeatBlock added in v0.9.2

func NewMetricHeartbeatBlock(hb *MetricHeartbeat) ([]byte, error)

NewMetricHeartbeatBlock serializes the given Metric heartbeat into a byte slice and adds a TLV header to the packet. block = TLV header + serialized packet.

Types

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