divide error logic in tracker code into multiple variables, allowing to determine if all errors in connecting were from unreachable trackers
This commit is contained in:
parent
594d887a36
commit
0aa4d36809
|
@ -73,16 +73,13 @@ struct tr_tracker_s
|
||||||
int randOffset;
|
int randOffset;
|
||||||
|
|
||||||
int completelyUnconnectable;
|
int completelyUnconnectable;
|
||||||
|
int allUnreachIfError;
|
||||||
|
int lastError;
|
||||||
|
|
||||||
uint64_t dateTry;
|
uint64_t dateTry;
|
||||||
uint64_t dateOk;
|
uint64_t dateOk;
|
||||||
uint64_t dateScrape;
|
uint64_t dateScrape;
|
||||||
int lastScrapeFailed;
|
int lastScrapeFailed;
|
||||||
|
|
||||||
#define TC_ATTEMPT_NOREACH 1
|
|
||||||
#define TC_ATTEMPT_ERROR 2
|
|
||||||
#define TC_ATTEMPT_OK 4
|
|
||||||
char lastAttempt;
|
|
||||||
int scrapeNeeded;
|
int scrapeNeeded;
|
||||||
|
|
||||||
tr_http_t * http;
|
tr_http_t * http;
|
||||||
|
@ -121,7 +118,8 @@ tr_tracker_t * tr_trackerInit( tr_torrent_t * tor )
|
||||||
tc->interval = 300;
|
tc->interval = 300;
|
||||||
tc->scrapeInterval = 600;
|
tc->scrapeInterval = 600;
|
||||||
|
|
||||||
tc->lastAttempt = TC_ATTEMPT_NOREACH;
|
tc->lastError = 1;
|
||||||
|
tc->allUnreachIfError = 1;
|
||||||
|
|
||||||
tc->bindPort = *(tor->bindPort);
|
tc->bindPort = *(tor->bindPort);
|
||||||
tc->newPort = -1;
|
tc->newPort = -1;
|
||||||
|
@ -225,20 +223,31 @@ static int shouldConnect( tr_tracker_t * tc )
|
||||||
|
|
||||||
now = tr_date();
|
now = tr_date();
|
||||||
|
|
||||||
/* Unreachable tracker, wait 10 seconds + random value before trying again */
|
/* If last was an error and it should not change trackers, then all must have been errors */
|
||||||
if( tc->lastAttempt == TC_ATTEMPT_NOREACH &&
|
if( tc->lastError )
|
||||||
now < tc->dateTry + tc->randOffset + 10000 )
|
|
||||||
{
|
{
|
||||||
return 0;
|
/* Unreachable trackers, wait 10 seconds + random value before trying again */
|
||||||
}
|
if( tc->allUnreachIfError )
|
||||||
|
{
|
||||||
/* The tracker rejected us (like 4XX code, unauthorized IP...),
|
if( now < tc->dateTry + tc->randOffset + 10000 )
|
||||||
don't hammer it - we'll probably get the same answer next time
|
{
|
||||||
anyway */
|
return 0;
|
||||||
if( tc->lastAttempt == TC_ATTEMPT_ERROR &&
|
}
|
||||||
now < tc->dateTry + 1000 * tc->interval + tc->randOffset )
|
}
|
||||||
{
|
/* The tracker rejected us (like 4XX code, unauthorized IP...),
|
||||||
return 0;
|
don't hammer it - we'll probably get the same answer next time
|
||||||
|
anyway */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( now < tc->dateTry + 1000 * tc->interval + tc->randOffset )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tc->allUnreachIfError = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do we need to send an event? */
|
/* Do we need to send an event? */
|
||||||
|
@ -428,12 +437,14 @@ void tr_trackerPulse( tr_tracker_t * tc )
|
||||||
tc->dateTry = tr_date();
|
tc->dateTry = tr_date();
|
||||||
|
|
||||||
failureAnnouncing( tc );
|
failureAnnouncing( tc );
|
||||||
|
|
||||||
|
tc->lastError = 1;
|
||||||
|
|
||||||
if ( tc->shouldChangeAnnounce == TC_CHANGE_NEXT )
|
if ( tc->shouldChangeAnnounce == TC_CHANGE_NEXT )
|
||||||
{
|
{
|
||||||
tr_trackerPulse( tc );
|
tr_trackerPulse( tc );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tc->lastAttempt = TC_ATTEMPT_NOREACH;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -640,7 +651,7 @@ static void readAnswer( tr_tracker_t * tc, const char * data, int len )
|
||||||
{
|
{
|
||||||
/* We don't have a valid HTTP status line */
|
/* We don't have a valid HTTP status line */
|
||||||
tr_inf( "Tracker: invalid HTTP status line" );
|
tr_inf( "Tracker: invalid HTTP status line" );
|
||||||
tc->lastAttempt = TC_ATTEMPT_NOREACH;
|
tc->lastError = 1;
|
||||||
failureAnnouncing( tc );
|
failureAnnouncing( tc );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -667,7 +678,8 @@ static void readAnswer( tr_tracker_t * tc, const char * data, int len )
|
||||||
{
|
{
|
||||||
/* we didn't get a 2xx status code */
|
/* we didn't get a 2xx status code */
|
||||||
tr_err( "Tracker: invalid HTTP status code: %i", code );
|
tr_err( "Tracker: invalid HTTP status code: %i", code );
|
||||||
tc->lastAttempt = TC_ATTEMPT_ERROR;
|
tc->lastError = 1;
|
||||||
|
tc->allUnreachIfError = 0;
|
||||||
failureAnnouncing( tc );
|
failureAnnouncing( tc );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -677,7 +689,7 @@ static void readAnswer( tr_tracker_t * tc, const char * data, int len )
|
||||||
if( NULL == body )
|
if( NULL == body )
|
||||||
{
|
{
|
||||||
tr_err( "Tracker: could not find end of HTTP headers" );
|
tr_err( "Tracker: could not find end of HTTP headers" );
|
||||||
tc->lastAttempt = TC_ATTEMPT_NOREACH;
|
tc->lastError = 1;
|
||||||
failureAnnouncing( tc );
|
failureAnnouncing( tc );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -698,11 +710,12 @@ static void readAnswer( tr_tracker_t * tc, const char * data, int len )
|
||||||
{
|
{
|
||||||
if( tc->stopped || 0 < tc->newPort )
|
if( tc->stopped || 0 < tc->newPort )
|
||||||
{
|
{
|
||||||
tc->lastAttempt = TC_ATTEMPT_OK;
|
tc->lastError = 0;
|
||||||
goto nodict;
|
goto nodict;
|
||||||
}
|
}
|
||||||
tr_err( "Tracker: no valid dictionary found in answer" );
|
tr_err( "Tracker: no valid dictionary found in answer" );
|
||||||
tc->lastAttempt = TC_ATTEMPT_ERROR;
|
tc->lastError = 1;
|
||||||
|
tc->allUnreachIfError = 0;
|
||||||
failureAnnouncing( tc );
|
failureAnnouncing( tc );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -715,7 +728,8 @@ static void readAnswer( tr_tracker_t * tc, const char * data, int len )
|
||||||
tor->error |= TR_ETRACKER;
|
tor->error |= TR_ETRACKER;
|
||||||
snprintf( tor->trackerError, sizeof( tor->trackerError ),
|
snprintf( tor->trackerError, sizeof( tor->trackerError ),
|
||||||
"%s", bePeers->val.s.s );
|
"%s", bePeers->val.s.s );
|
||||||
tc->lastAttempt = TC_ATTEMPT_ERROR;
|
tc->lastError = 1;
|
||||||
|
tc->allUnreachIfError = 0;
|
||||||
failureAnnouncing( tc );
|
failureAnnouncing( tc );
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -731,7 +745,8 @@ static void readAnswer( tr_tracker_t * tc, const char * data, int len )
|
||||||
}
|
}
|
||||||
|
|
||||||
tor->error &= ~TR_ETRACKER;
|
tor->error &= ~TR_ETRACKER;
|
||||||
tc->lastAttempt = TC_ATTEMPT_OK;
|
tc->lastError = 0;
|
||||||
|
tc->allUnreachIfError = 0;
|
||||||
|
|
||||||
/* Get the tracker interval, force to between
|
/* Get the tracker interval, force to between
|
||||||
10 sec and 5 mins */
|
10 sec and 5 mins */
|
||||||
|
|
Loading…
Reference in New Issue