Changeset 1517


Ignore:
Timestamp:
Feb 27, 2007, 4:00:38 AM (15 years ago)
Author:
joshe
Message:

Use a tr_tracker_info_t * directly in tr_info_t and tr_tracker_t.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/beos/TRInfoWindow.cpp

    r1505 r1517  
    3939        txtView->MakeEditable(false);
    4040       
    41         BString strTracker(status->trackerAddress);
    42         strTracker << ":" << status->trackerPort;
     41        BString strTracker(status->tracker->address);
     42        strTracker << ":" << status->tracker->port;
    4343
    4444        BString strPieceSize("");
     
    5656        BString infoStr("");
    5757        infoStr << "Tracker: " << strTracker << "\n"
    58                 << "Announce: " << status->trackerAnnounce << "\n"
     58                << "Announce: " << status->tracker->announce << "\n"
    5959                << "Piece Size: " << strPieceSize << "\n"
    6060                << "Pieces: " << info->pieceCount << "\n"
  • trunk/cli/transmissioncli.c

    r1496 r1517  
    148148        printf( "\n" );
    149149        printf( "tracker:  %s:%d\n",
    150                 s->trackerAddress, s->trackerPort );
    151         printf( "announce: %s\n", s->trackerAnnounce );
     150                s->tracker->address, s->tracker->port );
     151        printf( "announce: %s\n", s->tracker->announce );
    152152        printf( "size:     %"PRIu64" (%"PRIu64" * %d + %"PRIu64")\n",
    153153                info->totalSize, info->totalSize / info->pieceSize,
  • trunk/gtk/dialogs.c

    r1516 r1517  
    279279  INFOSEP(table, ii);
    280280
    281   if(80 == sb->trackerPort)
     281  if(80 == sb->tracker->port)
    282282    INFOLINEA(table, ii, _("Tracker:"), g_strdup_printf("http://%s",
    283               sb->trackerAddress));
     283              sb->tracker->address));
    284284  else
    285285    INFOLINEA(table, ii, _("Tracker:"), g_strdup_printf("http://%s:%i",
    286               sb->trackerAddress, sb->trackerPort));
    287   INFOLINE(table, ii, _("Announce:"), sb->trackerAnnounce);
     286              sb->tracker->address, sb->tracker->port));
     287  INFOLINE(table, ii, _("Announce:"), sb->tracker->announce);
    288288  INFOLINEA(table, ii, _("Piece Size:"), readablesize(in->pieceSize));
    289289  INFOLINEF(table, ii, "%i", _("Pieces:"), in->pieceCount);
  • trunk/libtransmission/metainfo.c

    r1440 r1517  
    3131 **********************************************************************/
    3232static int getannounce( tr_info_t * inf, benc_val_t * meta );
     33static char * announceToScrape( const char * announce );
    3334#define strcatUTF8( dst, src) _strcatUTF8( (dst), sizeof( dst ) - 1, (src) )
    3435static void _strcatUTF8( char *, int, char * );
     
    294295            free( inf->trackerList[ii].list[jj].address );
    295296            free( inf->trackerList[ii].list[jj].announce );
     297            free( inf->trackerList[ii].list[jj].scrape );
    296298        }
    297299        free( inf->trackerList[ii].list );
     
    348350                sublist[random].port     = port;
    349351                sublist[random].announce = announce;
     352                sublist[random].scrape   = announceToScrape( announce );
    350353                subcount++;
    351354            }
     
    415418        sublist[0].port           = port;
    416419        sublist[0].announce       = announce;
     420        sublist[0].scrape         = announceToScrape( announce );
    417421        inf->trackerList          = calloc( sizeof( inf->trackerList[0] ), 1 );
    418422        inf->trackerList[0].list  = sublist;
     
    422426
    423427    return 0;
     428}
     429
     430static char * announceToScrape( const char * announce )
     431{   
     432    char old[]  = "announce";
     433    int  oldlen = 8;
     434    char new[]  = "scrape";
     435    int  newlen = 6;
     436    char * slash, * scrape;
     437   
     438    slash = strrchr( announce, '/' );
     439    if( NULL == slash )
     440    {
     441        return NULL;
     442    }
     443    slash++;
     444   
     445    if( 0 != strncmp( slash, old, oldlen ) )
     446    {
     447        return NULL;
     448    }
     449
     450    scrape = calloc( strlen( announce ) - oldlen + newlen + 1, 1 );
     451    strncat( scrape, announce, slash - announce );
     452    strcat(  scrape, new );
     453    strcat(  scrape, slash + oldlen );
     454
     455    return scrape;
    424456}
    425457
  • trunk/libtransmission/torrent.c

    r1510 r1517  
    320320    tc = tor->tracker;
    321321    s->cannotConnect = tr_trackerCannotConnect( tc );
    322    
    323     if( tc )
    324     {
    325         s->trackerAddress  = tr_trackerAddress(  tc );
    326         s->trackerPort     = tr_trackerPort(     tc );
    327         s->trackerAnnounce = tr_trackerAnnounce( tc );
    328     }
    329     else
    330     {
    331         s->trackerAddress  = inf->trackerList[0].list[0].address;
    332         s->trackerPort     = inf->trackerList[0].list[0].port;
    333         s->trackerAnnounce = inf->trackerList[0].list[0].announce;
    334     }
     322    s->tracker = ( tc ? tr_trackerGet( tc ) : &inf->trackerList[0].list[0] );
    335323
    336324    s->peersTotal       = 0;
  • trunk/libtransmission/tracker.c

    r1439 r1517  
    3939    char         * id;
    4040    char         * trackerid;
    41    
    42     const char   * trackerAddress;
    43     int            trackerPort;
    44     const char   * trackerAnnounce;
    45     char           trackerScrape[MAX_PATH_LENGTH];
    46     int            trackerCanScrape;
     41
     42    tr_tracker_info_t * info;
    4743   
    4844    tr_announce_list_ptr_t ** trackerAnnounceListPtr;
     
    9086};
    9187
    92 static int         announceToScrape ( char * announce, char * scrape );
    9388static void        setAnnounce      ( tr_tracker_t * tc, tr_announce_list_ptr_t * announceItem );
    9489static void        failureAnnouncing( tr_tracker_t * tc );
     
    151146}
    152147
    153 static int announceToScrape( char * announce, char * scrape )
    154 {   
    155     char * slash, * nextSlash;
    156     int pre, post;
    157    
    158     slash = strchr( announce, '/' );
    159     while( ( nextSlash = strchr( slash + 1, '/' ) ) )
    160     {
    161         slash = nextSlash;
    162     }
    163     slash++;
    164    
    165     if( !strncmp( slash, "announce", 8 ) )
    166     {
    167         pre  = (long) slash - (long) announce;
    168         post = strlen( announce ) - pre - 8;
    169         memcpy( scrape, announce, pre );
    170         sprintf( &scrape[pre], "scrape" );
    171         memcpy( &scrape[pre+6], &announce[pre+8], post );
    172         scrape[pre+6+post] = 0;
    173        
    174         return 1;
    175     }
    176     else
    177     {
    178         return 0;
    179     }
    180 }
    181 
    182148static void setAnnounce( tr_tracker_t * tc, tr_announce_list_ptr_t * announcePtr )
    183149{
    184     tr_tracker_info_t * announceItem = announcePtr->item;
    185    
    186     tc->trackerAddress  = announceItem->address;
    187     tc->trackerPort     = announceItem->port;
    188     tc->trackerAnnounce = announceItem->announce;
    189    
    190     tc->trackerCanScrape = announceToScrape( announceItem->announce, tc->trackerScrape );
    191    
     150    tc->info = announcePtr->item;
     151
    192152    /* Needs a new scrape */
    193153    tc->seeders = -1;
     
    301261
    302262    /* in process of changing tracker or scrape not supported */
    303     if( tc->shouldChangeAnnounce != TC_CHANGE_NO || !tc->trackerCanScrape || tc->stopped )
     263    if( tc->shouldChangeAnnounce != TC_CHANGE_NO ||
     264        NULL == tc->info->scrape || tc->stopped )
    304265    {
    305266        return 0;
     
    364325            if( tc->shouldChangeAnnounce == TC_CHANGE_NEXT )
    365326            {
    366                 tr_inf( "Tracker: failed to connect to %s, trying next", tc->trackerAddress );
     327                tr_inf( "Tracker: failed to connect to %s, trying next",
     328                        tc->info->address );
    367329               
    368330                if( tc->announceTierLast + 1 < inf->trackerList[tc->announceTier].count )
     
    415377
    416378            tr_inf( "Tracker: connecting to %s:%d (%s)",
    417                     tc->trackerAddress, tc->trackerPort,
     379                    tc->info->address, tc->info->port,
    418380                    tc->started ? "sending 'started'" :
    419381                    ( tc->completed ? "sending 'completed'" :
     
    472434        {
    473435            tc->httpScrape = getScrapeQuery( tc );
    474             tr_inf( "Scrape: sent HTTP request to %s:%d%s", tc->trackerAddress, tc->trackerPort, tc->trackerScrape );
     436            tr_inf( "Scrape: sent HTTP request to %s:%d%s",
     437                    tc->info->address, tc->info->port, tc->info->scrape );
    475438        }
    476439    }
     
    593556    }
    594557
    595     start = ( strchr( tc->trackerAnnounce, '?' ) ? '&' : '?' );
     558    start = ( strchr( tc->info->announce, '?' ) ? '&' : '?' );
    596559    left  = tr_cpLeftBytes( tor->completion );
    597560
    598     return tr_httpClient( TR_HTTP_GET, tc->trackerAddress, tc->trackerPort,
     561    return tr_httpClient( TR_HTTP_GET, tc->info->address, tc->info->port,
    599562                          "%s%c"
    600563                          "info_hash=%s&"
     
    609572                          "%s%s"
    610573                          "%s",
    611                           tc->trackerAnnounce, start, tor->escapedHashString,
     574                          tc->info->announce, start, tor->escapedHashString,
    612575                          tc->id, tc->publicPort, up, down, left, numwant,
    613576                          tor->key, idparam, trackerid, event );
     
    619582    char           start;
    620583
    621     start = ( strchr( tc->trackerScrape, '?' ) ? '&' : '?' );
    622 
    623     return tr_httpClient( TR_HTTP_GET, tc->trackerAddress, tc->trackerPort,
     584    start = ( strchr( tc->info->scrape, '?' ) ? '&' : '?' );
     585
     586    return tr_httpClient( TR_HTTP_GET, tc->info->address, tc->info->port,
    624587                          "%s%c"
    625588                          "info_hash=%s",
    626                           tc->trackerScrape, start, tor->escapedHashString );
     589                          tc->info->scrape, start, tor->escapedHashString );
    627590}
    628591
     
    952915        tr_err( "Scrape: invalid HTTP status code: %i", code );
    953916        if( TR_HTTP_STATUS_FAIL_CLIENT( code ) )
    954             tc->trackerCanScrape = 0;
     917        {
     918            free( tc->info->scrape );
     919            tc->info->scrape = NULL;
     920        }
    955921        tc->lastScrapeFailed = 1;
    956922        return;
     
    10561022}
    10571023
    1058 const char * tr_trackerAddress( tr_tracker_t * tc )
     1024tr_tracker_info_t * tr_trackerGet( tr_tracker_t * tc )
    10591025{
    10601026    if( !tc )
     
    10621028        return NULL;
    10631029    }
    1064     return tc->trackerAddress;
    1065 }
    1066 
    1067 int tr_trackerPort( tr_tracker_t * tc )
    1068 {
    1069     if( !tc )
    1070     {
    1071         return 0;
    1072     }
    1073     return tc->trackerPort;
    1074 }
    1075 
    1076 const char * tr_trackerAnnounce( tr_tracker_t * tc )
    1077 {
    1078     if( !tc )
    1079     {
    1080         return NULL;
    1081     }
    1082     return tc->trackerAnnounce;
     1030    return tc->info;
    10831031}
    10841032
     
    11031051    tc = tr_trackerInit( tor );
    11041052
    1105     if( !tc->trackerCanScrape )
     1053    if( NULL == tc->info->scrape )
    11061054    {
    11071055        return 1;
  • trunk/libtransmission/tracker.h

    r1439 r1517  
    6060int tr_trackerDownloaded( tr_tracker_t * tc );
    6161
    62 const char * tr_trackerAddress ( tr_tracker_t * tc );
    63 int          tr_trackerPort    ( tr_tracker_t * tc );
    64 const char * tr_trackerAnnounce( tr_tracker_t * tc );
     62/***********************************************************************
     63 * tr_trackerGet
     64 ***********************************************************************
     65 * Return the tracker currently in use.
     66 **********************************************************************/
     67tr_tracker_info_t * tr_trackerGet( tr_tracker_t * tc );
    6568
    6669int tr_trackerCannotConnect( tr_tracker_t * tc );
  • trunk/libtransmission/transmission.h

    r1508 r1517  
    391391    char                errorString[128];
    392392    int                 cannotConnect;
    393    
    394     const char        * trackerAddress;
    395     int                 trackerPort;
    396     const char        * trackerAnnounce;
     393
     394    tr_tracker_info_t * tracker;
    397395
    398396    float               progress;
     
    446444    int    port;
    447445    char * announce;
     446    char * scrape;
    448447};
    449448
  • trunk/macosx/Torrent.m

    r1514 r1517  
    782782- (NSString *) trackerAddress
    783783{
    784     return [NSString stringWithFormat: @"http://%s:%d", fStat->trackerAddress, fStat->trackerPort];
     784    return [NSString stringWithFormat: @"http://%s:%d", fStat->tracker->address, fStat->tracker->port];
    785785}
    786786
    787787- (NSString *) trackerAddressAnnounce
    788788{
    789     return [NSString stringWithUTF8String: fStat->trackerAnnounce];
     789    return [NSString stringWithUTF8String: fStat->tracker->announce];
    790790}
    791791
Note: See TracChangeset for help on using the changeset viewer.