protocoldiscovery

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultFindingHeartbeat is the default heartbeat interval.
	DefaultFindingHeartbeat = time.Minute
	// DefaultMaxQuerySize is the default max query size when finding peers.
	DefaultMaxQuerySize = 10
	// DefaultQuerySize is the default size for finding from each others.
	DefaultQuerySize = 3
)

Variables

View Source
var (
	// ErrFinding will be returned if there is already a finding task running when calling FindPeers method.
	ErrFinding = errors.New("there is already a finding task running, try it again later")
)

Functions

func WithQuerySize

func WithQuerySize(size int) discovery.Option

WithQuerySize set an int value as default query size for finding peers.

func WithTimeout

func WithTimeout(timeout time.Duration) discovery.Option

WithTimeout set a time.Duration as timeout for finding peers.

Types

type Option

type Option func(*ProtocolBasedDiscovery) error

Option is a function to apply properties for discovery service.

func WithDefaultQueryTimeout

func WithDefaultQueryTimeout(timeout time.Duration) Option

WithDefaultQueryTimeout set a time.Duration as default timeout for finding peers.

func WithFindingTickerInterval

func WithFindingTickerInterval(interval time.Duration) Option

WithFindingTickerInterval set a time.Duration as interval for finding task heartbeat.

func WithLogger

func WithLogger(logger api.Logger) Option

WithLogger set a logger.

func WithMaxQuerySize

func WithMaxQuerySize(max int) Option

WithMaxQuerySize set an int value as default max query size for finding peers.

type ProtocolBasedDiscovery

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

ProtocolBasedDiscovery provides a discovery service based on protocols supported.

func NewProtocolBasedDiscovery

func NewProtocolBasedDiscovery(host host.Host, opts ...Option) (*ProtocolBasedDiscovery, error)

NewProtocolBasedDiscovery create a new ProtocolBasedDiscovery instance.

func (*ProtocolBasedDiscovery) Announce

func (d *ProtocolBasedDiscovery) Announce(_ context.Context, serviceName string, _ ...discovery.Option) error

Announce tell other peers that I have supported a new service with name given.

func (*ProtocolBasedDiscovery) FindPeers

func (d *ProtocolBasedDiscovery) FindPeers(ctx context.Context, serviceName string, opts ...discovery.Option) (<-chan ma.Multiaddr, error)

FindPeers run a loop task to find peers, and addresses of peers found will be push to result chan. If you want to quit finding task, the ctx should be canceled.

Source Files

  • discovery.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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