Changeset 4306


Ignore:
Timestamp:
Dec 24, 2007, 5:03:40 AM (15 years ago)
Author:
charles
Message:

replace the per-torrent PEX setting with a global one, as per discussion with SoftwareElves? and BentMyWookie?

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/torrents.c

    r4277 r4306  
    5858    uint8_t         hash[SHA_DIGEST_LENGTH];
    5959    tr_torrent    * tor;
    60     int             pexset;
    61     int             pex;
    6260    RB_ENTRY( tor ) idlinks;
    6361    RB_ENTRY( tor ) hashlinks;
     
    374372torrent_set_pex( int pex )
    375373{
    376     struct tor * tor;
    377 
    378     assert( NULL != gl_handle );
    379     assert( !gl_exiting );
    380 
    381     if( pex == gl_pex )
    382     {
    383         return;
    384     }
    385     gl_pex = pex;
    386 
    387     for( tor = iterate( NULL ); NULL != tor; tor = iterate( tor ) )
    388     {
    389         if( tor->pexset )
    390         {
    391             continue;
    392         }
    393         tr_torrentDisablePex( tor->tor, !gl_pex );
    394     }
    395 
    396     savestate();
     374    assert( NULL != gl_handle );
     375    assert( !gl_exiting );
     376
     377    if( pex != gl_pex )
     378    {
     379        tr_setPexEnabled( gl_handle, gl_pex );
     380
     381        savestate( );
     382    }
    397383}
    398384
     
    580566    memcpy( tor->hash, inf->hash, sizeof tor->hash );
    581567
    582     if( inf->isPrivate )
    583     {
    584         tor->pexset = 1;
    585         tor->pex    = 0;
    586     }
    587     else
    588     {
    589         tr_torrentDisablePex( tor->tor, !gl_pex );
    590     }
    591 
    592568    found = RB_INSERT( tortree, &gl_tree, tor );
    593569    assert( NULL == found );
     
    797773        if( NULL != num && TYPE_INT == num->type )
    798774        {
    799             tor->pexset = 1;
    800             tor->pex = ( num->val.i ? 1 : 0 );
    801         }
    802         tr_torrentDisablePex( tor->tor, !( tor->pexset ? tor->pex : gl_pex ) );
     775            fprintf( stderr, "warning: obsolete command 'pex'\n" );
     776        }
    803777
    804778        num = tr_bencDictFind( dict, "paused" );
     
    818792    struct tor * ii;
    819793    uint8_t    * buf;
    820     int          len, pexset;
     794    int          len;
    821795
    822796    tr_bencInit( &top, TYPE_DICT );
     
    862836        inf    = tr_torrentInfo( ii->tor );
    863837        st     = tr_torrentStat( ii->tor );
    864         pexset = ( ii->pexset && !inf->isPrivate );
    865         if( tr_bencDictReserve( tor, ( pexset ? 4 : 3 ) ) )
     838        if( tr_bencDictReserve( tor, 3 ) )
    866839        {
    867840            goto nomem;
     
    873846        tr_bencInitStr( tr_bencDictAdd( tor, "directory" ),
    874847                        tr_torrentGetFolder( ii->tor ), -1, 1 );
    875         if( pexset )
    876         {
    877             tr_bencInitInt( tr_bencDictAdd( tor, "pex" ), ii->pex );
    878         }
    879848    }
    880849
  • trunk/gtk/main.c

    r4304 r4306  
    142142static void
    143143prefschanged( TrCore * core, const char * key, gpointer data );
    144 static void
    145 setpex( tr_torrent * tor, void * arg );
    146144static gboolean
    147145updatemodel(gpointer gdata);
     
    734732    else if( !strcmp( key, PREF_KEY_PEX ) )
    735733    {
    736         gboolean enabled = pref_flag_get( key );
    737         tr_torrentIterate( tr, setpex, &enabled );
    738     }
    739 }
    740 
    741 void
    742 setpex( tr_torrent * tor, void * arg )
    743 {
    744     const gboolean * val = arg;
    745     tr_torrentDisablePex( tor, !*val );
     734        const gboolean enabled = pref_flag_get( key );
     735        tr_setPexEnabled( tr_core_handle( cbdata->core ), enabled );
     736    }
    746737}
    747738
  • trunk/gtk/sexy-icon-entry.c

    r4304 r4306  
    1919 * Boston, MA  02111-1307, USA.
    2020 */
    21 #include <config.h>
    2221#include <string.h>
    2322#include <gtk/gtk.h>
     
    157156
    158157static void
    159 sexy_icon_entry_editable_init(GtkEditableClass *iface)
     158sexy_icon_entry_editable_init(GtkEditableClass *iface G_GNUC_UNUSED )
    160159{
    161160};
     
    301300get_icon_allocation(SexyIconEntry *icon_entry,
    302301                                        gboolean left,
    303                                         GtkAllocation *widget_alloc,
     302                                        GtkAllocation *widget_alloc G_GNUC_UNUSED,
    304303                                        GtkAllocation *text_area_alloc,
    305304                                        GtkAllocation *allocation,
     
    648647
    649648static void
    650 update_icon(GObject *obj, GParamSpec *param, SexyIconEntry *entry)
     649update_icon(GObject *obj G_GNUC_UNUSED, GParamSpec *param, SexyIconEntry *entry)
    651650{
    652651        if (param != NULL)
  • trunk/gtk/tr_torrent.c

    r4272 r4306  
    165165{
    166166    TrTorrent * tor = g_object_new( TR_TORRENT_TYPE, NULL );
    167     tr_torrentDisablePex( handle, !pref_flag_get( PREF_KEY_PEX ) );
    168167    tor->handle = handle;
    169168    return tor;
  • trunk/libtransmission/fastresume.c

    r4285 r4306  
    294294    }
    295295
    296     if( TRUE ) /* FR_ID_PEX */
    297     {
    298         const char flag = tor->pexDisabled ? 'f' : 't';
    299         fastResumeWriteData( FR_ID_PEX, &flag, 1, 1, file );
    300     }
    301 
    302296    if( TRUE ) /* FR_ID_RUN */
    303297    {
     
    361355        case FR_ID_PEERS:          ret = TR_FR_PEERS;         break;
    362356        case FR_ID_DESTINATION:    ret = TR_FR_DESTINATION;   break;
    363         case FR_ID_PEX:            ret = TR_FR_PEX;           break;
    364357        case FR_ID_MAX_PEERS:      ret = TR_FR_MAX_PEERS;     break;
    365358        case FR_ID_MAX_UNCHOKED:   ret = TR_FR_MAX_UNCHOKED;  break;
     
    553546
    554547static uint64_t
    555 parsePex( tr_torrent * tor, const uint8_t * buf, uint32_t len )
    556 {
    557     if( len != 1 )
    558         return 0;
    559     tor->pexDisabled = *buf!='t';
    560     return TR_FR_PEX;
    561 }
    562 
    563 static uint64_t
    564548parsePeers( tr_torrent * tor, const uint8_t * buf, uint32_t len )
    565549{
     
    620604            case FR_ID_MAX_PEERS:    ret |= parseConnections( tor, buf, len ); break;
    621605            case FR_ID_MAX_UNCHOKED: ret |= parseUnchoked( tor, buf, len ); break;
    622             case FR_ID_PEX:          ret |= parsePex( tor, buf, len ); break;
    623606            case FR_ID_DESTINATION:  ret |= parseDestination( tor, buf, len ); break;
    624607            default:                 tr_dbg( "Skipping unknown resume code %d", (int)id ); break;
  • trunk/libtransmission/fastresume.h

    r4267 r4306  
    3939  TR_FR_RUN          = (1<<7),
    4040  TR_FR_DESTINATION  = (1<<8),
    41   TR_FR_PEX          = (1<<9),
    42   TR_FR_MAX_PEERS    = (1<<10),
    43   TR_FR_MAX_UNCHOKED = (1<<11),
     41  TR_FR_MAX_PEERS    = (1<<9),
     42  TR_FR_MAX_UNCHOKED = (1<<10)
    4443};
    4544
  • trunk/libtransmission/internal.h

    r4285 r4306  
    7979void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
    8080
     81int tr_torrentAllowsPex( const tr_torrent * );
     82
    8183/* get the index of this piece's first block */
    8284#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
     
    163165    void                     * status_func_user_data;
    164166
    165     unsigned int               pexDisabled : 1;
    166167    unsigned int               statCur : 1;
    167168    unsigned int               isRunning : 1;
     
    188189
    189190    char                     * tag;
    190     int                        isPortSet;
     191    unsigned int               isPortSet : 1;
     192    unsigned int               isPexEnabled : 1;
    191193
    192194    char                       useUploadLimit;
  • trunk/libtransmission/peer-mgr.c

    r4255 r4306  
    16501650        const int clientIsSeed = tr_torrentIsSeed( tor );
    16511651        const int peerIsSeed = atom->flags & ADDED_F_SEED_FLAG;
    1652         if( peerIsSeed && clientIsSeed && ( !tr_torrentIsPexEnabled(tor) || (now-atom->time>=30) ) ) {
     1652        if( peerIsSeed && clientIsSeed && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30) ) ) {
    16531653            tordbg( t, "purging peer %s because we're both seeds", tr_peerIoAddrStr(&atom->addr,atom->port) );
    16541654            return TRUE;
  • trunk/libtransmission/peer-msgs.c

    r4177 r4306  
    732732
    733733    /* decide if we want to advertise pex support */
    734     if( !tr_torrentIsPexEnabled( msgs->torrent ) )
     734    if( !tr_torrentAllowsPex( msgs->torrent ) )
    735735        pex = 0;
    736736    else if( msgs->peerSentLtepHandshake )
     
    824824    uint8_t * tmp;
    825825
    826     if( !tr_torrentIsPexEnabled( msgs->torrent ) ) /* no sharing! */
     826    if( !tr_torrentAllowsPex( msgs->torrent ) ) /* no sharing! */
    827827        return;
    828828
     
    17111711sendPex( tr_peermsgs * msgs )
    17121712{
    1713     if( msgs->peerSupportsPex && tr_torrentIsPexEnabled( msgs->torrent ) )
     1713    if( msgs->peerSupportsPex && tr_torrentAllowsPex( msgs->torrent ) )
    17141714    {
    17151715        int i;
  • trunk/libtransmission/torrent.c

    r4286 r4306  
    271271
    272272    tor->handle   = h;
    273     tor->pexDisabled = 0;
    274273
    275274    /**
     
    494493
    495494int
    496 tr_torrentIsPexEnabled( const tr_torrent * tor )
     495tr_torrentAllowsPex( const tr_torrent * tor )
    497496{
    498497    return tor
    499         && !tr_torrentIsPrivate( tor )
    500         && !tor->pexDisabled;
    501 }
    502 
    503 void
    504 tr_torrentDisablePex( tr_torrent * tor, int disable )
    505 {
    506     assert( tor != NULL );
    507     assert( disable==0 || disable==1 );
    508 
    509     /* pex is ALWAYS disabled for private torrents */
    510     if( tor->info.isPrivate )
    511         disable = TRUE;
    512 
    513     tor->pexDisabled = disable;
     498        && tor->handle->isPexEnabled
     499        && !tr_torrentIsPrivate( tor );
    514500}
    515501
  • trunk/libtransmission/transmission.c

    r4285 r4306  
    126126
    127127    h->lock = tr_lockNew( );
    128 
     128    h->isPexEnabled = 1;
    129129    h->encryptionMode = TR_ENCRYPTION_PREFERRED;
    130130
     
    430430    return torrents;
    431431}
     432
     433/***
     434****
     435***/
     436
     437void
     438tr_setPexEnabled( tr_handle * handle, int isPexEnabled )
     439{
     440    handle->isPexEnabled = isPexEnabled ? 1 : 0;
     441}
     442
     443int
     444tr_isPexEnabled( const tr_handle * handle )
     445{
     446    return handle->isPexEnabled;
     447}
  • trunk/libtransmission/transmission.h

    r4286 r4306  
    479479
    480480
    481 /***********************************************************************
    482  * tr_torrentDisablePex
    483  ***********************************************************************
    484  * Disable or enable peer exchange for this torrent. Peer exchange is
    485  * enabled by default, except for private torrents where pex is
    486  * disabled and cannot be enabled.
    487  **********************************************************************/
    488 void tr_torrentDisablePex( tr_torrent *, int disable );
    489 int tr_torrentIsPexEnabled( const tr_torrent * );
     481/**
     482 * Set whether or not torrents are allowed to do peer exchanges.
     483 * By default, PEX is enabled.
     484 * PEX is always disabled in private torrents regardless of this.
     485 */
     486void tr_setPexEnabled( tr_handle *, int isEnabled );
     487
     488int tr_isPexEnabled( const tr_handle * );
    490489
    491490const tr_info * tr_torrentInfo( const tr_torrent * );
    492491
    493492void   tr_torrentSetFolder( tr_torrent *, const char * );
     493
    494494const char * tr_torrentGetFolder( const tr_torrent * );
    495495
Note: See TracChangeset for help on using the changeset viewer.