discovery

package
v0.0.0-...-8b9b725 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: MIT, MIT Imports: 7 Imported by: 8

README

go-libp2p-discovery

standard-readme compliant

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

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

func FindPeers

func FindPeers(ctx context.Context, d Discoverer, ns string, limit int) ([]pstore.PeerInfo, error)

FindPeers is a utility function that synchonously collects peers from a Discoverer

Types

type Advertiser

type Advertiser interface {
	// Advertise advertises a service
	Advertise(ctx context.Context, ns string, opts ...Option) (time.Duration, error)
}

Advertiser is an interface for advertising services

type Discoverer

type Discoverer interface {
	// FindPeers discovers peers providing a service
	FindPeers(ctx context.Context, ns string, opts ...Option) (<-chan pstore.PeerInfo, error)
}

Discoverer is an interface for peer discovery

type Discovery

type Discovery interface {
	Advertiser
	Discoverer
}

Discovery is an interface that combines service advertisement and peer discovery

type Option

type Option func(opts *Options) error

Option is a single discovery option

func Limit

func Limit(limit int) Option

Limit is an option that provides an upper bound on the peer count for discovery

func TTL

func TTL(ttl time.Duration) Option

TTL is an option that provides a hint for the duration of an advertisement

type Options

type Options struct {
	Ttl   time.Duration
	Limit int
	// Other (implementation-specific) options
	Other map[interface{}]interface{}
}

Options is a set of discovery options

func (*Options) Apply

func (opts *Options) Apply(options ...Option) error

Apply applies the given options to this Options

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

func (*RoutingDiscovery) Advertise

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

func (*RoutingDiscovery) FindPeers

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

Jump to

Keyboard shortcuts

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