Changeset 5241
- Timestamp:
- Mar 13, 2008, 12:38:16 AM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/inout.c
r5081 r5241 13 13 #include <assert.h> 14 14 #include <errno.h> 15 #include <stdlib.h> /* realloc */ 15 16 #include <string.h> /* memcmp */ 16 17 … … 19 20 #include <unistd.h> 20 21 21 #include <openssl/sha.h>22 23 22 #include "transmission.h" 23 #include "crypto.h" 24 24 #include "fdlimit.h" 25 25 #include "inout.h" 26 #include "platform.h" 26 27 #include "stats.h" 27 28 #include "torrent.h" … … 221 222 uint8_t * setme ) 222 223 { 223 int offset; 224 int bytesLeft; 225 uint8_t buf[4096]; 224 static uint8_t * buf = NULL; 225 static int buflen = 0; 226 static tr_lock * lock = NULL; 227 228 int n; 229 tr_errno err; 226 230 const tr_info * info; 227 SHA_CTX sha; 231 232 /* only check one block at a time to prevent disk thrashing. 233 * this also lets us reuse the same buffer each time. */ 234 if( lock == NULL ) 235 lock = tr_lockNew( ); 236 237 tr_lockLock( lock ); 228 238 229 239 assert( tor != NULL ); … … 232 242 233 243 info = &tor->info; 234 offset = 0; 235 bytesLeft = tr_torPieceCountBytes( tor, pieceIndex ); 236 SHA1_Init( &sha ); 237 238 while( bytesLeft > 0 ) 239 { 240 const int bytesThisPass = MIN( bytesLeft, (int)sizeof(buf) ); 241 tr_errno err = tr_ioRead( tor, pieceIndex, offset, bytesThisPass, buf ); 242 if( err ) 243 return err; 244 SHA1_Update( &sha, buf, bytesThisPass ); 245 bytesLeft -= bytesThisPass; 246 offset += bytesThisPass; 244 n = tr_torPieceCountBytes( tor, pieceIndex ); 245 246 if( buflen < n ) { 247 buflen = n; 248 buf = tr_renew( uint8_t, buf, buflen ); 247 249 } 248 249 SHA1_Final( setme, &sha ); 250 251 err = tr_ioRead( tor, pieceIndex, 0, n, buf ); 252 if( !err ) 253 tr_sha1( setme, buf, n, NULL ); 254 255 tr_lockUnlock( lock ); 250 256 return 0; 251 257 } -
trunk/libtransmission/torrent.c
r5224 r5241 42 42 #include "verify.h" 43 43 44 #define MAX_BLOCK_SIZE (1024*16) 45 44 46 /*** 45 47 **** … … 290 292 */ 291 293 tor->blockSize = info->pieceSize; 292 while( tor->blockSize > (1024*16))294 while( tor->blockSize > MAX_BLOCK_SIZE ) 293 295 tor->blockSize /= 2; 294 296 … … 1296 1298 uint32_t length ) 1297 1299 { 1298 static const uint32_t MAX_REQUEST_BYTE_COUNT = (16 * 1024);1299 1300 int err = 0; 1300 1301 … … 1303 1304 else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) ) 1304 1305 err = 2; 1305 else if( length > MAX_ REQUEST_BYTE_COUNT)1306 else if( length > MAX_BLOCK_SIZE ) 1306 1307 err = 3; 1307 1308 else if( tr_pieceOffset( tor, index, offset, length ) > tor->info.totalSize )
Note: See TracChangeset
for help on using the changeset viewer.