Changeset 1614


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

Add API function to disable PEX for a torrent.

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/internal.h

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

    r1600 r1614  
    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/peerext.h

    r1606 r1614  
    137137    msgsval  = tr_bencDictAdd( &val, "m" );
    138138    tr_bencInit( msgsval, TYPE_DICT );
    139     if( !peer->private )
    140     {
    141         /* for public torrents, advertise utorrent pex message */
    142         if( tr_bencDictReserve( msgsval, 1 ) )
    143         {
    144             tr_bencFree( &val );
    145             return NULL;
    146         }
    147         tr_bencInitInt( tr_bencDictAdd( msgsval, "ut_pex" ), EXTENDED_PEX_ID );
    148     }
     139    if( tr_bencDictReserve( msgsval, 1 ) )
     140    {
     141        tr_bencFree( &val );
     142        return NULL;
     143    }
     144    /* for public torrents advertise utorrent pex message */
     145    tr_bencInitInt( tr_bencDictAdd( msgsval, "ut_pex" ),
     146                    ( peer->private ? 0 : EXTENDED_PEX_ID ) );
    149147
    150148    /* our listening port */
     
    245243        {
    246244            peer->pexStatus = 0;
    247             if( !peer->private && 0x0 < sub->val.i && 0xff >= sub->val.i )
     245            if( 0x0 < sub->val.i && 0xff >= sub->val.i )
    248246            {
    249247                peer->pexStatus = sub->val.i;
  • trunk/libtransmission/torrent.c

    r1604 r1614  
    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}
     
    638666    }
    639667
    640     tr_peerSetPrivate( peer, tor->info.flags & TR_FLAG_PRIVATE );
     668    tr_peerSetPrivate( peer, tor->info.flags & TR_FLAG_PRIVATE ||
     669                       tor->pexDisabled );
    641670    tr_peerSetTorrent( peer, tor );
    642671    tor->peers[tor->peerCount++] = peer;
  • trunk/libtransmission/transmission.h

    r1595 r1614  
    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.