Changeset 5045
- Timestamp:
- Feb 15, 2008, 6:25:42 PM (13 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/inout.c
r5042 r5045 222 222 ****/ 223 223 224 static int224 static tr_errno 225 225 tr_ioRecalculateHash( const tr_torrent * tor, 226 226 int pieceIndex, … … 245 245 { 246 246 const int bytesThisPass = MIN( bytesLeft, (int)sizeof(buf) ); 247 interr = tr_ioRead( tor, pieceIndex, offset, bytesThisPass, buf );247 tr_errno err = tr_ioRead( tor, pieceIndex, offset, bytesThisPass, buf ); 248 248 if( err ) 249 249 return err; … … 257 257 } 258 258 259 int 259 tr_errno 260 260 tr_ioTestPiece( const tr_torrent * tor, int pieceIndex ) 261 261 { 262 int err; 262 263 uint8_t hash[SHA_DIGEST_LENGTH]; 263 const int ret = tr_ioRecalculateHash( tor, pieceIndex, hash ) 264 || memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH ); 264 265 err = tr_ioRecalculateHash( tor, pieceIndex, hash ); 266 267 if( !err && memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH ) ) 268 err = TR_ERROR; 269 265 270 tr_dbg ("torrent [%s] piece %d hash check: %s", 266 tor->info.name, pieceIndex, ( ret ? "FAILED" : "OK" )); 267 return ret; 268 } 269 270 int 271 tr_ioHash( tr_torrent * tor, int pieceIndex ) 272 { 273 int ret; 274 const int success = !tr_ioTestPiece( tor, pieceIndex ); 275 276 if( success ) 277 { 278 tr_dbg( "Piece %d hash OK", pieceIndex ); 279 tr_cpPieceAdd( tor->completion, pieceIndex ); 280 ret = TR_OK; 281 } 282 else 283 { 284 tr_err( "Piece %d hash FAILED", pieceIndex ); 285 tr_cpPieceRem( tor->completion, pieceIndex ); 286 ret = TR_ERROR; 287 } 288 289 tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, 290 pieceIndex, success ); 291 292 return ret; 293 } 271 tor->info.name, pieceIndex, ( err ? "FAILED" : "OK" )); 272 273 return err; 274 } -
trunk/libtransmission/inout.h
r5042 r5045 51 51 52 52 /** 53 * returns true if the piece matches its metainfo's SHA1 checksum, 54 * false otherwise. 53 * returns 0 if the piece matches its metainfo's SHA1 checksum, 54 * or TR_ERROR_IO_* if there was a problem reading the piece, 55 * or TR_ERROR if the checksum didn't match. 55 56 */ 56 int tr_ioTestPiece( const tr_torrent*, int piece ); 57 58 59 /** 60 * tests the specified piece and uses the results to 61 * update the torrent's "completion" and "blame" fields. 62 */ 63 int tr_ioHash ( tr_torrent*, int piece ); 57 tr_errno tr_ioTestPiece( const tr_torrent*, int piece ); 64 58 65 59 -
trunk/libtransmission/peer-msgs.c
r5037 r5045 1456 1456 if( tr_cpPieceIsComplete( tor->completion, req->index ) ) 1457 1457 { 1458 if( tr_ioHash( tor, req->index ) ) 1459 { 1458 const tr_errno err = tr_ioTestPiece( tor, req->index ); 1459 1460 tr_torrentSetHasPiece( tor, req->index, !err ); 1461 tr_torrentSetPieceChecked( tor, req->index, TRUE ); 1462 tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, req->index, !err ); 1463 1464 if( !err ) 1465 fireClientHave( msgs, req->index ); 1466 else 1460 1467 gotBadPiece( msgs, req->index ); 1461 return 0;1462 }1463 1464 tr_torrentSetPieceChecked( tor, req->index, TRUE );1465 fireClientHave( msgs, req->index );1466 1468 } 1467 1469 -
trunk/libtransmission/verify.c
r5042 r5045 91 91 else if( !tr_torrentIsPieceChecked( tor, i ) ) 92 92 { 93 const int check = tr_ioTestPiece( tor, i ); 94 tr_torrentSetHasPiece( tor, i, !check ); 93 const tr_errno err = tr_ioTestPiece( tor, i ); 94 95 if( !err ) /* yay */ 96 { 97 tr_torrentSetHasPiece( tor, i, TRUE ); 98 } 99 else 100 { 101 /* if we were wrong about it being complete, 102 * reset and start again. if we were right about 103 * it being incomplete, do nothing -- we don't 104 * want to lose blocks in those incomplete pieces */ 105 106 if( tr_cpPieceIsComplete( tor->completion, i ) ) 107 tr_torrentSetHasPiece( tor, i, FALSE ); 108 } 109 95 110 tr_torrentSetPieceChecked( tor, i, TRUE ); 96 111 }
Note: See TracChangeset
for help on using the changeset viewer.