Documentation ¶
Index ¶
Constants ¶
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 ¶
Functions ¶
func WithQuerySize ¶
WithQuerySize set an int value as default query size for finding peers.
Types ¶
type Option ¶
type Option func(*ProtocolBasedDiscovery) error
Option is a function to apply properties for discovery service.
func WithDefaultQueryTimeout ¶
WithDefaultQueryTimeout set a time.Duration as default timeout for finding peers.
func WithFindingTickerInterval ¶
WithFindingTickerInterval set a time.Duration as interval for finding task heartbeat.
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.