void tr_cpBlockBitfieldSet( tr_completion_t * cp, uint8_t * bitfield ) { tr_torrent_t * tor = cp->tor; int i, j; int startBlock, endBlock; int pieceComplete; for( i = 0; i < cp->tor->info.pieceCount; i++ ) { startBlock = tr_pieceStartBlock( i ); endBlock = startBlock + tr_pieceCountBlocks( i ); pieceComplete = 1; for( j = startBlock; j < endBlock; j++ ) { if( tr_bitfieldHas( bitfield, j ) ) { tr_cpBlockAdd( cp, j ); } else { pieceComplete = 0; } } if( pieceComplete ) { tr_cpPieceAdd( cp, i ); } } }
void tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t piece ) { tr_block_index_t i, f, l; tr_torGetPieceBlockRange( cp->tor, piece, &f, &l ); for( i=f; i<=l; ++i ) tr_cpBlockAdd( cp, i ); }
void tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t piece ) { const tr_torrent * tor = cp->tor; const tr_block_index_t start = tr_torPieceFirstBlock( tor, piece ); const tr_block_index_t end = start + tr_torPieceCountBlocks( tor, piece ); tr_block_index_t i; for( i = start; i < end; ++i ) tr_cpBlockAdd( cp, i ); }
void tr_cpPieceAdd( tr_completion_t * cp, int piece ) { tr_torrent_t * tor = cp->tor; int startBlock, endBlock, i; startBlock = tr_pieceStartBlock( piece ); endBlock = startBlock + tr_pieceCountBlocks( piece ); for( i = startBlock; i < endBlock; i++ ) { tr_cpBlockAdd( cp, i ); } tr_bitfieldAdd( cp->pieceBitfield, piece ); }
int tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * bitfield ) { int success = FALSE; assert( cp ); assert( bitfield ); assert( cp->blockBitfield ); if( tr_bitfieldTestFast( bitfield, cp->tor->blockCount - 1 ) ) { tr_block_index_t i; tr_cpReset( cp ); for( i = 0; i < cp->tor->blockCount; ++i ) if( tr_bitfieldHasFast( bitfield, i ) ) tr_cpBlockAdd( cp, i ); success = TRUE; } return success; }