Changeset 3876


Ignore:
Timestamp:
Nov 18, 2007, 6:15:13 AM (15 years ago)
Author:
charles
Message:

fix choking bug that could penalize good peers.

File:
1 edited

Legend:

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

    r3871 r3876  
    14821482{
    14831483    tr_peer * peer;
    1484     double rate;
     1484    int rate;
    14851485    int preferred;
    14861486    int doUnchoke;
     
    14901490compareChoke( const void * va, const void * vb )
    14911491{
    1492     int i;
    14931492    const struct ChokeData * a = va;
    14941493    const struct ChokeData * b = vb;
    14951494
    1496     if(( i = (int)( 10 * ( a->rate - b->rate ))))
    1497         return i;
    1498 
     1495    /* primary key: larger speeds */
     1496    if( a->rate > b->rate )
     1497        return -1;
     1498    if ( a->rate < b->rate )
     1499        return 1;
     1500
     1501    /* secondary key: perferred peers */
    14991502    if( a->preferred != b->preferred )
    15001503        return a->preferred ? -1 : 1;
     
    15161519
    15171520static double
    1518 getWeightedThroughput( const tr_peer * peer )
    1519 {
    1520     /* FIXME: tweak this? */
    1521     return /* 1 * peer->rateToPeer )
    1522          +*/ ( 1 * peer->rateToClient );
     1521getWeightedThroughput( const tr_peer * peer, int clientIsSeed )
     1522{
     1523    return (int)( 10.0 * ( clientIsSeed ? peer->rateToPeer
     1524                                        : peer->rateToClient ) );
    15231525}
    15241526
     
    15261528rechoke( Torrent * t )
    15271529{
    1528     int i, peerCount, size=0;
     1530    int i, peerCount, size=0, unchoked=0;
    15291531    const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC;
    15301532    tr_peer ** peers = getConnectedPeers( t, &peerCount );
    15311533    struct ChokeData * choke = tr_new0( struct ChokeData, peerCount );
     1534    const int clientIsSeed = tr_torrentIsSeed( t->tor );
    15321535
    15331536    assert( torrentIsLocked( t ) );
     
    15381541        tr_peer * peer = peers[i];
    15391542        struct ChokeData * node;
    1540         if( peer->chokeChangedAt > fibrillationTime )
     1543        if( peer->chokeChangedAt > fibrillationTime ) {
     1544            if( !peer->peerIsChoked )
     1545                ++unchoked;
    15411546            continue;
     1547        }
    15421548
    15431549        node = &choke[size++];
    15441550        node->peer = peer;
    15451551        node->preferred = peer->peerIsInterested && !clientIsSnubbedBy(peer);
    1546         node->rate = getWeightedThroughput( peer );
     1552        node->rate = getWeightedThroughput( peer, clientIsSeed );
    15471553    }
    15481554
    15491555    qsort( choke, size, sizeof(struct ChokeData), compareChoke );
    15501556
    1551     for( i=0; i<size && i<NUM_UNCHOKED_PEERS_PER_TORRENT; ++i )
     1557    for( i=0; i<size && unchoked<NUM_UNCHOKED_PEERS_PER_TORRENT; ++i ) {
    15521558        choke[i].doUnchoke = 1;
     1559        ++unchoked;
     1560    }
    15531561
    15541562    for( ; i<size; ++i ) {
     1563        ++unchoked;
    15551564        choke[i].doUnchoke = 1;
    15561565        if( choke[i].peer->peerIsInterested )
Note: See TracChangeset for help on using the changeset viewer.