Changeset 1594


Ignore:
Timestamp:
Mar 26, 2007, 7:19:33 PM (15 years ago)
Author:
joshe
Message:

Don't save or load cached peers for private torrents.

Location:
trunk/libtransmission
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fastresume.h

    r1579 r1594  
    172172    fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file );
    173173
    174     /* Write IPs and ports of connectable peers, if any */
    175     if( ( size = tr_peerGetConnectable( tor, &buf ) ) > 0 )
    176     {
    177         fastResumeWriteData( FR_ID_PEERS, buf, size, 1, file );
    178         free( buf );
     174    if( !( TR_FLAG_PRIVATE & tor->info.flags ) )
     175    {
     176        /* Write IPs and ports of connectable peers, if any */
     177        if( ( size = tr_peerGetConnectable( tor, &buf ) ) > 0 )
     178        {
     179            fastResumeWriteData( FR_ID_PEERS, buf, size, 1, file );
     180            free( buf );
     181        }
    179182    }
    180183
     
    375378
    376379            case FR_ID_PEERS:
    377             {
    378                 uint8_t * buf = malloc( len );
    379                 if( 1 != fread( buf, len, 1, file ) )
     380                if( !( TR_FLAG_PRIVATE & tor->info.flags ) )
    380381                {
     382                    uint8_t * buf = malloc( len );
     383                    if( 1 != fread( buf, len, 1, file ) )
     384                    {
     385                        free( buf );
     386                        fclose( file );
     387                        return 1;
     388                    }
     389                    tr_torrentAddCompact( tor, TR_PEER_FROM_CACHE,
     390                                          buf, len / 6 );
    381391                    free( buf );
    382                     fclose( file );
    383                     return 1;
    384392                }
    385                 tr_torrentAddCompact( tor, TR_PEER_FROM_CACHE, buf, len / 6 );
    386                 free( buf );
    387393                continue;
    388             }
    389394
    390395            default:
  • trunk/libtransmission/internal.h

    r1579 r1594  
    202202    uint64_t          uploadedPrev;
    203203
     204    uint8_t           pexDisabled;
     205
    204206    tr_stat_t         stats[2];
    205207    int               statCur;
  • trunk/libtransmission/peer.c

    r1579 r1594  
    224224void tr_peerSetPrivate( tr_peer_t * peer, int private )
    225225{
     226    if( peer->private == private )
     227    {
     228        return;
     229    }
     230
    226231    peer->private = private;
     232
     233    if( !private )
     234    {
     235        peer->lastPex = 0;
     236    }
     237
     238    if( EXTENDED_HANDSHAKE == peer->extStatus )
     239    {
     240        sendExtended( peer->tor, peer, EXTENDED_HANDSHAKE_ID );
     241    }
    227242}
    228243
  • trunk/libtransmission/peeraz.h

    r1579 r1594  
    152152            continue;
    153153        }
     154        /* XXX azureus sucks, we can't enable or disable pex after handshake */
    154155        if( AZ_MSG_AZ_PEER_EXCHANGE == azmsgId( idx ) && peer->private )
    155156        {
  • trunk/libtransmission/peerext.h

    r1579 r1594  
    128128    /* create dict of supported extended messages */
    129129    tr_bencInit( msgsval, TYPE_DICT );
    130     if( !peer->private )
    131     {
    132         /* for public torrents advertise utorrent pex message */
    133         if( tr_bencDictAppendNofree( msgsval, "ut_pex", &pexval, NULL ) )
    134         {
    135             tr_bencFree( &val );
    136             return NULL;
    137         }
    138         tr_bencInitInt( pexval, EXTENDED_PEX_ID );
    139     }
     130    if( tr_bencDictAppendNofree( msgsval, "ut_pex", &pexval, NULL ) )
     131    {
     132        tr_bencFree( &val );
     133        return NULL;
     134    }
     135    /* for public torrents advertise utorrent pex message */
     136    tr_bencInitInt( pexval, ( peer->private ? 0 : EXTENDED_PEX_ID ) );
    140137
    141138    /* our listening port */
     
    233230        {
    234231            peer->pexStatus = 0;
    235             if( !peer->private && 0x0 < sub->val.i && 0xff >= sub->val.i )
     232            if( 0x0 < sub->val.i && 0xff >= sub->val.i )
    236233            {
    237234                peer->pexStatus = sub->val.i;
  • trunk/libtransmission/torrent.c

    r1579 r1594  
    138138    }
    139139
     140    tor->pexDisabled = 0;
     141
    140142    /* Block size: usually 16 ko, or less if we have to */
    141143    tor->blockSize  = MIN( inf->pieceSize, 1 << 14 );
     
    268270    }
    269271    tor->peerCount = 0;
     272    tr_lockUnlock( &tor->lock );
     273}
     274
     275void tr_torrentDisablePex( tr_torrent_t * tor, int disable )
     276{
     277    int ii;
     278
     279    if( TR_FLAG_PRIVATE & tor->info.flags )
     280    {
     281        return;
     282    }
     283
     284    tr_lockLock( &tor->lock );
     285
     286    if( tor->pexDisabled == disable )
     287    {
     288        tr_lockUnlock( &tor->lock );
     289        return;
     290    }
     291
     292    tor->pexDisabled = disable;
     293    for( ii = 0; ii < tor->peerCount; ii++ )
     294    {
     295        tr_peerSetPrivate( tor->peers[ii], disable );
     296    }
     297
    270298    tr_lockUnlock( &tor->lock );
    271299}
     
    636664    }
    637665
    638     tr_peerSetPrivate( peer, tor->info.flags & TR_FLAG_PRIVATE );
     666    tr_peerSetPrivate( peer, tor->info.flags & TR_FLAG_PRIVATE ||
     667                       tor->pexDisabled );
    639668    tr_peerSetTorrent( peer, tor );
    640669    tor->peers[tor->peerCount++] = peer;
  • trunk/libtransmission/transmission.h

    r1579 r1594  
    224224                                    int flags, int * error );
    225225
     226/***********************************************************************
     227 * tr_torrentDisablePex
     228 ***********************************************************************
     229 * Disable or enable peer exchange for this torrent. Peer exchange is
     230 * enabled by default, except for private torrents where pex is
     231 * disabled and cannot be enabled.
     232 **********************************************************************/
     233void tr_torrentDisablePex( tr_torrent_t *, int disable );
     234
     235/***********************************************************************
     236 * tr_torrentScrape
     237 ***********************************************************************
     238 * Return torrent metainfo.
     239 **********************************************************************/
    226240typedef struct tr_info_s tr_info_t;
    227241tr_info_t * tr_torrentInfo( tr_torrent_t * );
Note: See TracChangeset for help on using the changeset viewer.