Changeset 5932


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.

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr-private.h

    r5179 r5932  
    3535};
    3636
    37 /**
    38 *** The "SWIFT" system is described by Karthik Tamilmani,
    39 *** Vinay Pai, and Alexander Mohr of Stony Brook University
    40 *** in their paper "SWIFT: A System With Incentives For Trading"
    41 *** http://citeseer.ist.psu.edu/tamilmani04swift.html
    42 ***
    43 *** More SWIFT constants are defined in peer-mgr.c
    44 **/
    45 
    46 /**
    47  * Use SWIFT?
    48  */
    49 static const int SWIFT_ENABLED = 0;
    50 
    51 /**
    52  * For every byte the peer uploads to us,
    53  * allow them to download this many bytes from us
    54  */
    55 static const double SWIFT_REPAYMENT_RATIO = 1.33;
    56 
    57 
    5837typedef struct tr_peer
    5938{
     
    8968    struct tr_ratecontrol * rcToPeer;
    9069
    91     double rateToClient;
    92     double rateToPeer;
    93 
    94     int64_t credit;
     70    float rateToClient;
     71    float rateToPeer;
    9572}
    9673tr_peer;
  • 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;
  • trunk/libtransmission/peer-msgs.c

    r5922 r5932  
    11611161    tor->downloadedCur += byteCount;
    11621162    msgs->info->pieceDataActivityDate = now;
    1163     msgs->info->credit += (int)(byteCount * SWIFT_REPAYMENT_RATIO);
    11641163    tr_rcTransferred( msgs->info->rcToClient, byteCount );
    11651164    tr_rcTransferred( tor->download, byteCount );
     
    13841383    tor->uploadedCur += byteCount;
    13851384    msgs->info->pieceDataActivityDate = now;
    1386     msgs->info->credit -= byteCount;
    13871385    tr_rcTransferred( msgs->info->rcToPeer, byteCount );
    13881386    tr_rcTransferred( tor->upload, byteCount );
     
    15791577**/
    15801578
    1581 static int
    1582 isSwiftEnabled( const tr_peermsgs * msgs )
    1583 {
    1584     /* rationale: SWIFT is good for getting rid of deadbeats, but most
    1585      * private trackers have ratios where you _want_ to feed deadbeats
    1586      * as much as possible.  So we disable SWIFT on private torrents */
    1587     return SWIFT_ENABLED
    1588         && !tr_torrentIsSeed( msgs->torrent )
    1589         && !tr_torrentIsPrivate( msgs->torrent );
    1590 }
    1591 
    15921579static size_t
    15931580getUploadMax( const tr_peermsgs * msgs )
     
    15951582    static const size_t maxval = ~0;
    15961583    const tr_torrent * tor = msgs->torrent;
    1597     const int useSwift = isSwiftEnabled( msgs );
    1598     const size_t swiftLeft = msgs->info->credit;
    15991584    int speedLeft;
    16001585    int bufLeft;
    1601     size_t ret;
    16021586
    16031587    if( tor->uploadLimitMode == TR_SPEEDLIMIT_GLOBAL )
     
    16121596     * block message overhead */
    16131597    bufLeft = tor->blockSize + 13 - tr_peerIoWriteBytesWaiting( msgs->io );
    1614     ret = MIN( speedLeft, bufLeft );
    1615     if( useSwift)
    1616         ret = MIN( ret, swiftLeft );
    1617     return ret;
     1598    return MIN( speedLeft, bufLeft );
    16181599}
    16191600
  • trunk/libtransmission/ratecontrol.c

    r5342 r5932  
    4343struct tr_ratecontrol
    4444{
    45     int limit;
    46     int newest;
     45    int8_t limit;
     46    int8_t newest;
    4747    struct tr_transfer transfers[HISTORY_SIZE];
    4848};
  • trunk/libtransmission/transmission.h

    r5924 r5932  
    5353typedef uint64_t tr_block_index_t;
    5454
     55/**
     56 * @brief returns Transmission's default configuration file directory.
     57 *
     58 * The default configuration directory is determined this way:
     59 * - If the TRANSMISSION_HOME environmental variable is set,
     60 *   its value is returned.
     61 * - otherwise, if we're running on Darwin,
     62 *   "$HOME/Library/Application Support/Transmission" is returned.
     63 * - otherwise, if we're running on WIN32,
     64 *   "$CSIDL_APPDATA/Transmission" is returned.
     65 * - otherwise, if XDG_CONFIG_HOME is set,
     66 *   "$XDG_CONFIG_HOME/transmission" is returned.
     67 * - lastly, $HOME/.config/transmission" is used.
     68 */
    5569const char* tr_getDefaultConfigDir( void );
    5670
     
    7387 */
    7488
     89/** @see tr_sessionInitFull */
    7590#define TR_DEFAULT_CONFIG_DIR                  tr_getDefaultConfigDir()
     91/** @see tr_sessionInitFull */
    7692#define TR_DEFAULT_PEX_ENABLED                 1
     93/** @see tr_sessionInitFull */
    7794#define TR_DEFAULT_PORT_FORWARDING_ENABLED     0
     95/** @see tr_sessionInitFull */
    7896#define TR_DEFAULT_PORT                        51413
     97/** @see tr_sessionInitFull */
    7998#define TR_DEFAULT_GLOBAL_PEER_LIMIT           200
     99/** @see tr_sessionInitFull */
    80100#define TR_DEFAULT_PEER_SOCKET_TOS             8
     101/** @see tr_sessionInitFull */
    81102#define TR_DEFAULT_BLOCKLIST_ENABLED           0
     103/** @see tr_sessionInitFull */
    82104#define TR_DEFAULT_RPC_ENABLED                 0
     105/** @see tr_sessionInitFull */
    83106#define TR_DEFAULT_RPC_PORT                    9091
     107/** @see tr_sessionInitFull */
    84108#define TR_DEFAULT_RPC_PORT_STR                "9091"
     109/** @see tr_sessionInitFull */
    85110#define TR_DEFAULT_RPC_ACL                     "+127.0.0.1"
    86111
    87112/**
    88  * Create and return a Transmission session handle.
    89  *
    90  * @param configDir the config directory where libtransmission config
    91  *                  subdirectories will be found, such as "torrents",
    92  *                  "resume", and "blocklists".
    93  *                  TR_DEFAULT_CONFIG_DIR can be used as a default.
    94  * @param downloadDir The default directory to save added torrents.
    95  *                    This can be changed per-session with
    96  *                    tr_sessionSetDownloadDir() and per-torrent with
    97  *                    tr_ctorSetDownloadDir().
    98  * @param tag   Obsolete.  Only used now for locating legacy fastresume files.
    99  *              Valid tags: beos, cli, daemon, gtk, macos, wx
    100  * @param isPexEnabled whether or not PEX is allowed for non-private torrents.
    101  *                     This can be changed per-session with
    102  *                     tr_sessionSetPexEnabled().
    103  *                     TR_DEFAULT_PEX_ENABLED is the default.
    104  * @param isPortForwardingEnabled If true, libtransmission will attempt
    105  *                       to find a local UPnP-enabled or NATPMP-enabled
    106  *                       router and forward a port from there to the local
    107  *                       machine.  This is so remote peers can initiate
    108  *                       connections with us.
    109  *                       TR_DEFAULT_PORT_FORWARDING_ENABLED is the default.
    110  * @param publicPort Port number to open for incoming peer connections.
    111  *                   TR_DEFAULT_PORT is the default.
    112  * @param encryptionMode must be one of TR_PLAINTEXT_PREFERRED,
    113  *                       TR_ENCRYPTION_PREFERRED, or TR_ENCRYPTION_REQUIRED.
    114  * @param isUploadLimitEnabled If true, libtransmission will limit the entire
    115  *                             session's upload speed from `uploadLimit'.
    116  * @param uploadLimit The speed limit to use for the entire session when
    117  *                    isUploadLimitEnabled is true.
    118  * @param isDownloadLimitEnabled If true, libtransmission will limit the entire
    119  *                               session's download speed from `downloadLimit'.
    120  * @param downloadLimit The speed limit to use for the entire session when
    121  *                      isDownloadLimitEnabled is true.
    122  * @param peerLimit The maximum number of peer connections allowed in a session.
    123  *                  TR_DEFAULT_GLOBAL_PEER_LIMIT can be used as a default.
     113 * @brief Start a libtransmission session.
     114 * @return an opaque handle to the new session
     115 *
     116 * @param configDir
     117 *  The config directory where libtransmission config subdirectories
     118 *  will be found, such as "torrents", "resume", and "blocklists".
     119 *  #TR_DEFAULT_CONFIG_DIR can be used as a default.
     120 *
     121 * @param downloadDir
     122 *  The default directory to save added torrents.
     123 *  This can be changed per-session with
     124 *  tr_sessionSetDownloadDir() and per-torrent with
     125 *  tr_ctorSetDownloadDir().
     126 *
     127 * @param tag
     128 *  Obsolete.  Only used now for locating legacy fastresume files.
     129 *  This will be removed at some point in the future.
     130 *  Valid tags: beos cli daemon gtk macos wx
     131 *
     132 * @param isPexEnabled
     133 *  whether or not PEX is allowed for non-private torrents.
     134 *  This can be changed per-session with
     135 *  tr_sessionSetPexEnabled().
     136 *  #TR_DEFAULT_PEX_ENABLED is the default.
     137 *
     138 * @param isPortForwardingEnabled
     139 *  If true, libtransmission will attempt
     140 *  to find a local UPnP-enabled or NATPMP-enabled
     141 *  router and forward a port from there to the local
     142 *  machine.  This is so remote peers can initiate
     143 *  connections with us.
     144 *  #TR_DEFAULT_PORT_FORWARDING_ENABLED is the default.
     145 *
     146 * @param publicPort
     147 *  Port number to open for incoming peer connections.
     148 *  #TR_DEFAULT_PORT is the default.
     149 *
     150 * @param encryptionMode
     151 *  Must be one of #TR_PLAINTEXT_PREFERRED,
     152 *  #TR_ENCRYPTION_PREFERRED, or #TR_ENCRYPTION_REQUIRED.
     153 *
     154 * @param isUploadLimitEnabled
     155 *  If true, libtransmission will limit the entire
     156 *  session's upload speed from "uploadLimit".
     157 *
     158 * @param uploadLimit
     159 *  The speed limit to use for the entire session when
     160 *  "isUploadLimitEnabled" is true.
     161 *
     162 * @param isDownloadLimitEnabled
     163 *  If true, libtransmission will limit the entire
     164 *  session's download speed from "downloadLimit".
     165 *
     166 * @param downloadLimit
     167 *  The speed limit to use for the entire session when
     168 *  "isDownloadLimitEnabled" is true.
     169 *
     170 * @param peerLimit
     171 *  The maximum number of peer connections allowed in a session.
     172 *  #TR_DEFAULT_GLOBAL_PEER_LIMIT can be used as a default.
     173 *
     174 * @param messageLevel
     175 *  Verbosity level of libtransmission's logging mechanism.
     176 *  Must be one of #TR_MSG_ERR, #TR_MSG_INF, #TR_MSG_DBG.
     177 *
     178 * @param isMessageQueueingEnabled
     179 *  If true, then messages will build up in a queue until
     180 *  processed by the client application.
     181 *
     182 * @param isBlocklistEnabled
     183 *  If true, then Transmission will not allow peer connections
     184 *  to the IP addressess specified in the blocklist.
     185 *
     186 * @param peerSocketTOS
     187 *
     188 * @param rpcIsEnabled
     189 *  If true, then libtransmission will open an http server port
     190 *  to listen for incoming RPC requests.
     191 *
     192 * @param rpcPort
     193 *  The port on which to listen for incoming RPC requests
     194 *
     195 * @param rpcACL
     196 *  The access control list for allowing/denying RPC requests
     197 *  from specific IP ranges.
     198 *  @see tr_sessionSetRPCACL()
    124199 *
    125200 * @see TR_DEFAULT_PEER_SOCKET_TOS
     
    128203 * @see TR_DEFAULT_RPC_PORT
    129204 * @see TR_DEFAULT_RPC_ACL
     205 * @see tr_sessionClose()
    130206 */
    131207tr_handle * tr_sessionInitFull( const char * configDir,
     
    147223                                int          rpcIsEnabled,
    148224                                int          rpcPort,
    149                                 const char * rpcACL );
    150 
    151 /**
    152  * Like tr_sessionInitFull() but with default values supplied.
     225                                const char * rpcAccessControlList );
     226
     227/**
     228 * @brief shorter form of tr_sessionInitFull()
     229 *
     230 * @deprecated Use tr_sessionInitFull() instead.
    153231 */
    154232tr_handle * tr_sessionInit( const char * configDir,
     
    157235
    158236/**
    159  * Shut down a libtransmission instance created by tr_sessionInit*()
     237 * @brief end a libtransmission session
     238 * @see tr_sessionInitFull()
    160239 */
    161240void tr_sessionClose( tr_handle * );
     
    171250 * Set the per-session default download folder for new torrents.
    172251 * @see tr_sessionInitFull()
     252 * @see tr_sessionGetDownloadDir()
    173253 * @see tr_ctorSetDownloadDir()
    174254 */
    175255void tr_sessionSetDownloadDir( tr_handle *, const char * downloadDir );
    176256
     257/**
     258 * Get the default download folder for new torrents.
     259 *
     260 * This is set by tr_sessionInitFull() or tr_sessionSetDownloadDir(),
     261 * and can be overridden on a per-torrent basis by tr_ctorSetDownloadDir().
     262 */
    177263const char * tr_sessionGetDownloadDir( const tr_handle * );
    178264
     265/**
     266 * @brief Set whether or not RPC calls are allowed in this session.
     267 *
     268 * @details If true, libtransmission will open a server socket to listen
     269 * for incoming http RPC requests as described in docs/rpc-spec.txt.
     270 *
     271 * This is intially set by tr_sessionInitFull() and can be
     272 * queried by tr_sessionIsRPCEnabled().
     273 */
    179274void tr_sessionSetRPCEnabled( tr_handle *, int isEnabled );
    180275
     276/** @brief Get whether or not RPC calls are allowed in this session.
     277    @see tr_sessionInitFull()
     278    @see tr_sessionSetRPCEnabled() */
    181279int tr_sessionIsRPCEnabled( const tr_handle * handle );
    182280
     281/** @brief Specify which port to listen for RPC requests on.
     282    @see tr_sessionInitFull()
     283    @see tr_sessionGetRPCPort */
    183284void tr_sessionSetRPCPort( tr_handle *, int port );
    184285
     286/** @brief Get which port to listen for RPC requests on.
     287    @see tr_sessionInitFull()
     288    @see tr_sessionSetRPCPort */
    185289int tr_sessionGetRPCPort( const tr_handle * );
    186290
     
    198302 * generate it from a higher-level interface that doesn't allow user error,
    199303 * before calling this function.
     304 *
     305 * @see tr_sessionInitFull
     306 * @see tr_sessionGetRPCACL
    200307 */
    201308void tr_sessionSetRPCACL( tr_handle *, const char * acl );
    202309
     310/** Returns the Access Control List for allowing/denying RPC requests.
     311    @see tr_sessionInitFull
     312    @see tr_sessionSetRPCACL */
    203313const char* tr_sessionGetRPCACL( const tr_handle * );
    204314
     
    232342typedef struct tr_session_stats
    233343{
     344    float ratio;              /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */
    234345    uint64_t uploadedBytes;   /* total up */
    235346    uint64_t downloadedBytes; /* total down */
    236     double ratio;             /* TR_RATIO_INF, TR_RATIO_NA, or total up/down */
    237347    uint64_t filesAdded;      /* number of files added */
    238348    uint64_t sessionCount;    /* program started N times */
Note: See TracChangeset for help on using the changeset viewer.