|
|
@ -43,7 +43,7 @@ |
|
|
|
#define MAX_TRACKER_ERRORS 2 |
|
|
|
#define MAX_TRACKER_ERRORS 2 |
|
|
|
|
|
|
|
|
|
|
|
// Main constructor
|
|
|
|
// Main constructor
|
|
|
|
bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), folderScanInterval(5), queueingEnabled(false) { |
|
|
|
bittorrent::bittorrent() : timerScan(0), DHTEnabled(false), preAllocateAll(false), addInPause(false), maxConnecsPerTorrent(500), maxUploadsPerTorrent(4), max_ratio(-1), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), folderScanInterval(5), queueingEnabled(false), calculateETA(true) { |
|
|
|
// To avoid some exceptions
|
|
|
|
// To avoid some exceptions
|
|
|
|
fs::path::default_name_check(fs::no_check); |
|
|
|
fs::path::default_name_check(fs::no_check); |
|
|
|
// Creating bittorrent session
|
|
|
|
// Creating bittorrent session
|
|
|
@ -154,6 +154,24 @@ void bittorrent::deleteBigRatios() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void bittorrent::setETACalculation(bool enable) { |
|
|
|
|
|
|
|
if(calculateETA != enable) { |
|
|
|
|
|
|
|
calculateETA = enable; |
|
|
|
|
|
|
|
if(calculateETA) { |
|
|
|
|
|
|
|
foreach(QString hash, unfinishedTorrents) { |
|
|
|
|
|
|
|
QTorrentHandle h = getTorrentHandle(hash); |
|
|
|
|
|
|
|
if(!h.is_paused()) { |
|
|
|
|
|
|
|
TorrentsStartData[hash] = h.total_payload_download(); |
|
|
|
|
|
|
|
TorrentsStartTime[hash] = QDateTime::currentDateTime(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
TorrentsStartData.clear(); |
|
|
|
|
|
|
|
TorrentsStartTime.clear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void bittorrent::setDownloadLimit(QString hash, long val) { |
|
|
|
void bittorrent::setDownloadLimit(QString hash, long val) { |
|
|
|
QTorrentHandle h = getTorrentHandle(hash); |
|
|
|
QTorrentHandle h = getTorrentHandle(hash); |
|
|
|
if(h.is_valid()) |
|
|
|
if(h.is_valid()) |
|
|
@ -505,6 +523,7 @@ void bittorrent::updateDownloadQueue() { |
|
|
|
// Calculate the ETA using GASA
|
|
|
|
// Calculate the ETA using GASA
|
|
|
|
// GASA: global Average Speed Algorithm
|
|
|
|
// GASA: global Average Speed Algorithm
|
|
|
|
qlonglong bittorrent::getETA(QString hash) const { |
|
|
|
qlonglong bittorrent::getETA(QString hash) const { |
|
|
|
|
|
|
|
Q_ASSERT(calculateETA); |
|
|
|
QTorrentHandle h = getTorrentHandle(hash); |
|
|
|
QTorrentHandle h = getTorrentHandle(hash); |
|
|
|
if(!h.is_valid()) return -1; |
|
|
|
if(!h.is_valid()) return -1; |
|
|
|
switch(h.state()) { |
|
|
|
switch(h.state()) { |
|
|
@ -597,8 +616,10 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) { |
|
|
|
torrentBackup.remove(file); |
|
|
|
torrentBackup.remove(file); |
|
|
|
} |
|
|
|
} |
|
|
|
// Remove it from TorrentsStartTime hash table
|
|
|
|
// Remove it from TorrentsStartTime hash table
|
|
|
|
|
|
|
|
if(calculateETA) { |
|
|
|
TorrentsStartTime.remove(hash); |
|
|
|
TorrentsStartTime.remove(hash); |
|
|
|
TorrentsStartData.remove(hash); |
|
|
|
TorrentsStartData.remove(hash); |
|
|
|
|
|
|
|
} |
|
|
|
// Remove tracker errors
|
|
|
|
// Remove tracker errors
|
|
|
|
trackersErrors.remove(hash); |
|
|
|
trackersErrors.remove(hash); |
|
|
|
// Remove it from ratio table
|
|
|
|
// Remove it from ratio table
|
|
|
@ -665,9 +686,11 @@ void bittorrent::setUnfinishedTorrent(QString hash) { |
|
|
|
if(!unfinishedTorrents.contains(hash)) { |
|
|
|
if(!unfinishedTorrents.contains(hash)) { |
|
|
|
unfinishedTorrents << hash; |
|
|
|
unfinishedTorrents << hash; |
|
|
|
QTorrentHandle h = getTorrentHandle(hash); |
|
|
|
QTorrentHandle h = getTorrentHandle(hash); |
|
|
|
|
|
|
|
if(calculateETA) { |
|
|
|
TorrentsStartData[hash] = h.total_payload_download(); |
|
|
|
TorrentsStartData[hash] = h.total_payload_download(); |
|
|
|
TorrentsStartTime[hash] = QDateTime::currentDateTime(); |
|
|
|
TorrentsStartTime[hash] = QDateTime::currentDateTime(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if(queueingEnabled) { |
|
|
|
if(queueingEnabled) { |
|
|
|
// Remove it from uploadQueue
|
|
|
|
// Remove it from uploadQueue
|
|
|
|
if(uploadQueue->contains(hash)) { |
|
|
|
if(uploadQueue->contains(hash)) { |
|
|
@ -703,8 +726,10 @@ void bittorrent::setFinishedTorrent(QString hash) { |
|
|
|
unfinishedTorrents.removeAt(index); |
|
|
|
unfinishedTorrents.removeAt(index); |
|
|
|
} |
|
|
|
} |
|
|
|
// Remove it from TorrentsStartTime hash table
|
|
|
|
// Remove it from TorrentsStartTime hash table
|
|
|
|
|
|
|
|
if(calculateETA) { |
|
|
|
TorrentsStartTime.remove(hash); |
|
|
|
TorrentsStartTime.remove(hash); |
|
|
|
TorrentsStartData.remove(hash); |
|
|
|
TorrentsStartData.remove(hash); |
|
|
|
|
|
|
|
} |
|
|
|
// Remove it from
|
|
|
|
// Remove it from
|
|
|
|
if(queueingEnabled) { |
|
|
|
if(queueingEnabled) { |
|
|
|
downloadQueue->removeAll(hash); |
|
|
|
downloadQueue->removeAll(hash); |
|
|
@ -761,8 +786,10 @@ bool bittorrent::pauseTorrent(QString hash) { |
|
|
|
paused_file.close(); |
|
|
|
paused_file.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
// Remove it from TorrentsStartTime hash table
|
|
|
|
// Remove it from TorrentsStartTime hash table
|
|
|
|
|
|
|
|
if(calculateETA) { |
|
|
|
TorrentsStartTime.remove(hash); |
|
|
|
TorrentsStartTime.remove(hash); |
|
|
|
TorrentsStartData.remove(hash); |
|
|
|
TorrentsStartData.remove(hash); |
|
|
|
|
|
|
|
} |
|
|
|
return change; |
|
|
|
return change; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -773,8 +800,10 @@ bool bittorrent::resumeTorrent(QString hash) { |
|
|
|
if(h.is_valid() && h.is_paused()) { |
|
|
|
if(h.is_valid() && h.is_paused()) { |
|
|
|
if(!(queueingEnabled && (isDownloadQueued(hash)||isUploadQueued(hash)))) { |
|
|
|
if(!(queueingEnabled && (isDownloadQueued(hash)||isUploadQueued(hash)))) { |
|
|
|
// Save Addition DateTime
|
|
|
|
// Save Addition DateTime
|
|
|
|
|
|
|
|
if(calculateETA) { |
|
|
|
TorrentsStartData[hash] = h.total_payload_download(); |
|
|
|
TorrentsStartData[hash] = h.total_payload_download(); |
|
|
|
TorrentsStartTime[hash] = QDateTime::currentDateTime(); |
|
|
|
TorrentsStartTime[hash] = QDateTime::currentDateTime(); |
|
|
|
|
|
|
|
} |
|
|
|
h.resume(); |
|
|
|
h.resume(); |
|
|
|
success = true; |
|
|
|
success = true; |
|
|
|
emit resumedTorrent(hash); |
|
|
|
emit resumedTorrent(hash); |
|
|
@ -1702,9 +1731,11 @@ void bittorrent::readAlerts() { |
|
|
|
qDebug("%s was paused after checking", hash.toUtf8().data()); |
|
|
|
qDebug("%s was paused after checking", hash.toUtf8().data()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Save Addition DateTime
|
|
|
|
// Save Addition DateTime
|
|
|
|
|
|
|
|
if(calculateETA) { |
|
|
|
TorrentsStartTime[hash] = QDateTime::currentDateTime(); |
|
|
|
TorrentsStartTime[hash] = QDateTime::currentDateTime(); |
|
|
|
TorrentsStartData[hash] = h.total_payload_download(); |
|
|
|
TorrentsStartData[hash] = h.total_payload_download(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
emit torrentFinishedChecking(hash); |
|
|
|
emit torrentFinishedChecking(hash); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|