discovery

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: AGPL-3.0, MIT Imports: 14 Imported by: 0

README

go-libp2p-discovery

Discourse posts

Interfaces for active peer discovery

This package contains interfaces and utilities for active peer discovery. Peers providing a service use the interface to advertise their presence in some namespace. Vice versa, peers seeking a service use the interface to discover peers that have previously advertised as service providers. The package also includes a baseline implementation for discovery through Content Routing.

Documenation

See https://godoc.org/github.com/libp2p/go-libp2p-discovery.

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT


The last gx published version of this module was: 1.0.15: QmWA8k8apx6egshEjemkuxpKNJS7W7heCgzTnBhAvX9yoB

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Advertise(ctx context.Context, a Advertiser, ns string, opts ...Option)

Advertise is a utility function that persistently advertises a service through an Advertiser.

func FindPeers

func FindPeers(ctx context.Context, d Discoverer, ns string, opts ...Option) ([]peer.AddrInfo, error)

FindPeers is a utility function that synchronously collects peers from a Discoverer.

func FullJitter

func FullJitter(duration, min, max time.Duration, rng *rand.Rand) time.Duration

FullJitter returns a random number uniformly chose from the range [min, boundedDur]. boundedDur is the duration bounded between min and max.

func Limit

func Limit(limit int) core.Option

Limit is Deprecated: use github.com/RTradeLtd/libp2px-core/discovery.Limit instead.

func NewBackoffDiscovery

func NewBackoffDiscovery(disc discovery.Discovery, stratFactory BackoffFactory, opts ...BackoffDiscoveryOption) (discovery.Discovery, error)

NewBackoffDiscovery provides a backoff discovery service

func NoJitter

func NoJitter(duration, min, max time.Duration, rng *rand.Rand) time.Duration

NoJitter returns the duration bounded between min and max

func TTL

func TTL(ttl time.Duration) core.Option

TTL is Deprecated: use github.com/RTradeLtd/libp2px-core/discovery.TTL instead.

Types

type Advertiser

type Advertiser = core.Advertiser

Advertiser is Deprecated: use github.com/RTradeLtd/libp2px-core.Advertiser instead.

type BackoffConnector

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

BackoffConnector is a utility to connect to peers, but only if we have not recently tried connecting to them already

func NewBackoffConnector

func NewBackoffConnector(h host.Host, cacheSize int, connectionTryDuration time.Duration, backoff BackoffFactory) (*BackoffConnector, error)

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

func (*BackoffConnector) Connect

func (c *BackoffConnector) Connect(ctx context.Context, peerCh <-chan peer.AddrInfo)

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.

type BackoffDiscovery

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

BackoffDiscovery is an implementation of discovery that caches peer data and attenuates repeated queries

func (*BackoffDiscovery) Advertise

func (d *BackoffDiscovery) Advertise(ctx context.Context, ns string, opts ...discovery.Option) (time.Duration, error)

Advertise advertises support for the namespace

func (*BackoffDiscovery) FindPeers

func (d *BackoffDiscovery) FindPeers(ctx context.Context, ns string, opts ...discovery.Option) (<-chan peer.AddrInfo, error)

FindPeers finds peers supporting the namespace

type BackoffDiscoveryOption

type BackoffDiscoveryOption func(*BackoffDiscovery) error

BackoffDiscoveryOption configures a backoff discovery service

func WithBackoffDiscoveryReturnedChannelSize

func WithBackoffDiscoveryReturnedChannelSize(size int) BackoffDiscoveryOption

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

func WithBackoffDiscoverySimultaneousQueryBufferSize

func WithBackoffDiscoverySimultaneousQueryBufferSize(size int) BackoffDiscoveryOption

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

type BackoffFactory

type BackoffFactory func() BackoffStrategy

BackoffFactory returns a backoff strategy

func NewExponentialBackoff

func NewExponentialBackoff(min, max time.Duration, jitter Jitter,
	timeUnits time.Duration, base float64, offset time.Duration, rng *rand.Rand) BackoffFactory

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

func NewExponentialDecorrelatedJitter

func NewExponentialDecorrelatedJitter(min, max time.Duration, base float64, rng *rand.Rand) BackoffFactory

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

func NewFixedBackoff

func NewFixedBackoff(delay time.Duration) BackoffFactory

NewFixedBackoff creates a BackoffFactory with a constant backoff duration

func NewPolynomialBackoff

func NewPolynomialBackoff(min, max time.Duration, jitter Jitter,
	timeUnits time.Duration, polyCoefs []float64, rng *rand.Rand) BackoffFactory

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]

type BackoffStrategy

type BackoffStrategy interface {
	// Delay calculates how long the next backoff duration should be, given the prior calls to Delay
	Delay() time.Duration
	// Reset clears the internal state of the BackoffStrategy
	Reset()
}

BackoffStrategy describes how backoff will be implemented. BackoffStratgies are stateful.

type Discoverer

type Discoverer = core.Discoverer

Discoverer Deprecated: use github.com/RTradeLtd/libp2px-core.Discoverer instead.

type Discovery

type Discovery = core.Discovery

Discovery is Deprecated: use github.com/RTradeLtd/libp2px-core.Discovery instead.

type Jitter

type Jitter func(duration, min, max time.Duration, rng *rand.Rand) time.Duration

Jitter must return a duration between min and max. Min must be lower than, or equal to, max.

type Option

type Option = core.Option

Option is Deprecated: use github.com/RTradeLtd/libp2px-core/discovery.Option instead.

type Options

type Options = core.Options

Options is Deprecated: use github.com/RTradeLtd/libp2px-core/discovery.Options instead.

type Routing

type Routing struct {
	discovery.Discovery
	// contains filtered or unexported fields
}

Routing does?? TODO(bonedaddy): identify why this is here and if we can remove it

func NewDiscoveryRouting

func NewDiscoveryRouting(disc discovery.Discovery, opts ...discovery.Option) *Routing

NewDiscoveryRouting returns a configurable DiscoveryRouting router

func (*Routing) FindProvidersAsync

func (r *Routing) FindProvidersAsync(ctx context.Context, c cid.Cid, limit int) <-chan peer.AddrInfo

FindProvidersAsync is used to asychronously find providers for the cid

func (*Routing) Provide

func (r *Routing) Provide(ctx context.Context, c cid.Cid, bcast bool) error

Provide is used to provide to the cid namespace that are providing the content for it

type RoutingDiscovery

type RoutingDiscovery struct {
	routing.ContentRouting
}

RoutingDiscovery is an implementation of discovery using ContentRouting Namespaces are translated to Cids using the SHA256 hash.

func NewRoutingDiscovery

func NewRoutingDiscovery(router routing.ContentRouting) *RoutingDiscovery

NewRoutingDiscovery returns a content routing discovery service

func (*RoutingDiscovery) Advertise

func (d *RoutingDiscovery) Advertise(ctx context.Context, ns string, opts ...Option) (time.Duration, error)

Advertise is used to advertise we are interested in the namespace

func (*RoutingDiscovery) FindPeers

func (d *RoutingDiscovery) FindPeers(ctx context.Context, ns string, opts ...Option) (<-chan peer.AddrInfo, error)

FindPeers is used to find peers from the given namespace

Jump to

Keyboard shortcuts

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