bootstrap

package
v0.2.15-beta.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bootstrap

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

Bootstrap enforces required number of outbound connections.

func NewBootstrap

func NewBootstrap(logger log.Log, cfg Config, h host.Host, discovery Discovery) (*Bootstrap, error)

NewBootstrap create Bootstrap instance.

func (*Bootstrap) Stop

func (b *Bootstrap) Stop() error

Stop bootstrap and wait until background workers are terminated.

type Config

type Config struct {
	TargetOutbound int
	Timeout        time.Duration
}

Config for bootstrap.

type Discovery

type Discovery interface {
	Bootstrap(context.Context) error
}

Discovery is an interface that actively searches for peers when Bootstrap is called.

type EventSpacemeshPeer

type EventSpacemeshPeer struct {
	PID           peer.ID
	Direction     network.Direction
	Connectedness network.Connectedness
}

EventSpacemeshPeer is emitted when peer is connected after handshake or disconnected.

type Opt

type Opt func(*Peers)

Opt to modify peers instance.

func WithContext

func WithContext(ctx context.Context) Opt

WithContext sets parent context on Peers.

func WithLog

func WithLog(logger log.Log) Opt

WithLog sets logger for Peers instance.

func WithNodeReporter

func WithNodeReporter(f func()) Opt

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

type Peers

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

Peers is used by protocols to manage available peers.

func StartPeers

func StartPeers(h host.Host, opts ...Opt) *Peers

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

func (*Peers) GetPeers

func (p *Peers) GetPeers() []peer.ID

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()

Start listener goroutine in background.

func (*Peers) Stop

func (p *Peers) Stop()

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

func (*Peers) WaitPeers

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

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

type Provider

type Provider interface {
	PeerCount() uint64
	GetPeers() []peer.ID
}

Provider is an interface that provides peers.

type Waiter

type Waiter interface {
	WaitPeers(context.Context, int) ([]peer.ID, error)
}

Waiter is an interface to wait for peers.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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