Browse Source

Use enums for settings

adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
2da2054ccf
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 77
      src/base/bittorrent/session.cpp
  2. 50
      src/base/bittorrent/session.h
  3. 12
      src/gui/advancedsettings.cpp

77
src/base/bittorrent/session.cpp

@ -301,7 +301,8 @@ Session::Session(QObject *parent) @@ -301,7 +301,8 @@ Session::Session(QObject *parent)
, m_maxUploadsPerTorrent(BITTORRENT_SESSION_KEY("MaxUploadsPerTorrent"), -1, lowerLimited(0, -1))
, m_isUTPEnabled(BITTORRENT_SESSION_KEY("uTPEnabled"), true)
, m_isUTPRateLimited(BITTORRENT_SESSION_KEY("uTPRateLimited"), true)
, m_utpMixedMode(BITTORRENT_SESSION_KEY("uTPMixedMode"), m_isUTPEnabled, clampValue(0, 1))
, m_utpMixedMode(BITTORRENT_SESSION_KEY("uTPMixedMode"), MixedModeAlgorithm::Proportional
, clampValue(MixedModeAlgorithm::TCP, MixedModeAlgorithm::Proportional))
, m_multiConnectionsPerIpEnabled(BITTORRENT_SESSION_KEY("MultiConnectionsPerIp"), false)
, m_isAddTrackersEnabled(BITTORRENT_SESSION_KEY("AddTrackersEnabled"), false)
, m_additionalTrackers(BITTORRENT_SESSION_KEY("AdditionalTrackers"))
@ -330,8 +331,10 @@ Session::Session(QObject *parent) @@ -330,8 +331,10 @@ Session::Session(QObject *parent)
, m_encryption(BITTORRENT_SESSION_KEY("Encryption"), 0)
, m_isForceProxyEnabled(BITTORRENT_SESSION_KEY("ForceProxy"), true)
, m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY("ProxyPeerConnections"), false)
, m_chokingAlgorithm(BITTORRENT_SESSION_KEY("ChokingAlgorithm"), 0, clampValue(0, 2))
, m_seedChokingAlgorithm(BITTORRENT_SESSION_KEY("SeedChokingAlgorithm"), 1, clampValue(0, 2))
, m_chokingAlgorithm(BITTORRENT_SESSION_KEY("ChokingAlgorithm"), ChokingAlgorithm::FixedSlots
, clampValue(ChokingAlgorithm::FixedSlots, ChokingAlgorithm::RateBased))
, m_seedChokingAlgorithm(BITTORRENT_SESSION_KEY("SeedChokingAlgorithm"), SeedChokingAlgorithm::FastestUpload
, clampValue(SeedChokingAlgorithm::RoundRobin, SeedChokingAlgorithm::AntiLeech))
, m_storedCategories(BITTORRENT_SESSION_KEY("Categories"))
, m_storedTags(BITTORRENT_SESSION_KEY("Tags"))
, m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause)
@ -1324,7 +1327,15 @@ void Session::configure(libtorrent::settings_pack &settingsPack) @@ -1324,7 +1327,15 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
// uTP
settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, isUTPEnabled());
settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, isUTPEnabled());
settingsPack.set_int(libt::settings_pack::mixed_mode_algorithm, utpMixedMode());
switch (utpMixedMode()) {
case MixedModeAlgorithm::TCP:
default:
settingsPack.set_int(libt::settings_pack::mixed_mode_algorithm, libt::settings_pack::prefer_tcp);
break;
case MixedModeAlgorithm::Proportional:
settingsPack.set_int(libt::settings_pack::mixed_mode_algorithm, libt::settings_pack::peer_proportional);
break;
}
settingsPack.set_bool(libt::settings_pack::allow_multiple_connections_per_ip, multiConnectionsPerIpEnabled());
@ -1336,15 +1347,27 @@ void Session::configure(libtorrent::settings_pack &settingsPack) @@ -1336,15 +1347,27 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
settingsPack.set_bool(libt::settings_pack::enable_lsd, isLSDEnabled());
switch (chokingAlgorithm()) {
case 0:
case ChokingAlgorithm::FixedSlots:
default:
settingsPack.set_int(libt::settings_pack::choking_algorithm, libt::settings_pack::fixed_slots_choker);
break;
case 1:
case ChokingAlgorithm::RateBased:
settingsPack.set_int(libt::settings_pack::choking_algorithm, libt::settings_pack::rate_based_choker);
break;
}
settingsPack.set_int(libt::settings_pack::seed_choking_algorithm, seedChokingAlgorithm());
switch (seedChokingAlgorithm()) {
case SeedChokingAlgorithm::RoundRobin:
settingsPack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::round_robin);
break;
case SeedChokingAlgorithm::FastestUpload:
default:
settingsPack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::fastest_upload);
break;
case SeedChokingAlgorithm::AntiLeech:
settingsPack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::anti_leech);
break;
}
}
void Session::configurePeerClasses()
@ -1562,7 +1585,15 @@ void Session::configure(libtorrent::session_settings &sessionSettings) @@ -1562,7 +1585,15 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
sessionSettings.enable_outgoing_utp = isUTPEnabled();
// uTP rate limiting
sessionSettings.rate_limit_utp = isUTPRateLimited();
sessionSettings.mixed_mode_algorithm = utpMixedMode();
switch (utpMixedMode()) {
case MixedModeAlgorithm::TCP:
default:
sessionSettings.mixed_mode_algorithm = libt::session_settings::prefer_tcp;
break;
case MixedModeAlgorithm::Proportional:
sessionSettings.mixed_mode_algorithm = libt::session_settings::peer_proportional;
break;
}
sessionSettings.allow_multiple_connections_per_ip = multiConnectionsPerIpEnabled();
@ -1587,15 +1618,27 @@ void Session::configure(libtorrent::session_settings &sessionSettings) @@ -1587,15 +1618,27 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
m_nativeSession->stop_lsd();
switch (chokingAlgorithm()) {
case 0:
case ChokingAlgorithm::FixedSlots:
default:
sessionSettings.choking_algorithm = libt::session_settings::fixed_slots_choker;
break;
case 1:
case ChokingAlgorithm::RateBased:
sessionSettings.choking_algorithm = libt::session_settings::rate_based_choker;
break;
}
sessionSettings.seed_choking_algorithm = seedChokingAlgorithm();
switch (seedChokingAlgorithm()) {
case SeedChokingAlgorithm::RoundRobin:
sessionSettings.seed_choking_algorithm = libt::session_settings::round_robin;
break;
case SeedChokingAlgorithm::FastestUpload:
default:
sessionSettings.seed_choking_algorithm = libt::session_settings::fastest_upload;
break;
case SeedChokingAlgorithm::AntiLeech:
sessionSettings.seed_choking_algorithm = libt::session_settings::anti_leech;
break;
}
}
#endif
@ -2697,12 +2740,12 @@ void Session::setProxyPeerConnectionsEnabled(bool enabled) @@ -2697,12 +2740,12 @@ void Session::setProxyPeerConnectionsEnabled(bool enabled)
}
}
int Session::chokingAlgorithm() const
ChokingAlgorithm Session::chokingAlgorithm() const
{
return m_chokingAlgorithm;
}
void Session::setChokingAlgorithm(int mode)
void Session::setChokingAlgorithm(ChokingAlgorithm mode)
{
if (mode == m_chokingAlgorithm) return;
@ -2710,12 +2753,12 @@ void Session::setChokingAlgorithm(int mode) @@ -2710,12 +2753,12 @@ void Session::setChokingAlgorithm(int mode)
configureDeferred();
}
int Session::seedChokingAlgorithm() const
SeedChokingAlgorithm Session::seedChokingAlgorithm() const
{
return m_seedChokingAlgorithm;
}
void Session::setSeedChokingAlgorithm(int mode)
void Session::setSeedChokingAlgorithm(SeedChokingAlgorithm mode)
{
if (mode == m_seedChokingAlgorithm) return;
@ -3220,12 +3263,12 @@ void Session::setUTPRateLimited(bool limited) @@ -3220,12 +3263,12 @@ void Session::setUTPRateLimited(bool limited)
}
}
int Session::utpMixedMode() const
MixedModeAlgorithm Session::utpMixedMode() const
{
return m_utpMixedMode;
}
void Session::setUtpMixedMode(int mode)
void Session::setUtpMixedMode(MixedModeAlgorithm mode)
{
if (mode == m_utpMixedMode) return;

50
src/base/bittorrent/session.h

@ -151,6 +151,38 @@ namespace BitTorrent @@ -151,6 +151,38 @@ namespace BitTorrent
uint nbErrored = 0;
};
class SessionSettingsEnums
{
Q_GADGET
public:
// TODO: remove `SessionSettingsEnums` wrapper when we can use `Q_ENUM_NS` directly (QT >= 5.8 only)
enum class ChokingAlgorithm : int
{
FixedSlots = 0,
RateBased = 1
};
Q_ENUM(ChokingAlgorithm)
enum class SeedChokingAlgorithm : int
{
RoundRobin = 0,
FastestUpload = 1,
AntiLeech = 2
};
Q_ENUM(SeedChokingAlgorithm)
enum class MixedModeAlgorithm : int
{
TCP = 0,
Proportional = 1
};
Q_ENUM(MixedModeAlgorithm)
};
using ChokingAlgorithm = SessionSettingsEnums::ChokingAlgorithm;
using SeedChokingAlgorithm = SessionSettingsEnums::SeedChokingAlgorithm;
using MixedModeAlgorithm = SessionSettingsEnums::MixedModeAlgorithm;
#if LIBTORRENT_VERSION_NUM >= 10100
struct SessionMetricIndices
{
@ -317,10 +349,10 @@ namespace BitTorrent @@ -317,10 +349,10 @@ namespace BitTorrent
void setForceProxyEnabled(bool enabled);
bool isProxyPeerConnectionsEnabled() const;
void setProxyPeerConnectionsEnabled(bool enabled);
int chokingAlgorithm() const;
void setChokingAlgorithm(int mode);
int seedChokingAlgorithm() const;
void setSeedChokingAlgorithm(int mode);
ChokingAlgorithm chokingAlgorithm() const;
void setChokingAlgorithm(ChokingAlgorithm mode);
SeedChokingAlgorithm seedChokingAlgorithm() const;
void setSeedChokingAlgorithm(SeedChokingAlgorithm mode);
bool isAddTrackersEnabled() const;
void setAddTrackersEnabled(bool enabled);
QString additionalTrackers() const;
@ -385,8 +417,8 @@ namespace BitTorrent @@ -385,8 +417,8 @@ namespace BitTorrent
void setUTPEnabled(bool enabled);
bool isUTPRateLimited() const;
void setUTPRateLimited(bool limited);
int utpMixedMode() const;
void setUtpMixedMode(int mode);
MixedModeAlgorithm utpMixedMode() const;
void setUtpMixedMode(MixedModeAlgorithm mode);
bool multiConnectionsPerIpEnabled() const;
void setMultiConnectionsPerIpEnabled(bool enabled);
bool isTrackerFilteringEnabled() const;
@ -617,7 +649,7 @@ namespace BitTorrent @@ -617,7 +649,7 @@ namespace BitTorrent
CachedSettingValue<int> m_maxUploadsPerTorrent;
CachedSettingValue<bool> m_isUTPEnabled;
CachedSettingValue<bool> m_isUTPRateLimited;
CachedSettingValue<int> m_utpMixedMode;
CachedSettingValue<MixedModeAlgorithm> m_utpMixedMode;
CachedSettingValue<bool> m_multiConnectionsPerIpEnabled;
CachedSettingValue<bool> m_isAddTrackersEnabled;
CachedSettingValue<QString> m_additionalTrackers;
@ -646,8 +678,8 @@ namespace BitTorrent @@ -646,8 +678,8 @@ namespace BitTorrent
CachedSettingValue<int> m_encryption;
CachedSettingValue<bool> m_isForceProxyEnabled;
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
CachedSettingValue<int> m_chokingAlgorithm;
CachedSettingValue<int> m_seedChokingAlgorithm;
CachedSettingValue<ChokingAlgorithm> m_chokingAlgorithm;
CachedSettingValue<SeedChokingAlgorithm> m_seedChokingAlgorithm;
CachedSettingValue<QVariantMap> m_storedCategories;
CachedSettingValue<QStringList> m_storedTags;
CachedSettingValue<int> m_maxRatioAction;

12
src/gui/advancedsettings.cpp

@ -150,7 +150,7 @@ void AdvancedSettings::saveAdvancedSettings() @@ -150,7 +150,7 @@ void AdvancedSettings::saveAdvancedSettings()
session->setOutgoingPortsMin(outgoing_ports_min.value());
session->setOutgoingPortsMax(outgoing_ports_max.value());
// uTP-TCP mixed mode
session->setUtpMixedMode(comboUtpMixedMode.currentIndex());
session->setUtpMixedMode(static_cast<BitTorrent::MixedModeAlgorithm>(comboUtpMixedMode.currentIndex()));
// multiple connections per IP
session->setMultiConnectionsPerIpEnabled(cbMultiConnectionsPerIp.isChecked());
// Recheck torrents on completion
@ -200,9 +200,9 @@ void AdvancedSettings::saveAdvancedSettings() @@ -200,9 +200,9 @@ void AdvancedSettings::saveAdvancedSettings()
session->setTrackerEnabled(cb_tracker_status.isChecked());
pref->setTrackerPort(spin_tracker_port.value());
// Choking algorithm
session->setChokingAlgorithm(comboChokingAlgorithm.currentIndex());
session->setChokingAlgorithm(static_cast<BitTorrent::ChokingAlgorithm>(comboChokingAlgorithm.currentIndex()));
// Seed choking algorithm
session->setSeedChokingAlgorithm(comboSeedChokingAlgorithm.currentIndex());
session->setSeedChokingAlgorithm(static_cast<BitTorrent::SeedChokingAlgorithm>(comboSeedChokingAlgorithm.currentIndex()));
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
pref->setUpdateCheckEnabled(cb_update_check.isChecked());
@ -344,7 +344,7 @@ void AdvancedSettings::loadAdvancedSettings() @@ -344,7 +344,7 @@ void AdvancedSettings::loadAdvancedSettings()
addRow(OUTGOING_PORT_MAX, tr("Outgoing ports (Max) [0: Disabled]"), &outgoing_ports_max);
// uTP-TCP mixed mode
comboUtpMixedMode.addItems({"Prefer TCP", "Peer proportional (throttles TCP)"});
comboUtpMixedMode.setCurrentIndex(session->utpMixedMode());
comboUtpMixedMode.setCurrentIndex(static_cast<int>(session->utpMixedMode()));
addRow(UTP_MIX_MODE, tr("uTP-TCP mixed mode algorithm"), &comboUtpMixedMode);
// multiple connections per IP
cbMultiConnectionsPerIp.setChecked(session->multiConnectionsPerIpEnabled());
@ -429,11 +429,11 @@ void AdvancedSettings::loadAdvancedSettings() @@ -429,11 +429,11 @@ void AdvancedSettings::loadAdvancedSettings()
addRow(TRACKER_PORT, tr("Embedded tracker port"), &spin_tracker_port);
// Choking algorithm
comboChokingAlgorithm.addItems({"Fixed slots", "Upload rate based"});
comboChokingAlgorithm.setCurrentIndex(session->chokingAlgorithm());
comboChokingAlgorithm.setCurrentIndex(static_cast<int>(session->chokingAlgorithm()));
addRow(CHOKING_ALGORITHM, tr("Upload slots behavior"), &comboChokingAlgorithm);
// Seed choking algorithm
comboSeedChokingAlgorithm.addItems({"Round-robin", "Fastest upload", "Anti-leech"});
comboSeedChokingAlgorithm.setCurrentIndex(session->seedChokingAlgorithm());
comboSeedChokingAlgorithm.setCurrentIndex(static_cast<int>(session->seedChokingAlgorithm()));
addRow(SEED_CHOKING_ALGORITHM, tr("Upload choking algorithm"), &comboSeedChokingAlgorithm);
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)

Loading…
Cancel
Save