1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-10 06:02:57 +00:00

* 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.
This commit is contained in:
Charles Kerr 2007-10-07 16:07:19 +00:00
parent e2de6f8973
commit 1014e633ac
2 changed files with 35 additions and 35 deletions

View file

@ -1143,7 +1143,10 @@ gotBadPiece( tr_peermsgs * msgs, uint32_t pieceIndex )
} }
static void static void
gotUnwantedBlock( tr_peermsgs * msgs, uint32_t index UNUSED, uint32_t offset UNUSED, uint32_t length ) gotUnwantedBlock( tr_peermsgs * msgs,
uint32_t index UNUSED,
uint32_t offset UNUSED,
uint32_t length )
{ {
reassignBytesToCorrupt( msgs, length ); reassignBytesToCorrupt( msgs, length );
} }

View file

@ -44,11 +44,8 @@
/* unless the tracker tells us otherwise, reannounce this frequently */ /* unless the tracker tells us otherwise, reannounce this frequently */
#define DEFAULT_ANNOUNCE_INTERVAL_MSEC (MINUTES_TO_MSEC(20)) #define DEFAULT_ANNOUNCE_INTERVAL_MSEC (MINUTES_TO_MSEC(20))
/* this is how long we'll leave a scrape request hanging before timeout */ /* this is how long we'll leave a request hanging before timeout */
#define SCRAPE_TIMEOUT_INTERVAL_SEC 60 #define TIMEOUT_INTERVAL_SEC 5
/* this is how long we'll leave a tracker request hanging before timeout */
#define REQ_TIMEOUT_INTERVAL_SEC 60
/* the value of the 'numwant' argument passed in tracker requests */ /* the value of the 'numwant' argument passed in tracker requests */
#define NUMWANT 128 #define NUMWANT 128
@ -92,8 +89,6 @@ typedef struct
char key_param[TR_KEY_LEN+1]; char key_param[TR_KEY_LEN+1];
tr_timer * scrapeTimer; tr_timer * scrapeTimer;
struct evhttp_connection * connection;
} }
Tracker; Tracker;
@ -159,27 +154,26 @@ torrentCompare( const void * va, const void * vb )
**** ****
***/ ***/
static int
freeConnection( void * evcon )
{
evhttp_connection_free( evcon );
return FALSE;
}
static void
connectionClosedCB( struct evhttp_connection * evcon, void * handle )
{
tr_timerNew( handle, freeConnection, evcon, 100 );
}
static struct evhttp_connection* static struct evhttp_connection*
getConnection( Tracker * tracker, const char * address, int port ) getConnection( Tracker * tracker, const char * address, int port )
{ {
if( tracker->connection != NULL ) struct evhttp_connection * c = evhttp_connection_new( address, port );
{ evhttp_connection_set_timeout( c, TIMEOUT_INTERVAL_SEC );
char * a = NULL; evhttp_connection_set_closecb( c, connectionClosedCB, tracker->handle );
unsigned short p = 0; return c;
evhttp_connection_get_peer( tracker->connection, &a, &p );
/* old one matches -- reuse it */
if( a && !strcmp(a,address) && p==port )
return tracker->connection;
/* old one doesn't match -- throw it away */
evhttp_connection_free( tracker->connection );
tracker->connection = NULL;
}
/* make a new connection */
tracker->connection = evhttp_connection_new( address, port );
return tracker->connection;
} }
/*** /***
@ -371,9 +365,6 @@ onTorrentFreeNow( void * vtor )
int i; int i;
tr_ptrArrayRemoveSorted( getTrackerLookupTable( ), t, trackerCompare ); tr_ptrArrayRemoveSorted( getTrackerLookupTable( ), t, trackerCompare );
if( t->connection != NULL )
evhttp_connection_free( t->connection );
tr_ptrArrayFree( t->torrents, NULL ); tr_ptrArrayFree( t->torrents, NULL );
tr_ptrArrayFree( t->scrapeQueue, NULL ); tr_ptrArrayFree( t->scrapeQueue, NULL );
tr_ptrArrayFree( t->scraping, NULL ); tr_ptrArrayFree( t->scraping, NULL );
@ -684,8 +675,8 @@ onTrackerScrapeNow( void * vt )
char *march, *uri; char *march, *uri;
Torrent ** torrents = Torrent ** torrents =
(Torrent**) tr_ptrArrayPeek( t->scrapeQueue, &n ); (Torrent**) tr_ptrArrayPeek( t->scrapeQueue, &n );
struct evhttp_connection *evcon = NULL; struct evhttp_connection * evcon;
struct evhttp_request *req = NULL; struct evhttp_request *req;
ask_n = n; ask_n = n;
if( ask_n > t->multiscrapeMax ) if( ask_n > t->multiscrapeMax )
@ -719,7 +710,6 @@ onTrackerScrapeNow( void * vt )
tr_inf( "Sending scrape to tracker %s:%d: %s", tr_inf( "Sending scrape to tracker %s:%d: %s",
address->address, address->port, uri ); address->address, address->port, uri );
evcon = getConnection( t, address->address, address->port ); evcon = getConnection( t, address->address, address->port );
evhttp_connection_set_timeout( evcon, SCRAPE_TIMEOUT_INTERVAL_SEC );
req = evhttp_request_new( onScrapeResponse, t ); req = evhttp_request_new( onScrapeResponse, t );
assert( req ); assert( req );
addCommonHeaders( t, req ); addCommonHeaders( t, req );
@ -855,6 +845,11 @@ onTrackerResponseDataNew( Torrent * tor )
return data; return data;
} }
static void
onStoppedResponse( struct evhttp_request * req UNUSED, void * handle UNUSED )
{
}
static void static void
onTrackerResponse( struct evhttp_request * req, void * vdata ) onTrackerResponse( struct evhttp_request * req, void * vdata )
{ {
@ -975,7 +970,7 @@ sendTrackerRequest( void * vt, const char * eventName )
Torrent * t = (Torrent *) vt; Torrent * t = (Torrent *) vt;
const tr_tracker_info * address = getCurrentAddress( t->tracker ); const tr_tracker_info * address = getCurrentAddress( t->tracker );
char * uri; char * uri;
struct evhttp_connection * evcon = NULL; struct evhttp_connection * evcon;
const tr_torrent * tor; const tr_torrent * tor;
tor = tr_torrentFindFromHash( t->tracker->handle, t->hash ); tor = tr_torrentFindFromHash( t->tracker->handle, t->hash );
@ -1001,8 +996,10 @@ sendTrackerRequest( void * vt, const char * eventName )
struct evhttp_request * httpReq; struct evhttp_request * httpReq;
tr_free( t->lastRequest ); tr_free( t->lastRequest );
t->lastRequest = tr_strdup( eventName ); t->lastRequest = tr_strdup( eventName );
evhttp_connection_set_timeout( evcon, REQ_TIMEOUT_INTERVAL_SEC ); if( eventName && !strcmp( eventName, "stopped" ) )
httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) ); httpReq = evhttp_request_new( onStoppedResponse, t->tracker->handle );
else
httpReq = evhttp_request_new( onTrackerResponse, onTrackerResponseDataNew(t) );
addCommonHeaders( t->tracker, httpReq ); addCommonHeaders( t->tracker, httpReq );
tr_evhttp_make_request( t->tracker->handle, evcon, tr_evhttp_make_request( t->tracker->handle, evcon,
httpReq, EVHTTP_REQ_GET, uri ); httpReq, EVHTTP_REQ_GET, uri );