Changeset 60


Ignore:
Timestamp:
Jan 30, 2006, 1:58:27 AM (15 years ago)
Author:
titer
Message:

Rewrote rate control, background work for the download limit, the dl/ul
limits per torrent and for the choking algorithm

Location:
trunk/libtransmission
Files:
2 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/Jamfile

    r14 r60  
    33LIBTRANSMISSION_SRC =
    44    transmission.c bencode.c net.c tracker.c peer.c inout.c
    5     metainfo.c sha1.c utils.c upload.c fdlimit.c clients.c
    6     completion.c platform.c ;
     5    metainfo.c sha1.c utils.c fdlimit.c clients.c completion.c
     6    platform.c ratecontrol.c ;
    77
    88Library       libtransmission.a       : $(LIBTRANSMISSION_SRC) ;
  • trunk/libtransmission/internal.h

    r26 r60  
    9494#include "net.h"
    9595#include "inout.h"
    96 #include "upload.h"
     96#include "ratecontrol.h"
    9797#include "clients.h"
    9898
     
    101101    tr_info_t info;
    102102
    103     tr_upload_t     * upload;
    104     tr_fd_t         * fdlimit;
     103    tr_ratecontrol_t * globalUpload;
     104    tr_ratecontrol_t * globalDownload;
     105    tr_ratecontrol_t * upload;
     106    tr_ratecontrol_t * download;
     107    tr_fd_t          * fdlimit;
    105108
    106109    int               status;
     
    157160    tr_torrent_t * torrents[TR_MAX_TORRENT_COUNT];
    158161
    159     tr_upload_t  * upload;
     162    tr_ratecontrol_t * upload;
     163    tr_ratecontrol_t * download;
    160164    tr_fd_t      * fdlimit;
    161165
  • trunk/libtransmission/peer.c

    r26 r60  
    198198    if( !peer->amChoking )
    199199    {
    200         tr_uploadChoked( tor->upload );
     200        //tr_uploadChoked( tor->upload );
    201201    }
    202202    tr_peerDestroy( tor->fdlimit, peer );
     
    243243        if( NULL != tor )
    244244        {
     245            tr_rcTransferred( tor->download, ret );
     246            tr_rcTransferred( tor->globalDownload, ret );
    245247            if( parseBuf( tor, peer, ret ) )
    246248            {
     
    359361        while( ( p = blockPending( tor, peer, &size ) ) )
    360362        {
    361             if( !tr_uploadCanUpload( tor->upload ) )
     363            if( !tr_rcCanTransfer( tor->globalUpload ) )
    362364            {
    363365                break;
     
    375377
    376378            blockSent( peer, ret );
    377             tr_uploadUploaded( tor->upload, ret );
     379            tr_rcTransferred( tor->upload, ret );
     380            tr_rcTransferred( tor->globalUpload, ret );
    378381
    379382            tor->uploaded[9] += ret;
  • trunk/libtransmission/peerutils.h

    r26 r60  
    166166            /* He doesn't need us */
    167167            sendChoke( peer, 1 );
    168             tr_uploadChoked( tor->upload );
    169         }
    170         if( peer->amChoking && peer->peerInterested &&
    171             !peer->outSlow && tr_uploadCanUnchoke( tor->upload ) )
     168            //tr_uploadChoked( tor->upload );
     169        }
     170        if( peer->amChoking && peer->peerInterested /* &&
     171            !peer->outSlow && tr_uploadCanUnchoke( tor->upload ) */ )
    172172        {
    173173            sendChoke( peer, 0 );
    174             tr_uploadUnchoked( tor->upload );
     174            //tr_uploadUnchoked( tor->upload );
    175175        }
    176176    }
  • trunk/libtransmission/transmission.c

    r26 r60  
    2828static void torrentReallyStop( tr_handle_t * h, int t );
    2929static void  downloadLoop( void * );
    30 static float rateDownload( tr_torrent_t * );
    31 static float rateUpload( tr_torrent_t * );
    3230static void  acceptLoop( void * );
    3331static void acceptStop( tr_handle_t * h );
     
    6664
    6765    /* Initialize rate and file descripts controls */
    68     h->upload  = tr_uploadInit();
    69     h->fdlimit = tr_fdInit();
     66    h->upload   = tr_rcInit();
     67    h->download = tr_rcInit();
     68    h->fdlimit  = tr_fdInit();
    7069
    7170    h->bindPort = TR_DEFAULT_PORT;
     
    146145void tr_setUploadLimit( tr_handle_t * h, int limit )
    147146{
    148     tr_uploadSetLimit( h->upload, limit );
     147    tr_rcSetLimit( h->upload, limit );
    149148}
    150149
     
    156155void tr_torrentRates( tr_handle_t * h, float * dl, float * ul )
    157156{
    158     int            i;
    159     tr_torrent_t * tor;
    160 
    161     *dl = 0.0;
    162     *ul = 0.0;
    163 
    164     for( i = 0; i < h->torrentCount; i++ )
    165     {
    166         tor = h->torrents[i];
    167         tr_lockLock( &tor->lock );
    168         *dl += rateDownload( tor );
    169         *ul += rateUpload( tor );
    170         tr_lockUnlock( &tor->lock );
    171     }
     157    *dl = tr_rcRate( h->download );
     158    *ul = tr_rcRate( h->upload );
    172159}
    173160
     
    249236    tr_lockInit( &tor->lock );
    250237
    251     tor->upload  = h->upload;
    252     tor->fdlimit = h->fdlimit;
     238    tor->globalUpload   = h->upload;
     239    tor->globalDownload = h->download;
     240    tor->fdlimit        = h->fdlimit;
     241    tor->upload         = tr_rcInit();
     242    tor->download       = tr_rcInit();
    253243 
    254244    /* We have a new torrent */
     
    420410
    421411        s[i].progress     = tr_cpCompletionAsFloat( tor->completion );
    422         s[i].rateDownload = rateDownload( tor );
    423         s[i].rateUpload   = rateUpload( tor );
     412        s[i].rateDownload = tr_rcRate( tor->download );
     413        s[i].rateUpload   = tr_rcRate( tor->upload );
    424414       
    425415        s[i].seeders      = tr_trackerSeeders(tor);
     
    497487    tr_cpClose( tor->completion );
    498488
     489    tr_rcClose( tor->upload );
     490    tr_rcClose( tor->download );
     491
    499492    if( tor->destination )
    500493    {
     
    515508    acceptStop( h );
    516509    tr_fdClose( h->fdlimit );
    517     tr_uploadClose( h->upload );
     510    tr_rcClose( h->upload );
    518511    free( h );
    519512}
     
    584577
    585578    tr_dbg( "Thread exited" );
    586 }
    587 
    588 /***********************************************************************
    589  * rateDownload, rateUpload
    590  **********************************************************************/
    591 static float rateGeneric( uint64_t * dates, uint64_t * counts )
    592 {
    593     float ret;
    594     int i;
    595 
    596     ret = 0.0;
    597     for( i = 0; i < 9; i++ )
    598     {
    599         if( dates[i+1] == dates[i] )
    600         {
    601             continue;
    602         }
    603         ret += (float) ( i + 1 ) * 1000.0 / 1024.0 *
    604             (float) ( counts[i+1] - counts[i] ) /
    605             (float) ( dates[i+1] - dates[i] );
    606     }
    607     ret *= 1000.0 / 1024.0 / 45.0;
    608 
    609     return ret;
    610 }
    611 static float rateDownload( tr_torrent_t * tor )
    612 {
    613     return rateGeneric( tor->dates, tor->downloaded );
    614 }
    615 static float rateUpload( tr_torrent_t * tor )
    616 {
    617     return rateGeneric( tor->dates, tor->uploaded );
    618579}
    619580
Note: See TracChangeset for help on using the changeset viewer.