(trunk libT) #3329 "connection problems when downloading" -- randomize the peer arrays so that all untested peers will have an equal chance of being used. Suggested by Longinus00
This commit is contained in:
parent
e6cf296a68
commit
610c912c5a
|
@ -2498,8 +2498,14 @@ rechokeDownloads( Torrent * t )
|
||||||
/* separate the peers into "good" (ones with a low cancel-to-block ratio),
|
/* separate the peers into "good" (ones with a low cancel-to-block ratio),
|
||||||
* untested peers, and "bad" (ones with a high cancel-to-block ratio).
|
* untested peers, and "bad" (ones with a high cancel-to-block ratio).
|
||||||
* That's the order in which we'll choose who to show interest in */
|
* That's the order in which we'll choose who to show interest in */
|
||||||
for( i=0; i<peerCount; ++i )
|
|
||||||
{
|
{
|
||||||
|
/* Randomize the peer array so the peers in the three groups will be unsorted... */
|
||||||
|
int n = peerCount;
|
||||||
|
tr_peer ** peers = tr_memdup( tr_ptrArrayBase( &t->peers ), n * sizeof( tr_peer * ) );
|
||||||
|
|
||||||
|
while( n > 0 )
|
||||||
|
{
|
||||||
|
const int i = tr_cryptoWeakRandInt( n );
|
||||||
tr_peer * peer = tr_ptrArrayNth( &t->peers, i );
|
tr_peer * peer = tr_ptrArrayNth( &t->peers, i );
|
||||||
|
|
||||||
if( !isPeerInteresting( t->tor, peer ) )
|
if( !isPeerInteresting( t->tor, peer ) )
|
||||||
|
@ -2522,6 +2528,11 @@ rechokeDownloads( Torrent * t )
|
||||||
else
|
else
|
||||||
bad[badCount++] = peer;
|
bad[badCount++] = peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tr_removeElementFromArray( peers, i, sizeof(tr_peer*), n-- );
|
||||||
|
}
|
||||||
|
|
||||||
|
tr_free( peers );
|
||||||
}
|
}
|
||||||
|
|
||||||
t->interestedCount = 0;
|
t->interestedCount = 0;
|
||||||
|
|
Loading…
Reference in New Issue