Changeset 5241


Ignore:
Timestamp:
Mar 13, 2008, 12:38:16 AM (14 years ago)
Author:
charles
Message:

#781: experimental commit on the "failed data" issue.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/inout.c

    r5081 r5241  
    1313#include <assert.h>
    1414#include <errno.h>
     15#include <stdlib.h> /* realloc */
    1516#include <string.h> /* memcmp */
    1617
     
    1920#include <unistd.h>
    2021
    21 #include <openssl/sha.h>
    22 
    2322#include "transmission.h"
     23#include "crypto.h"
    2424#include "fdlimit.h"
    2525#include "inout.h"
     26#include "platform.h"
    2627#include "stats.h"
    2728#include "torrent.h"
     
    221222                      uint8_t           * setme )
    222223{
    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;
    226230    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 );
    228238
    229239    assert( tor != NULL );
     
    232242
    233243    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 );
    247249    }
    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 );
    250256    return 0;
    251257}
  • trunk/libtransmission/torrent.c

    r5224 r5241  
    4242#include "verify.h"
    4343
     44#define MAX_BLOCK_SIZE (1024*16)
     45
    4446/***
    4547****
     
    290292     */
    291293    tor->blockSize = info->pieceSize;
    292     while( tor->blockSize > (1024*16) )
     294    while( tor->blockSize > MAX_BLOCK_SIZE )
    293295        tor->blockSize /= 2;
    294296
     
    12961298                      uint32_t           length )
    12971299{
    1298     static const uint32_t MAX_REQUEST_BYTE_COUNT  = (16 * 1024);
    12991300    int err = 0;
    13001301
     
    13031304    else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )
    13041305        err = 2;
    1305     else if( length > MAX_REQUEST_BYTE_COUNT )
     1306    else if( length > MAX_BLOCK_SIZE )
    13061307        err = 3;
    13071308    else if( tr_pieceOffset( tor, index, offset, length ) > tor->info.totalSize )
Note: See TracChangeset for help on using the changeset viewer.