Changeset 7559
- Timestamp:
- Dec 31, 2008, 6:08:13 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/inout.c
r7543 r7559 211 211 ****/ 212 212 213 static int213 static tr_bool 214 214 recalculateHash( const tr_torrent * tor, 215 215 tr_piece_index_t pieceIndex, 216 void * buffer, 217 size_t buflen, 216 218 uint8_t * setme ) 217 219 { 218 220 size_t bytesLeft; 219 221 uint32_t offset = 0; 220 int success = TRUE; 222 tr_bool success = TRUE; 223 uint8_t stackbuf[MAX_STACK_ARRAY_SIZE]; 221 224 SHA_CTX sha; 222 225 223 assert( tor ); 224 assert( setme ); 226 /* fallback buffer */ 227 if( ( buffer == NULL ) || ( buflen < 1 ) ) 228 { 229 buffer = stackbuf; 230 buflen = sizeof( stackbuf ); 231 } 232 233 assert( tor != NULL ); 225 234 assert( pieceIndex < tor->info.pieceCount ); 235 assert( buffer != NULL ); 236 assert( buflen > 0 ); 237 assert( setme != NULL ); 226 238 227 239 SHA1_Init( &sha ); … … 230 242 while( bytesLeft ) 231 243 { 232 uint8_t buf[MAX_STACK_ARRAY_SIZE]; 233 const int len = MIN( bytesLeft, sizeof( buf ) ); 234 success = !tr_ioRead( tor, pieceIndex, offset, len, buf ); 244 const int len = MIN( bytesLeft, buflen ); 245 success = !tr_ioRead( tor, pieceIndex, offset, len, buffer ); 235 246 if( !success ) 236 247 break; 237 SHA1_Update( &sha, buf , len );248 SHA1_Update( &sha, buffer, len ); 238 249 offset += len; 239 250 bytesLeft -= len; … … 246 257 } 247 258 248 int 249 tr_ioTestPiece( const tr_torrent * tor, 250 int pieceIndex ) 259 tr_bool 260 tr_ioTestPiece( const tr_torrent * tor, 261 tr_piece_index_t pieceIndex, 262 void * buffer, 263 size_t buflen ) 251 264 { 252 265 uint8_t hash[SHA_DIGEST_LENGTH]; 253 const int recalculated = recalculateHash( tor, pieceIndex, hash ); 254 return recalculate d && !memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH );255 } 256 266 267 return recalculateHash( tor, pieceIndex, buffer, buflen, hash ) 268 && !memcmp( hash, tor->info.pieces[pieceIndex].hash, SHA_DIGEST_LENGTH ); 269 } -
trunk/libtransmission/inout.h
r7151 r7559 53 53 54 54 /** 55 * returns nonzero if the piece matches its metainfo's SHA1 checksum. 55 * @brief Test to see if the piece matches its metainfo's SHA1 checksum. 56 * 57 * @param optionalBuffer if calling tr_ioTestPiece() repeatedly, you can 58 * get best performance by providing a buffer with 59 * tor->info.pieceSize bytes. 56 60 */ 57 int tr_ioTestPiece( const tr_torrent*, 58 int piece ); 61 tr_bool tr_ioTestPiece( const tr_torrent * tor, 62 tr_piece_index_t piece, 63 void * optionalBuffer, 64 size_t optionalBufferLen ); 59 65 60 66 -
trunk/libtransmission/peer-mgr.c
r7551 r7559 1090 1090 { 1091 1091 const tr_piece_index_t p = e->pieceIndex; 1092 const tr_bool ok = tr_ioTestPiece( tor, p );1092 const tr_bool ok = tr_ioTestPiece( tor, p, NULL, 0 ); 1093 1093 1094 1094 if( !ok ) -
trunk/libtransmission/verify.c
r7404 r7559 61 61 62 62 static int 63 checkFile( tr_torrent * tor, 64 tr_file_index_t fileIndex, 65 int * abortFlag ) 63 checkFile( tr_torrent * tor, 64 void * buffer, 65 size_t buflen, 66 tr_file_index_t fileIndex, 67 int * abortFlag ) 66 68 { 67 69 tr_piece_index_t i; … … 85 87 else if( !tr_torrentIsPieceChecked( tor, i ) ) 86 88 { 87 const int wasComplete = tr_cpPieceIsComplete( 88 tor->completion, i ); 89 90 if( tr_ioTestPiece( tor, i ) ) /* yay */ 89 const int wasComplete = tr_cpPieceIsComplete( tor->completion, i ); 90 91 if( tr_ioTestPiece( tor, i, buffer, buflen ) ) /* yay */ 91 92 { 92 93 tr_torrentSetHasPiece( tor, i, TRUE ); … … 120 121 verifyThreadFunc( void * unused UNUSED ) 121 122 { 122 for( ; 123 for( ;; ) 123 124 { 124 125 int changed = 0; 125 126 tr_file_index_t i; 126 tr_torrent *tor;127 tr_torrent * tor; 127 128 struct verify_node * node; 129 void * buffer; 128 130 129 131 tr_lockLock( getVerifyLock( ) ); … … 142 144 tr_lockUnlock( getVerifyLock( ) ); 143 145 146 tr_torinf( tor, _( "Verifying torrent" ) ); 144 147 tor->verifyState = TR_VERIFY_NOW; 145 146 tr_torinf( tor, _( "Verifying torrent" ) ); 148 buffer = tr_new( uint8_t, tor->info.pieceSize ); 147 149 for( i = 0; i < tor->info.fileCount && !stopCurrent; ++i ) 148 changed |= checkFile( tor, i, &stopCurrent );149 150 changed |= checkFile( tor, buffer, tor->info.pieceSize, i, &stopCurrent ); 151 tr_free( buffer ); 150 152 tor->verifyState = TR_VERIFY_NONE; 151 153
Note: See TracChangeset
for help on using the changeset viewer.