Changeset 1131


Ignore:
Timestamp:
Nov 24, 2006, 9:22:05 PM (15 years ago)
Author:
livings124
Message:

support scrape minimum announce interval and scrape the normal amount if last scrape failed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/scrape/libtransmission/tracker.c

    r1130 r1131  
    3636
    3737    int            interval;
     38    int            scrapeInterval;
    3839    int            seeders;
    3940    int            leechers;
     
    4243    uint64_t       dateTry;
    4344    uint64_t       dateOk;
    44     uint64_t       dateTryScrape;
    45     uint64_t       dateOkScrape;
     45    uint64_t       dateScrape;
     46    int            lastScrapeFailed;
    4647
    4748#define TC_ATTEMPT_NOREACH 1
     
    7374
    7475    tc->interval = 300;
     76    tc->scrapeInterval = 600;
    7577    tc->seeders  = -1;
    7678    tc->leechers = -1;
     
    7880    tc->lastAttempt = TC_ATTEMPT_NOREACH;
    7981    tc->scrapeNeeded = 0;
     82   
     83    tc->lastScrapeFailed = 0;
    8084
    8185    tc->bindPort = *(tor->bindPort);
     
    147151
    148152    uint64_t now = tr_date();
    149     uint64_t interval = 1000 * 300;
    150    
    151     if (!tc->scrapeNeeded)
     153    uint64_t interval = 1000 * tc->scrapeInterval;
     154   
     155    // scrape half as often if there is no need to
     156    if (!tc->scrapeNeeded && !tc->lastScrapeFailed)
    152157    {
    153158        interval *= 2;
    154159    }
    155160   
    156     return now > tc->dateOkScrape + interval;
     161    return now > tc->dateScrape + interval;
    157162}
    158163
     
    216221            return 0;
    217222        }
    218         tc->dateTryScrape = tr_date();
     223        tc->dateScrape = tr_date();
    219224        tc->httpScrape = tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
    220225                            "%s%sinfo_hash=%s", tor->scrape, strchr( tor->scrape, '?' ) ?
     
    235240                tr_fdSocketClosed( tor->fdlimit, 1 );
    236241                tc->httpScrape    = NULL;
    237                 tc->dateTryScrape = tr_date();
     242                tc->lastScrapeFailed = 1;
    238243                return 0;
    239244
     
    284289    /* Even if we have connected recently, reconnect right now */
    285290    tc->dateTry = 0;
    286     tc->dateTryScrape = 0;
    287291}
    288292
     
    591595    benc_val_t scrape, * val1, * val2;
    592596
    593     tc->dateTryScrape = tr_date();
    594597    code = tr_httpResponseCode( data, len );
    595598    if( 0 > code )
     
    597600        /* We don't have a valid HTTP status line */
    598601        tr_inf( "Scrape: invalid HTTP status line" );
     602        tc->lastScrapeFailed = 1;
    599603        return;
    600604    }
     
    604608        /* we didn't get a 2xx status code */
    605609        tr_err( "Scrape: invalid HTTP status code: %i", code );
     610        tc->lastScrapeFailed = 1;
    606611        return;
    607612    }
     
    612617    {
    613618        tr_err( "Scrape: could not find end of HTTP headers" );
    614         tc->lastAttempt = TC_ATTEMPT_NOREACH;
    615         return;
    616     }
    617     tc->dateOkScrape = tr_date();
     619        tc->lastScrapeFailed = 1;
     620        return;
     621    }
     622   
     623    tc->lastScrapeFailed = 0;
    618624   
    619625    bodylen = len - (body - (const uint8_t*)data);
     
    662668    tc->leechers = val2->val.i;
    663669   
     670    val2 = tr_bencDictFind( val1, "flags" );
     671    if (val2)
     672    {
     673        val2 = tr_bencDictFind( val2, "min_request_interval" );
     674        if (val2)
     675        {
     676            tc->scrapeInterval = val2->val.i;
     677        }
     678    }
     679   
    664680    tc->hasManyPeers = tc->seeders + tc->leechers >= 50;
    665681   
Note: See TracChangeset for help on using the changeset viewer.