Changeset 3274
- Timestamp:
- Oct 2, 2007, 7:54:14 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r3273 r3274 403 403 } 404 404 405 static int reconnectPulse( void * vtorrent );406 407 static void408 restartReconnectTimer( Torrent * t )409 {410 tr_timerFree( &t->reconnectTimer );411 if( t->isRunning )412 t->reconnectTimer = tr_timerNew( t->manager->handle, reconnectPulse, t, RECONNECT_PERIOD_MSEC );413 }414 415 static int rechokePulse( void * vtorrent );416 417 static void418 restartChokeTimer( Torrent * t )419 {420 tr_timerFree( &t->rechokeTimer );421 if( t->isRunning )422 t->rechokeTimer = tr_timerNew( t->manager->handle, rechokePulse, t, RECHOKE_PERIOD_MSEC );423 }424 425 405 static Torrent* 426 406 torrentConstructor( tr_peerMgr * manager, tr_torrent * tor ) … … 435 415 t->outgoingHandshakes = tr_ptrArrayNew( ); 436 416 t->requested = tr_bitfieldNew( tor->blockCount ); 437 restartChokeTimer( t );438 restartReconnectTimer( t );439 417 memcpy( t->hash, tor->info.hash, SHA_DIGEST_LENGTH ); 440 418 … … 1096 1074 } 1097 1075 1076 static int reconnectPulse( void * vtorrent ); 1077 static int rechokePulse( void * vtorrent ); 1078 1098 1079 void 1099 1080 tr_peerMgrStartTorrent( tr_peerMgr * manager, … … 1105 1086 1106 1087 t = getExistingTorrent( manager, torrentHash ); 1088 1089 assert( t != NULL ); 1090 assert( !t->isRunning ); 1091 assert( t->reconnectTimer == NULL ); 1092 assert( t->rechokeTimer == NULL ); 1093 1107 1094 t->isRunning = 1; 1108 restartChokeTimer( t);1109 restartReconnectTimer( t);1095 t->reconnectTimer = tr_timerNew( t->manager->handle, reconnectPulse, t, RECONNECT_PERIOD_MSEC ); 1096 t->rechokeTimer = tr_timerNew( t->manager->handle, rechokePulse, t, RECHOKE_PERIOD_MSEC ); 1110 1097 1111 1098 managerUnlock( manager ); … … 1505 1492 else if( peer->doPurge ) 1506 1493 isWeak = TRUE; 1507 else if( peerIsSeed && clientIsSeed && (now-atom->time >= 30) ) /* pex time */1508 isWeak = TRUE;1494 else if( peerIsSeed && clientIsSeed ) 1495 isWeak = t->tor->pexDisabled || (now-atom->time>=30); 1509 1496 else if( ( now - atom->time ) < LAISSEZ_FAIRE_PERIOD_SECS ) 1510 1497 isWeak = FALSE; 1511 #if 01512 1498 else 1513 isWeak = TRUE; 1514 #else 1515 else if( now - peer->pieceDataActivityDate > 180 ) 1516 isWeak = TRUE; 1517 else 1518 isWeak = FALSE; 1519 #endif 1499 isWeak = now - peer->pieceDataActivityDate > 180; 1520 1500 1521 1501 if( isWeak ) … … 1598 1578 else 1599 1579 { 1600 int i, nCandidates, n Connections, nAdd;1580 int i, nCandidates, nWeak, nAdd; 1601 1581 struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates ); 1602 struct tr_connection * connections = getWeakConnections( t, &n Connections);1582 struct tr_connection * connections = getWeakConnections( t, &nWeak ); 1603 1583 const int peerCount = tr_ptrArraySize( t->peers ); 1604 1584 1605 1585 tordbg( t, "RECONNECT pulse for [%s]: %d weak connections, %d connection candidates, %d atoms, max per pulse is %d\n", 1606 t->tor->info.name, n Connections, nCandidates, tr_ptrArraySize(t->pool), (int)MAX_RECONNECTIONS_PER_PULSE );1607 1608 for( i=0; i<n Connections; ++i )1586 t->tor->info.name, nWeak, nCandidates, tr_ptrArraySize(t->pool), (int)MAX_RECONNECTIONS_PER_PULSE ); 1587 1588 for( i=0; i<nWeak; ++i ) 1609 1589 tordbg( t, "connection #%d: %s @ %.2f\n", i+1, 1610 1590 tr_peerIoAddrStr( &connections[i].peer->in_addr, connections[i].peer->port ), connections[i].throughput ); 1611 1591 1612 1592 /* disconnect some peers */ 1613 for( i=0; i<nConnections && i<(peerCount-5) && i<MAX_RECONNECTIONS_PER_PULSE; ++i ) { 1614 const double throughput = connections[i].throughput; 1615 tr_peer * peer = connections[i].peer; 1616 tordbg( t, "RECONNECT culling peer %s, whose throughput was %f\n", 1617 tr_peerIoAddrStr(&peer->in_addr, peer->port), throughput ); 1618 removePeer( t, peer ); 1619 } 1593 for( i=0; i<nWeak; ++i ) 1594 removePeer( t, connections[i].peer ); 1620 1595 1621 1596 /* add some new ones */
Note: See TracChangeset
for help on using the changeset viewer.