discovery

package
v0.0.0-...-4e9d6c2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discovery

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

Discovery combines advertise and discover services and allows to store discovered nodes. TODO: The code here gets horribly hairy, so we should refactor this at some point

func NewDiscovery

func NewDiscovery(
	h host.Host,
	d discovery.Discovery,
	opts ...Option,
) *Discovery

NewDiscovery constructs a new discovery.

func (*Discovery) Advertise

func (d *Discovery) Advertise(ctx context.Context)

Advertise is a utility function that persistently advertises a service through an Advertiser. TODO: Start advertising only after the reachability is confirmed by AutoNAT

func (*Discovery) Peers

func (d *Discovery) Peers(ctx context.Context) ([]peer.ID, error)

Peers provides a list of discovered peers in the "full" topic. If Discovery hasn't found any peers, it blocks until at least one peer is found.

func (*Discovery) Start

func (d *Discovery) Start(context.Context) error

func (*Discovery) Stop

func (d *Discovery) Stop(context.Context) error

func (*Discovery) WithMetrics

func (d *Discovery) WithMetrics() error

WithMetrics turns on metric collection in discoery.

func (*Discovery) WithOnPeersUpdate

func (d *Discovery) WithOnPeersUpdate(f OnUpdatedPeers)

WithOnPeersUpdate chains OnPeersUpdate callbacks on every update of discovered peers list.

type OnUpdatedPeers

type OnUpdatedPeers func(peerID peer.ID, isAdded bool)

type Option

type Option func(*Parameters)

Option is a function that configures Discovery Parameters

func WithAdvertiseInterval

func WithAdvertiseInterval(advInterval time.Duration) Option

WithAdvertiseInterval is a functional option that Discovery uses to set the AdvertiseInterval configuration param

func WithPeersLimit

func WithPeersLimit(peersLimit uint) Option

WithPeersLimit is a functional option that Discovery uses to set the PeersLimit configuration param

type Parameters

type Parameters struct {
	// PeersLimit defines the soft limit of FNs to connect to via discovery.
	// Set 0 to disable.
	PeersLimit uint
	// AdvertiseInterval is a interval between advertising sessions.
	// Set -1 to disable.
	// NOTE: only full and bridge can advertise themselves.
	AdvertiseInterval time.Duration
}

Parameters is the set of Parameters that must be configured for the Discovery module

func DefaultParameters

func DefaultParameters() Parameters

DefaultParameters returns the default Parameters' configuration values for the Discovery module

func (*Parameters) Validate

func (p *Parameters) Validate() error

Validate validates the values in Parameters

Jump to

Keyboard shortcuts

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