Changeset 1650


Ignore:
Timestamp:
Apr 3, 2007, 6:22:58 PM (15 years ago)
Author:
joshe
Message:

Cache peer client name.
Don't create an 'unknown client' name with nonprintable characters.

Location:
trunk/libtransmission
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/clients.c

    r1648 r1650  
    321321    if( !ret )
    322322    {
    323         if( id[0] != 0 )
     323        if( isprint( id[0] ) && isprint( id[1] ) && isprint( id[2] ) &&
     324            isprint( id[3] ) && isprint( id[4] ) && isprint( id[5] ) &&
     325            isprint( id[6] ) && isprint( id[7] ) )
    324326        {
    325327            asprintf( &ret, "unknown client (%c%c%c%c%c%c%c%c)",
     
    328330        else
    329331        {
    330             asprintf( &ret, "unknown client" );
     332            asprintf( &ret, "unknown client (0x%02x%02x%02x%02x%02x%02x%02x%02x",
     333                  id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7] );
    331334        }
    332335    }
  • trunk/libtransmission/internal.h

    r1614 r1650  
    4242#include <string.h>
    4343#include <unistd.h>
     44#include <ctype.h>
    4445#include <errno.h>
    4546#include <limits.h>
  • trunk/libtransmission/peer.c

    r1614 r1650  
    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( NULL == peer->client )
     231    {
     232        peer->client = tr_clientForId( peer->id );
     233    }
     234
     235    return peer->client;
    222236}
    223237
  • trunk/libtransmission/peer.h

    r1579 r1650  
    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 * );
  • trunk/libtransmission/peeraz.h

    r1612 r1650  
    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" );
  • trunk/libtransmission/peerext.h

    r1614 r1650  
    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" );
  • trunk/libtransmission/peerparse.h

    r1600 r1650  
    585585    tr_info_t * inf = &tor->info;
    586586    int         ii;
    587     char      * client;
    588587
    589588    if( memcmp( &peer->buf[28], inf->hash, SHA_DIGEST_LENGTH ) )
     
    615614    }
    616615
    617     client = tr_clientForId( (uint8_t *) peer->id );
    618616    if( PEER_SUPPORTS_EXTENDED_MESSAGES( &peer->buf[20] ) )
    619617    {
     
    621619        peer->extStatus = EXTENDED_SUPPORTED;
    622620        peer_dbg( "GET  handshake, ok (%s) extended messaging supported",
    623                   client );
     621                  tr_peerClient( peer ) );
    624622    }
    625623    else if( PEER_SUPPORTS_AZUREUS_PROTOCOL( &peer->buf[20] ) )
     
    629627        peer->date    = tr_date();
    630628        peer_dbg( "GET  handshake, ok (%s) will use azureus protocol",
    631                   client );
     629                  tr_peerClient( peer ) );
    632630    }
    633631    else
    634632    {
    635633        peer->status = PEER_STATUS_CONNECTED;
    636         peer_dbg( "GET  handshake, ok (%s)", client );
    637     }
    638     free( client );
     634        peer_dbg( "GET  handshake, ok (%s)", tr_peerClient( peer ) );
     635    }
    639636
    640637    return TR_OK;
  • trunk/libtransmission/torrent.c

    r1636 r1650  
    498498            }
    499499           
    500             peers[i].client = tr_clientForId(tr_peerId(peer));
    501            
     500            peers[i].client        = tr_peerClient( peer );
    502501            peers[i].isConnected   = tr_peerIsConnected( peer );
    503502            peers[i].from          = tr_peerIsFrom( peer );
     
    522521}
    523522
    524 void tr_torrentPeersFree( tr_peer_stat_t * peers, int peerCount )
    525 {
    526     int i;
    527 
     523void tr_torrentPeersFree( tr_peer_stat_t * peers, int peerCount UNUSED )
     524{
    528525    if (peers == NULL)
    529526        return;
    530 
    531     for (i = 0; i < peerCount; i++)
    532         free( peers[i].client );
    533527
    534528    free( peers );
  • trunk/libtransmission/transmission.h

    r1636 r1650  
    453453{
    454454    char    addr[INET_ADDRSTRLEN];
    455     char * client;
     455    const char * client;
    456456   
    457457    int     isConnected;
Note: See TracChangeset for help on using the changeset viewer.