(trunk libT) add randomness to the peer unchoking algorithm
This commit is contained in:
parent
353e37c69e
commit
77c43d3f66
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <errno.h> /* error codes ERANGE, ... */
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include <string.h> /* memcpy, memcmp, strstr */
|
||||
#include <stdlib.h> /* qsort */
|
||||
|
||||
|
@ -2579,6 +2580,7 @@ struct ChokeData
|
|||
tr_bool isInterested;
|
||||
tr_bool isChoked;
|
||||
int rate;
|
||||
int salt;
|
||||
tr_peer * peer;
|
||||
};
|
||||
|
||||
|
@ -2595,6 +2597,9 @@ compareChoke( const void * va,
|
|||
if( a->isChoked != b->isChoked ) /* prefer unchoked */
|
||||
return a->isChoked ? 1 : -1;
|
||||
|
||||
if( a->salt != b->salt ) /* random order */
|
||||
return a->salt - b->salt;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2665,6 +2670,7 @@ rechokeUploads( Torrent * t, const uint64_t now )
|
|||
n->isInterested = peer->peerIsInterested;
|
||||
n->isChoked = peer->peerIsChoked;
|
||||
n->rate = getRate( t->tor, atom, now );
|
||||
n->salt = tr_cryptoWeakRandInt( INT_MAX );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue