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 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 INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released
@ -82,14 +83,12 @@ ftFileControl::ftFileControl()
ftFileControl::ftFileControl(std::string fname,
std::string tmppath, std::string dest,
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),
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
{
if (cb)
mDoCallback = true;
return;
}
@ -738,10 +737,7 @@ bool ftController::completeFile(std::string hash)
uint32_t state = 0;
uint32_t period = 0;
uint32_t flags = 0;
bool doCallback = false;
uint32_t callbackCode = 0;
uint32_t extraflags = 0;
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
@ -822,17 +818,14 @@ bool ftController::completeFile(std::string hash)
size = fc->mSize;
state = fc->mState;
period = 30 * 24 * 3600; /* 30 days */
flags = 0;
extraflags = 0;
#ifdef CONTROL_DEBUG
std::cerr << "CompleteFile(): size = " << size << std::endl ;
#endif
doCallback = fc->mDoCallback;
callbackCode = fc->mCallbackCode;
mDataplex->removeTransferModule(hash_to_suppress) ;
uint32_t flgs = fc->mFlags ;
flags = fc->mFlags ;
locked_queueRemove(it->second->mQueuePosition) ;
@ -844,7 +837,7 @@ bool ftController::completeFile(std::string hash)
mDownloads.erase(it);
if(flgs & RS_FILE_HINTS_NETWORK_WIDE)
if(flags & RS_FILE_HINTS_NETWORK_WIDE)
mTurtle->stopMonitoringFileTunnels(hash_to_suppress) ;
} /******* UNLOCKED ********/
@ -855,50 +848,51 @@ bool ftController::completeFile(std::string hash)
***********************************************************/
/* 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
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;
#endif
switch (callbackCode)
if(flags & RS_FILE_HINTS_CACHE)
{
case CB_CODE_CACHE:
/* callback */
if (state == ftFileControl::COMPLETED)
{
/* callback */
if (state == ftFileControl::COMPLETED)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() doing Callback : Success";
std::cerr << std::endl;
std::cerr << "ftController::completeFile() doing Callback : Success";
std::cerr << std::endl;
#endif
CompletedCache(hash);
}
else
{
CompletedCache(hash);
}
else
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() Cache Callback : Failed";
std::cerr << std::endl;
std::cerr << "ftController::completeFile() Cache Callback : Failed";
std::cerr << std::endl;
#endif
FailedCache(hash);
}
break;
case CB_CODE_EXTRA:
FailedCache(hash);
}
}
if(flags & RS_FILE_HINTS_EXTRA)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() adding to ExtraList";
std::cerr << std::endl;
std::cerr << "ftController::completeFile() adding to ExtraList";
std::cerr << std::endl;
#endif
mExtraList->addExtraFile(path, hash, size, period, flags);
mExtraList->addExtraFile(path, hash, size, period, extraflags);
}
break;
case CB_CODE_MEDIA:
if(flags & RS_FILE_HINTS_MEDIA)
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController::completeFile() NULL MEDIA callback";
std::cerr << std::endl;
#endif
break;
}
}
else
@ -907,8 +901,6 @@ bool ftController::completeFile(std::string hash)
std::cerr << "ftController::completeFile() No callback";
std::cerr << std::endl;
#endif
}
IndicateConfigChanged(); /* completed transfer -> save */
@ -1158,27 +1150,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
}
} /******* UNLOCKED ********/
bool doCallback = false;
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
if(!(flags & RS_FILE_HINTS_NO_SEARCH))
{
/* do a source search - for any extra sources */
// add sources only in direct mode
@ -1210,22 +1182,8 @@ 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 */
std::string savepath;
std::string destination;
@ -1257,7 +1215,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
fc->setChunkStrategy(mDefaultChunkStrategy) ;
/* 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);
/* now add source peers (and their current state) */
@ -1943,8 +1901,9 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
if (fit == mDownloads.end())
continue;
/* ignore callback ones */
if (fit->second->mDoCallback)
/* ignore cache files. As this is small files, better download them again from scratch at restart.*/
if (fit->second->mFlags & RS_FILE_HINTS_CACHE)
{
#ifdef CONTROL_DEBUG
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(std::string fname, std::string tmppath, std::string dest,
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 mCurrentPath; /* current full path (including name) */
@ -88,8 +88,6 @@ class ftFileControl
std::string mHash;
uint64_t mSize;
uint32_t mFlags;
bool mDoCallback;
uint32_t mCallbackCode;
time_t mCreateTime;
DwlSpeed mPriority ;
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_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_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_NO_SEARCH = 0x02000000;
const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x01000000;
const uint32_t RS_FILE_HINTS_NO_SEARCH = 0x02000000;
/* 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 CB_CODE_CACHE = 0x0001;
const uint32_t CB_CODE_EXTRA = 0x0002;
const uint32_t CB_CODE_MEDIA = 0x0004;
struct SharedDirInfo
{
std::string filename ;

View File

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