Documentation ¶
Index ¶
- Constants
- Variables
- func CodeToStr(code uint16) string
- type BlockHeadersMsgBody
- type BlocksMsgBody
- type Downloader
- func (d *Downloader) Cancel()
- func (d *Downloader) DeliverMsg(peerID string, msg *p2p.Message)
- func (d *Downloader) RegisterPeer(peerID string, peer Peer)
- func (d *Downloader) Synchronise(id string, head common.Hash) error
- func (d *Downloader) Terminate()
- func (d *Downloader) UnRegisterPeer(peerID string)
- type Peer
- type PrivatedownloaderAPI
- type SeeleBackend
- type SyncInfo
Constants ¶
const ( // GetBlockHeadersMsg message type for getting block headers GetBlockHeadersMsg uint16 = 8 // BlockHeadersMsg message type for delivering block headers BlockHeadersMsg uint16 = 9 // GetBlocksMsg message type for getting blocks GetBlocksMsg uint16 = 10 // BlocksPreMsg is sent before BlockMsg, containing block numbers of BlockMsg. BlocksPreMsg uint16 = 11 // BlocksMsg message type for delivering blocks BlocksMsg uint16 = 12 )
const MsgWaitTimeout = time.Second * 25
MsgWaitTimeout this timeout should not be happened, but we need to handle it in case of such errors.
Variables ¶
var ( // MaxBlockFetch amount of blocks to be fetched per retrieval request MaxBlockFetch = 10 // MaxHeaderFetch amount of block headers to be fetched per retrieval request MaxHeaderFetch = 256 // MaxForkAncestry maximum chain reorganisation MaxForkAncestry = 90000 //MaxMessageLength maximum message length MaxMessageLength = 2 * 1024 * 1024 )
var ( // ErrIsSynchronising indicates downloader is synchronising ErrIsSynchronising = errors.New("Is synchronising") )
Functions ¶
Types ¶
type BlockHeadersMsgBody ¶
type BlockHeadersMsgBody struct { Magic uint32 Headers []*types.BlockHeader }
BlockHeadersMsgBody represents a message struct for BlockHeadersMsg
type BlocksMsgBody ¶
BlocksMsgBody represents a message struct for BlocksMsg
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader sync block chain with remote peer
func NewDownloader ¶
func NewDownloader(chain *core.Blockchain, seele SeeleBackend) *Downloader
NewDownloader create Downloader
func (*Downloader) DeliverMsg ¶
func (d *Downloader) DeliverMsg(peerID string, msg *p2p.Message)
DeliverMsg called by seeleprotocol to deliver received msg from network
func (*Downloader) RegisterPeer ¶
func (d *Downloader) RegisterPeer(peerID string, peer Peer)
RegisterPeer add peer to download routine
func (*Downloader) Synchronise ¶
func (d *Downloader) Synchronise(id string, head common.Hash) error
Synchronise try to sync with remote peer.
func (*Downloader) Terminate ¶
func (d *Downloader) Terminate()
Terminate close Downloader, cannot called anymore.
func (*Downloader) UnRegisterPeer ¶
func (d *Downloader) UnRegisterPeer(peerID string)
UnRegisterPeer remove peer from download routine
type Peer ¶
type Peer interface { Head() (common.Hash, *big.Int) RequestHeadersByHashOrNumber(magic uint32, origin common.Hash, num uint64, amount int, reverse bool) error RequestBlocksByHashOrNumber(magic uint32, origin common.Hash, num uint64, amount int) error GetPeerRequestInfo() (uint32, common.Hash, uint64, int) DisconnectPeer(reason string) }
Peer define some interfaces that request peer data
type PrivatedownloaderAPI ¶
type PrivatedownloaderAPI struct {
// contains filtered or unexported fields
}
PrivatedownloaderAPI provides an API to access downloader information.
func NewPrivatedownloaderAPI ¶
func NewPrivatedownloaderAPI(d *Downloader) *PrivatedownloaderAPI
NewPrivatedownloaderAPI creates a new PrivatedownloaderAPI object for rpc service.
func (*PrivatedownloaderAPI) GetStatus ¶
func (api *PrivatedownloaderAPI) GetStatus() *SyncInfo
GetStatus gets the SyncInfo.
func (*PrivatedownloaderAPI) IsSyncing ¶
func (api *PrivatedownloaderAPI) IsSyncing() bool
type SeeleBackend ¶
type SeeleBackend interface { TxPool() *core.TransactionPool DebtPool() *core.DebtPool }
SeeleBackend wraps all methods required for downloader.
type SyncInfo ¶
type SyncInfo struct { Status string // readable string of downloader.syncStatus Duration string // duration in seconds StartNum uint64 // start block number Amount uint64 // amount of blocks need to download Downloaded uint64 }
SyncInfo sync information for current downloader sessoin.