1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00

randomize the announce addresses within multitracker tiers

This commit is contained in:
Charles Kerr 2008-05-05 18:54:19 +00:00
parent 85e66062eb
commit 643716c6f0

View file

@ -28,6 +28,7 @@
#include <assert.h>
#include <string.h> /* memcmp */
#include <stdlib.h> /* qsort */
#include "transmission.h"
#include "bencode.h"
@ -289,6 +290,41 @@ tr_torrentInitFilePieces( tr_torrent * tor )
tor->info.pieces[pp].priority = calculatePiecePriority( tor, pp, -1 );
}
struct RandomTracker
{
tr_tracker_info tracker;
int random_value;
};
static int
compareRandomTracker( const void * va, const void * vb )
{
const struct RandomTracker * a = va;
const struct RandomTracker * b = vb;
if( a->tracker.tier != b->tracker.tier )
return a->tracker.tier - b->tracker.tier;
return a->random_value - b->random_value;
}
static void
randomizeTiers( tr_info * info )
{
int i;
const int n = info->trackerCount;
struct RandomTracker * r;
r = tr_new0( struct RandomTracker, n );
for( i=0; i<n; ++i ) {
r[i].tracker = info->trackers[i];
r[i].random_value = tr_rand( INT_MAX );
}
qsort( r, n, sizeof( struct RandomTracker ), compareRandomTracker );
for( i=0; i<n; ++i )
info->trackers[i] = r[i].tracker;
tr_free( r );
}
static void
torrentRealInit( tr_handle * h,
tr_torrent * tor,
@ -303,6 +339,8 @@ torrentRealInit( tr_handle * h,
tor->handle = h;
randomizeTiers( info );
/**
* Decide on a block size. constraints:
* (1) most clients decline requests over 16 KiB