* fixed, transfer start when subscribing to channel.

* cleaned up p3distrib callbacks.
 * added holdQueue for transfer startup in controller. 
 * fixed partial resume.
 * updated Mac script to only build library.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@828 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-11-21 00:10:59 +00:00
parent 71797d6f70
commit c46b823261
12 changed files with 222 additions and 141 deletions

View file

@ -73,7 +73,7 @@ ftFileControl::ftFileControl(std::string fname,
}
ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir)
:CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm)
:CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm), mFtActive(false)
{
/* TODO */
}
@ -100,6 +100,20 @@ void ftController::run()
//std::cerr << "ftController::run()";
//std::cerr << std::endl;
#endif
bool doPending = false;
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
doPending = (mFtActive) && (!mFtPendingDone);
}
if (doPending)
{
if (!handleAPendingRequest())
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
mFtPendingDone = true;
}
}
/* tick the transferModules */
std::list<std::string> done;
@ -124,6 +138,7 @@ void ftController::run()
completeFile(*it);
}
mDone.clear();
}
}
@ -329,10 +344,51 @@ bool ftController::completeFile(std::string hash)
const uint32_t FT_CNTRL_STANDARD_RATE = 1024 * 1024;
const uint32_t FT_CNTRL_SLOW_RATE = 10 * 1024;
bool ftController::activate()
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
mFtActive = true;
mFtPendingDone = false;
return true;
}
bool ftController::handleAPendingRequest()
{
ftPendingRequest req;
{ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
if (mPendingRequests.size() < 1)
{
return false;
}
req = mPendingRequests.front();
mPendingRequests.pop_front();
}
FileRequest(req.mName, req.mHash, req.mSize, req.mDest, req.mFlags, req.mSrcIds);
return true;
}
bool ftController::FileRequest(std::string fname, std::string hash,
uint64_t size, std::string dest, uint32_t flags,
std::list<std::string> &srcIds)
{
/* If file transfer is not enabled ....
* save request for later. This will also
* mean that we will have to copy local files,
* or have a callback which says: local file.
*/
{ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
if (!mFtActive)
{
/* store in pending queue */
ftPendingRequest req(fname, hash, size, dest, flags, srcIds);
mPendingRequests.push_back(req);
return true;
}
}
/* check if we have the file */
FileInfo info;
std::list<std::string>::iterator it;
@ -1070,22 +1126,22 @@ bool ftController::loadList(std::list<RsItem *> load)
}
loadConfigMap(configMap);
/* cleanup */
delete (*it);
}
else if (NULL != (rsft = dynamic_cast<RsFileTransfer *>(*it)))
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
/* save to the preLoad list */
mResumeTransferList.push_back(rsft);
}
else
{
/* cleanup */
delete (*it);
/* This will get stored on a waiting list - until the
* config files are fully loaded
*/
FileRequest(rsft->file.name, rsft->file.hash, rsft->file.filesize,
rsft->file.path, 0, rsft->allPeerIds.ids);
}
/* cleanup */
delete (*it);
}
return true;
@ -1112,31 +1168,3 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
return true;
}
bool ftController::ResumeTransfers()
{
std::list<RsFileTransfer *> resumeList;
std::list<RsFileTransfer *>::iterator it;
{ RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
resumeList = mResumeTransferList;
mResumeTransferList.clear();
}
for(it = resumeList.begin(); it != resumeList.end(); it++)
{
/* do File request */
std::string fname = (*it)->file.name;
std::string hash = (*it)->file.hash;
uint64_t size = (*it)->file.filesize;
std::string dest = (*it)->file.path;
uint32_t flags = 0; //(*it)->flags;
std::list<std::string> srcIds = (*it)->allPeerIds.ids;
FileRequest(fname,hash,size,dest,flags,srcIds);
delete (*it);
}
return true;
}

View file

@ -86,6 +86,25 @@ class ftFileControl
uint32_t mCallbackCode;
};
class ftPendingRequest
{
public:
ftPendingRequest(std::string fname, std::string hash,
uint64_t size, std::string dest, uint32_t flags,
std::list<std::string> &srcIds)
: mName(fname), mHash(hash), mSize(size),
mDest(dest), mFlags(flags),mSrcIds(srcIds) { return; }
ftPendingRequest() : mSize(0), mFlags(0) { return; }
std::string mName;
std::string mHash;
uint64_t mSize;
std::string mDest;
uint32_t mFlags;
std::list<std::string> mSrcIds;
};
class ftController: public CacheTransfer, public RsThread, public pqiMonitor, public p3Config
{
@ -95,7 +114,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir);
void setFtSearchNExtra(ftSearch *, ftExtraList *);
bool ResumeTransfers();
bool activate();
virtual void run();
@ -154,6 +173,7 @@ bool loadConfigMap(std::map<std::string, std::string> &configMap);
/* RunTime Functions */
void checkDownloadQueue();
bool completeFile(std::string hash);
bool handleAPendingRequest();
bool setPeerState(ftTransferModule *tm, std::string id,
uint32_t maxrate, bool online);
@ -184,13 +204,14 @@ bool setPeerState(ftTransferModule *tm, std::string id,
std::list<std::string> mStreamQueue;
std::list<std::string> mFastQueue;
/* Config Load */
std::list<RsFileTransfer *> mResumeTransferList;
/* callback list (for File Completion) */
RsMutex doneMutex;
std::list<std::string> mDone;
/* List to Pause File transfers until Caches are properly loaded */
bool mFtActive;
bool mFtPendingDone;
std::list<ftPendingRequest> mPendingRequests;
};
#endif

View file

@ -201,6 +201,10 @@ int ftFileCreator::initializeFileAttrs()
uint64_t recvdsize = ftell(fd);
std::cerr << "ftFileCreator::initializeFileAttrs() File Expected Size: " << mSize << " RecvdSize: " << recvdsize << std::endl;
/* start from there! */
mStart = recvdsize;
mEnd = recvdsize;
return 1;
}

View file

@ -794,7 +794,7 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
bool ftServer::ResumeTransfers()
{
mFtController->ResumeTransfers();
mFtController->activate();
return true;
}

View file

@ -148,7 +148,7 @@ bool ftTransferModule::addFileSource(std::string peerId)
std::cerr << std::endl;
#endif
}
return true;
}
@ -542,7 +542,7 @@ bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
return false;
}
if (ageReq > FT_TM_RESTART_DOWNLOAD * (info.nResets + 1))
if (ageReq > (int) (FT_TM_RESTART_DOWNLOAD * (info.nResets + 1)))
{
if (info.nResets > 1) /* 3rd timeout */
{
@ -569,7 +569,7 @@ bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info)
}
}
if (ageRecv > FT_TM_DOWNLOAD_TIMEOUT)
if (ageRecv > (int) FT_TM_DOWNLOAD_TIMEOUT)
{
info.state = PQIPEER_IDLE;
return false;