Ignore:
Timestamp:
May 26, 2008, 12:14:35 PM (14 years ago)
Author:
charles
Message:

(libT) (1) shave a few bytes from tr_peer and tr_ratecontrol's footprints. (2) remove some dead code.

File:
1 edited

Legend:

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

    r5843 r5932  
    3636#include "utils.h"
    3737
    38 /**
    39 *** The "SWIFT" system is described by Karthik Tamilmani,
    40 *** Vinay Pai, and Alexander Mohr of Stony Brook University
    41 *** in their paper "SWIFT: A System With Incentives For Trading"
    42 *** http://citeseer.ist.psu.edu/tamilmani04swift.html
    43 ***
    44 *** More SWIFT constants are defined in peer-mgr-private.h
    45 **/
    46 
    47 /**
    48  * Allow new peers to download this many bytes from
    49  * us when getting started.  This can prevent gridlock
    50  * with other peers using tit-for-tat algorithms
    51  */
    52 static const int SWIFT_INITIAL_CREDIT = 64 * 1024; /* 64 KiB */
    53 
    54 /**
    55  * We expend a fraction of our torrent's total upload speed
    56  * on largesse by uniformly distributing free credit to
    57  * all of our peers.  This too helps prevent gridlock.
    58  */
    59 static const double SWIFT_LARGESSE = 0.15; /* 15% of our UL */
    60 
    61 /**
    62  * How frequently to extend largesse-based credit
    63  */
    64 static const int SWIFT_PERIOD_MSEC = 5000;
    65 
    66 
    6738enum
    6839{
     
    136107    tr_timer * rechokeTimer;
    137108    tr_timer * refillTimer;
    138     tr_timer * swiftTimer;
    139109    tr_torrent * tor;
    140110    tr_peer * optimistic; /* the optimistic peer, or NULL if none */
     
    309279    tr_peer * p;
    310280    p = tr_new0( tr_peer, 1 );
    311     p->credit = SWIFT_INITIAL_CREDIT;
    312281    p->rcToClient = tr_rcInit( );
    313282    p->rcToPeer = tr_rcInit( );
     
    393362    tr_timerFree( &t->rechokeTimer );
    394363    tr_timerFree( &t->refillTimer );
    395     tr_timerFree( &t->swiftTimer );
    396364
    397365    tr_bitfieldFree( t->requested );
     
    12361204static int reconnectPulse( void * vtorrent );
    12371205static int rechokePulse( void * vtorrent );
    1238 static int swiftPulse( void * vtorrent );
    12391206
    12401207void
     
    12511218    assert( ( t->isRunning != 0 ) == ( t->reconnectTimer != NULL ) );
    12521219    assert( ( t->isRunning != 0 ) == ( t->rechokeTimer != NULL ) );
    1253     assert( ( t->isRunning != 0 ) == ( t->swiftTimer != NULL ) );
    12541220
    12551221    if( !t->isRunning )
     
    12651231                                       RECHOKE_PERIOD_MSEC );
    12661232
    1267         t->swiftTimer = tr_timerNew( t->manager->handle,
    1268                                      swiftPulse, t,
    1269                                      SWIFT_PERIOD_MSEC );
    1270 
    12711233        reconnectPulse( t );
    12721234
    12731235        rechokePulse( t );
    1274 
    1275         swiftPulse( t );
    12761236    }
    12771237
     
    12871247    tr_timerFree( &t->rechokeTimer );
    12881248    tr_timerFree( &t->reconnectTimer );
    1289     tr_timerFree( &t->swiftTimer );
    12901249
    12911250    /* disconnect the peers. */
     
    15641523**/
    15651524
    1566 static double
     1525static int
    15671526getWeightedRate( const tr_peer * peer, int clientIsSeed )
    15681527{
     
    16611620/***
    16621621****
    1663 ***/
    1664 
    1665 static int
    1666 swiftPulse( void * vtorrent )
    1667 {
    1668     Torrent * t = vtorrent;
    1669     torrentLock( t );
    1670 
    1671     if( !tr_torrentIsSeed( t->tor ) )
    1672     {
    1673         int i;
    1674         int peerCount = 0;
    1675         int deadbeatCount = 0;
    1676         tr_peer ** peers = getConnectedPeers( t, &peerCount );
    1677         tr_peer ** deadbeats = tr_new( tr_peer*, peerCount );
    1678 
    1679         const double ul_KiBsec = tr_rcRate( t->tor->upload );
    1680         const double ul_KiB = ul_KiBsec * (SWIFT_PERIOD_MSEC/1000.0);
    1681         const double ul_bytes = ul_KiB * 1024;
    1682         const double freeCreditTotal = ul_bytes * SWIFT_LARGESSE;
    1683         int freeCreditPerPeer;
    1684 
    1685         for( i=0; i<peerCount; ++i ) {
    1686             tr_peer * peer = peers[i];
    1687             if( peer->credit <= 0 )
    1688                 deadbeats[deadbeatCount++] =  peer;
    1689         }
    1690 
    1691         freeCreditPerPeer = (int)( freeCreditTotal / deadbeatCount );
    1692         for( i=0; i<deadbeatCount; ++i )
    1693             deadbeats[i]->credit = freeCreditPerPeer;
    1694 
    1695         tordbg( t, "%d deadbeats, "
    1696             "who are each being granted %d bytes' credit "
    1697             "for a total of %.1f KiB, "
    1698             "%d%% of the torrent's ul speed %.1f\n",
    1699             deadbeatCount, freeCreditPerPeer,
    1700             ul_KiBsec*SWIFT_LARGESSE, (int)(SWIFT_LARGESSE*100), ul_KiBsec );
    1701 
    1702         tr_free( deadbeats );
    1703         tr_free( peers );
    1704     }
    1705 
    1706     torrentUnlock( t );
    1707     return TRUE;
    1708 }
    1709 
    1710 /***
    1711 ****
    17121622****  Life and Death
    17131623****
     
    17531663        /* if we have >= relaxIfFewerThan, strictness is 100%.
    17541664         * if we have zero connections, strictness is 0% */
    1755         const double strictness = peerCount >= relaxStrictnessIfFewerThanN
     1665        const float strictness = peerCount >= relaxStrictnessIfFewerThanN
    17561666            ? 1.0
    1757             : peerCount / (double)relaxStrictnessIfFewerThanN;
     1667            : peerCount / (float)relaxStrictnessIfFewerThanN;
    17581668        const int lo = MIN_UPLOAD_IDLE_SECS;
    17591669        const int hi = MAX_UPLOAD_IDLE_SECS;
Note: See TracChangeset for help on using the changeset viewer.