downloader

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: LGPL-3.0 Imports: 14 Imported by: 6

Documentation

Index

Constants

View Source
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
)
View Source
const MsgWaitTimeout = time.Second * 25

MsgWaitTimeout this timeout should not be happened, but we need to handle it in case of such errors.

Variables

View Source
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
)
View Source
var (

	// ErrIsSynchronising indicates downloader is synchronising
	ErrIsSynchronising = errors.New("Is synchronising")
)

Functions

func CodeToStr

func CodeToStr(code uint16) string

CodeToStr message code -> message string

Types

type BlockHeadersMsgBody

type BlockHeadersMsgBody struct {
	Magic   uint32
	Headers []*types.BlockHeader
}

BlockHeadersMsgBody represents a message struct for BlockHeadersMsg

type BlocksMsgBody

type BlocksMsgBody struct {
	Magic  uint32
	Blocks []*types.Block
}

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

func (d *Downloader) Cancel()

Cancel cancels current session.

func (*Downloader) DeliverMsg

func (d *Downloader) DeliverMsg(peerID string, msg *p2p.Message)

DeliverMsg called by seeleprotocol to deliver received msg from network

func (*Downloader) IsSyncStatusNone added in v1.2.7

func (d *Downloader) IsSyncStatusNone() bool

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.

Jump to

Keyboard shortcuts

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