mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
Merge pull request #3071 from ppolewicz/interface_bind_fixes
Interface bind fixes
This commit is contained in:
commit
50822a7476
@ -203,6 +203,12 @@ Session::Session(QObject *parent)
|
|||||||
configure();
|
configure();
|
||||||
connect(pref, SIGNAL(changed()), SLOT(configure()));
|
connect(pref, SIGNAL(changed()), SLOT(configure()));
|
||||||
|
|
||||||
|
// Network configuration monitor
|
||||||
|
connect(&m_networkManager, SIGNAL(onlineStateChanged(bool)), SLOT(networkOnlineStateChanged(bool)));
|
||||||
|
connect(&m_networkManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), SLOT(networkConfigurationChange(const QNetworkConfiguration&)));
|
||||||
|
connect(&m_networkManager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), SLOT(networkConfigurationChange(const QNetworkConfiguration&)));
|
||||||
|
connect(&m_networkManager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), SLOT(networkConfigurationChange(const QNetworkConfiguration&)));
|
||||||
|
|
||||||
m_resumeDataTimer->start();
|
m_resumeDataTimer->start();
|
||||||
|
|
||||||
// initialize PortForwarder instance
|
// initialize PortForwarder instance
|
||||||
@ -484,7 +490,7 @@ void Session::configure()
|
|||||||
const unsigned short newListenPort = pref->getSessionPort();
|
const unsigned short newListenPort = pref->getSessionPort();
|
||||||
if (oldListenPort != newListenPort) {
|
if (oldListenPort != newListenPort) {
|
||||||
qDebug("Session port changes in program preferences: %d -> %d", oldListenPort, newListenPort);
|
qDebug("Session port changes in program preferences: %d -> %d", oldListenPort, newListenPort);
|
||||||
setListeningPort(newListenPort);
|
setListeningPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
// * Save path
|
// * Save path
|
||||||
@ -1459,12 +1465,28 @@ void Session::setAppendExtension(bool append)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::networkOnlineStateChanged(const bool online)
|
||||||
|
{
|
||||||
|
Logger::instance()->addMessage(tr("System network status changed to %1", "e.g: System network status changed to ONLINE").arg(online ? tr("ONLINE") : tr("OFFLINE")), Log::INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::networkConfigurationChange(const QNetworkConfiguration& cfg)
|
||||||
|
{
|
||||||
|
const QString configuredInterfaceName = Preferences::instance()->getNetworkInterface();
|
||||||
|
const QString changedInterface = cfg.name();
|
||||||
|
if (configuredInterfaceName.isEmpty() || configuredInterfaceName == changedInterface) {
|
||||||
|
Logger::instance()->addMessage(tr("Network configuration of %1 has changed, refreshing session binding", "e.g: Network configuration of tun0 has changed, refreshing session binding").arg(changedInterface), Log::INFO);
|
||||||
|
setListeningPort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set the ports range in which is chosen the port
|
// Set the ports range in which is chosen the port
|
||||||
// the BitTorrent session will listen to
|
// the BitTorrent session will listen to
|
||||||
void Session::setListeningPort(int port)
|
void Session::setListeningPort()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << port;
|
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
|
const unsigned short port = pref->getSessionPort();
|
||||||
|
qDebug() << Q_FUNC_INFO << port;
|
||||||
Logger* const logger = Logger::instance();
|
Logger* const logger = Logger::instance();
|
||||||
|
|
||||||
std::pair<int,int> ports(port, port);
|
std::pair<int,int> ports(port, port);
|
||||||
@ -1490,18 +1512,23 @@ void Session::setListeningPort(int port)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ip;
|
const QList<QNetworkAddressEntry> addresses = network_iface.addressEntries();
|
||||||
qDebug("This network interface has %d IP addresses", network_iface.addressEntries().size());
|
qDebug("This network interface has %d IP addresses", addresses.size());
|
||||||
foreach (const QNetworkAddressEntry &entry, network_iface.addressEntries()) {
|
QHostAddress ip;
|
||||||
if ((!listen_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv6Protocol))
|
QString ipString;
|
||||||
|| (listen_ipv6 && (entry.ip().protocol() == QAbstractSocket::IPv4Protocol)))
|
QAbstractSocket::NetworkLayerProtocol protocol;
|
||||||
|
foreach (const QNetworkAddressEntry &entry, addresses) {
|
||||||
|
ip = entry.ip();
|
||||||
|
ipString = ip.toString();
|
||||||
|
protocol = ip.protocol();
|
||||||
|
Q_ASSERT(protocol == QAbstractSocket::IPv4Protocol || protocol == QAbstractSocket::IPv6Protocol);
|
||||||
|
if ((!listen_ipv6 && (protocol == QAbstractSocket::IPv6Protocol))
|
||||||
|
|| (listen_ipv6 && (protocol == QAbstractSocket::IPv4Protocol)))
|
||||||
continue;
|
continue;
|
||||||
|
qDebug("Trying to listen on IP %s (%s)", qPrintable(ipString), qPrintable(iface_name));
|
||||||
qDebug("Trying to listen on IP %s (%s)", qPrintable(entry.ip().toString()), qPrintable(iface_name));
|
m_nativeSession->listen_on(ports, ec, ipString.toLatin1().constData(), libt::session::listen_no_system_port);
|
||||||
m_nativeSession->listen_on(ports, ec, entry.ip().toString().toLatin1().constData(), libt::session::listen_no_system_port);
|
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
ip = entry.ip().toString();
|
logger->addMessage(tr("qBittorrent is trying to listen on interface %1 port: %2", "e.g: qBittorrent is trying to listen on interface 192.168.0.1 port: TCP/6881").arg(ipString).arg(port), Log::INFO);
|
||||||
logger->addMessage(tr("qBittorrent is trying to listen on interface %1 port: %2", "e.g: qBittorrent is trying to listen on interface 192.168.0.1 port: TCP/6881").arg(ip).arg(QString::number(port)), Log::INFO);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
|
#include <QNetworkConfigurationManager>
|
||||||
|
|
||||||
#include "core/tristatebool.h"
|
#include "core/tristatebool.h"
|
||||||
#include "core/types.h"
|
#include "core/types.h"
|
||||||
@ -227,6 +228,10 @@ namespace BitTorrent
|
|||||||
void handleRedirectedToMagnet(const QString &url, const QString &magnetUri);
|
void handleRedirectedToMagnet(const QString &url, const QString &magnetUri);
|
||||||
void switchToAlternativeMode(bool alternative);
|
void switchToAlternativeMode(bool alternative);
|
||||||
|
|
||||||
|
// Session reconfiguration triggers
|
||||||
|
void networkOnlineStateChanged(const bool online);
|
||||||
|
void networkConfigurationChange(const QNetworkConfiguration&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Session(QObject *parent = 0);
|
explicit Session(QObject *parent = 0);
|
||||||
~Session();
|
~Session();
|
||||||
@ -242,7 +247,7 @@ namespace BitTorrent
|
|||||||
void setProxySettings(libtorrent::proxy_settings proxySettings);
|
void setProxySettings(libtorrent::proxy_settings proxySettings);
|
||||||
void adjustLimits();
|
void adjustLimits();
|
||||||
void adjustLimits(libtorrent::session_settings &sessionSettings);
|
void adjustLimits(libtorrent::session_settings &sessionSettings);
|
||||||
void setListeningPort(int port);
|
void setListeningPort();
|
||||||
void setDefaultSavePath(const QString &path);
|
void setDefaultSavePath(const QString &path);
|
||||||
void setDefaultTempPath(const QString &path = QString());
|
void setDefaultTempPath(const QString &path = QString());
|
||||||
void preAllocateAllFiles(bool b);
|
void preAllocateAllFiles(bool b);
|
||||||
@ -356,6 +361,8 @@ namespace BitTorrent
|
|||||||
QWaitCondition m_alertsWaitCondition;
|
QWaitCondition m_alertsWaitCondition;
|
||||||
QVector<libtorrent::alert *> m_alerts;
|
QVector<libtorrent::alert *> m_alerts;
|
||||||
|
|
||||||
|
QNetworkConfigurationManager m_networkManager;
|
||||||
|
|
||||||
static Session *m_instance;
|
static Session *m_instance;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user