Changeset 12254


Ignore:
Timestamp:
Mar 29, 2011, 3:23:54 PM (10 years ago)
Author:
jordan
Message:

(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.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

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

    r12249 r12254  
    22842284}
    22852285
     2286static bool
     2287isAtomInteresting( const tr_torrent * tor, struct peer_atom * atom )
     2288{
     2289    if( tr_torrentIsSeed( tor ) && atomIsSeed( atom ) )
     2290        return false;
     2291
     2292    if( peerIsInUse( tor->torrentPeers, atom ) )
     2293        return true;
     2294
     2295    if( isAtomBlocklisted( tor->session, atom ) )
     2296        return false;
     2297
     2298    if( atom->flags2 & MYFLAG_BANNED )
     2299        return false;
     2300
     2301    return true;
     2302}
     2303
    22862304int
    22872305tr_peerMgrGetPeers( tr_torrent   * tor,
     
    23032321    assert( setme_pex != NULL );
    23042322    assert( af==TR_AF_INET || af==TR_AF_INET6 );
    2305     assert( list_mode==TR_PEERS_CONNECTED || list_mode==TR_PEERS_ALL );
     2323    assert( list_mode==TR_PEERS_CONNECTED || list_mode==TR_PEERS_INTERESTING );
    23062324
    23072325    managerLock( t->manager );
     
    23202338            atoms[i] = peers[i]->atom;
    23212339    }
    2322     else /* TR_PEERS_ALL */
    2323     {
    2324         const struct peer_atom ** atomsBase = (const struct peer_atom**) tr_ptrArrayBase( &t->pool );
    2325         atomCount = tr_ptrArraySize( &t->pool );
    2326         atoms = tr_memdup( atomsBase, atomCount * sizeof( struct peer_atom * ) );
     2340    else /* TR_PEERS_INTERESTING */
     2341    {
     2342        int i;
     2343        struct peer_atom ** atomBase = (struct peer_atom**) tr_ptrArrayBase( &t->pool );
     2344        n = tr_ptrArraySize( &t->pool );
     2345        atoms = tr_new( struct peer_atom *, n );
     2346        for( i=0; i<n; ++i )
     2347            if( isAtomInteresting( tor, atomBase[i] ) )
     2348                atoms[atomCount++] = atomBase[i];
    23272349    }
    23282350
  • trunk/libtransmission/peer-mgr.h

    r12248 r12254  
    207207{
    208208    TR_PEERS_CONNECTED,
    209     TR_PEERS_ALL
     209    TR_PEERS_INTERESTING
    210210};
    211211
  • trunk/libtransmission/resume.c

    r12248 r12254  
    9494    tr_pex * pex;
    9595
    96     count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET, TR_PEERS_ALL, MAX_REMEMBERED_PEERS );
     96    count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS );
    9797    if( count > 0 )
    9898        tr_bencDictAddRaw( dict, KEY_PEERS, pex, sizeof( tr_pex ) * count );
    9999    tr_free( pex );
    100100
    101     count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET6, TR_PEERS_ALL, MAX_REMEMBERED_PEERS );
     101    count = tr_peerMgrGetPeers( (tr_torrent*) tor, &pex, TR_AF_INET6, TR_PEERS_INTERESTING, MAX_REMEMBERED_PEERS );
    102102    if( count > 0 )
    103103        tr_bencDictAddRaw( dict, KEY_PEERS6, pex, sizeof( tr_pex ) * count );
Note: See TracChangeset for help on using the changeset viewer.