tipselect

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoTipsAvailable is returned when no tips are available in the node.
	ErrNoTipsAvailable = errors.New("no tips available")
	// ErrTipLazy is returned when the chosen tip was lazy already.
	ErrTipLazy = errors.New("tip already lazy")
)

Functions

func TipCaller

func TipCaller(handler interface{}, params ...interface{})

TipCaller is used to signal tip events.

func WalkerStatsCaller

func WalkerStatsCaller(handler interface{}, params ...interface{})

WalkerStatsCaller is used to signal tip selection events.

Types

type Events

type Events struct {
	// TipAdded is fired when a tip is added.
	TipAdded *events.Event
	// TipRemoved is fired when a tip is removed.
	TipRemoved *events.Event
	// TipSelPerformed is fired when a tipselection was performed.
	TipSelPerformed *events.Event
}

Events represents events happening on the tip-selector.

type Score

type Score int

Score defines the score of a tip.

const (
	// ScoreLazy is a lazy tip and should not be selected.
	ScoreLazy Score = iota
	// ScoreSemiLazy is a somewhat lazy tip.
	ScoreSemiLazy
	// ScoreNonLazy is a non-lazy tip.
	ScoreNonLazy
)

type Tip

type Tip struct {
	// Score is the score of the tip.
	Score Score
	// MessageID is the message ID of the tip.
	MessageID hornet.MessageID
	// TimeFirstChild is the timestamp the tip was referenced for the first time by another message.
	TimeFirstChild time.Time
	// ChildrenCount is the amount the tip was referenced by other messages.
	ChildrenCount *atomic.Uint32
}

Tip defines a tip.

type TipSelStats

type TipSelStats struct {
	// The duration of the tip-selection for a single tip.
	Duration time.Duration `json:"duration"`
}

TipSelStats holds the stats for a tipselection run.

type TipSelectionFunc

type TipSelectionFunc = func() (hornet.MessageIDs, error)

TipSelectionFunc is a function which performs a tipselection and returns tips.

type TipSelector

type TipSelector struct {

	// Events are the events that are triggered by the TipSelector.
	Events Events
	// contains filtered or unexported fields
}

TipSelector manages a list of tips and emits events for their removal and addition.

func New

func New(storage *storage.Storage,
	serverMetrics *metrics.ServerMetrics,
	maxDeltaMsgYoungestConeRootIndexToCMI int,
	maxDeltaMsgOldestConeRootIndexToCMI int,
	belowMaxDepth int,
	retentionRulesTipsLimitNonLazy int,
	maxReferencedTipAgeNonLazy time.Duration,
	maxChildrenNonLazy uint32,
	spammerTipsThresholdNonLazy int,
	retentionRulesTipsLimitSemiLazy int,
	maxReferencedTipAgeSemiLazy time.Duration,
	maxChildrenSemiLazy uint32,
	spammerTipsThresholdSemiLazy int) *TipSelector

New creates a new tip-selector.

func (*TipSelector) AddTip

func (ts *TipSelector) AddTip(messageMeta *storage.MessageMetadata)

AddTip adds the given message as a tip.

func (*TipSelector) CleanUpReferencedTips

func (ts *TipSelector) CleanUpReferencedTips() int

CleanUpReferencedTips checks if tips were referenced before and removes them if they reached their maximum age.

func (*TipSelector) GetTipCount added in v1.0.0

func (ts *TipSelector) GetTipCount() (int, int)

GetTipCount returns the current amount of available tips in the non-lazy and semi-lazy pool.

func (*TipSelector) SelectNonLazyTips

func (ts *TipSelector) SelectNonLazyTips() (hornet.MessageIDs, error)

SelectNonLazyTips selects two non-lazy tips.

func (*TipSelector) SelectSemiLazyTips

func (ts *TipSelector) SelectSemiLazyTips() (hornet.MessageIDs, error)

SelectSemiLazyTips selects two semi-lazy tips.

func (*TipSelector) SelectSpammerTips added in v0.5.1

func (ts *TipSelector) SelectSpammerTips() (isSemiLazy bool, tips hornet.MessageIDs, err error)

func (*TipSelector) UpdateScores

func (ts *TipSelector) UpdateScores() int

UpdateScores updates the scores of the tips and removes lazy ones.

Jump to

Keyboard shortcuts

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