From 4c7a5633dabaf2cd6c6700a5deb23cad0fbcb0b2 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 5 Feb 2011 15:44:48 +0000 Subject: [PATCH] FEATURE: IP address reported to trackers is now customizable --- Changelog | 1 + src/preferences/advancedsettings.h | 18 +++++++++++++++++- src/preferences/preferences.h | 8 ++++++++ src/qtlibtorrent/qbtsession.cpp | 16 ++++++++++++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index 167d82134..4cbc20159 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ * Unknown - Christophe Dumez - v2.7.0 - FEATURE: Added auto-shutdown confirmation dialog - FEATURE: Added option to skip torrent deletion confirmation (Ville Kiiskinen) + - FEATURE: IP address reported to trackers is now customizable * Sun Jan 9 2011 - Christophe Dumez - v2.6.0 - FEATURE: Use system icons (Linux, Qt >= 4.6) diff --git a/src/preferences/advancedsettings.h b/src/preferences/advancedsettings.h index 2e33c2a7d..d1998b42c 100644 --- a/src/preferences/advancedsettings.h +++ b/src/preferences/advancedsettings.h @@ -4,14 +4,16 @@ #include #include #include +#include #include +#include #include #include #include #include "preferences.h" 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, NETWORK_IFACE, PROGRAM_NOTIFICATIONS, TRACKER_STATUS, TRACKER_PORT, +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, NETWORK_ADDRESS, PROGRAM_NOTIFICATIONS, TRACKER_STATUS, TRACKER_PORT, #if defined(Q_WS_WIN) || defined(Q_WS_MAC) UPDATE_CHECK, #endif @@ -34,6 +36,7 @@ private: #if defined(Q_WS_X11) && (QT_VERSION >= QT_VERSION_CHECK(4,6,0)) QCheckBox *cb_use_icon_theme; #endif + QLineEdit *txt_network_address; public: AdvancedSettings(QWidget *parent=0): QTableWidget(parent) { @@ -75,6 +78,7 @@ public: #if defined(Q_WS_X11) && (QT_VERSION >= QT_VERSION_CHECK(4,6,0)) delete cb_use_icon_theme; #endif + delete txt_network_address; } public slots: @@ -109,6 +113,12 @@ public slots: } else { pref.setNetworkInterface(combo_iface->currentText()); } + // Network address + QHostAddress addr(txt_network_address->text().trimmed()); + if(addr.isNull()) + pref.setNetworkAddress(""); + else + pref.setNetworkAddress(addr.toString()); // Program notification pref.useProgramNotification(cb_program_notifications->isChecked()); // Tracker @@ -224,6 +234,12 @@ protected slots: } connect(combo_iface, SIGNAL(currentIndexChanged(int)), this, SLOT(emitSettingsChanged())); setCellWidget(NETWORK_IFACE, VALUE, combo_iface); + // Network address + setItem(NETWORK_ADDRESS, PROPERTY, new QTableWidgetItem(tr("IP Address to report to trackers (requires restart)"))); + txt_network_address = new QLineEdit; + txt_network_address->setText(pref.getNetworkAddress()); + connect(txt_network_address, SIGNAL(textChanged(QString)), this, SLOT(emitSettingsChanged())); + setCellWidget(NETWORK_ADDRESS, VALUE, txt_network_address); // Program notifications setItem(PROGRAM_NOTIFICATIONS, PROPERTY, new QTableWidgetItem(tr("Display program notification balloons"))); cb_program_notifications = new QCheckBox(); diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index f3f7c0d3f..79905cb02 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -846,6 +846,14 @@ public: return value(QString::fromUtf8("Preferences/Connection/Interface"), QString()).toString(); } + void setNetworkAddress(const QString& addr) { + setValue(QString::fromUtf8("Preferences/Connection/InetAddress"), addr); + } + + QString getNetworkAddress() const { + return value(QString::fromUtf8("Preferences/Connection/InetAddress"), QString()).toString(); + } + #if LIBTORRENT_VERSION_MINOR > 14 bool isSuperSeedingEnabled() const { return value(QString::fromUtf8("Preferences/Advanced/SuperSeeding"), false).toBool(); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 56575de5e..6bc3452c6 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -408,6 +408,16 @@ void QBtSession::configureSession() { sessionSettings.ignore_limits_on_local_network = pref.ignoreLimitsOnLAN(); // Include overhead in transfer limits sessionSettings.rate_limit_ip_overhead = pref.includeOverheadInLimits(); + // IP address to announce to trackers + QString announce_ip = pref.getNetworkAddress(); + if(!announce_ip.isEmpty()) { + boost::system::error_code ec; + boost::asio::ip::address addr = boost::asio::ip::address::from_string(announce_ip.toStdString(), ec); + if(!ec) { + addConsoleMessage(tr("Reporting IP address %1 to trackers...").arg(announce_ip)); + sessionSettings.announce_ip = addr; + } + } // Super seeding #if LIBTORRENT_VERSION_MINOR > 14 sessionSettings.strict_super_seeding = pref.isSuperSeedingEnabled(); @@ -1683,12 +1693,14 @@ void QBtSession::setAppendqBExtension(bool append) { // Set the ports range in which is chosen the port the Bittorrent // session will listen to void QBtSession::setListeningPort(int port) { + Preferences pref; std::pair ports(port, port); - const QString& iface_name = Preferences().getNetworkInterface(); + const QString iface_name = pref.getNetworkInterface(); if(iface_name.isEmpty()) { s->listen_on(ports); return; } + // Attempt to listen on provided interface const QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name); if(!network_iface.isValid()) { qDebug("Invalid network interface: %s", qPrintable(iface_name)); @@ -1701,7 +1713,7 @@ void QBtSession::setListeningPort(int port) { qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size()); foreach(const QNetworkAddressEntry &entry, network_iface.addressEntries()) { qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name)); - if(s->listen_on(ports, qPrintable(entry.ip().toString()))) { + if(s->listen_on(ports, entry.ip().toString().toAscii().constData())) { ip = entry.ip().toString(); break; }