Changeset 3614


Ignore:
Timestamp:
Oct 28, 2007, 3:20:23 PM (15 years ago)
Author:
charles
Message:

#412 - 0.90 "ignores" speed limits (deanr, berkut, SineOtter?)

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

Legend:

Unmodified
Added
Removed
  • branches/0.9x/libtransmission/peer-msgs.c

    r3605 r3614  
    7171    KEEPALIVE_INTERVAL_SECS = 90,          /* idle seconds before we send a keepalive */
    7272    PEX_INTERVAL            = (60 * 1000), /* msec between calls to sendPex() */
    73     PEER_PULSE_INTERVAL     = (133),        /* msec between calls to pulse() */
     73    PEER_PULSE_INTERVAL     = (100),       /* msec between calls to pulse() */
    7474    RATE_PULSE_INTERVAL     = (333),       /* msec between calls to ratePulse() */
    7575};
     
    111111    tr_publisher_t * publisher;
    112112
     113    struct evbuffer * outBlock;    /* buffer of all the current piece message */
    113114    struct evbuffer * outMessages; /* buffer of all the non-piece messages */
    114115    struct evbuffer * inBlock;     /* the block we're currently receiving */
     
    233234    tr_peerIoWriteUint32( io, out, sizeof(uint8_t) );
    234235    tr_peerIoWriteUint8 ( io, out, choke ? BT_CHOKE : BT_UNCHOKE );
    235 }
    236 
    237 static void
    238 protocolSendPiece( tr_peermsgs                * msgs,
    239                    const struct peer_request  * r,
    240                    const uint8_t              * pieceData )
    241 {
    242     tr_peerIo * io = msgs->io;
    243     struct evbuffer * out = evbuffer_new( );
    244 
    245     dbgmsg( msgs, "sending block %u:%u->%u", r->index, r->offset, r->length );
    246     tr_peerIoWriteUint32( io, out, sizeof(uint8_t) + 2*sizeof(uint32_t) + r->length );
    247     tr_peerIoWriteUint8 ( io, out, BT_PIECE );
    248     tr_peerIoWriteUint32( io, out, r->index );
    249     tr_peerIoWriteUint32( io, out, r->offset );
    250     tr_peerIoWriteBytes ( io, out, pieceData, r->length );
    251     tr_peerIoWriteBuf   ( io, out );
    252 
    253     evbuffer_free( out );
    254236}
    255237
     
    13641346{
    13651347    /* don't let our outbuffer get too large */
    1366     if( tr_peerIoWriteBytesWaiting( msgs->io ) > 8192 )
     1348    if( tr_peerIoWriteBytesWaiting( msgs->io ) > 4096 )
    13671349        return FALSE;
    13681350
     
    13701352}
    13711353
    1372 static int
    1373 canUpload( const tr_peermsgs * msgs )
    1374 {
     1354static size_t
     1355getUploadMax( const tr_peermsgs * msgs )
     1356{
     1357    static const size_t maxval = ~0;
    13751358    const tr_torrent * tor = msgs->torrent;
    13761359
    13771360    if( !canWrite( msgs ) )
    1378         return FALSE;
     1361        return 0;
    13791362
    13801363    if( tor->uploadLimitMode == TR_SPEEDLIMIT_GLOBAL )
    1381         return !tor->handle->useUploadLimit || tr_rcCanTransfer( tor->handle->upload );
     1364        return tor->handle->useUploadLimit ? tr_rcBytesLeft( tor->handle->upload ) : maxval;
    13821365
    13831366    if( tor->uploadLimitMode == TR_SPEEDLIMIT_SINGLE )
    1384         return tr_rcCanTransfer( tor->upload );
    1385 
    1386     return TRUE;
     1367        return tr_rcBytesLeft( tor->upload );
     1368
     1369    return maxval;
    13871370}
    13881371
     
    13981381}
    13991382
     1383static struct peer_request*
     1384popNextRequest( tr_peermsgs * msgs )
     1385{
     1386    struct peer_request * ret;
     1387    ret = tr_list_pop_front( &msgs->peerAskedForFast );
     1388    if( !ret )
     1389        ret = tr_list_pop_front( &msgs->peerAskedFor);
     1390    return ret;
     1391}
     1392
    14001393static int
    14011394pulse( void * vmsgs )
    14021395{
    14031396    const time_t now = time( NULL );
    1404     tr_peermsgs * msgs = (tr_peermsgs *) vmsgs;
     1397    tr_peermsgs * msgs = vmsgs;
     1398    struct peer_request * r;
    14051399    size_t len;
    14061400
     
    14181412    {
    14191413    }
     1414    else if(( len = EVBUFFER_LENGTH( msgs->outBlock ) ))
     1415    {
     1416        const size_t uploadMax = getUploadMax( msgs );
     1417        const size_t outlen = MIN( len, uploadMax );
     1418        tr_peerIoWrite( msgs->io, EVBUFFER_DATA( msgs->outBlock ), outlen );
     1419        evbuffer_drain( msgs->outBlock, outlen );
     1420        msgs->clientSentAnythingAt = now;
     1421        peerGotBytes( msgs, outlen );
     1422        len -= outlen;
     1423        dbgmsg( msgs, "wrote %d bytes; %d left in block", (int)outlen, (int)len );
     1424        fflush( stdout );
     1425    }
    14201426    else if(( len = EVBUFFER_LENGTH( msgs->outMessages ) ))
    14211427    {
     
    14231429        msgs->clientSentAnythingAt = now;
    14241430    }
    1425     else if( msgs->peerAskedForFast || msgs->peerAskedFor )
    1426     {
    1427         if( canUpload( msgs ) )
     1431    else if( ( now - msgs->clientSentAnythingAt ) > KEEPALIVE_INTERVAL_SECS )
     1432    {
     1433        sendKeepalive( msgs );
     1434    }
     1435
     1436    if( !EVBUFFER_LENGTH( msgs->outBlock )
     1437        && (( r = popNextRequest( msgs )))
     1438        && requestIsValid( msgs, r )
     1439        && tr_cpPieceIsComplete( msgs->torrent->completion, r->index ) )
     1440    {
     1441        uint8_t * buf = tr_new( uint8_t, r->length );
     1442
     1443        if( !tr_ioRead( msgs->torrent, r->index, r->offset, r->length, buf ) )
    14281444        {
    1429             struct peer_request * r;
    1430             uint8_t * buf;
    1431 
    1432             r = tr_list_pop_front( &msgs->peerAskedForFast );
    1433             if( r == NULL )
    1434                 r = tr_list_pop_front( &msgs->peerAskedFor);
    1435 
    1436             buf = tr_new( uint8_t, r->length );
    1437 
    1438             if( requestIsValid( msgs, r )
    1439                 && tr_cpPieceIsComplete( msgs->torrent->completion, r->index )
    1440                 && !tr_ioRead( msgs->torrent, r->index, r->offset, r->length, buf ) )
    1441             {
    1442                 protocolSendPiece( msgs, r, buf );
    1443                 peerGotBytes( msgs, r->length );
    1444                 msgs->clientSentAnythingAt = now;
    1445             }
    1446 
    1447             tr_free( buf );
    1448             tr_free( r );
     1445            tr_peerIo * io = msgs->io;
     1446            struct evbuffer * out = msgs->outBlock;
     1447
     1448            dbgmsg( msgs, "sending block %u:%u->%u", r->index, r->offset, r->length );
     1449            tr_peerIoWriteUint32( io, out, sizeof(uint8_t) + 2*sizeof(uint32_t) + r->length );
     1450            tr_peerIoWriteUint8 ( io, out, BT_PIECE );
     1451            tr_peerIoWriteUint32( io, out, r->index );
     1452            tr_peerIoWriteUint32( io, out, r->offset );
     1453            tr_peerIoWriteBytes ( io, out, buf, r->length );
    14491454        }
    1450     }
    1451     else if( ( now - msgs->clientSentAnythingAt ) > KEEPALIVE_INTERVAL_SECS )
    1452     {
    1453         sendKeepalive( msgs );
     1455
     1456        tr_free( buf );
     1457        tr_free( r );
     1458
     1459        pulse( msgs ); /* start sending it right away */
    14541460    }
    14551461
     
    16611667    m->pexTimer = tr_timerNew( m->handle, pexPulse, m, PEX_INTERVAL );
    16621668    m->outMessages = evbuffer_new( );
     1669    m->outBlock = evbuffer_new( );
    16631670    m->inBlock = evbuffer_new( );
    16641671    m->peerAllowedPieces = NULL;
     
    17251732        tr_list_free( &msgs->peerAskedFor, tr_free );
    17261733        evbuffer_free( msgs->outMessages );
     1734        evbuffer_free( msgs->outBlock );
    17271735        evbuffer_free( msgs->inBlock );
    17281736        tr_free( msgs->pex );
  • branches/0.9x/libtransmission/ratecontrol.c

    r3105 r3614  
    113113}
    114114
     115size_t
     116tr_rcBytesLeft( const tr_ratecontrol * r )
     117{
     118    size_t bytes = 0;
     119
     120    if( r != NULL )
     121    {
     122        float cur, max;
     123        size_t kb;
     124 
     125        tr_lockLock( (tr_lock*)r->lock );
     126
     127        cur = rateForInterval( r, SHORT_INTERVAL_MSEC );
     128        max = r->limit;
     129        kb = max>cur ? max-cur : 0;
     130        bytes = kb * 1024u;
     131
     132        tr_lockUnlock( (tr_lock*)r->lock );
     133    }
     134
     135    return bytes;
     136}
     137
    115138float
    116139tr_rcRate( const tr_ratecontrol * r )
  • branches/0.9x/libtransmission/ratecontrol.h

    r3105 r3614  
    3232int              tr_rcGetLimit( const tr_ratecontrol * );
    3333int              tr_rcCanTransfer( const tr_ratecontrol * );
     34size_t           tr_rcBytesLeft( const tr_ratecontrol * );
    3435void             tr_rcTransferred( tr_ratecontrol *, size_t byteCount );
    3536float            tr_rcRate( const tr_ratecontrol * );
Note: See TracChangeset for help on using the changeset viewer.