Browse Source

Move network related code to core/net.

adaptive-webui-19844
Vladimir Golovnev (Glassez) 10 years ago
parent
commit
4b5e7e6168
  1. 14
      src/core/core.pri
  2. 2
      src/core/net/dnsupdater.cpp
  3. 5
      src/core/net/dnsupdater.h
  4. 69
      src/core/net/reverseresolution.cpp
  5. 67
      src/core/net/reverseresolution.h
  6. 4
      src/core/net/smtp.cpp
  7. 8
      src/core/net/smtp.h
  8. 4
      src/core/qtlibtorrent/qbtsession.cpp
  9. 1
      src/gui/gui.pri
  10. 4
      src/gui/options_imp.cpp
  11. 6
      src/gui/properties/peerlistwidget.cpp
  12. 8
      src/gui/properties/peerlistwidget.h
  13. 4
      src/webui/webui.cpp
  14. 14
      src/webui/webui.h

14
src/core/core.pri

@ -10,8 +10,6 @@ HEADERS += \ @@ -10,8 +10,6 @@ HEADERS += \
$$PWD/filesystemwatcher.h \
$$PWD/scannedfoldersmodel.h \
$$PWD/qinisettings.h \
$$PWD/smtp.h \
$$PWD/dnsupdater.h \
$$PWD/logger.h \
$$PWD/preferences.h \
$$PWD/qtracker.h \
@ -21,7 +19,10 @@ HEADERS += \ @@ -21,7 +19,10 @@ HEADERS += \
$$PWD/http/responsegenerator.h \
$$PWD/http/server.h \
$$PWD/http/types.h \
$$PWD/http/responsebuilder.h
$$PWD/http/responsebuilder.h \
$$PWD/net/dnsupdater.h \
$$PWD/net/reverseresolution.h \
$$PWD/net/smtp.h
SOURCES += \
$$PWD/downloadthread.cpp \
@ -29,8 +30,6 @@ SOURCES += \ @@ -29,8 +30,6 @@ SOURCES += \
$$PWD/torrentpersistentdata.cpp \
$$PWD/misc.cpp \
$$PWD/fs_utils.cpp \
$$PWD/smtp.cpp \
$$PWD/dnsupdater.cpp \
$$PWD/logger.cpp \
$$PWD/preferences.cpp \
$$PWD/qtracker.cpp \
@ -38,4 +37,7 @@ SOURCES += \ @@ -38,4 +37,7 @@ SOURCES += \
$$PWD/http/requestparser.cpp \
$$PWD/http/responsegenerator.cpp \
$$PWD/http/server.cpp \
$$PWD/http/responsebuilder.cpp
$$PWD/http/responsebuilder.cpp \
$$PWD/net/dnsupdater.cpp \
$$PWD/net/reverseresolution.cpp \
$$PWD/net/smtp.cpp

2
src/core/dnsupdater.cpp → src/core/net/dnsupdater.cpp

@ -38,6 +38,8 @@ @@ -38,6 +38,8 @@
#include "dnsupdater.h"
#include "logger.h"
using namespace Net;
DNSUpdater::DNSUpdater(QObject *parent) :
QObject(parent), m_state(OK), m_service(DNS::NONE)
{

5
src/core/dnsupdater.h → src/core/net/dnsupdater.h

@ -38,6 +38,9 @@ @@ -38,6 +38,9 @@
#include <QTimer>
#include "preferences.h"
namespace Net
{
/*!
* Based on http://www.dyndns.com/developers/specs/
*/
@ -78,4 +81,6 @@ private: @@ -78,4 +81,6 @@ private:
enum State { OK, INVALID_CREDS, FATAL };
};
}
#endif // DNSUPDATER_H

69
src/gui/reverseresolution.h → src/core/net/reverseresolution.cpp

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
@ -28,14 +28,9 @@ @@ -28,14 +28,9 @@
* Contact : chris@qbittorrent.org
*/
#ifndef REVERSERESOLUTION_H
#define REVERSERESOLUTION_H
#include <QList>
#include <QCache>
#include <QDebug>
#include <QHostInfo>
#include "misc.h"
#include <QString>
#include <boost/version.hpp>
#if BOOST_VERSION < 103500
@ -44,39 +39,45 @@ @@ -44,39 +39,45 @@
#include <boost/asio/ip/tcp.hpp>
#endif
#include "reverseresolution.h"
const int CACHE_SIZE = 500;
class ReverseResolution: public QObject {
Q_OBJECT
Q_DISABLE_COPY(ReverseResolution)
using namespace Net;
static inline bool isUsefulHostName(const QString &hostname, const QString &ip)
{
return (!hostname.isEmpty() && hostname != ip);
}
public:
explicit ReverseResolution(QObject* parent): QObject(parent) {
ReverseResolution::ReverseResolution(QObject *parent)
: QObject(parent)
{
m_cache.setMaxCost(CACHE_SIZE);
}
}
~ReverseResolution() {
ReverseResolution::~ReverseResolution()
{
qDebug("Deleting host name resolver...");
}
}
void resolve(const QString &ip) {
void ReverseResolution::resolve(const QString &ip)
{
if (m_cache.contains(ip)) {
const QString& hostname = *m_cache.object(ip);
const QString &hostname = *m_cache.object(ip);
qDebug() << "Resolved host name using cache: " << ip << " -> " << hostname;
if (isUsefulHostName(hostname, ip))
emit ip_resolved(ip, hostname);
return;
emit ipResolved(ip, hostname);
}
else {
// Actually resolve the ip
m_lookups.insert(QHostInfo::lookupHost(ip, this, SLOT(hostResolved(QHostInfo))), ip);
}
}
signals:
void ip_resolved(const QString &ip, const QString &hostname);
private slots:
void hostResolved(const QHostInfo& host) {
const QString& ip = m_lookups.take(host.lookupId());
void ReverseResolution::hostResolved(const QHostInfo &host)
{
const QString &ip = m_lookups.take(host.lookupId());
Q_ASSERT(!ip.isNull());
if (host.error() != QHostInfo::NoError) {
@ -84,22 +85,10 @@ private slots: @@ -84,22 +85,10 @@ private slots:
return;
}
const QString& hostname = host.hostName();
const QString &hostname = host.hostName();
qDebug() << Q_FUNC_INFO << ip << QString("->") << hostname;
m_cache.insert(ip, new QString(hostname));
if (isUsefulHostName(hostname, ip))
emit ip_resolved(ip, hostname);
}
private:
static inline bool isUsefulHostName(const QString& hostname, const QString& ip) {
return (!hostname.isEmpty() && hostname != ip);
}
QHash<int /* LookupID */, QString /* IP */> m_lookups;
QCache<QString /* IP */, QString /* HostName */> m_cache;
};
#endif // REVERSERESOLUTION_H
emit ipResolved(ip, hostname);
}

67
src/core/net/reverseresolution.h

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef NET_REVERSERESOLUTION_H
#define NET_REVERSERESOLUTION_H
#include <QCache>
#include <QObject>
QT_BEGIN_NAMESPACE
class QHostInfo;
class QString;
QT_END_NAMESPACE
namespace Net
{
class ReverseResolution : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(ReverseResolution)
public:
explicit ReverseResolution(QObject *parent = 0);
~ReverseResolution();
void resolve(const QString &ip);
signals:
void ipResolved(const QString &ip, const QString &hostname);
private slots:
void hostResolved(const QHostInfo &host);
private:
QHash<int /* LookupID */, QString /* IP */> m_lookups;
QCache<QString /* IP */, QString /* HostName */> m_cache;
};
}
#endif // NET_REVERSERESOLUTION_H

4
src/core/smtp.cpp → src/core/net/smtp.cpp

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
@ -89,6 +89,8 @@ QByteArray determineFQDN() @@ -89,6 +89,8 @@ QByteArray determineFQDN()
}
} // namespace
using namespace Net;
Smtp::Smtp(QObject *parent): QObject(parent),
state(Init), use_ssl(false) {
#ifndef QT_NO_OPENSSL

8
src/core/smtp.h → src/core/net/smtp.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
@ -50,6 +50,9 @@ class QTcpSocket; @@ -50,6 +50,9 @@ class QTcpSocket;
class QTextCodec;
QT_END_NAMESPACE
namespace Net
{
class Smtp : public QObject {
Q_OBJECT
@ -96,4 +99,7 @@ private: @@ -96,4 +99,7 @@ private:
QString username;
QString password;
};
}
#endif

4
src/core/qtlibtorrent/qbtsession.cpp

@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
#include <QProcess>
#include <QCoreApplication>
#include "smtp.h"
#include "core/net/smtp.h"
#include "filesystemwatcher.h"
#include "torrentspeedmonitor.h"
#include "torrentstatistics.h"
@ -2046,7 +2046,7 @@ void QBtSession::sendNotificationEmail(const QTorrentHandle &h) { @@ -2046,7 +2046,7 @@ void QBtSession::sendNotificationEmail(const QTorrentHandle &h) {
content += tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds").arg(misc::userFriendlyDuration(status.active_time)) + "\n\n\n";
content += tr("Thank you for using qBittorrent.") + "\n";
// Send the notification email
Smtp *sender = new Smtp(this);
Net::Smtp *sender = new Net::Smtp(this);
sender->sendMail("notification@qbittorrent.org", Preferences::instance()->getMailNotificationEmail(), tr("[qBittorrent] %1 has finished downloading").arg(h.name()), content);
}

1
src/gui/gui.pri

@ -22,7 +22,6 @@ HEADERS += \ @@ -22,7 +22,6 @@ HEADERS += \
$$PWD/torrentcontenttreeview.h \
$$PWD/deletionconfirmationdlg.h \
$$PWD/statusbar.h \
$$PWD/reverseresolution.h \
$$PWD/ico.h \
$$PWD/speedlimitdlg.h \
$$PWD/about_imp.h \

4
src/gui/options_imp.cpp

@ -48,7 +48,7 @@ @@ -48,7 +48,7 @@
#include "scannedfoldersmodel.h"
#include "qbtsession.h"
#include "iconprovider.h"
#include "dnsupdater.h"
#include "core/net/dnsupdater.h"
#ifndef QT_NO_OPENSSL
#include <QSslKey>
@ -1239,7 +1239,7 @@ void options_imp::on_btnWebUiKey_clicked() { @@ -1239,7 +1239,7 @@ void options_imp::on_btnWebUiKey_clicked() {
}
void options_imp::on_registerDNSBtn_clicked() {
QDesktopServices::openUrl(DNSUpdater::getRegistrationUrl(comboDNSService->currentIndex()));
QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(comboDNSService->currentIndex()));
}
void options_imp::on_IpFilterRefreshBtn_clicked() {

6
src/gui/properties/peerlistwidget.cpp

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
#include "peerlistwidget.h"
#include "peerlistdelegate.h"
#include "peerlistsortmodel.h"
#include "reverseresolution.h"
#include "core/net/reverseresolution.h"
#include "preferences.h"
#include "propertieswidget.h"
#include "geoipmanager.h"
@ -126,8 +126,8 @@ void PeerListWidget::updatePeerHostNameResolutionState() @@ -126,8 +126,8 @@ void PeerListWidget::updatePeerHostNameResolutionState()
{
if (Preferences::instance()->resolvePeerHostNames()) {
if (!m_resolver) {
m_resolver = new ReverseResolution(this);
connect(m_resolver, SIGNAL(ip_resolved(QString,QString)), SLOT(handleResolved(QString,QString)));
m_resolver = new Net::ReverseResolution(this);
connect(m_resolver, SIGNAL(ipResolved(QString,QString)), SLOT(handleResolved(QString,QString)));
loadPeers(m_properties->getCurrentTorrent(), true);
}
} else {

8
src/gui/properties/peerlistwidget.h

@ -37,9 +37,13 @@ @@ -37,9 +37,13 @@
#include <QSet>
#include <libtorrent/version.hpp>
namespace Net
{
class ReverseResolution;
}
class PeerListDelegate;
class PeerListSortModel;
class ReverseResolution;
class PropertiesWidget;
class QTorrentHandle;
@ -103,7 +107,7 @@ private: @@ -103,7 +107,7 @@ private:
QHash<QString, QStandardItem*> m_peerItems;
QHash<QString, boost::asio::ip::tcp::endpoint> m_peerEndpoints;
QSet<QString> m_missingFlags;
QPointer<ReverseResolution> m_resolver;
QPointer<Net::ReverseResolution> m_resolver;
PropertiesWidget *m_properties;
bool m_displayFlags;
};

4
src/webui/webui.cpp

@ -29,7 +29,7 @@ @@ -29,7 +29,7 @@
#include "webui.h"
#include "http/server.h"
#include "webapplication.h"
#include "dnsupdater.h"
#include "core/net/dnsupdater.h"
#include "preferences.h"
#include "logger.h"
@ -82,7 +82,7 @@ void WebUI::init() @@ -82,7 +82,7 @@ void WebUI::init()
// DynDNS
if (pref->isDynDNSEnabled()) {
if (!dynDNSUpdater_)
dynDNSUpdater_ = new DNSUpdater(this);
dynDNSUpdater_ = new Net::DNSUpdater(this);
else
dynDNSUpdater_->updateCredentials();
}

14
src/webui/webui.h

@ -32,8 +32,16 @@ @@ -32,8 +32,16 @@
#include <QObject>
#include <QPointer>
namespace Http { class Server; }
class DNSUpdater;
namespace Http
{
class Server;
}
namespace Net
{
class DNSUpdater;
}
class AbstractWebApplication;
class WebUI : public QObject
@ -48,7 +56,7 @@ private slots: @@ -48,7 +56,7 @@ private slots:
private:
QPointer<Http::Server> httpServer_;
QPointer<DNSUpdater> dynDNSUpdater_;
QPointer<Net::DNSUpdater> dynDNSUpdater_;
QPointer<AbstractWebApplication> webapp_;
};

Loading…
Cancel
Save