Ignore:
Timestamp:
Oct 7, 2007, 4:07:19 PM (15 years ago)
Author:
charles
Message:
  • don't reuse http connections to trackers. I think this is what caused most of the `no response from tracker X' messages.
  • extra safety checks to ensure the last `stopped' message to the tracker is sent on shutdown.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r3308 r3317  
    4545#define DEFAULT_ANNOUNCE_INTERVAL_MSEC (MINUTES_TO_MSEC(20))
    4646
    47 /* this is how long we'll leave a scrape request hanging before timeout */
    48 #define SCRAPE_TIMEOUT_INTERVAL_SEC 60
    49 
    50 /* this is how long we'll leave a tracker request hanging before timeout */
    51 #define REQ_TIMEOUT_INTERVAL_SEC 60
     47/* this is how long we'll leave a request hanging before timeout */
     48#define TIMEOUT_INTERVAL_SEC 5
    5249
    5350/* the value of the 'numwant' argument passed in tracker requests */
     
    9390
    9491    tr_timer * scrapeTimer;
    95 
    96     struct evhttp_connection * connection;
    9792}
    9893Tracker;
     
    160155***/
    161156
     157static int
     158freeConnection( void * evcon )
     159{
     160    evhttp_connection_free( evcon );
     161    return FALSE;
     162}
     163
     164static void
     165connectionClosedCB( struct evhttp_connection * evcon, void * handle )
     166{
     167    tr_timerNew( handle, freeConnection, evcon, 100 );
     168}
     169
    162170static struct evhttp_connection*
    163171getConnection( Tracker * tracker, const char * address, int port )
    164172{
    165     if( tracker->connection != NULL )
    166     {
    167         char * a = NULL;
    168         unsigned short p = 0;
    169         evhttp_connection_get_peer( tracker->connection, &a, &p );
    170 
    171         /* old one matches -- reuse it */
    172         if( a && !strcmp(a,address) && p==port )
    173             return tracker->connection;
    174 
    175         /* old one doesn't match -- throw it away */
    176         evhttp_connection_free( tracker->connection );
    177         tracker->connection = NULL;
    178     }
    179 
    180     /* make a new connection */
    181     tracker->connection = evhttp_connection_new( address, port );
    182     return tracker->connection;
     173    struct evhttp_connection * c = evhttp_connection_new( address, port );
     174    evhttp_connection_set_timeout( c, TIMEOUT_INTERVAL_SEC );
     175    evhttp_connection_set_closecb( c, connectionClosedCB, tracker->handle );
     176    return c;
    183177}
    184178
     
    371365        int i;
    372366        tr_ptrArrayRemoveSorted( getTrackerLookupTable( ), t, trackerCompare );
    373 
    374         if( t->connection != NULL )
    375             evhttp_connection_free( t->connection );
    376367
    377368        tr_ptrArrayFree( t->torrents, NULL );
     
    685676        Torrent ** torrents =
    686677            (Torrent**) tr_ptrArrayPeek( t->scrapeQueue, &n );
    687         struct evhttp_connection *evcon = NULL;
    688         struct evhttp_request *req = NULL;
     678        struct evhttp_connection * evcon;
     679        struct evhttp_request *req;
    689680
    690681        ask_n = n;
     
    720711                address->address, address->port, uri );
    721712        evcon = getConnection( t, address->address, address->port );
    722         evhttp_connection_set_timeout( evcon, SCRAPE_TIMEOUT_INTERVAL_SEC );
    723713        req = evhttp_request_new( onScrapeResponse, t );
    724714        assert( req );
     
    857847
    858848static void
     849onStoppedResponse( struct evhttp_request * req UNUSED, void * handle UNUSED )
     850{
     851}
     852
     853static void
    859854onTrackerResponse( struct evhttp_request * req, void * vdata )
    860855{
     
    976971    const tr_tracker_info * address = getCurrentAddress( t->tracker );
    977972    char * uri;
    978     struct evhttp_connection * evcon = NULL;
     973    struct evhttp_connection * evcon;
    979974    const tr_torrent * tor;
    980975
     
    1002997        tr_free( t->lastRequest );
    1003998        t->lastRequest = tr_strdup( eventName );
    1004         evhttp_connection_set_timeout( evcon, REQ_TIMEOUT_INTERVAL_SEC );
    1005         httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) );
     999        if( eventName && !strcmp( eventName, "stopped" ) )
     1000            httpReq = evhttp_request_new( onStoppedResponse, t->tracker->handle );
     1001        else
     1002            httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) );
    10061003        addCommonHeaders( t->tracker, httpReq );
    10071004        tr_evhttp_make_request( t->tracker->handle, evcon,
Note: See TracChangeset for help on using the changeset viewer.