diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index b6ecad237..809723f77 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -291,6 +291,35 @@ tr_torrentInitFilePieces( tr_torrent * tor ) tor->info.pieces[pp].priority = calculatePiecePriority( tor, pp, -1 ); } +int +tr_torrentPromoteTracker( tr_torrent * tor, int pos ) +{ + int i; + int tier; + + assert( tor != NULL ); + assert( 0 <= pos && pos < tor->info.trackerCount ); + + tier = tor->info.trackers[pos].tier; + + /* find the index of the first tracker in that tier */ + for( i=0; iinfo.trackerCount; ++i ) + if( tor->info.trackers[i].tier == tier ) + break; + + assert( i < tor->info.trackerCount ); + + /* swap them if they're not the same */ + if( i != pos ) { + tr_tracker_info tmp = tor->info.trackers[i]; + tor->info.trackers[i] = tor->info.trackers[pos]; + tor->info.trackers[pos] = tmp; + } + + /* return the new position of the tracker that started out at [pos] */ + return i; +} + struct RandomTracker { tr_tracker_info tracker; diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 931ad83ba..367b8596a 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -101,6 +101,8 @@ void tr_torrentSetPieceChecked ( tr_torrent *, tr_piece_index_t piece, int i void tr_torrentSetFileChecked ( tr_torrent *, tr_file_index_t file, int isChecked ); void tr_torrentUncheck ( tr_torrent * ); +int tr_torrentPromoteTracker ( tr_torrent *, int trackerIndex ); + time_t* tr_torrentGetMTimes ( const tr_torrent *, int * setmeCount ); typedef enum diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 9d99784f0..6320c1a44 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -240,16 +240,9 @@ updateAddresses( tr_tracker * t, } else if( response_code == HTTP_OK ) { -#if 0 -/* FIXME */ /* multitracker spec: "if a connection with a tracker is successful, it will be moved to the front of the tier." */ - const int i = t->addressIndex; - const int j = t->tierFronts[i]; - const tr_tracker_info swap = t->addresses[i]; - t->addresses[i] = t->addresses[j]; - t->addresses[j] = swap; -#endif + t->trackerIndex = tr_torrentPromoteTracker( torrent, t->trackerIndex ); } else {