Changeset 1239


Ignore:
Timestamp:
Dec 16, 2006, 7:46:45 PM (15 years ago)
Author:
livings124
Message:

swap the sublist address only after successful connect, as per the specs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/multitracker/libtransmission/tracker.c

    r1238 r1239  
    4949#define TC_CHANGE_NO        0
    5050#define TC_CHANGE_NEXT      1
    51 #define TC_CHANGE_REDIRECT  2
     51#define TC_CHANGE_NONEXT    2
     52#define TC_CHANGE_REDIRECT  4
    5253    int            shouldChangeAnnounce;
    5354    int            announceTier;
     
    203204    tc->shouldChangeAnnounce = tc->announceTier + 1 < inf->trackerTiers
    204205                                || tc->announceTierLast + 1 < inf->trackerList[tc->announceTier].count
    205                                 ? TC_CHANGE_NEXT : TC_CHANGE_NO;
    206    
    207     if( tc->shouldChangeAnnounce == TC_CHANGE_NO )
     206                                ? TC_CHANGE_NEXT : TC_CHANGE_NONEXT;
     207   
     208    if( tc->shouldChangeAnnounce == TC_CHANGE_NONEXT )
    208209    {
    209210        tc->completelyUnconnectable = 1;
     
    217218   
    218219    /* Last tracker failed, try next */
    219     if( tc->shouldChangeAnnounce != TC_CHANGE_NO )
     220    if( tc->shouldChangeAnnounce == TC_CHANGE_NEXT
     221        || tc->shouldChangeAnnounce == TC_CHANGE_REDIRECT )
    220222    {
    221223        return 1;
     
    332334        tc->dateTry = tr_date();
    333335       
     336        /* Use redirected address */
    334337        if( tc->shouldChangeAnnounce == TC_CHANGE_REDIRECT )
    335338        {
    336             /* Use redirected address */
    337339            if( !tr_httpParseUrl( tc->redirectAddress, tc->redirectAddressLen,
    338340                                     &address, &port, &announce ) )
     
    345347            }
    346348           
    347             tc->shouldChangeAnnounce = TC_CHANGE_NO;
    348            
    349349            free( tc->redirectAddress );
    350350            tc->redirectAddress = NULL;
     
    352352        else
    353353        {
     354            /* Need to change to next address in list */
    354355            if( tc->shouldChangeAnnounce == TC_CHANGE_NEXT )
    355356            {
     
    357358               
    358359                if( tc->announceTierLast + 1 < inf->trackerList[tc->announceTier].count )
     360                {
     361                    tc->announceTierLast++;
     362                   
     363                    announcePtr = tc->trackerAnnounceListPtr[tc->announceTier];
     364                    for( i = 0; i < tc->announceTierLast; i++ )
     365                    {
     366                        announcePtr = announcePtr->nextItem;
     367                    }
     368                }
     369                else
     370                {
     371                    tc->announceTierLast = 0;
     372                    tc->announceTier++;
     373                   
     374                    announcePtr = tc->trackerAnnounceListPtr[tc->announceTier];
     375                }
     376               
     377                tr_inf( "Tracker: tracker address set to %s", tc->trackerAnnounceListPtr[tc->announceTier]->item->address );
     378                setAnnounce( tc, announcePtr );
     379            }
     380            /* Need to change to first in list */
     381            else if( tc->announceTier != 0 || tc->announceTierLast != 0 )
     382            {
     383                /* Check if the last announce was successful and wasn't the first in the sublist */
     384                if( tc->shouldChangeAnnounce == TC_CHANGE_NO && tc->announceTierLast != 0 )
    359385                {
    360386                    prevAnnouncePtr = tc->trackerAnnounceListPtr[tc->announceTier];
     
    370396                    announcePtr->nextItem =  tc->trackerAnnounceListPtr[tc->announceTier];
    371397                    tc->trackerAnnounceListPtr[tc->announceTier] = announcePtr;
    372                    
    373                     tc->announceTierLast++;
    374                 }
    375                 else
    376                 {
    377                     tc->announceTierLast = 0;
    378                     tc->announceTier++;
    379398                }
    380399               
    381                 tr_inf( "Tracker: tracker address set to %s", tc->trackerAnnounceListPtr[tc->announceTier]->item->address );
    382                 setAnnounce( tc, tc->trackerAnnounceListPtr[tc->announceTier] );
    383                 tc->shouldChangeAnnounce = TC_CHANGE_NO;
    384             }
    385             else
    386             {
    387                 if( tc->announceTier != 0 )
    388                 {
    389                     setAnnounce( tc, tc->trackerAnnounceListPtr[0] );
    390                     tc->announceTier = 0;
    391                 }
     400                setAnnounce( tc, tc->trackerAnnounceListPtr[0] );
     401                tc->announceTier = 0;
    392402                tc->announceTierLast = 0;
    393403            }
     
    403413                          "getting peers" ) ) ) );
    404414        }
     415       
     416        tc->shouldChangeAnnounce = TC_CHANGE_NO;
    405417    }
    406418
     
    417429               
    418430                failureAnnouncing( tc );
    419                 if ( tc->shouldChangeAnnounce != TC_CHANGE_NO )
     431                if ( tc->shouldChangeAnnounce == TC_CHANGE_NEXT )
    420432                {
    421433                    tr_trackerPulse( tc );
     
    430442               
    431443                /* Something happened to need to try next address */
    432                 if ( tc->shouldChangeAnnounce != TC_CHANGE_NO )
     444                if ( tc->shouldChangeAnnounce == TC_CHANGE_NEXT
     445                    || tc->shouldChangeAnnounce == TC_CHANGE_REDIRECT )
    433446                {
    434447                    tr_trackerPulse( tc );
Note: See TracChangeset for help on using the changeset viewer.