mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
Don't save or load cached peers for private torrents.
This commit is contained in:
@@ -171,11 +171,14 @@ static void fastResumeSave( tr_io_t * io )
|
||||
total = tor->uploadedCur + tor->uploadedPrev;
|
||||
fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file );
|
||||
|
||||
/* Write IPs and ports of connectable peers, if any */
|
||||
if( ( size = tr_peerGetConnectable( tor, &buf ) ) > 0 )
|
||||
if( !( TR_FLAG_PRIVATE & tor->info.flags ) )
|
||||
{
|
||||
fastResumeWriteData( FR_ID_PEERS, buf, size, 1, file );
|
||||
free( buf );
|
||||
/* Write IPs and ports of connectable peers, if any */
|
||||
if( ( size = tr_peerGetConnectable( tor, &buf ) ) > 0 )
|
||||
{
|
||||
fastResumeWriteData( FR_ID_PEERS, buf, size, 1, file );
|
||||
free( buf );
|
||||
}
|
||||
}
|
||||
|
||||
fclose( file );
|
||||
@@ -374,18 +377,20 @@ static int fastResumeLoad( tr_io_t * io )
|
||||
break;
|
||||
|
||||
case FR_ID_PEERS:
|
||||
{
|
||||
uint8_t * buf = malloc( len );
|
||||
if( 1 != fread( buf, len, 1, file ) )
|
||||
if( !( TR_FLAG_PRIVATE & tor->info.flags ) )
|
||||
{
|
||||
uint8_t * buf = malloc( len );
|
||||
if( 1 != fread( buf, len, 1, file ) )
|
||||
{
|
||||
free( buf );
|
||||
fclose( file );
|
||||
return 1;
|
||||
}
|
||||
tr_torrentAddCompact( tor, TR_PEER_FROM_CACHE,
|
||||
buf, len / 6 );
|
||||
free( buf );
|
||||
fclose( file );
|
||||
return 1;
|
||||
}
|
||||
tr_torrentAddCompact( tor, TR_PEER_FROM_CACHE, buf, len / 6 );
|
||||
free( buf );
|
||||
continue;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -201,6 +201,8 @@ struct tr_torrent_s
|
||||
uint64_t uploadedCur;
|
||||
uint64_t uploadedPrev;
|
||||
|
||||
uint8_t pexDisabled;
|
||||
|
||||
tr_stat_t stats[2];
|
||||
int statCur;
|
||||
|
||||
|
||||
@@ -223,7 +223,22 @@ void tr_peerDestroy( tr_peer_t * peer )
|
||||
|
||||
void tr_peerSetPrivate( tr_peer_t * peer, int private )
|
||||
{
|
||||
if( peer->private == private )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
peer->private = private;
|
||||
|
||||
if( !private )
|
||||
{
|
||||
peer->lastPex = 0;
|
||||
}
|
||||
|
||||
if( EXTENDED_HANDSHAKE == peer->extStatus )
|
||||
{
|
||||
sendExtended( peer->tor, peer, EXTENDED_HANDSHAKE_ID );
|
||||
}
|
||||
}
|
||||
|
||||
void tr_peerSetTorrent( tr_peer_t * peer, tr_torrent_t * tor )
|
||||
|
||||
@@ -151,6 +151,7 @@ makeAZHandshake( tr_torrent_t * tor, tr_peer_t * peer, int * buflen )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
/* XXX azureus sucks, we can't enable or disable pex after handshake */
|
||||
if( AZ_MSG_AZ_PEER_EXCHANGE == azmsgId( idx ) && peer->private )
|
||||
{
|
||||
/* no point in saying we can do pex if the torrent is private */
|
||||
|
||||
@@ -127,16 +127,13 @@ makeExtendedHandshake( tr_torrent_t * tor, tr_peer_t * peer, int * len )
|
||||
|
||||
/* create dict of supported extended messages */
|
||||
tr_bencInit( msgsval, TYPE_DICT );
|
||||
if( !peer->private )
|
||||
if( tr_bencDictAppendNofree( msgsval, "ut_pex", &pexval, NULL ) )
|
||||
{
|
||||
/* for public torrents advertise utorrent pex message */
|
||||
if( tr_bencDictAppendNofree( msgsval, "ut_pex", &pexval, NULL ) )
|
||||
{
|
||||
tr_bencFree( &val );
|
||||
return NULL;
|
||||
}
|
||||
tr_bencInitInt( pexval, EXTENDED_PEX_ID );
|
||||
tr_bencFree( &val );
|
||||
return NULL;
|
||||
}
|
||||
/* for public torrents advertise utorrent pex message */
|
||||
tr_bencInitInt( pexval, ( peer->private ? 0 : EXTENDED_PEX_ID ) );
|
||||
|
||||
/* our listening port */
|
||||
if( 0 < tor->publicPort )
|
||||
@@ -232,7 +229,7 @@ parseExtendedHandshake( tr_peer_t * peer, uint8_t * buf, int len )
|
||||
if( NULL != sub && TYPE_INT == sub->type )
|
||||
{
|
||||
peer->pexStatus = 0;
|
||||
if( !peer->private && 0x0 < sub->val.i && 0xff >= sub->val.i )
|
||||
if( 0x0 < sub->val.i && 0xff >= sub->val.i )
|
||||
{
|
||||
peer->pexStatus = sub->val.i;
|
||||
}
|
||||
|
||||
@@ -137,6 +137,8 @@ static tr_torrent_t * torrentRealInit( tr_handle_t * h, tr_torrent_t * tor,
|
||||
"%%%02x", inf->hash[i] );
|
||||
}
|
||||
|
||||
tor->pexDisabled = 0;
|
||||
|
||||
/* Block size: usually 16 ko, or less if we have to */
|
||||
tor->blockSize = MIN( inf->pieceSize, 1 << 14 );
|
||||
tor->blockCount = ( inf->totalSize + tor->blockSize - 1 ) /
|
||||
@@ -270,6 +272,32 @@ static void torrentReallyStop( tr_torrent_t * tor )
|
||||
tr_lockUnlock( &tor->lock );
|
||||
}
|
||||
|
||||
void tr_torrentDisablePex( tr_torrent_t * tor, int disable )
|
||||
{
|
||||
int ii;
|
||||
|
||||
if( TR_FLAG_PRIVATE & tor->info.flags )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tr_lockLock( &tor->lock );
|
||||
|
||||
if( tor->pexDisabled == disable )
|
||||
{
|
||||
tr_lockUnlock( &tor->lock );
|
||||
return;
|
||||
}
|
||||
|
||||
tor->pexDisabled = disable;
|
||||
for( ii = 0; ii < tor->peerCount; ii++ )
|
||||
{
|
||||
tr_peerSetPrivate( tor->peers[ii], disable );
|
||||
}
|
||||
|
||||
tr_lockUnlock( &tor->lock );
|
||||
}
|
||||
|
||||
int tr_getFinished( tr_torrent_t * tor )
|
||||
{
|
||||
if( tor->finished )
|
||||
@@ -635,7 +663,8 @@ void tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * peer )
|
||||
}
|
||||
}
|
||||
|
||||
tr_peerSetPrivate( peer, tor->info.flags & TR_FLAG_PRIVATE );
|
||||
tr_peerSetPrivate( peer, tor->info.flags & TR_FLAG_PRIVATE ||
|
||||
tor->pexDisabled );
|
||||
tr_peerSetTorrent( peer, tor );
|
||||
tor->peers[tor->peerCount++] = peer;
|
||||
}
|
||||
|
||||
@@ -223,6 +223,20 @@ tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
|
||||
tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
|
||||
int flags, int * error );
|
||||
|
||||
/***********************************************************************
|
||||
* 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_t *, int disable );
|
||||
|
||||
/***********************************************************************
|
||||
* tr_torrentScrape
|
||||
***********************************************************************
|
||||
* Return torrent metainfo.
|
||||
**********************************************************************/
|
||||
typedef struct tr_info_s tr_info_t;
|
||||
tr_info_t * tr_torrentInfo( tr_torrent_t * );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user