improved strategy of cleaning unfinished cache transfers

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4171 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-04-25 14:20:57 +00:00
parent 61b387447f
commit 993e0d225c
4 changed files with 14 additions and 7 deletions

View File

@ -69,6 +69,7 @@
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 MAX_TIME_INACTIVE_REQUEUED = 60 ; // time after which an inactive ftFileControl is bt-queued
static const uint32_t TIMOUT_CACHE_FILE_TRANSFER = 800 ; // time after which cache transfer gets cancelled if inactive.
static const uint32_t FT_FILECONTROL_QUEUE_ADD_END = 0 ;
static const uint32_t FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE = 1 ;
@ -352,14 +353,14 @@ void ftController::cleanCacheDownloads()
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
if ((it->second)->mFlags & RS_FILE_HINTS_CACHE)
if (((it->second)->mFlags & RS_FILE_HINTS_CACHE) && it->second->mState != ftFileControl::DOWNLOADING)
// check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::run() cache transfer found. age of this tranfer is :" << (int)(time(NULL) - (it->second)->mCreateTime);
std::cerr << std::endl;
#endif
if ((now - (it->second)->mCreator->lastRecvTimeStamp()) > TIMOUT_CACHE_FILE_TRANSFER)
if ((now > (it->second)->mCreator->creationTimeStamp()) + TIMOUT_CACHE_FILE_TRANSFER)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::run() cache transfer to old. Cancelling transfer. Hash :" << (it->second)->mHash << ", time=" << (it->second)->mCreateTime << ", now = " << time(NULL) ;

View File

@ -59,9 +59,6 @@ class p3turtle ;
const uint32_t FC_TRANSFER_COMPLETE = 0x0001;
//timeouts in seconds
const int TIMOUT_CACHE_FILE_TRANSFER = 800;
class ftFileControl
{
public:

View File

@ -35,7 +35,9 @@ ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const std::
std::cerr << std::endl;
#endif
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
_last_recv_time_t = time(NULL) ;
time_t now = time(NULL) ;
_last_recv_time_t = now ;
_creation_time = now ;
}
bool ftFileCreator::getFileData(const std::string& peer_id,uint64_t offset, uint32_t &chunk_size, void *data)
@ -64,6 +66,11 @@ bool ftFileCreator::getFileData(const std::string& peer_id,uint64_t offset, uint
return false ;
}
time_t ftFileCreator::creationTimeStamp()
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
return _creation_time ;
}
time_t ftFileCreator::lastRecvTimeStamp()
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/

View File

@ -98,6 +98,7 @@ 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
//
@ -142,7 +143,8 @@ class ftFileCreator: public ftFileProvider
ChunkMap chunkMap ;
time_t _last_recv_time_t ; /// last time stamp when data was received.
time_t _last_recv_time_t ; /// last time stamp when data was received. Used for queue control.
time_t _creation_time ; /// time at which the file creator was created. Used to spot long-inactive transfers.
};
#endif // FT_FILE_CREATOR_HEADER