Changeset 7116


Ignore:
Timestamp:
Nov 15, 2008, 9:20:19 PM (12 years ago)
Author:
charles
Message:

(libT) #1471: upload speed is not given enough weight when rechoking
M libtransmission/peer-mgr.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.4x/libtransmission/peer-mgr.c

    r7073 r7116  
    18431843    unsigned int    doUnchoke    : 1;
    18441844    unsigned int    isInterested : 1;
    1845     double          rateToClient;
    1846     double          rateToPeer;
     1845    unsigned int    isChoked     : 1;
     1846    int             rate;
    18471847    tr_peer *       peer;
    18481848};
    18491849
    18501850static int
    1851 tr_compareDouble( double a,
    1852                   double b )
    1853 {
    1854     if( a < b ) return -1;
    1855     if( a > b ) return 1;
    1856     return 0;
    1857 }
    1858 
    1859 static int
    18601851compareChoke( const void * va,
    18611852              const void * vb )
     
    18631854    const struct ChokeData * a = va;
    18641855    const struct ChokeData * b = vb;
    1865     int                      diff = 0;
    1866 
    1867     if( diff == 0 ) /* prefer higher dl speeds */
    1868         diff = -tr_compareDouble( a->rateToClient, b->rateToClient );
    1869     if( diff == 0 ) /* prefer higher ul speeds */
    1870         diff = -tr_compareDouble( a->rateToPeer, b->rateToPeer );
    1871     if( diff == 0 ) /* prefer unchoked */
    1872         diff = (int)a->peer->peerIsChoked - (int)b->peer->peerIsChoked;
    1873 
    1874     return diff;
     1856
     1857    if( a->rate != b->rate ) /* prefer higher overall speeds */
     1858        return a->rate > b->rate ? -1 : 1;
     1859
     1860    if( a->isChoked != b->isChoked ) /* prefer unchoked */
     1861        return a->isChoked ? 1 : -1;
     1862
     1863    return 0;
    18751864}
    18761865
     
    19131902            n->peer         = peer;
    19141903            n->isInterested = peer->peerIsInterested;
    1915             n->rateToPeer   = tr_peerGetPieceSpeed( peer, TR_CLIENT_TO_PEER );
    1916             n->rateToClient = tr_peerGetPieceSpeed( peer, TR_PEER_TO_CLIENT );
     1904            n->isChoked     = peer->peerIsChoked;
     1905            n->rate = (int)(tr_peerGetPieceSpeed( peer, TR_CLIENT_TO_PEER )
     1906                            + tr_peerGetPieceSpeed( peer, TR_PEER_TO_CLIENT ) );
    19171907        }
    19181908    }
Note: See TracChangeset for help on using the changeset viewer.