Changeset 8879


Ignore:
Timestamp:
Aug 7, 2009, 5:41:33 AM (13 years ago)
Author:
charles
Message:

(trunk libT) #2318: improve the peer lists used in the .resume file and in PEX

File:
1 edited

Legend:

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

    r8878 r8879  
    10071007        case TR_PEER_UPLOAD_ONLY:
    10081008            /* update our atom */
    1009             if( peer )
    1010                 peer->atom->uploadOnly = e->uploadOnly ? UPLOAD_ONLY_YES : UPLOAD_ONLY_NO;
     1009            if( peer ) {
     1010                if( e->uploadOnly ) {
     1011                    peer->atom->uploadOnly = UPLOAD_ONLY_YES;
     1012                    peer->atom->flags |= ADDED_F_SEED_FLAG;
     1013                } else {
     1014                    peer->atom->uploadOnly = UPLOAD_ONLY_NO;
     1015                    peer->atom->flags &= ~ADDED_F_SEED_FLAG;
     1016                }
     1017            }
    10111018            break;
    10121019
     
    10881095            {
    10891096                struct peer_atom * atom = peer->atom;
    1090                 const int peerIsSeed = e->progress >= 1.0;
    1091                 if( peerIsSeed ) {
     1097                if( e->progress >= 1.0 ) {
    10921098                    tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) );
    10931099                    atom->flags |= ADDED_F_SEED_FLAG;
    1094                 } else {
    1095                     tordbg( t, "marking peer %s as a non-seed", tr_peerIoAddrStr( &atom->addr, atom->port ) );
    1096                     atom->flags &= ~ADDED_F_SEED_FLAG;
    10971100                }
    10981101            }
     
    15151518}
    15161519
     1520#if 0
    15171521static int
    15181522peerPrefersCrypto( const tr_peer * peer )
     
    15261530    return tr_peerIoIsEncrypted( peer->io );
    15271531}
     1532#endif
    15281533
    15291534int
    1530 tr_peerMgrGetPeers( tr_torrent      * tor,
    1531                     tr_pex         ** setme_pex,
    1532                     uint8_t           af)
    1533 {
    1534     int peersReturning = 0;
     1535tr_peerMgrGetPeers( tr_torrent * tor, tr_pex ** setme_pex, uint8_t af )
     1536{
     1537    int count = 0;
    15351538    const Torrent * t = tor->torrentPeers;
    15361539
     
    15391542    {
    15401543        int i;
    1541         const tr_peer ** peers = (const tr_peer**) tr_ptrArrayBase( &t->peers );
    1542         const int peerCount = tr_ptrArraySize( &t->peers );
     1544        const struct peer_atom ** atoms = (const struct peer_atom**) tr_ptrArrayBase( &t->pool );
     1545        const int atomCount = tr_ptrArraySize( &t->pool );
    15431546        /* for now, this will waste memory on torrents that have both
    15441547         * ipv6 and ipv4 peers */
    1545         tr_pex * pex = tr_new0( tr_pex, peerCount );
     1548        tr_pex * pex = tr_new0( tr_pex, atomCount );
    15461549        tr_pex * walk = pex;
    15471550
    1548         for( i=0; i<peerCount; ++i )
     1551        for( i=0; i<atomCount; ++i )
    15491552        {
    1550             const tr_peer * peer = peers[i];
    1551             if( peer->addr.type == af )
     1553            const struct peer_atom * atom = atoms[i];
     1554            if( atom->addr.type == af )
    15521555            {
    1553                 const struct peer_atom * atom = peer->atom;
    1554 
    1555                 assert( tr_isAddress( &peer->addr ) );
    1556                 walk->addr = peer->addr;
    1557                 walk->port = peer->port;
    1558                 walk->flags = 0;
    1559                 if( peerPrefersCrypto( peer ) )
    1560                     walk->flags |= ADDED_F_ENCRYPTION_FLAG;
    1561                 if( ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 ) )
    1562                     walk->flags |= ADDED_F_SEED_FLAG;
    1563                 ++peersReturning;
     1556                assert( tr_isAddress( &atom->addr ) );
     1557                walk->addr = atom->addr;
     1558                walk->port = atom->port;
     1559                walk->flags = atom->flags;
     1560                ++count;
    15641561                ++walk;
    15651562            }
    15661563        }
    15671564
    1568         assert( ( walk - pex ) == peersReturning );
    1569         qsort( pex, peersReturning, sizeof( tr_pex ), tr_pexCompare );
     1565        assert( ( walk - pex ) == count );
     1566        qsort( pex, count, sizeof( tr_pex ), tr_pexCompare );
    15701567        *setme_pex = pex;
    15711568    }
    15721569
    15731570    managerUnlock( t->manager );
    1574     return peersReturning;
     1571    return count;
    15751572}
    15761573
Note: See TracChangeset for help on using the changeset viewer.