peers

package
v1.2.2-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 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 Opt

type Opt func(*Peers)

func WithRateThreshold

func WithRateThreshold(rate float64) Opt

type Peers

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

func New

func New(opts ...Opt) *Peers

func (*Peers) Add

func (p *Peers) Add(id peer.ID)

func (*Peers) Delete

func (p *Peers) Delete(id peer.ID)

func (*Peers) OnFailure

func (p *Peers) OnFailure(id peer.ID)

func (*Peers) OnLatency

func (p *Peers) OnLatency(id peer.ID, latency time.Duration)

OnLatency records success and latency. Latency is not reported with every success as some requests has different amount of work and data, and we want to measure something comparable.

func (*Peers) SelectBest

func (p *Peers) SelectBest(n int) []peer.ID

SelectBest selects at most n peers sorted by responsiveness and latency.

SelectBest parametrized by N because sync protocol relies on receiving data from redundant connections to guarantee that it will get complete data set. If it doesn't get complete data set it will have to fallback into hash resolution, which is generally more expensive.

func (*Peers) SelectBestFrom

func (p *Peers) SelectBestFrom(peers []peer.ID) peer.ID

SelectBest peer with preferences.

func (*Peers) Total

func (p *Peers) Total() int

Jump to

Keyboard shortcuts

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