1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

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

This commit is contained in:
Charles Kerr 2008-01-11 02:09:20 +00:00
parent 6f6adb1d53
commit 39b1db460d
4 changed files with 44 additions and 5 deletions

View file

@ -58,6 +58,7 @@ struct tr_peerIo
int timeout;
struct bufferevent * bufev;
uint8_t peerId[20];
time_t timeCreated;
tr_extensions extensions;
@ -146,6 +147,7 @@ tr_peerIoNew( struct tr_handle * handle,
c->socket = socket;
c->isIncoming = isIncoming ? 1 : 0;
c->timeout = IO_TIMEOUT_SECS;
c->timeCreated = time( NULL );
c->bufev = bufferevent_new( c->socket,
canReadWrapper,
didWriteWrapper,
@ -582,3 +584,9 @@ tr_peerIoDrain( tr_peerIo * io,
tr_peerIoReadBytes( io, inbuf, tmp, byteCount );
tr_free( tmp );
}
int
tr_peerGetAge( const tr_peerIo * io )
{
return time( NULL ) - io->timeCreated;
}

View file

@ -80,7 +80,9 @@ int tr_peerIoReconnect( tr_peerIo * io );
int tr_peerIoIsIncoming( const tr_peerIo * io );
void tr_peerIoSetTimeoutSecs( tr_peerIo * io, int secs );
void tr_peerIoSetTimeoutSecs( tr_peerIo * io, int secs );
int tr_peerIoGetAge( const tr_peerIo * io );
/**

View file

@ -140,6 +140,7 @@ typedef struct
tr_timer * refillTimer;
tr_timer * swiftTimer;
tr_torrent * tor;
tr_peer * optimistic; /* the optimistic peer, or NULL if none */
tr_bitfield * requested;
unsigned int isRunning : 1;
@ -1480,6 +1481,7 @@ tr_peerMgrPeerStats( const tr_peerMgr * manager,
stat->isUploadingTo = stat->peerIsInterested && !stat->peerIsChoked;
pch = stat->flagStr;
if( t->optimistic == peer ) *pch++ = 'O';
if( stat->isDownloadingFrom ) *pch++ = 'D';
else if( stat->clientIsInterested ) *pch++ = 'd';
if( stat->isUploadingTo ) *pch++ = 'U';
@ -1519,6 +1521,18 @@ compareChoke( const void * va, const void * vb )
return -tr_compareUint32( a->rate, b->rate );
}
static int
isNew( const tr_peer * peer )
{
return peer && peer->io && tr_peerIoGetAge( peer->io ) < 45;
}
static int
isSame( const tr_peer * peer )
{
return peer && peer->client && strstr( peer->client, "Transmission" );
}
/**
***
**/
@ -1580,9 +1594,24 @@ rechoke( Torrent * t )
choke[i++].doUnchoke = 0;
/* optimistic unchoke */
if( i != size ) {
i = n + tr_rand( size - n );
choke[i].doUnchoke = 1;
if( i < size )
{
struct ChokeData * c;
tr_ptrArray * randPool = tr_ptrArrayNew( );
for( ; i<size; ++i )
{
const tr_peer * peer = choke[i].peer;
int x=1, y;
if( isNew( peer ) ) x *= 3;
if( isSame( peer ) ) x *= 3;
for( y=0; y<x; ++y )
tr_ptrArrayAppend( randPool, choke );
}
i = tr_rand( tr_ptrArraySize( randPool ) );
c = ( struct ChokeData* )tr_ptrArrayNth( randPool, i);
c->doUnchoke = 1;
t->optimistic = c->peer;
tr_ptrArrayFree( randPool, NULL );
}
for( i=0; i<size; ++i )

View file

@ -17,7 +17,7 @@
#include "trcompat.h" /* strlcpy */
#include "utils.h"
#define DEFAULT_MAX_UNCHOKED_PEERS 16
#define DEFAULT_MAX_UNCHOKED_PEERS 12
#define DEFAULT_MAX_CONNECTED_PEERS 50
struct optional_args