peers

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: AGPL-3.0 Imports: 12 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPeerMisbehave = errors.New("peer is misbehave")
	ErrNoValidPeer   = errors.New("Can't find valid fast sync peer")
)

Functions

This section is empty.

Types

type BasePeer

type BasePeer interface {
	Moniker() string
	Addr() net.Addr
	ID() string
	RemoteAddrHost() string
	ServiceFlag() consensus.ServiceFlag
	TrafficStatus() (*flowrate.Status, *flowrate.Status)
	TrySend(byte, interface{}) bool
	IsLAN() bool
}

BasePeer is the interface for connection level peer

type BasePeerSet

type BasePeerSet interface {
	StopPeerGracefully(string)
	IsBanned(ip string, level byte, reason string) bool
}

BasePeerSet is the intergace for connection level peer manager

type BroadcastMsg

type BroadcastMsg interface {
	FilterTargetPeers(ps *PeerSet) []string
	MarkSendRecord(ps *PeerSet, peers []string)
	GetChan() byte
	GetMsg() interface{}
	MsgString() string
}

type Peer

type Peer struct {
	BasePeer
	// contains filtered or unexported fields
}

func (*Peer) AddFilterAddress

func (p *Peer) AddFilterAddress(address []byte)

func (*Peer) AddFilterAddresses

func (p *Peer) AddFilterAddresses(addresses [][]byte)

func (*Peer) FilterClear

func (p *Peer) FilterClear()

func (*Peer) GetBlockByHeight

func (p *Peer) GetBlockByHeight(height uint64) bool

func (*Peer) GetBlocks

func (p *Peer) GetBlocks(locator []*bc.Hash, stopHash *bc.Hash) bool

func (*Peer) GetHeaders

func (p *Peer) GetHeaders(locator []*bc.Hash, stopHash *bc.Hash, skip uint64) bool

func (*Peer) GetPeerInfo

func (p *Peer) GetPeerInfo() *PeerInfo

func (*Peer) Height

func (p *Peer) Height() uint64

func (*Peer) IrreversibleHeight added in v0.2.0

func (p *Peer) IrreversibleHeight() uint64

func (*Peer) MarkBlock

func (p *Peer) MarkBlock(hash *bc.Hash)

func (*Peer) SendBlock

func (p *Peer) SendBlock(block *types.Block) (bool, error)

func (*Peer) SendBlocks

func (p *Peer) SendBlocks(blocks []*types.Block) (bool, error)

func (*Peer) SendHeaders

func (p *Peer) SendHeaders(headers []*types.BlockHeader) (bool, error)

func (*Peer) SendMerkleBlock

func (p *Peer) SendMerkleBlock(block *types.Block, txStatuses *bc.TransactionStatus) (bool, error)

func (*Peer) SendStatus

func (p *Peer) SendStatus(bestHeader, irreversibleHeader *types.BlockHeader) error

func (*Peer) SendTransactions

func (p *Peer) SendTransactions(txs []*types.Tx) error

func (*Peer) SetBestStatus added in v0.2.0

func (p *Peer) SetBestStatus(bestHeight uint64, bestHash *bc.Hash)

func (*Peer) SetIrreversibleStatus added in v0.2.0

func (p *Peer) SetIrreversibleStatus(irreversibleHeight uint64, irreversibleHash *bc.Hash)

type PeerInfo

type PeerInfo struct {
	ID                  string `json:"peer_id"`
	Moniker             string `json:"moniker"`
	RemoteAddr          string `json:"remote_addr"`
	Height              uint64 `json:"height"`
	Ping                string `json:"ping"`
	Duration            string `json:"duration"`
	TotalSent           int64  `json:"total_sent"`
	TotalReceived       int64  `json:"total_received"`
	AverageSentRate     int64  `json:"average_sent_rate"`
	AverageReceivedRate int64  `json:"average_received_rate"`
	CurrentSentRate     int64  `json:"current_sent_rate"`
	CurrentReceivedRate int64  `json:"current_received_rate"`
}

PeerInfo indicate peer status snap

type PeerSet

type PeerSet struct {
	BasePeerSet
	// contains filtered or unexported fields
}

func NewPeerSet

func NewPeerSet(basePeerSet BasePeerSet) *PeerSet

newPeerSet creates a new peer set to track the active participants.

func (*PeerSet) AddPeer

func (ps *PeerSet) AddPeer(peer BasePeer)

func (*PeerSet) BestIrreversiblePeer added in v0.2.0

func (ps *PeerSet) BestIrreversiblePeer(flag consensus.ServiceFlag) *Peer

func (*PeerSet) BestPeer

func (ps *PeerSet) BestPeer(flag consensus.ServiceFlag) *Peer

func (*PeerSet) BroadcastMsg

func (ps *PeerSet) BroadcastMsg(bm BroadcastMsg) error

BroadcastMsg Broadcast message to the target peers and mark the message send record

func (*PeerSet) BroadcastNewStatus

func (ps *PeerSet) BroadcastNewStatus(bestHeader, irreversibleHeader *types.BlockHeader) error

func (*PeerSet) BroadcastTx

func (ps *PeerSet) BroadcastTx(tx *types.Tx) error

func (*PeerSet) GetPeer

func (ps *PeerSet) GetPeer(id string) *Peer

Peer retrieves the registered peer with the given id.

func (*PeerSet) GetPeerInfos

func (ps *PeerSet) GetPeerInfos() []*PeerInfo

func (*PeerSet) GetPeersByHeight added in v0.3.0

func (ps *PeerSet) GetPeersByHeight(height uint64) []*Peer

func (*PeerSet) MarkBlock

func (ps *PeerSet) MarkBlock(peerID string, hash *bc.Hash)

func (*PeerSet) MarkBlockSignature

func (ps *PeerSet) MarkBlockSignature(peerID string, signature []byte)

func (*PeerSet) MarkStatus

func (ps *PeerSet) MarkStatus(peerID string, height uint64)

func (*PeerSet) MarkTx

func (ps *PeerSet) MarkTx(peerID string, txHash bc.Hash)

func (*PeerSet) PeersWithoutBlock

func (ps *PeerSet) PeersWithoutBlock(hash bc.Hash) []string

func (*PeerSet) PeersWithoutSignature added in v1.0.1

func (ps *PeerSet) PeersWithoutSignature(signature []byte) []string

func (*PeerSet) ProcessIllegal

func (ps *PeerSet) ProcessIllegal(peerID string, level byte, reason string)

func (*PeerSet) RemovePeer

func (ps *PeerSet) RemovePeer(peerID string)

func (*PeerSet) SendMsg

func (ps *PeerSet) SendMsg(peerID string, msgChannel byte, msg interface{}) bool

SendMsg send message to the target peer.

func (*PeerSet) SetIrreversibleStatus added in v1.0.1

func (ps *PeerSet) SetIrreversibleStatus(peerID string, height uint64, hash *bc.Hash)

func (*PeerSet) SetStatus

func (ps *PeerSet) SetStatus(peerID string, height uint64, hash *bc.Hash)

Jump to

Keyboard shortcuts

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