|
|
@ -57,9 +57,7 @@ |
|
|
|
#include <libtorrent/version.hpp> |
|
|
|
#include <libtorrent/version.hpp> |
|
|
|
#include <libtorrent/extensions/ut_metadata.hpp> |
|
|
|
#include <libtorrent/extensions/ut_metadata.hpp> |
|
|
|
#include <libtorrent/version.hpp> |
|
|
|
#include <libtorrent/version.hpp> |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
#include <libtorrent/extensions/lt_trackers.hpp> |
|
|
|
#include <libtorrent/extensions/lt_trackers.hpp> |
|
|
|
#endif |
|
|
|
|
|
|
|
#include <libtorrent/extensions/ut_pex.hpp> |
|
|
|
#include <libtorrent/extensions/ut_pex.hpp> |
|
|
|
#include <libtorrent/extensions/smart_ban.hpp> |
|
|
|
#include <libtorrent/extensions/smart_ban.hpp> |
|
|
|
//#include <libtorrent/extensions/metadata_transfer.hpp>
|
|
|
|
//#include <libtorrent/extensions/metadata_transfer.hpp>
|
|
|
@ -139,10 +137,8 @@ QBtSession::QBtSession() |
|
|
|
// 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); |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
if(pref.trackerExchangeEnabled()) |
|
|
|
if(pref.trackerExchangeEnabled()) |
|
|
|
s->add_extension(&create_lt_trackers_plugin); |
|
|
|
s->add_extension(&create_lt_trackers_plugin); |
|
|
|
#endif |
|
|
|
|
|
|
|
if(pref.isPeXEnabled()) { |
|
|
|
if(pref.isPeXEnabled()) { |
|
|
|
PeXEnabled = true; |
|
|
|
PeXEnabled = true; |
|
|
|
s->add_extension(&create_ut_pex_plugin); |
|
|
|
s->add_extension(&create_ut_pex_plugin); |
|
|
@ -154,9 +150,7 @@ QBtSession::QBtSession() |
|
|
|
connect(timerAlerts, SIGNAL(timeout()), SLOT(readAlerts())); |
|
|
|
connect(timerAlerts, SIGNAL(timeout()), SLOT(readAlerts())); |
|
|
|
timerAlerts->start(1000); |
|
|
|
timerAlerts->start(1000); |
|
|
|
appendLabelToSavePath = pref.appendTorrentLabel(); |
|
|
|
appendLabelToSavePath = pref.appendTorrentLabel(); |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
appendqBExtension = pref.useIncompleteFilesExtension(); |
|
|
|
appendqBExtension = pref.useIncompleteFilesExtension(); |
|
|
|
#endif |
|
|
|
|
|
|
|
connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), SLOT(addTorrentsFromScanFolder(QStringList&))); |
|
|
|
connect(m_scanFolders, SIGNAL(torrentsAdded(QStringList&)), SLOT(addTorrentsFromScanFolder(QStringList&))); |
|
|
|
// Apply user settings to Bittorrent session
|
|
|
|
// Apply user settings to Bittorrent session
|
|
|
|
configureSession(); |
|
|
|
configureSession(); |
|
|
@ -179,9 +173,6 @@ QBtSession::~QBtSession() { |
|
|
|
delete m_speedMonitor; |
|
|
|
delete m_speedMonitor; |
|
|
|
qDebug("Deleted the torrent speed monitor"); |
|
|
|
qDebug("Deleted the torrent speed monitor"); |
|
|
|
// Do some BT related saving
|
|
|
|
// Do some BT related saving
|
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
|
|
|
|
saveDHTEntry(); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
saveSessionState(); |
|
|
|
saveSessionState(); |
|
|
|
saveFastResumeData(); |
|
|
|
saveFastResumeData(); |
|
|
|
// Delete our objects
|
|
|
|
// Delete our objects
|
|
|
@ -309,9 +300,7 @@ void QBtSession::configureSession() { |
|
|
|
setDefaultTempPath(QString::null); |
|
|
|
setDefaultTempPath(QString::null); |
|
|
|
} |
|
|
|
} |
|
|
|
setAppendLabelToSavePath(pref.appendTorrentLabel()); |
|
|
|
setAppendLabelToSavePath(pref.appendTorrentLabel()); |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
setAppendqBExtension(pref.useIncompleteFilesExtension()); |
|
|
|
setAppendqBExtension(pref.useIncompleteFilesExtension()); |
|
|
|
#endif |
|
|
|
|
|
|
|
preAllocateAllFiles(pref.preAllocateAllFiles()); |
|
|
|
preAllocateAllFiles(pref.preAllocateAllFiles()); |
|
|
|
startTorrentsInPause(pref.addTorrentsInPause()); |
|
|
|
startTorrentsInPause(pref.addTorrentsInPause()); |
|
|
|
// * Export Dir
|
|
|
|
// * Export Dir
|
|
|
@ -404,22 +393,18 @@ void QBtSession::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
|
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
bool announce_to_all = pref.announceToAllTrackers(); |
|
|
|
bool announce_to_all = pref.announceToAllTrackers(); |
|
|
|
sessionSettings.announce_to_all_trackers = announce_to_all; |
|
|
|
sessionSettings.announce_to_all_trackers = announce_to_all; |
|
|
|
sessionSettings.announce_to_all_tiers = announce_to_all; |
|
|
|
sessionSettings.announce_to_all_tiers = announce_to_all; |
|
|
|
sessionSettings.auto_scrape_min_interval = 900; // 15 minutes
|
|
|
|
sessionSettings.auto_scrape_min_interval = 900; // 15 minutes
|
|
|
|
#endif |
|
|
|
|
|
|
|
sessionSettings.cache_size = pref.diskCacheSize()*64; |
|
|
|
sessionSettings.cache_size = pref.diskCacheSize()*64; |
|
|
|
qDebug() << "Using a disk cache size of" << pref.diskCacheSize() << "MiB"; |
|
|
|
qDebug() << "Using a disk cache size of" << pref.diskCacheSize() << "MiB"; |
|
|
|
// Disable OS cache to avoid memory problems (uTorrent behavior)
|
|
|
|
// Disable OS cache to avoid memory problems (uTorrent behavior)
|
|
|
|
#ifdef Q_WS_WIN |
|
|
|
#ifdef Q_WS_WIN |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
// Fixes huge memory usage on Windows 7 (especially when checking files)
|
|
|
|
// Fixes huge memory usage on Windows 7 (especially when checking files)
|
|
|
|
sessionSettings.disk_io_write_mode = session_settings::disable_os_cache; |
|
|
|
sessionSettings.disk_io_write_mode = session_settings::disable_os_cache; |
|
|
|
sessionSettings.disk_io_read_mode = session_settings::disable_os_cache; |
|
|
|
sessionSettings.disk_io_read_mode = session_settings::disable_os_cache; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
#if LIBTORRENT_VERSION_MINOR > 15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 15 |
|
|
|
sessionSettings.anonymous_mode = pref.isAnonymousModeEnabled(); |
|
|
|
sessionSettings.anonymous_mode = pref.isAnonymousModeEnabled(); |
|
|
|
if (sessionSettings.anonymous_mode) { |
|
|
|
if (sessionSettings.anonymous_mode) { |
|
|
@ -461,9 +446,7 @@ void QBtSession::configureSession() { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
// Super seeding
|
|
|
|
// Super seeding
|
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
sessionSettings.strict_super_seeding = pref.isSuperSeedingEnabled(); |
|
|
|
sessionSettings.strict_super_seeding = pref.isSuperSeedingEnabled(); |
|
|
|
#endif |
|
|
|
|
|
|
|
#if LIBTORRENT_VERSION_MINOR > 15 |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 15 |
|
|
|
// * Max Half-open connections
|
|
|
|
// * Max Half-open connections
|
|
|
|
sessionSettings.half_open_limit = pref.getMaxHalfOpenConnections(); |
|
|
|
sessionSettings.half_open_limit = pref.getMaxHalfOpenConnections(); |
|
|
@ -1163,11 +1146,10 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr |
|
|
|
qDebug("This is a NEW torrent (first time)..."); |
|
|
|
qDebug("This is a NEW torrent (first time)..."); |
|
|
|
loadTorrentTempData(h, savePath, false); |
|
|
|
loadTorrentTempData(h, savePath, false); |
|
|
|
|
|
|
|
|
|
|
|
#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); |
|
|
|
#endif |
|
|
|
|
|
|
|
// Backup torrent file
|
|
|
|
// Backup torrent file
|
|
|
|
const QString newFile = torrentBackup.absoluteFilePath(hash + ".torrent"); |
|
|
|
const QString newFile = torrentBackup.absoluteFilePath(hash + ".torrent"); |
|
|
|
if(path != newFile) |
|
|
|
if(path != newFile) |
|
|
@ -1232,15 +1214,11 @@ add_torrent_params QBtSession::initializeAddTorrentParams(const QString &hash) { |
|
|
|
add_torrent_params p; |
|
|
|
add_torrent_params p; |
|
|
|
|
|
|
|
|
|
|
|
// Seeding mode
|
|
|
|
// Seeding mode
|
|
|
|
#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; |
|
|
|
else |
|
|
|
else |
|
|
|
p.seed_mode=false; |
|
|
|
p.seed_mode=false; |
|
|
|
#else |
|
|
|
|
|
|
|
Q_UNUSED(hash); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Preallocation mode
|
|
|
|
// Preallocation mode
|
|
|
|
if(preAllocateAll) |
|
|
|
if(preAllocateAll) |
|
|
@ -1503,7 +1481,6 @@ void QBtSession::loadSessionState() { |
|
|
|
QFile::remove(state_path); |
|
|
|
QFile::remove(state_path); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
QFile state_file(state_path); |
|
|
|
QFile state_file(state_path); |
|
|
|
if(!state_file.open(QIODevice::ReadOnly)) return; |
|
|
|
if(!state_file.open(QIODevice::ReadOnly)) return; |
|
|
|
std::vector<char> in; |
|
|
|
std::vector<char> in; |
|
|
@ -1522,20 +1499,11 @@ void QBtSession::loadSessionState() { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
s->load_state(e); |
|
|
|
s->load_state(e); |
|
|
|
} |
|
|
|
} |
|
|
|
#else |
|
|
|
|
|
|
|
boost::filesystem::ifstream ses_state_file(state_path.toLocal8Bit().constData() |
|
|
|
|
|
|
|
, std::ios_base::binary); |
|
|
|
|
|
|
|
ses_state_file.unsetf(std::ios_base::skipws); |
|
|
|
|
|
|
|
s->load_state(bdecode( |
|
|
|
|
|
|
|
std::istream_iterator<char>(ses_state_file) |
|
|
|
|
|
|
|
, std::istream_iterator<char>())); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void QBtSession::saveSessionState() { |
|
|
|
void QBtSession::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"); |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
entry session_state; |
|
|
|
entry session_state; |
|
|
|
s->save_state(session_state); |
|
|
|
s->save_state(session_state); |
|
|
|
vector<char> out; |
|
|
|
vector<char> out; |
|
|
@ -1545,38 +1513,16 @@ void QBtSession::saveSessionState() { |
|
|
|
session_file.write(&out[0], out.size()); |
|
|
|
session_file.write(&out[0], out.size()); |
|
|
|
session_file.close(); |
|
|
|
session_file.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
#else |
|
|
|
|
|
|
|
entry session_state = s->state(); |
|
|
|
|
|
|
|
boost::filesystem::ofstream out(state_path.toLocal8Bit().constData() |
|
|
|
|
|
|
|
, std::ios_base::binary); |
|
|
|
|
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
|
|
|
|
bencode(std::ostream_iterator<char>(out), session_state); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Enable DHT
|
|
|
|
// Enable DHT
|
|
|
|
bool QBtSession::enableDHT(bool b) { |
|
|
|
bool QBtSession::enableDHT(bool b) { |
|
|
|
if(b) { |
|
|
|
if(b) { |
|
|
|
if(!DHTEnabled) { |
|
|
|
if(!DHTEnabled) { |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
|
|
|
|
entry dht_state; |
|
|
|
|
|
|
|
const QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); |
|
|
|
|
|
|
|
if(QFile::exists(dht_state_path)) { |
|
|
|
|
|
|
|
boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().constData(), std::ios_base::binary); |
|
|
|
|
|
|
|
dht_state_file.unsetf(std::ios_base::skipws); |
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
dht_state = bdecode(std::istream_iterator<char>(dht_state_file), std::istream_iterator<char>()); |
|
|
|
|
|
|
|
}catch (std::exception&) {} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
qDebug() << "Starting DHT..."; |
|
|
|
qDebug() << "Starting DHT..."; |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
Q_ASSERT(!s->is_dht_running()); |
|
|
|
Q_ASSERT(!s->is_dht_running()); |
|
|
|
s->start_dht(); |
|
|
|
s->start_dht(); |
|
|
|
#else |
|
|
|
|
|
|
|
s->start_dht(dht_state); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
s->add_dht_router(std::make_pair(std::string("router.bittorrent.com"), 6881)); |
|
|
|
s->add_dht_router(std::make_pair(std::string("router.bittorrent.com"), 6881)); |
|
|
|
s->add_dht_router(std::make_pair(std::string("router.utorrent.com"), 6881)); |
|
|
|
s->add_dht_router(std::make_pair(std::string("router.utorrent.com"), 6881)); |
|
|
|
s->add_dht_router(std::make_pair(std::string("dht.transmissionbt.com"), 6881)); |
|
|
|
s->add_dht_router(std::make_pair(std::string("dht.transmissionbt.com"), 6881)); |
|
|
@ -1807,7 +1753,6 @@ void QBtSession::setDefaultTempPath(QString temppath) { |
|
|
|
defaultTempPath = temppath; |
|
|
|
defaultTempPath = temppath; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append) { |
|
|
|
void QBtSession::appendqBextensionToTorrent(const 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; |
|
|
@ -1834,7 +1779,6 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QBtSession::changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label) { |
|
|
|
void QBtSession::changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label) { |
|
|
|
if(!h.is_valid()) return; |
|
|
|
if(!h.is_valid()) return; |
|
|
@ -1879,7 +1823,6 @@ void QBtSession::setAppendLabelToSavePath(bool append) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
void QBtSession::setAppendqBExtension(bool append) { |
|
|
|
void QBtSession::setAppendqBExtension(bool append) { |
|
|
|
if(appendqBExtension != append) { |
|
|
|
if(appendqBExtension != append) { |
|
|
|
appendqBExtension = !appendqBExtension; |
|
|
|
appendqBExtension = !appendqBExtension; |
|
|
@ -1892,7 +1835,6 @@ void QBtSession::setAppendqBExtension(bool append) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the ports range in which is chosen the port the Bittorrent
|
|
|
|
// Set the ports range in which is chosen the port the Bittorrent
|
|
|
|
// session will listen to
|
|
|
|
// session will listen to
|
|
|
@ -2191,11 +2133,10 @@ void QBtSession::readAlerts() { |
|
|
|
if(h.is_valid()) { |
|
|
|
if(h.is_valid()) { |
|
|
|
const QString hash = h.hash(); |
|
|
|
const QString hash = h.hash(); |
|
|
|
qDebug("Got a torrent finished alert for %s", qPrintable(h.name())); |
|
|
|
qDebug("Got a torrent finished alert for %s", qPrintable(h.name())); |
|
|
|
#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); |
|
|
|
#endif |
|
|
|
|
|
|
|
const bool was_already_seeded = TorrentPersistentData::isSeed(hash); |
|
|
|
const bool was_already_seeded = TorrentPersistentData::isSeed(hash); |
|
|
|
qDebug("Was already seeded: %d", was_already_seeded); |
|
|
|
qDebug("Was already seeded: %d", was_already_seeded); |
|
|
|
if(!was_already_seeded) { |
|
|
|
if(!was_already_seeded) { |
|
|
@ -2341,18 +2282,7 @@ void QBtSession::readAlerts() { |
|
|
|
} |
|
|
|
} |
|
|
|
else if (torrent_deleted_alert* p = dynamic_cast<torrent_deleted_alert*>(a.get())) { |
|
|
|
else if (torrent_deleted_alert* p = dynamic_cast<torrent_deleted_alert*>(a.get())) { |
|
|
|
qDebug("A torrent was deleted from the hard disk, attempting to remove the root folder too..."); |
|
|
|
qDebug("A torrent was deleted from the hard disk, attempting to remove the root folder too..."); |
|
|
|
QString hash; |
|
|
|
QString hash = misc::toQString(p->info_hash); |
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14 |
|
|
|
|
|
|
|
hash = misc::toQString(p->info_hash); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
// Unfortunately libtorrent v0.14 does not provide the hash,
|
|
|
|
|
|
|
|
// only the torrent handle that is often invalid when it arrives
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if(p->handle.is_valid()) { |
|
|
|
|
|
|
|
hash = misc::toQString(p->handle.info_hash()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}catch(std::exception){} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
if(!hash.isEmpty()) { |
|
|
|
if(!hash.isEmpty()) { |
|
|
|
if(savePathsToRemove.contains(hash)) { |
|
|
|
if(savePathsToRemove.contains(hash)) { |
|
|
|
const QString dirpath = savePathsToRemove.take(hash); |
|
|
|
const QString dirpath = savePathsToRemove.take(hash); |
|
|
@ -2403,11 +2333,9 @@ void QBtSession::readAlerts() { |
|
|
|
// Copy the torrent file to the export folder
|
|
|
|
// Copy the torrent file to the export folder
|
|
|
|
if(torrentExport) |
|
|
|
if(torrentExport) |
|
|
|
exportTorrentFile(h); |
|
|
|
exportTorrentFile(h); |
|
|
|
#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); |
|
|
|
#endif |
|
|
|
|
|
|
|
// Truncate root folder
|
|
|
|
// Truncate root folder
|
|
|
|
const QString root_folder = misc::truncateRootFolder(p->handle); |
|
|
|
const QString root_folder = misc::truncateRootFolder(p->handle); |
|
|
|
TorrentPersistentData::setRootFolder(h.hash(), root_folder); |
|
|
|
TorrentPersistentData::setRootFolder(h.hash(), root_folder); |
|
|
@ -2451,7 +2379,6 @@ void QBtSession::readAlerts() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#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); |
|
|
|
qDebug("A file completed download in torrent %s", qPrintable(h.name())); |
|
|
|
qDebug("A file completed download in torrent %s", qPrintable(h.name())); |
|
|
@ -2466,7 +2393,6 @@ void QBtSession::readAlerts() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
else if (torrent_paused_alert* p = dynamic_cast<torrent_paused_alert*>(a.get())) { |
|
|
|
else if (torrent_paused_alert* p = dynamic_cast<torrent_paused_alert*>(a.get())) { |
|
|
|
if(p->handle.is_valid()) { |
|
|
|
if(p->handle.is_valid()) { |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
QTorrentHandle h(p->handle); |
|
|
@ -2486,10 +2412,6 @@ void QBtSession::readAlerts() { |
|
|
|
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); |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
|
|
|
|
data.verified = false; |
|
|
|
|
|
|
|
++data.fail_count; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
trackers_data.insert(tracker_url, data); |
|
|
|
trackers_data.insert(tracker_url, data); |
|
|
|
trackersInfos[h.hash()] = trackers_data; |
|
|
|
trackersInfos[h.hash()] = trackers_data; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -2507,10 +2429,6 @@ void QBtSession::readAlerts() { |
|
|
|
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; |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
|
|
|
|
data.fail_count = 0; |
|
|
|
|
|
|
|
data.verified = true; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
trackers_data.insert(tracker_url, data); |
|
|
|
trackers_data.insert(tracker_url, data); |
|
|
|
trackersInfos[h.hash()] = trackers_data; |
|
|
|
trackersInfos[h.hash()] = trackers_data; |
|
|
|
} |
|
|
|
} |
|
|
@ -2522,10 +2440,6 @@ void QBtSession::readAlerts() { |
|
|
|
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
|
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
|
|
|
|
data.verified = true; |
|
|
|
|
|
|
|
data.fail_count = 0; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
trackers_data.insert(tracker_url, data); |
|
|
|
trackers_data.insert(tracker_url, data); |
|
|
|
trackersInfos[h.hash()] = trackers_data; |
|
|
|
trackersInfos[h.hash()] = trackers_data; |
|
|
|
qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str()); |
|
|
|
qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str()); |
|
|
@ -2560,12 +2474,7 @@ void QBtSession::readAlerts() { |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
if(h.is_valid()) { |
|
|
|
if(h.is_valid()) { |
|
|
|
qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str()); |
|
|
|
qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str()); |
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
|
|
|
|
QString msg = QString::fromLocal8Bit(p->message().c_str()); |
|
|
|
|
|
|
|
if(msg.contains("filesize", Qt::CaseInsensitive) && msg.contains("mismatch", Qt::CaseInsensitive) && TorrentPersistentData::isSeed(h.hash()) && h.has_missing_files()) { |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if(p->error.value() == 134 && TorrentPersistentData::isSeed(h.hash()) && h.has_missing_files()) { |
|
|
|
if(p->error.value() == 134 && TorrentPersistentData::isSeed(h.hash()) && h.has_missing_files()) { |
|
|
|
#endif |
|
|
|
|
|
|
|
const QString hash = h.hash(); |
|
|
|
const QString hash = h.hash(); |
|
|
|
// Mismatching file size (files were probably moved
|
|
|
|
// Mismatching file size (files were probably moved
|
|
|
|
addConsoleMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name())); |
|
|
|
addConsoleMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name())); |
|
|
@ -2775,27 +2684,6 @@ qreal QBtSession::getPayloadUploadRate() const{ |
|
|
|
return s->status().payload_upload_rate; |
|
|
|
return s->status().payload_upload_rate; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if LIBTORRENT_VERSION_MINOR < 15 |
|
|
|
|
|
|
|
// Save DHT entry to hard drive
|
|
|
|
|
|
|
|
void QBtSession::saveDHTEntry() { |
|
|
|
|
|
|
|
// Save DHT entry
|
|
|
|
|
|
|
|
if(DHTEnabled) { |
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
entry dht_state = s->dht_state(); |
|
|
|
|
|
|
|
const QString dht_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); |
|
|
|
|
|
|
|
if(QFile::exists(dht_path)) |
|
|
|
|
|
|
|
misc::safeRemove(dht_path); |
|
|
|
|
|
|
|
boost::filesystem::ofstream out(dht_path.toLocal8Bit().constData(), std::ios_base::binary); |
|
|
|
|
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
|
|
|
|
bencode(std::ostream_iterator<char>(out), dht_state); |
|
|
|
|
|
|
|
qDebug("DHT entry saved"); |
|
|
|
|
|
|
|
}catch (std::exception& e) { |
|
|
|
|
|
|
|
std::cerr << e.what() << std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QBtSession::applyEncryptionSettings(pe_settings se) { |
|
|
|
void QBtSession::applyEncryptionSettings(pe_settings se) { |
|
|
|
qDebug("Applying encryption settings"); |
|
|
|
qDebug("Applying encryption settings"); |
|
|
|
s->set_pe_settings(se); |
|
|
|
s->set_pe_settings(se); |
|
|
|