diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index e0527de7a..617bbb144 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1438,8 +1438,7 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager, struct ChokeData { tr_peer * peer; - float rate; - int randomKey; + double rate; int preferred; int doUnchoke; }; @@ -1447,22 +1446,17 @@ struct ChokeData static int compareChoke( const void * va, const void * vb ) { + int i; const struct ChokeData * a = va; const struct ChokeData * b = vb; + if(( i = (int)( 10 * ( a->rate - b->rate )))) + return i; + if( a->preferred != b->preferred ) return a->preferred ? -1 : 1; - if( a->preferred ) - { - if( a->rate > b->rate ) return -1; - if( a->rate < b->rate ) return 1; - return 0; - } - else - { - return a->randomKey - b->randomKey; - } + return 0; } static int @@ -1480,7 +1474,7 @@ clientIsSnubbedBy( const tr_peer * peer ) static double getWeightedThroughput( const tr_peer * peer ) { - /* FIXME: tweak this */ + /* FIXME: tweak this? */ return ( 1 * peer->rateToPeer ) + ( 1 * peer->rateToClient ); } @@ -1506,7 +1500,6 @@ rechoke( Torrent * t ) node = &choke[size++]; node->peer = peer; node->preferred = peer->peerIsInterested && !clientIsSnubbedBy(peer); - node->randomKey = tr_rand( INT_MAX ); node->rate = getWeightedThroughput( peer ); } diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 40150bf48..9f18f0f47 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -569,6 +569,9 @@ pumpRequestQueue( tr_peermsgs * msgs ) fireNeedReq( msgs ); } +static int +pulse( void * vmsgs ); + int tr_peerMsgsAddRequest( tr_peermsgs * msgs, uint32_t index, @@ -623,6 +626,7 @@ tr_peerMsgsAddRequest( tr_peermsgs * msgs, req = tr_new0( struct peer_request, 1 ); *req = tmp; tr_list_append( &msgs->clientWillAskFor, req ); + pulse( msgs ); return TR_ADDREQ_OK; }