Ignore:
Timestamp:
Mar 4, 2009, 7:52:57 PM (13 years ago)
Author:
charles
Message:

(trunk) libT and gtk+ parts for #1889: per-torrent vs. global speed limit confusion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/resume.c

    r7888 r8021  
    3939#define KEY_PRIORITY        "priority"
    4040#define KEY_PROGRESS        "progress"
    41 #define KEY_SPEEDLIMIT      "speed-limit"
     41#define KEY_SPEEDLIMIT_OLD  "speed-limit"
     42#define KEY_SPEEDLIMIT_UP   "speed-limit-up"
     43#define KEY_SPEEDLIMIT_DOWN "speed-limit-down"
    4244#define KEY_RATIOLIMIT      "ratio-limit"
    4345#define KEY_UPLOADED        "uploaded"
    4446
    45 #define KEY_SPEEDLIMIT_DOWN_SPEED "down-speed"
    46 #define KEY_SPEEDLIMIT_DOWN_MODE  "down-mode"
    47 #define KEY_SPEEDLIMIT_UP_SPEED   "up-speed"
    48 #define KEY_SPEEDLIMIT_UP_MODE    "up-mode"
    49 #define KEY_RATIOLIMIT_RATIO      "ratio-limit"
    50 #define KEY_RATIOLIMIT_MODE       "ratio-mode"
     47#define KEY_SPEED                  "speed"
     48#define KEY_USE_GLOBAL_SPEED_LIMIT "use-global-speed-limit"
     49#define KEY_USE_SPEED_LIMIT        "use-speed-limit"
     50#define KEY_SPEEDLIMIT_DOWN_SPEED  "down-speed"
     51#define KEY_SPEEDLIMIT_DOWN_MODE   "down-mode"
     52#define KEY_SPEEDLIMIT_UP_SPEED    "up-speed"
     53#define KEY_SPEEDLIMIT_UP_MODE     "up-mode"
     54#define KEY_RATIOLIMIT_RATIO       "ratio-limit"
     55#define KEY_RATIOLIMIT_MODE        "ratio-mode"
    5156
    5257#define KEY_PROGRESS_MTIMES   "mtimes"
     
    244249
    245250static void
    246 saveSpeedLimits( tr_benc *          dict,
    247                  const tr_torrent * tor )
    248 {
    249     tr_benc * d = tr_bencDictAddDict( dict, KEY_SPEEDLIMIT, 4 );
    250 
    251     tr_bencDictAddInt( d, KEY_SPEEDLIMIT_DOWN_SPEED,
    252                       tr_torrentGetSpeedLimit( tor, TR_DOWN ) );
    253     tr_bencDictAddInt( d, KEY_SPEEDLIMIT_DOWN_MODE,
    254                       tr_torrentGetSpeedMode( tor, TR_DOWN ) );
    255     tr_bencDictAddInt( d, KEY_SPEEDLIMIT_UP_SPEED,
    256                       tr_torrentGetSpeedLimit( tor, TR_UP ) );
    257     tr_bencDictAddInt( d, KEY_SPEEDLIMIT_UP_MODE,
    258                       tr_torrentGetSpeedMode( tor, TR_UP ) );
     251saveSingleSpeedLimit( tr_benc * d, const tr_torrent * tor, tr_direction dir )
     252{
     253    tr_bencDictReserve( d, 3 );
     254    tr_bencDictAddInt( d, KEY_SPEED, tr_torrentGetSpeedLimit( tor, dir ) );
     255    tr_bencDictAddInt( d, KEY_USE_GLOBAL_SPEED_LIMIT, tr_torrentIsUsingGlobalSpeedLimit( tor, dir ) );
     256    tr_bencDictAddInt( d, KEY_USE_SPEED_LIMIT, tr_torrentIsUsingSpeedLimit( tor, dir ) );
    259257}
    260258
    261259static void
    262 saveRatioLimits( tr_benc *          dict,
    263                  const tr_torrent * tor )
     260saveSpeedLimits( tr_benc * dict, const tr_torrent * tor )
     261{
     262    saveSingleSpeedLimit( tr_bencDictAddDict( dict, KEY_SPEEDLIMIT_DOWN, 0 ), tor, TR_DOWN );
     263    saveSingleSpeedLimit( tr_bencDictAddDict( dict, KEY_SPEEDLIMIT_UP, 0 ), tor, TR_UP );
     264}
     265
     266static void
     267saveRatioLimits( tr_benc * dict, const tr_torrent * tor )
    264268{
    265269    tr_benc * d = tr_bencDictAddDict( dict, KEY_RATIOLIMIT, 4 );
     
    271275}
    272276
    273 static uint64_t
    274 loadSpeedLimits( tr_benc *    dict,
    275                  tr_torrent * tor )
     277static void
     278loadSingleSpeedLimit( tr_benc * d, tr_direction dir, tr_torrent * tor )
     279{
     280    int64_t i;
     281    if( tr_bencDictFindInt( d, KEY_SPEED, &i ) )
     282        tr_torrentSetSpeedLimit( tor, dir, i );
     283    if( tr_bencDictFindInt( d, KEY_USE_SPEED_LIMIT, &i ) )
     284        tr_torrentUseSpeedLimit( tor, dir, i!=0 );
     285    if( tr_bencDictFindInt( d, KEY_USE_GLOBAL_SPEED_LIMIT, &i ) )
     286        tr_torrentUseGlobalSpeedLimit( tor, dir, i!=0 );
     287}
     288
     289enum old_speed_modes
     290{
     291    TR_SPEEDLIMIT_GLOBAL,   /* only follow the overall speed limit */
     292    TR_SPEEDLIMIT_SINGLE    /* only follow the per-torrent limit */
     293};
     294
     295static uint64_t
     296loadSpeedLimits( tr_benc * dict, tr_torrent * tor )
    276297{
    277298    uint64_t  ret = 0;
    278299    tr_benc * d;
    279300
    280     if( tr_bencDictFindDict( dict, KEY_SPEEDLIMIT, &d ) )
    281     {
     301    if( tr_bencDictFindDict( dict, KEY_SPEEDLIMIT_UP, &d ) )
     302    {
     303        loadSingleSpeedLimit( d, TR_UP, tor );
     304        ret = TR_FR_SPEEDLIMIT;
     305    }
     306    if( tr_bencDictFindDict( dict, KEY_SPEEDLIMIT_DOWN, &d ) )
     307    {
     308        loadSingleSpeedLimit( d, TR_DOWN, tor );
     309        ret = TR_FR_SPEEDLIMIT;
     310    }
     311
     312    /* older speedlimit structure */
     313    if( !ret && tr_bencDictFindDict( dict, KEY_SPEEDLIMIT_OLD, &d ) )
     314    {
     315
    282316        int64_t i;
    283317        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_SPEED, &i ) )
    284318            tr_torrentSetSpeedLimit( tor, TR_DOWN, i );
    285         if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_MODE, &i ) )
    286             tr_torrentSetSpeedMode( tor, TR_DOWN, i );
     319        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_MODE, &i ) ) {
     320            tr_torrentUseSpeedLimit ( tor, TR_DOWN, i==TR_SPEEDLIMIT_SINGLE );
     321            tr_torrentUseGlobalSpeedLimit( tor, TR_DOWN, i==TR_SPEEDLIMIT_GLOBAL );
     322         }
    287323        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_SPEED, &i ) )
    288324            tr_torrentSetSpeedLimit( tor, TR_UP, i );
    289         if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_MODE, &i ) )
    290             tr_torrentSetSpeedMode( tor, TR_UP, i );
     325        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_MODE, &i ) ) {
     326            tr_torrentUseSpeedLimit ( tor, TR_UP, i==TR_SPEEDLIMIT_SINGLE );
     327            tr_torrentUseGlobalSpeedLimit( tor, TR_UP, i==TR_SPEEDLIMIT_GLOBAL );
     328        }
    291329        ret = TR_FR_SPEEDLIMIT;
    292330    }
Note: See TracChangeset for help on using the changeset viewer.