msgqueue

package
v0.2.1-rc.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllIndicesCleaner

func AllIndicesCleaner(k Index) bool

AllIndicesCleaner is a cleaner that removes all existing indices

Types

type By

type By func(a, b *message.SSVMessage) bool

By is function to compare messages

func ByConsensusMsgType

func ByConsensusMsgType(messageTypes ...message.ConsensusMessageType) By

ByConsensusMsgType implements By for msg type based priority ()

func ByRound

func ByRound() By

ByRound implements By for round based priority

func (By) Add

func (by By) Add(msgs []*MsgContainer, msg *MsgContainer) []*MsgContainer

Add adds a new container

func (By) Combine

func (by By) Combine(other By) By

Combine runs current By and if result is negative, tries to run the other By.

func (By) Sort

func (by By) Sort(msgs []*MsgContainer)

Sort sorts the given containers

type Cleaner

type Cleaner func(Index) bool

Cleaner is a function for iterating over keys and clean irrelevant ones

func DefaultMsgCleaner

func DefaultMsgCleaner(mid message.Identifier, mts ...message.MsgType) Cleaner

DefaultMsgCleaner cleans ssv msgs from the queue

func SignedMsgCleaner

func SignedMsgCleaner(mid message.Identifier, h message.Height) Cleaner

SignedMsgCleaner cleans consensus messages from the queue it will clean messages of the given identifier and under the given height

func SignedPostConsensusMsgCleaner

func SignedPostConsensusMsgCleaner(mid message.Identifier, h message.Height) Cleaner

SignedPostConsensusMsgCleaner cleans post consensus messages from the queue it will clean messages of the given identifier and under the given height

type Index

type Index struct {
	Name string
	// Mt is the message type
	Mt message.MsgType
	// ID is the identifier
	ID string
	// H (optional) is the height, -1 is treated as nil
	H message.Height
	// Cmt (optional) is the consensus msg type, -1 is treated as nil
	Cmt message.ConsensusMessageType
}

Index is a struct representing an index in msg queue

func DecidedMsgIndex

func DecidedMsgIndex(mid string) Index

DecidedMsgIndex indexes a decided message.SignedMessage by identifier, msg type

func DefaultMsgIndex

func DefaultMsgIndex(mt message.MsgType, mid message.Identifier) Index

DefaultMsgIndex is the default msg index

func SignedMsgIndex

func SignedMsgIndex(msgType message.MsgType, mid string, h message.Height, cmt ...message.ConsensusMessageType) []Index

SignedMsgIndex indexes a message.SignedMessage by identifier, msg type and height

func SignedPostConsensusMsgIndex

func SignedPostConsensusMsgIndex(mid string, h message.Height) Index

SignedPostConsensusMsgIndex indexes a message.SignedPostConsensusMessage by identifier and height

type IndexGenerator

type IndexGenerator func() Index

IndexGenerator generates an index

type IndexIterator

type IndexIterator struct {
	// contains filtered or unexported fields
}

IndexIterator enables to iterate over future created indices

func NewIndexIterator

func NewIndexIterator() *IndexIterator

NewIndexIterator creates a new iterator

func (*IndexIterator) Add

func (ii *IndexIterator) Add(generators ...IndexGenerator) *IndexIterator

Add adds a new generator

func (*IndexIterator) Next

func (ii *IndexIterator) Next() IndexGenerator

Next returns the next generator

func (*IndexIterator) Reset

func (ii *IndexIterator) Reset()

Reset set iterator to 0. NOTE: use only in case we want to reuse the iterator

type Indexer

type Indexer func(msg *message.SSVMessage) Index

Indexer indexes the given message, returns an empty string if not applicable use WithIndexers to inject indexers upon start

func DecidedMsgIndexer

func DecidedMsgIndexer() Indexer

DecidedMsgIndexer is the Indexer used for decided message.SignedMessage

func DefaultMsgIndexer

func DefaultMsgIndexer() Indexer

DefaultMsgIndexer returns the default msg indexer to use for message.SSVMessage

func SignedMsgIndexer

func SignedMsgIndexer() Indexer

SignedMsgIndexer is the Indexer used for message.SignedMessage

func SignedPostConsensusMsgIndexer

func SignedPostConsensusMsgIndexer() Indexer

SignedPostConsensusMsgIndexer is the Indexer used for message.SignedPostConsensusMessage

type MsgContainer

type MsgContainer struct {
	// contains filtered or unexported fields
}

MsgContainer is a container for a message

type MsgQueue

type MsgQueue interface {
	// Add adds a new message to the queue for the matching indices
	Add(msg *message.SSVMessage)
	// Peek returns the first n messages for an index
	Peek(n int, idx Index) []*message.SSVMessage
	// Pop clears and returns the first n messages for an index
	Pop(n int, idx Index) []*message.SSVMessage
	// PopIndices clears and returns the first n messages for indices that are created on demand using the iterator
	PopIndices(n int, generator *IndexIterator) []*message.SSVMessage
	// Purge clears indexed messages for the given index
	Purge(idx Index) int64
	// Clean enables to aid in a custom Cleaner to clear any set of indices
	// TODO: check performance
	Clean(cleaners ...Cleaner) int64
	// Count counts messages for the given index
	Count(idx Index) int
	// Len counts all messages
	Len() int
}

MsgQueue is a message broker for message.SSVMessage

func New

func New(logger *zap.Logger, opt ...Option) (MsgQueue, error)

New creates a new MsgQueue

type Option

type Option func(opts *Options) error

Option helps to configure the Options

func WithIndexers

func WithIndexers(indexers ...Indexer) Option

WithIndexers is an option that configures indexers. it can be called multiple times

type Options

type Options struct {
	Indexers []Indexer
}

Options is a set of message queue options.

func (*Options) Apply

func (opts *Options) Apply(options ...Option) error

Apply applies the given options to this DiscoveryOpts

Jump to

Keyboard shortcuts

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