unicastcache

package
v0.32.7 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDialConfigNotFound = fmt.Errorf("dial config not found")

ErrDialConfigNotFound is a benign error that indicates that the dial config does not exist in the cache. It is not a fatal error.

Functions

func PeerIdToFlowId

func PeerIdToFlowId(pid peer.ID) flow.Identifier

PeerIdToFlowId converts a peer id to a flow id (hash value of the peer id).

Types

type DialConfigCache

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

func NewDialConfigCache

func NewDialConfigCache(
	size uint32,
	logger zerolog.Logger,
	collector module.HeroCacheMetrics,
	cfgFactory func() unicast.DialConfig,
) *DialConfigCache

NewDialConfigCache creates a new DialConfigCache. Args: - size: the maximum number of dial 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 dial config. Returns: - *DialConfigCache, the created cache. Note that the cache is supposed to keep the dial 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 dial 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 (*DialConfigCache) Adjust

func (d *DialConfigCache) Adjust(peerID peer.ID, adjustFunc unicast.DialConfigAdjustFunc) (*unicast.DialConfig, error)

Adjust applies the given adjust function to the dial 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 dial config. - adjustFunc: the function that adjusts the dial config. Returns:

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

func (*DialConfigCache) GetOrInit

func (d *DialConfigCache) GetOrInit(peerID peer.ID) (*unicast.DialConfig, error)

GetOrInit returns the dial 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 dial config. Returns:

  • *DialConfig, the dial 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 (*DialConfigCache) Size

func (d *DialConfigCache) Size() uint

Size returns the number of dial configs in the cache.

type DialConfigEntity

type DialConfigEntity struct {
	unicast.DialConfig
	PeerId peer.ID // remote peer id; used as the "key" in the dial config cache.
	// contains filtered or unexported fields
}

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

func (DialConfigEntity) Checksum

func (d DialConfigEntity) Checksum() flow.Identifier

Checksum acts the same as ID.

func (DialConfigEntity) ID

ID returns the ID of the dial 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