Exemple #1
0
static uint64_t
loadSpeedLimits( tr_benc * dict, tr_torrent * tor )
{
    tr_benc * d;
    uint64_t ret = 0;


    if( tr_bencDictFindDict( dict, KEY_SPEEDLIMIT_UP, &d ) )
    {
        loadSingleSpeedLimit( d, TR_UP, tor );
        ret = TR_FR_SPEEDLIMIT;
    }
    if( tr_bencDictFindDict( dict, KEY_SPEEDLIMIT_DOWN, &d ) )
    {
        loadSingleSpeedLimit( d, TR_DOWN, tor );
        ret = TR_FR_SPEEDLIMIT;
    }

    /* older speedlimit structure */
    if( !ret && tr_bencDictFindDict( dict, KEY_SPEEDLIMIT_OLD, &d ) )
    {

        int64_t i;
        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_SPEED, &i ) )
            tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, i*1024 );
        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_DOWN_MODE, &i ) ) {
            tr_torrentUseSpeedLimit( tor, TR_DOWN, i==TR_SPEEDLIMIT_SINGLE );
            tr_torrentUseSessionLimits( tor, i==TR_SPEEDLIMIT_GLOBAL );
         }
        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_SPEED, &i ) )
            tr_torrentSetSpeedLimit_Bps( tor, TR_UP, i*1024 );
        if( tr_bencDictFindInt( d, KEY_SPEEDLIMIT_UP_MODE, &i ) ) {
            tr_torrentUseSpeedLimit( tor, TR_UP, i==TR_SPEEDLIMIT_SINGLE );
            tr_torrentUseSessionLimits( tor, i==TR_SPEEDLIMIT_GLOBAL );
        }
        ret = TR_FR_SPEEDLIMIT;
    }

    return ret;
}
Exemple #2
0
static void
loadSingleSpeedLimit( tr_benc * d, tr_direction dir, tr_torrent * tor )
{
    int64_t i;
    tr_bool boolVal;

    if( tr_bencDictFindInt( d, KEY_SPEED_Bps, &i ) )
        tr_torrentSetSpeedLimit_Bps( tor, dir, i );
    else if( tr_bencDictFindInt( d, KEY_SPEED_KiBps, &i ) )
        tr_torrentSetSpeedLimit_Bps( tor, dir, i*1024 );

    if( tr_bencDictFindBool( d, KEY_USE_SPEED_LIMIT, &boolVal ) )
        tr_torrentUseSpeedLimit( tor, dir, boolVal );

    if( tr_bencDictFindBool( d, KEY_USE_GLOBAL_SPEED_LIMIT, &boolVal ) )
        tr_torrentUseSessionLimits( tor, boolVal );
}
static void
loadSingleSpeedLimit (tr_variant * d, tr_direction dir, tr_torrent * tor)
{
  int64_t i;
  bool boolVal;

  if (tr_variantDictFindInt (d, TR_KEY_speed_Bps, &i))
    tr_torrentSetSpeedLimit_Bps (tor, dir, i);
  else if (tr_variantDictFindInt (d, TR_KEY_speed, &i))
    tr_torrentSetSpeedLimit_Bps (tor, dir, i*1024);

  if (tr_variantDictFindBool (d, TR_KEY_use_speed_limit, &boolVal))
    tr_torrentUseSpeedLimit (tor, dir, boolVal);

  if (tr_variantDictFindBool (d, TR_KEY_use_global_speed_limit, &boolVal))
    tr_torrentUseSessionLimits (tor, boolVal);
}