peers

package
v0.9.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ResultSuccess indicates operation was successful and no extra action is required
	ResultSuccess result = iota
	// ResultSynced will save the status of pool as "synced" and will remove peers from it
	ResultSynced
	// ResultCooldownPeer will put returned peer on cooldown, meaning it won't be available by Peer
	// method for some time
	ResultCooldownPeer
	// ResultBlacklistPeer will blacklist peer. Blacklisted peers will be disconnected and blocked from
	// any p2p communication in future by libp2p Gater
	ResultBlacklistPeer
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DoneFunc

type DoneFunc func(result)

DoneFunc updates internal state depending on call results. Should be called once per returned peer from Peer method

type Manager

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

Manager keeps track of peers coming from shrex.Sub and from discovery

func NewManager

func NewManager(
	params Parameters,
	headerSub libhead.Subscriber[*header.ExtendedHeader],
	shrexSub *shrexsub.PubSub,
	discovery *discovery.Discovery,
	host host.Host,
	connGater *conngater.BasicConnectionGater,
) (*Manager, error)

func (*Manager) GC

func (m *Manager) GC(ctx context.Context)

func (*Manager) Peer

func (m *Manager) Peer(
	ctx context.Context, datahash share.DataHash,
) (peer.ID, DoneFunc, error)

Peer returns peer collected from shrex.Sub for given datahash if any available. If there is none, it will look for full nodes collected from discovery. If there is no discovered full nodes, it will wait until any peer appear in either source or timeout happen. After fetching data using given peer, caller is required to call returned DoneFunc using appropriate result value

func (*Manager) Start

func (m *Manager) Start(startCtx context.Context) error

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

type Parameters

type Parameters struct {
	// PoolValidationTimeout is the timeout used for validating incoming datahashes. Pools that have
	// been created for datahashes from shrexsub that do not see this hash from headersub after this
	// timeout will be garbage collected.
	PoolValidationTimeout time.Duration

	// PeerCooldown is the time a peer is put on cooldown after a ResultCooldownPeer.
	PeerCooldown time.Duration

	// GcInterval is the interval at which the manager will garbage collect unvalidated pools.
	GcInterval time.Duration

	// EnableBlackListing turns on blacklisting for misbehaved peers
	EnableBlackListing bool
}

func DefaultParameters

func DefaultParameters() Parameters

DefaultParameters returns the default configuration values for the daser parameters

func (*Parameters) Validate

func (p *Parameters) Validate() error

Validate validates the values in Parameters

Jump to

Keyboard shortcuts

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