package backoff

Import Path
	github.com/libp2p/go-libp2p/p2p/discovery/backoff (on go.dev)

Dependency Relation
	imports 12 packages, and imported by one package


Package-Level Type Names (total 6)
/* sort by: | */
BackoffConnector is a utility to connect to peers, but only if we have not recently tried connecting to them already Connect attempts to connect to the peers passed in by peerCh. Will not connect to peers if they are within the backoff period. As Connect will attempt to dial peers as soon as it learns about them, the caller should try to keep the number, and rate, of inbound peers manageable. func NewBackoffConnector(h host.Host, cacheSize int, connectionTryDuration time.Duration, backoff BackoffFactory) (*BackoffConnector, error)
BackoffDiscovery is an implementation of discovery that caches peer data and attenuates repeated queries (*BackoffDiscovery) Advertise(ctx context.Context, ns string, opts ...discovery.Option) (time.Duration, error) (*BackoffDiscovery) FindPeers(ctx context.Context, ns string, opts ...discovery.Option) (<-chan peer.AddrInfo, error) *BackoffDiscovery : github.com/libp2p/go-libp2p/core/discovery.Advertiser *BackoffDiscovery : github.com/libp2p/go-libp2p/core/discovery.Discoverer *BackoffDiscovery : github.com/libp2p/go-libp2p/core/discovery.Discovery
func WithBackoffDiscoveryReturnedChannelSize(size int) BackoffDiscoveryOption func WithBackoffDiscoverySimultaneousQueryBufferSize(size int) BackoffDiscoveryOption func NewBackoffDiscovery(disc discovery.Discovery, stratFactory BackoffFactory, opts ...BackoffDiscoveryOption) (discovery.Discovery, error)
func NewExponentialBackoff(min, max time.Duration, jitter Jitter, timeUnits time.Duration, base float64, offset time.Duration, rngSrc rand.Source) BackoffFactory func NewExponentialDecorrelatedJitter(min, max time.Duration, base float64, rngSrc rand.Source) BackoffFactory func NewFixedBackoff(delay time.Duration) BackoffFactory func NewPolynomialBackoff(min, max time.Duration, jitter Jitter, timeUnits time.Duration, polyCoefs []float64, rngSrc rand.Source) BackoffFactory func NewBackoffConnector(h host.Host, cacheSize int, connectionTryDuration time.Duration, backoff BackoffFactory) (*BackoffConnector, error) func NewBackoffDiscovery(disc discovery.Discovery, stratFactory BackoffFactory, opts ...BackoffDiscoveryOption) (discovery.Discovery, error)
BackoffStrategy describes how backoff will be implemented. BackoffStrategies are stateful. Delay calculates how long the next backoff duration should be, given the prior calls to Delay Reset clears the internal state of the BackoffStrategy
Jitter must return a duration between min and max. Min must be lower than, or equal to, max. func NewExponentialBackoff(min, max time.Duration, jitter Jitter, timeUnits time.Duration, base float64, offset time.Duration, rngSrc rand.Source) BackoffFactory func NewPolynomialBackoff(min, max time.Duration, jitter Jitter, timeUnits time.Duration, polyCoefs []float64, rngSrc rand.Source) BackoffFactory
Package-Level Functions (total 10)
FullJitter returns a random number, uniformly chosen from the range [min, boundedDur]. boundedDur is the duration bounded between min and max.
NewBackoffConnector creates a utility to connect to peers, but only if we have not recently tried connecting to them already cacheSize is the size of a TwoQueueCache connectionTryDuration is how long we attempt to connect to a peer before giving up backoff describes the strategy used to decide how long to backoff after previously attempting to connect to a peer
NewExponentialBackoff creates a BackoffFactory with backoff of the form base^x + offset where x is the attempt number jitter is the function for adding randomness around the backoff timeUnits are the units of time the base^x is evaluated in
NewExponentialDecorrelatedJitter creates a BackoffFactory with backoff of the roughly of the form base^x where x is the attempt number. Delays start at the minimum duration and after each attempt delay = rand(min, delay * base), bounded by the max See https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ for more information
NewFixedBackoff creates a BackoffFactory with a constant backoff duration
NewPolynomialBackoff creates a BackoffFactory with backoff of the form c0*x^0, c1*x^1, ...cn*x^n where x is the attempt number jitter is the function for adding randomness around the backoff timeUnits are the units of time the polynomial is evaluated in polyCoefs is the array of polynomial coefficients from [c0, c1, ... cn]
NoJitter returns the duration bounded between min and max
WithBackoffDiscoveryReturnedChannelSize sets the size of the buffer to be used during a FindPeer query. Note: This does not apply if the query occurs during the backoff time
WithBackoffDiscoverySimultaneousQueryBufferSize sets the buffer size for the channels between the main FindPeers query for a given namespace and all simultaneous FindPeers queries for the namespace