Changeset 3274


Ignore:
Timestamp:
Oct 2, 2007, 7:54:14 PM (15 years ago)
Author:
charles
Message:

tweak the peer manager code a little more.

File:
1 edited

Legend:

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

    r3273 r3274  
    403403}
    404404
    405 static int reconnectPulse( void * vtorrent );
    406 
    407 static void
    408 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 void
    418 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 
    425405static Torrent*
    426406torrentConstructor( tr_peerMgr * manager, tr_torrent * tor )
     
    435415    t->outgoingHandshakes = tr_ptrArrayNew( );
    436416    t->requested = tr_bitfieldNew( tor->blockCount );
    437     restartChokeTimer( t );
    438     restartReconnectTimer( t );
    439417    memcpy( t->hash, tor->info.hash, SHA_DIGEST_LENGTH );
    440418
     
    10961074}
    10971075
     1076static int reconnectPulse( void * vtorrent );
     1077static int rechokePulse( void * vtorrent );
     1078
    10981079void
    10991080tr_peerMgrStartTorrent( tr_peerMgr     * manager,
     
    11051086
    11061087    t = getExistingTorrent( manager, torrentHash );
     1088
     1089    assert( t != NULL );
     1090    assert( !t->isRunning );
     1091    assert( t->reconnectTimer == NULL );
     1092    assert( t->rechokeTimer == NULL );
     1093
    11071094    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 );
    11101097
    11111098    managerUnlock( manager );
     
    15051492        else if( peer->doPurge )
    15061493            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);
    15091496        else if( ( now - atom->time ) < LAISSEZ_FAIRE_PERIOD_SECS )
    15101497            isWeak = FALSE;
    1511 #if 0
    15121498        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;
    15201500
    15211501        if( isWeak )
     
    15981578    else
    15991579    {
    1600         int i, nCandidates, nConnections, nAdd;
     1580        int i, nCandidates, nWeak, nAdd;
    16011581        struct peer_atom ** candidates = getPeerCandidates( t, &nCandidates );
    1602         struct tr_connection * connections = getWeakConnections( t, &nConnections );
     1582        struct tr_connection * connections = getWeakConnections( t, &nWeak );
    16031583        const int peerCount = tr_ptrArraySize( t->peers );
    16041584
    16051585        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, nConnections, nCandidates, tr_ptrArraySize(t->pool), (int)MAX_RECONNECTIONS_PER_PULSE );
    1607 
    1608         for( i=0; i<nConnections; ++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 )
    16091589            tordbg( t, "connection #%d: %s @ %.2f\n", i+1,
    16101590                     tr_peerIoAddrStr( &connections[i].peer->in_addr, connections[i].peer->port ), connections[i].throughput );
    16111591
    16121592        /* 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 );
    16201595
    16211596        /* add some new ones */
Note: See TracChangeset for help on using the changeset viewer.