From 755b8dec305edf09f59220e56f58091c0fe8d272 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 17 Dec 2009 18:00:21 +0000 Subject: [PATCH] - Peer Exchange can be disabled from preferences --- Changelog | 1 + src/bittorrent.cpp | 16 ++++++++++++++-- src/bittorrent.h | 1 + src/options_imp.cpp | 3 +++ src/preferences.h | 5 +++++ src/ui/options.ui | 18 ++++++++++++++---- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index 4e161982f..ddb949071 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ * Unreleased - Christophe Dumez - v2.1.0 - FEATURE: Torrents can be labeled/categorized - FEATURE: Disk cache size can be set from preferences + - FEATURE: Peer Exchange (PeX) can be disabled from preferences * Thu Dec 10 2009 - Christophe Dumez - v2.0.0 - FEATURE: Added program option to disable splash screen diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 4b20c5144..19c10c6ca 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -88,7 +88,12 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit #ifdef LIBTORRENT_0_15 s->add_extension(create_lt_trackers_plugin); #endif - s->add_extension(&create_ut_pex_plugin); + if(Preferences::isPeXEnabled()) { + PeXEnabled = true; + s->add_extension(&create_ut_pex_plugin); + } else { + PeXEnabled = false; + } s->add_extension(&create_smart_ban_plugin); timerAlerts = new QTimer(); connect(timerAlerts, SIGNAL(timeout()), this, SLOT(readAlerts())); @@ -361,7 +366,14 @@ void Bittorrent::configureSession() { addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue")); } // * PeX - addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue")); + if(PeXEnabled) { + addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue")); + } else { + addConsoleMessage(tr("PeX support [OFF]"), QString::fromUtf8("red")); + } + if(PeXEnabled != Preferences::isPeXEnabled()) { + addConsoleMessage(tr("Restart is required to toggle PeX support"), QString::fromUtf8("red")); + } // * LSD if(Preferences::isLSDEnabled()) { enableLSD(true); diff --git a/src/bittorrent.h b/src/bittorrent.h index 8ea40788f..b1e3ff2c5 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -107,6 +107,7 @@ private: bool NATPMPEnabled; bool LSDEnabled; bool DHTEnabled; + bool PeXEnabled; bool queueingEnabled; QString defaultSavePath; QString defaultTempPath; diff --git a/src/options_imp.cpp b/src/options_imp.cpp index 939689d76..b5fe4af3e 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -214,6 +214,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ connect(spinMaxConnecPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxUploadsPerTorrent, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(checkDHT, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); + connect(checkPeX, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkDifferentDHTPort, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(spinDHTPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(checkLSD, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); @@ -427,6 +428,7 @@ void options_imp::saveOptions(){ settings.setValue(QString::fromUtf8("MaxConnecsPerTorrent"), getMaxConnecsPerTorrent()); settings.setValue(QString::fromUtf8("MaxUploadsPerTorrent"), getMaxUploadsPerTorrent()); settings.setValue(QString::fromUtf8("DHT"), isDHTEnabled()); + settings.setValue(QString::fromUtf8("PeX"), checkPeX->isChecked()); settings.setValue(QString::fromUtf8("sameDHTPortAsBT"), isDHTPortSameAsBT()); settings.setValue(QString::fromUtf8("DHTPort"), getDHTPort()); settings.setValue(QString::fromUtf8("LSD"), isLSDEnabled()); @@ -713,6 +715,7 @@ void options_imp::loadOptions(){ checkDifferentDHTPort->setChecked(!Preferences::isDHTPortSameAsBT()); enableDHTPortSettings(checkDifferentDHTPort->isChecked()); spinDHTPort->setValue(Preferences::getDHTPort()); + checkPeX->setChecked(Preferences::isPeXEnabled()); checkLSD->setChecked(Preferences::isLSDEnabled()); checkAzureusSpoof->setChecked(Preferences::isUtorrentSpoofingEnabled()); comboEncryption->setCurrentIndex(Preferences::getEncryptionSetting()); diff --git a/src/preferences.h b/src/preferences.h index 596006769..a85ff4efa 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -348,6 +348,11 @@ public: return settings.value(QString::fromUtf8("Preferences/Bittorrent/DHT"), true).toBool(); } + static bool isPeXEnabled() { + QSettings settings("qBittorrent", "qBittorrent"); + return settings.value(QString::fromUtf8("Preferences/Bittorrent/PeX"), true).toBool(); + } + static void setDHTEnabled(bool enabled) { QSettings settings("qBittorrent", "qBittorrent"); settings.setValue(QString::fromUtf8("Preferences/Bittorrent/DHT"), enabled); diff --git a/src/ui/options.ui b/src/ui/options.ui index 8efdadcb8..c282cfaf9 100644 --- a/src/ui/options.ui +++ b/src/ui/options.ui @@ -639,7 +639,7 @@ 0 0 642 - 457 + 472 @@ -1125,7 +1125,7 @@ 0 0 - 451 + 602 513 @@ -1546,8 +1546,8 @@ 0 0 - 468 - 347 + 620 + 490 @@ -1636,6 +1636,16 @@ + + + + Enable Peer Exchange / PeX (requires restart) + + + true + + +