Changeset 9416


Ignore:
Timestamp:
Oct 27, 2009, 8:06:55 PM (13 years ago)
Author:
charles
Message:

(trunk libT) use part of hexum's patch from <http://forum.transmissionbt.com/viewtopic.php?p=41572#p41572>. The part added sorts peers by their overall speed when deciding which ones to disconnect from first, and which to request from first.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r9414 r9416  
    800800
    801801static void
     802sortPeersByLiveliness( tr_peer ** peers, void ** clientData, int n, uint64_t now );
     803
     804static void
    802805refillPulse( int fd UNUSED, short type UNUSED, void * vtorrent )
    803806{
     
    823826
    824827    peers = getPeersUploadingToClient( t, &peerCount );
     828    sortPeersByLiveliness( peers, NULL, peerCount, tr_date( ) );
    825829    webseedCount = tr_ptrArraySize( &t->webseeds );
    826830    webseeds = tr_memdup( tr_ptrArrayBase( &t->webseeds ),
     
    21672171}
    21682172
     2173static void sortPeersByLivelinessReverse( tr_peer ** peers, void ** clientData, int n, uint64_t now );
     2174
    21692175static tr_peer **
    21702176getPeersToClose( Torrent * t, tr_close_type_t closeType, int * setmeSize )
     
    21792185        if( shouldPeerBeClosed( t, peers[i], peerCount ) == closeType )
    21802186            ret[outsize++] = peers[i];
     2187
     2188    sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_date( ) );
    21812189
    21822190    *setmeSize = outsize;
     
    24692477}
    24702478
    2471 /* FIXME: getPeersToClose() should use this */
    2472 static void
    2473 sortPeersByLiveliness( tr_peer ** peers, void** clientData, int n, uint64_t now )
     2479static int
     2480comparePeerLivelinessReverse( const void * va, const void * vb )
     2481{
     2482    return -comparePeerLiveliness (va, vb);
     2483}
     2484
     2485static void
     2486sortPeersByLivelinessImpl( tr_peer  ** peers,
     2487                           void     ** clientData,
     2488                           int         n,
     2489                           uint64_t    now,
     2490                           int (*compare) ( const void *va, const void *vb ) )
    24742491{
    24752492    int i;
     
    24782495    /* build a sortable array of peer + extra info */
    24792496    lives = l = tr_new0( struct peer_liveliness, n );
    2480     for( i=0; i<n; ++i, ++l ) {
     2497    for( i=0; i<n; ++i, ++l )
     2498    {
    24812499        tr_peer * p = peers[i];
    24822500        l->peer = p;
     
    24922510    /* sort 'em */
    24932511    assert( n == ( l - lives ) );
    2494     qsort( lives, n, sizeof( struct peer_liveliness ), comparePeerLiveliness );
     2512    qsort( lives, n, sizeof( struct peer_liveliness ), compare );
    24952513
    24962514    /* build the peer array */
     
    25052523    tr_free( lives );
    25062524}
     2525
     2526static void
     2527sortPeersByLiveliness( tr_peer ** peers, void ** clientData, int n, uint64_t now )
     2528{
     2529    sortPeersByLivelinessImpl( peers, clientData, n, now, comparePeerLiveliness );
     2530}
     2531
     2532static void
     2533sortPeersByLivelinessReverse( tr_peer ** peers, void ** clientData, int n, uint64_t now )
     2534{
     2535    sortPeersByLivelinessImpl( peers, clientData, n, now, comparePeerLivelinessReverse );
     2536}
     2537
    25072538
    25082539static void
Note: See TracChangeset for help on using the changeset viewer.