Changeset 10096


Ignore:
Timestamp:
Feb 5, 2010, 1:47:33 AM (12 years ago)
Author:
charles
Message:

(trunk libT) #2854 "Tracker did not respond" -- when calculating the interval to wait before retrying a failed announce or scrape, take into account that tracker's responses to other torrents' announces/scrapes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r10095 r10096  
    4848    DEFAULT_ANNOUNCE_MIN_INTERVAL_SEC = ( 60 * 2 ),
    4949
    50     /* how long to wait before a reannounce the first time we get an error */
    51     FIRST_ANNOUNCE_RETRY_INTERVAL_SEC = 30,
    52 
    53     /* how long to wait before a rescrape the first time we get an error */
    54     FIRST_SCRAPE_RETRY_INTERVAL_SEC = 120,
    55 
    5650    /* the length of the 'key' argument passed in tracker requests */
    5751    KEYLEN = 8,
     
    110104    /* the last time we sent an announce or scrape message */
    111105    time_t lastRequestTime;
     106
     107    /* the last successful announce/scrape time for this host */
     108    time_t lastSuccessfulRequest;
    112109}
    113110tr_host;
     
    376373    int announceIntervalSec;
    377374    int announceMinIntervalSec;
    378     int retryAnnounceIntervalSec;
    379     int retryScrapeIntervalSec;
    380375
    381376    int lastAnnouncePeerCount;
     
    432427    tier->announceIntervalSec = DEFAULT_ANNOUNCE_INTERVAL_SEC;
    433428    tier->announceMinIntervalSec = DEFAULT_ANNOUNCE_MIN_INTERVAL_SEC;
    434     tier->retryAnnounceIntervalSec = FIRST_ANNOUNCE_RETRY_INTERVAL_SEC;
    435     tier->retryScrapeIntervalSec = FIRST_SCRAPE_RETRY_INTERVAL_SEC;
    436429    tier->isAnnouncing = FALSE;
    437430    tier->isScraping = FALSE;
     
    974967
    975968static int
     969getRetryInterval( const tr_host * host )
     970{
     971    int interval;
     972    const int jitter = tr_cryptoWeakRandInt( 120 );
     973    const time_t timeSinceLastSuccess = tr_time() - host->lastSuccessfulRequest;
     974         if( timeSinceLastSuccess < 15*60 ) interval = 0;
     975    else if( timeSinceLastSuccess < 30*60 ) interval = 60*4;
     976    else if( timeSinceLastSuccess < 45*60 ) interval = 60*8;
     977    else if( timeSinceLastSuccess < 60*60 ) interval = 60*16;
     978    else                                    interval = 60*32;
     979    return interval + jitter;
     980}
     981
     982static int
    976983compareTiers( const void * va, const void * vb )
    977984{
     
    10861093        success = TRUE;
    10871094
    1088         tier->retryAnnounceIntervalSec = FIRST_ANNOUNCE_RETRY_INTERVAL_SEC;
    1089 
    10901095        if( tr_bencDictFindStr( &benc, "failure reason", &str ) )
    10911096        {
     
    12581263        if( responseCode == 0 )
    12591264        {
    1260             const int interval = tr_cryptoWeakRandInt( 120 );
     1265            const int interval = getRetryInterval( tier->currentTracker->host );
    12611266            dbgmsg( tier, "No response from tracker... retrying in %d seconds.", interval );
    12621267            tier->manualAnnounceAllowedAt = ~(time_t)0;
     
    13061311             * incapable of performing the request.  So we pause a bit and
    13071312             * try again. */
     1313            const int interval = getRetryInterval( tier->currentTracker->host );
    13081314            tier->manualAnnounceAllowedAt = ~(time_t)0;
    1309             tierSetNextAnnounce( tier, tier->announceEvent, now + tier->retryAnnounceIntervalSec );
    1310             tier->retryAnnounceIntervalSec *= 2;
     1315            tierSetNextAnnounce( tier, tier->announceEvent, now + interval );
    13111316        }
    13121317        else
     
    13221327
    13231328        if( success )
     1329        {
    13241330            tier->isRunning = data->isRunningOnSuccess;
     1331
     1332            if( tier->currentTracker->host )
     1333                tier->currentTracker->host->lastSuccessfulRequest = now;
     1334        }
    13251335
    13261336        if( !success )
     
    14351445                       "Scrape successful. Rescraping in %d seconds.",
    14361446                       tier->scrapeIntervalSec );
    1437 
    1438             tier->retryScrapeIntervalSec = FIRST_SCRAPE_RETRY_INTERVAL_SEC;
    14391447        }
    14401448    }
     
    15041512        else
    15051513        {
    1506             const int interval = tier->retryScrapeIntervalSec;
    1507             tier->retryScrapeIntervalSec *= 2;
     1514            const int interval = getRetryInterval( tier->currentTracker->host );
    15081515
    15091516            /* Don't retry on a 4xx.
     
    15261533
    15271534        tier->lastScrapeSucceeded = success;
     1535
     1536        if( success && tier->currentTracker->host )
     1537            tier->currentTracker->host->lastSuccessfulRequest = now;
    15281538    }
    15291539
Note: See TracChangeset for help on using the changeset viewer.