Changeset 1272


Ignore:
Timestamp:
Dec 23, 2006, 9:18:58 PM (16 years ago)
Author:
livings124
Message:

divide error logic in tracker code into multiple variables, allowing to determine if all errors in connecting were from unreachable trackers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r1265 r1272  
    7474   
    7575    int            completelyUnconnectable;
     76    int            allUnreachIfError;
     77    int            lastError;
    7678
    7779    uint64_t       dateTry;
     
    7981    uint64_t       dateScrape;
    8082    int            lastScrapeFailed;
    81 
    82 #define TC_ATTEMPT_NOREACH 1
    83 #define TC_ATTEMPT_ERROR   2
    84 #define TC_ATTEMPT_OK      4
    85     char           lastAttempt;
    8683    int            scrapeNeeded;
    8784
     
    122119    tc->scrapeInterval = 600;
    123120
    124     tc->lastAttempt    = TC_ATTEMPT_NOREACH;
     121    tc->lastError      = 1;
     122    tc->allUnreachIfError = 1;
    125123
    126124    tc->bindPort       = *(tor->bindPort);
     
    225223   
    226224    now = tr_date();
    227 
    228     /* Unreachable tracker, wait 10 seconds + random value before trying again */
    229     if( tc->lastAttempt == TC_ATTEMPT_NOREACH &&
    230         now < tc->dateTry + tc->randOffset + 10000 )
    231     {
    232         return 0;
    233     }
    234 
    235     /* The tracker rejected us (like 4XX code, unauthorized IP...),
    236        don't hammer it - we'll probably get the same answer next time
    237        anyway */
    238     if( tc->lastAttempt == TC_ATTEMPT_ERROR &&
    239         now < tc->dateTry + 1000 * tc->interval + tc->randOffset )
    240     {
    241         return 0;
     225   
     226    /* If last was an error and it should not change trackers, then all must have been errors */
     227    if( tc->lastError )
     228    {
     229        /* Unreachable trackers, wait 10 seconds + random value before trying again */
     230        if( tc->allUnreachIfError )
     231        {
     232            if( now < tc->dateTry + tc->randOffset + 10000 )
     233            {
     234                return 0;
     235            }
     236        }
     237        /* The tracker rejected us (like 4XX code, unauthorized IP...),
     238            don't hammer it - we'll probably get the same answer next time
     239            anyway */
     240        else
     241        {
     242            if( now < tc->dateTry + 1000 * tc->interval + tc->randOffset )
     243            {
     244                return 0;
     245            }
     246            else
     247            {
     248                tc->allUnreachIfError = 1;
     249            }
     250        }
    242251    }
    243252
     
    429438               
    430439                failureAnnouncing( tc );
     440               
     441                tc->lastError = 1;
     442               
    431443                if ( tc->shouldChangeAnnounce == TC_CHANGE_NEXT )
    432444                {
     
    434446                    return;
    435447                }
    436                 tc->lastAttempt = TC_ATTEMPT_NOREACH;
    437448               
    438449                break;
     
    641652        /* We don't have a valid HTTP status line */
    642653        tr_inf( "Tracker: invalid HTTP status line" );
    643         tc->lastAttempt = TC_ATTEMPT_NOREACH;
     654        tc->lastError = 1;
    644655        failureAnnouncing( tc );
    645656        return;
     
    668679        /* we didn't get a 2xx status code */
    669680        tr_err( "Tracker: invalid HTTP status code: %i", code );
    670         tc->lastAttempt = TC_ATTEMPT_ERROR;
     681        tc->lastError = 1;
     682        tc->allUnreachIfError = 0;
    671683        failureAnnouncing( tc );
    672684        return;
     
    678690    {
    679691        tr_err( "Tracker: could not find end of HTTP headers" );
    680         tc->lastAttempt = TC_ATTEMPT_NOREACH;
     692        tc->lastError = 1;
    681693        failureAnnouncing( tc );
    682694        return;
     
    699711        if( tc->stopped || 0 < tc->newPort )
    700712        {
    701             tc->lastAttempt = TC_ATTEMPT_OK;
     713            tc->lastError = 0;
    702714            goto nodict;
    703715        }
    704716        tr_err( "Tracker: no valid dictionary found in answer" );
    705         tc->lastAttempt = TC_ATTEMPT_ERROR;
     717        tc->lastError = 1;
     718        tc->allUnreachIfError = 0;
    706719        failureAnnouncing( tc );
    707720        return;
     
    716729        snprintf( tor->trackerError, sizeof( tor->trackerError ),
    717730                  "%s", bePeers->val.s.s );
    718         tc->lastAttempt = TC_ATTEMPT_ERROR;
     731        tc->lastError = 1;
     732        tc->allUnreachIfError = 0;
    719733        failureAnnouncing( tc );
    720734        goto cleanup;
     
    732746
    733747    tor->error &= ~TR_ETRACKER;
    734     tc->lastAttempt = TC_ATTEMPT_OK;
     748    tc->lastError = 0;
     749    tc->allUnreachIfError = 0;
    735750
    736751    /* Get the tracker interval, force to between
Note: See TracChangeset for help on using the changeset viewer.