piecedownloader

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBlockDuplicate is returned from PieceDownloader.GotBlock method when the received block is already present.
	ErrBlockDuplicate = errors.New("received duplicate block")
	// ErrBlockNotRequested is returned from PieceDownloader.GotBlock method when the received block is not requested yet.
	ErrBlockNotRequested = errors.New("received not requested block")
)

Functions

This section is empty.

Types

type Peer added in v0.5.0

type Peer interface {
	RequestPiece(index, begin, length uint32)
	CancelPiece(index, begin, length uint32)
	EnabledFast() bool
}

Peer of a Torrent.

type PieceDownloader

type PieceDownloader struct {
	Piece       *piece.Piece
	Peer        Peer
	AllowedFast bool
	Buffer      bufferpool.Buffer
	// contains filtered or unexported fields
}

PieceDownloader downloads all blocks of a piece from a peer.

func New

func New(pi *piece.Piece, pe Peer, allowedFast bool, buf bufferpool.Buffer) *PieceDownloader

New returns a new PieceDownloader.

func (*PieceDownloader) CancelPending

func (d *PieceDownloader) CancelPending()

CancelPending is called to cancel pending requests to the peer. Must be called when remaining blocks are downloaded from another peer.

func (*PieceDownloader) Choked

func (d *PieceDownloader) Choked()

Choked must be called when the peer has choked us. This will cancel pending reuqests.

func (*PieceDownloader) Done

func (d *PieceDownloader) Done() bool

Done returns true if all blocks of the piece has been downloaded.

func (*PieceDownloader) GotBlock

func (d *PieceDownloader) GotBlock(block piece.Block, data []byte) error

GotBlock must be called when a block is received from the piece.

func (*PieceDownloader) Rejected

func (d *PieceDownloader) Rejected(block piece.Block)

Rejected must be called when the peer has rejected a piece request.

func (*PieceDownloader) RequestBlocks

func (d *PieceDownloader) RequestBlocks(queueLength int)

RequestBlocks is called to request remaining blocks of the piece up to `queueLength`.

Jump to

Keyboard shortcuts

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