peers

package
v0.2.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Peers)

Option to modify peers instance.

func WithLog

func WithLog(lg log.Log) Option

WithLog sets logger for Peers instance.

func WithNodeStatesReporter

func WithNodeStatesReporter(f func()) Option

WithNodeStatesReporter sets callback to report node status. Callback is invoked after new peer joins or disconnects.

type Peer

type Peer p2pcrypto.PublicKey

Peer is represented by a p2p identity public key.

type PeerSubscriptionProvider

type PeerSubscriptionProvider interface {
	SubscribePeerEvents() (conn, disc chan p2pcrypto.PublicKey)
}

PeerSubscriptionProvider is the interface that provides us with peer events channels.

type Peers

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

Peers is used by protocols to manage available peers.

func New

func New(opts ...Option) *Peers

New creates a Peers using specified parameters and returns it.

func Start

func Start(s PeerSubscriptionProvider, opts ...Option) *Peers

Start creates a Peers instance that is registered to `s`'s events and starts it.

func (*Peers) Close

func (p *Peers) Close()

Close stops listening for events and waits for background worker to exit.

func (*Peers) GetPeers

func (p *Peers) GetPeers() []Peer

GetPeers returns a snapshot of the connected peers shuffled.

func (*Peers) PeerCount

func (p *Peers) PeerCount() uint64

PeerCount returns the number of connected peers.

func (*Peers) Start

func (p *Peers) Start(added, expired chan p2pcrypto.PublicKey)

Start listener goroutine in background.

func (*Peers) WaitPeers

func (p *Peers) WaitPeers(ctx context.Context, n int) ([]Peer, error)

WaitPeers returns with atleast N peers or when context is terminated. Nil slice is returned if Peers is closing.

Jump to

Keyboard shortcuts

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