From ee6bc3c2e90723d6219dae8693a429e40d00eab2 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 14 Jul 2009 07:50:00 +0000 Subject: [PATCH] - FEATURE: Allow to set a different port for DHT (UDP) than the one used for Bittorrent --- Changelog | 1 + src/GUI.cpp | 9 ++++-- src/bittorrent.cpp | 4 +-- src/options.ui | 73 +++++++++++++++++++++++++++++++++++++++++++-- src/options_imp.cpp | 30 +++++++++++++++++++ src/options_imp.h | 3 ++ 6 files changed, 113 insertions(+), 7 deletions(-) diff --git a/Changelog b/Changelog index f27659d60..8bddb2716 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,7 @@ - FEATURE: Resizing a column in a search results tab affects all tabs - FEATURE: Search results tab columns are now remembered upon startup - FEATURE: Added right click menu in search engine to clear completion history + - FEATURE: Allow to set a different port for DHT (UDP) than the one used for Bittorrent - BUGFIX: Provide more helpful explanation when an I/O error occured - BUGFIX: Stop enforcing UTF-8 and use system locale instead - COSMETIC: Redesigned program preferences diff --git a/src/GUI.cpp b/src/GUI.cpp index 820f13136..59e8cfd8c 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -990,7 +990,7 @@ void GUI::configureSession(bool deleteOptions) { BTSession->setListeningPortsRange(options->getPorts()); unsigned short new_listenPort = BTSession->getListenPort(); if(new_listenPort != old_listenPort) { - BTSession->addConsoleMessage(tr("qBittorrent is bind to port: %1", "e.g: qBittorrent is bind to port: 1666").arg( misc::toQString(new_listenPort))); + BTSession->addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg( misc::toQString(new_listenPort))); } // * Global download limit QPair limits = options->getGlobalBandwidthLimits(); @@ -1079,9 +1079,12 @@ void GUI::configureSession(bool deleteOptions) { // * DHT if(options->isDHTEnabled()) { // Set DHT Port - BTSession->setDHTPort(new_listenPort); + BTSession->setDHTPort(options->getDHTPort()); if(BTSession->enableDHT(true)) { - BTSession->addConsoleMessage(tr("DHT support [ON], port: %1").arg(new_listenPort), QString::fromUtf8("blue")); + int dht_port = new_listenPort; + if(options->getDHTPort()) + dht_port = options->getDHTPort(); + BTSession->addConsoleMessage(tr("DHT support [ON], port: UDP/%1").arg(dht_port), QString::fromUtf8("blue")); } else { BTSession->addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("red")); } diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index fe886c657..e29c7863b 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1072,9 +1072,9 @@ void bittorrent::saveTrackerFile(QString hash) { tracker_file.close(); } -// Set DHT port (>= 1000) +// Set DHT port (>= 1000 or 0 if same as BT) void bittorrent::setDHTPort(int dht_port) { - if(dht_port >= 1000) { + if(dht_port == 0 or dht_port >= 1000) { struct dht_settings DHTSettings; DHTSettings.service_port = dht_port; s->set_dht_settings(DHTSettings); diff --git a/src/options.ui b/src/options.ui index c7b33f72c..66d7d16a8 100644 --- a/src/options.ui +++ b/src/options.ui @@ -1429,13 +1429,13 @@ - + Bittorrent features - + @@ -1446,6 +1446,75 @@ + + + + Use the same port for DHT and Bittorrent + + + true + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 13 + 20 + + + + + + + + false + + + DHT port: + + + + + + + false + + + 1000 + + + 65525 + + + 6882 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/options_imp.cpp b/src/options_imp.cpp index b32e3c4f9..ab5f3c888 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -153,6 +153,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ connect(checkMaxUploadsPerTorrent, SIGNAL(stateChanged(int)), this, SLOT(enableMaxUploadsLimitPerTorrent(int))); connect(checkRatioLimit, SIGNAL(stateChanged(int)), this, SLOT(enableShareRatio(int))); connect(checkRatioRemove, SIGNAL(stateChanged(int)), this, SLOT(enableDeleteRatio(int))); + connect(checkSameDHTPort, SIGNAL(stateChanged(int)), this, SLOT(enableDHTPortSettings(int))); // Proxy tab connect(comboProxyType_http, SIGNAL(currentIndexChanged(int)),this, SLOT(enableProxyHTTP(int))); connect(checkProxyAuth_http, SIGNAL(stateChanged(int)), this, SLOT(enableProxyAuthHTTP(int))); @@ -202,6 +203,8 @@ 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(stateChanged(int)), this, SLOT(enableApplyButton())); + connect(checkSameDHTPort, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); + connect(spinDHTPort, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(checkLSD, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(checkAzureusSpoof, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(comboEncryption, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton())); @@ -396,6 +399,8 @@ 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("sameDHTPortAsBT"), isDHTPortSameAsBT()); + settings.setValue(QString::fromUtf8("DHTPort"), getDHTPort()); settings.setValue(QString::fromUtf8("LSD"), isLSDEnabled()); settings.setValue(QString::fromUtf8("AzureusSpoof"), shouldSpoofAzureus()); settings.setValue(QString::fromUtf8("Encryption"), getEncryptionSetting()); @@ -696,6 +701,9 @@ void options_imp::loadOptions(){ spinMaxUploadsPerTorrent->setEnabled(false); } checkDHT->setChecked(settings.value(QString::fromUtf8("DHT"), true).toBool()); + checkSameDHTPort->setChecked(settings.value(QString::fromUtf8("sameDHTPortAsBT"), true).toBool()); + enableDHTPortSettings(checkSameDHTPort->checkState()); + spinDHTPort->setValue(settings.value(QString::fromUtf8("DHTPort"), 6882).toInt()); checkLSD->setChecked(settings.value(QString::fromUtf8("LSD"), true).toBool()); checkAzureusSpoof->setChecked(settings.value(QString::fromUtf8("AzureusSpoof"), false).toBool()); comboEncryption->setCurrentIndex(settings.value(QString::fromUtf8("Encryption"), 0).toInt()); @@ -867,6 +875,12 @@ bool options_imp::systrayIntegration() const{ return (!checkNoSystray->isChecked()); } +int options_imp::getDHTPort() const { +if(isDHTPortSameAsBT()) + return 0; +return spinDHTPort->value(); +} + // Return Share ratio float options_imp::getDesiredRatio() const{ if(checkRatioLimit->isChecked()){ @@ -1108,6 +1122,18 @@ void options_imp::enableShareRatio(int checkBoxValue){ } } +void options_imp::enableDHTPortSettings(int checkBoxValue) { +if(checkBoxValue != 2){ + //Disable + spinDHTPort->setEnabled(false); + dh_port_lbl->setEnabled(false); + }else{ + //enable + spinDHTPort->setEnabled(true); + dh_port_lbl->setEnabled(true); + } +} + void options_imp::enableDeleteRatio(int checkBoxValue){ if(checkBoxValue != 2){ //Disable @@ -1214,6 +1240,10 @@ bool options_imp::addTorrentsInPause() const { return checkStartPaused->isChecked(); } +bool options_imp::isDHTPortSameAsBT() const { + return checkSameDHTPort->isChecked(); +} + // Proxy settings bool options_imp::isProxyEnabled() const{ return comboProxyType->currentIndex(); diff --git a/src/options_imp.h b/src/options_imp.h index 1efb14e63..313a8f079 100644 --- a/src/options_imp.h +++ b/src/options_imp.h @@ -97,6 +97,8 @@ class options_imp : public QDialog, private Ui::Dialog { int getMaxConnecsPerTorrent() const; int getMaxUploadsPerTorrent() const; bool isDHTEnabled() const; + bool isDHTPortSameAsBT() const; + int getDHTPort() const; bool isPeXEnabled() const; bool isLSDEnabled() const; bool isRSSEnabled() const; @@ -152,6 +154,7 @@ class options_imp : public QDialog, private Ui::Dialog { void enableDeleteRatio(int checkBoxValue); void enableFilter(int checkBoxValue); void enableRSS(int checkBoxValue); + void enableDHTPortSettings(int checkBoxValue); void enableQueueingSystem(int checkBoxValue); void setStyle(int style); void on_buttonBox_accepted();