added tr_torrentSetPeerLimits(), tr_torrentGetPeerLimits(), tr_setGlobalPeerLimit(), tr_getGlobalPeerLimit()
This commit is contained in:
parent
f4211ce19d
commit
5c4f841c7e
|
@ -86,7 +86,7 @@ myDebug( const char * file, int line, const char * fmt, ... )
|
|||
|
||||
enum
|
||||
{
|
||||
TR_MAX_SOCKETS = 512,
|
||||
TR_MAX_PEER_SOCKETS = 512,
|
||||
|
||||
TR_MAX_OPEN_FILES = 16, /* real files, not sockets */
|
||||
|
||||
|
@ -454,7 +454,7 @@ tr_fdSocketClose( int s )
|
|||
void
|
||||
tr_fdInit( void )
|
||||
{
|
||||
int i, j, s[TR_MAX_SOCKETS];
|
||||
int i, j, s[TR_MAX_PEER_SOCKETS];
|
||||
|
||||
assert( gFd == NULL );
|
||||
|
||||
|
@ -462,7 +462,7 @@ tr_fdInit( void )
|
|||
gFd->lock = tr_lockNew( );
|
||||
|
||||
/* count the max number of sockets we can use */
|
||||
for( i=0; i<TR_MAX_SOCKETS; ++i )
|
||||
for( i=0; i<TR_MAX_PEER_SOCKETS; ++i )
|
||||
if( ( s[i] = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 )
|
||||
break;
|
||||
for( j=0; j<i; ++j )
|
||||
|
@ -491,3 +491,16 @@ tr_fdClose( void )
|
|||
tr_list_free( &reservedSockets, NULL );
|
||||
tr_free( gFd );
|
||||
}
|
||||
|
||||
void
|
||||
tr_fdSetPeerLimit( uint16_t n )
|
||||
{
|
||||
assert( gFd!=NULL && "tr_fdInit() must be called first!" );
|
||||
gFd->normalMax = n;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
tr_fdGetPeerLimit( void )
|
||||
{
|
||||
return gFd ? gFd->normalMax : TR_MAX_PEER_SOCKETS;
|
||||
}
|
||||
|
|
|
@ -85,3 +85,8 @@ void tr_fdSocketClose( int s );
|
|||
**********************************************************************/
|
||||
void tr_fdClose( void );
|
||||
|
||||
|
||||
void tr_fdSetPeerLimit( uint16_t n );
|
||||
|
||||
uint16_t tr_fdGetPeerLimit( void );
|
||||
|
||||
|
|
|
@ -160,6 +160,9 @@ struct tr_torrent
|
|||
unsigned int statCur : 1;
|
||||
unsigned int isRunning : 1;
|
||||
|
||||
uint16_t maxConnectedPeers;
|
||||
uint16_t maxUnchokedPeers;
|
||||
|
||||
tr_recheck_state recheckState;
|
||||
|
||||
time_t lastStatTime;
|
||||
|
|
|
@ -86,19 +86,12 @@ enum
|
|||
* we're we don't get piece data from a peer in this long */
|
||||
SNUBBED_SEC = 60,
|
||||
|
||||
/* arbitrary */
|
||||
MAX_CONNECTED_PEERS_PER_TORRENT = 50,
|
||||
|
||||
/* when many peers are available, keep idle ones this long */
|
||||
MIN_UPLOAD_IDLE_SECS = (60 * 3),
|
||||
|
||||
/* when few peers are available, keep idle ones this long */
|
||||
MAX_UPLOAD_IDLE_SECS = (60 * 10),
|
||||
|
||||
/* how many peers to unchoke per-torrent. */
|
||||
/* FIXME: make this user-configurable? */
|
||||
NUM_UNCHOKED_PEERS_PER_TORRENT = 16, /* arbitrary */
|
||||
|
||||
/* set this too high and there will be a lot of churn.
|
||||
* set it too low and you'll get peers too slowly */
|
||||
MAX_RECONNECTIONS_PER_PULSE = 2,
|
||||
|
@ -998,7 +991,7 @@ myHandshakeDoneCB( tr_handshake * handshake,
|
|||
tordbg( t, "banned peer %s tried to reconnect", tr_peerIoAddrStr(&atom->addr,atom->port) );
|
||||
tr_peerIoFree( io );
|
||||
}
|
||||
else if( tr_ptrArraySize( t->peers ) >= MAX_CONNECTED_PEERS_PER_TORRENT )
|
||||
else if( tr_ptrArraySize( t->peers ) >= t->tor->maxConnectedPeers )
|
||||
{
|
||||
tr_peerIoFree( io );
|
||||
}
|
||||
|
@ -1554,7 +1547,7 @@ rechoke( Torrent * t )
|
|||
|
||||
qsort( choke, size, sizeof(struct ChokeData), compareChoke );
|
||||
|
||||
for( i=0; i<size && unchoked<NUM_UNCHOKED_PEERS_PER_TORRENT; ++i ) {
|
||||
for( i=0; i<size && unchoked<t->tor->maxUnchokedPeers; ++i ) {
|
||||
choke[i].doUnchoke = 1;
|
||||
++unchoked;
|
||||
}
|
||||
|
@ -1665,7 +1658,7 @@ shouldPeerBeClosed( const Torrent * t, const tr_peer * peer, int peerCount )
|
|||
/* disconnect if it's been too long since piece data has been transferred.
|
||||
* this is on a sliding scale based on number of available peers... */
|
||||
if( 1 ) {
|
||||
const int relaxStrictnessIfFewerThanN = (int)((MAX_CONNECTED_PEERS_PER_TORRENT * 0.9) + 0.5);
|
||||
const int relaxStrictnessIfFewerThanN = (int)((tor->maxConnectedPeers * 0.9) + 0.5);
|
||||
/* if we have >= relaxIfFewerThan, strictness is 100%.
|
||||
* if we have zero connections, strictness is 0% */
|
||||
const double strictness = peerCount >= relaxStrictnessIfFewerThanN
|
||||
|
@ -1820,8 +1813,8 @@ reconnectPulse( void * vtorrent )
|
|||
|
||||
/* add some new ones */
|
||||
addMax = tr_ptrArraySize(t->pool)
|
||||
? MAX_RECONNECTIONS_PER_PULSE
|
||||
: MAX_CONNECTED_PEERS_PER_TORRENT;
|
||||
? MAX_RECONNECTIONS_PER_PULSE
|
||||
: t->tor->maxConnectedPeers;
|
||||
|
||||
for( i=0; i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
|
||||
{
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
#include "trevent.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define DEFAULT_MAX_CONNECTED_PEERS 50
|
||||
#define DEFAULT_MAX_UNCHOKED_PEERS 16
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
@ -272,6 +275,8 @@ torrentRealInit( tr_handle * h,
|
|||
|
||||
tor->handle = h;
|
||||
tor->pexDisabled = 0;
|
||||
tor->maxConnectedPeers = DEFAULT_MAX_CONNECTED_PEERS;
|
||||
tor->maxUnchokedPeers = DEFAULT_MAX_UNCHOKED_PEERS;
|
||||
|
||||
/**
|
||||
* Decide on a block size. constraints:
|
||||
|
@ -1367,6 +1372,32 @@ tr_torrentSetFileDLs ( tr_torrent * tor,
|
|||
****
|
||||
***/
|
||||
|
||||
void
|
||||
tr_torrentSetPeerLimits( tr_torrent * tor,
|
||||
uint16_t maxConnectedPeers,
|
||||
uint16_t maxUnchokedPeers )
|
||||
{
|
||||
if( maxConnectedPeers )
|
||||
tor->maxConnectedPeers = maxConnectedPeers;
|
||||
if( maxUnchokedPeers )
|
||||
tor->maxUnchokedPeers = maxUnchokedPeers;
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentGetPeerLimits( const tr_torrent * tor,
|
||||
uint16_t * maxConnectedPeers,
|
||||
uint16_t * maxUnchokedPeers )
|
||||
{
|
||||
if( maxConnectedPeers )
|
||||
*maxConnectedPeers = tor->maxConnectedPeers;
|
||||
if( maxUnchokedPeers )
|
||||
*maxUnchokedPeers = tor->maxUnchokedPeers;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
int _tr_block( const tr_torrent * tor, int index, int begin )
|
||||
{
|
||||
const tr_info * inf = &tor->info;
|
||||
|
|
|
@ -282,6 +282,20 @@ tr_getGlobalSpeedLimit( tr_handle * h,
|
|||
: h->download );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tr_setGlobalPeerLimit( tr_handle * handle UNUSED,
|
||||
uint16_t maxGlobalPeers )
|
||||
{
|
||||
tr_fdSetPeerLimit( maxGlobalPeers );
|
||||
}
|
||||
|
||||
uint16_t
|
||||
tr_getGlobalPeerLimit( const tr_handle * handle UNUSED )
|
||||
{
|
||||
return tr_fdGetPeerLimit( );
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentRates( tr_handle * h, float * toClient, float * toPeer )
|
||||
{
|
||||
|
|
|
@ -273,6 +273,27 @@ void tr_getGlobalSpeedLimit( tr_handle * handle,
|
|||
int * setme_is_enabled,
|
||||
int * setme_KiBsec );
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*** Peer Limits
|
||||
**/
|
||||
|
||||
void tr_torrentSetPeerLimits( tr_torrent * tor,
|
||||
uint16_t maxConnectedPeers,
|
||||
uint16_t maxUnchokedPeers );
|
||||
|
||||
void tr_torrentGetPeerLimits( const tr_torrent * tor,
|
||||
uint16_t * maxConnectedPeers,
|
||||
uint16_t * maxUnchokedPeers );
|
||||
|
||||
void tr_setGlobalPeerLimit( tr_handle * handle,
|
||||
uint16_t maxGlobalPeers );
|
||||
|
||||
uint16_t tr_getGlobalPeerLimit( const tr_handle * handle );
|
||||
|
||||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Torrent Priorities
|
||||
**********************************************************************/
|
||||
|
|
Loading…
Reference in New Issue