From f7e3f85e5085e39eb59e5a1edd75c4a9d0100aa0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 1 Oct 2007 14:24:22 +0000 Subject: [PATCH] follow BT `best practices' more closely w.r.t. choosing which pieces to download --- libtransmission/peer-mgr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index ffdb6f783..a129dc66a 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -482,6 +482,7 @@ struct tr_refill_piece uint32_t piece; uint32_t peerCount; uint32_t fastAllowed; + uint32_t random; }; static int @@ -502,8 +503,8 @@ compareRefillPiece (const void * aIn, const void * bIn) if (a->fastAllowed != b->fastAllowed) return a->fastAllowed < b->fastAllowed ? -1 : 1; - /* otherwise go with the earlier piece */ - return a->piece - b->piece; + /* otherwise go with our random seed */ + return tr_compareUint32( a->random, b->random ); } static int @@ -555,6 +556,7 @@ getPreferredPieces( Torrent * t, setme->priority = inf->pieces[piece].priority; setme->peerCount = 0; setme->fastAllowed = 0; + setme->random = tr_rand( UINT32_MAX ); /* FIXME */ // setme->fastAllowed = tr_bitfieldHas( t->tor->allowedList, i);