Changeset 7875


Ignore:
Timestamp:
Feb 11, 2009, 4:38:07 PM (13 years ago)
Author:
charles
Message:

(1.5x libT) partial adoption of r7825: keep the rechoke() and reconnect() changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.5x/libtransmission/peer-mgr.c

    r7813 r7875  
    4848
    4949    /* minimum interval for refilling peers' request lists */
    50     REFILL_PERIOD_MSEC = 333,
    51 
    52     /* when many peers are available, keep idle ones this long */
    53     MIN_UPLOAD_IDLE_SECS = ( 30 ),
    54 
    55     /* when few peers are available, keep idle ones this long */
    56     MAX_UPLOAD_IDLE_SECS = ( 60 * 5 ),
    57 
    58     /* how frequently to decide which peers live and die */
    59     RECONNECT_PERIOD_MSEC = ( 2 * 1000 ),
     50    REFILL_PERIOD_MSEC = 400,
    6051   
    6152    /* how frequently to reallocate bandwidth */
    6253    BANDWIDTH_PERIOD_MSEC = 500,
    6354
     55    /* how frequently to decide which peers live and die */
     56    RECONNECT_PERIOD_MSEC = 500,
     57
     58    /* when many peers are available, keep idle ones this long */
     59    MIN_UPLOAD_IDLE_SECS = ( 30 ),
     60
     61    /* when few peers are available, keep idle ones this long */
     62    MAX_UPLOAD_IDLE_SECS = ( 60 * 5 ),
     63
    6464    /* max # of peers to ask fer per torrent per reconnect pulse */
    6565    MAX_RECONNECTIONS_PER_PULSE = 16,
     
    7575    MYFLAG_BANNED = 1,
    7676
     77    /* use for bitwise operations w/peer_atom.myflags */
    7778    /* unreachable for now... but not banned.
    7879     * if they try to connect to us it's okay */
     
    127128    tr_ptrArray     peers; /* tr_peer */
    128129    tr_ptrArray     webseeds; /* tr_webseed */
    129     tr_timer *      reconnectTimer;
    130     tr_timer *      rechokeTimer;
    131130    tr_timer *      refillTimer;
    132131    tr_torrent *    tor;
     
    142141    tr_ptrArray       incomingHandshakes; /* tr_handshake */
    143142    tr_timer        * bandwidthTimer;
     143    tr_timer        * rechokeTimer;
     144    tr_timer        * reconnectTimer;
    144145};
    145146
     
    381382    memcpy( hash, t->hash, SHA_DIGEST_LENGTH );
    382383
    383     tr_timerFree( &t->reconnectTimer );
    384     tr_timerFree( &t->rechokeTimer );
    385384    tr_timerFree( &t->refillTimer );
    386385
     
    425424
    426425
    427 static int bandwidthPulse( void * vmgr );
    428 
     426static int bandwidthPulse ( void * vmgr );
     427static int rechokePulse   ( void * vmgr );
     428static int reconnectPulse ( void * vmgr );
    429429
    430430tr_peerMgr*
     
    436436    m->incomingHandshakes = TR_PTR_ARRAY_INIT;
    437437    m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC );
     438    m->rechokeTimer   = tr_timerNew( session, rechokePulse,   m, RECHOKE_PERIOD_MSEC );
     439    m->reconnectTimer = tr_timerNew( session, reconnectPulse, m, RECONNECT_PERIOD_MSEC );
     440
     441    rechokePulse( m );
     442
    438443    return m;
    439444}
     
    444449    managerLock( manager );
    445450
     451    tr_timerFree( &manager->reconnectTimer );
     452    tr_timerFree( &manager->rechokeTimer );
    446453    tr_timerFree( &manager->bandwidthTimer );
    447454
     
    15071514}
    15081515
    1509 static int reconnectPulse( void * vtorrent );
    1510 
    1511 static int rechokePulse( void * vtorrent );
    1512 
    15131516void
    15141517tr_peerMgrStartTorrent( tr_torrent * tor )
     
    15191522
    15201523    assert( t );
    1521     assert( ( t->isRunning != 0 ) == ( t->reconnectTimer != NULL ) );
    1522     assert( ( t->isRunning != 0 ) == ( t->rechokeTimer != NULL ) );
    15231524
    15241525    if( !t->isRunning )
    15251526    {
    1526         t->isRunning = 1;
    1527 
    1528         t->reconnectTimer = tr_timerNew( t->manager->session,
    1529                                          reconnectPulse, t,
    1530                                          RECONNECT_PERIOD_MSEC );
    1531 
    1532         t->rechokeTimer = tr_timerNew( t->manager->session,
    1533                                        rechokePulse, t,
    1534                                        RECHOKE_PERIOD_MSEC );
    1535 
    1536         reconnectPulse( t );
    1537 
    1538         rechokePulse( t );
     1527        t->isRunning = TRUE;
    15391528
    15401529        if( !tr_ptrArrayEmpty( &t->webseeds ) )
     
    15501539    assert( torrentIsLocked( t ) );
    15511540
    1552     t->isRunning = 0;
    1553     tr_timerFree( &t->rechokeTimer );
    1554     tr_timerFree( &t->reconnectTimer );
     1541    t->isRunning = FALSE;
    15551542
    15561543    /* disconnect the peers. */
     
    18681855
    18691856static void
    1870 rechoke( Torrent * t )
     1857rechokeTorrent( Torrent * t )
    18711858{
    18721859    int i, size, unchokedInterested;
     
    19681955
    19691956static int
    1970 rechokePulse( void * vtorrent )
    1971 {
    1972     Torrent * t = vtorrent;
    1973 
    1974     torrentLock( t );
    1975     rechoke( t );
    1976     torrentUnlock( t );
     1957rechokePulse( void * vmgr )
     1958{
     1959    tr_torrent * tor = NULL;
     1960    tr_peerMgr * mgr = vmgr;
     1961    managerLock( mgr );
     1962
     1963    while(( tor = tr_torrentNext( mgr->session, tor )))
     1964        if( tor->isRunning )
     1965            rechokeTorrent( tor->torrentPeers );
     1966
     1967    managerUnlock( mgr );
    19771968    return TRUE;
    19781969}
     
    22162207}
    22172208
    2218 static int
    2219 reconnectPulse( void * vtorrent )
    2220 {
    2221     Torrent *     t = vtorrent;
     2209static void
     2210reconnectTorrent( Torrent * t )
     2211{
    22222212    static time_t prevTime = 0;
    22232213    static int    newConnectionsThisSecond = 0;
    22242214    time_t        now;
    2225 
    2226     torrentLock( t );
    22272215
    22282216    now = time( NULL );
     
    23272315        tr_free( canClose );
    23282316    }
    2329 
    2330     torrentUnlock( t );
     2317}
     2318
     2319static int
     2320reconnectPulse( void * vmgr )
     2321{
     2322    tr_torrent * tor = NULL;
     2323    tr_peerMgr * mgr = vmgr;
     2324    managerLock( mgr );
     2325
     2326    while(( tor = tr_torrentNext( mgr->session, tor )))
     2327        if( tor->isRunning )
     2328            reconnectTorrent( tor->torrentPeers );
     2329
     2330    managerUnlock( mgr );
    23312331    return TRUE;
    23322332}
Note: See TracChangeset for help on using the changeset viewer.