Changeset 3439


Ignore:
Timestamp:
Oct 17, 2007, 1:17:30 AM (14 years ago)
Author:
charles
Message:

Follow uTorrent 1.8's behavior of allowing a manual reannounce every max(60 seconds, min_interval) where min_interval is from the tracker.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tracker.c

    r3369 r3439  
    3636#define MINUTES_TO_MSEC(N) ((N) * 60 * 1000)
    3737
    38 /* manual announces via "update tracker" are allowed this frequently */
    39 #define MANUAL_ANNOUNCE_INTERVAL_MSEC (MINUTES_TO_MSEC(10))
     38/* we follow uTorrent 1.8's lead of allowing a manual reannounce
     39 * every MAX( 60 seconds, min_interval ) */
     40#define DEFAULT_MANUAL_ANNOUNCE_INTERVAL_SEC (60)
    4041
    4142/* unless the tracker tells us otherwise, rescrape this frequently */
    42 #define DEFAULT_SCRAPE_INTERVAL_MSEC (MINUTES_TO_MSEC(15))
    43 
    44 /* unless the tracker tells us otherwise, reannounce this frequently */
    45 #define DEFAULT_ANNOUNCE_INTERVAL_MSEC (MINUTES_TO_MSEC(20))
     43#define DEFAULT_SCRAPE_INTERVAL_SEC (60*15)
     44
     45/* unless the tracker tells us otherwise, this is the announce interval */
     46#define DEFAULT_ANNOUNCE_INTERVAL_SEC (240)
     47
     48/* unless the tracker tells us otherwise, this is the announce min_interval */
     49#define DEFAULT_MIN_ANNOUNCE_INTERVAL_SEC (30)
    4650
    4751/* this is how long we'll leave a request hanging before timeout */
     
    7074
    7175    /* these are set from the latest scrape or tracker response */
    72     int announceIntervalMsec;
    73     int minAnnounceIntervalMsec;
    74     int scrapeIntervalMsec;
     76    int announceIntervalSec;
     77    int minAnnounceIntervalSec;
     78    int scrapeIntervalSec;
    7579
    7680    /* calculated when we get fewer scrapes
     
    126130    char * lastRequest;
    127131
    128     uint64_t manualAnnounceAllowedAt;
     132    time_t manualAnnounceAllowedAt;
    129133
    130134    Tracker * tracker;
     
    285289        t->handle = tor->handle;
    286290        t->primaryAddress = tr_strdup( info->primaryAddress );
    287         t->scrapeIntervalMsec      = DEFAULT_SCRAPE_INTERVAL_MSEC;
    288         t->announceIntervalMsec    = DEFAULT_ANNOUNCE_INTERVAL_MSEC;
    289         t->minAnnounceIntervalMsec = DEFAULT_ANNOUNCE_INTERVAL_MSEC;
     291        t->scrapeIntervalSec       = DEFAULT_SCRAPE_INTERVAL_SEC;
     292        t->announceIntervalSec     = DEFAULT_ANNOUNCE_INTERVAL_SEC;
     293        t->minAnnounceIntervalSec  = DEFAULT_MIN_ANNOUNCE_INTERVAL_SEC;
    290294        t->multiscrapeMax = INT_MAX;
    291295        t->torrents    = tr_ptrArrayNew( );
     
    640644                if(( flags = tr_bencDictFind( tordict, "flags" )))
    641645                    if(( tmp = tr_bencDictFind( flags, "min_request_interval")))
    642                         t->scrapeIntervalMsec = tmp->val.i * 1000;
     646                        t->scrapeIntervalSec = tmp->val.i;
    643647
    644648                tr_ptrArrayRemoveSorted( t->scraping, tor, torrentCompare );
    645649
    646650                tr_timerFree( &tor->scrapeTimer );
    647                 tor->scrapeTimer = tr_timerNew( t->handle, onTorrentScrapeNow, torrentHashNew(tor), t->scrapeIntervalMsec );
     651                tor->scrapeTimer = tr_timerNew( t->handle, onTorrentScrapeNow, torrentHashNew(tor), t->scrapeIntervalSec*1000 );
    648652                tr_dbg( "Torrent '%s' scrape successful."
    649653                        "  Rescraping in %d seconds",
    650                         tor->name, t->scrapeIntervalMsec/1000 );
     654                        tor->name, t->scrapeIntervalSec );
    651655            }
    652656
     
    859863
    860864    if( minimum > 0 )
    861         t->minAnnounceIntervalMsec = minimum;
     865        t->minAnnounceIntervalSec = minimum;
    862866
    863867    if( interval > 0 )
    864         t->announceIntervalMsec = interval;
    865 
    866     if( t->announceIntervalMsec < t->minAnnounceIntervalMsec )
    867         t->announceIntervalMsec = t->minAnnounceIntervalMsec;
     868        t->announceIntervalSec = interval;
     869
     870    if( t->announceIntervalSec < t->minAnnounceIntervalSec )
     871        t->announceIntervalSec = t->minAnnounceIntervalSec;
    868872}
    869873
     
    873877onStoppedResponse( struct evhttp_request * req UNUSED, void * handle UNUSED )
    874878{
     879}
     880
     881static int
     882getManualReannounceIntervalSecs( const Tracker * tracker )
     883{
     884    return tracker
     885        ? MAX( tracker->minAnnounceIntervalSec, DEFAULT_MANUAL_ANNOUNCE_INTERVAL_SEC )
     886        : DEFAULT_MANUAL_ANNOUNCE_INTERVAL_SEC;
    875887}
    876888
     
    881893    Torrent * tor;
    882894    int isStopped;
    883     int reannounceInterval;
     895    int reannounceIntervalSecs;
    884896    tr_torrent * t;
    885897
     
    953965        }
    954966
    955         reannounceInterval = isStopped
     967        reannounceIntervalSecs = isStopped
    956968            ? -1
    957             : tor->tracker->announceIntervalMsec;
     969            : tor->tracker->announceIntervalSec;
    958970
    959971        if( bencLoaded )
     
    968980                tor->name );
    969981
    970         reannounceInterval = 30 * 1000;
     982        reannounceIntervalSecs = 30;
    971983    }
    972984
     
    977989    }
    978990
    979     if( !isStopped && reannounceInterval>0 ) {
     991    if( !isStopped && reannounceIntervalSecs>0 ) {
    980992        tr_dbg( "torrent '%s' reannouncing in %d seconds",
    981                 tor->name, (reannounceInterval/1000) );
     993                tor->name, (reannounceIntervalSecs) );
    982994        tr_timerFree( &tor->reannounceTimer );
    983         tor->reannounceTimer = tr_timerNew( tor->tracker->handle, onReannounceNow, tor, reannounceInterval );
    984         tor->manualAnnounceAllowedAt
    985                            = tr_date() + MANUAL_ANNOUNCE_INTERVAL_MSEC;
     995        tor->reannounceTimer = tr_timerNew( tor->tracker->handle, onReannounceNow, tor, reannounceIntervalSecs*1000 );
     996        tor->manualAnnounceAllowedAt = time(NULL) + getManualReannounceIntervalSecs( tor->tracker );
    986997    }
    987998}
     
    10751086       and it's been long enough since the last announce */
    10761087    return ( torrentIsRunning( tor ) )
    1077         && ( tr_date() >= tor->manualAnnounceAllowedAt );
     1088        && ( time(NULL) >= tor->manualAnnounceAllowedAt );
    10781089}
    10791090
Note: See TracChangeset for help on using the changeset viewer.