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_END = 0 ;
static const int32_t FT_FILECONTROL_QUEUE_ADD_AFTER_CACHE = 1 ; 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() ftFileControl::ftFileControl()
:mTransfer(NULL), mCreator(NULL), :mTransfer(NULL), mCreator(NULL),
mState(DOWNLOADING), mSize(0), mFlags(0) mState(DOWNLOADING), mSize(0), mFlags(0)
@ -232,6 +235,7 @@ void ftController::run()
if(now > last_save_time + SAVE_TRANSFERS_DELAY) if(now > last_save_time + SAVE_TRANSFERS_DELAY)
{ {
cleanCacheDownloads() ; cleanCacheDownloads() ;
searchForDirectSources() ;
IndicateConfigChanged() ; IndicateConfigChanged() ;
last_save_time = now ; 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() void ftController::tickTransfers()
{ {
// 1 - sort modules into arrays according to priority // 1 - sort modules into arrays according to priority
@ -960,9 +981,6 @@ bool ftController::completeFile(std::string hash)
/********************** Controller Access **********************/ /********************** Controller Access **********************/
/***************************************************************/ /***************************************************************/
const uint32_t FT_CNTRL_STANDARD_RATE = 1024 * 1024;
const uint32_t FT_CNTRL_SLOW_RATE = 10 * 1024;
bool ftController::activate() bool ftController::activate()
{ {
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ 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); virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
void cleanCacheDownloads() ; void cleanCacheDownloads() ;
void searchForDirectSources() ;
void tickTransfers() ; void tickTransfers() ;
/***************************************************************/ /***************************************************************/

View File

@ -166,6 +166,7 @@ bool ftTransferModule::addFileSource(const std::string& peerId)
std::cerr << " adding peer: " << peerId << " to sourceList"; std::cerr << " adding peer: " << peerId << " to sourceList";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return true ;
} }
else else
@ -175,8 +176,8 @@ bool ftTransferModule::addFileSource(const std::string& peerId)
std::cerr << " peer: " << peerId << " already there"; std::cerr << " peer: " << peerId << " already there";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
return false;
} }
return true;
} }
bool ftTransferModule::removeFileSource(const std::string& peerId) bool ftTransferModule::removeFileSource(const std::string& peerId)