(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.
This commit is contained in:
Jordan Lee 2011-03-29 15:23:54 +00:00
parent 9f122a021a
commit 4230cd7786
3 changed files with 30 additions and 8 deletions

View File

@ -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; i<atomCount; ++i )
atoms[i] = peers[i]->atom;
}
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<n; ++i )
if( isAtomInteresting( tor, atomBase[i] ) )
atoms[atomCount++] = atomBase[i];
}
qsort( atoms, atomCount, sizeof( struct peer_atom * ), compareAtomsByUsefulness );

View File

@ -206,7 +206,7 @@ void tr_peerMgrMarkAllAsSeeds( tr_torrent * tor );
enum
{
TR_PEERS_CONNECTED,
TR_PEERS_ALL
TR_PEERS_INTERESTING
};
int tr_peerMgrGetPeers( tr_torrent * tor,

View File

@ -93,12 +93,12 @@ savePeers( tr_benc * dict, const tr_torrent * tor )
int count;
tr_pex * pex;
count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET, TR_PEERS_ALL, MAX_REMEMBERED_PEERS );
count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS );
if( count > 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 );