Changeset 5746


Ignore:
Timestamp:
May 5, 2008, 6:54:19 PM (14 years ago)
Author:
charles
Message:

randomize the announce addresses within multitracker tiers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r5707 r5746  
    2929#include <assert.h>
    3030#include <string.h> /* memcmp */
     31#include <stdlib.h> /* qsort */
    3132
    3233#include "transmission.h"
     
    290291}
    291292
     293struct RandomTracker
     294{
     295    tr_tracker_info tracker;
     296    int random_value;
     297};
     298
     299static int
     300compareRandomTracker( const void * va, const void * vb )
     301{
     302    const struct RandomTracker * a = va;
     303    const struct RandomTracker * b = vb;
     304
     305    if( a->tracker.tier != b->tracker.tier )
     306        return a->tracker.tier - b->tracker.tier;
     307
     308   return a->random_value - b->random_value;
     309}
     310   
     311static void
     312randomizeTiers( tr_info * info )
     313{
     314    int i;
     315    const int n = info->trackerCount;
     316    struct RandomTracker * r;
     317    r = tr_new0( struct RandomTracker, n );
     318    for( i=0; i<n; ++i ) {
     319        r[i].tracker = info->trackers[i];
     320        r[i].random_value = tr_rand( INT_MAX );
     321    }
     322    qsort( r, n, sizeof( struct RandomTracker ), compareRandomTracker );
     323    for( i=0; i<n; ++i )
     324        info->trackers[i] = r[i].tracker;
     325    tr_free( r );
     326}
     327
    292328static void
    293329torrentRealInit( tr_handle     * h,
     
    303339
    304340    tor->handle   = h;
     341
     342    randomizeTiers( info );
    305343
    306344    /**
Note: See TracChangeset for help on using the changeset viewer.