messages

package
v0.0.0-...-d90da2b Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package messages allows for encoding and decoding messages to broadcast over gossip.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Broadcast

func Broadcast(m Message, onDone func()) (memberlist.Broadcast, error)

Broadcast converts m into a memberlist Broadcast. m should not change once being converted into a Broadcast.

onDone will be called once the message has been broadcasted or invalidated.

func Decode

func Decode(buf []byte, m Message) error

Decode decodes a message from Parse.

func Encode

func Encode(m Message) (raw []byte, err error)

Encode encodes m into a byte slice that can be broadcast to other peers. Encode will panic if the Type of m is invalid or unknown.

Types

type Message

type Message interface {
	// Type returns the Type of the message. Type must be a known, valid type.
	Type() Type

	// Invalidates should return true if this message takes precedence over m.
	Invalidates(m Message) bool

	// Cache should return true if this Message should be cached into the local
	// state. Messages in the local state will be synchronized with peers over
	// time, and is useful for anti-entropy.
	Cache() bool
}

Message is a payload that can be gossiped to other peers.

type State

type State struct {
	// Name of the node this state change is for.
	NodeName string
	// New State of the node.
	NewState peer.State
	// Time the state was generated.
	Time lamport.Time
}

State represents a State change broadcast from a node.

func (*State) Cache

func (s *State) Cache() bool

Cache implements Message.

func (*State) Invalidates

func (s *State) Invalidates(m Message) bool

Invalidates implements Message.

func (State) String

func (s State) String() string

String returns the string representation of the State message.

func (*State) Type

func (s *State) Type() Type

Type implements Message.

type Type

type Type uint8

Type of the message. Encoded along with the payload to be able to determine what message was sent during decoding.

const (
	TypeInvalid Type = iota // TypeInvalid is an invalid type.
	TypeState               // TypeState is used for a State broadcast
)

Types for messages.

func Parse

func Parse(raw []byte) (buf []byte, ty Type, err error)

Parse parses an encoded buffer returned by Encode. The resulting buf can be passed to Decode. Returns an error if the magic header or type is invalid.

buf will be a slice referencing data in raw; do not modify raw until you are finished with the message.

func (Type) String

func (t Type) String() string

String returns the string representation of t.

Jump to

Keyboard shortcuts

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