Changeset 4024


Ignore:
Timestamp:
Nov 30, 2007, 11:37:44 PM (14 years ago)
Author:
charles
Message:

take inspiration from Solomon when handling odd tracker errors that confuse tracker's request queue: stop the torrent.
when the tracker gives us errors that confuse the tracker work queue,

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r3970 r4024  
    171171            tor->error = TR_ERROR_TC_ERROR;
    172172            strlcpy( tor->errorString, event->text, sizeof(tor->errorString) );
     173            tr_torrentStop( tor );
    173174            break;
    174175
  • trunk/libtransmission/tracker.c

    r4021 r4024  
    3636{
    3737    /* seconds between tracker pulses */
    38     PULSE_INTERVAL_MSEC = 750,
     38    PULSE_INTERVAL_MSEC = 1000,
    3939
    4040    /* maximum number of concurrent tracker socket connections */
     
    111111    time_t reannounceAt;
    112112    time_t scrapeAt;
    113 
    114     time_t resendRequestAt;
    115     int resendRequestType;
    116113
    117114    unsigned int isRunning     : 1;
     
    216213publishMessage( tr_tracker * t, const char * msg, int type )
    217214{
    218     tr_tracker_event event = emptyEvent;
    219     event.hash = t->hash;
    220     event.messageType = type;
    221     event.text = msg;
    222     tr_publisherPublish( t->publisher, t, &event );
     215    if( t != NULL )
     216    {
     217        tr_tracker_event event = emptyEvent;
     218        event.hash = t->hash;
     219        event.messageType = type;
     220        event.text = msg;
     221        tr_publisherPublish( t->publisher, t, &event );
     222    }
    223223}
    224224
     
    230230
    231231static void
    232 publishErrorMessage( tr_tracker * t, const char * msg )
    233 {
     232publishErrorMessageAndStop( tr_tracker * t, const char * msg )
     233{
     234    t->isRunning = 0;
    234235    publishMessage( t, msg, TR_TRACKER_ERROR );
    235236}
     
    412413            if(( tmp = tr_bencDictFind( &benc, "failure reason" ))) {
    413414                dbgmsg( t, "got failure message [%s]", tmp->val.s.s );
    414                 publishErrorMessage( t, tmp->val.s.s );
     415                publishErrorMessageAndStop( t, tmp->val.s.s );
    415416            }
    416417
     
    497498    else if( 400<=responseCode && responseCode<=499 )
    498499    {
    499         dbgmsg( t, "got a 4xx error." );
     500        const char * err = req && req->response_code_line
     501            ? req->response_code_line
     502            : "Unspecified 4xx error from tracker.";
     503        dbgmsg( t, err );
    500504
    501505        /* The request could not be understood by the server due to
    502506         * malformed syntax. The client SHOULD NOT repeat the
    503507         * request without modifications. */
    504         if( req && req->response_code_line )
    505             publishErrorMessage( t, req->response_code_line );
     508        publishErrorMessageAndStop( t, err );
    506509        t->manualAnnounceAllowedAt = ~(time_t)0;
    507510        t->reannounceAt = 0;
     
    526529        /* WTF did we get?? */
    527530        if( req && req->response_code_line )
    528             publishErrorMessage( t, req->response_code_line );
     531            publishWarning( t, req->response_code_line );
    529532        t->manualAnnounceAllowedAt = ~(time_t)0;
    530533        t->reannounceAt = time(NULL) + 60;
     
    539542    tr_tracker * t = findTrackerFromHash( vhash );
    540543
    541     dbgmsg( t, "Got scrape response for '%s': %s", (t ? t->name : "(null)"), (req ? req->response_code_line : "(no line)") );
     544    dbgmsg( t, "Got scrape response for '%s': %s (%d)", (t ? t->name : "(null)"), (req ? req->response_code_line : "(no line)"), (req ? req->response_code : -1) );
    542545
    543546    tr_free( vhash );
     
    825828    --handle->tracker->socketCount;
    826829    dbgmsg( NULL, "decrementing socket count to %d", handle->tracker->socketCount );
     830    pulse( handle );
    827831}
    828832
     
    835839}
    836840
    837 static int
     841static void
    838842invokeRequest( tr_handle * handle, const struct tr_tracker_request * req )
    839843{
    840     int err;
    841844    struct evhttp_connection * evcon = getConnection( handle, req->address, req->port );
    842     dbgmsg( NULL, "sending '%s' to tracker %s:%d, timeout is %d", req->uri, req->address, req->port, (int)req->timeout );
     845    tr_tracker * t = findTracker( handle, req->torrent_hash );
     846    dbgmsg( t, "sending '%s' to tracker %s:%d, timeout is %d", req->uri, req->address, req->port, (int)req->timeout );
    843847    evhttp_connection_set_timeout( evcon, req->timeout );
    844     err = evhttp_make_request( evcon, req->req, EVHTTP_REQ_GET, req->uri );
    845     if( !err ) {
     848    if( evhttp_make_request( evcon, req->req, EVHTTP_REQ_GET, req->uri ))
     849        publishErrorMessageAndStop( t, "Tracker could not be reached." );
     850    else {
    846851        ++handle->tracker->socketCount;
    847         dbgmsg( NULL, "incremented socket count to %d", handle->tracker->socketCount );
    848     }
    849     return err;
     852        dbgmsg( t, "incremented socket count to %d", handle->tracker->socketCount );
     853    }
    850854}
    851855
     
    854858{
    855859    struct tr_tracker_request * req = tr_list_pop_front( list );
    856     const int err = invokeRequest( handle, req );
    857 
    858     if( err )
    859     {
    860         tr_tracker * t = findTracker( handle, req->torrent_hash );
    861         if( t != NULL )
    862         {
    863             if( req->reqtype == TR_REQ_SCRAPE ) {
    864                 t->scrapeAt = time(NULL) + 30;
    865                 dbgmsg( t, "scrape failed... retrying in 30 seconds" );
    866             }
    867             else {
    868                 dbgmsg( t, "request [%s] failed... retrying in 30 seconds", req->uri );
    869                 t->resendRequestAt = time(NULL) + 30;
    870                 t->resendRequestType = req->reqtype;
    871             }
    872         }
    873     }
    874 
     860    invokeRequest( handle, req );
    875861    freeRequest( req );
    876862}
     
    902888}
    903889
    904 /**
    905  * This function is called when there's been an error invoking a request,
    906  * or when the tracker has returned back a server error that might require
    907  * the request to be re-sent.
    908  */
    909 static void
    910 maybeRequeueRequest( tr_handle * handle, const tr_tracker * tracker, int reqtype )
    911 {
    912     /* FIXME */
    913     enqueueRequest( handle, tracker, reqtype );
    914 }
    915 
    916890static int
    917891pulse( void * vhandle )
     
    929903    {
    930904        tr_tracker * t = tor->tracker;
    931 
    932         if( t->resendRequestAt && ( now >= t->resendRequestAt ) ) {
    933             t->resendRequestAt = 0;
    934             maybeRequeueRequest( handle, t, t->resendRequestType );
    935         }
    936905
    937906        if( t->scrapeAt && trackerSupportsScrape( t ) && ( now >= t->scrapeAt ) ) {
Note: See TracChangeset for help on using the changeset viewer.