spammer

package
v0.0.0-...-1f0f14a Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeBlock       = "blk"
	TypeTx          = "tx"
	TypeDs          = "ds"
	TypeCustom      = "custom"
	TypeCommitments = "commitments"
	TypeAccounts    = "accounts"
)

Variables

View Source
var (
	ErrFailPostBlock       = ierrors.New("failed to post block")
	ErrFailSendDataBlock   = ierrors.New("failed to send a data block")
	ErrFailGetReferences   = ierrors.New("failed to get references")
	ErrTransactionIsNil    = ierrors.New("provided transaction is nil")
	ErrTransactionInvalid  = ierrors.New("provided transaction is invalid")
	ErrPayloadIsNil        = ierrors.New("provided payload is nil")
	ErrFailToPrepareBatch  = ierrors.New("custom conflict batch could not be prepared")
	ErrInsufficientClients = ierrors.New("insufficient clients to send conflicts")
	ErrInputsNotSolid      = ierrors.New("not all inputs are solid")
	ErrFailPrepareBlock    = ierrors.New("failed to prepare block")
	ErrFailGetAccount      = ierrors.New("failed to get account from the account wallet")
)

Functions

func AccountSpammingFunction

func AccountSpammingFunction(s *Spammer)

func BigWalletsNeeded

func BigWalletsNeeded(rate int, timeUnit, duration time.Duration) int

BigWalletsNeeded calculates how many big wallets needs to be prepared for a spam based on provided spam details.

func CustomConflictSpammingFunc

func CustomConflictSpammingFunc(s *Spammer)

func DataSpammingFunction

func DataSpammingFunction(s *Spammer)

Types

type CommitmentSpamDetails

type CommitmentSpamDetails struct {
	CommitmentType string
}

type ErrorCounter

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

ErrorCounter counts errors that appeared during the spam, as during the spam they are ignored and allows to print the summary (might be useful for debugging).

func NewErrorCount

func NewErrorCount() *ErrorCounter

func (*ErrorCounter) CountError

func (e *ErrorCounter) CountError(err error)

func (*ErrorCounter) GetErrorsSummary

func (e *ErrorCounter) GetErrorsSummary() string

func (*ErrorCounter) GetTotalErrorCount

func (e *ErrorCounter) GetTotalErrorCount() int64

type Logger

type Logger interface {
	Infof(template string, args ...interface{})
	Info(args ...interface{})
	Debugf(template string, args ...interface{})
	Debug(args ...interface{})
	Warn(args ...interface{})
	Warnf(template string, args ...interface{})
	Error(args ...interface{})
	Errorf(template string, args ...interface{})
}

type Options

type Options func(*Spammer)

func WithAccountAlias

func WithAccountAlias(alias string) Options

WithAccountAlias sets the alias of the account that will be used to pay with mana for sent blocks.

func WithBatchesSent

func WithBatchesSent(maxBatchesSent int) Options

WithBatchesSent provides spammer with options regarding rate, time unit, and finishing spam criteria. Provide 0 to one of max parameters to skip it.

func WithClientURL

func WithClientURL(clientURL string) Options

func WithErrorCounter

func WithErrorCounter(errCounter *ErrorCounter) Options

WithErrorCounter allows for setting an error counter object, if not provided a new instance will be created.

func WithEvilScenario

func WithEvilScenario(scenario *evilwallet.EvilScenario) Options

WithEvilScenario provides initWallet of spammer, if omitted spammer will prepare funds based on maxBlkSent parameter.

func WithEvilWallet

func WithEvilWallet(initWallets *evilwallet.EvilWallet) Options

WithEvilWallet provides evil wallet instance, that will handle all spam logic according to provided EvilScenario.

func WithLogTickerInterval

func WithLogTickerInterval(interval time.Duration) Options

WithLogTickerInterval allows for changing interval between progress spamming logs, default is 30s.

func WithNumberOfSpends

func WithNumberOfSpends(n int) Options

WithNumberOfSpends sets how many transactions should be created with the same input, e.g 3 for triple spend, 2 for double spend. For this to work user needs to make sure that there is enough number of clients.

func WithRateSetter

func WithRateSetter(enable bool) Options

WithRateSetter enables setting rate of spammer.

func WithSpamDuration

func WithSpamDuration(maxDuration time.Duration) Options

WithSpamDuration provides spammer with options regarding rate, time unit, and finishing spam criteria. Provide 0 to one of max parameters to skip it.

func WithSpamRate

func WithSpamRate(rate int, timeUnit time.Duration) Options

WithSpamRate provides spammer with options regarding rate, time unit, and finishing spam criteria. Provide 0 to one of max parameters to skip it.

func WithSpammingFunc

func WithSpammingFunc(spammerFunc func(s *Spammer)) Options

WithSpammingFunc sets core function of the spammer with spamming logic, needs to use done spammer's channel to communicate. end of spamming and errors. Default one is the CustomConflictSpammingFunc.

func WithTimeDelayForDoubleSpend

func WithTimeDelayForDoubleSpend(timeDelay time.Duration) Options

type SpamDetails

type SpamDetails struct {
	Rate           int
	TimeUnit       time.Duration
	MaxDuration    time.Duration
	MaxBatchesSent int
}

type SpamType

type SpamType int
const (
	SpamEvilWallet SpamType = iota
	SpamCommitments
)

type Spammer

type Spammer struct {
	SpamDetails   *SpamDetails
	State         *State
	UseRateSetter bool
	SpamType      SpamType
	Clients       models.Connector
	EvilWallet    *evilwallet.EvilWallet
	EvilScenario  *evilwallet.EvilScenario
	// CommitmentManager *CommitmentManager
	ErrCounter  *ErrorCounter
	IssuerAlias string

	TimeDelayBetweenConflicts time.Duration
	NumberOfSpends            int
	// contains filtered or unexported fields
}

Spammer is a utility object for new spammer creations, can be modified by passing options. Mandatory options: WithClients, WithSpammingFunc Not mandatory options, if not provided spammer will use default settings: WithSpamDetails, WithEvilWallet, WithErrorCounter, WithLogTickerInterval.

func NewSpammer

func NewSpammer(options ...Options) *Spammer

NewSpammer is a constructor of Spammer.

func (*Spammer) BatchesPrepared

func (s *Spammer) BatchesPrepared() uint64

func (*Spammer) BlocksSent

func (s *Spammer) BlocksSent() uint64

func (*Spammer) CheckIfAllSent

func (s *Spammer) CheckIfAllSent()

func (*Spammer) PrepareAndPostBlock

func (s *Spammer) PrepareAndPostBlock(txData *models.PayloadIssuanceData, issuerAlias string, clt models.Client)

func (*Spammer) Spam

func (s *Spammer) Spam()

Spam runs the spammer. Function will stop after maxDuration time will pass or when maxBlkSent will be exceeded.

func (*Spammer) StopSpamming

func (s *Spammer) StopSpamming()

StopSpamming finishes tasks before shutting down the spammer.

type SpammerFunc

type SpammerFunc func(*Spammer)

type State

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

Jump to

Keyboard shortcuts

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