diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 303b48639..2f464635f 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -283,6 +283,7 @@ 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) , m_isAddTrackersEnabled(BITTORRENT_SESSION_KEY("AddTrackersEnabled"), false) , m_additionalTrackers(BITTORRENT_SESSION_KEY("AdditionalTrackers")) , m_globalMaxRatio(BITTORRENT_SESSION_KEY("GlobalMaxRatio"), -1, [](qreal r) { return r < 0 ? -1. : r;}) @@ -1299,9 +1300,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, isUTPRateLimited() - ? libt::settings_pack::prefer_tcp - : libt::settings_pack::peer_proportional); + switch (utpMixedMode()) { + case 0: + default: + settingsPack.set_int(libt::settings_pack::mixed_mode_algorithm, libt::settings_pack::prefer_tcp); + break; + case 1: + settingsPack.set_int(libt::settings_pack::mixed_mode_algorithm, libt::settings_pack::peer_proportional); + break; + } settingsPack.set_bool(libt::settings_pack::apply_ip_filter_to_trackers, isTrackerFilteringEnabled()); @@ -1521,9 +1528,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 = isUTPRateLimited() - ? libt::session_settings::prefer_tcp - : libt::session_settings::peer_proportional; + switch (utpMixedMode()) { + case 0: + default: + sessionSettings.mixed_mode_algorithm = libt::session_settings::prefer_tcp; + break; + case 1: + sessionSettings.mixed_mode_algorithm = libt::session_settings::peer_proportional; + break; + } sessionSettings.apply_ip_filter_to_trackers = isTrackerFilteringEnabled(); @@ -3090,6 +3103,19 @@ void Session::setUTPRateLimited(bool limited) } } +int Session::utpMixedMode() const +{ + return m_utpMixedMode; +} + +void Session::setUtpMixedMode(int mode) +{ + if (mode == m_utpMixedMode) return; + + m_utpMixedMode = mode; + configureDeferred(); +} + bool Session::isTrackerFilteringEnabled() const { return m_isTrackerFilteringEnabled; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 1697f07e4..b3454a2ee 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -373,6 +373,8 @@ namespace BitTorrent void setUTPEnabled(bool enabled); bool isUTPRateLimited() const; void setUTPRateLimited(bool limited); + int utpMixedMode() const; + void setUtpMixedMode(int mode); bool isTrackerFilteringEnabled() const; void setTrackerFilteringEnabled(bool enabled); QStringList bannedIPs() const; @@ -597,6 +599,7 @@ namespace BitTorrent CachedSettingValue m_maxUploadsPerTorrent; CachedSettingValue m_isUTPEnabled; CachedSettingValue m_isUTPRateLimited; + CachedSettingValue m_utpMixedMode; CachedSettingValue m_isAddTrackersEnabled; CachedSettingValue m_additionalTrackers; CachedSettingValue m_globalMaxRatio; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index cad8c5eca..590c6fe08 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -83,6 +83,7 @@ enum AdvSettingsRows MAX_HALF_OPEN, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, + UTP_MIX_MODE, // embedded tracker TRACKER_STATUS, TRACKER_PORT, @@ -135,6 +136,8 @@ void AdvancedSettings::saveAdvancedSettings() // Outgoing ports session->setOutgoingPortsMin(outgoing_ports_min.value()); session->setOutgoingPortsMax(outgoing_ports_max.value()); + // uTP-TCP mixed mode + session->setUtpMixedMode(comboUtpMixedMode.currentIndex()); // Recheck torrents on completion pref->recheckTorrentsOnCompletion(cb_recheck_completed.isChecked()); // Transfer list refresh interval @@ -300,6 +303,10 @@ void AdvancedSettings::loadAdvancedSettings() outgoing_ports_max.setMaximum(65535); outgoing_ports_max.setValue(session->outgoingPortsMax()); 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()); + addRow(UTP_MIX_MODE, tr("uTP-TCP mixed mode algorithm"), &comboUtpMixedMode); // Recheck completed torrents cb_recheck_completed.setChecked(pref->recheckTorrentsOnCompletion()); addRow(RECHECK_COMPLETED, tr("Recheck torrents on completion"), &cb_recheck_completed); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 069817c33..1b9ecd0cf 100644 --- a/src/gui/advancedsettings.h +++ b/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, 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; - QComboBox combo_iface, combo_iface_address; + QComboBox combo_iface, combo_iface_address, comboUtpMixedMode; QLineEdit txtAnnounceIP; // OS dependent settings