Changeset 224


Ignore:
Timestamp:
Apr 8, 2006, 6:33:56 PM (16 years ago)
Author:
titer
Message:

Make a difference whether the tracker is unreachable or the tracker
replied with an error.

File:
1 edited

Legend:

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

    r223 r224  
    4747    char           status;
    4848
     49#define TC_ATTEMPT_NOREACH 1
     50#define TC_ATTEMPT_ERROR   2
     51#define TC_ATTEMPT_OK      4
     52    char           lastAttempt;
     53
    4954    tr_resolve_t * resolve;
    5055    int            socket;
     
    7378    tc->started  = 1;
    7479
     80    tc->interval = 300;
    7581    tc->seeders  = -1;
    7682    tc->leechers = -1;
    7783
    7884    tc->status   = TC_STATUS_IDLE;
     85    tc->lastAttempt = TC_ATTEMPT_NOREACH;
    7986    tc->size     = 1024;
    8087    tc->buf      = malloc( tc->size );
     
    93100    uint64_t now = tr_date();
    94101
    95     /* In any case, always wait 5 seconds between two requests */
    96     if( now < tc->dateTry + 5000 )
     102    /* Unreachable tracker, try 10 seconds before trying again */
     103    if( tc->lastAttempt == TC_ATTEMPT_NOREACH &&
     104        now < tc->dateTry + 10000 )
     105    {
     106        return 0;
     107    }
     108
     109    /* The tracker rejected us (like 4XX code, unauthorized IP...),
     110       don't hammer it - we'll probably get the same answer next time
     111       anyway */
     112    if( tc->lastAttempt == TC_ATTEMPT_ERROR &&
     113        now < tc->dateTry + 1000 * tc->interval )
    97114    {
    98115        return 0;
     
    391408        /* We don't have a complete HTTP status line */
    392409        tr_inf( "Tracker: incomplete HTTP status line" );
     410        tc->lastAttempt = TC_ATTEMPT_NOREACH;
    393411        return;
    394412    }
     
    399417        tr_err( "Tracker: invalid HTTP status code: %c%c%c",
    400418                tc->buf[9], tc->buf[10], tc->buf[11] );
     419        tc->lastAttempt = TC_ATTEMPT_ERROR;
    401420        return;
    402421    }
     
    417436    {
    418437        tr_err( "Tracker: could not find end of HTTP headers" );
     438        tc->lastAttempt = TC_ATTEMPT_ERROR;
    419439        return;
    420440    }
     
    435455        if( tc->stopped || 0 < tc->newPort )
    436456        {
     457            tc->lastAttempt = TC_ATTEMPT_OK;
    437458            goto nodict;
    438459        }
    439460        tr_err( "Tracker: no dictionary in answer" );
    440         // printf( "%s\n", body );
     461        tc->lastAttempt = TC_ATTEMPT_ERROR;
    441462        return;
    442463    }
     
    445466    {
    446467        tr_err( "Tracker: error parsing bencoded data" );
     468        tc->lastAttempt = TC_ATTEMPT_ERROR;
    447469        return;
    448470    }
     
    456478        snprintf( tor->trackerError, sizeof( tor->trackerError ),
    457479                  "%s", bePeers->val.s.s );
     480        tc->lastAttempt = TC_ATTEMPT_ERROR;
    458481        goto cleanup;
    459482    }
     483
    460484    tor->error &= ~TR_ETRACKER;
     485    tc->lastAttempt = TC_ATTEMPT_OK;
    461486
    462487    if( !tc->interval )
Note: See TracChangeset for help on using the changeset viewer.