Documentation
¶
Index ¶
- Constants
- Variables
- func NewPeerSet(discover *p2p.DiscoverManager, dm *deputynode.Manager) *peerSet
- func VerifyLemoAddress(lemoAddress string) bool
- func VerifyNode(node string) bool
- type BlockCache
- func (c *BlockCache) Add(block *types.Block)
- func (c *BlockCache) Clear(height uint32)
- func (c *BlockCache) FirstHeight() uint32
- func (c *BlockCache) IsExit(hash common.Hash, height uint32) bool
- func (c *BlockCache) Iterate(callback func(*types.Block) bool)
- func (c *BlockCache) Remove(block *types.Block)
- func (c *BlockCache) Size() int
- type BlockChain
- type BlockConfirmData
- type BlockConfirms
- type BlockHashData
- type ConfirmCache
- type DiscoverReqData
- type DiscoverResData
- type GetBlocksData
- type GetConfirmInfo
- type GetLatestStatus
- type GetSingleBlockData
- type LatestStatus
- type MsgCache
- type ProtocolHandshake
- type ProtocolManager
- type TxPool
Constants ¶
View Source
const ( DurShort = 3 * time.Second DurLong = 10 * time.Second )
View Source
const ( HeartbeatMsg = 0x01 // heartbeat message ProHandshakeMsg = 0x02 // protocol handshake message LstStatusMsg = 0x03 // latest status message GetLstStatusMsg = 0x04 // get latest status message BlockHashMsg = 0x05 // block's hash message TxsMsg = 0x06 // transactions message GetBlocksMsg = 0x07 // get blocks message BlocksMsg = 0x08 // blocks message ConfirmMsg = 0x09 // a confirm of one block message GetConfirmsMsg = 0x0a // get confirms of one block message ConfirmsMsg = 0x0b // confirms of one block message // for find node DiscoverReqMsg = 0x0c // find node request message DiscoverResMsg = 0x0d // find node response message // for lemochain-server and light node GetBlocksWithChangeLogMsg = 0x0e )
protocol code
View Source
const ( ForceSyncInternal = 10 * time.Second DiscoverInternal = 10 * time.Second DefaultLimit = 50 // default connection limit )
Variables ¶
View Source
var ( ErrInvalidCode = errors.New("invalid code about net message") ErrReadTimeout = errors.New("protocol handshake timeout") ErrReadMsg = errors.New("protocol handshake failed: read remote message failed") )
View Source
var ( ErrNodeInvalid = errors.New("discover node is invalid") ErrRequestBlocks = errors.New("invalid request blocks' param") )
Functions ¶
func NewPeerSet ¶
func NewPeerSet(discover *p2p.DiscoverManager, dm *deputynode.Manager) *peerSet
NewPeerSet
func VerifyLemoAddress ¶ added in v1.3.0
VerifyLemoAddress check lemoAddress
func VerifyNode ¶ added in v1.3.0
VerifyNode check string node (node = nodeID@IP:Port)
Types ¶
type BlockCache ¶
type BlockCache struct {
// contains filtered or unexported fields
}
func NewBlockCache ¶
func NewBlockCache() *BlockCache
func (*BlockCache) Add ¶
func (c *BlockCache) Add(block *types.Block)
func (*BlockCache) Clear ¶
func (c *BlockCache) Clear(height uint32)
Clear clear blocks of block'Height <= height
func (*BlockCache) FirstHeight ¶
func (c *BlockCache) FirstHeight() uint32
func (*BlockCache) IsExit ¶ added in v1.3.0
func (c *BlockCache) IsExit(hash common.Hash, height uint32) bool
IsExit
func (*BlockCache) Remove ¶ added in v1.3.0
func (c *BlockCache) Remove(block *types.Block)
Remove remove a block
func (*BlockCache) Size ¶
func (c *BlockCache) Size() int
type BlockChain ¶
type BlockChain interface {
Genesis() *types.Block
// HasBlock if block exist in local chain
HasBlock(hash common.Hash) bool
// GetBlockByHeight get block by height from local chain
GetBlockByHeight(height uint32) *types.Block
// GetBlockByHash get block by hash from local chain
GetBlockByHash(hash common.Hash) *types.Block
// CurrentBlock local chain's current block
CurrentBlock() *types.Block
// StableBlock local chain's latest stable block
StableBlock() *types.Block
// InsertBlock insert a block to local chain
InsertBlock(block *types.Block) error
// ReceiveConfirm received a confirm message from remote peer
InsertConfirm(info *BlockConfirmData)
// InsertStableConfirms received a block's confirm info
InsertStableConfirms(pack BlockConfirms)
// IsInBlackList
IsInBlackList(b *types.Block) bool
}
BlockChain
type BlockConfirmData ¶
type BlockConfirmData struct {
Hash common.Hash // block Hash
Height uint32 // block height
SignInfo types.SignData // block sign info
}
blockConfirmData
type BlockConfirms ¶
type BlockConfirms struct {
Height uint32 // block height
Hash common.Hash // block hash
Pack []types.SignData
}
BlockConfirms confirms of a block
type ConfirmCache ¶
type ConfirmCache struct {
// contains filtered or unexported fields
}
ConfirmCache record block confirm data which block doesn't exist in local
func NewConfirmCache ¶
func NewConfirmCache() *ConfirmCache
func (*ConfirmCache) Clear ¶
func (c *ConfirmCache) Clear(height uint32)
Clear clear dirty data form cache
func (*ConfirmCache) Pop ¶
func (c *ConfirmCache) Pop(height uint32, hash common.Hash) []*BlockConfirmData
Pop get special confirm data by height and hash and then delete from cache
func (*ConfirmCache) Push ¶
func (c *ConfirmCache) Push(data *BlockConfirmData)
Push push block confirm data to cache
type GetLatestStatus ¶
type GetLatestStatus struct {
Revert uint32
}
GetLatestStatus get latest status
type GetSingleBlockData ¶
GetSingleBlockData
type LatestStatus ¶
type LatestStatus struct {
CurHeight uint32
CurHash common.Hash
StaHeight uint32
StaHash common.Hash
}
LatestStatus latest peer's status
type MsgCache ¶ added in v1.3.0
type MsgCache struct {
// contains filtered or unexported fields
}
func NewMsgCache ¶ added in v1.3.0
func NewMsgCache() *MsgCache
type ProtocolHandshake ¶
type ProtocolHandshake struct {
ChainID uint16
GenesisHash common.Hash
NodeVersion uint32
LatestStatus LatestStatus
}
ProtocolHandshake protocol handshake
func (*ProtocolHandshake) Bytes ¶
func (phs *ProtocolHandshake) Bytes() []byte
Bytes object to bytes
type ProtocolManager ¶
type ProtocolManager struct {
// contains filtered or unexported fields
}
func NewProtocolManager ¶
func NewProtocolManager(chainID uint16, nodeID p2p.NodeID, chain BlockChain, dm *deputynode.Manager, txPool TxPool, discover *p2p.DiscoverManager, limit int, nodeVersion uint32) *ProtocolManager
type TxPool ¶
type TxPool interface {
/* 本节点出块时,从交易池中取出交易进行打包,但并不从交易池中删除 */
Get(time uint32, size int) []*types.Transaction
/* 收到一笔新的交易 */
RecvTx(tx *types.Transaction) bool
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package p2p implements the Lemochain p2p network protocols.
|
Package p2p implements the Lemochain p2p network protocols. |
|
Package rpc provides access to the exported methods of an object across a network or other I/O connection.
|
Package rpc provides access to the exported methods of an object across a network or other I/O connection. |
Click to show internal directories.
Click to hide internal directories.