network

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: LGPL-3.0 Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DurShort = 3 * time.Second
	DurLong  = 10 * time.Second
)
View Source
const BlackBlockFile = "blackblocklist"

区块黑名单cache

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")
	ErrHandleLstStatusMsg = errors.New("stable height can't > current height")
	ErrHandleGetBlocksMsg = errors.New("invalid request blocks'param")
)
View Source
var (
	ErrInvalidNodeUri = errors.New("invalid node uri")
)

Functions

func InitBlockBlackCache added in v1.4.0

func InitBlockBlackCache(dataDir string) *invalidBlockCache

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

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. Return error for distribution project
	InsertBlock(block *types.Block) error
	// InsertConfirms received a block's confirm info
	InsertConfirms(height uint32, blockHash common.Hash, sigList []types.SignData)
	// 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 set 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 HashSet added in v1.4.0

type HashSet struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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, txGuard *txpool.TxGuard, discover *p2p.DiscoverManager, delayNodeLimit int, nodeVersion uint32, dataDir string) *ProtocolManager

func (*ProtocolManager) Start

func (pm *ProtocolManager) Start()

Start

func (*ProtocolManager) Stop

func (pm *ProtocolManager) Stop()

Stop

type TxPool

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

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