Browse Source

Merge pull request #12577 from NotTsunami/peer

Allow users to configure no_connect_privileged_ports
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
c3b5668a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/base/bittorrent/session.cpp
  2. 3
      src/base/bittorrent/session.h
  3. 6
      src/gui/advancedsettings.cpp
  4. 3
      src/gui/advancedsettings.h
  5. 5
      src/webui/api/appcontroller.cpp
  6. 10
      src/webui/www/private/views/preferences.html

17
src/base/bittorrent/session.cpp

@ -381,6 +381,7 @@ Session::Session(QObject *parent)
, clampValue(MixedModeAlgorithm::TCP, MixedModeAlgorithm::Proportional)) , clampValue(MixedModeAlgorithm::TCP, MixedModeAlgorithm::Proportional))
, m_multiConnectionsPerIpEnabled(BITTORRENT_SESSION_KEY("MultiConnectionsPerIp"), false) , m_multiConnectionsPerIpEnabled(BITTORRENT_SESSION_KEY("MultiConnectionsPerIp"), false)
, m_validateHTTPSTrackerCertificate(BITTORRENT_SESSION_KEY("ValidateHTTPSTrackerCertificate"), false) , m_validateHTTPSTrackerCertificate(BITTORRENT_SESSION_KEY("ValidateHTTPSTrackerCertificate"), false)
, m_blockPeersOnPrivilegedPorts(BITTORRENT_SESSION_KEY("BlockPeersOnPrivilegedPorts"), false)
, m_isAddTrackersEnabled(BITTORRENT_SESSION_KEY("AddTrackersEnabled"), false) , m_isAddTrackersEnabled(BITTORRENT_SESSION_KEY("AddTrackersEnabled"), false)
, m_additionalTrackers(BITTORRENT_SESSION_KEY("AdditionalTrackers")) , m_additionalTrackers(BITTORRENT_SESSION_KEY("AdditionalTrackers"))
, m_globalMaxRatio(BITTORRENT_SESSION_KEY("GlobalMaxRatio"), -1, [](qreal r) { return r < 0 ? -1. : r;}) , m_globalMaxRatio(BITTORRENT_SESSION_KEY("GlobalMaxRatio"), -1, [](qreal r) { return r < 0 ? -1. : r;})
@ -1044,7 +1045,6 @@ void Session::initializeNativeSession()
pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes
pack.set_int(lt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes pack.set_int(lt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes
pack.set_int(lt::settings_pack::connection_speed, 20); // default is 10 pack.set_int(lt::settings_pack::connection_speed, 20); // default is 10
pack.set_bool(lt::settings_pack::no_connect_privileged_ports, false);
// libtorrent 1.1 enables UPnP & NAT-PMP by default // libtorrent 1.1 enables UPnP & NAT-PMP by default
// turn them off before `lt::session` ctor to avoid split second effects // turn them off before `lt::session` ctor to avoid split second effects
pack.set_bool(lt::settings_pack::enable_upnp, false); pack.set_bool(lt::settings_pack::enable_upnp, false);
@ -1385,6 +1385,8 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack)
settingsPack.set_bool(lt::settings_pack::validate_https_trackers, validateHTTPSTrackerCertificate()); settingsPack.set_bool(lt::settings_pack::validate_https_trackers, validateHTTPSTrackerCertificate());
#endif #endif
settingsPack.set_bool(lt::settings_pack::no_connect_privileged_ports, blockPeersOnPrivilegedPorts());
settingsPack.set_bool(lt::settings_pack::apply_ip_filter_to_trackers, isTrackerFilteringEnabled()); settingsPack.set_bool(lt::settings_pack::apply_ip_filter_to_trackers, isTrackerFilteringEnabled());
settingsPack.set_bool(lt::settings_pack::enable_dht, isDHTEnabled()); settingsPack.set_bool(lt::settings_pack::enable_dht, isDHTEnabled());
@ -3531,6 +3533,19 @@ void Session::setValidateHTTPSTrackerCertificate(const bool enabled)
configureDeferred(); configureDeferred();
} }
bool Session::blockPeersOnPrivilegedPorts() const
{
return m_blockPeersOnPrivilegedPorts;
}
void Session::setBlockPeersOnPrivilegedPorts(const bool enabled)
{
if (enabled == m_blockPeersOnPrivilegedPorts) return;
m_blockPeersOnPrivilegedPorts = enabled;
configureDeferred();
}
bool Session::isTrackerFilteringEnabled() const bool Session::isTrackerFilteringEnabled() const
{ {
return m_isTrackerFilteringEnabled; return m_isTrackerFilteringEnabled;

3
src/base/bittorrent/session.h

@ -418,6 +418,8 @@ namespace BitTorrent
void setMultiConnectionsPerIpEnabled(bool enabled); void setMultiConnectionsPerIpEnabled(bool enabled);
bool validateHTTPSTrackerCertificate() const; bool validateHTTPSTrackerCertificate() const;
void setValidateHTTPSTrackerCertificate(bool enabled); void setValidateHTTPSTrackerCertificate(bool enabled);
bool blockPeersOnPrivilegedPorts() const;
void setBlockPeersOnPrivilegedPorts(bool enabled);
bool isTrackerFilteringEnabled() const; bool isTrackerFilteringEnabled() const;
void setTrackerFilteringEnabled(bool enabled); void setTrackerFilteringEnabled(bool enabled);
QStringList bannedIPs() const; QStringList bannedIPs() const;
@ -687,6 +689,7 @@ namespace BitTorrent
CachedSettingValue<MixedModeAlgorithm> m_utpMixedMode; CachedSettingValue<MixedModeAlgorithm> m_utpMixedMode;
CachedSettingValue<bool> m_multiConnectionsPerIpEnabled; CachedSettingValue<bool> m_multiConnectionsPerIpEnabled;
CachedSettingValue<bool> m_validateHTTPSTrackerCertificate; CachedSettingValue<bool> m_validateHTTPSTrackerCertificate;
CachedSettingValue<bool> m_blockPeersOnPrivilegedPorts;
CachedSettingValue<bool> m_isAddTrackersEnabled; CachedSettingValue<bool> m_isAddTrackersEnabled;
CachedSettingValue<QString> m_additionalTrackers; CachedSettingValue<QString> m_additionalTrackers;
CachedSettingValue<qreal> m_globalMaxRatio; CachedSettingValue<qreal> m_globalMaxRatio;

6
src/gui/advancedsettings.cpp

@ -115,6 +115,7 @@ namespace
#ifdef HAS_HTTPS_TRACKER_VALIDATION #ifdef HAS_HTTPS_TRACKER_VALIDATION
VALIDATE_HTTPS_TRACKER_CERTIFICATE, VALIDATE_HTTPS_TRACKER_CERTIFICATE,
#endif #endif
BLOCK_PEERS_ON_PRIVILEGED_PORTS,
// embedded tracker // embedded tracker
TRACKER_STATUS, TRACKER_STATUS,
TRACKER_PORT, TRACKER_PORT,
@ -230,6 +231,8 @@ void AdvancedSettings::saveAdvancedSettings()
// Validate HTTPS tracker certificate // Validate HTTPS tracker certificate
session->setValidateHTTPSTrackerCertificate(m_checkBoxValidateHTTPSTrackerCertificate.isChecked()); session->setValidateHTTPSTrackerCertificate(m_checkBoxValidateHTTPSTrackerCertificate.isChecked());
#endif #endif
// Disallow connection to peers on privileged ports
session->setBlockPeersOnPrivilegedPorts(m_checkBoxBlockPeersOnPrivilegedPorts.isChecked());
// Recheck torrents on completion // Recheck torrents on completion
pref->recheckTorrentsOnCompletion(m_checkBoxRecheckCompleted.isChecked()); pref->recheckTorrentsOnCompletion(m_checkBoxRecheckCompleted.isChecked());
// Transfer list refresh interval // Transfer list refresh interval
@ -537,6 +540,9 @@ void AdvancedSettings::loadAdvancedSettings()
+ ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#validate_https_trackers", "(?)")) + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#validate_https_trackers", "(?)"))
, &m_checkBoxValidateHTTPSTrackerCertificate); , &m_checkBoxValidateHTTPSTrackerCertificate);
#endif #endif
// Disallow connection to peers on privileged ports
m_checkBoxBlockPeersOnPrivilegedPorts.setChecked(session->blockPeersOnPrivilegedPorts());
addRow(BLOCK_PEERS_ON_PRIVILEGED_PORTS, (tr("Disallow connection to peers on privileged ports") + ' ' + makeLink("https://libtorrent.org/single-page-ref.html#no_connect_privileged_ports", "(?)")), &m_checkBoxBlockPeersOnPrivilegedPorts);
// Recheck completed torrents // Recheck completed torrents
m_checkBoxRecheckCompleted.setChecked(pref->recheckTorrentsOnCompletion()); m_checkBoxRecheckCompleted.setChecked(pref->recheckTorrentsOnCompletion());
addRow(RECHECK_COMPLETED, tr("Recheck torrents on completion"), &m_checkBoxRecheckCompleted); addRow(RECHECK_COMPLETED, tr("Recheck torrents on completion"), &m_checkBoxRecheckCompleted);

3
src/gui/advancedsettings.h

@ -69,7 +69,8 @@ private:
QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts, QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts,
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus, m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers, m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers,
m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxPieceExtentAffinity, m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled; m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity,
m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled;
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm, m_comboBoxSeedChokingAlgorithm; QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm, m_comboBoxSeedChokingAlgorithm;
QLineEdit m_lineEditAnnounceIP; QLineEdit m_lineEditAnnounceIP;

5
src/webui/api/appcontroller.cpp

@ -309,6 +309,8 @@ void AppController::preferencesAction()
data["enable_multi_connections_from_same_ip"] = session->multiConnectionsPerIpEnabled(); data["enable_multi_connections_from_same_ip"] = session->multiConnectionsPerIpEnabled();
// Validate HTTPS tracker certificate // Validate HTTPS tracker certificate
data["validate_https_tracker_certificate"] = session->validateHTTPSTrackerCertificate(); data["validate_https_tracker_certificate"] = session->validateHTTPSTrackerCertificate();
// Disallow connection to peers on privileged ports
data["block_peers_on_privileged_ports"] = session->blockPeersOnPrivilegedPorts();
// Embedded tracker // Embedded tracker
data["enable_embedded_tracker"] = session->isTrackerEnabled(); data["enable_embedded_tracker"] = session->isTrackerEnabled();
data["embedded_tracker_port"] = pref->getTrackerPort(); data["embedded_tracker_port"] = pref->getTrackerPort();
@ -749,6 +751,9 @@ void AppController::setPreferencesAction()
// Validate HTTPS tracker certificate // Validate HTTPS tracker certificate
if (hasKey("validate_https_tracker_certificate")) if (hasKey("validate_https_tracker_certificate"))
session->setValidateHTTPSTrackerCertificate(it.value().toBool()); session->setValidateHTTPSTrackerCertificate(it.value().toBool());
// Disallow connection to peers on privileged ports
if (hasKey("block_peers_on_privileged_ports"))
session->setBlockPeersOnPrivilegedPorts(it.value().toBool());
// Embedded tracker // Embedded tracker
if (hasKey("embedded_tracker_port")) if (hasKey("embedded_tracker_port"))
pref->setTrackerPort(it.value().toInt()); pref->setTrackerPort(it.value().toInt());

10
src/webui/www/private/views/preferences.html

@ -1090,6 +1090,14 @@
<input type="checkbox" id="validateHTTPSTrackerCertificate" /> <input type="checkbox" id="validateHTTPSTrackerCertificate" />
</td> </td>
</tr> </tr>
<tr>
<td>
<label for="blockPeersOnPrivilegedPorts">QBT_TR(Disallow connection to peers on privileged ports:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://libtorrent.org/single-page-ref.html#no_connect_privileged_ports" target="_blank">(?)</a></label>
</td>
<td>
<input type="checkbox" id="blockPeersOnPrivilegedPorts" />
</td>
</tr>
<tr> <tr>
<td> <td>
<label for="enableEmbeddedTracker">QBT_TR(Enable embedded tracker:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="enableEmbeddedTracker">QBT_TR(Enable embedded tracker:)QBT_TR[CONTEXT=OptionsDialog]</label>
@ -1881,6 +1889,7 @@
$('utpTCPMixedModeAlgorithm').setProperty('value', pref.utp_tcp_mixed_mode); $('utpTCPMixedModeAlgorithm').setProperty('value', pref.utp_tcp_mixed_mode);
$('allowMultipleConnectionsFromTheSameIPAddress').setProperty('checked', pref.enable_multi_connections_from_same_ip); $('allowMultipleConnectionsFromTheSameIPAddress').setProperty('checked', pref.enable_multi_connections_from_same_ip);
$('validateHTTPSTrackerCertificate').setProperty('checked', pref.validate_https_tracker_certificate); $('validateHTTPSTrackerCertificate').setProperty('checked', pref.validate_https_tracker_certificate);
$('blockPeersOnPrivilegedPorts').setProperty('checked', pref.no_connect_privileged_ports);
$('enableEmbeddedTracker').setProperty('checked', pref.enable_embedded_tracker); $('enableEmbeddedTracker').setProperty('checked', pref.enable_embedded_tracker);
$('embeddedTrackerPort').setProperty('value', pref.embedded_tracker_port); $('embeddedTrackerPort').setProperty('value', pref.embedded_tracker_port);
$('uploadSlotsBehavior').setProperty('value', pref.upload_slots_behavior); $('uploadSlotsBehavior').setProperty('value', pref.upload_slots_behavior);
@ -2266,6 +2275,7 @@
settings.set('utp_tcp_mixed_mode', $('utpTCPMixedModeAlgorithm').getProperty('value')); settings.set('utp_tcp_mixed_mode', $('utpTCPMixedModeAlgorithm').getProperty('value'));
settings.set('enable_multi_connections_from_same_ip', $('allowMultipleConnectionsFromTheSameIPAddress').getProperty('checked')); settings.set('enable_multi_connections_from_same_ip', $('allowMultipleConnectionsFromTheSameIPAddress').getProperty('checked'));
settings.set('validate_https_tracker_certificate', $('validateHTTPSTrackerCertificate').getProperty('checked')); settings.set('validate_https_tracker_certificate', $('validateHTTPSTrackerCertificate').getProperty('checked'));
settings.set('block_peers_on_privileged_ports', $('blockPeersOnPrivilegedPorts').getProperty('checked'));
settings.set('enable_embedded_tracker', $('enableEmbeddedTracker').getProperty('checked')); settings.set('enable_embedded_tracker', $('enableEmbeddedTracker').getProperty('checked'));
settings.set('embedded_tracker_port', $('embeddedTrackerPort').getProperty('value')); settings.set('embedded_tracker_port', $('embeddedTrackerPort').getProperty('value'));
settings.set('upload_slots_behavior', $('uploadSlotsBehavior').getProperty('value')); settings.set('upload_slots_behavior', $('uploadSlotsBehavior').getProperty('value'));

Loading…
Cancel
Save