Browse Source

Refactor code for reporting listen failure/success.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
08138307da
  1. 45
      src/qtlibtorrent/qbtsession.cpp
  2. 2
      src/qtlibtorrent/qbtsession.h

45
src/qtlibtorrent/qbtsession.cpp

@ -107,8 +107,7 @@ QBtSession::QBtSession()
LSDEnabled(false), LSDEnabled(false),
DHTEnabled(false), current_dht_port(0), queueingEnabled(false), DHTEnabled(false), current_dht_port(0), queueingEnabled(false),
m_torrentExportEnabled(false), m_torrentExportEnabled(false),
m_finishedTorrentExportEnabled(false), m_finishedTorrentExportEnabled(false)
m_randomPortEnabled(false)
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
, geoipDBLoaded(false), resolve_countries(false) , geoipDBLoaded(false), resolve_countries(false)
#endif #endif
@ -285,24 +284,15 @@ void QBtSession::setQueueingEnabled(bool enable) {
void QBtSession::configureSession() { void QBtSession::configureSession() {
qDebug("Configuring session"); qDebug("Configuring session");
Preferences pref; Preferences pref;
if (pref.useRandomPort()) {
pref.setSessionPort(rand() % USHRT_MAX + 1025);
}
const unsigned short old_listenPort = getListenPort(); const unsigned short old_listenPort = getListenPort();
const unsigned short new_listenPort = pref.getSessionPort(); const unsigned short new_listenPort = pref.getSessionPort();
if (pref.useRandomPort()) { // to check if the randomPort checkbox is selected if (old_listenPort != new_listenPort) {
if (!m_randomPortEnabled) { qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort);
m_randomPortEnabled = true; setListeningPort(new_listenPort);
const unsigned short randomPort = rand() % USHRT_MAX + 1025;
setListeningPort(randomPort);
addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(getListenPort())));
pref.setSessionPort(randomPort);
}
} else {
// * Ports binding
m_randomPortEnabled = false;
if (old_listenPort != new_listenPort) {
qDebug("Session port changes in program preferences: %d -> %d", old_listenPort, new_listenPort);
setListeningPort(new_listenPort);
addConsoleMessage(tr("qBittorrent is bound to port: TCP/%1", "e.g: qBittorrent is bound to port: 6881").arg(QString::number(getListenPort())));
}
} }
// Downloads // Downloads
@ -1921,6 +1911,7 @@ void QBtSession::setListeningPort(int port) {
#endif #endif
const QString iface_name = pref.getNetworkInterface(); const QString iface_name = pref.getNetworkInterface();
if (iface_name.isEmpty()) { if (iface_name.isEmpty()) {
addConsoleMessage(tr("qBittorrent is trying to listen on any interface port: TCP/%1", "e.g: qBittorrent is trying to listen on any interface port: TCP/6881").arg(QString::number(port)), "blue");
#if LIBTORRENT_VERSION_NUM >= 001600 #if LIBTORRENT_VERSION_NUM >= 001600
s->listen_on(ports, ec); s->listen_on(ports, ec);
#else #else
@ -1946,15 +1937,10 @@ void QBtSession::setListeningPort(int port) {
if (s->listen_on(ports, entry.ip().toString().toAscii().constData())) { if (s->listen_on(ports, entry.ip().toString().toAscii().constData())) {
#endif #endif
ip = entry.ip().toString(); ip = entry.ip().toString();
addConsoleMessage(tr("qBittorrent is trying to listen on interface %1 port: TCP/%2", "e.g: qBittorrent is trying to listen on interface 192.168.0.1 port: TCP/6881").arg(ip).arg(QString::number(port)), "blue");
break; break;
} }
} }
if (s->is_listening()) {
addConsoleMessage(tr("Listening on IP address %1 on network interface %2...").arg(ip).arg(iface_name));
} else {
qDebug("Failed to listen on any of the IP addresses");
addConsoleMessage(tr("Failed to listen on network interface %1").arg(iface_name), "red");
}
} }
// Set download rate limit // Set download rate limit
@ -2546,7 +2532,8 @@ void QBtSession::readAlerts() {
} }
else if (listen_succeeded_alert *p = dynamic_cast<listen_succeeded_alert*>(a.get())) { else if (listen_succeeded_alert *p = dynamic_cast<listen_succeeded_alert*>(a.get())) {
boost::system::error_code ec; boost::system::error_code ec;
qDebug() << "Sucessfully listening on" << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port(); qDebug() << "Successfully listening on" << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port();
addConsoleMessage(tr("qBittorrent is successfully listening on interface %1 port: TCP/%2", "e.g: qBittorrent is successfully listening on interface 192.168.0.1 port: TCP/6881").arg(p->endpoint.address().to_string(ec).c_str()).arg(QString::number(p->endpoint.port())), "blue");
// Force reannounce on all torrents because some trackers blacklist some ports // Force reannounce on all torrents because some trackers blacklist some ports
std::vector<torrent_handle> torrents = s->get_torrents(); std::vector<torrent_handle> torrents = s->get_torrents();
@ -2555,7 +2542,11 @@ void QBtSession::readAlerts() {
for ( ; it != itend; ++it) { for ( ; it != itend; ++it) {
it->force_reannounce(); it->force_reannounce();
} }
emit listenSucceeded(); }
else if (listen_failed_alert *p = dynamic_cast<listen_failed_alert*>(a.get())) {
boost::system::error_code ec;
qDebug() << "Failed listening on" << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port();
addConsoleMessage(tr("qBittorrent failed listening on interface %1 port: TCP/%2. Reason: %3", "e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use").arg(p->endpoint.address().to_string(ec).c_str()).arg(QString::number(p->endpoint.port())).arg(QString::fromStdString((p->error.message()))), "red");
} }
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())) { else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())) {
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);

2
src/qtlibtorrent/qbtsession.h

@ -224,7 +224,6 @@ signals:
void alternativeSpeedsModeChanged(bool alternative); void alternativeSpeedsModeChanged(bool alternative);
void recursiveTorrentDownloadPossible(const QTorrentHandle &h); void recursiveTorrentDownloadPossible(const QTorrentHandle &h);
void ipFilterParsed(bool error, int ruleCount); void ipFilterParsed(bool error, int ruleCount);
void listenSucceeded();
private: private:
// Bittorrent // Bittorrent
@ -258,7 +257,6 @@ private:
bool m_torrentExportEnabled; bool m_torrentExportEnabled;
bool m_finishedTorrentExportEnabled; bool m_finishedTorrentExportEnabled;
bool appendqBExtension; bool appendqBExtension;
bool m_randomPortEnabled;
QString defaultSavePath; QString defaultSavePath;
QString defaultTempPath; QString defaultTempPath;
// IP filtering // IP filtering

Loading…
Cancel
Save