Changeset 1127


Ignore:
Timestamp:
Nov 24, 2006, 6:27:53 PM (15 years ago)
Author:
livings124
Message:

first attempt at getting scrape to work...doesn't seem to currently work

Location:
branches/scrape
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/scrape/Transmission.xcodeproj/project.pbxproj

    r1125 r1127  
    264264                4DCCBB3C09C3D71100D3CABF /* TorrentCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = TorrentCell.m; path = macosx/TorrentCell.m; sourceTree = "<group>"; };
    265265                4DCCBB3D09C3D71100D3CABF /* TorrentCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = TorrentCell.h; path = macosx/TorrentCell.h; sourceTree = "<group>"; };
    266                 4DDBB71909E16BAE00284745 /* transmissioncli */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = transmissioncli; sourceTree = BUILT_PRODUCTS_DIR; };
     266                4DDBB71909E16BAE00284745 /* transmissioncli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = transmissioncli; sourceTree = BUILT_PRODUCTS_DIR; };
    267267                4DDBB71B09E16BF100284745 /* transmissioncli.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = transmissioncli.c; path = cli/transmissioncli.c; sourceTree = "<group>"; };
    268268                4DDFDD20099A5D8E00189D81 /* DownloadBadge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = DownloadBadge.png; path = macosx/Images/DownloadBadge.png; sourceTree = "<group>"; };
     
    284284                4DFBC2DE09C0970D00D5C571 /* Torrent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Torrent.m; path = macosx/Torrent.m; sourceTree = "<group>"; };
    285285                8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; name = Info.plist; path = macosx/Info.plist; sourceTree = "<group>"; };
    286                 8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; };
     286                8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; };
    287287                A200B8390A2263BA007BBB1E /* InfoWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InfoWindowController.h; path = macosx/InfoWindowController.h; sourceTree = "<group>"; };
    288288                A200B83A0A2263BA007BBB1E /* InfoWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InfoWindowController.m; path = macosx/InfoWindowController.m; sourceTree = "<group>"; };
  • branches/scrape/libtransmission/tracker.c

    r1059 r1127  
    4242    uint64_t       dateTry;
    4343    uint64_t       dateOk;
     44    uint64_t       dateTryScrape;
     45    uint64_t       dateOkScrape;
    4446
    4547#define TC_ATTEMPT_NOREACH 1
     
    4749#define TC_ATTEMPT_OK      4
    4850    char           lastAttempt;
     51    int            scrapeNeeded;
    4952
    5053    tr_http_t    * http;
     54    tr_http_t    * httpScrape;
    5155
    5256    int            bindPort;
     
    5660static tr_http_t * getQuery   ( tr_tracker_t * tc );
    5761static void        readAnswer ( tr_tracker_t * tc, const char *, int );
     62static void readScrapeAnswer( tr_tracker_t * tc, const char * data, int len );
    5863
    5964tr_tracker_t * tr_trackerInit( tr_torrent_t * tor )
     
    7277
    7378    tc->lastAttempt = TC_ATTEMPT_NOREACH;
     79    tc->scrapeNeeded = 0;
    7480
    7581    tc->bindPort = *(tor->bindPort);
     
    8288{
    8389    uint64_t now = tr_date();
    84 
     90   
    8591    /* Unreachable tracker, try 10 seconds before trying again */
    8692    if( tc->lastAttempt == TC_ATTEMPT_NOREACH &&
     
    130136
    131137    return 0;
     138}
     139
     140static int shouldScrape( tr_tracker_t * tc )
     141{
     142    // scrape not supported
     143    if( !tc->tor->scrape[0] )
     144    {
     145        return 0;
     146    }
     147
     148    uint64_t now = tr_date();
     149    uint64_t interval = 1000 * 300;
     150   
     151    if (!tc->scrapeNeeded)
     152        interval *= 2.0;
     153   
     154    return now > tc->dateOkScrape + interval;
    132155}
    133156
     
    161184                      "getting peers" ) ) ) );
    162185    }
    163 
     186   
    164187    if( NULL != tc->http )
    165188    {
     
    167190        {
    168191            case TR_WAIT:
    169                 return 0;
     192                break;
    170193
    171194            case TR_ERROR:
     
    174197                tc->http    = NULL;
    175198                tc->dateTry = tr_date();
    176                 return 0;
     199                break;
    177200
    178201            case TR_OK:
     
    184207        }
    185208    }
     209   
     210    if( ( NULL == tc->httpScrape ) && shouldScrape( tc ) )
     211    {
     212        if( tr_fdSocketWillCreate( tor->fdlimit, 1 ) )
     213        {
     214            return 0;
     215        }
     216        tc->dateTryScrape = tr_date();
     217        tc->httpScrape = tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
     218                          "%s?info_hash=%s", tor->scrape, tor->hashString );
     219        tr_inf( "Scrape: sent http request to %s:%d",
     220                    inf->trackerAddress, inf->trackerPort );
     221    }
     222   
     223    if( NULL != tc->httpScrape )
     224    {
     225        switch( tr_httpPulse( tc->httpScrape, &data, &len ) )
     226        {
     227            case TR_WAIT:
     228                return 0;
     229
     230            case TR_ERROR:
     231                tr_httpClose( tc->httpScrape );
     232                tr_fdSocketClosed( tor->fdlimit, 1 );
     233                tc->httpScrape    = NULL;
     234                tc->dateTryScrape = tr_date();
     235                return 0;
     236
     237            case TR_OK:
     238                readScrapeAnswer( tc, data, len );
     239                tr_httpClose( tc->httpScrape );
     240                tc->httpScrape = NULL;
     241                tr_fdSocketClosed( tor->fdlimit, 1 );
     242                break;
     243        }
     244    }
    186245
    187246    return 0;
     
    207266        tr_fdSocketClosed( tor->fdlimit, 1 );
    208267    }
     268    if( NULL != tc->httpScrape )
     269    {
     270        /* If we are already sendy a query at the moment, we need to
     271           reconnect */
     272        tr_httpClose( tc->httpScrape );
     273        tc->httpScrape = NULL;
     274        tr_fdSocketClosed( tor->fdlimit, 1 );
     275    }
    209276
    210277    tc->started   = 0;
     
    214281    /* Even if we have connected recently, reconnect right now */
    215282    tc->dateTry = 0;
     283    tc->dateTryScrape = 0;
    216284}
    217285
     
    225293        tr_fdSocketClosed( tor->fdlimit, 1 );
    226294    }
     295    if( NULL != tc->httpScrape )
     296    {
     297        tr_httpClose( tc->httpScrape );
     298        tr_fdSocketClosed( tor->fdlimit, 1 );
     299    }
     300   
    227301    free( tc );
    228302}
     
    390464    }
    391465
     466    int scrapeNeeded = 0;
    392467    if( ( beFoo = tr_bencDictFind( &beAll, "complete" ) ) &&
    393468        ( beFoo->type & TYPE_INT ) )
     
    395470        tc->seeders = beFoo->val.i;
    396471    }
     472    else
     473    {
     474        scrapeNeeded = 1;
     475    }
    397476    if( ( beFoo = tr_bencDictFind( &beAll, "incomplete" ) ) &&
    398477        ( beFoo->type & TYPE_INT ) )
     
    400479        tc->leechers = beFoo->val.i;
    401480    }
     481    else
     482    {
     483        scrapeNeeded = 1;
     484    }
     485    tc->scrapeNeeded = scrapeNeeded;
     486   
    402487    if( tc->seeders + tc->leechers >= 50 )
    403488    {
     
    494579}
    495580
    496 int tr_trackerScrape( tr_torrent_t * tor, int * seeders, int * leechers )
    497 {
    498     tr_info_t * inf = &tor->info;
    499 
    500     tr_http_t  * http;
    501     const char * data, * body;
    502     int          datalen, bodylen;
    503     int          code, ii;
    504     benc_val_t   scrape, * val1, * val2;
    505 
    506     if( !tor->scrape[0] )
    507     {
    508         /* scrape not supported */
    509         return 1;
    510     }
    511 
    512     http = tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
    513                           "%s?info_hash=%s", tor->scrape, tor->hashString );
    514 
    515     data = NULL;
    516     while( NULL == data )
    517     {
    518         switch( tr_httpPulse( http, &data, &datalen ) )
    519         {
    520             case TR_WAIT:
    521                 break;
    522 
    523             case TR_ERROR:
    524                 tr_httpClose( http );
    525                 return 1;
    526 
    527             case TR_OK:
    528                 if( NULL == data || 0 >= datalen )
    529                 {
    530                     tr_httpClose( http );
    531                     return 1;
    532                 }
    533                 break;
    534         }
    535         tr_wait( 10 );
    536     }
    537 
    538     code = tr_httpResponseCode( data, datalen );
     581static void readScrapeAnswer( tr_tracker_t * tc, const char * data, int len )
     582{
     583    tr_torrent_t * tor = tc->tor;
     584    int i;
     585    int code;
     586    const uint8_t * body;
     587    int bodylen, ii;
     588    benc_val_t scrape, * val1, * val2;
     589
     590    tc->dateTryScrape = tr_date();
     591    code = tr_httpResponseCode( data, len );
     592    if( 0 > code )
     593    {
     594        /* We don't have a valid HTTP status line */
     595        tr_inf( "Scrape: invalid HTTP status line" );
     596        return;
     597    }
     598
    539599    if( !TR_HTTP_STATUS_OK( code ) )
    540600    {
    541         tr_httpClose( http );
    542         return 1;
    543     }
    544 
    545     body = tr_httpParse( data, datalen , NULL );
     601        /* we didn't get a 2xx status code */
     602        tr_err( "Scrape: invalid HTTP status code: %i", code );
     603        return;
     604    }
     605
     606    /* find the end of the http headers */
     607    body = (uint8_t *) tr_httpParse( data, len, NULL );
    546608    if( NULL == body )
    547609    {
    548         tr_httpClose( http );
    549         return 1;
    550     }
    551     bodylen = datalen - ( body - data );
     610        tr_err( "Tracker: could not find end of HTTP headers" );
     611        tc->lastAttempt = TC_ATTEMPT_NOREACH;
     612        return;
     613    }
     614    tc->dateOkScrape = tr_date();
     615   
     616    bodylen = len - (body - (const uint8_t*)data);
    552617
    553618    for( ii = 0; ii < bodylen - 8; ii++ )
     
    560625    if( ii >= bodylen - 8 )
    561626    {
    562         tr_httpClose( http );
    563         return 1;
     627        return;
    564628    }
    565629    if( tr_bencLoad( body + ii, bodylen - ii, &scrape, NULL ) )
    566630    {
    567         tr_httpClose( http );
    568         return 1;
     631        return;
    569632    }
    570633
     
    573636    {
    574637        tr_bencFree( &scrape );
    575         tr_httpClose( http );
    576         return 1;
     638        return;
    577639    }
    578640    val1 = &val1->val.l.vals[1];
     
    580642    {
    581643        tr_bencFree( &scrape );
    582         tr_httpClose( http );
    583         return 1;
     644        return;
    584645    }
    585646    val2 = tr_bencDictFind( val1, "complete" );
     
    587648    {
    588649        tr_bencFree( &scrape );
    589         tr_httpClose( http );
    590         return 1;
    591     }
    592     *seeders = val2->val.i;
     650        return;
     651    }
     652    tc->seeders = val2->val.i;
    593653    val2 = tr_bencDictFind( val1, "incomplete" );
    594654    if( !val2 )
    595655    {
    596656        tr_bencFree( &scrape );
    597         tr_httpClose( http );
    598         return 1;
    599     }
    600     *leechers = val2->val.i;
     657        return;
     658    }
     659    tc->leechers = val2->val.i;
     660   
     661    tc->hasManyPeers = tc->seeders + tc->leechers >= 50;
     662   
    601663    tr_bencFree( &scrape );
    602     tr_httpClose( http );
    603 
    604     return 0;
    605664}
    606665
  • branches/scrape/libtransmission/tracker.h

    r261 r1127  
    4949int                         tr_trackerLeechers ( tr_tracker_t * );
    5050
    51 int            tr_trackerScrape    ( tr_torrent_t *, int *, int * );
    52 
    5351#endif
  • branches/scrape/libtransmission/transmission.c

    r1064 r1127  
    369369 * tr_torrentScrape
    370370 **********************************************************************/
    371 int tr_torrentScrape( tr_torrent_t * tor, int * s, int * l )
     371/*int tr_torrentScrape( tr_torrent_t * tor, int * s, int * l )
    372372{
    373373    return tr_trackerScrape( tor, s, l );
    374 }
     374}*/
    375375
    376376void tr_torrentSetFolder( tr_torrent_t * tor, const char * path )
  • branches/scrape/libtransmission/transmission.h

    r1119 r1127  
    211211 * before returning.
    212212 **********************************************************************/
    213 int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
     213//int tr_torrentScrape( tr_torrent_t *, int * s, int * l );
    214214
    215215/***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.