peers

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByID

type ByID []*Peer

func (ByID) Len

func (a ByID) Len() int

func (ByID) Less

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

func (ByID) Swap

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

type ByPubHex

type ByPubHex []*Peer

ByPubHex implements sort.Interface for Peers based on the PubKeyHex field.

func (ByPubHex) Len

func (a ByPubHex) Len() int

func (ByPubHex) Less

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

func (ByPubHex) Swap

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

type IdPeers

type IdPeers map[int]*Peer

type JSONPeers

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

JSONPeers is used to provide peer persistence on disk in the form of a JSON file. This allows human operators to manipulate the file.

func NewJSONPeers

func NewJSONPeers(base string) *JSONPeers

NewJSONPeers creates a new JSONPeers store.

func (*JSONPeers) Peers

func (j *JSONPeers) Peers() (*Peers, error)

Peers implements the PeerStore interface.

func (*JSONPeers) SetPeers

func (j *JSONPeers) SetPeers(peers []*Peer) error

SetPeers implements the PeerStore interface.

type Peer

type Peer struct {
	ID        int `json:"-"`
	NetAddr   string
	PubKeyHex string
}

func ExcludePeer

func ExcludePeer(peers []*Peer, peer string) (int, []*Peer)

ExcludePeer is used to exclude a single peer from a list of peers.

func NewPeer

func NewPeer(pubKeyHex, netAddr string) *Peer

func (*Peer) PubKeyBytes

func (p *Peer) PubKeyBytes() ([]byte, error)

type PeerStore

type PeerStore interface {
	// Peers returns the list of known peers.
	Peers() (*Peers, error)

	// SetPeers sets the list of known peers. This is invoked when a peer is
	// added or removed.
	SetPeers([]*Peer) error
}

PeerStore provides an interface for persistent storage and retrieval of peers.

type Peers

type Peers struct {
	sync.RWMutex
	Sorted   []*Peer
	ByPubKey PubKeyPeers
	ById     IdPeers
}

func NewPeers

func NewPeers() *Peers

func NewPeersFromSlice

func NewPeersFromSlice(source []*Peer) *Peers

func (*Peers) AddPeer

func (p *Peers) AddPeer(peer *Peer)

func (*Peers) Len

func (p *Peers) Len() int

func (*Peers) RemovePeer

func (p *Peers) RemovePeer(peer *Peer)

func (*Peers) RemovePeerById

func (p *Peers) RemovePeerById(id int)

func (*Peers) RemovePeerByPubKey

func (p *Peers) RemovePeerByPubKey(pubKey string)

func (*Peers) ToIDSlice

func (p *Peers) ToIDSlice() []int

func (*Peers) ToPeerSlice

func (p *Peers) ToPeerSlice() []*Peer

func (*Peers) ToPubKeySlice

func (p *Peers) ToPubKeySlice() []string

type PubKeyPeers

type PubKeyPeers map[string]*Peer

type StaticPeers

type StaticPeers struct {
	StaticPeers []Peer
	// contains filtered or unexported fields
}

StaticPeers is used to provide a static list of peers.

func (*StaticPeers) Peers

func (s *StaticPeers) Peers() ([]Peer, error)

Peers implements the PeerStore interface.

func (*StaticPeers) SetPeers

func (s *StaticPeers) SetPeers(p []Peer) error

SetPeers implements the PeerStore interface.

Jump to

Keyboard shortcuts

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