diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 052503825..9dfc2116c 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -426,17 +426,17 @@ void ftController::checkDownloadQueue() for(std::map::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; diff --git a/libretroshare/src/ft/ftfilecreator.cc b/libretroshare/src/ft/ftfilecreator.cc index 20b7ba860..81c6c508d 100644 --- a/libretroshare/src/ft/ftfilecreator.cc +++ b/libretroshare/src/ft/ftfilecreator.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -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() { diff --git a/libretroshare/src/ft/ftfilecreator.h b/libretroshare/src/ft/ftfilecreator.h index 6483fae93..b6df21918 100644 --- a/libretroshare/src/ft/ftfilecreator.h +++ b/libretroshare/src/ft/ftfilecreator.h @@ -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 diff --git a/libretroshare/src/ft/fttransfermodule.cc b/libretroshare/src/ft/fttransfermodule.cc index 08c1c7c93..0517112d4 100644 --- a/libretroshare/src/ft/fttransfermodule.cc +++ b/libretroshare/src/ft/fttransfermodule.cc @@ -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; } diff --git a/libretroshare/src/ft/fttransfermodule.h b/libretroshare/src/ft/fttransfermodule.h index 5901f9c5c..0bc5810ef 100644 --- a/libretroshare/src/ft/fttransfermodule.h +++ b/libretroshare/src/ft/fttransfermodule.h @@ -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 ;