package discovery

import "github.com/libp2p/go-libp2p/core/discovery"

Package discovery provides service advertisement and peer discovery interfaces for libp2p.

Index

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 peer.AddrInfo, 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

DiscoveryOpt 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{}
}

DiscoveryOpts is a set of discovery options.

func (*Options) Apply

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

Apply applies the given options to this DiscoveryOpts

Source Files

discovery.go options.go

Version
v0.42.0 (latest)
Published
Jun 18, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
1 week ago

Tools for package owners.