]> granicus.if.org Git - transmission/commitdiff
when one of the trackers in a multitracker list is successful, bump it to the top...
authorCharles Kerr <charles@transmissionbt.com>
Mon, 5 May 2008 19:51:53 +0000 (19:51 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Mon, 5 May 2008 19:51:53 +0000 (19:51 +0000)
libtransmission/torrent.c
libtransmission/torrent.h
libtransmission/tracker.c

index b6ecad237447f2e6a8822a2acc4390adb806b912..809723f7734bd07903192d1385b56b58fd7689a5 100644 (file)
@@ -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; i<tor->info.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;
index 931ad83ba09c5acc5040feba3920503a3ac37bdb..367b8596ae899c8972e3c8d919a003e3e9bd29fa 100644 (file)
@@ -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
index 9d99784f02369a22ec0735f8317486d4b9ec7b43..6320c1a44e7aa706cb4921bd57a71910770d9f05 100644 (file)
@@ -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 
     {