Changeset 1173


Ignore:
Timestamp:
Dec 8, 2006, 6:02:00 AM (15 years ago)
Author:
livings124
Message:

rework storage of announce addresses

Location:
branches/multitracker
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/multitracker/libtransmission/metainfo.c

    r1172 r1173  
    301301    }
    302302   
    303     tr_setTorrentAnnounce( inf, inf->trackerAnnounceList[0] );
    304    
    305303    free( address );
    306304    free( announce );
  • branches/multitracker/libtransmission/tracker.c

    r1167 r1173  
    2525#include "transmission.h"
    2626
     27typedef struct tr_announce_list_ptr_s tr_announce_list_ptr_t;
     28struct tr_announce_list_ptr_s
     29{
     30    tr_announce_list_item_t * item;
     31    tr_announce_list_ptr_t * nextItem;
     32};
     33
    2734struct tr_tracker_s
    2835{
     
    3138    char         * id;
    3239    char         * trackerid;
     40   
     41    char           trackerAddress[256];
     42    int            trackerPort;
     43    char           trackerAnnounce[MAX_PATH_LENGTH];
     44    char           trackerScrape[MAX_PATH_LENGTH];
     45    int            trackerCanScrape;
     46   
     47    tr_announce_list_ptr_t ** trackerAnnounceListPtr;
     48   
     49    int            shouldChangeAnnounce;
     50    int            announceTier;
     51    int            announceTierLast;
    3352
    3453    char           started;
     
    4867    uint64_t       dateScrape;
    4968    int            lastScrapeFailed;
    50    
    51     int            shouldChangeAnnounce;
    52     int            announceTier;
    53     int            announceTierLast;
    5469
    5570#define TC_ATTEMPT_NOREACH 1
     
    6681};
    6782
    68 static void        setAnnounce      ( tr_tracker_t * tc, tr_announce_list_item_t * announceItem );
     83static int         announceToScrape ( char * announce, char * scrape );
     84static void        setAnnounce      ( tr_tracker_t * tc, tr_announce_list_ptr_t * announceItem );
    6985static void        failureAnnouncing( tr_tracker_t * tc );
    7086static tr_http_t * getQuery         ( tr_tracker_t * tc );
     
    7793{
    7894    tr_tracker_t * tc;
     95    tr_announce_list_item_t * announceItem;
     96    tr_announce_list_ptr_t * announcePtr, * prevAnnouncePtr;
     97    int i;
    7998
    8099    tc                 = calloc( 1, sizeof( tr_tracker_t ) );
     
    94113    tc->bindPort       = *(tor->bindPort);
    95114    tc->newPort        = -1;
     115   
     116    tc->trackerAnnounceListPtr = calloc( sizeof( int ), tor->info.trackerAnnounceTiers );
     117    for( i = 0; i < tor->info.trackerAnnounceTiers; i++ )
     118    {
     119        tc->trackerAnnounceListPtr[i] = calloc( 1, sizeof( tr_announce_list_ptr_t ) );
     120        tc->trackerAnnounceListPtr[i]->item = tor->info.trackerAnnounceList[i];
     121        prevAnnouncePtr = tc->trackerAnnounceListPtr[i];
     122       
     123        for( announceItem = tor->info.trackerAnnounceList[i]->nextItem; announceItem != NULL;
     124                announceItem = announceItem->nextItem )
     125        {
     126            announcePtr = calloc( 1, sizeof( tr_announce_list_ptr_t ) );
     127           
     128            announcePtr->item = announceItem;
     129            prevAnnouncePtr->nextItem = announcePtr;
     130            prevAnnouncePtr = announcePtr;
     131        }
     132    }
     133   
     134    setAnnounce( tc, tc->trackerAnnounceListPtr[0] );
    96135
    97136    return tc;
    98137}
    99138
    100 static void setAnnounce( tr_tracker_t * tc, tr_announce_list_item_t * announceItem )
    101 {
    102     tr_setTorrentAnnounce( &tc->tor->info, announceItem);
     139static int announceToScrape( char * announce, char * scrape )
     140{   
     141    char * slash, * nextSlash;
     142    int pre, post;
     143   
     144    slash = strchr( announce, '/' );
     145    while( ( nextSlash = strchr( slash + 1, '/' ) ) )
     146    {
     147        slash = nextSlash;
     148    }
     149    slash++;
     150   
     151    if( !strncmp( slash, "announce", 8 ) )
     152    {
     153        pre  = (long) slash - (long) announce;
     154        post = strlen( announce ) - pre - 8;
     155        memcpy( scrape, announce, pre );
     156        sprintf( &scrape[pre], "scrape" );
     157        memcpy( &scrape[pre+6], &announce[pre+8], post );
     158        scrape[pre+6+post] = 0;
     159       
     160        return 1;
     161    }
     162    else
     163    {
     164        return 0;
     165    }
     166}
     167
     168static void setAnnounce( tr_tracker_t * tc, tr_announce_list_ptr_t * announcePtr )
     169{
     170    tr_announce_list_item_t * announceItem = announcePtr->item;
     171   
     172    snprintf( tc->trackerAddress, 256, "%s", announceItem->address );
     173    tc->trackerPort = announceItem->port;
     174    snprintf( tc->trackerAnnounce, MAX_PATH_LENGTH, "%s", announceItem->announce );
     175   
     176    tc->trackerCanScrape = announceToScrape( announceItem->announce, tc->trackerScrape );
    103177   
    104178    /* Needs a new scrape */
     
    115189   
    116190    int i;
    117     tr_announce_list_item_t * announceItem;
     191    tr_announce_list_ptr_t * announcePtr;
    118192   
    119193    tc->shouldChangeAnnounce = 1;
     
    126200   
    127201    /* If there are no more trackers don't try to change the announce */
    128     announceItem = inf->trackerAnnounceList[tc->announceTier];
     202    announcePtr = tc->trackerAnnounceListPtr[tc->announceTier];
    129203    for( i = 0; i <= tc->announceTierLast; i++ )
    130204    {
    131         announceItem = announceItem->nextItem;
    132     }
    133    
    134     if( announceItem == NULL )
     205        announcePtr = announcePtr->nextItem;
     206    }
     207   
     208    if( announcePtr == NULL )
    135209    {
    136210        tc->shouldChangeAnnounce = 0;
     
    219293
    220294    /* in process of changing tracker or scrape not supported */
    221     if( tc->shouldChangeAnnounce || !inf->trackerCanScrape )
     295    if( tc->shouldChangeAnnounce || !tc->trackerCanScrape )
    222296    {
    223297        return 0;
     
    247321    const char   * data;
    248322    int            len, i;
    249     tr_announce_list_item_t * announceItem, * prevAnnounceItem;
     323    tr_announce_list_ptr_t * announcePtr, * prevAnnouncePtr;
    250324
    251325    if( ( NULL == tc->http ) && shouldConnect( tc ) )
     
    253327        if( tc->shouldChangeAnnounce )
    254328        {
    255             tr_inf( "Tracker: %s failed to connect, trying next", inf->trackerAddress );
     329            tr_inf( "Tracker: %s failed to connect, trying next", tc->trackerAddress );
    256330           
    257             announceItem = inf->trackerAnnounceList[tc->announceTier];
     331            announcePtr = tc->trackerAnnounceListPtr[tc->announceTier];
    258332            for( i = 0; i <= tc->announceTierLast; i++ )
    259333            {
    260                 prevAnnounceItem = announceItem;
    261                 announceItem = announceItem->nextItem;
     334                prevAnnouncePtr = announcePtr;
     335                announcePtr = announcePtr->nextItem;
    262336            }
    263337           
    264             if( announceItem != NULL )
     338            if( announcePtr != NULL )
    265339            {
    266340                tc->announceTierLast++;
    267341               
    268342                /* Move address to front of tier in announce list */
    269                 prevAnnounceItem->nextItem = announceItem->nextItem;
    270                 announceItem->nextItem = inf->trackerAnnounceList[tc->announceTier];
    271                 inf->trackerAnnounceList[tc->announceTier] = announceItem;
     343                prevAnnouncePtr->nextItem = announcePtr->nextItem;
     344                announcePtr->nextItem =  tc->trackerAnnounceListPtr[tc->announceTier];
     345                tc->trackerAnnounceListPtr[tc->announceTier] = announcePtr;
    272346            }
    273347            else
     
    277351            }
    278352           
    279             tr_inf( "Tracker: tracker address set to %s", inf->trackerAnnounceList[tc->announceTier]->address );
    280             setAnnounce( tc, inf->trackerAnnounceList[tc->announceTier] );
     353            tr_inf( "Tracker: tracker address set to %s", tc->trackerAnnounceListPtr[tc->announceTier]->item->address );
     354            setAnnounce( tc, tc->trackerAnnounceListPtr[tc->announceTier] );
    281355            tc->shouldChangeAnnounce = 0;
    282356        }
     
    285359            if( tc->announceTier != 0 )
    286360            {
    287                 setAnnounce( tc, inf->trackerAnnounceList[0] );
     361                setAnnounce( tc, tc->trackerAnnounceListPtr[0] );
    288362                tc->announceTier = 0;
    289363            }
     
    299373
    300374        tr_inf( "Tracker: connecting to %s:%d (%s)",
    301                 inf->trackerAddress, inf->trackerPort,
     375                tc->trackerAddress, tc->trackerPort,
    302376                tc->started ? "sending 'started'" :
    303377                ( tc->completed ? "sending 'completed'" :
     
    349423        tc->dateScrape = tr_date();
    350424        tc->httpScrape = getScrapeQuery( tc );
    351         tr_inf( "Scrape: sent http request to %s:%d",
    352                     inf->trackerAddress, inf->trackerPort );
     425        tr_inf( "Scrape: sent http request to %s:%d", tc->trackerAddress, tc->trackerPort );
    353426    }
    354427
     
    460533    }
    461534
    462     start = ( strchr( inf->trackerAnnounce, '?' ) ? '&' : '?' );
     535    start = ( strchr( tc->trackerAnnounce, '?' ) ? '&' : '?' );
    463536    left  = tr_cpLeftBytes( tor->completion );
    464537
    465     return tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
     538    return tr_httpClient( TR_HTTP_GET, tc->trackerAddress, tc->trackerPort,
    466539                          "%s%c"
    467540                          "info_hash=%s&"
     
    476549                          "%s%s"
    477550                          "%s",
    478                           inf->trackerAnnounce, start, tor->escapedHashString,
     551                          tc->trackerAnnounce, start, tor->escapedHashString,
    479552                          tc->id, tc->bindPort, up, down, left, numwant,
    480553                          tor->key, idparam, trackerid, event );
     
    488561    char           start;
    489562
    490     start = ( strchr( inf->trackerScrape, '?' ) ? '&' : '?' );
    491 
    492     return tr_httpClient( TR_HTTP_GET, inf->trackerAddress, inf->trackerPort,
     563    start = ( strchr( tc->trackerScrape, '?' ) ? '&' : '?' );
     564
     565    return tr_httpClient( TR_HTTP_GET, tc->trackerAddress, tc->trackerPort,
    493566                          "%s%c"
    494567                          "info_hash=%s",
    495                           inf->trackerScrape, start, tor->escapedHashString );
     568                          tc->trackerScrape, start, tor->escapedHashString );
    496569}
    497570
     
    764837        tr_err( "Scrape: invalid HTTP status code: %i", code );
    765838        if( TR_HTTP_STATUS_FAIL_CLIENT( code ) )
    766             tc->tor->info.trackerCanScrape = 0;
     839            tc->trackerCanScrape = 0;
    767840        tc->lastScrapeFailed = 1;
    768841        return;
     
    870943    }
    871944    return tc->complete;
     945}
     946
     947char * tr_trackerAddress( tr_tracker_t * tc )
     948{
     949    if( !tc )
     950    {
     951        return NULL;
     952    }
     953    return tc->trackerAddress;
     954}
     955
     956int tr_trackerPort( tr_tracker_t * tc )
     957{
     958    if( !tc )
     959    {
     960        return 0;
     961    }
     962    return tc->trackerPort;
     963}
     964
     965char * tr_trackerAnnounce( tr_tracker_t * tc )
     966{
     967    if( !tc )
     968    {
     969        return NULL;
     970    }
     971    return tc->trackerAnnounce;
    872972}
    873973
     
    883983    int            ret;
    884984
    885     if( !inf->trackerCanScrape )
     985    if( !tc->trackerCanScrape )
    886986    {
    887987        return 1;
  • branches/multitracker/libtransmission/tracker.h

    r1149 r1173  
    5757int tr_trackerDownloaded( tr_tracker_t * tc );
    5858
     59char * tr_trackerAddress( tr_tracker_t * tc );
     60int tr_trackerPort( tr_tracker_t * tc );
     61char * tr_trackerAnnounce( tr_tracker_t * tc );
     62
    5963/***********************************************************************
    6064 * tr_trackerScrape
  • branches/multitracker/libtransmission/transmission.c

    r1169 r1173  
    3131                                       int flags, int * error );
    3232static void torrentReallyStop( tr_torrent_t * );
    33 static void  downloadLoop( void * );
    34 static void  acceptLoop( void * );
     33static void downloadLoop( void * );
     34static void acceptLoop( void * );
    3535static void acceptStop( tr_handle_t * h );
    36 static int announceToScrape( char * announce, char * scrape );
    3736
    3837/***********************************************************************
     
    477476    memcpy( s->trackerError, tor->trackerError,
    478477            sizeof( s->trackerError ) );
     478   
     479    if( tor->tracker )
     480    {
     481        snprintf( s->trackerAddress, 256, "%s", tr_trackerAddress( tor->tracker ) );
     482        s->trackerPort = tr_trackerPort( tor->tracker );
     483        snprintf( s->trackerAnnounce, MAX_PATH_LENGTH, "%s", tr_trackerAnnounce( tor->tracker ) );
     484    }
     485    else
     486    {
     487        snprintf( s->trackerAddress, 256, "%s", inf->trackerAnnounceList[0]->address );
     488        s->trackerPort = inf->trackerAnnounceList[0]->port;
     489        snprintf( s->trackerAnnounce, MAX_PATH_LENGTH, "%s", inf->trackerAnnounceList[0]->announce );
     490    }
    479491
    480492    s->peersTotal       = 0;
     
    522534    s->rateUpload = tr_rcRate( tor->upload );
    523535   
    524     s->seeders  = tr_trackerSeeders(tor->tracker);
    525     s->leechers = tr_trackerLeechers(tor->tracker);
    526     s->completedFromTracker = tr_trackerDownloaded(tor->tracker);
     536    s->seeders  = tr_trackerSeeders( tor->tracker );
     537    s->leechers = tr_trackerLeechers( tor->tracker );
     538    s->completedFromTracker = tr_trackerDownloaded( tor->tracker );
    527539
    528540    s->swarmspeed = tr_rcRate( tor->swarmspeed );
     
    544556
    545557    return s;
    546 }
    547 
    548 static int announceToScrape( char * announce, char * scrape )
    549 {   
    550     char * slash, * nextSlash;
    551     int pre, post;
    552    
    553     slash = strchr( announce, '/' );
    554     while( ( nextSlash = strchr( slash + 1, '/' ) ) )
    555     {
    556         slash = nextSlash;
    557     }
    558     slash++;
    559    
    560     if( !strncmp( slash, "announce", 8 ) )
    561     {
    562         pre  = (long) slash - (long) announce;
    563         post = strlen( announce ) - pre - 8;
    564         memcpy( scrape, announce, pre );
    565         sprintf( &scrape[pre], "scrape" );
    566         memcpy( &scrape[pre+6], &announce[pre+8], post );
    567         scrape[pre+6+post] = 0;
    568        
    569         return 1;
    570     }
    571     else
    572     {
    573         return 0;
    574     }
    575 }
    576 
    577 void tr_setTorrentAnnounce( tr_info_t * inf, tr_announce_list_item_t * announceItem )
    578 {
    579     snprintf( inf->trackerAddress, 256, "%s", announceItem->address );
    580     inf->trackerPort = announceItem->port;
    581     snprintf( inf->trackerAnnounce, MAX_PATH_LENGTH, "%s", announceItem->announce );
    582    
    583     inf->trackerCanScrape = announceToScrape( announceItem->announce, inf->trackerScrape );
    584558}
    585559
  • branches/multitracker/libtransmission/transmission.h

    r1161 r1173  
    260260
    261261/***********************************************************************
    262  * tr_setTorrentAnnounce
    263  ***********************************************************************/
    264 void tr_setTorrentAnnounce( tr_info_t * inf, tr_announce_list_item_t * announceItem );
    265 
    266 /***********************************************************************
    267262 * tr_torrentPeers
    268263 ***********************************************************************/
     
    321316#define TR_FSAVEPRIVATE 0x01    /* save a private copy of the torrent */
    322317    int         flags;
    323 
    324     /* Tracker info */
    325     char                trackerAddress[256];
    326     int                 trackerPort;
    327     char                trackerAnnounce[MAX_PATH_LENGTH];
    328     char                trackerScrape[MAX_PATH_LENGTH];
    329     int                 trackerCanScrape;
    330318   
    331     tr_announce_list_item_t  ** trackerAnnounceList;
    332     int                 trackerAnnounceTiers;
     319    tr_announce_list_item_t ** trackerAnnounceList;
     320    int         trackerAnnounceTiers;
    333321   
    334322    /* Torrent info */
     
    370358    int                 error;
    371359    char                trackerError[128];
     360   
     361    char                trackerAddress[256];
     362    int                 trackerPort;
     363    char                trackerAnnounce[MAX_PATH_LENGTH];
    372364
    373365    float               progress;
  • branches/multitracker/macosx/Torrent.m

    r1149 r1173  
    705705- (NSString *) tracker
    706706{
    707     return [NSString stringWithFormat: @"%s:%d", fInfo->trackerAddress, fInfo->trackerPort];
     707    return [NSString stringWithFormat: @"%s:%d", fStat->trackerAddress, fStat->trackerPort];
    708708}
    709709
    710710- (NSString *) announce
    711711{
    712     return [NSString stringWithUTF8String: fInfo->trackerAnnounce];
     712    return [NSString stringWithUTF8String: fStat->trackerAnnounce];
    713713}
    714714
Note: See TracChangeset for help on using the changeset viewer.