mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
split lastRecvTimeStamp into two different time stamps: one for last time the file is wrote (or data is received) and one for last activity that is used (and sometimes reset) by ftcontroller when queuing files
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6921 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d0d85c0242
commit
028c9f8c07
@ -426,17 +426,17 @@ void ftController::checkDownloadQueue()
|
||||
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
|
||||
&& (it->second->mState == ftFileControl::PAUSED
|
||||
|| now > it->second->mCreator->lastRecvTimeStamp() + (time_t)MAX_TIME_INACTIVE_REQUEUED))
|
||||
|| now > it->second->mTransfer->lastActvTimeStamp() + (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 ;
|
||||
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->lastActvTimeStamp() << std::endl ;
|
||||
#endif
|
||||
locked_bottomQueue(it->second->mQueuePosition) ;
|
||||
#ifdef DEBUG_DWLQUEUE
|
||||
std::cerr << " new position: " << it->second->mQueuePosition << std::endl ;
|
||||
std::cerr << " new state: " << it->second->mState << std::endl ;
|
||||
#endif
|
||||
it->second->mCreator->resetRecvTimeStamp() ; // very important!
|
||||
it->second->mTransfer->resetActvTimeStamp() ; // very important!
|
||||
++nb_moved ;
|
||||
}
|
||||
|
||||
@ -640,7 +640,7 @@ void ftController::locked_checkQueueElement(uint32_t pos)
|
||||
if(pos < _max_active_downloads && _queue[pos]->mState != ftFileControl::PAUSED)
|
||||
{
|
||||
if(_queue[pos]->mState == ftFileControl::QUEUED)
|
||||
_queue[pos]->mCreator->resetRecvTimeStamp() ;
|
||||
_queue[pos]->mTransfer->resetActvTimeStamp() ;
|
||||
|
||||
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
|
||||
|
||||
@ -1717,7 +1717,7 @@ bool ftController::FileDetails(const std::string &hash, FileInfo &info)
|
||||
{
|
||||
it->second->mTransfer->getFileSources(peerIds);
|
||||
info.priority = it->second->mTransfer->downloadPriority() ;
|
||||
info.lastTS = it->second->mCreator->lastRecvTimeStamp();
|
||||
info.lastTS = it->second->mCreator->lastRecvTimeStamp(); // last time the file was actually written
|
||||
}
|
||||
else
|
||||
info.lastTS = 0;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <util/rsdiscspace.h>
|
||||
#include <util/rsdir.h>
|
||||
|
||||
@ -37,8 +38,26 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::
|
||||
#endif
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
time_t now = time(NULL) ;
|
||||
_last_recv_time_t = now ;
|
||||
_creation_time = now ;
|
||||
|
||||
struct stat64 buf;
|
||||
|
||||
// Initialise last recv time stamp to last modification time for the partial file.
|
||||
//
|
||||
#ifdef WINDOWS_SYS
|
||||
std::wstring wfullname;
|
||||
librs::util::ConvertUtf8ToUtf16(file_name, wfullname);
|
||||
if ( 0 == _wstati64(wfullname.c_str(), &buf))
|
||||
#else
|
||||
if ( 0 == stat64(file_name.c_str(), &buf))
|
||||
#endif
|
||||
_last_recv_time_t = buf.st_mtime ;
|
||||
else
|
||||
_last_recv_time_t = now ;
|
||||
|
||||
#ifdef FILE_DEBUG
|
||||
std::cerr << "Inited last modification time for hash " << hash << " to " << _last_recv_time_t << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ftFileCreator::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
|
||||
@ -77,11 +96,6 @@ time_t ftFileCreator::lastRecvTimeStamp()
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
return _last_recv_time_t ;
|
||||
}
|
||||
void ftFileCreator::resetRecvTimeStamp()
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
_last_recv_time_t = time(NULL) ;
|
||||
}
|
||||
|
||||
void ftFileCreator::closeFile()
|
||||
{
|
||||
|
@ -113,7 +113,6 @@ class ftFileCreator: public ftFileProvider
|
||||
|
||||
// Returns resets the time stamp of the last data receive.
|
||||
time_t lastRecvTimeStamp() ;
|
||||
void resetRecvTimeStamp() ;
|
||||
time_t creationTimeStamp() ;
|
||||
|
||||
// actually store data in the file, and update chunks info
|
||||
|
@ -96,6 +96,8 @@ ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftCon
|
||||
_crcmap_last_asked_time = 0 ;
|
||||
_crcmap_last_tunnel_keepup = 0 ;
|
||||
_crcreq_source = "";
|
||||
|
||||
_last_activity_time_stamp = time(NULL) ;
|
||||
}
|
||||
|
||||
ftTransferModule::~ftTransferModule()
|
||||
@ -286,7 +288,16 @@ uint32_t ftTransferModule::getDataRate(const std::string& peerId)
|
||||
else
|
||||
return (uint32_t) (mit->second).actualRate;
|
||||
}
|
||||
|
||||
void ftTransferModule::resetActvTimeStamp()
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
_last_activity_time_stamp = time(NULL);
|
||||
}
|
||||
time_t ftTransferModule::lastActvTimeStamp()
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
return _last_activity_time_stamp ;
|
||||
}
|
||||
|
||||
//interface to client module
|
||||
bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset, uint32_t chunk_size, void *data)
|
||||
@ -319,6 +330,8 @@ bool ftTransferModule::recvFileData(const std::string& peerId, uint64_t offset,
|
||||
|
||||
locked_storeData(offset, chunk_size, data);
|
||||
|
||||
_last_activity_time_stamp = time(NULL) ;
|
||||
|
||||
free(data) ;
|
||||
return ok;
|
||||
}
|
||||
|
@ -158,6 +158,10 @@ public:
|
||||
DwlSpeed downloadPriority() const { return mPriority ; }
|
||||
void setDownloadPriority(DwlSpeed p) { mPriority =p ; }
|
||||
|
||||
// read/reset the last time the transfer module was active (either wrote data, or was solicitaded by clients)
|
||||
time_t lastActvTimeStamp() ;
|
||||
void resetActvTimeStamp() ;
|
||||
|
||||
private:
|
||||
|
||||
bool locked_tickPeerTransfer(peerInfo &info);
|
||||
@ -190,6 +194,8 @@ private:
|
||||
time_t _crcmap_last_tunnel_keepup ;
|
||||
std::string _crcreq_source ;
|
||||
|
||||
time_t _last_activity_time_stamp ;
|
||||
|
||||
ftFileStatus mFileStatus; //used for pause/resume file transfer
|
||||
|
||||
HashThread *_hash_thread ;
|
||||
|
Loading…
Reference in New Issue
Block a user