unicastcache

package
v0.36.9-crescendo-RC2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UnicastConfigCache added in v0.33.1

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

func NewUnicastConfigCache added in v0.33.1

func NewUnicastConfigCache(
	size uint32,
	logger zerolog.Logger,
	collector module.HeroCacheMetrics,
	cfgFactory func() unicast.Config,
) *UnicastConfigCache

NewUnicastConfigCache creates a new UnicastConfigCache. Args: - size: the maximum number of unicast configs that the cache can hold. - logger: the logger used by the cache. - collector: the metrics collector used by the cache. - cfgFactory: a factory function that creates a new unicast config. Returns: - *UnicastConfigCache, the created cache. Note that the cache is supposed to keep the unicast config for all types of nodes. Since the number of such nodes is expected to be small, size must be large enough to hold all the unicast configs of the authorized nodes. To avoid any crash-failure, the cache is configured to eject the least recently used configs when the cache is full. Hence, we recommend setting the size to a large value to minimize the ejections.

func (*UnicastConfigCache) AdjustWithInit added in v0.33.1

func (d *UnicastConfigCache) AdjustWithInit(peerID peer.ID, adjustFunc unicast.UnicastConfigAdjustFunc) (*unicast.Config, error)

AdjustWithInit applies the given adjust function to the unicast config of the given peer ID, and stores the adjusted config in the cache. It returns an error if the adjustFunc returns an error. Note that if the Adjust is called when the config does not exist, the config is initialized and the adjust function is applied to the initialized config again. In this case, the adjust function should not return an error. Args: - peerID: the peer id of the unicast config. - adjustFunc: the function that adjusts the unicast config. Returns:

  • error any returned error should be considered as an irrecoverable error and indicates a bug.

func (*UnicastConfigCache) GetWithInit added in v0.33.1

func (d *UnicastConfigCache) GetWithInit(peerID peer.ID) (*unicast.Config, error)

GetWithInit returns the unicast config for the given peer id. If the config does not exist, it creates a new config using the factory function and stores it in the cache. Args: - peerID: the peer id of the unicast config. Returns:

  • *Config, the unicast config for the given peer id.
  • error if the factory function returns an error. Any error should be treated as an irrecoverable error and indicates a bug.

func (*UnicastConfigCache) Size added in v0.33.1

func (d *UnicastConfigCache) Size() uint

Size returns the number of unicast configs in the cache.

type UnicastConfigEntity added in v0.33.1

type UnicastConfigEntity struct {
	unicast.Config
	PeerId   peer.ID         // remote peer id; used as the "key" in the unicast config cache.
	EntityId flow.Identifier // cache the id for fast lookup (HeroCache).
}

UnicastConfigEntity is a struct that represents a unicast config entry for storing in the unicast config cache. It implements the flow.Entity interface.

func (UnicastConfigEntity) Checksum added in v0.33.1

func (d UnicastConfigEntity) Checksum() flow.Identifier

Checksum acts the same as ID.

func (UnicastConfigEntity) ID added in v0.33.1

ID returns the ID of the unicast config entity; it is hash value of the peer id.

Jump to

Keyboard shortcuts

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