Changeset 2374


Ignore:
Timestamp:
Jul 16, 2007, 11:19:44 AM (15 years ago)
Author:
charles
Message:

re-randomize peer_id each time we start a torrent. (ticket #257)

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/internal.h

    r2343 r2374  
    133133#endif
    134134
     135void tr_peerIdNew ( char* buf, int buflen );
     136
    135137void tr_torrentResetTransferStats( tr_torrent_t * );
    136138
     
    157159run_status_t;
    158160
     161#define TR_ID_LEN               20
     162#define TR_KEY_LEN              20
     163
    159164struct tr_torrent_s
    160165{
     
    172177    int               hasChangedState;
    173178
    174     char            * id;
     179    char              peer_id[TR_ID_LEN+1];
    175180    char            * key;
    176181    uint8_t         * azId;
     
    235240    tr_shared_t      * shared;
    236241
    237 #define TR_ID_LEN               20
    238     char           id[TR_ID_LEN+1];
    239 #define TR_KEY_LEN              20
    240242    char           key[TR_KEY_LEN+1];
    241243
  • trunk/libtransmission/peer.c

    r2343 r2374  
    497497        buf[25] = 0x10;         /* extended messages */
    498498        memcpy( &buf[28], inf->hash, 20 );
    499         memcpy( &buf[48], tor->id, 20 );
     499        memcpy( &buf[48], tor->peer_id, 20 );
    500500
    501501        switch( tr_netSend( peer->socket, buf, 68 ) )
  • trunk/libtransmission/peerparse.h

    r2339 r2374  
    612612    }
    613613
    614     if( !memcmp( &peer->buf[48], tor->id, TR_ID_LEN ) )
     614    if( !memcmp( &peer->buf[48], tor->peer_id, TR_ID_LEN ) )
    615615    {
    616616        /* We are connected to ourselves... */
  • trunk/libtransmission/torrent.c

    r2369 r2374  
    188188
    189189    tor->handle   = h;
    190     tor->id       = h->id;
    191190    tor->key      = h->key;
    192191    tor->azId     = h->azId;
     
    688687    for( i=0; i<n; ++i, ++walk )
    689688    {
    690         const uint64_t length = tor->info.files[i].length;
     689        const tr_file_t * file = tor->info.files + i;
    691690        cp_status_t cp;
    692691
    693692        walk->bytesCompleted = fileBytesCompleted( tor, i );
    694693
    695         walk->progress = length
    696             ? walk->bytesCompleted / (float)length
     694        walk->progress = file->length
     695            ? walk->bytesCompleted / (float)file->length
    697696            : 1.0;
    698697
    699         if( walk->bytesCompleted >= length )
     698        if( walk->bytesCompleted >= file->length )
    700699            cp = TR_CP_COMPLETE;
    701700        else if( tor->info.files[i].dnd )
     
    10901089                    continue;
    10911090                }
     1091                tr_peerIdNew ( tor->peer_id, sizeof(tor->peer_id) );
    10921092                tor->tracker = tr_trackerInit( tor );
    10931093                tor->startDate = tr_date();
  • trunk/libtransmission/tracker.c

    r2358 r2374  
    4747    tr_torrent_t * tor;
    4848
    49     char         * id;
     49    const char   * peer_id;
    5050    char         * trackerid;
    5151
     
    9898static void        failureAnnouncing( tr_tracker_t * tc );
    9999static tr_http_t * getQuery         ( tr_tracker_t * tc );
    100 static tr_http_t * getScrapeQuery   ( tr_tracker_t * tc );
     100static tr_http_t * getScrapeQuery   ( const tr_tracker_t * tc );
    101101static void        readAnswer       ( tr_tracker_t * tc, const char *, int,
    102102                                      int * peerCount, uint8_t ** peerCompact );
     
    121121
    122122    tc->tor            = tor;
    123     tc->id             = tor->id;
     123    tc->peer_id        = tor->peer_id;
    124124
    125125    tc->started        = 1;
     
    525525{
    526526    tr_torrent_t * tor = tc->tor;
    527     tr_tracker_info_t * tcInf = tc->tcCur->tl_inf;
    528 
    529     char         * event, * trackerid, * idparam;
     527    const tr_tracker_info_t * tcInf = tc->tcCur->tl_inf;
     528
     529    const char   * trackerid;
     530    const char   * event;
     531    const char   * idparam;
    530532    uint64_t       left;
    531533    char           start;
     
    585587                          "%s",
    586588                          tcInf->announce, start, tor->escapedHashString,
    587                           tc->id, tc->publicPort, tor->uploadedCur, tor->downloadedCur,
     589                          tc->peer_id, tc->publicPort, tor->uploadedCur, tor->downloadedCur,
    588590                          left, numwant, tor->key, idparam, trackerid, event );
    589591}
    590592
    591 static tr_http_t * getScrapeQuery( tr_tracker_t * tc )
    592 {
    593     tr_torrent_t * tor = tc->tor;
    594     tr_tracker_info_t * tcInf = tc->tcCur->tl_inf;
    595     char           start;
    596 
    597     start = ( strchr( tcInf->scrape, '?' ) ? '&' : '?' );
    598 
     593static tr_http_t * getScrapeQuery( const tr_tracker_t * tc )
     594{
     595    const tr_torrent_t * tor = tc->tor;
     596    const tr_tracker_info_t * tcInf = tc->tcCur->tl_inf;
     597    const char start = ( strchr( tcInf->scrape, '?' ) ? '&' : '?' );
    599598    return tr_httpClient( TR_HTTP_GET, tcInf->address, tcInf->port,
    600599                          "%s%c"
  • trunk/libtransmission/transmission.c

    r2328 r2374  
    2929#include "shared.h"
    3030
     31/* Generate a peer id : "-TRxxyz-" + 12 random alphanumeric
     32   characters, where xx is the major version number, y is the
     33   minor version number, and z is the maintenance number (Azureus-style) */
     34void
     35tr_peerIdNew ( char * buf, int buflen )
     36{
     37    int i;
     38    assert( buflen == TR_ID_LEN + 1 );
     39    snprintf( buf, TR_ID_LEN, "-TR" VERSION_MAJOR VERSION_MINOR VERSION_MAINTENANCE VERSION_BETA "-" );
     40    assert( strlen(buf) == 8 );
     41    for( i=8; i<TR_ID_LEN; ++i ) {
     42        const int r = tr_rand( 36 );
     43        buf[i] = ( r < 26 ) ? ( 'a' + r ) : ( '0' + r - 26 ) ;
     44    }
     45    buf[TR_ID_LEN] = '\0';
     46}
     47
     48
    3149/***********************************************************************
    3250 * tr_init
     
    5472        return NULL;
    5573    }
    56 
    57     /* Generate a peer id : "-TRxxyz-" + 12 random alphanumeric
    58        characters, where xx is the major version number, y is the
    59        minor version number, and z is the maintenance number (Azureus-style) */
    60     snprintf( h->id, sizeof h->id, "-TR" VERSION_MAJOR VERSION_MINOR VERSION_MAINTENANCE VERSION_BETA "-" );
    61     assert( strlen(h->id) == 8 );
    62     for( i=8; i<TR_ID_LEN; ++i )
    63     {
    64         const int r = tr_rand( 36 );
    65         h->id[i] = ( r < 26 ) ? ( 'a' + r ) : ( '0' + r - 26 ) ;
    66     }
    67     tr_dbg( "Transmission ID is [%s]", h->id );
    6874
    6975    /* Random key */
Note: See TracChangeset for help on using the changeset viewer.