peers

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByName

type ByName []Peer

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type HistoryRequester

type HistoryRequester interface {
	ID() netip.Addr
	RequestBlockIDs(ids []proto.BlockID)
	RequestBlock(id proto.BlockID)
}

type Peer

type Peer struct {
	AddressPort netip.AddrPort `json:"address"`
	Nonce       uint64         `json:"nonce"`
	Name        string         `json:"name"`
	Version     proto.Version  `json:"version"`
	State       State          `json:"state"`
	NextAttempt time.Time      `json:"next_attempt"`
	Score       *big.Int       `json:"score"`
	// contains filtered or unexported fields
}

func (*Peer) ID

func (p *Peer) ID() netip.Addr

func (*Peer) RequestBlock

func (p *Peer) RequestBlock(id proto.BlockID)

func (*Peer) RequestBlockIDs

func (p *Peer) RequestBlockIDs(ids []proto.BlockID)

func (*Peer) Send

func (p *Peer) Send(msg proto.Message)

func (*Peer) String

func (p *Peer) String() string

func (*Peer) TCPAddr

func (p *Peer) TCPAddr() *net.TCPAddr

type Registry

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

func NewRegistry

func NewRegistry(
	scheme proto.Scheme, declared proto.TCPAddr, versions []proto.Version, path string,
) (*Registry, error)

func (*Registry) Addresses

func (r *Registry) Addresses() ([]net.Addr, error)

func (*Registry) AppendAddresses

func (r *Registry) AppendAddresses(addresses []*net.TCPAddr) int

AppendAddresses adds new addresses to the storage filtering out already known addresses. Function returns the number of newly added addresses.

func (*Registry) Broadcast

func (r *Registry) Broadcast(msg proto.Message)

func (*Registry) Close

func (r *Registry) Close() error

func (*Registry) Connections

func (r *Registry) Connections() ([]Peer, error)

Connections returns the list of active connections.

func (*Registry) FriendlyPeers

func (r *Registry) FriendlyPeers() ([]Peer, error)

func (*Registry) MarkAsHostile

func (r *Registry) MarkAsHostile(addr net.Addr) error

func (*Registry) Peer

func (r *Registry) Peer(addr netip.Addr) (Peer, error)

func (*Registry) Peers

func (r *Registry) Peers() ([]Peer, error)

func (*Registry) RegisterPeer

func (r *Registry) RegisterPeer(addr netip.Addr, np peer.Peer, handshake proto.Handshake) error

func (*Registry) SuggestVersion

func (r *Registry) SuggestVersion(addr netip.Addr) (proto.Version, error)

SuggestVersion returns the best version possible for the peer on given address.

func (*Registry) TakeAvailableAddresses

func (r *Registry) TakeAvailableAddresses() ([]netip.AddrPort, error)

TakeAvailableAddresses returns the list of known non-hostile addresses that are not in the list of active connections and not in the list of pending connections.

func (*Registry) UnregisterPeer

func (r *Registry) UnregisterPeer(addr netip.Addr) error

func (*Registry) UpdatePeerScore

func (r *Registry) UpdatePeerScore(addr netip.Addr, score *big.Int) error

type State

type State byte
const (
	PeerUnknown State = iota
	PeerConnected
	PeerHostile
)

func (State) String

func (i State) String() string

type VersionProvider

type VersionProvider interface {
	SuggestVersion(addr netip.Addr) (proto.Version, error)
}

Jump to

Keyboard shortcuts

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