Add choking_algorithm & seed_choking_algorithm knob

This commit is contained in:
Chocobo1 2017-08-11 17:06:31 +08:00 committed by sledgehammer999
parent d3b4c7bec4
commit 6f54c170ab
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
4 changed files with 73 additions and 3 deletions

View file

@ -312,6 +312,8 @@ 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)
, m_seedChokingAlgorithm(BITTORRENT_SESSION_KEY("SeedChokingAlgorithm"), 1)
, m_storedCategories(BITTORRENT_SESSION_KEY("Categories"))
, m_storedTags(BITTORRENT_SESSION_KEY("Tags"))
, m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause)
@ -380,7 +382,6 @@ Session::Session(QObject *parent)
sessionSettings.auto_scrape_min_interval = 900; // 15 minutes
sessionSettings.connection_speed = 20; // default is 10
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
// Soon to be deprecated there
// 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::connection_speed, 20); // default is 10
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
// Soon to be deprecated there
// More info: https://github.com/arvidn/libtorrent/issues/2251
@ -1335,6 +1335,17 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
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_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()
@ -1583,6 +1594,17 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
m_nativeSession->start_lsd();
else
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
@ -2670,6 +2692,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
{
return m_isAddTrackersEnabled;

View file

@ -317,6 +317,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);
bool isAddTrackersEnabled() const;
void setAddTrackersEnabled(bool enabled);
QString additionalTrackers() const;
@ -631,6 +635,8 @@ namespace BitTorrent
CachedSettingValue<int> m_encryption;
CachedSettingValue<bool> m_isForceProxyEnabled;
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
CachedSettingValue<int> m_chokingAlgorithm;
CachedSettingValue<int> m_seedChokingAlgorithm;
CachedSettingValue<QVariantMap> m_storedCategories;
CachedSettingValue<QStringList> m_storedTags;
CachedSettingValue<int> m_maxRatioAction;

View file

@ -89,6 +89,8 @@ enum AdvSettingsRows
TRACKER_STATUS,
TRACKER_PORT,
// seeding
CHOKING_ALGORITHM,
SEED_CHOKING_ALGORITHM,
SUPER_SEEDING,
// tracker
ANNOUNCE_ALL_TRACKERS,
@ -187,6 +189,11 @@ void AdvancedSettings::saveAdvancedSettings()
// Tracker
session->setTrackerEnabled(cb_tracker_status.isChecked());
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)
pref->setUpdateCheckEnabled(cb_update_check.isChecked());
#endif
@ -390,6 +397,15 @@ void AdvancedSettings::loadAdvancedSettings()
spin_tracker_port.setMaximum(65535);
spin_tracker_port.setValue(pref->getTrackerPort());
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)
cb_update_check.setChecked(pref->isUpdateCheckEnabled());
addRow(UPDATE_CHECK, tr("Check for software updates"), &cb_update_check);

View file

@ -79,7 +79,7 @@ private:
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_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;
// OS dependent settings