2007-03-05 16:55:23 +03:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 18:31:59 +04:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2007-03-05 16:55:23 +03:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* 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.
|
2007-03-05 16:55:23 +03:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 21:00:55 +04:00
|
|
|
* 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.
|
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* Contact : chris@qbittorrent.org
|
2007-03-05 16:55:23 +03:00
|
|
|
*/
|
|
|
|
#ifndef __BITTORRENT_H__
|
|
|
|
#define __BITTORRENT_H__
|
|
|
|
|
2007-06-29 19:23:15 +04:00
|
|
|
#include <QHash>
|
2007-07-23 16:46:36 +04:00
|
|
|
#include <QStringList>
|
2008-09-07 15:31:29 +04:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QPalette>
|
2008-09-13 11:33:41 +04:00
|
|
|
#include <QPointer>
|
2007-06-29 19:23:15 +04:00
|
|
|
|
2007-03-05 16:55:23 +03:00
|
|
|
#include <libtorrent/session.hpp>
|
2007-10-01 13:47:00 +04:00
|
|
|
#include <libtorrent/ip_filter.hpp>
|
2007-08-20 10:29:18 +04:00
|
|
|
#include "qtorrenthandle.h"
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
2009-11-16 23:28:58 +03:00
|
|
|
#define MAX_SAMPLES 20
|
|
|
|
|
2007-03-08 01:36:01 +03:00
|
|
|
class downloadThread;
|
2007-07-30 17:56:31 +04:00
|
|
|
class QTimer;
|
2009-11-12 21:24:51 +03:00
|
|
|
class FileSystemWatcher;
|
2008-05-18 00:32:03 +04:00
|
|
|
class FilterParserThread;
|
2009-11-18 20:46:59 +03:00
|
|
|
class HttpServer;
|
2007-03-08 01:36:01 +03:00
|
|
|
|
2009-11-19 18:04:43 +03:00
|
|
|
class TrackerInfos {
|
|
|
|
public:
|
|
|
|
QString name_or_url;
|
|
|
|
QString last_message;
|
|
|
|
unsigned long num_peers;
|
2009-11-22 14:16:30 +03:00
|
|
|
#ifndef LIBTORRENT_0_15
|
2009-11-23 10:18:28 +03:00
|
|
|
bool verified;
|
|
|
|
uint fail_count;
|
2009-11-22 14:16:30 +03:00
|
|
|
#endif
|
2009-11-19 18:04:43 +03:00
|
|
|
|
|
|
|
//TrackerInfos() {}
|
|
|
|
TrackerInfos(const TrackerInfos &b) {
|
|
|
|
name_or_url = b.name_or_url;
|
|
|
|
Q_ASSERT(!name_or_url.isEmpty());
|
|
|
|
last_message = b.last_message;
|
|
|
|
num_peers = b.num_peers;
|
2009-11-22 14:16:30 +03:00
|
|
|
#ifndef LIBTORRENT_0_15
|
2009-11-23 10:18:28 +03:00
|
|
|
verified = b.verified;
|
|
|
|
fail_count = b.fail_count;
|
2009-11-22 14:16:30 +03:00
|
|
|
#endif
|
2009-11-19 18:04:43 +03:00
|
|
|
}
|
|
|
|
TrackerInfos(QString name_or_url): name_or_url(name_or_url), last_message(""), num_peers(0) {
|
2009-11-22 14:16:30 +03:00
|
|
|
#ifndef LIBTORRENT_0_15
|
2009-11-23 10:18:28 +03:00
|
|
|
fail_count = 0;
|
|
|
|
verified = false;
|
2009-11-22 14:16:30 +03:00
|
|
|
#endif
|
2009-11-19 18:04:43 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-20 11:01:59 +03:00
|
|
|
class Bittorrent : public QObject {
|
2007-03-05 20:35:38 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
private:
|
|
|
|
// Bittorrent
|
|
|
|
session *s;
|
|
|
|
QPointer<QTimer> timerAlerts;
|
|
|
|
QHash<QString, QString> savepath_fromurl;
|
2009-11-19 18:04:43 +03:00
|
|
|
QHash<QString, QHash<QString, TrackerInfos> > trackersInfos;
|
2009-11-19 11:14:04 +03:00
|
|
|
// Ratio
|
|
|
|
QPointer<QTimer> BigRatioTimer;
|
|
|
|
// HTTP
|
|
|
|
QPointer<downloadThread> downloader;
|
|
|
|
// File System
|
|
|
|
QPointer<FileSystemWatcher> FSWatcher;
|
|
|
|
// Console / Log
|
|
|
|
QStringList consoleMessages;
|
|
|
|
QStringList peerBanMessages;
|
|
|
|
// Settings
|
|
|
|
bool preAllocateAll;
|
|
|
|
bool addInPause;
|
|
|
|
float ratio_limit;
|
|
|
|
bool UPnPEnabled;
|
|
|
|
bool NATPMPEnabled;
|
|
|
|
bool LSDEnabled;
|
|
|
|
bool DHTEnabled;
|
|
|
|
bool queueingEnabled;
|
|
|
|
QString defaultSavePath;
|
|
|
|
QString defaultTempPath;
|
|
|
|
// GeoIP
|
|
|
|
bool resolve_countries;
|
|
|
|
bool geoipDBLoaded;
|
|
|
|
// ETA Computation
|
|
|
|
QPointer<QTimer> timerETA;
|
|
|
|
QHash<QString, QList<int> > ETA_samples;
|
|
|
|
// IP filtering
|
|
|
|
QPointer<FilterParserThread> filterParser;
|
|
|
|
QString filterPath;
|
|
|
|
// Web UI
|
|
|
|
QPointer<HttpServer> httpServer;
|
|
|
|
QStringList url_skippingDlg;
|
2009-12-01 00:30:14 +03:00
|
|
|
// Fast exit (async)
|
|
|
|
bool exiting;
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
protected:
|
|
|
|
QString getSavePath(QString hash);
|
|
|
|
bool initWebUi(QString username, QString password, int port);
|
2007-03-05 20:35:38 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
public:
|
|
|
|
// Constructor / Destructor
|
2009-11-20 11:01:59 +03:00
|
|
|
Bittorrent();
|
|
|
|
~Bittorrent();
|
2009-11-19 11:14:04 +03:00
|
|
|
QTorrentHandle getTorrentHandle(QString hash) const;
|
|
|
|
std::vector<torrent_handle> getTorrents() const;
|
|
|
|
bool isFilePreviewPossible(QString fileHash) const;
|
|
|
|
bool isDHTEnabled() const;
|
2009-11-21 18:18:09 +03:00
|
|
|
bool isLSDEnabled() const;
|
2009-11-19 11:14:04 +03:00
|
|
|
float getPayloadDownloadRate() const;
|
|
|
|
float getPayloadUploadRate() const;
|
|
|
|
session_status getSessionStatus() const;
|
|
|
|
int getListenPort() const;
|
|
|
|
float getRealRatio(QString hash) const;
|
|
|
|
session* getSession() const;
|
2009-11-19 18:04:43 +03:00
|
|
|
QHash<QString, TrackerInfos> getTrackersInfo(QString hash) const;
|
2009-11-19 11:14:04 +03:00
|
|
|
bool hasActiveTorrents() const;
|
|
|
|
bool isQueueingEnabled() const;
|
|
|
|
int getMaximumActiveDownloads() const;
|
|
|
|
int getMaximumActiveTorrents() const;
|
|
|
|
int loadTorrentPriority(QString hash);
|
|
|
|
QStringList getConsoleMessages() const;
|
|
|
|
QStringList getPeerBanMessages() const;
|
|
|
|
qlonglong getETA(QString hash);
|
|
|
|
bool useTemporaryFolder() const;
|
|
|
|
QString getDefaultSavePath() const;
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
public slots:
|
|
|
|
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
|
|
|
|
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
|
|
|
|
void importOldTorrents();
|
|
|
|
void applyFormerAttributeFiles(QTorrentHandle h);
|
|
|
|
void importOldTempData(QString torrent_path);
|
|
|
|
void loadSessionState();
|
|
|
|
void saveSessionState();
|
|
|
|
void downloadFromUrl(QString url);
|
|
|
|
void deleteTorrent(QString hash, bool delete_local_files = false);
|
|
|
|
void startUpTorrents();
|
2009-12-01 00:30:14 +03:00
|
|
|
session_proxy asyncDeletion();
|
2009-11-19 11:14:04 +03:00
|
|
|
/* Needed by Web UI */
|
|
|
|
void pauseAllTorrents();
|
|
|
|
void pauseTorrent(QString hash);
|
|
|
|
void resumeTorrent(QString hash);
|
|
|
|
void resumeAllTorrents();
|
|
|
|
/* End Web UI */
|
|
|
|
void saveDHTEntry();
|
|
|
|
void preAllocateAllFiles(bool b);
|
|
|
|
void saveFastResumeData();
|
|
|
|
void enableDirectoryScanning(QString scan_dir);
|
|
|
|
void disableDirectoryScanning();
|
|
|
|
void enableIPFilter(QString filter);
|
|
|
|
void disableIPFilter();
|
|
|
|
void setQueueingEnabled(bool enable);
|
|
|
|
void handleDownloadFailure(QString url, QString reason);
|
|
|
|
void downloadUrlAndSkipDialog(QString url, QString save_path=QString::null);
|
|
|
|
// Session configuration - Setters
|
|
|
|
void setListeningPort(int port);
|
|
|
|
void setMaxConnections(int maxConnec);
|
|
|
|
void setMaxConnectionsPerTorrent(int max);
|
|
|
|
void setMaxUploadsPerTorrent(int max);
|
|
|
|
void setDownloadRateLimit(long rate);
|
|
|
|
void setUploadRateLimit(long rate);
|
|
|
|
void setGlobalRatio(float ratio);
|
|
|
|
void setDeleteRatio(float ratio);
|
|
|
|
void setDHTPort(int dht_port);
|
|
|
|
void setProxySettings(proxy_settings proxySettings, bool trackers=true, bool peers=true, bool web_seeds=true, bool dht=true);
|
|
|
|
void setSessionSettings(session_settings sessionSettings);
|
|
|
|
void startTorrentsInPause(bool b);
|
|
|
|
void setDefaultTempPath(QString temppath);
|
|
|
|
void applyEncryptionSettings(pe_settings se);
|
|
|
|
void setDownloadLimit(QString hash, long val);
|
|
|
|
void setUploadLimit(QString hash, long val);
|
|
|
|
void enableUPnP(bool b);
|
|
|
|
void enableNATPMP(bool b);
|
|
|
|
void enableLSD(bool b);
|
|
|
|
bool enableDHT(bool b);
|
|
|
|
void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText));
|
|
|
|
void addPeerBanMessage(QString msg, bool from_ipfilter);
|
|
|
|
void processDownloadedFile(QString, QString);
|
|
|
|
void addMagnetSkipAddDlg(QString uri);
|
|
|
|
void downloadFromURLList(const QStringList& urls);
|
|
|
|
void configureSession();
|
|
|
|
void banIP(QString ip);
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
protected slots:
|
|
|
|
void addTorrentsFromScanFolder(QStringList&);
|
|
|
|
void readAlerts();
|
|
|
|
void deleteBigRatios();
|
|
|
|
void takeETASamples();
|
2007-03-05 16:55:23 +03:00
|
|
|
|
2009-11-19 11:14:04 +03:00
|
|
|
signals:
|
|
|
|
void addedTorrent(QTorrentHandle& h);
|
|
|
|
void deletedTorrent(QString hash);
|
|
|
|
void pausedTorrent(QTorrentHandle& h);
|
|
|
|
void resumedTorrent(QTorrentHandle& h);
|
|
|
|
void finishedTorrent(QTorrentHandle& h);
|
|
|
|
void fullDiskError(QTorrentHandle& h, QString msg);
|
|
|
|
void trackerError(QString hash, QString time, QString msg);
|
|
|
|
void trackerAuthenticationRequired(QTorrentHandle& h);
|
|
|
|
void newDownloadedTorrent(QString path, QString url);
|
|
|
|
void updateFileSize(QString hash);
|
|
|
|
void downloadFromUrlFailure(QString url, QString reason);
|
|
|
|
void torrentFinishedChecking(QTorrentHandle& h);
|
|
|
|
void metadataReceived(QTorrentHandle &h);
|
2007-03-05 20:35:38 +03:00
|
|
|
};
|
2007-03-05 16:55:23 +03:00
|
|
|
|
|
|
|
#endif
|