internal

package
v0.33.17 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppSpecificScoreCache

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

AppSpecificScoreCache is a cache that stores the application specific score of peers. The application specific score of a peer is used to calculate the GossipSub score of the peer. Note that the application specific score and the GossipSub score are solely used by the current peer to select the peers to which it will connect on a topic mesh.

func NewAppSpecificScoreCache

func NewAppSpecificScoreCache(sizeLimit uint32, logger zerolog.Logger, collector module.HeroCacheMetrics) *AppSpecificScoreCache

NewAppSpecificScoreCache creates a new application specific score cache with the given size limit. The cache has an LRU eviction policy. Args: - sizeLimit: the size limit of the cache. - logger: the logger to use for logging. - collector: the metrics collector to use for collecting metrics. Returns: - *AppSpecificScoreCache: the created cache.

func (*AppSpecificScoreCache) AdjustWithInit

func (a *AppSpecificScoreCache) AdjustWithInit(peerID peer.ID, score float64, time time.Time) error

AdjustWithInit adds the application specific score of a peer to the cache. If the peer already has a score in the cache, the score is updated. Args: - peerID: the peer ID of the peer in the GossipSub protocol. - score: the application specific score of the peer. - time: the time at which the score was last updated. Returns: - error on failure to add the score. The returned error is irrecoverable and indicates an exception.

func (*AppSpecificScoreCache) Get

func (a *AppSpecificScoreCache) Get(peerID peer.ID) (float64, time.Time, bool)

Get returns the application specific score of a peer from the cache. Args: - peerID: the peer ID of the peer in the GossipSub protocol. Returns: - float64: the application specific score of the peer. - time.Time: the time at which the score was last updated. - bool: true if the score was retrieved successfully, false otherwise.

type SubscriptionRecordCache

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

SubscriptionRecordCache manages the subscription records of peers in a network. It uses a currentCycle counter to track the update cycles of the cache, ensuring the relevance of subscription data.

func NewSubscriptionRecordCache

func NewSubscriptionRecordCache(sizeLimit uint32,
	logger zerolog.Logger,
	collector module.HeroCacheMetrics) *SubscriptionRecordCache

NewSubscriptionRecordCache creates a new subscription cache with the given size limit. Args: - sizeLimit: the size limit of the cache. - logger: the logger to use for logging. - collector: the metrics collector to use for collecting metrics.

func (*SubscriptionRecordCache) AddWithInitTopicForPeer

func (s *SubscriptionRecordCache) AddWithInitTopicForPeer(pid peer.ID, topic string) ([]string, error)

AddWithInitTopicForPeer appends a topic to the list of topics a peer is subscribed to. If the peer is not subscribed to any topics yet, a new record is created. If the last update cycle is older than the current cycle, the list of topics for the peer is first cleared, and then the topic is added to the list. This is to ensure that the list of topics for a peer is always up to date. Args: - pid: the peer id of the peer. - topic: the topic to add. Returns: - []string: the list of topics the peer is subscribed to after the update. - error: an error if the update failed; any returned error is an irrecoverable error and indicates a bug or misconfiguration. Implementation must be thread-safe.

func (*SubscriptionRecordCache) GetSubscribedTopics

func (s *SubscriptionRecordCache) GetSubscribedTopics(pid peer.ID) ([]string, bool)

GetSubscribedTopics returns the list of topics a peer is subscribed to. Returns: - []string: the list of topics the peer is subscribed to. - bool: true if there is a record for the peer, false otherwise.

func (*SubscriptionRecordCache) MoveToNextUpdateCycle

func (s *SubscriptionRecordCache) MoveToNextUpdateCycle() uint64

MoveToNextUpdateCycle moves the subscription cache to the next update cycle. A new update cycle is started when the subscription cache is first created, and then every time the subscription cache is updated. The update cycle is used to keep track of the last time the subscription cache was updated. It is used to implement a notion of time in the subscription cache. When the update cycle is moved forward, it means that all the updates made to the subscription cache so far are considered out-of-date, and the new updates to the cache records should overwrite the old ones. The expected behavior is that the update cycle is moved forward by the module that uses the subscription provider once per each update on the "entire" cache (and not per each update on a single record). In other words, assume a cache with 3 records: A, B, and C. If the module updates record A, then record B, and then record C, the module should move the update cycle forward only once after updating record C, and then update record A B, and C again. If the module moves the update cycle forward after updating record A, then again after updating record B, and then again after updating record C, the cache will be in an inconsistent state. Returns: - uint64: the current update cycle.

type SubscriptionRecordEntity

type SubscriptionRecordEntity struct {

	// PeerID is the peer id of the peer that is the owner of the subscription.
	PeerID peer.ID

	// Topics is the list of topics the peer is subscribed to.
	Topics []string

	// LastUpdatedCycle is the last cycle counter value that this record was updated.
	// This is used to clean up old records' topics upon update.
	LastUpdatedCycle uint64
	// contains filtered or unexported fields
}

SubscriptionRecordEntity is an entity that represents a the list of topics a peer is subscribed to. It is internally used by the SubscriptionRecordCache to store the subscription records in the cache.

func (SubscriptionRecordEntity) Checksum

Checksum returns the entity id of the subscription record, which is the hash of the peer id. It is of no use in the cache, but it is implemented to satisfy the flow.Entity interface.

func (SubscriptionRecordEntity) ID

ID returns the entity id of the subscription record, which is the hash of the peer id.

Jump to

Keyboard shortcuts

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