network

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

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")
)
View Source
var (
	ErrHandleLstStatusMsg = errors.New("stable height can't > current height")
	ErrHandleGetBlocksMsg = errors.New("invalid request blocks'param")
	ErrTxExpiration       = errors.New("received transaction expiration time illegal")
)

Functions

func NewPeerSet

func NewPeerSet(discover *p2p.DiscoverManager, dm *deputynode.Manager) *peerSet

NewPeerSet

func VerifyLemoAddress added in v1.3.0

func VerifyLemoAddress(lemoAddress string) bool

VerifyLemoAddress check lemoAddress

func VerifyNode added in v1.3.0

func VerifyNode(node string) bool

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

func (c *BlockCache) Iterate(callback func(*types.Block) bool)

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 BlockHashData

type BlockHashData struct {
	Height uint32
	Hash   common.Hash
}

BlockHashData

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

func (*ConfirmCache) Size

func (c *ConfirmCache) Size() int

Size calculate cache's size

type DiscoverReqData

type DiscoverReqData struct {
	Sequence uint
}

for find node

type DiscoverResData

type DiscoverResData struct {
	Sequence uint
	Nodes    []string
}

for find node

type GetBlocksData

type GetBlocksData struct {
	From uint32
	To   uint32
}

getBlocksData

type GetConfirmInfo

type GetConfirmInfo struct {
	Height uint32
	Hash   common.Hash
}

getConfirmInfo

type GetLatestStatus

type GetLatestStatus struct {
	Revert uint32
}

GetLatestStatus get latest status

type GetSingleBlockData

type GetSingleBlockData struct {
	Hash   common.Hash
	Height uint32
}

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

func (*MsgCache) Pop added in v1.3.0

func (m *MsgCache) Pop() *p2p.Msg

Pop

func (*MsgCache) Push added in v1.3.0

func (m *MsgCache) Push(msg *p2p.Msg)

Push

func (*MsgCache) Size added in v1.3.0

func (m *MsgCache) Size() int

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

func (*ProtocolManager) Start

func (pm *ProtocolManager) Start()

Start

func (*ProtocolManager) Stop

func (pm *ProtocolManager) Stop()

Stop

type TxPool

type TxPool interface {
	/* 本节点出块时,从交易池中取出交易进行打包,但并不从交易池中删除 */
	Get(time uint32, size int) []*types.Transaction
	/* 收到一笔新的交易 */
	RecvTx(tx *types.Transaction) bool
}

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.

Jump to

Keyboard shortcuts

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