peers

package
v0.0.0-...-4e9d6c2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

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

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

func (*Manager) Validate

Validate will collect peer.ID into corresponding peer pool

func (*Manager) WithMetrics

func (m *Manager) WithMetrics() error

WithMetrics turns on metric collection in peer manager.

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