Changeset 90


Ignore:
Timestamp:
Feb 5, 2006, 9:10:20 PM (15 years ago)
Author:
titer
Message:

Comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/choking.c

    r76 r90  
    4949        c->slots = 4242;
    5050    else
     51        /* Reckon a number of slots from the upload limit. There is no
     52           official right way to do this, the formula above e.g. gives:
     53            10  KB/s -> 4  * 2.50 KB/s
     54            20  KB/s -> 6  * 3.33 KB/s
     55            50  KB/s -> 10 * 5.00 KB/s
     56            100 KB/s -> 14 * 7.14 KB/s */
    5157        c->slots = lrintf( sqrt( 2 * limit ) );
    5258    tr_lockUnlock( &c->lock );
     
    97103    unchokedCount        = 0;
    98104
    99     /* Build two lists of interested peers: those who may choke,
    100        those who may unchoke */
    101105    for( i = 0; i < c->h->torrentCount; i++ )
    102106    {
     
    109113                continue;
    110114
     115            /* Choke peers who have lost their interest in us */
    111116            if( !tr_peerIsInterested( peer ) )
    112117            {
     
    116121            }
    117122
     123            /* Build two lists of interested peers: those we may choke,
     124               those we may unchoke. Whatever happens, we never choke a
     125               peer less than 10 seconds after the time we unchoked him
     126               (or the other way around). */
    118127            if( tr_peerIsUnchoked( peer ) )
    119128            {
     
    130139    }
    131140
     141    /* Sort peers by the rate we are downloading from them. */
    132142    sortPeers( peersCanChoke, peersCanChokeCount );
    133143    sortPeers( peersCanUnchoke, peersCanUnchokeCount );
     
    135145    if( unchokedCount > c->slots && peersCanChokeCount > 0 )
    136146    {
     147        /* We have more open slots than what we should have (the user
     148           has just lower his upload limit. We need to choke some of the
     149           peers we are uploading to. */
    137150        int willChoke;
    138151        willChoke = MIN( peersCanChokeCount, unchokedCount - c->slots );
     
    145158    else if( unchokedCount < c->slots && peersCanUnchokeCount > 0 )
    146159    {
     160        /* We have unused open slots. Let's unchoke some people. */
    147161        int willUnchoke;
    148162        willUnchoke = MIN( peersCanUnchokeCount, c->slots - unchokedCount );
     
    154168    while( peersCanChokeCount > 0 && peersCanUnchokeCount > 0 )
    155169    {
     170        /* All slots are used and more peers are waiting. If
     171           applicable, choke some peers in favor of others who are
     172           uploading more to us. */
    156173        if( tr_peerDownloadRate( peersCanUnchoke[peersCanUnchokeCount - 1] )
    157174                < tr_peerDownloadRate( peersCanChoke[0] ) )
Note: See TracChangeset for help on using the changeset viewer.