diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index e5f5e12a2..d69da0e5e 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -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; imanager; 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 ); }