FEATURE: IP address reported to trackers is now customizable

This commit is contained in:
Christophe Dumez 2011-02-05 15:44:48 +00:00
parent 76d3e9033d
commit 4c7a5633da
4 changed files with 40 additions and 3 deletions

View file

@ -1,6 +1,7 @@
* Unknown - Christophe Dumez <chris@qbittorrent.org> - 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 <chris@qbittorrent.org> - v2.6.0
- FEATURE: Use system icons (Linux, Qt >= 4.6)

View file

@ -4,14 +4,16 @@
#include <QTableWidget>
#include <QHeaderView>
#include <QSpinBox>
#include <QHostAddress>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
#include <QNetworkInterface>
#include <libtorrent/version.hpp>
#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();

View file

@ -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();

View file

@ -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<int,int> 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;
}