Changeset 11229


Ignore:
Timestamp:
Sep 19, 2010, 1:04:49 AM (12 years ago)
Author:
charles
Message:

(trunk libT) #3568 "don't optimistically unchoke torrents when our bandwidth is maxed out" -- fixed.

File:
1 edited

Legend:

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

    r11101 r11229  
    25802580struct ChokeData
    25812581{
    2582     tr_bool         doUnchoke;
    25832582    tr_bool         isInterested;
     2583    tr_bool         wasChoked;
    25842584    tr_bool         isChoked;
    25852585    int             rate;
     
    25982598        return a->rate > b->rate ? -1 : 1;
    25992599
    2600     if( a->isChoked != b->isChoked ) /* prefer unchoked */
    2601         return a->isChoked ? 1 : -1;
     2600    if( a->wasChoked != b->wasChoked ) /* prefer unchoked */
     2601        return a->wasChoked ? 1 : -1;
    26022602
    26032603    if( a->salt != b->salt ) /* random order */
     
    26352635    /* convert it to bytes per second */
    26362636    return Bps;
     2637}
     2638
     2639static inline tr_bool
     2640isBandwidthMaxedOut( const tr_bandwidth * b,
     2641                     const uint64_t now_msec, tr_direction dir )
     2642{
     2643    if( !tr_bandwidthIsLimited( b, dir ) )
     2644        return FALSE;
     2645    else {
     2646        const int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir );
     2647        const int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir );
     2648        return got >= want;
     2649    }
    26372650}
    26382651
     
    26462659    const tr_session * session = t->manager->session;
    26472660    const int chokeAll = !tr_torrentIsPieceTransferAllowed( t->tor, TR_CLIENT_TO_PEER );
     2661    const tr_bool isMaxedOut = isBandwidthMaxedOut( t->tor->bandwidth, now, TR_UP );
    26482662
    26492663    assert( torrentIsLocked( t ) );
     
    26722686            n->peer         = peer;
    26732687            n->isInterested = peer->peerIsInterested;
    2674             n->isChoked     = peer->peerIsChoked;
     2688            n->wasChoked    = peer->peerIsChoked;
    26752689            n->rate         = getRate( t->tor, atom, now );
    26762690            n->salt         = tr_cryptoWeakRandInt( INT_MAX );
     
    26922706     * a complete file, it uses its upload rate rather than its download
    26932707     * rate to decide which peers to unchoke.
     2708     *
     2709     * If our bandwidth is maxed out, don't unchoke any more peers.
    26942710     */
    26952711    unchokedInterested = 0;
    26962712    for( i=0; i<size && unchokedInterested<session->uploadSlotsPerTorrent; ++i ) {
    2697         choke[i].doUnchoke = 1;
     2713        choke[i].isChoked = isMaxedOut ? choke[i].wasChoked : FALSE;
    26982714        if( choke[i].isInterested )
    26992715            ++unchokedInterested;
     
    27012717
    27022718    /* optimistic unchoke */
    2703     if( i < size )
     2719    if( !isMaxedOut && (i<size) )
    27042720    {
    27052721        int n;
     
    27222738        {
    27232739            c = tr_ptrArrayNth( &randPool, tr_cryptoWeakRandInt( n ));
    2724             c->doUnchoke = 1;
     2740            c->isChoked = FALSE;
    27252741            t->optimistic = c->peer;
    27262742        }
     
    27302746
    27312747    for( i=0; i<size; ++i )
    2732         tr_peerMsgsSetChoke( choke[i].peer->msgs, !choke[i].doUnchoke );
     2748        tr_peerMsgsSetChoke( choke[i].peer->msgs, choke[i].isChoked );
    27332749
    27342750    /* cleanup */
     
    33133329***/
    33143330
    3315 static inline tr_bool
    3316 isBandwidthMaxedOut( const tr_bandwidth * b,
    3317                      const uint64_t now_msec, tr_direction dir )
    3318 {
    3319     if( !tr_bandwidthIsLimited( b, dir ) )
    3320         return FALSE;
    3321     else {
    3322         const int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir );
    3323         const int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir );
    3324         return got >= want;
    3325     }
    3326 }
    3327 
    33283331/* is this atom someone that we'd want to initiate a connection to? */
    33293332static tr_bool
Note: See TracChangeset for help on using the changeset viewer.