]> granicus.if.org Git - transmission/commitdiff
(trunk libT) fix bug which caused libtransmission to hold onto nonproductive peers...
authorCharles Kerr <charles@transmissionbt.com>
Thu, 11 Dec 2008 07:04:46 +0000 (07:04 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Thu, 11 Dec 2008 07:04:46 +0000 (07:04 +0000)
libtransmission/peer-mgr-private.h
libtransmission/peer-mgr.c
libtransmission/peer-msgs.c

index 689c3f2b2209e159dd1f74c79c87c47644d48da3..aa0dc7e2ee860a9006acd0a9b827f4b3d1c06c9e 100644 (file)
@@ -62,9 +62,7 @@ typedef struct tr_peer
     /* the client name from the `v' string in LTEP's handshake dictionary */
     char                   * client;
 
-    time_t                   peerSentPieceDataAt;
     time_t                   chokeChangedAt;
-    time_t                   pieceDataActivityDate;
 
     struct tr_peermsgs     * msgs;
     tr_publisher_tag         msgsTag;
index 39fc17f85d652a061c09c0a4bf8e54a1a9a50fec..64b5dc07cdc38f479e4272cf9ef52ce838835210 100644 (file)
@@ -48,10 +48,10 @@ enum
     REFILL_PERIOD_MSEC = 333,
 
     /* when many peers are available, keep idle ones this long */
-    MIN_UPLOAD_IDLE_SECS = ( 60 * 3 ),
+    MIN_UPLOAD_IDLE_SECS = ( 30 ),
 
     /* when few peers are available, keep idle ones this long */
-    MAX_UPLOAD_IDLE_SECS = ( 60 * 10 ),
+    MAX_UPLOAD_IDLE_SECS = ( 60 * 5 ),
 
     /* how frequently to decide which peers live and die */
     RECONNECT_PERIOD_MSEC = ( 2 * 1000 ),
@@ -1018,7 +1018,8 @@ peerCallbackFunc( void * vpeer,
             /* update our atom */
             if( peer ) {
                 struct peer_atom * a = getExistingAtom( t, &peer->addr );
-                a->piece_data_time = now;
+                if( e->wasPieceData )
+                    a->piece_data_time = now;
             }
 
             break;
@@ -1056,7 +1057,8 @@ peerCallbackFunc( void * vpeer,
             /* update our atom */
             if( peer ) {
                 struct peer_atom * a = getExistingAtom( t, &peer->addr );
-                a->piece_data_time = now;
+                if( e->wasPieceData )
+                    a->piece_data_time = now;
             }
 
             break;
@@ -1240,6 +1242,7 @@ myHandshakeDoneCB( tr_handshake *  handshake,
         ensureAtomExists( t, addr, port, 0, TR_PEER_FROM_INCOMING );
         atom = getExistingAtom( t, addr );
         atom->time = time( NULL );
+        atom->piece_data_time = 0;
 
         if( atom->myflags & MYFLAG_BANNED )
         {
@@ -2027,9 +2030,9 @@ shouldPeerBeClosed( const Torrent * t,
             : peerCount / (float)relaxStrictnessIfFewerThanN;
         const int lo = MIN_UPLOAD_IDLE_SECS;
         const int hi = MAX_UPLOAD_IDLE_SECS;
-        const int limit = lo + ( ( hi - lo ) * strictness );
-        const time_t then = peer->pieceDataActivityDate;
-        const int idleTime = then ? ( now - then ) : 0;
+        const int limit = hi - ( ( hi - lo ) * strictness );
+        const int idleTime = now - MAX( atom->time, atom->piece_data_time );
+/*fprintf( stderr, "strictness is %.3f, limit is %d seconds... time since connect is %d, time since piece is %d ... idleTime is %d, doPurge is %d\n", (double)strictness, limit, (int)(now - atom->time), (int)(now - atom->piece_data_time), idleTime, idleTime > limit );*/
         if( idleTime > limit ) {
             tordbg( t, "purging peer %s because it's been %d secs since we shared anything",
                        tr_peerIoAddrStr( &atom->addr, atom->port ), idleTime );
@@ -2219,7 +2222,7 @@ reconnectPulse( void * vtorrent )
         for( i = 0; i < nBad; ++i ) {
             tr_peer * peer = connections[i];
             struct peer_atom * atom = getExistingAtom( t, &peer->addr );
-            if( peer->pieceDataActivityDate )
+            if( atom->piece_data_time )
                 atom->numFails = 0;
             else
                 ++atom->numFails;
index 848454f66732ab476d643b8b1bd73e09eb945cf2..05c9db4f03fd0f5a0bbfc3056f1d697210eea174 100644 (file)
@@ -1669,7 +1669,6 @@ clientGotBlock( tr_peermsgs *               msgs,
     ***  Save the block
     **/
 
-    msgs->info->peerSentPieceDataAt = time( NULL );
     if(( err = tr_ioWrite( tor, req->index, req->offset, req->length, data )))
         return err;