netsync

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockchainChannel = byte(0x40)

	BlockRequestByte    = byte(0x10)
	BlockResponseByte   = byte(0x11)
	HeadersRequestByte  = byte(0x12)
	HeadersResponseByte = byte(0x13)
	BlocksRequestByte   = byte(0x14)
	BlocksResponseByte  = byte(0x15)
	HeaderRequestByte   = byte(0x16)
	HeaderResponseByte  = byte(0x17)
	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

This section is empty.

Functions

This section is empty.

Types

type BasePeer

type BasePeer interface {
	Addr() net.Addr
	ID() string
	ServiceFlag() consensus.ServiceFlag
	TrySend(byte, interface{}) bool
	IsOutbound() bool
	IsTrustworthy() bool
}

BasePeer is the interface for connection level peer

type BasePeerSet

type BasePeerSet interface {
	AddBannedPeer(string, string) error
	StopPeerGracefully(string)
}

BasePeerSet is the intergace for connection level peer manager

type BlockMessage

type BlockMessage struct {
	RawBlock []byte
}

BlockMessage response get block msg

func NewBlockMessage

func NewBlockMessage(block *massutil.Block) (*BlockMessage, error)

NewBlockMessage construct bock response msg

func (*BlockMessage) GetBlock

func (m *BlockMessage) GetBlock() (*massutil.Block, error)

GetBlock get block from msg

func (*BlockMessage) String

func (m *BlockMessage) String() string

String convert msg to string

type BlockchainMessage

type BlockchainMessage interface{}

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

type BlocksMessage struct {
	RawBlocks [][]byte
}

BlocksMessage is one of the mass msg type

func NewBlocksMessage

func NewBlocksMessage(blocks []*massutil.Block) (*BlocksMessage, error)

NewBlocksMessage create a new BlocksMessage

func (*BlocksMessage) GetBlocks

func (msg *BlocksMessage) GetBlocks() ([]*massutil.Block, error)

GetBlocks returns the blocks in the msg

type Chain

type Chain interface {
	BestBlockHeader() *wire.BlockHeader
	BestBlockHeight() uint64
	GetBlockByHash(*wire.Hash) (*massutil.Block, error)
	GetBlockByHeight(uint64) (*massutil.Block, error)
	GetHeaderByHash(*wire.Hash) (*wire.BlockHeader, error)
	GetHeaderByHeight(uint64) (*wire.BlockHeader, error)
	InMainChain(wire.Hash) bool
	ProcessBlock(*massutil.Block) (bool, error)
	ProcessTx(*massutil.Tx) (bool, error)
	ChainID() *wire.Hash
	Checkpoints() []config.Checkpoint
}

type FilterAddMessage

type FilterAddMessage struct {
	Address []byte
}

FilterAddMessage tells the receiving peer to add address to the filter.

type FilterClearMessage

type FilterClearMessage struct{}

FilterClearMessage tells the receiving peer to remove a previously-set filter.

type FilterLoadMessage

type FilterLoadMessage struct {
	Addresses [][]byte
}

FilterLoadMessage tells the receiving peer to filter the transactions according to address.

type GetBlockMessage

type GetBlockMessage struct {
	Height  uint64
	RawHash [32]byte
}

GetBlockMessage request blocks from remote peers by height/hash

func (*GetBlockMessage) GetHash

func (m *GetBlockMessage) GetHash() *wire.Hash

GetHash reutrn the hash of the request

func (*GetBlockMessage) String

func (m *GetBlockMessage) String() string

String convert msg to string

type GetBlocksMessage

type GetBlocksMessage struct {
	RawBlockLocator [][32]byte
	RawStopHash     [32]byte
}

GetBlocksMessage is one of the mass msg type

func NewGetBlocksMessage

func NewGetBlocksMessage(blockLocator []*wire.Hash, stopHash *wire.Hash) *GetBlocksMessage

NewGetBlocksMessage create a new GetBlocksMessage

func (*GetBlocksMessage) GetBlockLocator

func (msg *GetBlocksMessage) GetBlockLocator() []*wire.Hash

GetBlockLocator return the locator of the msg

func (*GetBlocksMessage) GetStopHash

func (msg *GetBlocksMessage) GetStopHash() *wire.Hash

GetStopHash return the stop hash of the msg

type GetHeaderMessage

type GetHeaderMessage struct {
	Height  uint64
	RawHash [32]byte
}

GetHeaderMessage request header from remote peers by height/hash

func (*GetHeaderMessage) GetHash

func (m *GetHeaderMessage) GetHash() *wire.Hash

GetHash reutrn the hash of the request

func (*GetHeaderMessage) String

func (m *GetHeaderMessage) String() string

String convert msg to string

type GetHeadersMessage

type GetHeadersMessage struct {
	RawBlockLocator [][32]byte
	RawStopHash     [32]byte
}

GetHeadersMessage is one of the mass msg type

func NewGetHeadersMessage

func NewGetHeadersMessage(blockLocator []*wire.Hash, stopHash *wire.Hash) *GetHeadersMessage

NewGetHeadersMessage return a new GetHeadersMessage

func (*GetHeadersMessage) GetBlockLocator

func (msg *GetHeadersMessage) GetBlockLocator() []*wire.Hash

GetBlockLocator return the locator of the msg

func (*GetHeadersMessage) GetStopHash

func (msg *GetHeadersMessage) GetStopHash() *wire.Hash

GetStopHash return the stop hash of the msg

type HeaderMessage

type HeaderMessage struct {
	RawHeader []byte
}

HeaderMessage response get header msg

func NewHeaderMessage

func NewHeaderMessage(header *wire.BlockHeader) (*HeaderMessage, error)

NewHeaderMessage construct bock response msg

func (*HeaderMessage) GetHeader

func (m *HeaderMessage) GetHeader() (*wire.BlockHeader, error)

GetHeader get header from msg

func (*HeaderMessage) String

func (m *HeaderMessage) String() string

String convert msg to string

type HeadersMessage

type HeadersMessage struct {
	RawHeaders [][]byte
}

HeadersMessage is one of the mass msg type

func NewHeadersMessage

func NewHeadersMessage(headers []*wire.BlockHeader) (*HeadersMessage, error)

NewHeadersMessage create a new HeadersMessage

func (*HeadersMessage) GetHeaders

func (msg *HeadersMessage) GetHeaders() ([]*wire.BlockHeader, error)

GetHeaders return the headers in the msg

type MineBlockMessage

type MineBlockMessage struct {
	RawBlock []byte
}

MineBlockMessage new mined block msg

func NewMinedBlockMessage

func NewMinedBlockMessage(block *massutil.Block) (*MineBlockMessage, error)

NewMinedBlockMessage construct new mined block msg

func (*MineBlockMessage) GetMineBlock

func (m *MineBlockMessage) GetMineBlock() (*massutil.Block, error)

GetMineBlock get mine block from msg

func (*MineBlockMessage) String

func (m *MineBlockMessage) String() string

String convert msg to string

type PeerInfo

type PeerInfo struct {
	ID         string `json:"peer_id"`
	RemoteAddr string `json:"remote_addr"`
	Height     uint64 `json:"height"`
	IsOutbound bool   `json:"is_outbound"`
	Delay      uint32 `json:"delay"`
}

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) OnStop

func (pr *ProtocolReactor) OnStop()

OnStop 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

String

type StatusResponseMessage

type StatusResponseMessage struct {
	Height      uint64
	RawHash     [32]byte
	GenesisHash [32]byte
}

StatusResponseMessage get status response msg

func NewStatusResponseMessage

func NewStatusResponseMessage(blockHeader *wire.BlockHeader, hash *wire.Hash) *StatusResponseMessage

NewStatusResponseMessage construct get status response msg

func (*StatusResponseMessage) GetGenesisHash

func (m *StatusResponseMessage) GetGenesisHash() *wire.Hash

GetGenesisHash get hash from msg

func (*StatusResponseMessage) GetHash

func (m *StatusResponseMessage) GetHash() *wire.Hash

GetHash get hash from msg

func (*StatusResponseMessage) String

func (m *StatusResponseMessage) String() string

String convert msg to string

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 *config.Config, chain Chain, txPool *blockchain.TxPool, newBlockCh chan *wire.Hash) (*SyncManager, error)

NewSyncManager create a sync manager

func (*SyncManager) BestPeer

func (sm *SyncManager) BestPeer() *PeerInfo

BestPeer return the highest p2p peerInfo

func (*SyncManager) GetNewTxCh

func (sm *SyncManager) GetNewTxCh() chan *massutil.Tx

GetNewTxCh return a unconfirmed transaction feed channel

func (*SyncManager) GetPeerInfos

func (sm *SyncManager) GetPeerInfos() []*PeerInfo

GetPeerInfos return peer info of all peers

func (*SyncManager) IsCaughtUp

func (sm *SyncManager) IsCaughtUp() bool

IsCaughtUp check wheather the peer finish the sync

func (*SyncManager) NodeInfo

func (sm *SyncManager) NodeInfo() *p2p.NodeInfo

NodeInfo get P2P peer node info

func (*SyncManager) NodePubKeyS

func (sm *SyncManager) NodePubKeyS() string

NodePubKeyS get P2P peer node pubKey string

func (*SyncManager) PeerCount

func (sm *SyncManager) PeerCount() int

GetPeerInfos return peer info of all peers

func (*SyncManager) Start

func (sm *SyncManager) Start()

Start start sync manager service

func (*SyncManager) Stop

func (sm *SyncManager) Stop()

Stop stop sync manager

func (*SyncManager) StopPeer

func (sm *SyncManager) StopPeer(peerID string) error

StopPeer try to stop peer by given ID

func (*SyncManager) Switch

func (sm *SyncManager) Switch() *p2p.Switch

Switch get sync manager switch

type TransactionMessage

type TransactionMessage struct {
	RawTx []byte
}

TransactionMessage notify new tx msg

func NewTransactionMessage

func NewTransactionMessage(tx *massutil.Tx) (*TransactionMessage, error)

NewTransactionMessage construct notify new tx msg

func (*TransactionMessage) GetTransaction

func (m *TransactionMessage) GetTransaction() (*massutil.Tx, error)

GetTransaction get tx from msg

func (*TransactionMessage) String

func (m *TransactionMessage) String() string

String

type TxPool

type TxPool interface {
	TxDescs() []*blockchain.TxDesc
	SetNewTxCh(chan *massutil.Tx)
}

Jump to

Keyboard shortcuts

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