Documentation ¶
Index ¶
- Constants
- type BlockInfo
- type BlockSyncMgr
- func (this *BlockSyncMgr) Close()
- func (this *BlockSyncMgr) OnAddNode(nodeId uint64)
- func (this *BlockSyncMgr) OnBlockReceive(fromID uint64, blockSize uint32, block *types.Block, merkleRoot common.Uint256)
- func (this *BlockSyncMgr) OnDelNode(nodeId uint64)
- func (this *BlockSyncMgr) OnHeaderReceive(fromID uint64, headers []*types.Header)
- func (this *BlockSyncMgr) Start()
- type NodeWeight
- type NodeWeights
- type P2PServer
- func (this *P2PServer) GetConnectionCnt() uint32
- func (this *P2PServer) GetConnectionState() uint32
- func (this *P2PServer) GetID() uint64
- func (this *P2PServer) GetNeighborAddrs() []common.PeerAddr
- func (this *P2PServer) GetNetWork() p2pnet.P2P
- func (this *P2PServer) GetPID() *evtActor.PID
- func (this *P2PServer) GetPort() uint16
- func (this *P2PServer) GetTime() int64
- func (this *P2PServer) GetVersion() uint32
- func (this *P2PServer) OnAddNode(id uint64)
- func (this *P2PServer) OnBlockReceive(fromID uint64, blockSize uint32, block *types.Block, merkleRoot comm.Uint256)
- func (this *P2PServer) OnDelNode(id uint64)
- func (this *P2PServer) OnHeaderReceive(fromID uint64, headers []*types.Header)
- func (this *P2PServer) Send(p *peer.Peer, msg msgtypes.Message, isConsensus bool) error
- func (this *P2PServer) SetAddr(addr string)
- func (this *P2PServer) SetPID(pid *evtActor.PID)
- func (this *P2PServer) Start() error
- func (this *P2PServer) Stop()
- func (this *P2PServer) WaitForPeersStart()
- func (this *P2PServer) WaitForSyncBlkFinish()
- func (this *P2PServer) Xmit(message interface{}) error
- type ReconnectAddrs
- type SyncFlightInfo
- func (this *SyncFlightInfo) GetFailedTimes(nodeId uint64) int
- func (this *SyncFlightInfo) GetNodeId() uint64
- func (this *SyncFlightInfo) GetStartTime() time.Time
- func (this *SyncFlightInfo) GetTotalFailedTimes() int
- func (this *SyncFlightInfo) MarkFailedNode()
- func (this *SyncFlightInfo) ResetStartTime()
- func (this *SyncFlightInfo) SetNodeId(nodeId uint64)
Constants ¶
const ( SYNC_MAX_HEADER_FORWARD_SIZE = 5000 //keep CurrentHeaderHeight - CurrentBlockHeight <= SYNC_MAX_HEADER_FORWARD_SIZE SYNC_MAX_FLIGHT_HEADER_SIZE = 1 //Number of headers on flight SYNC_MAX_FLIGHT_BLOCK_SIZE = 50 //Number of blocks on flight SYNC_MAX_BLOCK_CACHE_SIZE = 500 //Cache size of block wait to commit to ledger SYNC_HEADER_REQUEST_TIMEOUT = 2 //s, Request header timeout time. If header haven't receive after SYNC_HEADER_REQUEST_TIMEOUT second, retry SYNC_BLOCK_REQUEST_TIMEOUT = 2 //s, Request block timeout time. If block haven't received after SYNC_BLOCK_REQUEST_TIMEOUT second, retry SYNC_NEXT_BLOCK_TIMES = 3 //Request times of next height block SYNC_NEXT_BLOCKS_HEIGHT = 2 //for current block height plus next SYNC_NODE_RECORD_SPEED_CNT = 3 //Record speed count for accuracy SYNC_NODE_RECORD_TIME_CNT = 3 //Record request time for accuracy SYNC_NODE_SPEED_INIT = 100 * 1024 //Init a big speed (100MB/s) for every node in first round SYNC_MAX_ERROR_RESP_TIMES = 5 //Max error headers/blocks response times, if reaches, delete it SYNC_MAX_HEIGHT_OFFSET = 5 //Offset of the max height and current height )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockInfo ¶
type BlockInfo struct {
// contains filtered or unexported fields
}
BlockInfo is used for saving block information in cache
type BlockSyncMgr ¶
type BlockSyncMgr struct {
// contains filtered or unexported fields
}
BlockSyncMgr is the manager class to deal with block sync
func NewBlockSyncMgr ¶
func NewBlockSyncMgr(server *P2PServer) *BlockSyncMgr
NewBlockSyncMgr return a BlockSyncMgr instance
func (*BlockSyncMgr) OnAddNode ¶
func (this *BlockSyncMgr) OnAddNode(nodeId uint64)
OnAddNode to node list when a new node added
func (*BlockSyncMgr) OnBlockReceive ¶
func (this *BlockSyncMgr) OnBlockReceive(fromID uint64, blockSize uint32, block *types.Block, merkleRoot common.Uint256)
OnBlockReceive receive block from net
func (*BlockSyncMgr) OnDelNode ¶
func (this *BlockSyncMgr) OnDelNode(nodeId uint64)
OnDelNode remove from node list. When the node disconnect
func (*BlockSyncMgr) OnHeaderReceive ¶
func (this *BlockSyncMgr) OnHeaderReceive(fromID uint64, headers []*types.Header)
OnHeaderReceive receive header from net
type NodeWeight ¶
type NodeWeight struct {
// contains filtered or unexported fields
}
NodeWeight record some params of node, using for sort
func (*NodeWeight) AddErrorRespCnt ¶
func (this *NodeWeight) AddErrorRespCnt()
AddErrorRespCnt incre receive error header/block count
func (*NodeWeight) AddTimeoutCnt ¶
func (this *NodeWeight) AddTimeoutCnt()
AddTimeoutCnt incre timeout count
func (*NodeWeight) AppendNewReqtime ¶
func (this *NodeWeight) AppendNewReqtime()
AppendNewReqTime append new request time
func (*NodeWeight) AppendNewSpeed ¶
func (this *NodeWeight) AppendNewSpeed(s float32)
addNewSpeed apend the new speed to tail, remove the oldest one
func (*NodeWeight) GetErrorRespCnt ¶
func (this *NodeWeight) GetErrorRespCnt() int
GetErrorRespCnt get the error response count
func (*NodeWeight) Weight ¶
func (this *NodeWeight) Weight() float32
Weight calculate node's weight for sort. Highest weight node will be accessed first for next request.
type NodeWeights ¶
type NodeWeights []*NodeWeight
NodeWeights implement sorting
func (NodeWeights) Len ¶
func (nws NodeWeights) Len() int
func (NodeWeights) Less ¶
func (nws NodeWeights) Less(i, j int) bool
func (NodeWeights) Swap ¶
func (nws NodeWeights) Swap(i, j int)
type P2PServer ¶
type P2PServer struct { ReconnectAddrs // contains filtered or unexported fields }
P2PServer control all network activities
func NewServer ¶
func NewServer() *P2PServer
NewServer return a new p2pserver according to the pubkey
func (*P2PServer) GetConnectionCnt ¶
GetConnectionCnt return the established connect count
func (*P2PServer) GetConnectionState ¶
Todo: remove it if no use
func (*P2PServer) GetNeighborAddrs ¶
GetNeighborAddrs return all nbr`s address
func (*P2PServer) GetNetWork ¶
GetNetWork returns the low level netserver
func (*P2PServer) GetTime ¶
GetTime return lastet contact time
func (*P2PServer) GetVersion ¶
GetVersion return self version
func (*P2PServer) OnAddNode ¶
OnAddNode adds the peer id to the block sync mgr
func (*P2PServer) OnBlockReceive ¶
func (this *P2PServer) OnBlockReceive(fromID uint64, blockSize uint32, block *types.Block, merkleRoot comm.Uint256)
OnBlockReceive adds the block from network
func (*P2PServer) OnDelNode ¶
OnDelNode removes the peer id from the block sync mgr
func (*P2PServer) OnHeaderReceive ¶
OnHeaderReceive adds the header list from network
func (*P2PServer) Send ¶
Send tranfer buffer to peer
func (*P2PServer) SetAddr ¶
SetAddr sets base58 formatted account address
func (*P2PServer) Stop ¶
func (this *P2PServer) Stop()
Stop halt all service by send signal to channels
func (*P2PServer) WaitForPeersStart ¶
func (this *P2PServer) WaitForPeersStart()
WaitForPeersStart check whether enough peer linked in loop
type ReconnectAddrs ¶
ReconnectAddrs contain addr need to reconnect
type SyncFlightInfo ¶
type SyncFlightInfo struct { Height uint32 //BlockHeight of HeaderHeight // contains filtered or unexported fields }
SyncFlightInfo record the info of fight object(header or block)
func NewSyncFlightInfo ¶
func NewSyncFlightInfo(height uint32, nodeId uint64) *SyncFlightInfo
NewSyncFlightInfo return a new SyncFlightInfo instance
func (*SyncFlightInfo) GetFailedTimes ¶
func (this *SyncFlightInfo) GetFailedTimes(nodeId uint64) int
GetFailedTimes return failed times of a node
func (*SyncFlightInfo) GetNodeId ¶
func (this *SyncFlightInfo) GetNodeId() uint64
GetNodeId return current node id for sending msg
func (*SyncFlightInfo) GetStartTime ¶
func (this *SyncFlightInfo) GetStartTime() time.Time
GetStartTime return the start time of request
func (*SyncFlightInfo) GetTotalFailedTimes ¶
func (this *SyncFlightInfo) GetTotalFailedTimes() int
GetTotalFailedTimes return the total failed times of request
func (*SyncFlightInfo) MarkFailedNode ¶
func (this *SyncFlightInfo) MarkFailedNode()
MarkFailedNode mark node failed, after request timeout
func (*SyncFlightInfo) SetNodeId ¶
func (this *SyncFlightInfo) SetNodeId(nodeId uint64)
SetNodeId set a new node id