moved the callback information into flags in ftFileControl. Side effect: code is simpler, channel transfers are saved in a backward compatible way

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3674 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-10-16 15:21:37 +00:00
parent 8369d42600
commit c8f6770b7d
4 changed files with 46 additions and 95 deletions

View file

@ -63,6 +63,7 @@
* #define CONTROL_DEBUG 1 * #define CONTROL_DEBUG 1
* #define DEBUG_DWLQUEUE 1 * #define DEBUG_DWLQUEUE 1
*****/ *****/
#define CONTROL_DEBUG 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
@ -82,14 +83,12 @@ ftFileControl::ftFileControl()
ftFileControl::ftFileControl(std::string fname, ftFileControl::ftFileControl(std::string fname,
std::string tmppath, std::string dest, std::string tmppath, std::string dest,
uint64_t size, std::string hash, uint32_t flags, uint64_t size, std::string hash, uint32_t flags,
ftFileCreator *fc, ftTransferModule *tm, uint32_t cb) ftFileCreator *fc, ftTransferModule *tm)
:mName(fname), mCurrentPath(tmppath), mDestination(dest), :mName(fname), mCurrentPath(tmppath), mDestination(dest),
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash), mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
mSize(size), mFlags(flags), mDoCallback(false), mCallbackCode(cb), mSize(size), mFlags(flags),
mPriority(SPEED_NORMAL) // default priority to normal mPriority(SPEED_NORMAL) // default priority to normal
{ {
if (cb)
mDoCallback = true;
return; return;
} }
@ -738,10 +737,7 @@ bool ftController::completeFile(std::string hash)
uint32_t state = 0; uint32_t state = 0;
uint32_t period = 0; uint32_t period = 0;
uint32_t flags = 0; uint32_t flags = 0;
uint32_t extraflags = 0;
bool doCallback = false;
uint32_t callbackCode = 0;
{ {
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
@ -822,17 +818,14 @@ bool ftController::completeFile(std::string hash)
size = fc->mSize; size = fc->mSize;
state = fc->mState; state = fc->mState;
period = 30 * 24 * 3600; /* 30 days */ period = 30 * 24 * 3600; /* 30 days */
flags = 0; extraflags = 0;
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "CompleteFile(): size = " << size << std::endl ; std::cerr << "CompleteFile(): size = " << size << std::endl ;
#endif #endif
doCallback = fc->mDoCallback;
callbackCode = fc->mCallbackCode;
mDataplex->removeTransferModule(hash_to_suppress) ; mDataplex->removeTransferModule(hash_to_suppress) ;
uint32_t flgs = fc->mFlags ; flags = fc->mFlags ;
locked_queueRemove(it->second->mQueuePosition) ; locked_queueRemove(it->second->mQueuePosition) ;
@ -844,7 +837,7 @@ bool ftController::completeFile(std::string hash)
mDownloads.erase(it); mDownloads.erase(it);
if(flgs & RS_FILE_HINTS_NETWORK_WIDE) if(flags & RS_FILE_HINTS_NETWORK_WIDE)
mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ; mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ;
} /******* UNLOCKED ********/ } /******* UNLOCKED ********/
@ -855,15 +848,15 @@ bool ftController::completeFile(std::string hash)
***********************************************************/ ***********************************************************/
/* If it has a callback - do it now */ /* If it has a callback - do it now */
if (doCallback)
if(flags & ( RS_FILE_HINTS_CACHE | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_MEDIA))
{ {
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() doing Callback, callbackCode:" << callbackCode; std::cerr << "ftController::completeFile() doing Callback, callbackflags:" << (flags & ( RS_FILE_HINTS_CACHE | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_MEDIA)) ;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
switch (callbackCode) if(flags & RS_FILE_HINTS_CACHE)
{ {
case CB_CODE_CACHE:
/* callback */ /* callback */
if (state == ftFileControl::COMPLETED) if (state == ftFileControl::COMPLETED)
{ {
@ -882,23 +875,24 @@ bool ftController::completeFile(std::string hash)
#endif #endif
FailedCache(hash); FailedCache(hash);
} }
break; }
case CB_CODE_EXTRA:
if(flags & RS_FILE_HINTS_EXTRA)
{
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() adding to ExtraList"; std::cerr << "ftController::completeFile() adding to ExtraList";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mExtraList->addExtraFile(path, hash, size, period, flags); mExtraList->addExtraFile(path, hash, size, period, extraflags);
}
if(flags & RS_FILE_HINTS_MEDIA)
break; {
case CB_CODE_MEDIA:
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() NULL MEDIA callback"; std::cerr << "ftController::completeFile() NULL MEDIA callback";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
break;
} }
} }
else else
@ -907,8 +901,6 @@ bool ftController::completeFile(std::string hash)
std::cerr << "ftController::completeFile() No callback"; std::cerr << "ftController::completeFile() No callback";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
} }
IndicateConfigChanged(); /* completed transfer -> save */ IndicateConfigChanged(); /* completed transfer -> save */
@ -1158,27 +1150,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
} }
} /******* UNLOCKED ********/ } /******* UNLOCKED ********/
bool doCallback = false; if(!(flags & RS_FILE_HINTS_NO_SEARCH))
uint32_t callbackCode = 0;
if (flags & RS_FILE_HINTS_NO_SEARCH)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest() Flags for NO_SEARCH ";
std::cerr << std::endl;
#endif
/* no search */
if (flags & RS_FILE_HINTS_CACHE)
{
doCallback = true;
callbackCode = CB_CODE_CACHE;
}
else if (flags & RS_FILE_HINTS_EXTRA)
{
doCallback = true;
callbackCode = CB_CODE_EXTRA;
}
}
else
{ {
/* do a source search - for any extra sources */ /* do a source search - for any extra sources */
// add sources only in direct mode // add sources only in direct mode
@ -1210,21 +1182,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
} }
} }
} }
if (flags & RS_FILE_HINTS_EXTRA)
{
doCallback = true;
callbackCode = CB_CODE_EXTRA;
} }
else if (flags & RS_FILE_HINTS_MEDIA)
{
doCallback = true;
callbackCode = CB_CODE_MEDIA;
}
}
//std::map<std::string, ftTransferModule *> mTransfers;
//std::map<std::string, ftFileCreator *> mFileCreators;
/* add in new item for download */ /* add in new item for download */
std::string savepath; std::string savepath;
@ -1257,7 +1215,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
fc->setChunkStrategy(mDefaultChunkStrategy) ; fc->setChunkStrategy(mDefaultChunkStrategy) ;
/* add into maps */ /* add into maps */
ftFileControl *ftfc = new ftFileControl(fname, savepath, destination, size, hash, flags, fc, tm, callbackCode); ftFileControl *ftfc = new ftFileControl(fname, savepath, destination, size, hash, flags, fc, tm);
ftfc->mCreateTime = time(NULL); ftfc->mCreateTime = time(NULL);
/* now add source peers (and their current state) */ /* now add source peers (and their current state) */
@ -1943,8 +1901,9 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
if (fit == mDownloads.end()) if (fit == mDownloads.end())
continue; continue;
/* ignore callback ones */ /* ignore cache files. As this is small files, better download them again from scratch at restart.*/
if (fit->second->mDoCallback)
if (fit->second->mFlags & RS_FILE_HINTS_CACHE)
{ {
#ifdef CONTROL_DEBUG #ifdef CONTROL_DEBUG
std::cerr << "ftcontroller::saveList(): Not saving (callback) file entry " << fit->second->mName << ", " << fit->second->mHash << ", " << fit->second->mSize << std::endl ; std::cerr << "ftcontroller::saveList(): Not saving (callback) file entry " << fit->second->mName << ", " << fit->second->mHash << ", " << fit->second->mSize << std::endl ;

View file

@ -77,7 +77,7 @@ class ftFileControl
ftFileControl(); ftFileControl();
ftFileControl(std::string fname, std::string tmppath, std::string dest, ftFileControl(std::string fname, std::string tmppath, std::string dest,
uint64_t size, std::string hash, uint32_t flags, uint64_t size, std::string hash, uint32_t flags,
ftFileCreator *fc, ftTransferModule *tm, uint32_t cb_flags); ftFileCreator *fc, ftTransferModule *tm);
std::string mName; std::string mName;
std::string mCurrentPath; /* current full path (including name) */ std::string mCurrentPath; /* current full path (including name) */
@ -88,8 +88,6 @@ class ftFileControl
std::string mHash; std::string mHash;
uint64_t mSize; uint64_t mSize;
uint32_t mFlags; uint32_t mFlags;
bool mDoCallback;
uint32_t mCallbackCode;
time_t mCreateTime; time_t mCreateTime;
DwlSpeed mPriority ; DwlSpeed mPriority ;
uint32_t mQueuePriority ; uint32_t mQueuePriority ;

View file

@ -73,22 +73,16 @@ const uint32_t RS_FILE_HINTS_UPLOAD = 0x00000020;
const uint32_t RS_FILE_HINTS_NETWORK_WIDE = 0x00000080; // anonymously shared over network const uint32_t RS_FILE_HINTS_NETWORK_WIDE = 0x00000080; // anonymously shared over network
const uint32_t RS_FILE_HINTS_BROWSABLE = 0x00000100; // browsable by friends const uint32_t RS_FILE_HINTS_BROWSABLE = 0x00000100; // browsable by friends
const uint32_t RS_FILE_HINTS_ASSUME_AVAILABILITY = 0x00000200; // Assume full source availability. Used for cache files. const uint32_t RS_FILE_HINTS_ASSUME_AVAILABILITY = 0x00000200; // Assume full source availability. Used for cache files.
const uint32_t RS_FILE_HINTS_MEDIA = 0x00001000;
const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly.
const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x01000000; const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x01000000;
const uint32_t RS_FILE_HINTS_NO_SEARCH = 0x02000000; const uint32_t RS_FILE_HINTS_NO_SEARCH = 0x02000000;
/* Callback Codes */ /* Callback Codes */
//const uint32_t RS_FILE_HINTS_CACHE = 0x00000001; // ALREADY EXISTS
const uint32_t RS_FILE_HINTS_MEDIA = 0x00001000;
const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly.
const uint32_t RS_FILE_EXTRA_DELETE = 0x0010; 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;
struct SharedDirInfo struct SharedDirInfo
{ {
std::string filename ; std::string filename ;

View file

@ -768,7 +768,7 @@ void TransfersDialog::insertTransfers()
continue; continue;
} }
if((info.flags & CB_CODE_CACHE) && !showCacheTransfers) if((info.flags & RS_FILE_HINTS_CACHE) && !showCacheTransfers)
continue; continue;
QString fileName = QString::fromUtf8(info.fname.c_str()); QString fileName = QString::fromUtf8(info.fname.c_str());
@ -901,7 +901,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((info.flags & CB_CODE_CACHE) && showCacheTransfers) if((info.flags & RS_FILE_HINTS_CACHE) && showCacheTransfers)
continue ; continue ;
std::list<TransferInfo>::iterator pit; std::list<TransferInfo>::iterator pit;