(trunk libT) use part of hexum's patch from <http://forum.transmissionbt.com/viewtopic.php?p=41572#p41572>. The part added sorts peers by their overall speed when deciding which ones to disconnect from first, and which to request from first.

This commit is contained in:
Charles Kerr 2009-10-27 20:06:55 +00:00
parent 57bfbaabc6
commit 7a4f22ba12
1 changed files with 35 additions and 4 deletions

View File

@ -798,6 +798,9 @@ refillUpkeep( void * vmgr )
return TRUE;
}
static void
sortPeersByLiveliness( tr_peer ** peers, void ** clientData, int n, uint64_t now );
static void
refillPulse( int fd UNUSED, short type UNUSED, void * vtorrent )
{
@ -822,6 +825,7 @@ refillPulse( int fd UNUSED, short type UNUSED, void * vtorrent )
t->refillQueue = blockIteratorNew( t );
peers = getPeersUploadingToClient( t, &peerCount );
sortPeersByLiveliness( peers, NULL, peerCount, tr_date( ) );
webseedCount = tr_ptrArraySize( &t->webseeds );
webseeds = tr_memdup( tr_ptrArrayBase( &t->webseeds ),
webseedCount * sizeof( tr_webseed* ) );
@ -2166,6 +2170,8 @@ shouldPeerBeClosed( const Torrent * t,
return TR_CAN_KEEP;
}
static void sortPeersByLivelinessReverse( tr_peer ** peers, void ** clientData, int n, uint64_t now );
static tr_peer **
getPeersToClose( Torrent * t, tr_close_type_t closeType, int * setmeSize )
{
@ -2179,6 +2185,8 @@ getPeersToClose( Torrent * t, tr_close_type_t closeType, int * setmeSize )
if( shouldPeerBeClosed( t, peers[i], peerCount ) == closeType )
ret[outsize++] = peers[i];
sortPeersByLivelinessReverse ( ret, NULL, outsize, tr_date( ) );
*setmeSize = outsize;
return ret;
}
@ -2468,16 +2476,26 @@ comparePeerLiveliness( const void * va, const void * vb )
return 0;
}
/* FIXME: getPeersToClose() should use this */
static int
comparePeerLivelinessReverse( const void * va, const void * vb )
{
return -comparePeerLiveliness (va, vb);
}
static void
sortPeersByLiveliness( tr_peer ** peers, void** clientData, int n, uint64_t now )
sortPeersByLivelinessImpl( tr_peer ** peers,
void ** clientData,
int n,
uint64_t now,
int (*compare) ( const void *va, const void *vb ) )
{
int i;
struct peer_liveliness *lives, *l;
/* build a sortable array of peer + extra info */
lives = l = tr_new0( struct peer_liveliness, n );
for( i=0; i<n; ++i, ++l ) {
for( i=0; i<n; ++i, ++l )
{
tr_peer * p = peers[i];
l->peer = p;
l->doPurge = p->doPurge;
@ -2491,7 +2509,7 @@ sortPeersByLiveliness( tr_peer ** peers, void** clientData, int n, uint64_t now
/* sort 'em */
assert( n == ( l - lives ) );
qsort( lives, n, sizeof( struct peer_liveliness ), comparePeerLiveliness );
qsort( lives, n, sizeof( struct peer_liveliness ), compare );
/* build the peer array */
for( i=0, l=lives; i<n; ++i, ++l ) {
@ -2505,6 +2523,19 @@ sortPeersByLiveliness( tr_peer ** peers, void** clientData, int n, uint64_t now
tr_free( lives );
}
static void
sortPeersByLiveliness( tr_peer ** peers, void ** clientData, int n, uint64_t now )
{
sortPeersByLivelinessImpl( peers, clientData, n, now, comparePeerLiveliness );
}
static void
sortPeersByLivelinessReverse( tr_peer ** peers, void ** clientData, int n, uint64_t now )
{
sortPeersByLivelinessImpl( peers, clientData, n, now, comparePeerLivelinessReverse );
}
static void
enforceTorrentPeerLimit( Torrent * t, uint64_t now )
{