From e34173759ec5f0c0c13a9ea68f10d73cb3b99507 Mon Sep 17 00:00:00 2001 From: joss17 Date: Wed, 6 May 2009 20:48:32 +0000 Subject: [PATCH] timeout on fil index cache transfer \n Set fileIndex cache transfer timeout to 300sec \n Remove the downloads item for file index cache transfer Merge branch 'fiIndexCacheTransfertImprove' git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1180 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftcontroller.cc | 38 +++++++++++++++++----- libretroshare/src/ft/ftcontroller.h | 8 ++--- libretroshare/src/ft/ftserver.cc | 1 - libretroshare/src/rsiface/rsfiles.h | 4 +++ retroshare-gui/src/gui/TransfersDialog.cpp | 6 ++++ retroshare-gui/src/rsiface/rsfiles.h | 4 +++ 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index ace3ebdb3..20b729719 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -67,7 +67,7 @@ ftFileControl::ftFileControl(std::string fname, ftFileCreator *fc, ftTransferModule *tm, uint32_t cb) :mName(fname), mCurrentPath(tmppath), mDestination(dest), mTransfer(tm), mCreator(fc), mState(0), mHash(hash), - mSize(size), mFlags(0), mDoCallback(false), mCallbackCode(cb) + mSize(size), mFlags(flags), mDoCallback(false), mCallbackCode(cb) { if (cb) mDoCallback = true; @@ -88,8 +88,8 @@ void ftController::setFtSearchNExtra(ftSearch *search, ftExtraList *list) void ftController::run() { - /* check the queues */ + /* check the queues */ while(1) { #ifdef WIN32 @@ -99,8 +99,8 @@ void ftController::run() #endif #ifdef CONTROL_DEBUG - //std::cerr << "ftController::run()"; - //std::cerr << std::endl; + std::cerr << "ftController::run()"; + std::cerr << std::endl; #endif bool doPending = false; { @@ -124,7 +124,8 @@ void ftController::run() RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ std::map::iterator it; - for(it = mDownloads.begin(); it != mDownloads.end(); it++) + std::map currentDownloads = *(&mDownloads); + for(it = currentDownloads.begin(); it != currentDownloads.end(); it++) { #ifdef CONTROL_DEBUG @@ -132,8 +133,26 @@ void ftController::run() std::cerr << std::endl; #endif - if (it->second.mTransfer) - (it->second.mTransfer)->tick(); + if (it->second.mTransfer) { + (it->second.mTransfer)->tick(); + + + //check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER + if ((it->second).mFlags & RS_FILE_HINTS_CACHE) { +#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 ((time(NULL) - (it->second).mCreateTime) > TIMOUT_CACHE_FILE_TRANSFER) { +#ifdef CONTROL_DEBUG + std::cerr << "ftController::run() cache transfer to old. Cancelling transfer. Hash :" << (it->second).mHash; + std::cerr << std::endl; +#endif + this->FileCancel((it->second).mHash); + } + } + + } } } @@ -143,7 +162,6 @@ void ftController::run() completeFile(*it); } mDone.clear(); - } } @@ -661,12 +679,15 @@ bool ftController::FileRequest(std::string fname, std::string hash, /* add into maps */ ftFileControl ftfc(fname, savepath, destination, size, hash, flags, fc, tm, callbackCode); + ftfc.mCreateTime = time(NULL); #ifdef CONTROL_DEBUG std::cerr << "ftController::FileRequest() Created ftFileCreator @: " << fc; std::cerr << std::endl; std::cerr << "ftController::FileRequest() Created ftTransModule @: " << tm; std::cerr << std::endl; + std::cerr << "ftController::FileRequest() Created ftFileControl." ; + std::cerr << std::endl; #endif /* add to ClientModule */ @@ -959,6 +980,7 @@ bool ftController::FileDetails(std::string hash, FileInfo &info) /* extract details */ info.hash = hash; info.fname = it->second.mName; + info.flags = it->second.mFlags; info.path = RsDirUtil::removeTopDir(it->second.mDestination); /* remove fname */ /* get list of sources from transferModule */ diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 132ca5a4f..3c9b1250a 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -56,12 +56,11 @@ class ftDataMultiplex; #include -const uint32_t CB_CODE_CACHE = 0x0001; -const uint32_t CB_CODE_EXTRA = 0x0002; -const uint32_t CB_CODE_MEDIA = 0x0004; - const uint32_t FC_TRANSFER_COMPLETE = 0x0001; +//timeouts in seconds +const int TIMOUT_CACHE_FILE_TRANSFER = 300; + class ftFileControl { public: @@ -84,6 +83,7 @@ class ftFileControl uint32_t mFlags; bool mDoCallback; uint32_t mCallbackCode; + time_t mCreateTime; }; class ftPendingRequest diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 5110f7a20..799deadec 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -356,7 +356,6 @@ int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &d std::cerr << "mFiStore not SET yet = FAIL"; std::cerr << std::endl; } - #endif return mFiStore->RequestDirDetails(uid, path, details); } diff --git a/libretroshare/src/rsiface/rsfiles.h b/libretroshare/src/rsiface/rsfiles.h index 58335ee48..2ede4e3e8 100644 --- a/libretroshare/src/rsiface/rsfiles.h +++ b/libretroshare/src/rsiface/rsfiles.h @@ -81,6 +81,10 @@ const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly. const uint32_t RS_FILE_EXTRA_DELETE = 0x0010; +const uint32_t CB_CODE_CACHE = 0x0001; +const uint32_t CB_CODE_EXTRA = 0x0002; +const uint32_t CB_CODE_MEDIA = 0x0004; + class RsFiles { diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index 22bb3ada5..99a88ca44 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -383,6 +383,12 @@ void TransfersDialog::insertTransfers() continue; } + //if file transfer is a cache file index file, don't show it + if (info.flags & CB_CODE_CACHE) + { + continue; + } + std::list::iterator pit; for(pit = info.peers.begin(); pit != info.peers.end(); pit++) { diff --git a/retroshare-gui/src/rsiface/rsfiles.h b/retroshare-gui/src/rsiface/rsfiles.h index 58335ee48..2ede4e3e8 100644 --- a/retroshare-gui/src/rsiface/rsfiles.h +++ b/retroshare-gui/src/rsiface/rsfiles.h @@ -81,6 +81,10 @@ const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly. const uint32_t RS_FILE_EXTRA_DELETE = 0x0010; +const uint32_t CB_CODE_CACHE = 0x0001; +const uint32_t CB_CODE_EXTRA = 0x0002; +const uint32_t CB_CODE_MEDIA = 0x0004; + class RsFiles {