diff --git a/Changelog b/Changelog index a1864ec7b..b1f6521e8 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ * Unreleased - Christophe Dumez - v2.6.6 + - FEATURE: IP address reported to trackers is now customizable - COSMETIC: Improve main window layout - COSMETIC: Improve properties buttons style - COSMETIC: Display pieces being downloaded in green instead of yellow diff --git a/src/preferences/advancedsettings.h b/src/preferences/advancedsettings.h index 0620dc0d5..306038279 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 @@ -33,6 +35,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) { @@ -73,6 +76,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: @@ -107,6 +111,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 @@ -221,6 +231,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 531617ec8..e9e5b4d95 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 36e154f32..6e94a72c9 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; }