added dynamic addign of direct sources from file lists. Useful for channels. Is called once every 61 seconds.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5850 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-11-19 22:45:37 +00:00
parent 93501bdc12
commit b2e97407b5
3 changed files with 43 additions and 23 deletions

View File

@ -74,6 +74,9 @@ static const int32_t TIMOUT_CACHE_FILE_TRANSFER = 800 ; // time after which cac
static const int32_t FT_FILECONTROL_QUEUE_ADD_END = 0 ;
static const int32_t FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE = 1 ;
const uint32_t FT_CNTRL_STANDARD_RATE = 1024 * 1024;
const uint32_t FT_CNTRL_SLOW_RATE = 10 * 1024;
ftFileControl::ftFileControl()
:mTransfer(NULL), mCreator(NULL),
mState(DOWNLOADING), mSize(0), mFlags(0)
@ -232,6 +235,7 @@ void ftController::run()
if(now > last_save_time + SAVE_TRANSFERS_DELAY)
{
cleanCacheDownloads() ;
searchForDirectSources() ;
IndicateConfigChanged() ;
last_save_time = now ;
@ -277,6 +281,23 @@ void ftController::run()
}
void ftController::searchForDirectSources()
{
std::cerr << "Searching for potential new direct sources" << std::endl;
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
FileInfo info ;
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
if(it->second->mState != ftFileControl::QUEUED && it->second->mState != ftFileControl::PAUSED)
if(! (it->second->mFlags & RS_FILE_REQ_CACHE))
if(mSearch->search(it->first, RS_FILE_HINTS_REMOTE | RS_FILE_HINTS_SPEC_ONLY, info))
for(std::list<TransferInfo>::const_iterator pit = info.peers.begin(); pit != info.peers.end(); pit++)
if(it->second->mTransfer->addFileSource(pit->peerId)) /* if the sources don't exist already - add in */
setPeerState(it->second->mTransfer, pit->peerId, FT_CNTRL_STANDARD_RATE, mLinkMgr->isOnline( pit->peerId ));
}
void ftController::tickTransfers()
{
// 1 - sort modules into arrays according to priority
@ -960,9 +981,6 @@ bool ftController::completeFile(std::string hash)
/********************** Controller Access **********************/
/***************************************************************/
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 ********/

View File

@ -192,6 +192,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
void cleanCacheDownloads() ;
void searchForDirectSources() ;
void tickTransfers() ;
/***************************************************************/

View File

@ -149,34 +149,35 @@ bool ftTransferModule::getFileSources(std::list<std::string> &peerIds)
bool ftTransferModule::addFileSource(const std::string& peerId)
{
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit;
mit = mFileSources.find(peerId);
if (mit == mFileSources.end())
{
/* add in new source */
peerInfo pInfo(peerId);
mFileSources.insert(std::pair<std::string,peerInfo>(peerId,pInfo));
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
std::map<std::string,peerInfo>::iterator mit;
mit = mFileSources.find(peerId);
if (mit == mFileSources.end())
{
/* add in new source */
peerInfo pInfo(peerId);
mFileSources.insert(std::pair<std::string,peerInfo>(peerId,pInfo));
mit = mFileSources.find(peerId);
mMultiplexor->sendChunkMapRequest(peerId, mHash,false) ;
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::addFileSource()";
std::cerr << " adding peer: " << peerId << " to sourceList";
std::cerr << std::endl;
std::cerr << "ftTransferModule::addFileSource()";
std::cerr << " adding peer: " << peerId << " to sourceList";
std::cerr << std::endl;
#endif
return true ;
}
else
{
}
else
{
#ifdef FT_DEBUG
std::cerr << "ftTransferModule::addFileSource()";
std::cerr << " peer: " << peerId << " already there";
std::cerr << std::endl;
std::cerr << "ftTransferModule::addFileSource()";
std::cerr << " peer: " << peerId << " already there";
std::cerr << std::endl;
#endif
}
return true;
return false;
}
}
bool ftTransferModule::removeFileSource(const std::string& peerId)