diff --git a/libtransmission/peer-mgr-private.h b/libtransmission/peer-mgr-private.h index 851f4fe02..095c340c1 100644 --- a/libtransmission/peer-mgr-private.h +++ b/libtransmission/peer-mgr-private.h @@ -49,9 +49,9 @@ typedef struct tr_peer /* the client name from the `v' string in LTEP's handshake dictionary */ char * client; - time_t clientSentPieceDataAt; time_t peerSentPieceDataAt; time_t chokeChangedAt; + time_t pieceDataActivityDate; struct tr_peermsgs * msgs; tr_publisher_tag msgsTag; diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 7365d0090..5dce62de9 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -520,15 +520,15 @@ tr_peerMgrFree( tr_peerMgr * manager ) { managerLock( manager ); - /* free the torrents. */ - tr_ptrArrayFree( manager->torrents, (PtrArrayForeachFunc)torrentDestructor ); - /* free the handshakes. Abort invokes handshakeDoneCB(), which removes * the item from manager->handshakes, so this is a little roundabout... */ while( !tr_ptrArrayEmpty( manager->incomingHandshakes ) ) tr_handshakeAbort( tr_ptrArrayNth( manager->incomingHandshakes, 0 ) ); tr_ptrArrayFree( manager->incomingHandshakes, NULL ); + /* free the torrents. */ + tr_ptrArrayFree( manager->torrents, (PtrArrayForeachFunc)torrentDestructor ); + managerUnlock( manager ); tr_free( manager ); } @@ -1466,7 +1466,7 @@ struct tr_connection double throughput; }; -#define LAISSEZ_FAIRE_PERIOD_SECS 60 +#define LAISSEZ_FAIRE_PERIOD_SECS 90 static int compareConnections( const void * va, const void * vb ) @@ -1500,16 +1500,23 @@ getWeakConnections( Torrent * t, int * setmeSize ) assert( atom != NULL ); - if( peer->doPurge ) + if( throughput >= 3 ) + isWeak = FALSE; + else if( peer->doPurge ) isWeak = TRUE; - if( peerIsSeed && clientIsSeed && (now-atom->time >= 30) ) /* pex time */ + else if( peerIsSeed && clientIsSeed && (now-atom->time >= 30) ) /* pex time */ isWeak = TRUE; else if( ( now - atom->time ) < LAISSEZ_FAIRE_PERIOD_SECS ) isWeak = FALSE; - else if( throughput >= 5 ) - isWeak = FALSE; +#if 0 else isWeak = TRUE; +#else + else if( now - peer->pieceDataActivityDate > 180 ) + isWeak = TRUE; + else + isWeak = FALSE; +#endif if( isWeak ) { @@ -1603,7 +1610,7 @@ reconnectPulse( void * vtorrent ) tr_peerIoAddrStr( &connections[i].peer->in_addr, connections[i].peer->port ), connections[i].throughput ); /* disconnect some peers */ - for( i=0; itorrent; tor->activityDate = tr_date( ); tor->downloadedCur += byteCount; + msgs->info->pieceDataActivityDate = time( NULL ); tr_rcTransferred( msgs->info->rateToClient, byteCount ); tr_rcTransferred( tor->download, byteCount ); tr_rcTransferred( tor->handle->download, byteCount ); @@ -983,6 +984,7 @@ peerGotBytes( tr_peermsgs * msgs, uint32_t byteCount ) tr_torrent * tor = msgs->torrent; tor->activityDate = tr_date( ); tor->uploadedCur += byteCount; + msgs->info->pieceDataActivityDate = time( NULL ); tr_rcTransferred( msgs->info->rateToPeer, byteCount ); tr_rcTransferred( tor->upload, byteCount ); tr_rcTransferred( tor->handle->upload, byteCount );