Changeset 12028


Ignore:
Timestamp:
Feb 24, 2011, 3:13:48 PM (11 years ago)
Author:
jordan
Message:

(2.2x) backport r11980, r11981, r11982 for #3372 "What happened with closing idle peers?"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2x/libtransmission/peer-mgr.c

    r11783 r12028  
    27752775***/
    27762776
    2777 typedef enum
    2778 {
    2779     TR_CAN_KEEP,
    2780     TR_CAN_CLOSE,
    2781     TR_MUST_CLOSE,
    2782 }
    2783 tr_close_type_t;
    2784 
    2785 static tr_close_type_t
     2777static tr_bool
    27862778shouldPeerBeClosed( const Torrent    * t,
    27872779                    const tr_peer    * peer,
     
    27972789        tordbg( t, "purging peer %s because its doPurge flag is set",
    27982790                tr_atomAddrStr( atom ) );
    2799         return TR_MUST_CLOSE;
     2791        return TRUE;
    28002792    }
    28012793
     
    28222814            tordbg( t, "purging peer %s because we're both seeds",
    28232815                    tr_atomAddrStr( atom ) );
    2824             return TR_MUST_CLOSE;
     2816            return TRUE;
    28252817        }
    28262818    }
     
    28432835            tordbg( t, "purging peer %s because it's been %d secs since we shared anything",
    28442836                       tr_atomAddrStr( atom ), idleTime );
    2845             return TR_CAN_CLOSE;
    2846         }
    2847     }
    2848 
    2849     return TR_CAN_KEEP;
    2850 }
    2851 
    2852 static void sortPeersByLivelinessReverse( tr_peer ** peers, void ** clientData, int n, uint64_t now );
     2837            return TRUE;
     2838        }
     2839    }
     2840
     2841    return FALSE;
     2842}
    28532843
    28542844static tr_peer **
    2855 getPeersToClose( Torrent * t, tr_close_type_t closeType,
    2856                  const uint64_t now_msec, const time_t now_sec,
    2857                  int * setmeSize )
     2845getPeersToClose( Torrent * t, const time_t now_sec, int * setmeSize )
    28582846{
    28592847    int i, peerCount, outsize;
     
    28642852
    28652853    for( i = outsize = 0; i < peerCount; ++i )
    2866         if( shouldPeerBeClosed( t, peers[i], peerCount, now_sec ) == closeType )
     2854        if( shouldPeerBeClosed( t, peers[i], peerCount, now_sec ) )
    28672855            ret[outsize++] = peers[i];
    2868 
    2869     sortPeersByLivelinessReverse ( ret, NULL, outsize, now_msec );
    28702856
    28712857    *setmeSize = outsize;
     
    29342920
    29352921static void
    2936 closeBadPeers( Torrent * t, const uint64_t now_msec, const time_t now_sec )
    2937 {
    2938     if( !t->isRunning )
    2939     {
    2940         removeAllPeers( t );
    2941     }
    2942     else
    2943     {
    2944         int i;
    2945         int mustCloseCount;
    2946         struct tr_peer ** mustClose;
    2947 
    2948         /* disconnect the really bad peers */
    2949         mustClose = getPeersToClose( t, TR_MUST_CLOSE, now_msec, now_sec, &mustCloseCount );
    2950         for( i=0; i<mustCloseCount; ++i )
    2951             closePeer( t, mustClose[i] );
    2952         tr_free( mustClose );
    2953     }
     2922closeBadPeers( Torrent * t, const time_t now_sec )
     2923{
     2924    int i;
     2925    int peerCount;
     2926    struct tr_peer ** peers = getPeersToClose( t, now_sec, &peerCount );
     2927    for( i=0; i<peerCount; ++i )
     2928        closePeer( t, peers[i] );
     2929    tr_free( peers );
    29542930}
    29552931
     
    29852961
    29862962    return 0;
    2987 }
    2988 
    2989 static int
    2990 comparePeerLivelinessReverse( const void * va, const void * vb )
    2991 {
    2992     return -comparePeerLiveliness (va, vb);
    29932963}
    29942964
     
    30383008{
    30393009    sortPeersByLivelinessImpl( peers, clientData, n, now, comparePeerLiveliness );
    3040 }
    3041 
    3042 static void
    3043 sortPeersByLivelinessReverse( tr_peer ** peers, void ** clientData, int n, uint64_t now )
    3044 {
    3045     sortPeersByLivelinessImpl( peers, clientData, n, now, comparePeerLivelinessReverse );
    30463010}
    30473011
     
    31323096    tor = NULL;
    31333097    while(( tor = tr_torrentNext( mgr->session, tor )))
    3134         closeBadPeers( tor->torrentPeers, now_msec, now_sec );
     3098        if( !tor->torrentPeers->isRunning )
     3099            removeAllPeers( tor->torrentPeers );
     3100        else
     3101            closeBadPeers( tor->torrentPeers, now_sec );
    31353102
    31363103    /* try to make new peer connections */
Note: See TracChangeset for help on using the changeset viewer.