From 4230cd7786b80471672799934e7d86544f30e283 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Tue, 29 Mar 2011 15:23:54 +0000 Subject: [PATCH] (trunk libT) don't cache unininteresting peer addresses between sessions For example, if we're both seeds, or if the peer is not connectible, don't bother caching it for the next session. If it's still alive, we'll find it up through DHT or tracker announces next time around. As with r12253, this commit's intention is to reduce the number of unproductive peer_atoms that we waste time trying to connect to. --- libtransmission/peer-mgr.c | 32 +++++++++++++++++++++++++++----- libtransmission/peer-mgr.h | 2 +- libtransmission/resume.c | 4 ++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index b4f4068a5..865c8eb30 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -2283,6 +2283,24 @@ compareAtomsByUsefulness( const void * va, const void *vb ) return 0; } +static bool +isAtomInteresting( const tr_torrent * tor, struct peer_atom * atom ) +{ + if( tr_torrentIsSeed( tor ) && atomIsSeed( atom ) ) + return false; + + if( peerIsInUse( tor->torrentPeers, atom ) ) + return true; + + if( isAtomBlocklisted( tor->session, atom ) ) + return false; + + if( atom->flags2 & MYFLAG_BANNED ) + return false; + + return true; +} + int tr_peerMgrGetPeers( tr_torrent * tor, tr_pex ** setme_pex, @@ -2302,7 +2320,7 @@ tr_peerMgrGetPeers( tr_torrent * tor, assert( tr_isTorrent( tor ) ); assert( setme_pex != NULL ); assert( af==TR_AF_INET || af==TR_AF_INET6 ); - assert( list_mode==TR_PEERS_CONNECTED || list_mode==TR_PEERS_ALL ); + assert( list_mode==TR_PEERS_CONNECTED || list_mode==TR_PEERS_INTERESTING ); managerLock( t->manager ); @@ -2319,11 +2337,15 @@ tr_peerMgrGetPeers( tr_torrent * tor, for( i=0; iatom; } - else /* TR_PEERS_ALL */ + else /* TR_PEERS_INTERESTING */ { - const struct peer_atom ** atomsBase = (const struct peer_atom**) tr_ptrArrayBase( &t->pool ); - atomCount = tr_ptrArraySize( &t->pool ); - atoms = tr_memdup( atomsBase, atomCount * sizeof( struct peer_atom * ) ); + int i; + struct peer_atom ** atomBase = (struct peer_atom**) tr_ptrArrayBase( &t->pool ); + n = tr_ptrArraySize( &t->pool ); + atoms = tr_new( struct peer_atom *, n ); + for( i=0; i 0 ) tr_bencDictAddRaw( dict, KEY_PEERS, pex, sizeof( tr_pex ) * count ); tr_free( pex ); - count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET6, TR_PEERS_ALL, MAX_REMEMBERED_PEERS ); + count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET6, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS ); if( count > 0 ) tr_bencDictAddRaw( dict, KEY_PEERS6, pex, sizeof( tr_pex ) * count );