replace the per-torrent PEX setting with a global one, as per discussion with SoftwareElves and BentMyWookie
This commit is contained in:
parent
63e7a8597e
commit
401cfbdb6b
|
@ -57,8 +57,6 @@ struct tor
|
|||
int id;
|
||||
uint8_t hash[SHA_DIGEST_LENGTH];
|
||||
tr_torrent * tor;
|
||||
int pexset;
|
||||
int pex;
|
||||
RB_ENTRY( tor ) idlinks;
|
||||
RB_ENTRY( tor ) hashlinks;
|
||||
};
|
||||
|
@ -373,27 +371,15 @@ torrent_get_port( void )
|
|||
void
|
||||
torrent_set_pex( int pex )
|
||||
{
|
||||
struct tor * tor;
|
||||
|
||||
assert( NULL != gl_handle );
|
||||
assert( !gl_exiting );
|
||||
|
||||
if( pex == gl_pex )
|
||||
if( pex != gl_pex )
|
||||
{
|
||||
return;
|
||||
}
|
||||
gl_pex = pex;
|
||||
tr_setPexEnabled( gl_handle, gl_pex );
|
||||
|
||||
for( tor = iterate( NULL ); NULL != tor; tor = iterate( tor ) )
|
||||
{
|
||||
if( tor->pexset )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
tr_torrentDisablePex( tor->tor, !gl_pex );
|
||||
savestate( );
|
||||
}
|
||||
|
||||
savestate();
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -579,16 +565,6 @@ opentor( const char * path, const char * hash, uint8_t * data, size_t size,
|
|||
inf = tr_torrentInfo( tor->tor );
|
||||
memcpy( tor->hash, inf->hash, sizeof tor->hash );
|
||||
|
||||
if( inf->isPrivate )
|
||||
{
|
||||
tor->pexset = 1;
|
||||
tor->pex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tr_torrentDisablePex( tor->tor, !gl_pex );
|
||||
}
|
||||
|
||||
found = RB_INSERT( tortree, &gl_tree, tor );
|
||||
assert( NULL == found );
|
||||
found = RB_INSERT( hashtree, &gl_hashes, tor );
|
||||
|
@ -796,10 +772,8 @@ loadstate( void )
|
|||
num = tr_bencDictFind( dict, "pex" );
|
||||
if( NULL != num && TYPE_INT == num->type )
|
||||
{
|
||||
tor->pexset = 1;
|
||||
tor->pex = ( num->val.i ? 1 : 0 );
|
||||
fprintf( stderr, "warning: obsolete command 'pex'\n" );
|
||||
}
|
||||
tr_torrentDisablePex( tor->tor, !( tor->pexset ? tor->pex : gl_pex ) );
|
||||
|
||||
num = tr_bencDictFind( dict, "paused" );
|
||||
if( NULL != num && TYPE_INT == num->type && !num->val.i )
|
||||
|
@ -817,7 +791,7 @@ savestate( void )
|
|||
benc_val_t top, * list, * tor;
|
||||
struct tor * ii;
|
||||
uint8_t * buf;
|
||||
int len, pexset;
|
||||
int len;
|
||||
|
||||
tr_bencInit( &top, TYPE_DICT );
|
||||
if( tr_bencDictReserve( &top, 9 ) )
|
||||
|
@ -861,8 +835,7 @@ savestate( void )
|
|||
tr_bencInit( tor, TYPE_DICT );
|
||||
inf = tr_torrentInfo( ii->tor );
|
||||
st = tr_torrentStat( ii->tor );
|
||||
pexset = ( ii->pexset && !inf->isPrivate );
|
||||
if( tr_bencDictReserve( tor, ( pexset ? 4 : 3 ) ) )
|
||||
if( tr_bencDictReserve( tor, 3 ) )
|
||||
{
|
||||
goto nomem;
|
||||
}
|
||||
|
@ -872,10 +845,6 @@ savestate( void )
|
|||
!TR_STATUS_IS_ACTIVE( st->status ) );
|
||||
tr_bencInitStr( tr_bencDictAdd( tor, "directory" ),
|
||||
tr_torrentGetFolder( ii->tor ), -1, 1 );
|
||||
if( pexset )
|
||||
{
|
||||
tr_bencInitInt( tr_bencDictAdd( tor, "pex" ), ii->pex );
|
||||
}
|
||||
}
|
||||
|
||||
buf = ( uint8_t * )tr_bencSave( &top, &len );
|
||||
|
|
13
gtk/main.c
13
gtk/main.c
|
@ -141,8 +141,6 @@ static void
|
|||
initializeFromPrefs( struct cbdata * cbdata );
|
||||
static void
|
||||
prefschanged( TrCore * core, const char * key, gpointer data );
|
||||
static void
|
||||
setpex( tr_torrent * tor, void * arg );
|
||||
static gboolean
|
||||
updatemodel(gpointer gdata);
|
||||
static GList *
|
||||
|
@ -733,18 +731,11 @@ prefschanged( TrCore * core UNUSED, const char * key, gpointer data )
|
|||
}
|
||||
else if( !strcmp( key, PREF_KEY_PEX ) )
|
||||
{
|
||||
gboolean enabled = pref_flag_get( key );
|
||||
tr_torrentIterate( tr, setpex, &enabled );
|
||||
const gboolean enabled = pref_flag_get( key );
|
||||
tr_setPexEnabled( tr_core_handle( cbdata->core ), enabled );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
setpex( tr_torrent * tor, void * arg )
|
||||
{
|
||||
const gboolean * val = arg;
|
||||
tr_torrentDisablePex( tor, !*val );
|
||||
}
|
||||
|
||||
gboolean
|
||||
updatemodel(gpointer gdata) {
|
||||
struct cbdata *data = gdata;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "sexy-icon-entry.h"
|
||||
|
@ -156,7 +155,7 @@ sexy_icon_entry_class_init(SexyIconEntryClass *klass)
|
|||
}
|
||||
|
||||
static void
|
||||
sexy_icon_entry_editable_init(GtkEditableClass *iface)
|
||||
sexy_icon_entry_editable_init(GtkEditableClass *iface G_GNUC_UNUSED )
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -300,7 +299,7 @@ get_text_area_size(SexyIconEntry *entry, GtkAllocation *alloc)
|
|||
static void
|
||||
get_icon_allocation(SexyIconEntry *icon_entry,
|
||||
gboolean left,
|
||||
GtkAllocation *widget_alloc,
|
||||
GtkAllocation *widget_alloc G_GNUC_UNUSED,
|
||||
GtkAllocation *text_area_alloc,
|
||||
GtkAllocation *allocation,
|
||||
SexyIconEntryPosition *icon_pos)
|
||||
|
@ -647,7 +646,7 @@ sexy_icon_entry_expose(GtkWidget *widget, GdkEventExpose *event)
|
|||
}
|
||||
|
||||
static void
|
||||
update_icon(GObject *obj, GParamSpec *param, SexyIconEntry *entry)
|
||||
update_icon(GObject *obj G_GNUC_UNUSED, GParamSpec *param, SexyIconEntry *entry)
|
||||
{
|
||||
if (param != NULL)
|
||||
{
|
||||
|
|
|
@ -164,7 +164,6 @@ static TrTorrent *
|
|||
maketorrent( tr_torrent * handle )
|
||||
{
|
||||
TrTorrent * tor = g_object_new( TR_TORRENT_TYPE, NULL );
|
||||
tr_torrentDisablePex( handle, !pref_flag_get( PREF_KEY_PEX ) );
|
||||
tor->handle = handle;
|
||||
return tor;
|
||||
}
|
||||
|
|
|
@ -293,12 +293,6 @@ tr_fastResumeSave( const tr_torrent * tor )
|
|||
tr_free( buf );
|
||||
}
|
||||
|
||||
if( TRUE ) /* FR_ID_PEX */
|
||||
{
|
||||
const char flag = tor->pexDisabled ? 'f' : 't';
|
||||
fastResumeWriteData( FR_ID_PEX, &flag, 1, 1, file );
|
||||
}
|
||||
|
||||
if( TRUE ) /* FR_ID_RUN */
|
||||
{
|
||||
const char is_running = tor->isRunning ? 't' : 'f';
|
||||
|
@ -360,7 +354,6 @@ internalIdToPublicBitfield( uint8_t id )
|
|||
case FR_ID_CORRUPT: ret = TR_FR_CORRUPT; break;
|
||||
case FR_ID_PEERS: ret = TR_FR_PEERS; break;
|
||||
case FR_ID_DESTINATION: ret = TR_FR_DESTINATION; break;
|
||||
case FR_ID_PEX: ret = TR_FR_PEX; break;
|
||||
case FR_ID_MAX_PEERS: ret = TR_FR_MAX_PEERS; break;
|
||||
case FR_ID_MAX_UNCHOKED: ret = TR_FR_MAX_UNCHOKED; break;
|
||||
}
|
||||
|
@ -551,15 +544,6 @@ parseRun( tr_torrent * tor, const uint8_t * buf, uint32_t len )
|
|||
return TR_FR_RUN;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
parsePex( tr_torrent * tor, const uint8_t * buf, uint32_t len )
|
||||
{
|
||||
if( len != 1 )
|
||||
return 0;
|
||||
tor->pexDisabled = *buf!='t';
|
||||
return TR_FR_PEX;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
parsePeers( tr_torrent * tor, const uint8_t * buf, uint32_t len )
|
||||
{
|
||||
|
@ -619,7 +603,6 @@ parseVersion1( tr_torrent * tor, const uint8_t * buf, const uint8_t * end,
|
|||
case FR_ID_PEERS: ret |= parsePeers( tor, buf, len ); break;
|
||||
case FR_ID_MAX_PEERS: ret |= parseConnections( tor, buf, len ); break;
|
||||
case FR_ID_MAX_UNCHOKED: ret |= parseUnchoked( tor, buf, len ); break;
|
||||
case FR_ID_PEX: ret |= parsePex( tor, buf, len ); break;
|
||||
case FR_ID_DESTINATION: ret |= parseDestination( tor, buf, len ); break;
|
||||
default: tr_dbg( "Skipping unknown resume code %d", (int)id ); break;
|
||||
}
|
||||
|
|
|
@ -38,9 +38,8 @@ enum
|
|||
TR_FR_SPEEDLIMIT = (1<<6),
|
||||
TR_FR_RUN = (1<<7),
|
||||
TR_FR_DESTINATION = (1<<8),
|
||||
TR_FR_PEX = (1<<9),
|
||||
TR_FR_MAX_PEERS = (1<<10),
|
||||
TR_FR_MAX_UNCHOKED = (1<<11),
|
||||
TR_FR_MAX_PEERS = (1<<9),
|
||||
TR_FR_MAX_UNCHOKED = (1<<10)
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,6 +78,8 @@ tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
|
|||
|
||||
void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
|
||||
|
||||
int tr_torrentAllowsPex( const tr_torrent * );
|
||||
|
||||
/* get the index of this piece's first block */
|
||||
#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
|
||||
|
||||
|
@ -162,7 +164,6 @@ struct tr_torrent
|
|||
tr_torrent_status_func * status_func;
|
||||
void * status_func_user_data;
|
||||
|
||||
unsigned int pexDisabled : 1;
|
||||
unsigned int statCur : 1;
|
||||
unsigned int isRunning : 1;
|
||||
|
||||
|
@ -187,7 +188,8 @@ struct tr_handle
|
|||
tr_torrent * torrentList;
|
||||
|
||||
char * tag;
|
||||
int isPortSet;
|
||||
unsigned int isPortSet : 1;
|
||||
unsigned int isPexEnabled : 1;
|
||||
|
||||
char useUploadLimit;
|
||||
char useDownloadLimit;
|
||||
|
|
|
@ -1649,7 +1649,7 @@ shouldPeerBeClosed( const Torrent * t, const tr_peer * peer, int peerCount )
|
|||
if( 1 ) {
|
||||
const int clientIsSeed = tr_torrentIsSeed( tor );
|
||||
const int peerIsSeed = atom->flags & ADDED_F_SEED_FLAG;
|
||||
if( peerIsSeed && clientIsSeed && ( !tr_torrentIsPexEnabled(tor) || (now-atom->time>=30) ) ) {
|
||||
if( peerIsSeed && clientIsSeed && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30) ) ) {
|
||||
tordbg( t, "purging peer %s because we're both seeds", tr_peerIoAddrStr(&atom->addr,atom->port) );
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -731,7 +731,7 @@ sendLtepHandshake( tr_peermsgs * msgs )
|
|||
msgs->clientSentLtepHandshake = 1;
|
||||
|
||||
/* decide if we want to advertise pex support */
|
||||
if( !tr_torrentIsPexEnabled( msgs->torrent ) )
|
||||
if( !tr_torrentAllowsPex( msgs->torrent ) )
|
||||
pex = 0;
|
||||
else if( msgs->peerSentLtepHandshake )
|
||||
pex = msgs->peerSupportsPex ? 1 : 0;
|
||||
|
@ -823,7 +823,7 @@ parseUtPex( tr_peermsgs * msgs, int msglen, struct evbuffer * inbuf )
|
|||
benc_val_t val, * sub;
|
||||
uint8_t * tmp;
|
||||
|
||||
if( !tr_torrentIsPexEnabled( msgs->torrent ) ) /* no sharing! */
|
||||
if( !tr_torrentAllowsPex( msgs->torrent ) ) /* no sharing! */
|
||||
return;
|
||||
|
||||
tmp = tr_new( uint8_t, msglen );
|
||||
|
@ -1710,7 +1710,7 @@ pexElementCb( void * vpex, void * userData )
|
|||
static void
|
||||
sendPex( tr_peermsgs * msgs )
|
||||
{
|
||||
if( msgs->peerSupportsPex && tr_torrentIsPexEnabled( msgs->torrent ) )
|
||||
if( msgs->peerSupportsPex && tr_torrentAllowsPex( msgs->torrent ) )
|
||||
{
|
||||
int i;
|
||||
tr_pex * newPex = NULL;
|
||||
|
|
|
@ -270,7 +270,6 @@ torrentRealInit( tr_handle * h,
|
|||
tr_globalLock( h );
|
||||
|
||||
tor->handle = h;
|
||||
tor->pexDisabled = 0;
|
||||
|
||||
/**
|
||||
* Decide on a block size. constraints:
|
||||
|
@ -493,24 +492,11 @@ tr_torrentIsPrivate( const tr_torrent * tor )
|
|||
}
|
||||
|
||||
int
|
||||
tr_torrentIsPexEnabled( const tr_torrent * tor )
|
||||
tr_torrentAllowsPex( const tr_torrent * tor )
|
||||
{
|
||||
return tor
|
||||
&& !tr_torrentIsPrivate( tor )
|
||||
&& !tor->pexDisabled;
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentDisablePex( tr_torrent * tor, int disable )
|
||||
{
|
||||
assert( tor != NULL );
|
||||
assert( disable==0 || disable==1 );
|
||||
|
||||
/* pex is ALWAYS disabled for private torrents */
|
||||
if( tor->info.isPrivate )
|
||||
disable = TRUE;
|
||||
|
||||
tor->pexDisabled = disable;
|
||||
&& tor->handle->isPexEnabled
|
||||
&& !tr_torrentIsPrivate( tor );
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -125,7 +125,7 @@ tr_handle * tr_init( const char * tag )
|
|||
return NULL;
|
||||
|
||||
h->lock = tr_lockNew( );
|
||||
|
||||
h->isPexEnabled = 1;
|
||||
h->encryptionMode = TR_ENCRYPTION_PREFERRED;
|
||||
|
||||
tr_netInit(); /* must go before tr_eventInit */
|
||||
|
@ -429,3 +429,19 @@ tr_loadTorrents ( tr_handle * h,
|
|||
tr_inf( "Loaded %d torrents from disk", *setmeCount );
|
||||
return torrents;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
void
|
||||
tr_setPexEnabled( tr_handle * handle, int isPexEnabled )
|
||||
{
|
||||
handle->isPexEnabled = isPexEnabled ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
tr_isPexEnabled( const tr_handle * handle )
|
||||
{
|
||||
return handle->isPexEnabled;
|
||||
}
|
||||
|
|
|
@ -478,19 +478,19 @@ tr_torrent ** tr_loadTorrents ( tr_handle * h,
|
|||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* tr_torrentDisablePex
|
||||
***********************************************************************
|
||||
* Disable or enable peer exchange for this torrent. Peer exchange is
|
||||
* enabled by default, except for private torrents where pex is
|
||||
* disabled and cannot be enabled.
|
||||
**********************************************************************/
|
||||
void tr_torrentDisablePex( tr_torrent *, int disable );
|
||||
int tr_torrentIsPexEnabled( const tr_torrent * );
|
||||
/**
|
||||
* Set whether or not torrents are allowed to do peer exchanges.
|
||||
* By default, PEX is enabled.
|
||||
* PEX is always disabled in private torrents regardless of this.
|
||||
*/
|
||||
void tr_setPexEnabled( tr_handle *, int isEnabled );
|
||||
|
||||
int tr_isPexEnabled( const tr_handle * );
|
||||
|
||||
const tr_info * tr_torrentInfo( const tr_torrent * );
|
||||
|
||||
void tr_torrentSetFolder( tr_torrent *, const char * );
|
||||
|
||||
const char * tr_torrentGetFolder( const tr_torrent * );
|
||||
|
||||
/***********************************************************************
|
||||
|
|
Loading…
Reference in New Issue