Browse Source

The user can force listening on a particular network interface

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
4ec1fd3968
  1. 1
      Changelog
  2. 30
      src/advancedsettings.h
  3. 20
      src/bittorrent.cpp
  4. 10
      src/preferences.h

1
Changelog

@ -2,6 +2,7 @@
- FEATURE: Simplified torrent root folder renaming/truncating (< v2.3.0 is no longer forward compatible) - FEATURE: Simplified torrent root folder renaming/truncating (< v2.3.0 is no longer forward compatible)
- FEATURE: Max number of half-open connections can now be edited - FEATURE: Max number of half-open connections can now be edited
- FEATURE: Added support for strict super seeding - FEATURE: Added support for strict super seeding
- FEATURE: The user can force listening on a particular network interface
- COSMETIC: Display peers country name in tooltip - COSMETIC: Display peers country name in tooltip
* Sun Mar 14 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.2.0 * Sun Mar 14 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.2.0

30
src/advancedsettings.h

@ -5,11 +5,13 @@
#include <QHeaderView> #include <QHeaderView>
#include <QSpinBox> #include <QSpinBox>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox>
#include <QNetworkInterface>
#include "preferences.h" #include "preferences.h"
enum AdvSettingsCols {PROPERTY, VALUE}; enum AdvSettingsCols {PROPERTY, VALUE};
enum AdvSettingsRows {DISK_CACHE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, IGNORE_LIMIT_LAN, COUNT_OVERHEAD, RECHECK_COMPLETED, LIST_REFRESH, RESOLVE_COUNTRIES, RESOLVE_HOSTS, MAX_HALF_OPEN, SUPER_SEEDING }; enum AdvSettingsRows {DISK_CACHE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, IGNORE_LIMIT_LAN, COUNT_OVERHEAD, RECHECK_COMPLETED, LIST_REFRESH, RESOLVE_COUNTRIES, RESOLVE_HOSTS, MAX_HALF_OPEN, SUPER_SEEDING, NETWORK_IFACE };
#define ROW_COUNT 11 #define ROW_COUNT 12
class AdvancedSettings: public QTableWidget { class AdvancedSettings: public QTableWidget {
Q_OBJECT Q_OBJECT
@ -17,6 +19,7 @@ class AdvancedSettings: public QTableWidget {
private: private:
QSpinBox *spin_cache, *outgoing_ports_min, *outgoing_ports_max, *spin_list_refresh, *spin_maxhalfopen; QSpinBox *spin_cache, *outgoing_ports_min, *outgoing_ports_max, *spin_list_refresh, *spin_maxhalfopen;
QCheckBox *cb_ignore_limits_lan, *cb_count_overhead, *cb_recheck_completed, *cb_resolve_countries, *cb_resolve_hosts, *cb_super_seeding; QCheckBox *cb_ignore_limits_lan, *cb_count_overhead, *cb_recheck_completed, *cb_resolve_countries, *cb_resolve_hosts, *cb_super_seeding;
QComboBox *combo_iface;
public: public:
AdvancedSettings(QWidget *parent=0): QTableWidget(parent) { AdvancedSettings(QWidget *parent=0): QTableWidget(parent) {
@ -47,6 +50,7 @@ public:
delete cb_resolve_hosts; delete cb_resolve_hosts;
delete spin_maxhalfopen; delete spin_maxhalfopen;
delete cb_super_seeding; delete cb_super_seeding;
delete combo_iface;
} }
public slots: public slots:
@ -73,6 +77,13 @@ public slots:
// Super seeding // Super seeding
Preferences::enableSuperSeeding(cb_super_seeding->isChecked()); Preferences::enableSuperSeeding(cb_super_seeding->isChecked());
#endif #endif
// Network interface
if(combo_iface->currentIndex() == 0) {
// All interfaces (default)
Preferences::setNetworkInterface(QString::null);
} else {
Preferences::setNetworkInterface(combo_iface->currentText());
}
} }
protected slots: protected slots:
@ -159,6 +170,21 @@ protected slots:
cb_super_seeding->setEnabled(false); cb_super_seeding->setEnabled(false);
#endif #endif
setCellWidget(SUPER_SEEDING, VALUE, cb_super_seeding); setCellWidget(SUPER_SEEDING, VALUE, cb_super_seeding);
// Network interface
setItem(NETWORK_IFACE, PROPERTY, new QTableWidgetItem(tr("Network Interface (requires restart)")));
combo_iface = new QComboBox;
combo_iface->addItem(tr("Any interface", "i.e. Any network interface"));
const QString &current_iface = Preferences::getNetworkInterface();
int i = 1;
foreach(const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
if(iface.name() == "lo") continue;
combo_iface->addItem(iface.name());
if(!current_iface.isEmpty() && iface.name() == current_iface)
combo_iface->setCurrentIndex(i);
++i;
}
connect(combo_iface, SIGNAL(currentIndexChanged(int)), this, SLOT(emitSettingsChanged()));
setCellWidget(NETWORK_IFACE, VALUE, combo_iface);
} }
void emitSettingsChanged() { void emitSettingsChanged() {

20
src/bittorrent.cpp

@ -32,6 +32,9 @@
#include <QDateTime> #include <QDateTime>
#include <QString> #include <QString>
#include <QSettings> #include <QSettings>
#include <QNetworkInterface>
#include <QHostAddress>
#include <QNetworkAddressEntry>
#include <stdlib.h> #include <stdlib.h>
#include "filesystemwatcher.h" #include "filesystemwatcher.h"
@ -1696,7 +1699,22 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
// session will listen to // session will listen to
void Bittorrent::setListeningPort(int port) { void Bittorrent::setListeningPort(int port) {
std::pair<int,int> ports(port, port); std::pair<int,int> ports(port, port);
s->listen_on(ports); const QString& iface_name = Preferences::getNetworkInterface();
if(iface_name.isEmpty()) {
s->listen_on(ports);
return;
}
QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name);
if(!network_iface.isValid()) {
s->listen_on(ports);
return;
}
QString ip = "127.0.0.1";
if(!network_iface.addressEntries().isEmpty()) {
ip = network_iface.addressEntries().first().ip().toString();
}
qDebug("Listening on interface %s with ip %s", qPrintable(iface_name), qPrintable(ip));
s->listen_on(ports, ip.toLocal8Bit().constData());
} }
// Set download rate limit // Set download rate limit

10
src/preferences.h

@ -929,6 +929,16 @@ public:
settings.setValue(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), value); settings.setValue(QString::fromUtf8("Preferences/Connection/MaxHalfOpenConnec"), value);
} }
static void setNetworkInterface(QString iface) {
QSettings settings("qBittorrent", "qBittorrent");
settings.setValue(QString::fromUtf8("Preferences/Connection/Interface"), iface);
}
static QString getNetworkInterface() {
QSettings settings("qBittorrent", "qBittorrent");
return settings.value(QString::fromUtf8("Preferences/Connection/Interface"), QString()).toString();
}
#ifdef LIBTORRENT_0_15 #ifdef LIBTORRENT_0_15
static bool isSuperSeedingEnabled() { static bool isSuperSeedingEnabled() {
QSettings settings("qBittorrent", "qBittorrent"); QSettings settings("qBittorrent", "qBittorrent");

Loading…
Cancel
Save