Browse Source

Add choking_algorithm & seed_choking_algorithm knob

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

52
src/base/bittorrent/session.cpp

@ -312,6 +312,8 @@ Session::Session(QObject *parent)
, m_encryption(BITTORRENT_SESSION_KEY("Encryption"), 0) , m_encryption(BITTORRENT_SESSION_KEY("Encryption"), 0)
, m_isForceProxyEnabled(BITTORRENT_SESSION_KEY("ForceProxy"), true) , m_isForceProxyEnabled(BITTORRENT_SESSION_KEY("ForceProxy"), true)
, m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY("ProxyPeerConnections"), false) , m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY("ProxyPeerConnections"), false)
, m_chokingAlgorithm(BITTORRENT_SESSION_KEY("ChokingAlgorithm"), 0)
, m_seedChokingAlgorithm(BITTORRENT_SESSION_KEY("SeedChokingAlgorithm"), 1)
, m_storedCategories(BITTORRENT_SESSION_KEY("Categories")) , m_storedCategories(BITTORRENT_SESSION_KEY("Categories"))
, m_storedTags(BITTORRENT_SESSION_KEY("Tags")) , m_storedTags(BITTORRENT_SESSION_KEY("Tags"))
, m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause) , m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause)
@ -380,7 +382,6 @@ Session::Session(QObject *parent)
sessionSettings.auto_scrape_min_interval = 900; // 15 minutes sessionSettings.auto_scrape_min_interval = 900; // 15 minutes
sessionSettings.connection_speed = 20; // default is 10 sessionSettings.connection_speed = 20; // default is 10
sessionSettings.no_connect_privileged_ports = false; sessionSettings.no_connect_privileged_ports = false;
sessionSettings.seed_choking_algorithm = libt::session_settings::fastest_upload;
// Disk cache pool is rarely tested in libtorrent and doesn't free buffers // Disk cache pool is rarely tested in libtorrent and doesn't free buffers
// Soon to be deprecated there // Soon to be deprecated there
// More info: https://github.com/arvidn/libtorrent/issues/2251 // More info: https://github.com/arvidn/libtorrent/issues/2251
@ -411,7 +412,6 @@ Session::Session(QObject *parent)
pack.set_int(libt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes pack.set_int(libt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes
pack.set_int(libt::settings_pack::connection_speed, 20); // default is 10 pack.set_int(libt::settings_pack::connection_speed, 20); // default is 10
pack.set_bool(libt::settings_pack::no_connect_privileged_ports, false); pack.set_bool(libt::settings_pack::no_connect_privileged_ports, false);
pack.set_int(libt::settings_pack::seed_choking_algorithm, libt::settings_pack::fastest_upload);
// Disk cache pool is rarely tested in libtorrent and doesn't free buffers // Disk cache pool is rarely tested in libtorrent and doesn't free buffers
// Soon to be deprecated there // Soon to be deprecated there
// More info: https://github.com/arvidn/libtorrent/issues/2251 // More info: https://github.com/arvidn/libtorrent/issues/2251
@ -1319,6 +1319,17 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
if (isDHTEnabled()) if (isDHTEnabled())
settingsPack.set_str(libt::settings_pack::dht_bootstrap_nodes, "dht.libtorrent.org:25401,router.bittorrent.com:6881,router.utorrent.com:6881,dht.transmissionbt.com:6881,dht.aelitis.com:6881"); settingsPack.set_str(libt::settings_pack::dht_bootstrap_nodes, "dht.libtorrent.org:25401,router.bittorrent.com:6881,router.utorrent.com:6881,dht.transmissionbt.com:6881,dht.aelitis.com:6881");
settingsPack.set_bool(libt::settings_pack::enable_lsd, isLSDEnabled()); settingsPack.set_bool(libt::settings_pack::enable_lsd, isLSDEnabled());
switch (chokingAlgorithm()) {
case 0:
default:
settingsPack.set_int(libt::settings_pack::choking_algorithm, libt::settings_pack::fixed_slots_choker);
break;
case 1:
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());
} }
void Session::configurePeerClasses() void Session::configurePeerClasses()
@ -1562,6 +1573,17 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
m_nativeSession->start_lsd(); m_nativeSession->start_lsd();
else else
m_nativeSession->stop_lsd(); m_nativeSession->stop_lsd();
switch (chokingAlgorithm()) {
case 0:
default:
sessionSettings.choking_algorithm = libt::session_settings::fixed_slots_choker;
break;
case 1:
sessionSettings.choking_algorithm = libt::session_settings::rate_based_choker;
break;
}
sessionSettings.seed_choking_algorithm = seedChokingAlgorithm();
} }
#endif #endif
@ -2663,6 +2685,32 @@ void Session::setProxyPeerConnectionsEnabled(bool enabled)
} }
} }
int Session::chokingAlgorithm() const
{
return m_chokingAlgorithm;
}
void Session::setChokingAlgorithm(int mode)
{
if (mode == m_chokingAlgorithm) return;
m_chokingAlgorithm = mode;
configureDeferred();
}
int Session::seedChokingAlgorithm() const
{
return m_seedChokingAlgorithm;
}
void Session::setSeedChokingAlgorithm(int mode)
{
if (mode == m_seedChokingAlgorithm) return;
m_seedChokingAlgorithm = mode;
configureDeferred();
}
bool Session::isAddTrackersEnabled() const bool Session::isAddTrackersEnabled() const
{ {
return m_isAddTrackersEnabled; return m_isAddTrackersEnabled;

6
src/base/bittorrent/session.h

@ -317,6 +317,10 @@ namespace BitTorrent
void setForceProxyEnabled(bool enabled); void setForceProxyEnabled(bool enabled);
bool isProxyPeerConnectionsEnabled() const; bool isProxyPeerConnectionsEnabled() const;
void setProxyPeerConnectionsEnabled(bool enabled); void setProxyPeerConnectionsEnabled(bool enabled);
int chokingAlgorithm() const;
void setChokingAlgorithm(int mode);
int seedChokingAlgorithm() const;
void setSeedChokingAlgorithm(int mode);
bool isAddTrackersEnabled() const; bool isAddTrackersEnabled() const;
void setAddTrackersEnabled(bool enabled); void setAddTrackersEnabled(bool enabled);
QString additionalTrackers() const; QString additionalTrackers() const;
@ -630,6 +634,8 @@ namespace BitTorrent
CachedSettingValue<int> m_encryption; CachedSettingValue<int> m_encryption;
CachedSettingValue<bool> m_isForceProxyEnabled; CachedSettingValue<bool> m_isForceProxyEnabled;
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled; CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
CachedSettingValue<int> m_chokingAlgorithm;
CachedSettingValue<int> m_seedChokingAlgorithm;
CachedSettingValue<QVariantMap> m_storedCategories; CachedSettingValue<QVariantMap> m_storedCategories;
CachedSettingValue<QStringList> m_storedTags; CachedSettingValue<QStringList> m_storedTags;
CachedSettingValue<int> m_maxRatioAction; CachedSettingValue<int> m_maxRatioAction;

16
src/gui/advancedsettings.cpp

@ -89,6 +89,8 @@ enum AdvSettingsRows
TRACKER_STATUS, TRACKER_STATUS,
TRACKER_PORT, TRACKER_PORT,
// seeding // seeding
CHOKING_ALGORITHM,
SEED_CHOKING_ALGORITHM,
SUPER_SEEDING, SUPER_SEEDING,
// tracker // tracker
ANNOUNCE_ALL_TRACKERS, ANNOUNCE_ALL_TRACKERS,
@ -187,6 +189,11 @@ void AdvancedSettings::saveAdvancedSettings()
// Tracker // Tracker
session->setTrackerEnabled(cb_tracker_status.isChecked()); session->setTrackerEnabled(cb_tracker_status.isChecked());
pref->setTrackerPort(spin_tracker_port.value()); pref->setTrackerPort(spin_tracker_port.value());
// Choking algorithm
session->setChokingAlgorithm(comboChokingAlgorithm.currentIndex());
// Seed choking algorithm
session->setSeedChokingAlgorithm(comboSeedChokingAlgorithm.currentIndex());
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
pref->setUpdateCheckEnabled(cb_update_check.isChecked()); pref->setUpdateCheckEnabled(cb_update_check.isChecked());
#endif #endif
@ -391,6 +398,15 @@ void AdvancedSettings::loadAdvancedSettings()
spin_tracker_port.setMaximum(65535); spin_tracker_port.setMaximum(65535);
spin_tracker_port.setValue(pref->getTrackerPort()); spin_tracker_port.setValue(pref->getTrackerPort());
addRow(TRACKER_PORT, tr("Embedded tracker port"), &spin_tracker_port); addRow(TRACKER_PORT, tr("Embedded tracker port"), &spin_tracker_port);
// Choking algorithm
comboChokingAlgorithm.addItems({"Fixed slots", "Upload rate based"});
comboChokingAlgorithm.setCurrentIndex(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());
addRow(SEED_CHOKING_ALGORITHM, tr("Upload choking algorithm"), &comboSeedChokingAlgorithm);
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
cb_update_check.setChecked(pref->isUpdateCheckEnabled()); cb_update_check.setChecked(pref->isUpdateCheckEnabled());
addRow(UPDATE_CHECK, tr("Check for software updates"), &cb_update_check); addRow(UPDATE_CHECK, tr("Check for software updates"), &cb_update_check);

2
src/gui/advancedsettings.h

@ -79,7 +79,7 @@ private:
QCheckBox cb_os_cache, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, cb_super_seeding, QCheckBox cb_os_cache, cb_recheck_completed, cb_resolve_countries, cb_resolve_hosts, cb_super_seeding,
cb_program_notifications, cb_torrent_added_notifications, cb_tracker_favicon, cb_tracker_status, cb_program_notifications, cb_torrent_added_notifications, cb_tracker_favicon, cb_tracker_status,
cb_confirm_torrent_recheck, cb_confirm_remove_all_tags, cb_listen_ipv6, cb_announce_all_trackers, cbGuidedReadCache, cbMultiConnectionsPerIp; cb_confirm_torrent_recheck, cb_confirm_remove_all_tags, cb_listen_ipv6, cb_announce_all_trackers, cbGuidedReadCache, cbMultiConnectionsPerIp;
QComboBox combo_iface, combo_iface_address, comboUtpMixedMode; QComboBox combo_iface, combo_iface_address, comboUtpMixedMode, comboChokingAlgorithm, comboSeedChokingAlgorithm;
QLineEdit txtAnnounceIP; QLineEdit txtAnnounceIP;
// OS dependent settings // OS dependent settings

Loading…
Cancel
Save