internal

package
v0.33.31 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const NonceSize = 8

Variables

This section is empty.

Functions

This section is empty.

Types

type ProtocolSpamRecordEntity

type ProtocolSpamRecordEntity struct {
	model.ProtocolSpamRecord
}

ProtocolSpamRecordEntity is an entity that represents a spam record. It is internally used by the SpamRecordCache to store the spam records in the cache. The identifier of this entity is the origin id of the spam record. This entails that the spam records are deduplicated by origin id.

func (ProtocolSpamRecordEntity) Checksum

Checksum returns the origin id of the spam record, it does not have any purpose in the cache. It is implemented to satisfy the flow.Entity interface.

func (ProtocolSpamRecordEntity) ID

ID returns the origin id of the spam record, which is used as the unique identifier of the entity for maintenance and deduplication purposes in the cache.

type ReportedMisbehaviorWork

type ReportedMisbehaviorWork struct {
	// Channel is the channel that the misbehavior report is about.
	Channel channels.Channel

	// OriginId is the ID of the peer that the misbehavior report is about.
	OriginId flow.Identifier

	// Reason is the reason of the misbehavior.
	Reason network.Misbehavior

	// Nonce is a random nonce value that is used to make the key of the struct unique in the queue even when
	// the same misbehavior report is reported multiple times. This is needed as we expect the same misbehavior report
	// to be reported multiple times when an attack persists for a while. We don't want to deduplicate the misbehavior
	// reports in the queue as we want to penalize the misbehaving node for each report.
	Nonce [NonceSize]byte

	// Penalty is the penalty value of the misbehavior.
	// We use `rlp:"-"` to ignore this field when serializing the struct to RLP to determine the key of this struct
	// when storing in the queue. Hence, the penalty value does "not" contribute to the key for storing in the queue.
	// As RLP encoding does not support float64, we cannot use this field as the key of the
	// struct. As we use a random nonce value for the key of the struct, we can be sure that we will not have a collision
	// in the queue, and duplicate reports will be accepted with unique keys.
	Penalty float64 `rlp:"-"`
}

ReportedMisbehaviorWork is an internal data structure for "temporarily" storing misbehavior reports in the queue till they are processed by the worker.

type SpamRecordCache

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

SpamRecordCache is a cache that stores spam records at the protocol layer for ALSP.

func NewSpamRecordCache

func NewSpamRecordCache(sizeLimit uint32, logger zerolog.Logger, collector module.HeroCacheMetrics, recordFactory model.SpamRecordFactoryFunc) *SpamRecordCache

NewSpamRecordCache creates a new SpamRecordCache. Args: - sizeLimit: the maximum number of records that the cache can hold. - logger: the logger used by the cache. - collector: the metrics collector used by the cache. - recordFactory: a factory function that creates a new spam record. Returns: - *SpamRecordCache, the created cache. Note that the cache is supposed to keep the spam record for the authorized (staked) nodes. Since the number of such nodes is expected to be small, we do not eject any records from the cache. The cache size must be large enough to hold all the spam records of the authorized nodes. Also, this cache is keeping at most one record per origin id, so the size of the cache must be at least the number of authorized nodes.

func (*SpamRecordCache) AdjustWithInit added in v0.33.1

func (s *SpamRecordCache) AdjustWithInit(originId flow.Identifier, adjustFunc model.RecordAdjustFunc) (float64, error)

AdjustWithInit applies the given adjust function to the spam record of the given origin id. Returns the Penalty value of the record after the adjustment. It returns an error if the adjustFunc returns an error or if the record does not exist. Note that if the record does not exist, the record is initialized and the adjust function is applied to the initialized record again. Args: - originId: the origin id of the spam record. - adjustFunc: the function that adjusts the spam record. Returns:

  • Penalty value of the record after the adjustment.
  • error any returned error should be considered as an irrecoverable error and indicates a bug.

func (*SpamRecordCache) Get

Get returns the spam record of the given origin id. Returns the record and true if the record exists, nil and false otherwise. Args: - originId: the origin id of the spam record. Returns: - the record and true if the record exists, nil and false otherwise. Note that the returned record is a copy of the record in the cache (we do not want the caller to modify the record).

func (*SpamRecordCache) Identities

func (s *SpamRecordCache) Identities() []flow.Identifier

Identities returns the list of identities of the nodes that have a spam record in the cache.

func (*SpamRecordCache) Remove

func (s *SpamRecordCache) Remove(originId flow.Identifier) bool

Remove removes the spam record of the given origin id from the cache. Returns true if the record is removed, false otherwise (i.e., the record does not exist). Args: - originId: the origin id of the spam record. Returns: - true if the record is removed, false otherwise (i.e., the record does not exist).

func (*SpamRecordCache) Size

func (s *SpamRecordCache) Size() uint

Size returns the number of spam records in the cache.

Jump to

Keyboard shortcuts

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