Documentation ¶
Index ¶
- Constants
- type AddressPeers
- type ByID
- type ByPubHex
- type ByUsed
- type IDPeers
- type JSONPeers
- type Listener
- type NetAddrPeers
- type Peer
- func (p *Peer) Address() (a common.Address)
- func (*Peer) Descriptor() ([]byte, []int)
- func (p *Peer) Equals(cmp *Peer) bool
- func (m *Peer) GetHeight() int64
- func (m *Peer) GetID() uint64
- func (m *Peer) GetInDegree() int64
- func (m *Peer) GetNetAddr() string
- func (m *Peer) GetPubKeyHex() string
- func (m *Peer) GetUsed() int64
- func (*Peer) ProtoMessage()
- func (p *Peer) PubKeyBytes() ([]byte, error)
- func (m *Peer) Reset()
- func (m *Peer) String() string
- func (m *Peer) XXX_DiscardUnknown()
- func (m *Peer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Peer) XXX_Merge(src proto.Message)
- func (m *Peer) XXX_Size() int
- func (m *Peer) XXX_Unmarshal(b []byte) error
- type PeerStore
- type Peers
- func (p *Peers) AddPeer(peer *Peer)
- func (p *Peers) EmitNewPeer(peer *Peer)
- func (p *Peers) GetHeightByPubKeyHex(key string) int64
- func (p *Peers) IncInDegreeByPubKeyHex(key string)
- func (p *Peers) Len() int
- func (p *Peers) NextHeightByPubKeyHex(key string) int64
- func (p *Peers) OnNewPeer(cb func(*Peer))
- func (p *Peers) ReadByAddress(key common.Address) (Peer, bool)
- func (p *Peers) ReadByID(key uint64) (Peer, bool)
- func (p *Peers) ReadByNetAddr(key string) (Peer, bool)
- func (p *Peers) ReadByPubKey(key string) (Peer, bool)
- func (p *Peers) RemovePeer(peer *Peer)
- func (p *Peers) RemovePeerByID(id uint64)
- func (p *Peers) RemovePeerByPubKey(pubKey string)
- func (p *Peers) SetHeightByPubKeyHex(key string, height int64)
- func (p *Peers) SetInDegreeByPubKeyHex(key string, inDegree int64)
- func (p *Peers) ToIDSlice() []uint64
- func (p *Peers) ToPeerByUsedSlice() []*Peer
- func (p *Peers) ToPeerSlice() []*Peer
- func (p *Peers) ToPubKeySlice() []string
- type PubKeyPeers
- type StaticPeers
Constants ¶
const PeerNIL uint64 = 0
PeerNIL is used for nil peer id
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByPubHex ¶
type ByPubHex []*Peer
ByPubHex implements sort.Interface for Peers based on the PubKeyHex field.
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 ¶
NewJSONPeers creates a new JSONPeers store.
type NetAddrPeers ¶
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 ¶
ExcludePeer is used to exclude a single peer from a list of peers.
func ExcludePeers ¶
ExcludePeers is used to exclude multiple peers from a list of peers.
func (*Peer) Descriptor ¶
func (*Peer) GetInDegree ¶
func (*Peer) GetNetAddr ¶
func (*Peer) GetPubKeyHex ¶
func (*Peer) ProtoMessage ¶
func (*Peer) ProtoMessage()
func (*Peer) PubKeyBytes ¶
PubKeyBytes returns the public key bytes for a peer
func (*Peer) XXX_DiscardUnknown ¶
func (m *Peer) XXX_DiscardUnknown()
func (*Peer) XXX_Unmarshal ¶
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 NewPeersFromSlice ¶
NewPeersFromSlice create a new peers struct from a subset of peers
func (*Peers) EmitNewPeer ¶
EmitNewPeer emits an event for all listeners as soon as a peer joins
func (*Peers) GetHeightByPubKeyHex ¶
func (*Peers) IncInDegreeByPubKeyHex ¶
func (*Peers) NextHeightByPubKeyHex ¶
func (*Peers) RemovePeer ¶
RemovePeer removes a peer from the peers struct
func (*Peers) RemovePeerByID ¶
RemovePeerByID removes a peer based on their ID
func (*Peers) RemovePeerByPubKey ¶
RemovePeerByPubKey removes a peer by their public key
func (*Peers) SetHeightByPubKeyHex ¶
func (*Peers) SetInDegreeByPubKeyHex ¶
func (*Peers) ToPeerByUsedSlice ¶
ToPeerByUsedSlice sorted peers list
func (*Peers) ToPeerSlice ¶
ToPeerSlice returns a slice of peers sorted
func (*Peers) ToPubKeySlice ¶
ToPubKeySlice peers struct 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.