Changeset 3169


Ignore:
Timestamp:
Sep 25, 2007, 10:30:41 PM (15 years ago)
Author:
charles
Message:

fix peer-msgs.c assertion failure. (tbo)

Location:
trunk/libtransmission
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Makefile.am

    r3105 r3169  
    4545noinst_HEADERS = \
    4646    bencode.h \
    47     bsdqueue.h \
    4847    bsdtree.h \
    4948    clients.h \
  • trunk/libtransmission/peer-mgr.c

    r3163 r3169  
    12371237        }
    12381238    }
    1239  
     1239
     1240#if 0
    12401241    /* maybe connect to some new peers */
    12411242    if( t->isRunning && (liveCount<MAX_CONNECTED_PEERS_PER_TORRENT) )
     
    12821283        tr_free( pool );
    12831284    }
     1285#endif
    12841286
    12851287    return TRUE;
  • trunk/libtransmission/peer-msgs.c

    r3165 r3169  
    381381pulse( void * vmsgs );
    382382
     383static int
     384reqIsValid( const tr_peermsgs * msgs, uint32_t index, uint32_t offset, uint32_t length )
     385{
     386    const tr_torrent * tor = msgs->torrent;
     387
     388    if( index >= (uint32_t) tor->info.pieceCount )
     389        return FALSE;
     390    if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )
     391        return FALSE;
     392    if( length > MAX_REQUEST_BYTE_COUNT )
     393        return FALSE;
     394    if( tr_pieceOffset( tor, index, offset, length ) > tor->info.totalSize )
     395        return FALSE;
     396
     397    return TRUE;
     398}
     399
     400static int
     401requestIsValid( const tr_peermsgs * msgs, struct peer_request * req )
     402{
     403    return reqIsValid( msgs, req->index, req->offset, req->length );
     404}
     405
    383406int
    384407tr_peerMsgsAddRequest( tr_peermsgs * msgs,
     
    394417    assert( msgs != NULL );
    395418    assert( msgs->torrent != NULL );
    396     assert( index < ((uint32_t)msgs->torrent->info.pieceCount) );
    397     assert( offset < (uint32_t)tr_torPieceCountBytes( msgs->torrent, (int)index ) );
    398     assert( (offset + length) <= (uint32_t)tr_torPieceCountBytes( msgs->torrent, (int)index ) );
     419    assert( reqIsValid( msgs, index, offset, length ) );
    399420
    400421    if( msgs->info->clientIsChoked )
     
    608629        msgs->state = AWAITING_BT_MESSAGE;
    609630    } return READ_AGAIN;
    610 }
    611 
    612 static int
    613 requestIsValid( const tr_peermsgs * msgs, struct peer_request * req )
    614 {
    615     const tr_torrent * tor = msgs->torrent;
    616     assert( req != NULL );
    617 
    618     if( req->index >= (uint32_t) tor->info.pieceCount )
    619         return FALSE;
    620     if ( (int)req->offset >= tr_torPieceCountBytes( tor, (int)req->index ) )
    621         return FALSE;
    622     if( req->length > MAX_REQUEST_BYTE_COUNT )
    623         return FALSE;
    624     if( tr_pieceOffset( tor, req->index, req->offset, req->length ) > tor->info.totalSize )
    625         return FALSE;
    626 
    627     return TRUE;
    628631}
    629632
     
    727730            dbgmsg( msgs, "peer sent us a BT_PIECE" );
    728731            assert( msgs->blockToUs.length == 0 );
    729             msgs->state = READING_BT_PIECE;
    730732            tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.index );
    731733            tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.offset );
    732734            msgs->blockToUs.length = msglen - 8;
    733             assert( msgs->blockToUs.length > 0 );
    734735            assert( EVBUFFER_LENGTH(msgs->inBlock) == 0 );
    735736            //evbuffer_drain( msgs->inBlock, ~0 );
     737            msgs->state = msgs->blockToUs.length ? READING_BT_PIECE : AWAITING_BT_LENGTH;
    736738            return READ_AGAIN;
    737739            break;
     
    10111013{
    10121014    /* don't let our outbuffer get too large */
    1013     if( tr_peerIoWriteBytesWaiting( msgs->io ) > 1024 )
     1015    if( tr_peerIoWriteBytesWaiting( msgs->io ) > 2048 )
    10141016        return FALSE;
    10151017
     
    10561058        while ( len && canUpload( msgs ) )
    10571059        {
    1058             const size_t outlen = MIN( len, 1024 );
     1060            const size_t outlen = MIN( len, 2048 );
    10591061            tr_peerIoWrite( msgs->io, EVBUFFER_DATA(msgs->outBlock), outlen );
    10601062            evbuffer_drain( msgs->outBlock, outlen );
Note: See TracChangeset for help on using the changeset viewer.