1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-03 21:12:05 +00:00

test patch for the "router death" bug: throttle the number of connections made per second

This commit is contained in:
Charles Kerr 2008-01-11 18:13:09 +00:00
parent 7b4c423054
commit 876cd4c413

View file

@ -73,9 +73,6 @@ enum
/* how frequently to change which peers are choked */
RECHOKE_PERIOD_MSEC = (10 * 1000),
/* how frequently to decide which peers live and die */
RECONNECT_PERIOD_MSEC = (5 * 1000),
/* how frequently to refill peers' request lists */
REFILL_PERIOD_MSEC = 666,
@ -89,12 +86,19 @@ enum
/* when few peers are available, keep idle ones this long */
MAX_UPLOAD_IDLE_SECS = (60 * 10),
/* if this * RECONNECT_PERIOD_MSEC is too high, routers die.
* if this * RECONNECT_PERIOD_MSEC it too low, peers come slow. */
/* how frequently to decide which peers live and die */
RECONNECT_PERIOD_MSEC = (4 * 1000),
/* max # of peers to ask fer per torrent per reconnect pulse */
MAX_RECONNECTIONS_PER_PULSE = 16,
/* max number of peers to ask for per second overall.
* this throttle is to avoid overloading the router */
MAX_CONNECTIONS_PER_SECOND = 64,
/* corresponds to ut_pex's added.f flags */
ADDED_F_ENCRYPTION_FLAG = 1,
/* corresponds to ut_pex's added.f flags */
ADDED_F_SEED_FLAG = 2,
@ -1478,7 +1482,7 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
stat->clientIsInterested = peer->clientIsInterested;
stat->isIncoming = tr_peerIoIsIncoming( peer->io );
stat->isDownloadingFrom = stat->clientIsInterested && !stat->clientIsChoked;
stat->isUploadingTo = stat->peerIsInterested && !stat->peerIsChoked;
stat->isUploadingTo = stat->peerIsInterested && !stat->peerIsChoked;
pch = stat->flagStr;
if( t->optimistic == peer ) *pch++ = 'O';
@ -1840,9 +1844,19 @@ static int
reconnectPulse( void * vtorrent )
{
Torrent * t = vtorrent;
static time_t prevTime = 0;
static int newConnectionsThisSecond = 0;
time_t now;
torrentLock( t );
now = time( NULL );
if( prevTime != now )
{
prevTime = now;
newConnectionsThisSecond = 0;
}
if( !t->isRunning )
{
removeAllPeers( t );
@ -1875,7 +1889,9 @@ reconnectPulse( void * vtorrent )
}
/* add some new ones */
for( i=0; i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i )
for( i=0; i < nCandidates
&& i < MAX_RECONNECTIONS_PER_PULSE
&& newConnectionsThisSecond < MAX_CONNECTIONS_PER_SECOND; ++i )
{
tr_peerMgr * mgr = t->manager;
struct peer_atom * atom = candidates[i];
@ -1898,6 +1914,8 @@ reconnectPulse( void * vtorrent )
assert( tr_peerIoGetTorrentHash( io ) != NULL );
++newConnectionsThisSecond;
tr_ptrArrayInsertSorted( t->outgoingHandshakes, handshake, handshakeCompare );
}