Changeset 9730


Ignore:
Timestamp:
Dec 12, 2009, 5:05:31 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #2661 "better torrent prioritization when making outbound peer connection attempts" -- implemented for 1.80

File:
1 edited

Legend:

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

    r9709 r9730  
    28692869}
    28702870
    2871 
     2871struct reconnectTorrentStruct
     2872{
     2873    tr_torrent * torrent;
     2874    int salt;
     2875};
     2876
     2877static int
     2878compareReconnectTorrents( const void * va, const void * vb )
     2879{
     2880    int ai, bi;
     2881    const struct reconnectTorrentStruct * a = va;
     2882    const struct reconnectTorrentStruct * b = vb;
     2883
     2884    /* primary key: higher priority goes first */
     2885    ai = tr_torrentGetPriority( a->torrent );
     2886    bi = tr_torrentGetPriority( b->torrent );
     2887    if( ai != bi )
     2888        return ai > bi ? -1 : 1;
     2889
     2890    /* secondary key: since users tend to stare at the screens
     2891     * watching their downloads' progress, give downloads a
     2892     * first shot at attempting outbound peer connections. */
     2893    ai = tr_torrentIsSeed( a->torrent );
     2894    bi = tr_torrentIsSeed( b->torrent );
     2895    if( ai != bi )
     2896        return bi ? -1 : 1;
     2897
     2898    /* tertiary key: random */
     2899    if( a->salt != b->salt )
     2900        return a->salt - b->salt;
     2901
     2902    return 0;
     2903}
     2904   
    28722905static void
    28732906reconnectPulse( int foo UNUSED, short bar UNUSED, void * vmgr )
     
    28752908    tr_torrent * tor;
    28762909    tr_peerMgr * mgr = vmgr;
     2910    struct reconnectTorrentStruct * torrents;
     2911    int torrentCount;
     2912    int i;
    28772913    uint64_t now;
    28782914    managerLock( mgr );
    28792915
    28802916    now = tr_date( );
     2917
     2918    /**
     2919    ***  enforce the per-session and per-torrent peer limits
     2920    **/
    28812921
    28822922    /* if we're over the per-torrent peer limits, cull some peers */
     
    28892929    enforceSessionPeerLimit( mgr->session, now );
    28902930
    2891     tor = NULL;
    2892     while(( tor = tr_torrentNext( mgr->session, tor )))
    2893         if( tor->isRunning )
    2894             reconnectTorrent( tor->torrentPeers );
    2895 
     2931    /**
     2932    ***  try to make new peer connections
     2933    **/
     2934
     2935    torrentCount = 0;
     2936    torrents = tr_new( struct reconnectTorrentStruct,
     2937                       mgr->session->torrentCount );
     2938    while(( tor = tr_torrentNext( mgr->session, tor ))) {
     2939        if( tor->isRunning ) {
     2940            struct reconnectTorrentStruct * r = torrents + torrentCount++;
     2941            r->torrent = tor;
     2942            r->salt = tr_cryptoWeakRandInt( 1024 );
     2943        }
     2944    }
     2945    qsort( torrents,
     2946           torrentCount, sizeof( struct reconnectTorrentStruct ),
     2947           compareReconnectTorrents );
     2948    for( i=0; i<torrentCount; ++i )
     2949        reconnectTorrent( torrents[i].torrent->torrentPeers );
     2950
     2951
     2952    /* cleanup */
     2953    tr_free( torrents );
    28962954    tr_timerAddMsec( mgr->reconnectTimer, RECONNECT_PERIOD_MSEC );
    28972955    managerUnlock( mgr );
Note: See TracChangeset for help on using the changeset viewer.