fixed a bug in download queue when ticking inactive files. Added a checkbox for showing cache transfers. Cleaned the dialog cleaning method.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2583 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-03-21 15:35:20 +00:00
parent 20fd24d7b8
commit 3b1006bfa4
5 changed files with 51 additions and 72 deletions

View file

@ -57,6 +57,7 @@
* #define CONTROL_DEBUG 1 * #define CONTROL_DEBUG 1
* #define DEBUG_DWLQUEUE 1 * #define DEBUG_DWLQUEUE 1
*****/ *****/
#define DEBUG_DWLQUEUE 1
static const uint32_t SAVE_TRANSFERS_DELAY = 61 ; // save transfer progress every 61 seconds. static const uint32_t SAVE_TRANSFERS_DELAY = 61 ; // save transfer progress every 61 seconds.
static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released
@ -410,16 +411,23 @@ void ftController::checkDownloadQueue()
// Check for inactive transfers. // Check for inactive transfers.
// //
time_t now = time(NULL) ; time_t now = time(NULL) ;
uint32_t nb_moved = 0 ; // don't move more files than the size of the queue.
for(std::map<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end();++it) for(std::map<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end() && nb_moved <= _max_active_downloads;++it)
if( it->second->mState != ftFileControl::QUEUED if( it->second->mState != ftFileControl::QUEUED
&& it->second->mState != ftFileControl::PAUSED && it->second->mState != ftFileControl::PAUSED
&& now - it->second->mCreator->lastRecvTimeStamp() > (time_t)MAX_TIME_INACTIVE_REQUEUED) && now > it->second->mCreator->lastRecvTimeStamp() + (time_t)MAX_TIME_INACTIVE_REQUEUED)
{ {
#ifdef DEBUG_DWLQUEUE
std::cerr << " - Inactive file " << it->second->mName << " at position " << it->second->mQueuePosition << " moved to end of the queue. mState=" << it->second->mState << ", time lapse=" << now - it->second->mCreator->lastRecvTimeStamp() << std::endl ;
#endif
locked_bottomQueue(it->second->mQueuePosition) ; locked_bottomQueue(it->second->mQueuePosition) ;
#ifdef DEBUG_DWLQUEUE #ifdef DEBUG_DWLQUEUE
std::cerr << " - Inactive file " << it->second->mName << " moved to end of the queue" << std::endl ; std::cerr << " new position: " << it->second->mQueuePosition << std::endl ;
std::cerr << " new state: " << it->second->mState << std::endl ;
#endif #endif
it->second->mCreator->resetRecvTimeStamp() ; // very important!
++nb_moved ;
} }
} }
@ -541,11 +549,6 @@ void ftController::locked_swapQueue(uint32_t pos1,uint32_t pos2)
locked_checkQueueElement(pos2) ; locked_checkQueueElement(pos2) ;
} }
//void ftController::checkQueueElements()
//{
// for(uint32_t pos=0;pos<_queue.size();++pos)
// checkQueueElement(pos) ;
//}
void ftController::locked_checkQueueElement(uint32_t pos) void ftController::locked_checkQueueElement(uint32_t pos)
{ {
_queue[pos]->mQueuePosition = pos ; _queue[pos]->mQueuePosition = pos ;

View file

@ -58,6 +58,11 @@ time_t ftFileCreator::lastRecvTimeStamp()
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
return _last_recv_time_t ; return _last_recv_time_t ;
} }
void ftFileCreator::resetRecvTimeStamp()
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
_last_recv_time_t = time(NULL) ;
}
void ftFileCreator::closeFile() void ftFileCreator::closeFile()
{ {

View file

@ -76,8 +76,9 @@ class ftFileCreator: public ftFileProvider
// removes the designated file source from the chunkmap. // removes the designated file source from the chunkmap.
void removeFileSource(const std::string& peer_id) ; void removeFileSource(const std::string& peer_id) ;
// Returns the time stamp of the last data receive. // Returns resets the time stamp of the last data receive.
time_t lastRecvTimeStamp() ; time_t lastRecvTimeStamp() ;
void resetRecvTimeStamp() ;
// actually store data in the file, and update chunks info // actually store data in the file, and update chunks info
// //

View file

@ -201,6 +201,7 @@ TransfersDialog::TransfersDialog(QWidget *parent)
#endif #endif
QObject::connect(ui._showCacheTransfers_CB,SIGNAL(toggled(bool)),this,SLOT(insertTransfers())) ;
} }
@ -629,50 +630,23 @@ void TransfersDialog::insertTransfers()
// std::list<DwlDetails> dwlDetails; // std::list<DwlDetails> dwlDetails;
// rsFiles->getDwlDetails(dwlDetails); // rsFiles->getDwlDetails(dwlDetails);
//first clean the model in case some files are not download anymore
//remove items that are not fiends anymore
int removeIndex = 0; std::set<std::string> used_hashes ;
while (removeIndex < DLListModel->rowCount()) {
std::string hash = DLListModel->item(removeIndex, ID)->data(Qt::EditRole).toString().toStdString();
std::list<std::string>::iterator downHashesIt;
bool found = false;
for (downHashesIt = downHashes.begin(); downHashesIt != downHashes.end(); downHashesIt++) {
if (hash == *downHashesIt) {
found = true;
break;
}
}
// if (!found) {
// //look in the queued files
// std::list<DwlDetails>::iterator dwlDetailsIt;
// for (dwlDetailsIt = dwlDetails.begin(); dwlDetailsIt != dwlDetails.end(); dwlDetailsIt++) {
// if (hash == dwlDetailsIt->hash) {
// found = true;
// break;
// }
// }
// }
if (!found) {
DLListModel->takeRow(removeIndex);
} else {
removeIndex++;
}
}
// clear all source peers. // clear all source peers.
std::list<std::string>::iterator it; std::list<std::string>::iterator it;
for (it = downHashes.begin(); it != downHashes.end(); it++) { for (it = downHashes.begin(); it != downHashes.end(); it++)
{
FileInfo info; FileInfo info;
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) { if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) {
//if file transfer is a cache file index file, don't show it //if file transfer is a cache file index file, don't show it
continue; continue;
} }
if ((info.flags & CB_CODE_CACHE)) { if((info.flags & CB_CODE_CACHE) && !ui._showCacheTransfers_CB->isChecked())
/*(!_show_cache_transfers) &&*/
continue; continue;
}
QString fileName = QString::fromUtf8(info.fname.c_str()); QString fileName = QString::fromUtf8(info.fname.c_str());
QString fileHash = QString::fromStdString(info.hash); QString fileHash = QString::fromStdString(info.hash);
@ -729,6 +703,7 @@ void TransfersDialog::insertTransfers()
pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ; pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ;
int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime); int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime);
used_hashes.insert(info.hash) ;
/* continue to next download item if no peers to add */ /* continue to next download item if no peers to add */
if (!info.peers.size()) continue; if (!info.peers.size()) continue;
@ -776,7 +751,7 @@ void TransfersDialog::insertTransfers()
// std::cerr << std::endl ; // std::cerr << std::endl ;
// std::cerr << std::endl ; // std::cerr << std::endl ;
std::cout << "adding peer " << peerName.toStdString() << " to row " << addedRow << ", hashfile and peerid=" << hashFileAndPeerId.toStdString() << std::endl ; // std::cout << "adding peer " << peerName.toStdString() << " to row " << addedRow << ", hashfile and peerid=" << hashFileAndPeerId.toStdString() << std::endl ;
int row_id = addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, status, peerpinfo); int row_id = addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, status, peerpinfo);
used_rows.insert(row_id) ; used_rows.insert(row_id) ;
@ -791,31 +766,22 @@ void TransfersDialog::insertTransfers()
if(used_rows.find(r) == used_rows.end()) if(used_rows.find(r) == used_rows.end())
dlItem->takeRow(r) ; dlItem->takeRow(r) ;
} }
// remove hashes that where not shown
//first clean the model in case some files are not download anymore
//remove items that are not fiends anymore
int removeIndex = 0;
while (removeIndex < DLListModel->rowCount())
{
std::string hash = DLListModel->item(removeIndex, ID)->data(Qt::EditRole).toString().toStdString();
/* here i will insert files from the download queue - which are if(used_hashes.find(hash) == used_hashes.end())
* not started yet and can't be find in FileDownloads DLListModel->takeRow(removeIndex);
* */ else
// std::list<DwlDetails>::iterator dit; removeIndex++;
// for (dit = dwlDetails.begin(); dit != dwlDetails.end(); dit ++) }
// {
//// switch (dit->priority) {
//// case 0: priority = tr("Low"); break;
//// case 1: priority = tr("Normal"); break;
//// case 2: priority = tr("High"); break;
//// case 3: priority = tr("Auto"); break;
//// default: priority = tr("Auto"); break;
//// }
//
// FileProgressInfo pinfo ;
// pinfo.progress = 0.0 ;
// pinfo.nb_chunks = 0 ;
//
// addItem("", QString::fromUtf8(dit->fname.c_str()),
// QString::fromStdString(dit->hash), dit->count, pinfo, 0, 0,
// tr("Queued"), "", 0, 0, 0);
// }
//
// Now show upload hashes
//
std::list<std::string> upHashes; std::list<std::string> upHashes;
rsFiles->FileUploads(upHashes); rsFiles->FileUploads(upHashes);
//first clean the model in case some files are not uploaded anymore //first clean the model in case some files are not uploaded anymore
@ -847,7 +813,7 @@ void TransfersDialog::insertTransfers()
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info)) { if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_UPLOAD, info)) {
continue; continue;
} }
if (/*(!_show_cache_transfers) &&*/ (info.flags & CB_CODE_CACHE)) if((info.flags & CB_CODE_CACHE) && !ui._showCacheTransfers_CB->isChecked())
continue ; continue ;
std::list<TransferInfo>::iterator pit; std::list<TransferInfo>::iterator pit;

View file

@ -602,6 +602,13 @@ p, li { white-space: pre-wrap; }
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QCheckBox" name="_showCacheTransfers_CB">
<property name="text">
<string>Show cache transfers</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -658,9 +665,6 @@ p, li { white-space: pre-wrap; }
<attribute name="headerStretchLastSection"> <attribute name="headerStretchLastSection">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -843,8 +847,8 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>98</width> <width>578</width>
<height>28</height> <height>113</height>
</rect> </rect>
</property> </property>
</widget> </widget>