network

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2019 License: LGPL-3.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DurShort  = 3 * time.Second
	DurMiddle = 5 * 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
)

protocol code

View Source
const (
	ForceSyncInternal = 10 * time.Second
	DiscoverInternal  = 10 * time.Second
	ReqStatusTimeout  = 5 * time.Second // must less than ForceSyncInternal

	SyncTimeout = int64(20)
)

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

Functions

func NewPeerSet

func NewPeerSet(discover *p2p.DiscoverManager) *peerSet

NewPeerSet

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)

func (*BlockCache) FirstHeight

func (c *BlockCache) FirstHeight() uint32

func (*BlockCache) Iterate

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

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
	// InsertChain insert a block to local chain
	InsertChain(block *types.Block, isSyncing bool) error
	// SetStableBlock set local chain's latest stable block
	SetStableBlock(hash common.Hash, height uint32) error
	// Verify verify block
	Verify(block *types.Block) error
	// ReceiveConfirm received a confirm message from remote peer
	ReceiveConfirm(info *BlockConfirmData) (err error)
	// GetConfirms get a block's confirms from local chain
	GetConfirms(query *GetConfirmInfo) []types.SignData
	// ReceiveConfirms received a block's confirm info
	ReceiveConfirms(pack BlockConfirms)
}

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 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, txPool TxPool, discover *p2p.DiscoverManager, nodeVersion uint32) *ProtocolManager

func (*ProtocolManager) Start

func (pm *ProtocolManager) Start()

Start

func (*ProtocolManager) Stop

func (pm *ProtocolManager) Stop()

Stop

type TxPool

type TxPool interface {
	// AddTxs add transaction
	AddTxs(txs []*types.Transaction) error
	// Remove remove transaction
	Remove(keys []common.Hash)
}

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