Changeset 3842


Ignore:
Timestamp:
Nov 16, 2007, 9:58:11 PM (15 years ago)
Author:
charles
Message:

progress on the "speed limits kill my transfer rate" bug.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-io.c

    r3841 r3842  
    3030#define IO_TIMEOUT_SECS 8
    3131
    32 #define TR_RDBUF 2048
     32/* arbitrary. */
     33#define TR_RDBUF (1024*6)
    3334
    3435/**
  • trunk/libtransmission/peer-msgs.c

    r3839 r3842  
    141141    time_t clientSentAnythingAt;
    142142
    143     unsigned int notListening             : 1;
    144143    unsigned int peerSupportsPex          : 1;
    145144    unsigned int clientSentLtepHandshake  : 1;
     
    875874
    876875static int
    877 readBtLength( tr_peermsgs * msgs, struct evbuffer * inbuf )
     876readBtLength( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
    878877{
    879878    uint32_t len;
    880879
    881     if( EVBUFFER_LENGTH(inbuf) < sizeof(len) )
     880    if( inlen < sizeof(len) )
    882881        return READ_MORE;
    883882
     
    896895
    897896static int
    898 readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf );
     897readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen );
    899898
    900899static int
    901 readBtId( tr_peermsgs * msgs, struct evbuffer * inbuf )
     900readBtId( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
    902901{
    903902    uint8_t id;
    904903
    905     if( EVBUFFER_LENGTH(inbuf) < sizeof(uint8_t) )
     904    if( inlen < sizeof(uint8_t) )
    906905        return READ_MORE;
    907906
     
    919918        return READ_AGAIN;
    920919    }
    921     else return readBtMessage( msgs, inbuf );
     920    else return readBtMessage( msgs, inbuf, inlen-1 );
    922921}
    923922
     
    10301029
    10311030static int
    1032 readBtPiece( tr_peermsgs * msgs, struct evbuffer * inbuf )
     1031readBtPiece( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
    10331032{
    10341033    struct peer_request * req = &msgs->incoming.blockReq;
     
    10371036    if( !req->length )
    10381037    {
    1039         if( EVBUFFER_LENGTH( inbuf ) < 8 )
     1038        if( inlen < 8 )
    10401039            return READ_MORE;
    10411040
     
    10521051        /* read in another chunk of data */
    10531052        const size_t nLeft = req->length - EVBUFFER_LENGTH(msgs->incoming.block);
    1054         size_t n = MIN( nLeft, EVBUFFER_LENGTH(inbuf) );
     1053        size_t n = MIN( nLeft, inlen );
    10551054        uint8_t * buf = tr_new( uint8_t, n );
    10561055        tr_peerIoReadBytes( msgs->io, inbuf, buf, n );
     
    10801079
    10811080static int
    1082 readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf )
     1081readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen )
    10831082{
    10841083    uint32_t ui32;
     
    10911090    --msglen; // id length
    10921091
    1093     if( EVBUFFER_LENGTH(inbuf) < msglen ) {
     1092    if( inlen < msglen ) {
    10941093        dbgmsg( msgs, " too short!!! " );
    10951094        return READ_MORE;
    10961095    }
    10971096
    1098     dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, (int)msglen, (int)EVBUFFER_LENGTH(inbuf) );
     1097    dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, (int)msglen, (int)inlen );
    10991098
    11001099    if( !messageLengthIsCorrect( msgs, id, msglen+1 ) )
     
    12651264}
    12661265
    1267 static int
    1268 canDownload( const tr_peermsgs * msgs )
    1269 {
    1270     tr_torrent * tor = msgs->torrent;
     1266static size_t
     1267getDownloadMax( const tr_peermsgs * msgs )
     1268{
     1269    static const size_t maxval = ~0;
     1270    const tr_torrent * tor = msgs->torrent;
    12711271
    12721272    if( tor->downloadLimitMode == TR_SPEEDLIMIT_GLOBAL )
    1273         return !tor->handle->useDownloadLimit || tr_rcCanTransfer( tor->handle->download );
     1273        return tor->handle->useDownloadLimit
     1274            ? tr_rcBytesLeft( tor->handle->download ) : maxval;
    12741275
    12751276    if( tor->downloadLimitMode == TR_SPEEDLIMIT_SINGLE )
    1276         return tr_rcCanTransfer( tor->download );
    1277 
    1278     return TRUE;
     1277        return tr_rcBytesLeft( tor->download );
     1278
     1279    return maxval;
    12791280}
    12801281
     
    14071408    tr_peermsgs * msgs = (tr_peermsgs *) vmsgs;
    14081409    struct evbuffer * inbuf = EVBUFFER_INPUT ( evin );
    1409 
    1410 dbgmsg( msgs, "canRead, state is %d", msgs->state );
    1411     if( !canDownload( msgs ) )
    1412     {
    1413 dbgmsg( msgs, "oh, but canDownload failed" );
    1414         msgs->notListening = 1;
     1410    const size_t buflen = EVBUFFER_LENGTH( inbuf );
     1411    const size_t inlen = MIN( buflen, getDownloadMax( msgs ) );
     1412
     1413    if( !inlen )
     1414    {
    14151415        ret = READ_DONE;
    14161416    }
    14171417    else switch( msgs->state )
    14181418    {
    1419         case AWAITING_BT_LENGTH:  ret = readBtLength  ( msgs, inbuf ); break;
    1420         case AWAITING_BT_ID:      ret = readBtId      ( msgs, inbuf ); break;
    1421         case AWAITING_BT_MESSAGE: ret = readBtMessage ( msgs, inbuf ); break;
    1422         case AWAITING_BT_PIECE:   ret = readBtPiece   ( msgs, inbuf ); break;
     1419        case AWAITING_BT_LENGTH:  ret = readBtLength ( msgs, inbuf, inlen ); break;
     1420        case AWAITING_BT_ID:      ret = readBtId     ( msgs, inbuf, inlen ); break;
     1421        case AWAITING_BT_MESSAGE: ret = readBtMessage( msgs, inbuf, inlen ); break;
     1422        case AWAITING_BT_PIECE:   ret = readBtPiece  ( msgs, inbuf, inlen ); break;
    14231423        default: assert( 0 );
    14241424    }
     
    14961496    size_t len;
    14971497
    1498     /* if we froze out a downloaded block because of speed limits,
    1499        start listening to the peer again */
    1500     if( msgs->notListening && canDownload( msgs ) )
    1501     {
    1502         msgs->notListening = 0;
    1503         tr_peerIoTryRead( msgs->io );
    1504     }
     1498    tr_peerIoTryRead( msgs->io );
    15051499
    15061500    pumpRequestQueue( msgs );
     
    15581552
    15591553    return TRUE; /* loop forever */
    1560 }
    1561 
    1562 static void
    1563 didWrite( struct bufferevent * evin UNUSED, void * vmsgs )
    1564 {
    1565     pulse( vmsgs );
    15661554}
    15671555
     
    17901778   
    17911779    tr_peerIoSetTimeoutSecs( m->io, 150 ); /* timeout after N seconds of inactivity */
    1792     tr_peerIoSetIOFuncs( m->io, canRead, didWrite, gotError, m );
     1780    tr_peerIoSetIOFuncs( m->io, canRead, NULL, gotError, m );
    17931781    ratePulse( m );
    17941782
  • trunk/libtransmission/ratecontrol.c

    r3815 r3842  
    3131
    3232#define GRANULARITY_MSEC 250
    33 #define SHORT_INTERVAL_MSEC 3000
    34 #define LONG_INTERVAL_MSEC 20000
     33#define SHORT_INTERVAL_MSEC 2000
     34#define LONG_INTERVAL_MSEC 10000
    3535#define HISTORY_SIZE (LONG_INTERVAL_MSEC / GRANULARITY_MSEC)
    3636
Note: See TracChangeset for help on using the changeset viewer.