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(torrent parser.TorrentFile) (tracker *PieceTracker)
NewPieceTracker returns a new PieceTracker object for the torrent
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 (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 (tracker *PieceTracker) Fill(index uint32)
Fill is used to revive the piecetracker while resuming the torrent
func (tracker *PieceTracker) IsDone() (result bool)
IsDone tells if the torrent file has been successfully received
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 (tracker *PieceTracker) PieceIsDone(pieceIndex uint32) (result bool)
PieceIsDone tells if the pieceIndex piece has been downloaded successfully
func (tracker *PieceTracker) PrintPercentageDone()
PrintPercentageDone prints the percentage of download completed on the screen
func (tracker *PieceTracker) Reset(index uint32)
Reset the piece - Called when invalid SHA