Browse Source

Add option to bind directly to an IP instead of using a network Interface

adaptive-webui-19844
Sjoerd van der Berg 9 years ago
parent
commit
e2f43b3383
  1. 9
      src/base/bittorrent/session.cpp
  2. 18
      src/base/preferences.cpp
  3. 6
      src/base/preferences.h
  4. 23
      src/gui/advancedsettings.cpp
  5. 1
      src/gui/advancedsettings.h

9
src/base/bittorrent/session.cpp

@ -633,7 +633,7 @@ void Session::setSessionSettings()
// Include overhead in transfer limits // Include overhead in transfer limits
sessionSettings.rate_limit_ip_overhead = pref->includeOverheadInLimits(); sessionSettings.rate_limit_ip_overhead = pref->includeOverheadInLimits();
// IP address to announce to trackers // IP address to announce to trackers
sessionSettings.announce_ip = Utils::String::toStdString(pref->getNetworkAddress()); sessionSettings.announce_ip = Utils::String::toStdString(pref->getAnnounceAddress());
// Super seeding // Super seeding
sessionSettings.strict_super_seeding = pref->isSuperSeedingEnabled(); sessionSettings.strict_super_seeding = pref->isSuperSeedingEnabled();
// * Max Half-open connections // * Max Half-open connections
@ -1658,6 +1658,13 @@ const QStringList Session::getListeningIPs()
Logger* const logger = Logger::instance(); Logger* const logger = Logger::instance();
QStringList IPs; QStringList IPs;
//Take the override addresss
const QString networkAddr = pref->getNetworkAddress();
if ( !networkAddr.isEmpty()) {
IPs.append( networkAddr);
return IPs;
}
const QString ifaceName = pref->getNetworkInterface(); const QString ifaceName = pref->getNetworkInterface();
const bool listenIPv6 = pref->getListenIPv6(); const bool listenIPv6 = pref->getListenIPv6();

18
src/base/preferences.cpp

@ -1349,6 +1349,16 @@ QString Preferences::getNetworkInterfaceName() const
return value("Preferences/Connection/InterfaceName").toString(); return value("Preferences/Connection/InterfaceName").toString();
} }
void Preferences::setNetworkAddress(const QString& iface)
{
setValue("Preferences/Connection/InterfaceAddress", iface);
}
QString Preferences::getNetworkAddress() const
{
return value("Preferences/Connection/InterfaceAddress").toString();
}
void Preferences::setNetworkInterfaceName(const QString& iface) void Preferences::setNetworkInterfaceName(const QString& iface)
{ {
setValue("Preferences/Connection/InterfaceName", iface); setValue("Preferences/Connection/InterfaceName", iface);
@ -1364,14 +1374,14 @@ void Preferences::setListenIPv6(bool enable)
setValue("Preferences/Connection/InterfaceListenIPv6", enable); setValue("Preferences/Connection/InterfaceListenIPv6", enable);
} }
QString Preferences::getNetworkAddress() const QString Preferences::getAnnounceAddress() const
{ {
return value("Preferences/Connection/InetAddress").toString(); return value("Preferences/Connection/AnnounceAddress").toString();
} }
void Preferences::setNetworkAddress(const QString& addr) void Preferences::setAnnounceAddress(const QString& addr)
{ {
setValue("Preferences/Connection/InetAddress", addr); setValue("Preferences/Connection/AnnounceAddress", addr);
} }
bool Preferences::isAnonymousModeEnabled() const bool Preferences::isAnonymousModeEnabled() const

6
src/base/preferences.h

@ -363,12 +363,14 @@ public:
void setMaxHalfOpenConnections(int value); void setMaxHalfOpenConnections(int value);
QString getNetworkInterface() const; QString getNetworkInterface() const;
void setNetworkInterface(const QString& iface); void setNetworkInterface(const QString& iface);
QString getNetworkAddress() const;
void setNetworkAddress(const QString& iface);
QString getNetworkInterfaceName() const; QString getNetworkInterfaceName() const;
void setNetworkInterfaceName(const QString& iface); void setNetworkInterfaceName(const QString& iface);
bool getListenIPv6() const; bool getListenIPv6() const;
void setListenIPv6(bool enable); void setListenIPv6(bool enable);
QString getNetworkAddress() const; QString getAnnounceAddress() const;
void setNetworkAddress(const QString& addr); void setAnnounceAddress(const QString& addr);
bool isAnonymousModeEnabled() const; bool isAnonymousModeEnabled() const;
void enableAnonymousMode(bool enabled); void enableAnonymousMode(bool enabled);
bool isSuperSeedingEnabled() const; bool isSuperSeedingEnabled() const;

23
src/gui/advancedsettings.cpp

@ -45,6 +45,8 @@ enum AdvSettingsRows
QBITTORRENT_HEADER, QBITTORRENT_HEADER,
// network interface // network interface
NETWORK_IFACE, NETWORK_IFACE,
//Optional bind address
NETWORK_ADDRESS,
NETWORK_LISTEN_IPV6, NETWORK_LISTEN_IPV6,
// behavior // behavior
SAVE_RESUME_DATA_INTERVAL, SAVE_RESUME_DATA_INTERVAL,
@ -80,7 +82,7 @@ enum AdvSettingsRows
// tracker // tracker
TRACKER_EXCHANGE, TRACKER_EXCHANGE,
ANNOUNCE_ALL_TRACKERS, ANNOUNCE_ALL_TRACKERS,
NETWORK_ADDRESS, ANNOUNCE_ADDRESS,
ROW_COUNT ROW_COUNT
}; };
@ -144,11 +146,18 @@ void AdvancedSettings::saveAdvancedSettings()
// Listen on IPv6 address // Listen on IPv6 address
pref->setListenIPv6(cb_listen_ipv6.isChecked()); pref->setListenIPv6(cb_listen_ipv6.isChecked());
// Network address // Network address
QHostAddress addr(txt_network_address.text().trimmed()); QHostAddress networkAddr(txt_network_address.text().trimmed());
if (addr.isNull()) if (networkAddr.isNull())
pref->setNetworkAddress(""); pref->setNetworkAddress("");
else else
pref->setNetworkAddress(addr.toString()); pref->setNetworkAddress(networkAddr.toString());
// Announce address
QHostAddress announceAddr(txt_announce_address.text().trimmed());
if (announceAddr.isNull())
pref->setAnnounceAddress("");
else
pref->setAnnounceAddress(announceAddr.toString());
// Program notification // Program notification
pref->useProgramNotification(cb_program_notifications.isChecked()); pref->useProgramNotification(cb_program_notifications.isChecked());
// Tracker // Tracker
@ -276,7 +285,11 @@ void AdvancedSettings::loadAdvancedSettings()
addRow(NETWORK_LISTEN_IPV6, tr("Listen on IPv6 address (requires restart)"), &cb_listen_ipv6); addRow(NETWORK_LISTEN_IPV6, tr("Listen on IPv6 address (requires restart)"), &cb_listen_ipv6);
// Network address // Network address
txt_network_address.setText(pref->getNetworkAddress()); txt_network_address.setText(pref->getNetworkAddress());
addRow(NETWORK_ADDRESS, tr("IP Address to report to trackers (requires restart)"), &txt_network_address); addRow(NETWORK_ADDRESS, tr("IP Address to bind to( requires restart))"), &txt_network_address);
// Network address
txt_announce_address.setText(pref->getAnnounceAddress());
addRow(ANNOUNCE_ADDRESS, tr("IP Address to report to trackers (requires restart)"), &txt_announce_address);
// Program notifications // Program notifications
cb_program_notifications.setChecked(pref->useProgramNotification()); cb_program_notifications.setChecked(pref->useProgramNotification());
addRow(PROGRAM_NOTIFICATIONS, tr("Display program on-screen notifications"), &cb_program_notifications); addRow(PROGRAM_NOTIFICATIONS, tr("Display program on-screen notifications"), &cb_program_notifications);

1
src/gui/advancedsettings.h

@ -63,6 +63,7 @@ private:
cb_super_seeding, cb_program_notifications, cb_tracker_status, cb_super_seeding, cb_program_notifications, cb_tracker_status,
cb_confirm_torrent_recheck, cb_enable_tracker_ext, cb_listen_ipv6, cb_announce_all_trackers; cb_confirm_torrent_recheck, cb_enable_tracker_ext, cb_listen_ipv6, cb_announce_all_trackers;
QComboBox combo_iface; QComboBox combo_iface;
QLineEdit txt_announce_address;
QLineEdit txt_network_address; QLineEdit txt_network_address;
// OS dependent settings // OS dependent settings

Loading…
Cancel
Save