peers

package
v1.7.9 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PeerStats added in v1.4.0

type PeerStats struct {
	ID       peer.ID
	Success  int
	Failures int
	Latency  time.Duration
}

func (*PeerStats) MarshalLogObject added in v1.4.0

func (p *PeerStats) MarshalLogObject(enc zapcore.ObjectEncoder) error

type Peers

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

func New

func New() *Peers

func (*Peers) Add

func (p *Peers) Add(id peer.ID, protocols func() []protocol.ID) bool

func (*Peers) Contains added in v1.7.7

func (p *Peers) Contains(id peer.ID) bool

func (*Peers) Delete

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

func (*Peers) OnFailure

func (p *Peers) OnFailure(id peer.ID, size int, latency time.Duration)

func (*Peers) OnLatency

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

OnLatency updates average peer and global latency.

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) SelectBestWithProtocols added in v1.7.8

func (p *Peers) SelectBestWithProtocols(n int, protocols []protocol.ID) []peer.ID

SelectBestWithProtocols is similar to SelectBest but filters peers by supported protocols. If protocols is empty, it returns the best peers regardless of the protocol. If protocols is not empty, it returns the best peers that support at least one of the protocols.

func (*Peers) Stats added in v1.4.0

func (p *Peers) Stats() Stats

func (*Peers) Total

func (p *Peers) Total() int

type Stats added in v1.4.0

type Stats struct {
	Total                int
	GlobalAverageLatency time.Duration
	BestPeers            []PeerStats
}

func (*Stats) MarshalLogObject added in v1.4.0

func (s *Stats) MarshalLogObject(enc zapcore.ObjectEncoder) error

Jump to

Keyboard shortcuts

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