(trunk libT) #2609 "Leave 5% of connection slots for incoming connections" -- implemented in trunk for 2.00

This commit is contained in:
Charles Kerr 2010-04-29 03:21:54 +00:00
parent 61e2493d00
commit 97affa46a9
1 changed files with 3 additions and 1 deletions

View File

@ -3343,13 +3343,15 @@ getPeerCandidates( tr_session * session, int * candidateCount )
struct peer_candidate * walk;
const time_t now = tr_time( );
const uint64_t now_msec = tr_date( );
/* leave 5% of connection slots for incoming connections -- ticket #2609 */
const int maxCandidates = tr_sessionGetPeerLimit( session ) * 0.95;
/* don't start any new handshakes if we're full up */
n = 0;
tor= NULL;
while(( tor = tr_torrentNext( session, tor )))
n += tr_ptrArraySize( &tor->torrentPeers->peers );
if( tr_sessionGetPeerLimit( session ) <= n ) {
if( maxCandidates <= n ) {
*candidateCount = 0;
return NULL;
}