Documentation ¶
Index ¶
- Constants
- Variables
- type BasePeer
- type BasePeerSet
- type BlockMessage
- type BlockchainMessage
- type BlocksMessage
- type Chain
- type FilterAddMessage
- type FilterClearMessage
- type FilterLoadMessage
- type GetBlockMessage
- type GetBlocksMessage
- type GetHeadersMessage
- type GetMerkleBlockMessage
- type HeadersMessage
- type MerkleBlockMessage
- type MineBlockMessage
- type PeerInfo
- type ProtocolReactor
- func (pr *ProtocolReactor) AddPeer(peer *p2p.Peer) error
- func (pr *ProtocolReactor) GetChannels() []*connection.ChannelDescriptor
- func (pr *ProtocolReactor) OnStart() error
- func (pr *ProtocolReactor) OnStop()
- func (pr *ProtocolReactor) Receive(chID byte, src *p2p.Peer, msgBytes []byte)
- func (pr *ProtocolReactor) RemovePeer(peer *p2p.Peer, reason interface{})
- type StatusRequestMessage
- type StatusResponseMessage
- type Switch
- type SyncManager
- func (sm *SyncManager) BestPeer() *PeerInfo
- func (sm *SyncManager) DialPeerWithAddress(addr *p2p.NetAddress) error
- func (sm *SyncManager) GetNetwork() string
- func (sm *SyncManager) GetPeerInfos() []*PeerInfo
- func (sm *SyncManager) IsCaughtUp() bool
- func (sm *SyncManager) IsListening() bool
- func (sm *SyncManager) NodeInfo() *p2p.NodeInfo
- func (sm *SyncManager) PeerCount() int
- func (sm *SyncManager) Start() error
- func (sm *SyncManager) Stop()
- func (sm *SyncManager) StopPeer(peerID string) error
- type TransactionMessage
Constants ¶
const ( BlockchainChannel = byte(0x40) BlockRequestByte = byte(0x10) BlockResponseByte = byte(0x11) HeadersRequestByte = byte(0x12) HeadersResponseByte = byte(0x13) BlocksRequestByte = byte(0x14) BlocksResponseByte = byte(0x15) StatusRequestByte = byte(0x20) StatusResponseByte = byte(0x21) NewTransactionByte = byte(0x30) NewMineBlockByte = byte(0x40) FilterLoadByte = byte(0x50) FilterAddByte = byte(0x51) FilterClearByte = byte(0x52) MerkleRequestByte = byte(0x60) MerkleResponseByte = byte(0x61) )
protocol msg byte
Variables ¶
var (
ErrPeerMisbehave = errors.New("peer is misbehave")
)
Functions ¶
This section is empty.
Types ¶
type BasePeer ¶ added in v1.0.4
type BasePeer interface { 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 ¶ added in v1.0.4
type BasePeerSet interface { StopPeerGracefully(string) IsBanned(ip string, level byte, reason string) bool }
BasePeerSet is the intergace for connection level peer manager
type BlockMessage ¶ added in v1.0.4
type BlockMessage struct {
RawBlock []byte
}
BlockMessage response get block msg
func NewBlockMessage ¶ added in v1.0.4
func NewBlockMessage(block *types.Block) (*BlockMessage, error)
NewBlockMessage construct bock response msg
func (*BlockMessage) GetBlock ¶ added in v1.0.4
func (m *BlockMessage) GetBlock() (*types.Block, error)
GetBlock get block from msg
func (*BlockMessage) String ¶ added in v1.0.4
func (m *BlockMessage) String() string
type BlockchainMessage ¶
type BlockchainMessage interface {
String() string
}
BlockchainMessage is a generic message for this reactor.
func DecodeMessage ¶
func DecodeMessage(bz []byte) (msgType byte, msg BlockchainMessage, err error)
DecodeMessage decode msg
type BlocksMessage ¶ added in v1.0.4
type BlocksMessage struct {
RawBlocks [][]byte
}
BlocksMessage is one of the bytom msg type
func NewBlocksMessage ¶ added in v1.0.4
func NewBlocksMessage(blocks []*types.Block) (*BlocksMessage, error)
NewBlocksMessage create a new BlocksMessage
func (*BlocksMessage) GetBlocks ¶ added in v1.0.4
func (m *BlocksMessage) GetBlocks() ([]*types.Block, error)
GetBlocks returns the blocks in the msg
func (*BlocksMessage) String ¶ added in v1.0.7
func (m *BlocksMessage) String() string
type Chain ¶ added in v1.0.4
type Chain interface { BestBlockHeader() *types.BlockHeader BestBlockHeight() uint64 CalcNextSeed(*bc.Hash) (*bc.Hash, error) GetBlockByHash(*bc.Hash) (*types.Block, error) GetBlockByHeight(uint64) (*types.Block, error) GetHeaderByHash(*bc.Hash) (*types.BlockHeader, error) GetHeaderByHeight(uint64) (*types.BlockHeader, error) GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error) InMainChain(bc.Hash) bool ProcessBlock(*types.Block) (bool, error) ValidateTx(*types.Tx) (bool, error) }
Chain is the interface for Bytom core
type FilterAddMessage ¶ added in v1.0.5
type FilterAddMessage struct {
Address []byte
}
FilterAddMessage tells the receiving peer to add address to the filter.
func (*FilterAddMessage) String ¶ added in v1.0.7
func (m *FilterAddMessage) String() string
type FilterClearMessage ¶ added in v1.0.5
type FilterClearMessage struct{}
FilterClearMessage tells the receiving peer to remove a previously-set filter.
func (*FilterClearMessage) String ¶ added in v1.0.7
func (m *FilterClearMessage) String() string
type FilterLoadMessage ¶ added in v1.0.5
type FilterLoadMessage struct {
Addresses [][]byte
}
FilterLoadMessage tells the receiving peer to filter the transactions according to address.
func (*FilterLoadMessage) String ¶ added in v1.0.7
func (m *FilterLoadMessage) String() string
type GetBlockMessage ¶ added in v1.0.4
GetBlockMessage request blocks from remote peers by height/hash
func (*GetBlockMessage) GetHash ¶ added in v1.0.4
func (m *GetBlockMessage) GetHash() *bc.Hash
GetHash reutrn the hash of the request
func (*GetBlockMessage) String ¶ added in v1.0.4
func (m *GetBlockMessage) String() string
type GetBlocksMessage ¶ added in v1.0.4
GetBlocksMessage is one of the bytom msg type
func NewGetBlocksMessage ¶ added in v1.0.4
func NewGetBlocksMessage(blockLocator []*bc.Hash, stopHash *bc.Hash) *GetBlocksMessage
NewGetBlocksMessage create a new GetBlocksMessage
func (*GetBlocksMessage) GetBlockLocator ¶ added in v1.0.4
func (m *GetBlocksMessage) GetBlockLocator() []*bc.Hash
GetBlockLocator return the locator of the msg
func (*GetBlocksMessage) GetStopHash ¶ added in v1.0.4
func (m *GetBlocksMessage) GetStopHash() *bc.Hash
GetStopHash return the stop hash of the msg
func (*GetBlocksMessage) String ¶ added in v1.0.7
func (m *GetBlocksMessage) String() string
type GetHeadersMessage ¶ added in v1.0.4
GetHeadersMessage is one of the bytom msg type
func NewGetHeadersMessage ¶ added in v1.0.4
func NewGetHeadersMessage(blockLocator []*bc.Hash, stopHash *bc.Hash) *GetHeadersMessage
NewGetHeadersMessage return a new GetHeadersMessage
func (*GetHeadersMessage) GetBlockLocator ¶ added in v1.0.4
func (m *GetHeadersMessage) GetBlockLocator() []*bc.Hash
GetBlockLocator return the locator of the msg
func (*GetHeadersMessage) GetStopHash ¶ added in v1.0.4
func (m *GetHeadersMessage) GetStopHash() *bc.Hash
GetStopHash return the stop hash of the msg
func (*GetHeadersMessage) String ¶ added in v1.0.7
func (m *GetHeadersMessage) String() string
type GetMerkleBlockMessage ¶ added in v1.0.5
GetMerkleBlockMessage request merkle blocks from remote peers by height/hash
func (*GetMerkleBlockMessage) GetHash ¶ added in v1.0.5
func (m *GetMerkleBlockMessage) GetHash() *bc.Hash
GetHash reutrn the hash of the request
func (*GetMerkleBlockMessage) String ¶ added in v1.0.7
func (m *GetMerkleBlockMessage) String() string
type HeadersMessage ¶ added in v1.0.4
type HeadersMessage struct {
RawHeaders [][]byte
}
HeadersMessage is one of the bytom msg type
func NewHeadersMessage ¶ added in v1.0.4
func NewHeadersMessage(headers []*types.BlockHeader) (*HeadersMessage, error)
NewHeadersMessage create a new HeadersMessage
func (*HeadersMessage) GetHeaders ¶ added in v1.0.4
func (m *HeadersMessage) GetHeaders() ([]*types.BlockHeader, error)
GetHeaders return the headers in the msg
func (*HeadersMessage) String ¶ added in v1.0.7
func (m *HeadersMessage) String() string
type MerkleBlockMessage ¶ added in v1.0.5
type MerkleBlockMessage struct { RawBlockHeader []byte TxHashes [][32]byte RawTxDatas [][]byte StatusHashes [][32]byte RawTxStatuses [][]byte Flags []byte }
MerkleBlockMessage return the merkle block to client
func NewMerkleBlockMessage ¶ added in v1.0.5
func NewMerkleBlockMessage() *MerkleBlockMessage
NewMerkleBlockMessage construct merkle block message
func (*MerkleBlockMessage) String ¶ added in v1.0.7
func (m *MerkleBlockMessage) String() string
type MineBlockMessage ¶
type MineBlockMessage struct {
RawBlock []byte
}
MineBlockMessage new mined block msg
func NewMinedBlockMessage ¶
func NewMinedBlockMessage(block *types.Block) (*MineBlockMessage, error)
NewMinedBlockMessage construct new mined block msg
func (*MineBlockMessage) GetMineBlock ¶
func (m *MineBlockMessage) GetMineBlock() (*types.Block, error)
GetMineBlock get mine block from msg
func (*MineBlockMessage) String ¶
func (m *MineBlockMessage) String() string
type PeerInfo ¶ added in v1.0.4
type PeerInfo struct { ID string `json:"peer_id"` 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 ProtocolReactor ¶
type ProtocolReactor struct { p2p.BaseReactor // contains filtered or unexported fields }
ProtocolReactor handles new coming protocol message.
func NewProtocolReactor ¶
func NewProtocolReactor(sm *SyncManager, peers *peerSet) *ProtocolReactor
NewProtocolReactor returns the reactor of whole blockchain.
func (*ProtocolReactor) AddPeer ¶
func (pr *ProtocolReactor) AddPeer(peer *p2p.Peer) error
AddPeer implements Reactor by sending our state to peer.
func (*ProtocolReactor) GetChannels ¶
func (pr *ProtocolReactor) GetChannels() []*connection.ChannelDescriptor
GetChannels implements Reactor
func (*ProtocolReactor) OnStart ¶
func (pr *ProtocolReactor) OnStart() error
OnStart implements BaseService
func (*ProtocolReactor) Receive ¶
func (pr *ProtocolReactor) Receive(chID byte, src *p2p.Peer, msgBytes []byte)
Receive implements Reactor by handling 4 types of messages (look below).
func (*ProtocolReactor) RemovePeer ¶
func (pr *ProtocolReactor) RemovePeer(peer *p2p.Peer, reason interface{})
RemovePeer implements Reactor by removing peer from the pool.
type StatusRequestMessage ¶
type StatusRequestMessage struct{}
StatusRequestMessage status request msg
func (*StatusRequestMessage) String ¶
func (m *StatusRequestMessage) String() string
type StatusResponseMessage ¶
StatusResponseMessage get status response msg
func NewStatusResponseMessage ¶
func NewStatusResponseMessage(blockHeader *types.BlockHeader, hash *bc.Hash) *StatusResponseMessage
NewStatusResponseMessage construct get status response msg
func (*StatusResponseMessage) GetGenesisHash ¶ added in v0.5.1
func (m *StatusResponseMessage) GetGenesisHash() *bc.Hash
GetGenesisHash get hash from msg
func (*StatusResponseMessage) GetHash ¶
func (m *StatusResponseMessage) GetHash() *bc.Hash
GetHash get hash from msg
func (*StatusResponseMessage) String ¶
func (m *StatusResponseMessage) String() string
type Switch ¶ added in v1.0.8
type Switch interface { AddReactor(name string, reactor p2p.Reactor) p2p.Reactor StopPeerGracefully(string) NodeInfo() *p2p.NodeInfo Start() (bool, error) Stop() bool IsListening() bool DialPeerWithAddress(addr *p2p.NetAddress) error Peers() *p2p.PeerSet IsBanned(peerID string, level byte, reason string) bool }
type SyncManager ¶
type SyncManager struct {
// contains filtered or unexported fields
}
SyncManager Sync Manager is responsible for the business layer information synchronization
func NewSyncManager ¶
func NewSyncManager(config *cfg.Config, chain Chain, txPool *core.TxPool, dispatcher *event.Dispatcher) (*SyncManager, error)
CreateSyncManager create sync manager and set switch.
func (*SyncManager) BestPeer ¶ added in v1.0.4
func (sm *SyncManager) BestPeer() *PeerInfo
BestPeer return the highest p2p peerInfo
func (*SyncManager) DialPeerWithAddress ¶ added in v1.0.8
func (sm *SyncManager) DialPeerWithAddress(addr *p2p.NetAddress) error
func (*SyncManager) GetNetwork ¶ added in v1.0.8
func (sm *SyncManager) GetNetwork() string
func (*SyncManager) GetPeerInfos ¶ added in v1.0.4
func (sm *SyncManager) GetPeerInfos() []*PeerInfo
GetPeerInfos return peer info of all peers
func (*SyncManager) IsCaughtUp ¶ added in v1.0.4
func (sm *SyncManager) IsCaughtUp() bool
IsCaughtUp check wheather the peer finish the sync
func (*SyncManager) IsListening ¶ added in v1.0.8
func (sm *SyncManager) IsListening() bool
func (*SyncManager) NodeInfo ¶
func (sm *SyncManager) NodeInfo() *p2p.NodeInfo
func (*SyncManager) PeerCount ¶ added in v1.0.8
func (sm *SyncManager) PeerCount() int
func (*SyncManager) Start ¶
func (sm *SyncManager) Start() error
func (*SyncManager) StopPeer ¶ added in v1.0.4
func (sm *SyncManager) StopPeer(peerID string) error
StopPeer try to stop peer by given ID
type TransactionMessage ¶ added in v1.0.4
type TransactionMessage struct {
RawTx []byte
}
TransactionMessage notify new tx msg
func NewTransactionMessage ¶ added in v1.0.4
func NewTransactionMessage(tx *types.Tx) (*TransactionMessage, error)
NewTransactionMessage construct notify new tx msg
func (*TransactionMessage) GetTransaction ¶ added in v1.0.4
func (m *TransactionMessage) GetTransaction() (*types.Tx, error)
GetTransaction get tx from msg
func (*TransactionMessage) String ¶ added in v1.0.4
func (m *TransactionMessage) String() string