diff --git a/libtransmission/announcer.c b/libtransmission/announcer.c index 31c5bb126..c1be5fd59 100644 --- a/libtransmission/announcer.c +++ b/libtransmission/announcer.c @@ -225,7 +225,7 @@ getKey( const char * url ) static tr_tracker* trackerNew( const char * announce, const char * scrape, uint32_t id ) { - tr_tracker * tracker = tr_new0( tr_tracker, 1 ); + tr_tracker * tracker = tr_new0( tr_tracker, 1 ); tracker->key = getKey( announce ); tracker->announce = tr_strdup( announce ); tracker->scrape = tr_strdup( scrape ); @@ -348,8 +348,9 @@ static void tierIncrementTracker( tr_tier * tier ) { /* move our index to the next tracker in the tier */ - const int i = ( tier->currentTrackerIndex + 1 ) - % tr_ptrArraySize( &tier->trackers ); + const int i = ( tier->currentTracker == NULL ) + ? 0 + : ( tier->currentTrackerIndex + 1 ) % tr_ptrArraySize( &tier->trackers ); tier->currentTracker = tr_ptrArrayNth( &tier->trackers, i ); tier->currentTrackerIndex = i; @@ -519,21 +520,120 @@ publishPeersPex( tr_tier * tier, int seeds, int leechers, **** ***/ +struct ann_tracker_info +{ + tr_tracker_info info; + + char * scheme; + char * host; + char * path; + int port; +}; + + +/* primary key: tier + * secondary key: udp comes before http */ +static int +filter_trackers_compare_func( const void * va, const void * vb ) +{ + const struct ann_tracker_info * a = va; + const struct ann_tracker_info * b = vb; + if( a->info.tier != b->info.tier ) + return a->info.tier - b->info.tier; + return -strcmp( a->scheme, b->scheme ); +} + +/** + * Massages the incoming list of trackers into something we can use. + */ +static tr_tracker_info * +filter_trackers( tr_tracker_info * input, int input_count, int * setme_count ) +{ + int i, in; + int j, jn; + int n = 0; + struct tr_tracker_info * ret; + struct ann_tracker_info * tmp = tr_new0( struct ann_tracker_info, input_count ); + + /*for( i=0, in=input_count; iinfo.trackerCount; - const tr_tracker_info * trackers = tor->info.trackers; + tr_tracker_info * infos = filter_trackers( tor->info.trackers, + tor->info.trackerCount, &n ); - /* get the trackers that we support... */ - infos = tr_new0( const tr_tracker_info*, trackerCount ); - for( i=n=0; i 0 ) { int tierIndex = -1; @@ -541,7 +641,7 @@ addTorrentToTier( tr_torrent_tiers * tiers, tr_torrent * tor ) for( i=0; itier != tierIndex ) tier = NULL; @@ -620,7 +720,7 @@ tr_announcerNextManualAnnounce( const tr_torrent * tor ) const tr_torrent_tiers * tiers; time_t ret = ~(time_t)0; - assert( tr_isTorrent( tor ) ); + assert( tr_isTorrent( tor ) ); /* find the earliest manual announce time from all peers */ tiers = tor->tiers;