downloader

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: LGPL-3.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	States = 0
	Blocks = 1
	Pkgs   = 2
)

Variables

View Source
var (
	MinBlockRoundFetch = 500
	MaxBlockRoundFetch = 1000 // Amount of rounds of blocks to allow fetching per request

	MinStateFetch = 1
	MaxStateFetch = 384 // Amount of node state values to allow fetching per request

	MinPkgsFetch     = 1
	MaxPkgsFetch     = 500              // Amount of kpgs to allow fetching per request
	RttMaxEstimate   = 60 * time.Second // Maximum Round-trip time to target for download requests
	QosConfidenceCap = 10               // Number of peers above which not to modify RTT confidence
	RttMinConfidence = 0.1              // Worse confidence factor in our estimated RTT value
	TtlScaling       = 3                // Constant scaling factor for RTT -> TTL conversion
	TtlLimit         = 90 * time.Second // Maximum TTL allowance to prevent reaching crazy timeouts
	BytesPerRound    = 3 * 100          // Average bits of blocks per round
	BytesPerPkg      = 10 * 1024        //Average bit of kpg

)

Functions

This section is empty.

Types

type BlockFetcher

type BlockFetcher struct {
	// contains filtered or unexported fields
}

BlockFetcher schedules requests for fetching blocks according a given rounds range.

func StartFetchBlocks

func StartFetchBlocks(roundFrom, roundTo uint64, peers map[string]FetcherPeer,
	dropPeerFn peerDropFn, autoStop bool, stage protocol.SyncStage, chain blockchain, blockCh chan *types.Block) *BlockFetcher

func (*BlockFetcher) DeliverData

func (bf *BlockFetcher) DeliverData(id string, data interface{}, kind int) error

func (*BlockFetcher) Finish

func (bf *BlockFetcher) Finish()

func (*BlockFetcher) Register

func (bf *BlockFetcher) Register(peer FetcherPeer) error

func (*BlockFetcher) Wait

func (bf *BlockFetcher) Wait() error

Wait blocks until the fetcher is done or canceled.

type FetcherPeer

type FetcherPeer interface {
	GetID() string
	RequestNodeData(hashes []common.Hash) error
	RequestSyncPkgs(stage protocol.SyncStage, hashes []common.Hash) error
	RequestSyncBlocks(stage protocol.SyncStage, roundFrom uint64, roundTo uint64) error
}

type Peer

type Peer struct {
	FP FetcherPeer // Peer used to fetch data
	// contains filtered or unexported fields
}

func (*Peer) FetchBlocks

func (p *Peer) FetchBlocks(stage protocol.SyncStage, roundFrom uint64, roundTo uint64) error

FetchBodies sends blocks range or a block hash retrieval request to the remote peer.

func (*Peer) FetchNodeData

func (p *Peer) FetchNodeData(hashes []common.Hash) error

FetchNodeData sends a node state data retrieval request to the remote peer.

func (*Peer) FetchPkgs

func (p *Peer) FetchPkgs(stage protocol.SyncStage, hashes []common.Hash) error

FetchBodies sends packages retrieval request to the remote peer.

func (*Peer) GetIdle

func (p *Peer) GetIdle() int32

GetIdle return 0 if the peer is idle else return 0

func (*Peer) GetRtt

func (p *Peer) GetRtt() time.Duration

func (*Peer) GetThroughput

func (p *Peer) GetThroughput() float64

func (*Peer) SetIdle

func (p *Peer) SetIdle(delivered int)

SetNodeDataIdle sets the peer to idle, allowing it to execute new state trie data retrieval requests. Its estimated state retrieval throughput is updated with that measured just now.

func (*Peer) SetIdleWithoutDelivered

func (p *Peer) SetIdleWithoutDelivered()

func (*Peer) SetRtt

func (p *Peer) SetRtt(rtt time.Duration)

func (*Peer) SetThroughput

func (p *Peer) SetThroughput(throughput float64)

type StateSync

type StateSync struct {
	// contains filtered or unexported fields
}

StateSync schedules requests for downloading a particular state trie defined by a given state root.

func SyncState

func SyncState(peers map[string]FetcherPeer, dropPeerFn peerDropFn, root common.Hash, chaindb dbwrapper.Database) *StateSync

syncState starts downloading state with the given root Hash and peers.

func (*StateSync) Cancel

func (f *StateSync) Cancel() error

Cancel cancels the fetcher and waits until it has shut down.

func (*StateSync) DeliverData

func (s *StateSync) DeliverData(id string, data [][]byte) (err error)

deliverData injects a new batch of node state data received from a remote node.

func (*StateSync) Wait

func (f *StateSync) Wait() error

Wait blocks until the fetcher is done or canceled.

Jump to

Keyboard shortcuts

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