uint64_t
tr_cpHaveValid( const tr_completion * cp )
{
- uint64_t b = 0;
- tr_piece_index_t i;
- const tr_torrent * tor = cp->tor;
-
- for( i = 0; i < tor->info.pieceCount; ++i )
+ uint64_t b = 0;
+ tr_piece_index_t i;
+ const tr_torrent * tor = cp->tor;
+ const uint64_t pieceSize = tor->info.pieceSize;
+ const uint64_t lastPieceSize = tor->lastPieceSize;
+ const tr_piece_index_t lastPiece = tor->info.pieceCount - 1;
+
+ for( i=0; i!=lastPiece; ++i )
if( tr_cpPieceIsComplete( cp, i ) )
- b += tr_torPieceCountBytes( tor, i );
+ b += pieceSize;
+
+ if( tr_cpPieceIsComplete( cp, lastPiece ) )
+ b += lastPieceSize;
return b;
}
tr_torrent * tor = NULL;
while( ( tor = tr_torrentNext( handle, tor ) ) )
- if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
- return tor;
+ if( *tor->info.hash == *torrentHash )
+ if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
+ return tor;
return NULL;
}