return err;
}
-tr_errno
+int
tr_ioTestPiece( const tr_torrent * tor,
int pieceIndex )
{
- int err;
uint8_t hash[SHA_DIGEST_LENGTH];
-
- err = recalculateHash( tor, pieceIndex, hash );
-
- if( !err && memcmp( hash, tor->info.pieces[pieceIndex].hash,
- SHA_DIGEST_LENGTH ) )
- err = TR_ERROR_IO_CHECKSUM;
-
- tr_tordbg ( tor, "piece %d hash check: %s",
- pieceIndex, ( err ? "FAILED" : "OK" ) );
-
- return err;
+ const tr_errno err = recalculateHash( tor, pieceIndex, hash );
+ return !err && !memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH );
}
const uint8_t * writeme );
/**
- * returns 0 if the piece matches its metainfo's SHA1 checksum,
- * or TR_ERROR_IO_* if there was a problem reading the piece,
- * or TR_ERROR if the checksum didn't match.
+ * returns nonzero if the piece matches its metainfo's SHA1 checksum.
*/
-tr_errno tr_ioTestPiece( const tr_torrent*,
- int piece );
+int tr_ioTestPiece( const tr_torrent*,
+ int piece );
/**
if( tr_cpPieceIsComplete( tor->completion, e->pieceIndex ) )
{
const tr_piece_index_t p = e->pieceIndex;
- const tr_errno err = tr_ioTestPiece( tor, p );
+ const int ok = tr_ioTestPiece( tor, p );
- if( err )
+ if( !ok )
{
tr_torerr( tor,
- _(
- "Piece %lu, which was just downloaded, failed its checksum test: %s" ),
- (unsigned long)p, tr_errorString( err ) );
+ _( "Piece %lu, which was just downloaded, failed its checksum test" ),
+ (unsigned long)p );
}
- tr_torrentSetHasPiece( tor, p, !err );
+ tr_torrentSetHasPiece( tor, p, ok );
tr_torrentSetPieceChecked( tor, p, TRUE );
- tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p,
- !err );
+ tr_peerMgrSetBlame( tor->session->peerMgr, tor->info.hash, p, ok );
- if( err )
+ if( !ok )
gotBadPiece( t, p );
else
{
{
const int wasComplete = tr_cpPieceIsComplete(
tor->completion, i );
- const tr_errno err = tr_ioTestPiece( tor, i );
- if( !err ) /* yay */
+ if( tr_ioTestPiece( tor, i ) ) /* yay */
{
tr_torrentSetHasPiece( tor, i, TRUE );
if( !wasComplete )