Changeset 4608


Ignore:
Timestamp:
Jan 11, 2008, 2:09:20 AM (14 years ago)
Author:
charles
Message:

follow the spec's suggestion that new connections be 3x as likely for optimistic unchoke

Location:
trunk/libtransmission
Files:
4 edited

Legend:

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

    r4600 r4608  
    5959    struct bufferevent * bufev;
    6060    uint8_t peerId[20];
     61    time_t timeCreated;
    6162
    6263    tr_extensions extensions;
     
    147148    c->isIncoming = isIncoming ? 1 : 0;
    148149    c->timeout = IO_TIMEOUT_SECS;
     150    c->timeCreated = time( NULL );
    149151    c->bufev = bufferevent_new( c->socket,
    150152                                canReadWrapper,
     
    583585    tr_free( tmp );
    584586}
     587
     588int
     589tr_peerGetAge( const tr_peerIo * io )
     590{
     591    return time( NULL ) - io->timeCreated;
     592}
  • trunk/libtransmission/peer-io.h

    r4404 r4608  
    8181int   tr_peerIoIsIncoming( const tr_peerIo * io );
    8282
    83 void tr_peerIoSetTimeoutSecs( tr_peerIo * io, int secs );
     83void  tr_peerIoSetTimeoutSecs( tr_peerIo * io, int secs );
     84
     85int   tr_peerIoGetAge( const tr_peerIo * io );
    8486
    8587
  • trunk/libtransmission/peer-mgr.c

    r4605 r4608  
    141141    tr_timer * swiftTimer;
    142142    tr_torrent * tor;
     143    tr_peer * optimistic; /* the optimistic peer, or NULL if none */
    143144    tr_bitfield * requested;
    144145
     
    14811482
    14821483        pch = stat->flagStr;
     1484        if( t->optimistic == peer ) *pch++ = 'O';
    14831485        if( stat->isDownloadingFrom ) *pch++ = 'D';
    14841486        else if( stat->clientIsInterested ) *pch++ = 'd';
     
    15181520    const struct ChokeData * b = vb;
    15191521    return -tr_compareUint32( a->rate, b->rate );
     1522}
     1523
     1524static int
     1525isNew( const tr_peer * peer )
     1526{
     1527    return peer && peer->io && tr_peerIoGetAge( peer->io ) < 45;
     1528}
     1529
     1530static int
     1531isSame( const tr_peer * peer )
     1532{
     1533    return peer && peer->client && strstr( peer->client, "Transmission" );
    15201534}
    15211535
     
    15811595
    15821596    /* optimistic unchoke */
    1583     if( i != size ) {
    1584         i = n + tr_rand( size - n );
    1585         choke[i].doUnchoke = 1;
     1597    if( i < size )
     1598    {
     1599        struct ChokeData * c;
     1600        tr_ptrArray * randPool = tr_ptrArrayNew( );
     1601        for( ; i<size; ++i )
     1602        {
     1603            const tr_peer * peer = choke[i].peer;
     1604            int x=1, y;
     1605            if( isNew( peer ) ) x *= 3;
     1606            if( isSame( peer ) ) x *= 3;
     1607            for( y=0; y<x; ++y )
     1608                tr_ptrArrayAppend( randPool, choke );
     1609        }
     1610        i = tr_rand( tr_ptrArraySize( randPool ) );
     1611        c = ( struct ChokeData* )tr_ptrArrayNth( randPool, i);
     1612        c->doUnchoke = 1;
     1613        t->optimistic = c->peer;
     1614        tr_ptrArrayFree( randPool, NULL );
    15861615    }
    15871616
  • trunk/libtransmission/torrent-ctor.c

    r4437 r4608  
    1818#include "utils.h"
    1919
    20 #define DEFAULT_MAX_UNCHOKED_PEERS 16
     20#define DEFAULT_MAX_UNCHOKED_PEERS 12
    2121#define DEFAULT_MAX_CONNECTED_PEERS 50
    2222
Note: See TracChangeset for help on using the changeset viewer.