Changeset 1147


Ignore:
Timestamp:
Dec 1, 2006, 9:03:19 PM (15 years ago)
Author:
joshe
Message:

Minor style cleanups, no functional changes.

Location:
branches/scrape/libtransmission
Files:
2 edited

Legend:

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

    r1145 r1147  
    7070    tr_tracker_t * tc;
    7171
    72     tc           = calloc( 1, sizeof( tr_tracker_t ) );
    73     tc->tor      = tor;
    74     tc->id       = tor->id;
    75 
    76     tc->started  = 1;
    77 
    78     tc->interval = 300;
    79     tc->minInterval = 0;
     72    tc                 = calloc( 1, sizeof( tr_tracker_t ) );
     73    tc->tor            = tor;
     74    tc->id             = tor->id;
     75
     76    tc->started        = 1;
     77
     78    tc->interval       = 300;
    8079    tc->scrapeInterval = 600;
    81     tc->seeders  = -1;
    82     tc->leechers = -1;
    83     tc->downloaded  = -1;
    84 
    85     tc->lastAttempt = TC_ATTEMPT_NOREACH;
    86     tc->scrapeNeeded = 0;
    87    
    88     tc->lastScrapeFailed = 0;
    89 
    90     tc->bindPort = *(tor->bindPort);
    91     tc->newPort  = -1;
     80    tc->seeders        = -1;
     81    tc->leechers       = -1;
     82    tc->downloaded     = -1;
     83
     84    tc->lastAttempt    = TC_ATTEMPT_NOREACH;
     85
     86    tc->bindPort       = *(tor->bindPort);
     87    tc->newPort        = -1;
    9288
    9389    return tc;
     
    9793{
    9894    uint64_t now = tr_date();
    99    
     95
    10096    /* Unreachable tracker, try 10 seconds before trying again */
    10197    if( tc->lastAttempt == TC_ATTEMPT_NOREACH &&
     
    158154static int shouldScrape( tr_tracker_t * tc )
    159155{
    160     // scrape not supported
     156    uint64_t now, interval;
     157
     158    /* scrape not supported */
    161159    if( !tc->tor->scrape[0] )
    162160    {
     
    164162    }
    165163
    166     uint64_t now = tr_date();
    167     uint64_t interval = 1000 * MAX(tc->scrapeInterval, 60);
    168    
    169     // scrape half as often if there is no need to
    170     if (!tc->scrapeNeeded && !tc->lastScrapeFailed)
     164    now      = tr_date();
     165    interval = 1000 * MAX( tc->scrapeInterval, 60 );
     166
     167    /* scrape half as often if there is no need to */
     168    if( !tc->scrapeNeeded && !tc->lastScrapeFailed )
    171169    {
    172170        interval *= 2;
    173171    }
    174    
     172
    175173    return now > tc->dateScrape + interval;
    176174}
     
    205203                      "getting peers" ) ) ) );
    206204    }
    207    
     205
    208206    if( NULL != tc->http )
    209207    {
     
    240238                    inf->trackerAddress, inf->trackerPort );
    241239    }
    242    
     240
    243241    if( NULL != tc->httpScrape )
    244242    {
     
    251249                tr_httpClose( tc->httpScrape );
    252250                tr_fdSocketClosed( tor->fdlimit, 1 );
    253                 tc->httpScrape    = NULL;
     251                tc->httpScrape       = NULL;
    254252                tc->lastScrapeFailed = 1;
    255253                return 0;
     
    326324    uint64_t       down;
    327325    uint64_t       up;
    328     char         * start;
     326    char           start;
    329327    int            numwant = 50;
    330328
    331329    down = tor->downloadedCur;
    332     up = tor->uploadedCur;
     330    up   = tor->uploadedCur;
    333331    if( tc->started )
    334332    {
    335333        event = "&event=started";
    336         down = up = 0;
    337        
     334        down  = 0;
     335        up    = 0;
     336
    338337        if( 0 < tc->newPort )
    339338        {
    340339            tc->bindPort = tc->newPort;
    341             tc->newPort = -1;
     340            tc->newPort  = -1;
    342341        }
    343342    }
     
    356355    }
    357356
    358     if( NULL == strchr( inf->trackerAnnounce, '?' ) )
    359     {
    360         start = "?";
    361     }
    362     else
    363     {
    364         start = "&";
    365     }
    366 
    367     left = tr_cpLeftBytes( tor->completion );
    368    
     357    start     = ( strchr( inf->trackerAnnounce, '?' ) ? '&' : '?' );
     358    left      = tr_cpLeftBytes( tor->completion );
    369359    trackerid = tor->trackerid ? ( "&trackerid=%s", tor->trackerid ) : "";
    370360
    371     return tr_httpClient( TR_HTTP_GET, inf->trackerAddress,
    372                           inf->trackerPort,
    373                           "%s%s"
     361    return tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
     362                          "%s%c"
    374363                          "info_hash=%s&"
    375364                          "peer_id=%s&"
     
    383372                          "%s"
    384373                          "%s",
    385                           inf->trackerAnnounce, start, tor->escapedHashString, tc->id,
    386                           tc->bindPort, up, down, left, numwant, tor->key, trackerid, event );
     374                          inf->trackerAnnounce, start, tor->escapedHashString,
     375                          tc->id, tc->bindPort, up, down, left, numwant,
     376                          tor->key, trackerid, event );
    387377}
    388378
     
    392382    tr_info_t    * inf = &tor->info;
    393383
     384    char           start;
     385
     386    start = ( strchr( tor->scrape, '?' ) ? '&' : '?' );
     387
    394388    return tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
    395                           "%s%sinfo_hash=%s", tor->scrape, strchr( tor->scrape, '?' ) ?
    396                           "&" : "?", tor->escapedHashString );
     389                          "%s%c"
     390                          "info_hash=%s",
     391                          tor->scrape, start, tor->escapedHashString );
    397392}
    398393
     
    405400    benc_val_t * bePeers, * beFoo;
    406401    const uint8_t * body;
    407     int bodylen;
    408     int shouldfree;
     402    int bodylen, shouldfree, scrapeNeeded;
    409403
    410404    tc->dateTry = tr_date();
     
    434428        return;
    435429    }
    436     bodylen = len - (body - (const uint8_t*)data);
     430    bodylen = len - ( body - (const uint8_t*)data );
    437431
    438432    /* Find and load the dictionary */
     
    476470    /* Get the tracker interval, force to between
    477471       10 sec and 5 mins */
    478     if( !( beFoo = tr_bencDictFind( &beAll, "interval" ) ) ||
    479         !( beFoo->type & TYPE_INT ) )
     472    beFoo = tr_bencDictFind( &beAll, "interval" );
     473    if( !beFoo || TYPE_INT != beFoo->type )
    480474    {
    481475        tr_err( "Tracker: no 'interval' field" );
     
    485479    tc->interval = beFoo->val.i;
    486480    tr_inf( "Tracker: interval = %d seconds", tc->interval );
    487    
     481
    488482    tc->interval = MIN( tc->interval, 300 );
    489483    tc->interval = MAX( 10, tc->interval );
    490    
     484
    491485    /* Get the tracker minimum interval, force to between
    492486       10 sec and 5 mins  */
    493     if( ( beFoo = tr_bencDictFind( &beAll, "min interval" ) ) &&
    494         ( beFoo->type & TYPE_INT ) )
     487    beFoo = tr_bencDictFind( &beAll, "min interval" );
     488    if( beFoo && TYPE_INT == beFoo->type )
    495489    {
    496490        tc->minInterval = beFoo->val.i;
    497491        tr_inf( "Tracker: min interval = %d seconds", tc->minInterval );
    498        
     492
    499493        tc->minInterval = MIN( tc->minInterval, 300 );
    500494        tc->minInterval = MAX( 10, tc->minInterval );
    501        
    502         if( tc->interval < tc->minInterval)
     495
     496        if( tc->interval < tc->minInterval )
    503497        {
    504498            tc->interval = tc->minInterval;
    505             tr_inf( "Tracker: 'interval' less than 'min interval', use 'min interval'" );
     499            tr_inf( "Tracker: 'interval' less than 'min interval', "
     500                    "using 'min interval'" );
    506501        }
    507502    }
     
    512507    }
    513508
    514     int scrapeNeeded = 0;
    515     if( ( beFoo = tr_bencDictFind( &beAll, "complete" ) ) &&
    516         ( beFoo->type & TYPE_INT ) )
     509    scrapeNeeded = 0;
     510    beFoo = tr_bencDictFind( &beAll, "complete" );
     511    if( beFoo && TYPE_INT == beFoo->type )
    517512    {
    518513        tc->seeders = beFoo->val.i;
     
    522517        scrapeNeeded = 1;
    523518    }
    524     if( ( beFoo = tr_bencDictFind( &beAll, "incomplete" ) ) &&
    525         ( beFoo->type & TYPE_INT ) )
     519
     520    beFoo = tr_bencDictFind( &beAll, "incomplete" );
     521    if( beFoo && TYPE_INT == beFoo->type )
    526522    {
    527523        tc->leechers = beFoo->val.i;
     
    531527        scrapeNeeded = 1;
    532528    }
     529
    533530    tc->scrapeNeeded = scrapeNeeded;
    534    
    535531    if( !scrapeNeeded )
    536         tc->hasManyPeers = tc->seeders + tc->leechers >= 50;
    537    
    538     if( beFoo = tr_bencDictFind( &beAll, "tracker id" ) )
    539     {
    540         if( tor->trackerid )
    541             free( tor->trackerid );
     532    {
     533        tc->hasManyPeers = ( tc->seeders + tc->leechers >= 50 );
     534    }
     535
     536    beFoo = tr_bencDictFind( &beAll, "tracker id" );
     537    if( beFoo )
     538    {
     539        free( tor->trackerid );
    542540        tor->trackerid = strdup( beFoo->val.s.s );
    543         tr_inf( "Tracker: tracker id = %s", tor->trackerid);
    544     }
    545    
    546     if( !( bePeers = tr_bencDictFind( &beAll, "peers" ) ) )
     541        tr_inf( "Tracker: tracker id = %s", tor->trackerid );
     542    }
     543
     544    bePeers = tr_bencDictFind( &beAll, "peers" );
     545    if( !bePeers )
    547546    {
    548547        if( tc->stopped || 0 < tc->newPort )
     
    635634static void readScrapeAnswer( tr_tracker_t * tc, const char * data, int len )
    636635{
    637     tr_torrent_t * tor = tc->tor;
    638     int i;
    639636    int code;
    640637    const uint8_t * body;
     
    667664        return;
    668665    }
    669    
     666
    670667    tc->lastScrapeFailed = 0;
    671    
    672     bodylen = len - (body - (const uint8_t*)data);
     668    bodylen = len - ( body - (const uint8_t*)data );
    673669
    674670    for( ii = 0; ii < bodylen - 8; ii++ )
     
    726722   
    727723    val2 = tr_bencDictFind( val1, "flags" );
    728     if (val2)
     724    if( val2 )
    729725    {
    730726        val2 = tr_bencDictFind( val2, "min_request_interval" );
    731         if (val2)
     727        if( val2 )
    732728        {
    733729            tc->scrapeInterval = val2->val.i;
     
    735731    }
    736732   
    737     tc->hasManyPeers = tc->seeders + tc->leechers >= 50;
     733    tc->hasManyPeers = ( tc->seeders + tc->leechers >= 50 );
    738734   
    739735    tr_bencFree( &scrape );
     
    770766int tr_trackerScrape( tr_torrent_t * tor, int * s, int * l, int * d )
    771767{
    772     tr_info_t    * inf = &tor->info;
    773768    tr_tracker_t * tc;
    774769    tr_http_t    * http;
     
    794789            case TR_ERROR:
    795790                goto scrapeDone;
    796                 break;
    797791
    798792            case TR_OK:
    799793                readScrapeAnswer( tc, data, len );
    800794                goto scrapeDone;
    801                 break;
    802795        }
    803796    }
  • branches/scrape/libtransmission/tracker.h

    r1143 r1147  
    5757int tr_trackerDownloaded( tr_tracker_t * tc );
    5858
    59 
     59/***********************************************************************
     60 * tr_trackerScrape
     61 ***********************************************************************
     62 * Attempt a blocking scrape and return the seeders, leechers, and
     63 * completed downloads if successful.
     64 **********************************************************************/
    6065int tr_trackerScrape( tr_torrent_t * tor, int * s, int * l, int * d );
    6166
Note: See TracChangeset for help on using the changeset viewer.