...

Package piece

import "github.com/concurrency-8/piece"
Overview
Index

Overview ▾

type PieceTracker

PieceTracker stores flags for blocks of pieces requested and received Requested[i][j] = true => jth block of ith piece has been requested

type PieceTracker struct {
    Torrent   parser.TorrentFile
    Requested [][]bool
    Received  [][]bool
    // contains filtered or unexported fields
}

func NewPieceTracker

func NewPieceTracker(torrent parser.TorrentFile) (tracker *PieceTracker)

NewPieceTracker returns a new PieceTracker object for the torrent

func (*PieceTracker) AddReceived

func (tracker *PieceTracker) AddReceived(block parser.PieceBlock)

AddReceived flags the received value of a block in a piece Invoked when a block is received

func (*PieceTracker) AddRequested

func (tracker *PieceTracker) AddRequested(block parser.PieceBlock)

AddRequested flags the request value of a block in a piece Invoked while requesting the block of a piece

func (*PieceTracker) Fill

func (tracker *PieceTracker) Fill(index uint32)

Fill is used to revive the piecetracker while resuming the torrent

func (*PieceTracker) IsDone

func (tracker *PieceTracker) IsDone() (result bool)

IsDone tells if the torrent file has been successfully received

func (*PieceTracker) Needed

func (tracker *PieceTracker) Needed(block parser.PieceBlock) bool

Needed checks if we want a block. If we have already requested all, we reset requested to be equal to received and request the remaining pieces

func (*PieceTracker) PieceIsDone

func (tracker *PieceTracker) PieceIsDone(pieceIndex uint32) (result bool)

PieceIsDone tells if the pieceIndex piece has been downloaded successfully

func (*PieceTracker) PrintPercentageDone

func (tracker *PieceTracker) PrintPercentageDone()

PrintPercentageDone prints the percentage of download completed on the screen

func (*PieceTracker) Reset

func (tracker *PieceTracker) Reset(index uint32)

Reset the piece - Called when invalid SHA