Changeset 1712 for branches/daemon


Ignore:
Timestamp:
Apr 14, 2007, 6:34:52 AM (15 years ago)
Author:
joshe
Message:

Merge libT revs 1616:1711 from trunk to daemon branch.

Location:
branches/daemon/libtransmission
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/daemon/libtransmission/clients.c

    r1610 r1712  
    123123                      charToInt( id[5] ), charToInt( id[6] ) );
    124124        }
    125         else if( !memcmp( &id[1], "ES", 2 ) )
     125        else if( !memcmp( &id[1], "TT", 2 ) )
     126        {
     127            asprintf( &ret, "TuoTu %c.%c.%c",
     128                      id[3], id[4], id[5] );
     129        }
     130                else if( !memcmp( &id[1], "ES", 2 ) )
    126131        {
    127132            asprintf( &ret, "Electric Sheep %c.%c.%c",
     
    173178                      id[3], id[4], id[5], id[6] );
    174179        }
     180                else if( !memcmp( &id[1], "BB", 2 ) )
     181        {
     182            asprintf( &ret, "BitBuddy %c.%c%c%c",
     183                      id[3], id[4], id[5], id[6] );
     184        }
     185                else if( !memcmp( &id[1], "qB", 2 ) )
     186        {
     187            asprintf( &ret, "qBittorrent %d.%d.%d",
     188                      charToInt( id[3] ), charToInt( id[4] ),
     189                      charToInt( id[5] ) );
     190        }
    175191       
    176192        if( ret )
     
    311327    if( !ret )
    312328    {
    313         if( id[0] != 0 )
     329        if( isprint( id[0] ) && isprint( id[1] ) && isprint( id[2] ) &&
     330            isprint( id[3] ) && isprint( id[4] ) && isprint( id[5] ) &&
     331            isprint( id[6] ) && isprint( id[7] ) )
    314332        {
    315333            asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)",
     
    318336        else
    319337        {
    320             asprintf( &ret, "unknown client" );
     338            asprintf( &ret, "unknown client (0x%02x%02x%02x%02x%02x%02x%02x%02x)",
     339                  id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
    321340        }
    322341    }
  • branches/daemon/libtransmission/fastresume.h

    r1603 r1712  
    3232 * the 5 bytes for the ID and length.
    3333 *
    34  * The name of the resume file is "resume.<hash>".
     34 * The name of the resume file is "resume.<hash>-<tag>", although
     35 * older files with a name of "resume.<hash>" will be recognized if
     36 * the former doesn't exist.
    3537 *
    3638 * All values are stored in the native endianness. Moving a
     
    6466  ( FR_MTIME_LEN( t ) + FR_BLOCK_BITFIELD_LEN( t ) + FR_SLOTPIECE_LEN( t ) )
    6567
    66 static char * fastResumeFileName( tr_io_t * io )
    67 {
    68     char * ret;
    69 
    70     asprintf( &ret, "%s/resume.%s", tr_getCacheDirectory(),
    71               io->tor->info.hashString );
    72 
    73     return ret;
     68static void
     69fastResumeFileName( char * path, size_t size, tr_torrent_t * tor, int tag )
     70{
     71    if( tag )
     72    {
     73        snprintf( path, size, "%s/resume.%s-%s", tr_getCacheDirectory(),
     74                  tor->info.hashString, tor->handle->tag );
     75    }
     76    else
     77    {
     78        snprintf( path, size, "%s/resume.%s", tr_getCacheDirectory(),
     79                  tor->info.hashString );
     80    }
    7481}
    7582
     
    122129{
    123130    tr_torrent_t * tor = io->tor;
    124    
     131
     132    char      path[MAX_PATH_LENGTH];
    125133    FILE    * file;
    126134    int       version = 1;
    127     char    * path;
    128135    uint8_t * buf;
    129136    uint64_t  total;
     
    141148
    142149    /* Create/overwrite the resume file */
    143     path = fastResumeFileName( io );
    144     if( !( file = fopen( path, "w" ) ) )
     150    fastResumeFileName( path, sizeof path, tor, 1 );
     151    file = fopen( path, "w" );
     152    if( NULL == file )
    145153    {
    146154        tr_err( "Could not open '%s' for writing", path );
    147155        free( buf );
    148         free( path );
    149156        return;
    150157    }
     
    185192
    186193    tr_dbg( "Resume file '%s' written", path );
    187     free( path );
    188194}
    189195
     
    293299{
    294300    tr_torrent_t * tor = io->tor;
    295    
     301
     302    char      path[MAX_PATH_LENGTH];
    296303    FILE    * file;
    297304    int       version = 0;
    298     char    * path;
    299305    uint8_t   id;
    300306    uint32_t  len;
     
    302308
    303309    /* Open resume file */
    304     path = fastResumeFileName( io );
    305     if( !( file = fopen( path, "r" ) ) )
    306     {
     310    fastResumeFileName( path, sizeof path, tor, 1 );
     311    file = fopen( path, "r" );
     312    if( NULL == file )
     313    {
     314        if( ENOENT == errno )
     315        {
     316            fastResumeFileName( path, sizeof path, tor, 0 );
     317            file = fopen( path, "r" );
     318            if( NULL != file )
     319            {
     320                goto good;
     321            }
     322            fastResumeFileName( path, sizeof path, tor, 1 );
     323        }
    307324        tr_inf( "Could not open '%s' for reading", path );
    308         free( path );
    309         return 1;
    310     }
     325        return 1;
     326    }
     327  good:
    311328    tr_dbg( "Resume file '%s' loaded", path );
    312     free( path );
    313329
    314330    /* Check format version */
  • branches/daemon/libtransmission/http.c

    r1579 r1712  
    450450    if( tr_sprintf( EXPANDBUF( http->header ), " HTTP/1.1" CR LF
    451451                    "Host: %s" CR LF
    452                     "User-Agent: %s/%d.%d" CR LF
     452                    "User-Agent: %s/%d.%d%d" CR LF
    453453                    "Connection: close" CR LF,
    454                     http->host, TR_NAME, VERSION_MAJOR, VERSION_MINOR ) )
     454                    http->host, TR_NAME, VERSION_MAJOR, VERSION_MINOR, VERSION_MAINTENANCE ) )
    455455    {
    456456        goto err;
  • branches/daemon/libtransmission/internal.h

    r1696 r1712  
    4242#include <string.h>
    4343#include <unistd.h>
     44#include <ctype.h>
    4445#include <errno.h>
    4546#include <limits.h>
     
    132133
    133134#include "trcompat.h"
     135#include "bsdqueue.h"
     136#include "bsdtree.h"
    134137#include "platform.h"
    135138#include "bencode.h"
  • branches/daemon/libtransmission/metainfo.c

    r1638 r1712  
    7878        savedname( inf->torrent, sizeof inf->torrent, inf->hashString, tag );
    7979    }
     80    else
     81    {
     82        snprintf( inf->torrent, sizeof inf->torrent, "%s", path );
     83    }
    8084
    8185    free( buf );
  • branches/daemon/libtransmission/peer.c

    r1614 r1712  
    136136    tr_ratecontrol_t  * download;
    137137    tr_ratecontrol_t  * upload;
     138
     139    char              * client;
    138140};
    139141
     
    219221    tr_rcClose( peer->download );
    220222    tr_rcClose( peer->upload );
     223    free( peer->client );
    221224    free( peer );
     225}
     226
     227const char *
     228tr_peerClient( tr_peer_t * peer )
     229{
     230    if( PEER_STATUS_HANDSHAKE >= peer->status )
     231    {
     232        return "not connected";
     233    }
     234
     235    if( NULL == peer->client )
     236    {
     237        peer->client = tr_clientForId( peer->id );
     238    }
     239
     240    return peer->client;
    222241}
    223242
  • branches/daemon/libtransmission/peer.h

    r1579 r1712  
    3232tr_peer_t * tr_peerInit          ( struct in_addr, in_port_t, int sock, int );
    3333void        tr_peerDestroy       ( tr_peer_t * );
     34const char *tr_peerClient        ( tr_peer_t * );
    3435void        tr_peerSetPrivate    ( tr_peer_t *, int );
    3536void        tr_peerSetTorrent    ( tr_peer_t *, tr_torrent_t * );
  • branches/daemon/libtransmission/peeraz.h

    r1612 r1712  
    360360    }
    361361
     362#if 0 /* ugh, we have to deal with encoding if we do this */
     363    /* get peer's client name */
     364    sub  = tr_bencDictFind( &val, "client" );
     365    sub2 = tr_bencDictFind( &val, "version" );
     366    if( NULL != sub  && TYPE_STR == sub->type &&
     367        NULL != sub2 && TYPE_STR == sub->type )
     368    {
     369        if( NULL == peer->client ||
     370            ( 0 != strncmp( peer->client, sub->val.s.s, sub->val.s.i ) ||
     371              ' ' != peer->client[sub->val.s.i] ||
     372              0 != strcmp( peer->client + sub->val.s.i + 1, sub2->val.s.s ) ) )
     373        {
     374            client = NULL;
     375            asprintf( &client, "%s %s", sub->val.s.s, sub2->val.s.s );
     376            if( NULL != client )
     377            {
     378                free( peer->client );
     379                peer->client = client;
     380            }
     381        }
     382    }
     383#endif
     384
    362385    /* get the peer's listening port */
    363386    sub = tr_bencDictFind( &val, "tcp_port" );
  • branches/daemon/libtransmission/peerext.h

    r1614 r1712  
    220220{
    221221    benc_val_t val, * sub;
    222     int dbgport, dbgpex;
     222    int        dbgport, dbgpex;
    223223
    224224    if( tr_bencLoad( buf, len, &val, NULL ) )
     
    251251    }
    252252
     253#if 0 /* ugh, we have to deal with encoding if we do this */
     254    /* get peer's client name */
     255    sub = tr_bencDictFind( &val, "v" );
     256    if( NULL != sub && TYPE_STR == sub->type &&
     257        ( NULL == peer->client || 0 != strcmp( sub->val.s.s, peer->client ) ) )
     258    {
     259        client = tr_bencStealStr( sub );
     260        if( NULL != client )
     261        {
     262            free( peer->client );
     263            peer->client = client;
     264        }
     265    }
     266#endif
     267
    253268    /* get peer's listening port */
    254269    sub = tr_bencDictFind( &val, "p" );
  • branches/daemon/libtransmission/peermessages.h

    r1600 r1712  
    335335 *
    336336 **********************************************************************/
    337 static void sendCancel( tr_torrent_t * tor, int block )
     337static void sendCancel( tr_peer_t * peer, int index, int begin,
     338                        int length )
     339{
     340    uint8_t * p;
     341    p = getMessagePointer( peer, 12, PEER_MSG_CANCEL );
     342
     343    TR_HTONL( index,  p     );
     344    TR_HTONL( begin,  p + 4 );
     345    TR_HTONL( length, p + 8 );
     346
     347    peer_dbg( "SEND cancel %d/%d (%d bytes)", index, begin, length );
     348}
     349
     350/***********************************************************************
     351 * broadcastCancel
     352 ***********************************************************************
     353 *
     354 **********************************************************************/
     355static void broadcastCancel( tr_torrent_t * tor, int index, int begin,
     356                             int length )
    338357{
    339358    int i, j;
    340     uint8_t * p;
    341359    tr_peer_t * peer;
    342360    tr_request_t * r;
     
    346364        peer = tor->peers[i];
    347365
    348         for( j = 1; j < peer->inRequestCount; j++ )
     366        for( j = 0; j < peer->inRequestCount; j++ )
    349367        {
    350368            r = &peer->inRequests[j];
    351369
    352             if( block != tr_block( r->index, r->begin ) )
     370            if( r->index != index || r->begin != begin ||
     371                r->length != length )
    353372            {
    354373                continue;
    355374            }
    356375
    357             p = getMessagePointer( peer, 12, PEER_MSG_CANCEL );
    358        
    359             /* Build the "cancel" message */
    360             TR_HTONL( r->index,  p     );
    361             TR_HTONL( r->begin,  p + 4 );
    362             TR_HTONL( r->length, p + 8 );
    363 
    364             peer_dbg( "SEND cancel %d/%d (%d bytes)",
    365                       r->index, r->begin, r->length );
     376            sendCancel( peer, index, begin, length );
    366377
    367378            (peer->inRequestCount)--;
     
    372383    }
    373384}
     385
     386
    374387
    375388/***********************************************************************
  • branches/daemon/libtransmission/peerparse.h

    r1600 r1712  
    5555            r = &peer->inRequests[i];
    5656            tr_cpDownloaderRem( tor->completion, tr_block(r->index,r->begin) );
     57
     58            /* According to the spec, all requests are dropped when you
     59               are choked, however some clients seem to remember those
     60               the next time they unchoke you. Also, if you get quickly
     61               choked and unchoked while you are sending requests, you
     62               can't know when the other peer received them and how it
     63               handled it.
     64               This can cause us to receive blocks multiple times and
     65               overdownload, so we send 'cancel' messages to try and
     66               reduce that. */
     67            sendCancel( peer, r->index, r->begin, r->length );
    5768        }
    5869        peer->inRequestCount = 0;
     
    243254}
    244255
    245 static inline void updateRequests( tr_torrent_t * tor, tr_peer_t * peer,
    246                                    int index, int begin )
     256static inline void updateRequests( tr_peer_t * peer, int index, int begin )
    247257{
    248258    tr_request_t * r;
    249     int i, j;
     259    int i;
    250260
    251261    /* Find this block in the requests list */
     
    259269    }
    260270
    261     /* Usually i should be 0, but some clients don't handle multiple
    262        request well and drop previous requests */
     271    /* Usually 'i' would be 0, but some clients don't handle multiple
     272       requests and drop previous requests, some other clients don't
     273       send blocks in the same order we sent the requests */
    263274    if( i < peer->inRequestCount )
    264275    {
    265         if( i > 0 )
    266         {
    267             peer_dbg( "not expecting this block yet (%d requests dropped)", i );
    268         }
    269         i++;
    270         for( j = 0; j < i; j++ )
    271         {
    272             r = &peer->inRequests[j];
    273             tr_cpDownloaderRem( tor->completion,
    274                                 tr_block( r->index, r->begin ) );
    275         }
    276         peer->inRequestCount -= i;
    277         memmove( &peer->inRequests[0], &peer->inRequests[i],
    278                  peer->inRequestCount * sizeof( tr_request_t ) );
     276        peer->inRequestCount--;
     277        memmove( &peer->inRequests[i], &peer->inRequests[i+1],
     278                 ( peer->inRequestCount - i ) * sizeof( tr_request_t ) );
    279279    }
    280280    else
     
    282282        /* Not in the list. Probably because of a cancel that arrived
    283283           too late */
     284        peer_dbg( "wasn't expecting this block" );
    284285    }
    285286}
     
    316317              index, begin, len - 8 );
    317318
    318     updateRequests( tor, peer, index, begin );
    319     tor->downloadedCur += len;
     319    updateRequests( peer, index, begin );
     320    tor->downloadedCur += len - 8;
    320321
    321322    /* Sanity checks */
     
    344345    }
    345346    tr_cpBlockAdd( tor->completion, block );
    346     sendCancel( tor, block );
     347    broadcastCancel( tor, index, begin, len - 8 );
    347348
    348349    if( !tr_cpPieceHasAllBlocks( tor->completion, index ) )
     
    541542static inline int parseBufHeader( tr_peer_t * peer )
    542543{
     544    static uint8_t badproto_http[] =
     545"HTTP/1.0 400 Nice try...\015\012"
     546"Content-type: text/plain\015\012"
     547"\015\012";
     548    static uint8_t badproto_tinfoil[] =
     549"This is not a rootkit or other backdoor, it's a BitTorrent\015\012"
     550"client. Really. Why should you be worried, can't you read this\015\012"
     551"reassuring message? Now just listen to this social engi, er, I mean,\015\012"
     552"completely truthful statement, and go about your business. Your box is\015\012"
     553"safe and completely impregnable, the marketing hype for your OS even\015\012"
     554"says so. You can believe everything you read. Now move along, nothing\015\012"
     555"to see here.";
    543556    uint8_t * p   = peer->buf;
    544557
     
    553566           already */
    554567        peer_dbg( "GET  handshake, invalid" );
    555         tr_netSend( peer->socket, (uint8_t *) "Nice try...\r\n", 13 );
     568        if( 0 == memcmp( p, "GET ", 4 ) || 0 == memcmp( p, "HEAD", 4 ) )
     569        {
     570            tr_netSend( peer->socket, badproto_http, sizeof badproto_http - 1 );
     571        }
     572        tr_netSend( peer->socket, badproto_tinfoil, sizeof badproto_tinfoil - 1 );
    556573        return TR_ERROR;
    557574    }
     
    585602    tr_info_t * inf = &tor->info;
    586603    int         ii;
    587     char      * client;
    588604
    589605    if( memcmp( &peer->buf[28], inf->hash, SHA_DIGEST_LENGTH ) )
     
    615631    }
    616632
    617     client = tr_clientForId( (uint8_t *) peer->id );
    618633    if( PEER_SUPPORTS_EXTENDED_MESSAGES( &peer->buf[20] ) )
    619634    {
     
    621636        peer->extStatus = EXTENDED_SUPPORTED;
    622637        peer_dbg( "GET  handshake, ok (%s) extended messaging supported",
    623                   client );
     638                  tr_peerClient( peer ) );
    624639    }
    625640    else if( PEER_SUPPORTS_AZUREUS_PROTOCOL( &peer->buf[20] ) )
     
    629644        peer->date    = tr_date();
    630645        peer_dbg( "GET  handshake, ok (%s) will use azureus protocol",
    631                   client );
     646                  tr_peerClient( peer ) );
    632647    }
    633648    else
    634649    {
    635650        peer->status = PEER_STATUS_CONNECTED;
    636         peer_dbg( "GET  handshake, ok (%s)", client );
    637     }
    638     free( client );
     651        peer_dbg( "GET  handshake, ok (%s)", tr_peerClient( peer ) );
     652    }
    639653
    640654    return TR_OK;
  • branches/daemon/libtransmission/torrent.c

    r1634 r1712  
    426426
    427427    s->progress = tr_cpCompletionAsFloat( tor->completion );
     428    s->left     = tr_cpLeftBytes( tor->completion );
    428429    if( tor->status & TR_STATUS_DOWNLOAD )
    429430    {
     
    498499            }
    499500           
    500             peers[i].client = tr_clientForId(tr_peerId(peer));
    501            
     501            peers[i].client        = tr_peerClient( peer );
    502502            peers[i].isConnected   = tr_peerIsConnected( peer );
    503503            peers[i].from          = tr_peerIsFrom( peer );
     
    522522}
    523523
    524 void tr_torrentPeersFree( tr_peer_stat_t * peers, int peerCount )
    525 {
    526     int i;
    527 
     524void tr_torrentPeersFree( tr_peer_stat_t * peers, int peerCount UNUSED )
     525{
    528526    if (peers == NULL)
    529527        return;
    530 
    531     for (i = 0; i < peerCount; i++)
    532         free( peers[i].client );
    533528
    534529    free( peers );
  • branches/daemon/libtransmission/tracker.c

    r1612 r1712  
    2626#include "shared.h"
    2727
    28 typedef struct tr_announce_list_ptr_s tr_announce_list_ptr_t;
    29 struct tr_announce_list_ptr_s
    30 {
    31     tr_tracker_info_t * item;
    32     tr_announce_list_ptr_t * nextItem;
     28struct tclist
     29{
     30    tr_tracker_info_t   * tl_inf;
     31    int                   tl_badscrape;
     32    SLIST_ENTRY( tclist ) next;
    3333};
     34SLIST_HEAD( tchead, tclist );
    3435
    3536struct tr_tracker_s
     
    4041    char         * trackerid;
    4142
    42     tr_tracker_info_t * info;
    43    
    44     tr_announce_list_ptr_t ** trackerAnnounceListPtr;
     43    struct tchead * tiers;
     44    size_t          tierCount;
     45    size_t          tierIndex;
     46    struct tclist * tcCur;
    4547
    4648#define TC_CHANGE_NO        0
     
    4951#define TC_CHANGE_REDIRECT  4
    5052    int            shouldChangeAnnounce;
    51     int            announceTier;
    52     int            announceTierLast;
    5353   
    5454    char         * redirectAddress;
     
    8686};
    8787
    88 static void        setAnnounce      ( tr_tracker_t * tc, tr_announce_list_ptr_t * announceItem );
     88static void        setAnnounce      ( tr_tracker_t * tc, struct tclist * new );
    8989static void        failureAnnouncing( tr_tracker_t * tc );
    9090static tr_http_t * getQuery         ( tr_tracker_t * tc );
     
    102102
    103103    tr_tracker_t * tc;
    104     tr_announce_list_ptr_t * prev, * cur;
    105     int ii, jj;
    106 
    107     tc                 = calloc( 1, sizeof( tr_tracker_t ) );
     104    struct tclist * item;
     105    size_t ii, jj;
     106
     107    tc = calloc( 1, sizeof *tc );
     108    if( NULL == tc )
     109    {
     110        return NULL;
     111    }
     112
    108113    tc->tor            = tor;
    109114    tc->id             = tor->id;
     
    121126
    122127    tc->publicPort     = tor->publicPort;
    123    
    124     tc->trackerAnnounceListPtr = calloc( sizeof( int ), inf->trackerTiers );
    125     for( ii = 0; ii < inf->trackerTiers; ii++ )
    126     {
    127         prev = NULL;
    128         for( jj = 0; jj < inf->trackerList[ii].count; jj++ )
    129         {
    130             cur = calloc( sizeof( tr_announce_list_ptr_t ), 1 );
    131             cur->item = &inf->trackerList[ii].list[jj];
    132             if( NULL == prev )
     128
     129    assert( 0 <= inf->trackerTiers );
     130    assert( sizeof( struct tchead ) == sizeof *tc->tiers );
     131    tc->tiers          = calloc( inf->trackerTiers, sizeof *tc->tiers );
     132    tc->tierCount      = inf->trackerTiers;
     133    for( ii = 0; tc->tierCount > ii; ii++ )
     134    {
     135        assert( 0 <= inf->trackerList[ii].count );
     136        SLIST_INIT( &tc->tiers[ii] );
     137        for( jj = inf->trackerList[ii].count; 0 < jj; jj-- )
     138        {
     139            item = calloc( 1, sizeof *item );
     140            if( NULL == item )
    133141            {
    134                 tc->trackerAnnounceListPtr[ii] = cur;
     142                tr_trackerClose( tc );
     143                return NULL;
    135144            }
    136             else
    137             {
    138                 prev->nextItem = cur;
    139             }
    140             prev = cur;
    141         }
    142     }
    143    
    144     setAnnounce( tc, tc->trackerAnnounceListPtr[0] );
     145            item->tl_inf = &inf->trackerList[ii].list[jj-1];
     146            SLIST_INSERT_HEAD( &tc->tiers[ii], item, next );
     147        }
     148    }
     149
     150    setAnnounce( tc, SLIST_FIRST( &tc->tiers[0] ) );
    145151
    146152    return tc;
    147153}
    148154
    149 static void setAnnounce( tr_tracker_t * tc, tr_announce_list_ptr_t * announcePtr )
    150 {
    151     tc->info = announcePtr->item;
     155static void setAnnounce( tr_tracker_t * tc, struct tclist * new )
     156{
     157    tc->tcCur = new;
    152158
    153159    /* Needs a new scrape */
     
    160166static void failureAnnouncing( tr_tracker_t * tc )
    161167{
    162     tr_info_t * inf = &tc->tor->info;
    163    
    164     tc->shouldChangeAnnounce = tc->announceTier + 1 < inf->trackerTiers
    165                                 || tc->announceTierLast + 1 < inf->trackerList[tc->announceTier].count
    166                                 ? TC_CHANGE_NEXT : TC_CHANGE_NONEXT;
    167    
    168     if( tc->shouldChangeAnnounce == TC_CHANGE_NONEXT )
    169     {
     168    if( NULL != SLIST_NEXT( tc->tcCur, next ) ||
     169        tc->tierIndex + 1 < tc->tierCount )
     170    {
     171        tc->shouldChangeAnnounce = TC_CHANGE_NEXT;
     172    }
     173    else
     174    {
     175        tc->shouldChangeAnnounce = TC_CHANGE_NONEXT;
    170176        tc->completelyUnconnectable = 1;
    171177    }
     
    186192    now = tr_date();
    187193   
    188     /* If last attempt was an error and it did not change trackers, then all must have been errors */
     194    /* If last attempt was an error and it did not change trackers,
     195       then all must have been errors */
    189196    if( tc->lastError )
    190197    {
    191         /* Unreachable trackers, wait 10 seconds + random value before trying again */
     198        /* Unreachable trackers, wait 10 seconds + random value before
     199           trying again */
    192200        if( tc->allUnreachIfError )
    193201        {
     
    197205            }
    198206        }
    199         /* The tracker rejected us (like 4XX code, unauthorized IP...),
    200             don't hammer it - we'll probably get the same answer next time anyway */
     207        /* The tracker rejected us (like 4XX code, unauthorized
     208            IP...), don't hammer it - we'll probably get the same
     209            answer next time anyway */
    201210        else
    202211        {
     
    207216            else
    208217            {
    209                 tc->allUnreachIfError = 1; //since starting at the top of the list, reset if any were reached previously
     218                /* since starting at the top of the list, reset if any
     219                   were reached previously */
     220                tc->allUnreachIfError = 1;
    210221            }
    211222        }
     
    263274    /* in process of changing tracker or scrape not supported */
    264275    if( tc->shouldChangeAnnounce != TC_CHANGE_NO ||
    265         NULL == tc->info->scrape || tc->stopped )
     276        NULL == tc->tcCur->tl_inf->scrape || tc->tcCur->tl_badscrape ||
     277        tc->stopped )
    266278    {
    267279        return 0;
     
    283295                              uint8_t ** peerCompact, int manual )
    284296{
    285     tr_torrent_t * tor = tc->tor;
    286     tr_info_t    * inf = &tor->info;
    287297    const char   * data;
    288298    char         * address, * announce;
    289     int            len, i, port;
    290     tr_announce_list_ptr_t * announcePtr, * prevAnnouncePtr;
     299    int            len, port;
     300    struct tclist * next;
     301    struct tchead * tier;
    291302
    292303    *peerCount = 0;
     
    295306    if( ( NULL == tc->http ) && ( manual || shouldConnect( tc ) ) )
    296307    {
    297         //if announcing manually, don't consider not reaching a tracker an error
     308        /* if announcing manually, don't consider not reaching a
     309           tracker an error */
    298310        if( manual )
    299311        {
     
    313325            {
    314326                tr_err( "Tracker: redirected URL: %s:%d", address, port );
    315                 tc->http = tr_httpClient( TR_HTTP_GET, address, port, "%s", announce );
     327                tc->http = tr_httpClient( TR_HTTP_GET, address, port,
     328                                          "%s", announce );
    316329               
    317330                free( address );
     
    327340            if( tc->shouldChangeAnnounce == TC_CHANGE_NEXT )
    328341            {
    329                 tr_inf( "Tracker: failed to connect to %s, trying next",
    330                         tc->info->address );
    331                
    332                 if( tc->announceTierLast + 1 < inf->trackerList[tc->announceTier].count )
     342                tr_inf( "Tracker: failed to connect to %s:%i, trying next",
     343                        tc->tcCur->tl_inf->address, tc->tcCur->tl_inf->port );
     344                next = SLIST_NEXT( tc->tcCur, next );
     345                if( NULL == next )
    333346                {
    334                     tc->announceTierLast++;
    335                    
    336                     announcePtr = tc->trackerAnnounceListPtr[tc->announceTier];
    337                     for( i = 0; i < tc->announceTierLast; i++ )
    338                     {
    339                         announcePtr = announcePtr->nextItem;
    340                     }
    341                 }
    342                 else
    343                 {
    344                     tc->announceTierLast = 0;
    345                     tc->announceTier++;
    346                    
    347                     announcePtr = tc->trackerAnnounceListPtr[tc->announceTier];
     347                    assert( tc->tierCount > tc->tierIndex + 1 );
     348                    tc->tierIndex++;
     349                    next = SLIST_FIRST( &tc->tiers[tc->tierIndex] );
     350                    /* XXX will there always be at least one tracker
     351                       in a tier? */
    348352                }
    349353               
    350                 tr_inf( "Tracker: tracker address set to %s", tc->trackerAnnounceListPtr[tc->announceTier]->item->address );
    351                 setAnnounce( tc, announcePtr );
     354                tr_inf( "Tracker: switching to tracker http://%s:%i%s",
     355                        next->tl_inf->address, next->tl_inf->port,
     356                        next->tl_inf->announce );
     357                setAnnounce( tc, next );
    352358            }
    353359            /* Need to change to first in list */
    354             else if( tc->announceTier != 0 || tc->announceTierLast != 0 )
     360            else if( SLIST_FIRST( &tc->tiers[0] ) != tc->tcCur )
    355361            {
    356                 /* Check if the last announce was successful and wasn't the first in the sublist */
    357                 if( tc->shouldChangeAnnounce == TC_CHANGE_NO && tc->announceTierLast != 0 )
     362                tier = &tc->tiers[tc->tierIndex];
     363                /* Check if the last announce was successful and
     364                   wasn't the first in the sublist */
     365                if( tc->shouldChangeAnnounce == TC_CHANGE_NO &&
     366                    SLIST_FIRST( tier ) != tc->tcCur )
    358367                {
    359                     announcePtr = tc->trackerAnnounceListPtr[tc->announceTier];
    360                     prevAnnouncePtr = NULL;
    361                     for( i = 0; i < tc->announceTierLast; i++ )
    362                     {
    363                         prevAnnouncePtr = announcePtr;
    364                         announcePtr = announcePtr->nextItem;
    365                     }
    366                    
    367                     /* Move address to front of tier in announce list */
    368                     prevAnnouncePtr->nextItem = announcePtr->nextItem;
    369                     announcePtr->nextItem =  tc->trackerAnnounceListPtr[tc->announceTier];
    370                     tc->trackerAnnounceListPtr[tc->announceTier] = announcePtr;
     368                    SLIST_REMOVE( tier, tc->tcCur, tclist, next );
     369                    SLIST_INSERT_HEAD( tier, tc->tcCur, next );
    371370                }
    372371               
    373                 setAnnounce( tc, tc->trackerAnnounceListPtr[0] );
    374                 tc->announceTier = 0;
    375                 tc->announceTierLast = 0;
     372                setAnnounce( tc, SLIST_FIRST( tier ) );
    376373            }
    377            
     374
    378375            tc->http = getQuery( tc );
    379376
    380377            tr_inf( "Tracker: connecting to %s:%d (%s)",
    381                     tc->info->address, tc->info->port,
     378                    tc->tcCur->tl_inf->address, tc->tcCur->tl_inf->port,
    382379                    tc->started ? "sending 'started'" :
    383380                    ( tc->completed ? "sending 'completed'" :
    384381                      ( tc->stopped ? "sending 'stopped'" :
    385                         ( shouldChangePort( tc ) ? "sending 'stopped' to change port" :
     382                        ( shouldChangePort( tc ) ?
     383                          "sending 'stopped' to change port" :
    386384                          "getting peers" ) ) ) );
    387385        }
     
    420418        {
    421419            /* Use redirected address */
    422             if( !tr_httpParseUrl( tc->redirectScrapeAddress, tc->redirectScrapeAddressLen,
    423                                      &address, &port, &announce ) )
     420            if( !tr_httpParseUrl( tc->redirectScrapeAddress,
     421                                  tc->redirectScrapeAddressLen,
     422                                  &address, &port, &announce ) )
    424423            {
    425424                tr_err( "Scrape: redirected URL: %s:%d", address, port );
    426                 tc->httpScrape = tr_httpClient( TR_HTTP_GET, address, port, "%s", announce );
     425                tc->httpScrape = tr_httpClient( TR_HTTP_GET, address, port,
     426                                                "%s", announce );
    427427               
    428428                free( address );
     
    436436        {
    437437            tc->httpScrape = getScrapeQuery( tc );
    438             tr_inf( "Scrape: sent HTTP request to %s:%d%s",
    439                     tc->info->address, tc->info->port, tc->info->scrape );
     438            tr_inf( "Scrape: sent HTTP request for http://%s:%d%s",
     439                    tc->tcCur->tl_inf->address,
     440                    tc->tcCur->tl_inf->port,
     441                    tc->tcCur->tl_inf->scrape );
    440442        }
    441443    }
     
    486488void tr_trackerClose( tr_tracker_t * tc )
    487489{
    488     tr_torrent_t * tor = tc->tor;
    489     tr_info_t * inf = &tor->info;
    490     tr_announce_list_ptr_t * cur, * curFree;
    491     int ii;
     490    size_t          ii;
     491    struct tclist * dead;
    492492
    493493    killHttp( &tc->http );
    494494    killHttp( &tc->httpScrape );
    495495
    496     for( ii = 0; ii < inf->trackerTiers; ii++ )
    497     {
    498         for( cur = tc->trackerAnnounceListPtr[ii]; cur; )
    499         {
    500             curFree = cur;
    501             cur = cur->nextItem;
    502             free( curFree );
    503         }
    504     }
    505     free( tc->trackerAnnounceListPtr );
     496    for( ii = 0; tc->tierCount > ii; ii++ )
     497    {
     498        while( !SLIST_EMPTY( &tc->tiers[ii] ) )
     499        {
     500            dead = SLIST_FIRST( &tc->tiers[ii] );
     501            SLIST_REMOVE_HEAD( &tc->tiers[ii], next );
     502            free( dead );
     503        }
     504    }
     505    free( tc->tiers );
    506506
    507507    free( tc->trackerid );
     
    512512{
    513513    tr_torrent_t * tor = tc->tor;
     514    tr_tracker_info_t * tcInf = tc->tcCur->tl_inf;
    514515
    515516    char         * event, * trackerid, * idparam;
     
    558559    }
    559560
    560     start = ( strchr( tc->info->announce, '?' ) ? '&' : '?' );
     561    start = ( strchr( tcInf->announce, '?' ) ? '&' : '?' );
    561562    left  = tr_cpLeftBytes( tor->completion );
    562563
    563     return tr_httpClient( TR_HTTP_GET, tc->info->address, tc->info->port,
     564    return tr_httpClient( TR_HTTP_GET, tcInf->address, tcInf->port,
    564565                          "%s%c"
    565566                          "info_hash=%s&"
     
    574575                          "%s%s"
    575576                          "%s",
    576                           tc->info->announce, start, tor->escapedHashString,
     577                          tcInf->announce, start, tor->escapedHashString,
    577578                          tc->id, tc->publicPort, up, down, left, numwant,
    578579                          tor->key, idparam, trackerid, event );
     
    582583{
    583584    tr_torrent_t * tor = tc->tor;
     585    tr_tracker_info_t * tcInf = tc->tcCur->tl_inf;
    584586    char           start;
    585587
    586     start = ( strchr( tc->info->scrape, '?' ) ? '&' : '?' );
    587 
    588     return tr_httpClient( TR_HTTP_GET, tc->info->address, tc->info->port,
     588    start = ( strchr( tcInf->scrape, '?' ) ? '&' : '?' );
     589
     590    return tr_httpClient( TR_HTTP_GET, tcInf->address, tcInf->port,
    589591                          "%s%c"
    590592                          "info_hash=%s",
    591                           tc->info->scrape, start, tor->escapedHashString );
     593                          tcInf->scrape, start, tor->escapedHashString );
    592594}
    593595
     
    685687    }
    686688
    687     // tr_bencPrint( &beAll );
     689    /* tr_bencPrint( &beAll ); */
    688690
    689691    if( ( bePeers = tr_bencDictFind( &beAll, "failure reason" ) ) )
     
    891893        if( TR_HTTP_STATUS_FAIL_CLIENT( code ) )
    892894        {
    893             free( tc->info->scrape );
    894             tc->info->scrape = NULL;
     895            tc->tcCur->tl_badscrape = 1;
    895896        }
    896897        tc->lastScrapeFailed = 1;
     
    10031004        return NULL;
    10041005    }
    1005     return tc->info;
     1006    return tc->tcCur->tl_inf;
    10061007}
    10071008
     
    10261027    tc = tr_trackerInit( tor );
    10271028
    1028     if( NULL == tc->info->scrape )
     1029    if( NULL == tc->tcCur->tl_inf->scrape || tc->tcCur->tl_badscrape )
    10291030    {
    10301031        return 1;
  • branches/daemon/libtransmission/transmission.c

    r1600 r1712  
    5252    }
    5353
    54     /* Generate a peer id : "-TRxxyy-" + 12 random alphanumeric
    55        characters, where xx is the major version number and yy the
    56        minor version number (Azureus-style) */
    57     snprintf( h->id, sizeof h->id, "-TR%02d%02d-",
    58               VERSION_MAJOR, VERSION_MINOR );
     54    /* Generate a peer id : "-TRxxyz-" + 12 random alphanumeric
     55       characters, where xx is the major version number, y is the
     56       minor version number, and z is the maintenance number (Azureus-style) */
     57    snprintf( h->id, sizeof h->id, "-TR%02d%01d%01d-",
     58              VERSION_MAJOR, VERSION_MINOR, VERSION_MAINTENANCE );
    5959    for( i = 8; i < TR_ID_LEN; i++ )
    6060    {
  • branches/daemon/libtransmission/transmission.h

    r1634 r1712  
    441441    int                 completedFromTracker;
    442442
     443    uint64_t            left;
    443444    uint64_t            downloaded;
    444445    uint64_t            uploaded;
     
    453454{
    454455    char    addr[INET_ADDRSTRLEN];
    455     char * client;
     456    const char * client;
    456457   
    457458    int     isConnected;
  • branches/daemon/libtransmission/upnp.c

    r1579 r1712  
    122122devicePulseGetHttp( tr_upnp_device_t * dev );
    123123static int
    124 parseRoot( const char *buf, int len, char ** soap, char ** scpd );
     124parseRoot( const char * root, const char *buf, int len,
     125           char ** soap, char ** scpd );
    125126static void
    126127addUrlbase( const char * base, char ** path );
     
    665666                        dev->host, code );
    666667            }
    667             else if( parseRoot( body, len, &dev->soap, &dev->scpd ) )
     668            else if( parseRoot( dev->root, body, len,
     669                                &dev->soap, &dev->scpd ) )
    668670            {
    669671                tr_dbg( "upnp device %s: parse root failed", dev->host );
     
    942944
    943945static int
    944 parseRoot(const char *buf, int len, char ** soap, char ** scpd )
     946parseRoot( const char * root, const char *buf, int len,
     947           char ** soap, char ** scpd )
    945948{
    946949    const char * end, * ii, * jj, * kk, * urlbase;
     
    9991002    }
    10001003
    1001     basedup = tr_xmlDupContents( urlbase, end );
     1004    if( NULL == urlbase )
     1005    {
     1006        basedup = strrchr( root, '/' );
     1007        assert( NULL != basedup );
     1008        basedup = tr_dupstr( root, basedup - root + 1 );
     1009    }
     1010    else
     1011    {
     1012        basedup = tr_xmlDupContents( urlbase, end );
     1013    }
    10021014    addUrlbase( basedup, soap );
    10031015    addUrlbase( basedup, scpd );
Note: See TracChangeset for help on using the changeset viewer.