Changeset 10883 for branches


Ignore:
Timestamp:
Jun 26, 2010, 8:40:13 PM (12 years ago)
Author:
charles
Message:

(2.0x libT) #3329 "connection problems when downloading" -- backport r10820 to 2.0x

File:
1 edited

Legend:

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

    r10878 r10883  
    24992499     * untested peers, and "bad" (ones with a high cancel-to-block ratio).
    25002500     * That's the order in which we'll choose who to show interest in */
    2501     for( i=0; i<peerCount; ++i )
    2502     {
    2503         tr_peer * peer = tr_ptrArrayNth( &t->peers, i );
    2504 
    2505         if( !isPeerInteresting( t->tor, peer ) )
     2501    {
     2502        /* Randomize the peer array so the peers in the three groups will be unsorted... */
     2503        int n = peerCount;
     2504        tr_peer ** peers = tr_memdup( tr_ptrArrayBase( &t->peers ), n * sizeof( tr_peer * ) );
     2505
     2506        while( n > 0 )
    25062507        {
    2507             tr_peerMsgsSetInterested( peer->msgs, FALSE );
    2508         }
    2509         else
    2510         {
    2511             const int blocks = tr_historyGet( peer->blocksSentToClient, now, msec );
    2512             const int cancels = tr_historyGet( peer->cancelsSentToPeer, now, msec );
    2513 
    2514             if( !blocks && !cancels )
    2515                 untested[untestedCount++] = peer;
    2516             else if( !cancels )
    2517                 good[goodCount++] = peer;
    2518             else if( !blocks )
    2519                 bad[badCount++] = peer;
    2520             else if( ( cancels * 10 ) < blocks )
    2521                 good[goodCount++] = peer;
     2508            const int i = tr_cryptoWeakRandInt( n );
     2509            tr_peer * peer = tr_ptrArrayNth( &t->peers, i );
     2510
     2511            if( !isPeerInteresting( t->tor, peer ) )
     2512            {
     2513                tr_peerMsgsSetInterested( peer->msgs, FALSE );
     2514            }
    25222515            else
    2523                 bad[badCount++] = peer;
    2524         }
     2516            {
     2517                const int blocks = tr_historyGet( peer->blocksSentToClient, now, msec );
     2518                const int cancels = tr_historyGet( peer->cancelsSentToPeer, now, msec );
     2519
     2520                if( !blocks && !cancels )
     2521                    untested[untestedCount++] = peer;
     2522                else if( !cancels )
     2523                    good[goodCount++] = peer;
     2524                else if( !blocks )
     2525                    bad[badCount++] = peer;
     2526                else if( ( cancels * 10 ) < blocks )
     2527                    good[goodCount++] = peer;
     2528                else
     2529                    bad[badCount++] = peer;
     2530            }
     2531
     2532            tr_removeElementFromArray( peers, i, sizeof(tr_peer*), n-- );
     2533        }
     2534
     2535        tr_free( peers );
    25252536    }
    25262537
Note: See TracChangeset for help on using the changeset viewer.