peers

package
v0.0.0-...-168a2c3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const PeerNIL uint64 = 0

PeerNIL is used for nil peer id

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressPeers

type AddressPeers map[common.Address]*Peer

AddressPeers maps address to peer

type ByID

type ByID []*Peer

ByID sorted by ID peers list

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 ByUsed

type ByUsed []*Peer

ByUsed TODO

func (ByUsed) Len

func (a ByUsed) Len() int

func (ByUsed) Less

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

func (ByUsed) Swap

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

type IDPeers

type IDPeers map[uint64]*Peer

IDPeers map of peers sorted by ID

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 Listener

type Listener func(*Peer)

Listener for listening for new peers joining

type NetAddrPeers

type NetAddrPeers map[string]*Peer

type Peer

type Peer struct {
	ID                   uint64   `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
	NetAddr              string   `protobuf:"bytes,2,opt,name=NetAddr,proto3" json:"NetAddr,omitempty"`
	PubKeyHex            string   `protobuf:"bytes,3,opt,name=PubKeyHex,proto3" json:"PubKeyHex,omitempty"`
	Used                 int64    `protobuf:"varint,4,opt,name=used,proto3" json:"used,omitempty"`
	Height               int64    `protobuf:"varint,5,opt,name=height,proto3" json:"height,omitempty"`
	InDegree             int64    `protobuf:"varint,6,opt,name=inDegree,proto3" json:"inDegree,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func ExcludePeer

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

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

func ExcludePeers

func ExcludePeers(peers []*Peer, local string, last string) []*Peer

ExcludePeers is used to exclude multiple peers from a list of peers.

func NewPeer

func NewPeer(pubKeyHex, netAddr string) *Peer

NewPeer creates a new peer based on public key and network address

func (*Peer) Address

func (p *Peer) Address() (a common.Address)

Address returns the address for a peer TODO: hash of publickey

func (*Peer) Descriptor

func (*Peer) Descriptor() ([]byte, []int)

func (*Peer) Equals

func (p *Peer) Equals(cmp *Peer) bool

Equals checks peers for equality

func (*Peer) GetHeight

func (m *Peer) GetHeight() int64

func (*Peer) GetID

func (m *Peer) GetID() uint64

func (*Peer) GetInDegree

func (m *Peer) GetInDegree() int64

func (*Peer) GetNetAddr

func (m *Peer) GetNetAddr() string

func (*Peer) GetPubKeyHex

func (m *Peer) GetPubKeyHex() string

func (*Peer) GetUsed

func (m *Peer) GetUsed() int64

func (*Peer) ProtoMessage

func (*Peer) ProtoMessage()

func (*Peer) PubKeyBytes

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

PubKeyBytes returns the public key bytes for a peer

func (*Peer) Reset

func (m *Peer) Reset()

func (*Peer) String

func (m *Peer) String() string

func (*Peer) XXX_DiscardUnknown

func (m *Peer) XXX_DiscardUnknown()

func (*Peer) XXX_Marshal

func (m *Peer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Peer) XXX_Merge

func (dst *Peer) XXX_Merge(src proto.Message)

func (*Peer) XXX_Size

func (m *Peer) XXX_Size() int

func (*Peer) XXX_Unmarshal

func (m *Peer) XXX_Unmarshal(b []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
	ByAddress AddressPeers
	ByNetAddr NetAddrPeers
	Listeners []Listener
}

Peers struct for all known peers for this node

func NewPeers

func NewPeers() *Peers

NewPeers creates a new peers struct

func NewPeersFromSlice

func NewPeersFromSlice(source []*Peer) *Peers

NewPeersFromSlice create a new peers struct from a subset of peers

func (*Peers) AddPeer

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

AddPeer adds a peer to the peers struct

func (*Peers) EmitNewPeer

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

EmitNewPeer emits an event for all listeners as soon as a peer joins

func (*Peers) GetHeightByPubKeyHex

func (p *Peers) GetHeightByPubKeyHex(key string) int64

func (*Peers) IncInDegreeByPubKeyHex

func (p *Peers) IncInDegreeByPubKeyHex(key string)

func (*Peers) Len

func (p *Peers) Len() int

Len returns the length of peers

func (*Peers) NextHeightByPubKeyHex

func (p *Peers) NextHeightByPubKeyHex(key string) int64

func (*Peers) OnNewPeer

func (p *Peers) OnNewPeer(cb func(*Peer))

OnNewPeer on new peer joined event trigger listener

func (*Peers) ReadByAddress

func (p *Peers) ReadByAddress(key common.Address) (Peer, bool)

func (*Peers) ReadByID

func (p *Peers) ReadByID(key uint64) (Peer, bool)

func (*Peers) ReadByNetAddr

func (p *Peers) ReadByNetAddr(key string) (Peer, bool)

func (*Peers) ReadByPubKey

func (p *Peers) ReadByPubKey(key string) (Peer, bool)

func (*Peers) RemovePeer

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

RemovePeer removes a peer from the peers struct

func (*Peers) RemovePeerByID

func (p *Peers) RemovePeerByID(id uint64)

RemovePeerByID removes a peer based on their ID

func (*Peers) RemovePeerByPubKey

func (p *Peers) RemovePeerByPubKey(pubKey string)

RemovePeerByPubKey removes a peer by their public key

func (*Peers) SetHeightByPubKeyHex

func (p *Peers) SetHeightByPubKeyHex(key string, height int64)

func (*Peers) SetInDegreeByPubKeyHex

func (p *Peers) SetInDegreeByPubKeyHex(key string, inDegree int64)

func (*Peers) ToIDSlice

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

ToIDSlice peers struct by ID

func (*Peers) ToPeerByUsedSlice

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

ToPeerByUsedSlice sorted peers list

func (*Peers) ToPeerSlice

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

ToPeerSlice returns a slice of peers sorted

func (*Peers) ToPubKeySlice

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

ToPubKeySlice peers struct by public key

type PubKeyPeers

type PubKeyPeers map[string]*Peer

PubKeyPeers map of peers sorted by public key

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