tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex ) { tr_block_index_t block; const tr_torrent * tor = cp->tor; const tr_file * file = &tor->info.files[fileIndex]; const tr_block_index_t firstBlock = file->offset / tor->blockSize; const tr_block_index_t lastBlock = file->length ? ( ( file->offset + file->length - 1 ) / tor->blockSize ) : firstBlock; tr_assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece, "file->offset %"PRIu64"; file->length %"PRIu64"; " "pieceSize %"PRIu32"; blockSize %"PRIu32"; " "firstBlock %"PRIu64"; lastBlock %"PRIu64, file->offset, file->length, tor->info.pieceSize, tor->blockSize, firstBlock, lastBlock ); tr_assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece, "file->offset %"PRIu64"; file->length %"PRIu64"; " "pieceSize %"PRIu32"; blockSize %"PRIu32"; " "firstBlock %"PRIu64"; lastBlock %"PRIu64, file->offset, file->length, tor->info.pieceSize, tor->blockSize, firstBlock, lastBlock ); for( block=firstBlock; block<=lastBlock; ++block ) if( !tr_cpBlockIsComplete( cp, block ) ) return FALSE; return TRUE; }
void tr_cpBlockAdd( tr_completion * cp, tr_block_index_t block ) { const tr_torrent * tor = cp->tor; if( !tr_cpBlockIsComplete( cp, block ) ) { const tr_piece_index_t piece = tr_torBlockPiece( tor, block ); const int blockSize = tr_torBlockCountBytes( tor, block ); ++cp->completeBlocks[piece]; if( tr_cpPieceIsComplete( cp, piece ) ) tr_bitfieldAdd( cp->pieceBitfield, piece ); tr_bitfieldAdd( cp->blockBitfield, block ); cp->sizeNow += blockSize; cp->haveValidIsDirty = 1; cp->sizeWhenDoneIsDirty = 1; } }
tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex ) { tr_block_index_t block; const tr_torrent * tor = cp->tor; const tr_file * file = &tor->info.files[fileIndex]; const tr_block_index_t firstBlock = file->offset / tor->blockSize; const tr_block_index_t lastBlock = file->length ? ( ( file->offset + file->length - 1 ) / tor->blockSize ) : firstBlock; assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece ); assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece ); for( block=firstBlock; block<=lastBlock; ++block ) if( !tr_cpBlockIsCompleteFast( cp, block ) ) return FALSE; return TRUE; }
void tr_cpBlockAdd(tr_completion* cp, tr_block_index_t block) { tr_torrent const* tor = cp->tor; if (!tr_cpBlockIsComplete(cp, block)) { tr_piece_index_t const piece = tr_torBlockPiece(cp->tor, block); tr_bitfieldAdd(&cp->blockBitfield, block); cp->sizeNow += tr_torBlockCountBytes(tor, block); cp->haveValidIsDirty = true; cp->sizeWhenDoneIsDirty |= tor->info.pieces[piece].dnd; } }