Changeset 3261
- Timestamp:
- Oct 1, 2007, 4:50:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r3260 r3261 40 40 41 41 /* how frequently to decide which peers live and die */ 42 RECONNECT_PERIOD_MSEC = ( 15 * 1000),42 RECONNECT_PERIOD_MSEC = (5 * 1000), 43 43 44 44 /* how frequently to refill peers' request lists */ … … 336 336 assert( removed == peer ); 337 337 freePeer( removed ); 338 } 339 340 static void 341 removeAllPeers( Torrent * t ) 342 { 343 while( !tr_ptrArrayEmpty( t->peers ) ) 344 removePeer( t, tr_ptrArrayNth( t->peers, 0 ) ); 338 345 } 339 346 … … 1613 1620 { 1614 1621 Torrent * t = vtorrent; 1615 struct peer_atom ** candidates;1616 struct tr_connection * connections;1617 int i, nCandidates, nConnections, nCull, nAdd;1618 int peerCount;1619 1622 1620 1623 torrentLock( t ); 1621 1624 1622 connections = getWeakConnections( t, &nConnections ); 1623 candidates = getPeerCandidates( t, &nCandidates ); 1624 1625 /* figure out how many peers to disconnect */ 1626 nCull = nConnections-4; 1627 1628 fprintf( stderr, "RECONNECT pulse for [%s]: %d connections, %d candidates, %d atoms, %d cull\n", t->tor->info.name, nConnections, nCandidates, tr_ptrArraySize(t->pool), nCull ); 1629 1630 for( i=0; i<nConnections; ++i ) 1631 fprintf( stderr, "connection #%d: %s @ %.2f\n", i+1, tr_peerIoAddrStr( &connections[i].peer->in_addr, connections[i].peer->port ), connections[i].throughput ); 1632 1633 /* disconnect some peers */ 1634 for( i=0; i<nCull && i<nConnections; ++i ) { 1635 const double throughput = connections[i].throughput; 1636 tr_peer * peer = connections[i].peer; 1637 fprintf( stderr, "RECONNECT culling peer %s, whose throughput was %f\n", tr_peerIoAddrStr(&peer->in_addr, peer->port), throughput ); 1638 removePeer( t, peer ); 1639 } 1640 1641 /* add some new ones */ 1642 peerCount = tr_ptrArraySize( t->peers ); 1643 nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount; 1644 for( i=0; i<nAdd && i<nCandidates; ++i ) { 1645 struct peer_atom * atom = candidates[i]; 1646 tr_peerIo * io = tr_peerIoNewOutgoing( t->manager->handle, &atom->addr, atom->port, t->hash ); 1647 fprintf( stderr, "RECONNECT adding an outgoing connection...\n" ); 1648 initiateHandshake( t->manager, io ); 1649 atom->time = time( NULL ); 1650 } 1651 1652 /* cleanup */ 1653 tr_free( connections ); 1654 tr_free( candidates ); 1625 if( !t->isRunning ) 1626 { 1627 removeAllPeers( t ); 1628 } 1629 else 1630 { 1631 int i, nCandidates, nConnections, nAdd; 1632 struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates ); 1633 struct tr_connection * connections = getWeakConnections( t, &nConnections ); 1634 const int peerCount = tr_ptrArraySize( t->peers ); 1635 1636 fprintf( stderr, "RECONNECT pulse for [%s]: %d weak connections, %d connection candidates, %d atoms\n", 1637 t->tor->info.name, nConnections, nCandidates, tr_ptrArraySize(t->pool) ); 1638 1639 for( i=0; i<nConnections; ++i ) 1640 fprintf( stderr, "connection #%d: %s @ %.2f\n", i+1, 1641 tr_peerIoAddrStr( &connections[i].peer->in_addr, connections[i].peer->port ), connections[i].throughput ); 1642 1643 /* disconnect some peers */ 1644 for( i=0; i<nConnections && i<(peerCount-5); ++i ) { 1645 const double throughput = connections[i].throughput; 1646 tr_peer * peer = connections[i].peer; 1647 fprintf( stderr, "RECONNECT culling peer %s, whose throughput was %f\n", 1648 tr_peerIoAddrStr(&peer->in_addr, peer->port), throughput ); 1649 removePeer( t, peer ); 1650 } 1651 1652 /* add some new ones */ 1653 nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount; 1654 for( i=0; i<nAdd && i<nCandidates; ++i ) { 1655 struct peer_atom * atom = candidates[i]; 1656 tr_peerIo * io = tr_peerIoNewOutgoing( t->manager->handle, &atom->addr, atom->port, t->hash ); 1657 fprintf( stderr, "RECONNECT adding an outgoing connection...\n" ); 1658 initiateHandshake( t->manager, io ); 1659 atom->time = time( NULL ); 1660 } 1661 1662 /* cleanup */ 1663 tr_free( connections ); 1664 tr_free( candidates ); 1665 } 1666 1655 1667 torrentUnlock( t ); 1656 1668 return TRUE;
Note: See TracChangeset
for help on using the changeset viewer.