Browse Source

- Clean up of bittorrent class

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
d5e2905ead
  1. 36
      src/bittorrent.cpp
  2. 40
      src/bittorrent.h

36
src/bittorrent.cpp

@ -62,7 +62,7 @@
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4}; enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4};
// Main constructor // Main constructor
bittorrent::bittorrent() : DHTEnabled(false), preAllocateAll(false), addInPause(false), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), queueingEnabled(false), geoipDBLoaded(false) { bittorrent::bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), DHTEnabled(false), queueingEnabled(false), geoipDBLoaded(false) {
resolve_countries = false; resolve_countries = false;
// To avoid some exceptions // To avoid some exceptions
fs::path::default_name_check(fs::no_check); fs::path::default_name_check(fs::no_check);
@ -204,7 +204,7 @@ void bittorrent::configureSession() {
qDebug("Configuring session"); qDebug("Configuring session");
// Downloads // Downloads
// * Save path // * Save path
setDefaultSavePath(Preferences::getSavePath()); defaultSavePath = Preferences::getSavePath();
if(Preferences::isTempPathEnabled()) { if(Preferences::isTempPathEnabled()) {
setDefaultTempPath(Preferences::getTempPath()); setDefaultTempPath(Preferences::getTempPath());
} else { } else {
@ -1271,10 +1271,6 @@ void bittorrent::addTorrentsFromScanFolder(QStringList &pathList) {
} }
} }
void bittorrent::setDefaultSavePath(QString savepath) {
defaultSavePath = savepath;
}
QString bittorrent::getDefaultSavePath() const { QString bittorrent::getDefaultSavePath() const {
return defaultSavePath; return defaultSavePath;
} }
@ -1297,6 +1293,7 @@ void bittorrent::setDefaultTempPath(QString temppath) {
h.move_storage(getSavePath(h.hash())); h.move_storage(getSavePath(h.hash()));
} }
} else { } else {
// Moving all downloading torrents to temporary save path
std::vector<torrent_handle> torrents = getTorrents(); std::vector<torrent_handle> torrents = getTorrents();
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
@ -1597,12 +1594,8 @@ void bittorrent::readAlerts() {
if(h.is_valid()){ if(h.is_valid()){
// Authentication // Authentication
if(p->status_code != 401) { if(p->status_code != 401) {
QString hash = h.hash(); qDebug("Received a tracker error for %s: %s", p->url.c_str(), p->msg.c_str());
qDebug("Received a tracker error for %s", p->url.c_str()); trackersErrors[h.hash()][misc::toQString(p->url)] = misc::toQString(p->message());
QHash<QString, QString> errors = trackersErrors.value(hash, QHash<QString, QString>());
// p->url requires at least libtorrent v0.13.1
errors[misc::toQString(p->url)] = QString::fromUtf8(a->message().c_str());
trackersErrors[hash] = errors;
} else { } else {
emit trackerAuthenticationRequired(h); emit trackerAuthenticationRequired(h);
} }
@ -1611,12 +1604,21 @@ void bittorrent::readAlerts() {
else if (tracker_reply_alert* p = dynamic_cast<tracker_reply_alert*>(a.get())) { else if (tracker_reply_alert* p = dynamic_cast<tracker_reply_alert*>(a.get())) {
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
if(h.is_valid()){ if(h.is_valid()){
qDebug("Received a tracker reply from %s", (const char*)h.current_tracker().toLocal8Bit()); qDebug("Received a tracker reply from %s", h.current_tracker().toLocal8Bit().data());
QString hash = h.hash(); // Connection was successful now. Remove possible old errors
QHash<QString, QString> errors = trackersErrors.value(hash, QHash<QString, QString>()); QHash<QString, QString> errors = trackersErrors.value(h.hash(), QHash<QString, QString>());
// p->url requires at least libtorrent v0.13.1 errors.remove(h.current_tracker());
trackersErrors[h.hash()] = errors;
}
} else if (tracker_warning_alert* p = dynamic_cast<tracker_warning_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()){
// Connection was successful now. Remove possible old errors
QHash<QString, QString> errors = trackersErrors.value(h.hash(), QHash<QString, QString>());
errors.remove(h.current_tracker()); errors.remove(h.current_tracker());
trackersErrors[hash] = errors; trackersErrors[h.hash()] = errors;
qDebug("Received a tracker warning from %s: %s", h.current_tracker().toLocal8Bit().data(), p->msg.c_str());
// XXX: The tracker warning is silently ignored... do something with it.
} }
} }
else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a.get())) { else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a.get())) {

40
src/bittorrent.h

@ -53,41 +53,50 @@ class HttpServer;
class bittorrent : public QObject { class bittorrent : public QObject {
Q_OBJECT Q_OBJECT
private: private:
// Bittorrent
session *s; session *s;
QPointer<FileSystemWatcher> FSWatcher;
QPointer<QTimer> timerAlerts; QPointer<QTimer> timerAlerts;
QHash<QString, QString> savepath_fromurl;
QHash<QString, QHash<QString, QString> > trackersErrors;
// Ratio
QPointer<QTimer> BigRatioTimer; QPointer<QTimer> BigRatioTimer;
bool DHTEnabled; // HTTP
QPointer<downloadThread> downloader; QPointer<downloadThread> downloader;
QString defaultSavePath; // File System
QString defaultTempPath; QPointer<FileSystemWatcher> FSWatcher;
QHash<QString, QHash<QString, QString> > trackersErrors; // Console / Log
QStringList consoleMessages; QStringList consoleMessages;
QStringList peerBanMessages; QStringList peerBanMessages;
// Settings
bool preAllocateAll; bool preAllocateAll;
bool addInPause; bool addInPause;
float ratio_limit; float ratio_limit;
bool UPnPEnabled; bool UPnPEnabled;
bool NATPMPEnabled; bool NATPMPEnabled;
bool LSDEnabled; bool LSDEnabled;
QPointer<FilterParserThread> filterParser; bool DHTEnabled;
QString filterPath;
bool queueingEnabled; bool queueingEnabled;
QStringList url_skippingDlg; QString defaultSavePath;
QHash<QString, QString> savepath_fromurl; QString defaultTempPath;
// GeoIP
bool resolve_countries; bool resolve_countries;
bool geoipDBLoaded; bool geoipDBLoaded;
// ETA Computation
QPointer<QTimer> timerETA; QPointer<QTimer> timerETA;
QHash<QString, QList<int> > ETA_samples; QHash<QString, QList<int> > ETA_samples;
// IP filtering
QPointer<FilterParserThread> filterParser;
QString filterPath;
// Web UI // Web UI
QPointer<HttpServer> httpServer; QPointer<HttpServer> httpServer;
QStringList url_skippingDlg;
protected: protected:
QString getSavePath(QString hash); QString getSavePath(QString hash);
bool initWebUi(QString username, QString password, int port); bool initWebUi(QString username, QString password, int port);
public: public:
// Constructor / Destructor // Constructor / Destructor
bittorrent(); bittorrent();
~bittorrent(); ~bittorrent();
@ -114,7 +123,7 @@ class bittorrent : public QObject {
bool useTemporaryFolder() const; bool useTemporaryFolder() const;
QString getDefaultSavePath() const; QString getDefaultSavePath() const;
public slots: public slots:
QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false); QTorrentHandle addTorrent(QString path, bool fromScanDir = false, QString from_url = QString(), bool resumed = false);
QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false); QTorrentHandle addMagnetUri(QString magnet_uri, bool resumed=false);
void importOldTorrents(); void importOldTorrents();
@ -155,7 +164,6 @@ class bittorrent : public QObject {
void setProxySettings(proxy_settings proxySettings, bool trackers=true, bool peers=true, bool web_seeds=true, bool dht=true); void setProxySettings(proxy_settings proxySettings, bool trackers=true, bool peers=true, bool web_seeds=true, bool dht=true);
void setSessionSettings(session_settings sessionSettings); void setSessionSettings(session_settings sessionSettings);
void startTorrentsInPause(bool b); void startTorrentsInPause(bool b);
void setDefaultSavePath(QString savepath);
void setDefaultTempPath(QString temppath); void setDefaultTempPath(QString temppath);
void applyEncryptionSettings(pe_settings se); void applyEncryptionSettings(pe_settings se);
void loadFilesPriorities(QTorrentHandle& h); void loadFilesPriorities(QTorrentHandle& h);
@ -174,14 +182,14 @@ class bittorrent : public QObject {
void configureSession(); void configureSession();
void banIP(QString ip); void banIP(QString ip);
protected slots: protected slots:
void addTorrentsFromScanFolder(QStringList&); void addTorrentsFromScanFolder(QStringList&);
void readAlerts(); void readAlerts();
void loadTrackerFile(QString hash); void loadTrackerFile(QString hash);
void deleteBigRatios(); void deleteBigRatios();
void takeETASamples(); void takeETASamples();
signals: signals:
void addedTorrent(QTorrentHandle& h); void addedTorrent(QTorrentHandle& h);
void deletedTorrent(QString hash); void deletedTorrent(QString hash);
void pausedTorrent(QTorrentHandle& h); void pausedTorrent(QTorrentHandle& h);

Loading…
Cancel
Save