|
|
@ -51,7 +51,8 @@ |
|
|
|
#include "httpserver.h" |
|
|
|
#include "httpserver.h" |
|
|
|
#include "bandwidthscheduler.h" |
|
|
|
#include "bandwidthscheduler.h" |
|
|
|
#include <libtorrent/extensions/ut_metadata.hpp> |
|
|
|
#include <libtorrent/extensions/ut_metadata.hpp> |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#include <libtorrent/version.hpp> |
|
|
|
|
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
#include <libtorrent/extensions/lt_trackers.hpp> |
|
|
|
#include <libtorrent/extensions/lt_trackers.hpp> |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#include <libtorrent/extensions/ut_pex.hpp> |
|
|
|
#include <libtorrent/extensions/ut_pex.hpp> |
|
|
@ -121,7 +122,7 @@ Bittorrent::Bittorrent() |
|
|
|
// Enabling plugins
|
|
|
|
// Enabling plugins
|
|
|
|
//s->add_extension(&create_metadata_plugin);
|
|
|
|
//s->add_extension(&create_metadata_plugin);
|
|
|
|
s->add_extension(&create_ut_metadata_plugin); |
|
|
|
s->add_extension(&create_ut_metadata_plugin); |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
s->add_extension(create_lt_trackers_plugin); |
|
|
|
s->add_extension(create_lt_trackers_plugin); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
if(Preferences::isPeXEnabled()) { |
|
|
|
if(Preferences::isPeXEnabled()) { |
|
|
@ -141,7 +142,7 @@ Bittorrent::Bittorrent() |
|
|
|
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); |
|
|
|
connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); |
|
|
|
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); |
|
|
|
connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); |
|
|
|
appendLabelToSavePath = Preferences::appendTorrentLabel(); |
|
|
|
appendLabelToSavePath = Preferences::appendTorrentLabel(); |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
appendqBExtension = Preferences::useIncompleteFilesExtension(); |
|
|
|
appendqBExtension = Preferences::useIncompleteFilesExtension(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), this, SLOT(addTorrentsFromScanFolder(QStringList&))); |
|
|
|
connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), this, SLOT(addTorrentsFromScanFolder(QStringList&))); |
|
|
@ -154,7 +155,7 @@ session_proxy Bittorrent::asyncDeletion() { |
|
|
|
qDebug("Bittorrent session async deletion IN"); |
|
|
|
qDebug("Bittorrent session async deletion IN"); |
|
|
|
exiting = true; |
|
|
|
exiting = true; |
|
|
|
// Do some BT related saving
|
|
|
|
// Do some BT related saving
|
|
|
|
#ifndef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
saveDHTEntry(); |
|
|
|
saveDHTEntry(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
saveSessionState(); |
|
|
|
saveSessionState(); |
|
|
@ -171,7 +172,7 @@ Bittorrent::~Bittorrent() { |
|
|
|
qDebug("BTSession destructor IN"); |
|
|
|
qDebug("BTSession destructor IN"); |
|
|
|
if(!exiting) { |
|
|
|
if(!exiting) { |
|
|
|
// Do some BT related saving
|
|
|
|
// Do some BT related saving
|
|
|
|
#ifndef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
saveDHTEntry(); |
|
|
|
saveDHTEntry(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
saveSessionState(); |
|
|
|
saveSessionState(); |
|
|
@ -281,7 +282,7 @@ void Bittorrent::configureSession() { |
|
|
|
setDefaultTempPath(QString::null); |
|
|
|
setDefaultTempPath(QString::null); |
|
|
|
} |
|
|
|
} |
|
|
|
setAppendLabelToSavePath(Preferences::appendTorrentLabel()); |
|
|
|
setAppendLabelToSavePath(Preferences::appendTorrentLabel()); |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
setAppendqBExtension(Preferences::useIncompleteFilesExtension()); |
|
|
|
setAppendqBExtension(Preferences::useIncompleteFilesExtension()); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
preAllocateAllFiles(Preferences::preAllocateAllFiles()); |
|
|
|
preAllocateAllFiles(Preferences::preAllocateAllFiles()); |
|
|
@ -423,7 +424,7 @@ void Bittorrent::configureSession() { |
|
|
|
sessionSettings.stop_tracker_timeout = 1; |
|
|
|
sessionSettings.stop_tracker_timeout = 1; |
|
|
|
//sessionSettings.announce_to_all_trackers = true;
|
|
|
|
//sessionSettings.announce_to_all_trackers = true;
|
|
|
|
sessionSettings.auto_scrape_interval = 1200; // 20 minutes
|
|
|
|
sessionSettings.auto_scrape_interval = 1200; // 20 minutes
|
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
sessionSettings.announce_to_all_trackers = true; |
|
|
|
sessionSettings.announce_to_all_trackers = true; |
|
|
|
sessionSettings.announce_to_all_tiers = true; //uTorrent behavior
|
|
|
|
sessionSettings.announce_to_all_tiers = true; //uTorrent behavior
|
|
|
|
sessionSettings.auto_scrape_min_interval = 900; // 15 minutes
|
|
|
|
sessionSettings.auto_scrape_min_interval = 900; // 15 minutes
|
|
|
@ -858,7 +859,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { |
|
|
|
qDebug("addMagnetURI: using save_path: %s", qPrintable(savePath)); |
|
|
|
qDebug("addMagnetURI: using save_path: %s", qPrintable(savePath)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
|
|
|
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
|
|
|
if(TorrentTempData::isSeedingMode(hash)){ |
|
|
|
if(TorrentTempData::isSeedingMode(hash)){ |
|
|
|
p.seed_mode=true; |
|
|
|
p.seed_mode=true; |
|
|
@ -1082,7 +1083,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr |
|
|
|
qDebug("addTorrent: using save_path: %s", qPrintable(savePath)); |
|
|
|
qDebug("addTorrent: using save_path: %s", qPrintable(savePath)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
|
|
|
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
|
|
|
if(TorrentTempData::isSeedingMode(hash)){ |
|
|
|
if(TorrentTempData::isSeedingMode(hash)){ |
|
|
|
p.seed_mode=true; |
|
|
|
p.seed_mode=true; |
|
|
@ -1173,7 +1174,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr |
|
|
|
qDebug("addTorrent: Saving save_path in persistent data: %s", qPrintable(savePath)); |
|
|
|
qDebug("addTorrent: Saving save_path in persistent data: %s", qPrintable(savePath)); |
|
|
|
TorrentPersistentData::saveSavePath(hash, savePath); |
|
|
|
TorrentPersistentData::saveSavePath(hash, savePath); |
|
|
|
} |
|
|
|
} |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
// Append .!qB to incomplete files
|
|
|
|
// Append .!qB to incomplete files
|
|
|
|
if(appendqBExtension) |
|
|
|
if(appendqBExtension) |
|
|
|
appendqBextensionToTorrent(h, true); |
|
|
|
appendqBextensionToTorrent(h, true); |
|
|
@ -1357,7 +1358,7 @@ void Bittorrent::enableLSD(bool b) { |
|
|
|
void Bittorrent::loadSessionState() { |
|
|
|
void Bittorrent::loadSessionState() { |
|
|
|
const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state"); |
|
|
|
const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state"); |
|
|
|
if(!QFile::exists(state_path)) return; |
|
|
|
if(!QFile::exists(state_path)) return; |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
std::vector<char> in; |
|
|
|
std::vector<char> in; |
|
|
|
if (load_file(state_path.toLocal8Bit().constData(), in) == 0) |
|
|
|
if (load_file(state_path.toLocal8Bit().constData(), in) == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1378,7 +1379,7 @@ void Bittorrent::loadSessionState() { |
|
|
|
void Bittorrent::saveSessionState() { |
|
|
|
void Bittorrent::saveSessionState() { |
|
|
|
qDebug("Saving session state to disk..."); |
|
|
|
qDebug("Saving session state to disk..."); |
|
|
|
const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state"); |
|
|
|
const QString state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state"); |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
entry session_state; |
|
|
|
entry session_state; |
|
|
|
s->save_state(session_state); |
|
|
|
s->save_state(session_state); |
|
|
|
std::vector<char> out; |
|
|
|
std::vector<char> out; |
|
|
@ -1404,7 +1405,7 @@ void Bittorrent::saveSessionState() { |
|
|
|
bool Bittorrent::enableDHT(bool b) { |
|
|
|
bool Bittorrent::enableDHT(bool b) { |
|
|
|
if(b) { |
|
|
|
if(b) { |
|
|
|
if(!DHTEnabled) { |
|
|
|
if(!DHTEnabled) { |
|
|
|
#ifndef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
entry dht_state; |
|
|
|
entry dht_state; |
|
|
|
const QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); |
|
|
|
const QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); |
|
|
|
if(QFile::exists(dht_state_path)) { |
|
|
|
if(QFile::exists(dht_state_path)) { |
|
|
@ -1416,7 +1417,7 @@ bool Bittorrent::enableDHT(bool b) { |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
try { |
|
|
|
try { |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
s->start_dht(); |
|
|
|
s->start_dht(); |
|
|
|
#else |
|
|
|
#else |
|
|
|
s->start_dht(dht_state); |
|
|
|
s->start_dht(dht_state); |
|
|
@ -1632,7 +1633,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
defaultTempPath = temppath; |
|
|
|
defaultTempPath = temppath; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
void Bittorrent::appendqBextensionToTorrent(QTorrentHandle h, bool append) { |
|
|
|
void Bittorrent::appendqBextensionToTorrent(QTorrentHandle h, bool append) { |
|
|
|
if(!h.is_valid() || !h.has_metadata()) return; |
|
|
|
if(!h.is_valid() || !h.has_metadata()) return; |
|
|
|
std::vector<size_type> fp; |
|
|
|
std::vector<size_type> fp; |
|
|
@ -1704,7 +1705,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
void Bittorrent::setAppendqBExtension(bool append) { |
|
|
|
void Bittorrent::setAppendqBExtension(bool append) { |
|
|
|
if(appendqBExtension != append) { |
|
|
|
if(appendqBExtension != append) { |
|
|
|
appendqBExtension = !appendqBExtension; |
|
|
|
appendqBExtension = !appendqBExtension; |
|
|
@ -1932,7 +1933,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
if(h.is_valid()) { |
|
|
|
if(h.is_valid()) { |
|
|
|
emit finishedTorrent(h); |
|
|
|
emit finishedTorrent(h); |
|
|
|
const QString &hash = h.hash(); |
|
|
|
const QString &hash = h.hash(); |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
// Remove .!qB extension if necessary
|
|
|
|
// Remove .!qB extension if necessary
|
|
|
|
if(appendqBExtension) |
|
|
|
if(appendqBExtension) |
|
|
|
appendqBextensionToTorrent(h, false); |
|
|
|
appendqBextensionToTorrent(h, false); |
|
|
@ -2059,7 +2060,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
// Append .!qB to incomplete files
|
|
|
|
// Append .!qB to incomplete files
|
|
|
|
if(appendqBExtension) |
|
|
|
if(appendqBExtension) |
|
|
|
appendqBextensionToTorrent(h, true); |
|
|
|
appendqBextensionToTorrent(h, true); |
|
|
@ -2089,7 +2090,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a.get())) { |
|
|
|
else if (file_completed_alert* p = dynamic_cast<file_completed_alert*>(a.get())) { |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
if(appendqBExtension) { |
|
|
|
if(appendqBExtension) { |
|
|
@ -2119,7 +2120,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>()); |
|
|
|
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>()); |
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); |
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); |
|
|
|
data.last_message = misc::toQString(p->msg); |
|
|
|
data.last_message = misc::toQString(p->msg); |
|
|
|
#ifndef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
data.verified = false; |
|
|
|
data.verified = false; |
|
|
|
++data.fail_count; |
|
|
|
++data.fail_count; |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -2140,7 +2141,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); |
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); |
|
|
|
data.last_message = ""; // Reset error/warning message
|
|
|
|
data.last_message = ""; // Reset error/warning message
|
|
|
|
data.num_peers = p->num_peers; |
|
|
|
data.num_peers = p->num_peers; |
|
|
|
#ifndef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
data.fail_count = 0; |
|
|
|
data.fail_count = 0; |
|
|
|
data.verified = true; |
|
|
|
data.verified = true; |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -2155,7 +2156,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
const QString &tracker_url = misc::toQString(p->url); |
|
|
|
const QString &tracker_url = misc::toQString(p->url); |
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); |
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); |
|
|
|
data.last_message = misc::toQString(p->msg); // Store warning message
|
|
|
|
data.last_message = misc::toQString(p->msg); // Store warning message
|
|
|
|
#ifndef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
data.verified = true; |
|
|
|
data.verified = true; |
|
|
|
data.fail_count = 0; |
|
|
|
data.fail_count = 0; |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -2388,7 +2389,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
return sessionStatus.payload_upload_rate; |
|
|
|
return sessionStatus.payload_upload_rate; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifndef LIBTORRENT_0_15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
// Save DHT entry to hard drive
|
|
|
|
// Save DHT entry to hard drive
|
|
|
|
void Bittorrent::saveDHTEntry() { |
|
|
|
void Bittorrent::saveDHTEntry() { |
|
|
|
// Save DHT entry
|
|
|
|
// Save DHT entry
|
|
|
|