Changeset 3662


Ignore:
Timestamp:
Oct 31, 2007, 4:23:50 AM (14 years ago)
Author:
charles
Message:

"corruption" fix part 2: lots of assertions, and try to complete pieces & ban bad peers sooner

Location:
branches/0.9x/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/0.9x/libtransmission/completion.c

    r3178 r3662  
    138138tr_cpPieceIsComplete( const tr_completion * cp, int piece )
    139139{
    140     return cp->completeBlocks[piece] >= tr_torPieceCountBlocks(cp->tor,piece);
     140    assert( piece >= 0 );
     141    assert( piece < cp->tor->info.pieceCount );
     142    assert( cp->completeBlocks[piece] <= tr_torPieceCountBlocks(cp->tor,piece) );
     143
     144    return cp->completeBlocks[piece] == tr_torPieceCountBlocks(cp->tor,piece);
    141145}
    142146
  • branches/0.9x/libtransmission/inout.c

    r3649 r3662  
    208208
    209209static int
    210 tr_ioRecalculateHash ( tr_torrent    * tor,
    211                        int             pieceIndex,
    212                        uint8_t       * setme )
     210tr_ioRecalculateHash( tr_torrent    * tor,
     211                      int             pieceIndex,
     212                      uint8_t       * setme )
    213213{
    214214    int n;
     
    224224    n = tr_torPieceCountBytes( tor, pieceIndex );
    225225
    226     buf = malloc( n );
    227     ret = readOrWritePiece ( tor, TR_IO_READ, pieceIndex, 0, buf, n );
     226    buf = tr_new( uint8_t, n );
     227    ret = tr_ioRead( tor, pieceIndex, 0, n, buf );
    228228    if( !ret )
    229229        tr_sha1( setme, buf, n, NULL );
    230     free( buf );
    231 
    232     return ret;
    233 }
    234 
    235 static int
    236 checkPiece ( tr_torrent * tor, int pieceIndex )
     230    tr_free( buf );
     231
     232    return ret;
     233}
     234
     235static int
     236checkPiece( tr_torrent * tor, int pieceIndex )
    237237{
    238238    uint8_t hash[SHA_DIGEST_LENGTH];
  • branches/0.9x/libtransmission/peer-mgr.c

    r3618 r3662  
    545545{
    546546    tr_priority_t priority;
     547    int percentDone;
    547548    uint16_t random;
    548549    uint32_t piece;
     
    567568    if (a->priority != b->priority)
    568569        return a->priority > b->priority ? -1 : 1;
     570
     571    /* try to fill partial pieces */
     572    if( a->percentDone != b->percentDone )
     573        return a->percentDone > b->percentDone ? -1 : 1;
    569574   
    570575    /* otherwise if one has fewer peers, it goes first */
     
    626631            setme->fastAllowed = 0;
    627632            setme->random = tr_rand( UINT16_MAX );
     633            setme->percentDone = (int)( 100.0 * tr_cpPercentBlocksInPiece( tor->completion, piece ) );
    628634
    629635            for( k=0; k<peerCount; ++k ) {
     
    638644        }
    639645
    640         qsort (p, poolSize, sizeof(struct tr_refill_piece), compareRefillPiece);
     646        qsort( p, poolSize, sizeof(struct tr_refill_piece), compareRefillPiece );
    641647
    642648        for( j=0; j<poolSize; ++j )
  • branches/0.9x/libtransmission/peer-msgs.c

    r3614 r3662  
    938938
    939939        case BT_PIECE:
    940             return len > 9;
     940            return len>9 && len<=16393;
    941941
    942942        case BT_PORT:
     
    12111211        return;
    12121212    }
    1213     dbgmsg( msgs, "Got block %u:%u->%u (turnaround time %d secs)",
     1213    dbgmsg( msgs, "got block %u:%u->%u (turnaround time %d secs)",
    12141214                     req->index, req->offset, req->length,
    12151215                     (int)(time(NULL) - req->time_requested) );
     
    12421242    if( tr_ioWrite( tor, index, offset, length, EVBUFFER_DATA( inbuf )))
    12431243        return;
     1244
     1245#warning this sanity check is here to help track down the excess corrupt data bug, but is expensive and should be removed before the next release
     1246{
     1247    uint8_t * tmp = tr_new( uint8_t, length );
     1248    const int val = tr_ioRead( tor, index, offset, length, tmp );
     1249    assert( !val );
     1250    assert( !memcmp( tmp, EVBUFFER_DATA(inbuf), length ) );
     1251    tr_free( tmp );
     1252}
    12441253
    12451254    tr_cpBlockAdd( tor->completion, block );
  • branches/0.9x/libtransmission/utils.c

    r3649 r3662  
    788788    static const uint8_t ands[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };
    789789    bitfield->bits[nth>>3u] |= ands[nth&7u];
     790    assert( tr_bitfieldHas( bitfield, nth ) );
    790791}
    791792
     
    809810    if( bitfield != NULL )
    810811        bitfield->bits[nth>>3u] &= rems[nth&7u];
     812
     813    assert( !tr_bitfieldHas( bitfield, nth ) );
    811814}
    812815
Note: See TracChangeset for help on using the changeset viewer.