Browse Source

- Do not save fastresume data regularly for seeding torrents

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
7982011d0b
  1. 40
      src/bittorrent.cpp
  2. 2
      src/bittorrent.h

40
src/bittorrent.cpp

@ -59,7 +59,7 @@ bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false
connect(ETARefresher, SIGNAL(timeout()), this, SLOT(updateETAs())); connect(ETARefresher, SIGNAL(timeout()), this, SLOT(updateETAs()));
ETARefresher->start(ETA_REFRESH_INTERVAL); ETARefresher->start(ETA_REFRESH_INTERVAL);
fastResumeSaver = new QTimer(); fastResumeSaver = new QTimer();
connect(fastResumeSaver, SIGNAL(timeout()), this, SLOT(saveFastResumeAndRatioData())); connect(fastResumeSaver, SIGNAL(timeout()), this, SLOT(saveFastResumeAndRatioDataUnfinished()));
fastResumeSaver->start(60000); fastResumeSaver->start(60000);
// To download from urls // To download from urls
downloader = new downloadThread(this); downloader = new downloadThread(this);
@ -310,6 +310,8 @@ void bittorrent::setFinishedTorrent(QString hash) {
// Remove it from ETAs hash tables // Remove it from ETAs hash tables
ETAstats.remove(hash); ETAstats.remove(hash);
ETAs.remove(hash); ETAs.remove(hash);
// Save fast resume data
saveFastResumeAndRatioData(hash);
} }
// Pause a running torrent // Pause a running torrent
@ -831,16 +833,18 @@ void bittorrent::saveDownloadUploadForTorrent(QString hash) {
ratio_file.close(); ratio_file.close();
} }
// Only save fast resume data for unfinished torrents (Optimization)
void bittorrent::saveFastResumeAndRatioDataUnfinished() {
QString hash;
QStringList hashes = getUnfinishedTorrents();
foreach(hash, hashes) {
saveFastResumeAndRatioData(hash);
}
}
// Save fastresume data for all torrents (called periodically) // Save fastresume data for all torrents (called periodically)
void bittorrent::saveFastResumeAndRatioData() { void bittorrent::saveFastResumeAndRatioData() {
qDebug("Saving fast resume and ratio data"); qDebug("Saving fast resume and ratio data");
QString file;
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
// Checking if torrentBackup Dir exists
// create it if it is not
if(! torrentBackup.exists()) {
torrentBackup.mkpath(torrentBackup.path());
}
std::vector<torrent_handle> handles = s->get_torrents(); std::vector<torrent_handle> handles = s->get_torrents();
// It is not necessary to pause the torrents before saving fastresume data anymore // It is not necessary to pause the torrents before saving fastresume data anymore
// because we either use Full allocation or sparse mode. // because we either use Full allocation or sparse mode.
@ -852,7 +856,25 @@ void bittorrent::saveFastResumeAndRatioData() {
continue; continue;
} }
QString hash = h.hash(); QString hash = h.hash();
saveFastResumeAndRatioData(hash);
}
qDebug("Fast resume and ratio data saved");
}
void bittorrent::saveFastResumeAndRatioData(QString hash) {
QString file;
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
// Checking if torrentBackup Dir exists
// create it if it is not
if(! torrentBackup.exists()) {
torrentBackup.mkpath(torrentBackup.path());
}
// Extracting resume data // Extracting resume data
QTorrentHandle h = getTorrentHandle(hash);
if(!h.is_valid()) {
qDebug("/!\\ Error: Invalid handle");
return;
}
if (h.has_metadata() && h.state() != torrent_status::checking_files && h.state() != torrent_status::queued_for_checking) { if (h.has_metadata() && h.state() != torrent_status::checking_files && h.state() != torrent_status::queued_for_checking) {
if(QFile::exists(torrentBackup.path()+QDir::separator()+hash+".torrent")) { if(QFile::exists(torrentBackup.path()+QDir::separator()+hash+".torrent")) {
// Remove old .fastresume data in case it exists // Remove old .fastresume data in case it exists
@ -867,8 +889,6 @@ void bittorrent::saveFastResumeAndRatioData() {
// Save ratio data // Save ratio data
saveDownloadUploadForTorrent(hash); saveDownloadUploadForTorrent(hash);
} }
}
qDebug("Fast resume and ratio data saved");
} }
bool bittorrent::isFilePreviewPossible(QString hash) const{ bool bittorrent::isFilePreviewPossible(QString hash) const{

2
src/bittorrent.h

@ -98,6 +98,8 @@ class bittorrent : public QObject{
void saveDHTEntry(); void saveDHTEntry();
void preAllocateAllFiles(bool b); void preAllocateAllFiles(bool b);
void saveFastResumeAndRatioData(); void saveFastResumeAndRatioData();
void saveFastResumeAndRatioData(QString hash);
void saveFastResumeAndRatioDataUnfinished();
void enableDirectoryScanning(QString scan_dir); void enableDirectoryScanning(QString scan_dir);
void disableDirectoryScanning(); void disableDirectoryScanning();
void enablePeerExchange(); void enablePeerExchange();

Loading…
Cancel
Save