Changeset 8879
- Timestamp:
- Aug 7, 2009, 5:41:33 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r8878 r8879 1007 1007 case TR_PEER_UPLOAD_ONLY: 1008 1008 /* 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 } 1011 1018 break; 1012 1019 … … 1088 1095 { 1089 1096 struct peer_atom * atom = peer->atom; 1090 const int peerIsSeed = e->progress >= 1.0; 1091 if( peerIsSeed ) { 1097 if( e->progress >= 1.0 ) { 1092 1098 tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) ); 1093 1099 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;1097 1100 } 1098 1101 } … … 1515 1518 } 1516 1519 1520 #if 0 1517 1521 static int 1518 1522 peerPrefersCrypto( const tr_peer * peer ) … … 1526 1530 return tr_peerIoIsEncrypted( peer->io ); 1527 1531 } 1532 #endif 1528 1533 1529 1534 int 1530 tr_peerMgrGetPeers( tr_torrent * tor, 1531 tr_pex ** setme_pex, 1532 uint8_t af) 1533 { 1534 int peersReturning = 0; 1535 tr_peerMgrGetPeers( tr_torrent * tor, tr_pex ** setme_pex, uint8_t af ) 1536 { 1537 int count = 0; 1535 1538 const Torrent * t = tor->torrentPeers; 1536 1539 … … 1539 1542 { 1540 1543 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 ); 1543 1546 /* for now, this will waste memory on torrents that have both 1544 1547 * ipv6 and ipv4 peers */ 1545 tr_pex * pex = tr_new0( tr_pex, peerCount );1548 tr_pex * pex = tr_new0( tr_pex, atomCount ); 1546 1549 tr_pex * walk = pex; 1547 1550 1548 for( i=0; i< peerCount; ++i )1551 for( i=0; i<atomCount; ++i ) 1549 1552 { 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 ) 1552 1555 { 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; 1564 1561 ++walk; 1565 1562 } 1566 1563 } 1567 1564 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 ); 1570 1567 *setme_pex = pex; 1571 1568 } 1572 1569 1573 1570 managerUnlock( t->manager ); 1574 return peersReturning;1571 return count; 1575 1572 } 1576 1573
Note: See TracChangeset
for help on using the changeset viewer.