1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

fix choking bug that could penalize good peers.

This commit is contained in:
Charles Kerr 2007-11-18 06:15:13 +00:00
parent 84b10c4312
commit ed72b1b795

View file

@ -1481,7 +1481,7 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
struct ChokeData struct ChokeData
{ {
tr_peer * peer; tr_peer * peer;
double rate; int rate;
int preferred; int preferred;
int doUnchoke; int doUnchoke;
}; };
@ -1489,13 +1489,16 @@ struct ChokeData
static int static int
compareChoke( const void * va, const void * vb ) compareChoke( const void * va, const void * vb )
{ {
int i;
const struct ChokeData * a = va; const struct ChokeData * a = va;
const struct ChokeData * b = vb; const struct ChokeData * b = vb;
if(( i = (int)( 10 * ( a->rate - b->rate )))) /* primary key: larger speeds */
return i; if( a->rate > b->rate )
return -1;
if ( a->rate < b->rate )
return 1;
/* secondary key: perferred peers */
if( a->preferred != b->preferred ) if( a->preferred != b->preferred )
return a->preferred ? -1 : 1; return a->preferred ? -1 : 1;
@ -1515,20 +1518,20 @@ clientIsSnubbedBy( const tr_peer * peer )
**/ **/
static double static double
getWeightedThroughput( const tr_peer * peer ) getWeightedThroughput( const tr_peer * peer, int clientIsSeed )
{ {
/* FIXME: tweak this? */ return (int)( 10.0 * ( clientIsSeed ? peer->rateToPeer
return /* 1 * peer->rateToPeer ) : peer->rateToClient ) );
+*/ ( 1 * peer->rateToClient );
} }
static void static void
rechoke( Torrent * t ) rechoke( Torrent * t )
{ {
int i, peerCount, size=0; int i, peerCount, size=0, unchoked=0;
const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC; const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC;
tr_peer ** peers = getConnectedPeers( t, &peerCount ); tr_peer ** peers = getConnectedPeers( t, &peerCount );
struct ChokeData * choke = tr_new0( struct ChokeData, peerCount ); struct ChokeData * choke = tr_new0( struct ChokeData, peerCount );
const int clientIsSeed = tr_torrentIsSeed( t->tor );
assert( torrentIsLocked( t ) ); assert( torrentIsLocked( t ) );
@ -1537,21 +1540,27 @@ rechoke( Torrent * t )
{ {
tr_peer * peer = peers[i]; tr_peer * peer = peers[i];
struct ChokeData * node; struct ChokeData * node;
if( peer->chokeChangedAt > fibrillationTime ) if( peer->chokeChangedAt > fibrillationTime ) {
if( !peer->peerIsChoked )
++unchoked;
continue; continue;
}
node = &choke[size++]; node = &choke[size++];
node->peer = peer; node->peer = peer;
node->preferred = peer->peerIsInterested && !clientIsSnubbedBy(peer); node->preferred = peer->peerIsInterested && !clientIsSnubbedBy(peer);
node->rate = getWeightedThroughput( peer ); node->rate = getWeightedThroughput( peer, clientIsSeed );
} }
qsort( choke, size, sizeof(struct ChokeData), compareChoke ); qsort( choke, size, sizeof(struct ChokeData), compareChoke );
for( i=0; i<size && i<NUM_UNCHOKED_PEERS_PER_TORRENT; ++i ) for( i=0; i<size && unchoked<NUM_UNCHOKED_PEERS_PER_TORRENT; ++i ) {
choke[i].doUnchoke = 1; choke[i].doUnchoke = 1;
++unchoked;
}
for( ; i<size; ++i ) { for( ; i<size; ++i ) {
++unchoked;
choke[i].doUnchoke = 1; choke[i].doUnchoke = 1;
if( choke[i].peer->peerIsInterested ) if( choke[i].peer->peerIsInterested )
break; break;