Changeset 5749


Ignore:
Timestamp:
May 5, 2008, 8:11:03 PM (14 years ago)
Author:
charles
Message:

fix multitracker problem reported by BentMyWookie?

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r5748 r5749  
    299299
    300300    assert( tor != NULL );
    301     assert( 0 <= pos && pos < tor->info.trackerCount );
    302 
     301    assert( ( 0 <= pos ) && ( pos < tor->info.trackerCount ) );
     302
     303    /* the tier of the tracker we're promoting */
    303304    tier = tor->info.trackers[pos].tier;
    304305
    305     /* find the index of the first tracker in that tier */
     306    /* find the index of that tier's first tracker */
    306307    for( i=0; i<tor->info.trackerCount; ++i )
    307308        if( tor->info.trackers[i].tier == tier )
     
    310311    assert( i < tor->info.trackerCount );
    311312
    312     /* swap them if they're not the same */
     313    /* promote the tracker at `pos' to the front of the tier */
    313314    if( i != pos ) {
    314         tr_tracker_info tmp = tor->info.trackers[i];
     315        const tr_tracker_info tmp = tor->info.trackers[i];
    315316        tor->info.trackers[i] = tor->info.trackers[pos];
    316317        tor->info.trackers[pos] = tmp;
     
    327328};
    328329
     330/* the tiers will be sorted from lowest to highest,
     331 * and trackers are randomized within the tiers */
    329332static int
    330333compareRandomTracker( const void * va, const void * vb )
     
    344347    int i;
    345348    const int n = info->trackerCount;
    346     struct RandomTracker * r;
    347     r = tr_new0( struct RandomTracker, n );
     349    struct RandomTracker * r = tr_new0( struct RandomTracker, n );
    348350    for( i=0; i<n; ++i ) {
    349351        r[i].tracker = info->trackers[i];
  • trunk/libtransmission/tracker.c

    r5748 r5749  
    225225static void onReqDone( tr_session * session );
    226226
    227 static void
    228 updateAddresses( tr_tracker  * t,
    229                  long          response_code,
    230                  int           moveToNextAddress,
    231                  int         * tryAgain )
    232 {
     227static int
     228updateAddresses( tr_tracker  * t, int success )
     229{
     230    int retry;
     231
    233232    tr_torrent * torrent = tr_torrentFindFromHash( t->session, t->hash );
    234233
    235 
    236     if( !response_code ) /* tracker didn't respond */
    237     {
    238         tr_ninf( t->name, _( "Tracker hasn't responded yet.  Retrying..." ) );
    239         moveToNextAddress = TRUE;
    240     }
    241     else if( response_code == HTTP_OK )
     234    if( success )
    242235    {
    243236        /* multitracker spec: "if a connection with a tracker is
    244237           successful, it will be moved to the front of the tier." */
    245238        t->trackerIndex = tr_torrentPromoteTracker( torrent, t->trackerIndex );
    246     }
    247     else
    248     {
    249         moveToNextAddress = TRUE;
    250     }
    251 
    252     *tryAgain = moveToNextAddress;
    253     if( moveToNextAddress )
    254     {
    255         if ( ++t->trackerIndex >= torrent->info.trackerCount ) /* we've tried them all */
    256         {
    257             *tryAgain = FALSE;
    258             t->trackerIndex = 0;
    259         }
    260         else
    261         {
    262             const tr_tracker_info * n = getCurrentAddressFromTorrent( t, torrent );
    263             tr_ninf( t->name, _( "Trying tracker \"%s\"" ), n->announce );
    264         }
    265     }
     239        retry = FALSE; /* we succeeded; no need to retry */
     240    }
     241    else if ( ++t->trackerIndex >= torrent->info.trackerCount )
     242    {
     243        t->trackerIndex = 0;
     244        retry = FALSE; /* we've tried them all */
     245    }
     246    else
     247    {
     248        const tr_tracker_info * n = getCurrentAddressFromTorrent( t, torrent );
     249        tr_ninf( t->name, _( "Trying tracker \"%s\"" ), n->announce );
     250        retry = TRUE;
     251    }
     252
     253    return retry;
    266254}
    267255
     
    322310                   void          * torrent_hash )
    323311{
    324     int moveToNextAddress = FALSE;
    325     int tryAgain;
     312    int retry;
     313    int success = FALSE;
    326314    tr_tracker * t;
    327315
     
    348336            const char * str;
    349337
     338            success = TRUE;
     339
    350340            if(( tr_bencDictFindStr( &benc, "failure reason", &str ))) {
    351341               // publishErrorMessageAndStop( t, str );
    352                 moveToNextAddress = TRUE;
    353342                publishMessage( t, str, TR_TRACKER_ERROR );
     343                success = FALSE;
    354344            }
    355345
     
    398388    }
    399389
    400     updateAddresses( t, responseCode, moveToNextAddress, &tryAgain );
     390    retry = updateAddresses( t, success );
    401391
    402392    /**
     
    404394    **/
    405395
    406     if( tryAgain )
     396    if( retry )
    407397        responseCode = 300;
    408398
     
    459449                  void         * torrent_hash )
    460450{
    461     int moveToNextAddress = FALSE;
    462     int tryAgain;
     451    int success = FALSE;
     452    int retry;
    463453    tr_tracker * t;
    464454
     
    505495                        t->scrapeIntervalSec = i;
    506496
     497                success = TRUE;
     498
    507499                tr_ndbg( t->name, "Scrape successful.  Rescraping in %d seconds.",
    508500                         t->scrapeIntervalSec );
     
    511503            }
    512504        }
    513         else
    514             moveToNextAddress = TRUE;
    515505
    516506        if( bencLoaded )
     
    518508    }
    519509
    520     updateAddresses( t, responseCode, moveToNextAddress, &tryAgain );
     510    retry = updateAddresses( t, success );
    521511
    522512    /**
     
    524514    **/
    525515
    526     if( tryAgain )
     516    if( retry )
    527517        responseCode = 300;
    528518
Note: See TracChangeset for help on using the changeset viewer.