mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
merged branch 0.5.0 commits 2576, 2579, 2581-2583 into trunk
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2592 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
294f4207ed
commit
b000245ef5
14 changed files with 201 additions and 247 deletions
|
@ -57,6 +57,7 @@
|
|||
* #define CONTROL_DEBUG 1
|
||||
* #define DEBUG_DWLQUEUE 1
|
||||
*****/
|
||||
#define DEBUG_DWLQUEUE 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
|
||||
|
@ -410,16 +411,23 @@ void ftController::checkDownloadQueue()
|
|||
// Check for inactive transfers.
|
||||
//
|
||||
time_t now = time(NULL) ;
|
||||
uint32_t nb_moved = 0 ; // don't move more files than the size of the queue.
|
||||
|
||||
for(std::map<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||
for(std::map<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end() && nb_moved <= _max_active_downloads;++it)
|
||||
if( it->second->mState != ftFileControl::QUEUED
|
||||
&& it->second->mState != ftFileControl::PAUSED
|
||||
&& now - it->second->mCreator->lastRecvTimeStamp() > (time_t)MAX_TIME_INACTIVE_REQUEUED)
|
||||
&& now > it->second->mCreator->lastRecvTimeStamp() + (time_t)MAX_TIME_INACTIVE_REQUEUED)
|
||||
{
|
||||
#ifdef DEBUG_DWLQUEUE
|
||||
std::cerr << " - Inactive file " << it->second->mName << " at position " << it->second->mQueuePosition << " moved to end of the queue. mState=" << it->second->mState << ", time lapse=" << now - it->second->mCreator->lastRecvTimeStamp() << std::endl ;
|
||||
#endif
|
||||
locked_bottomQueue(it->second->mQueuePosition) ;
|
||||
#ifdef DEBUG_DWLQUEUE
|
||||
std::cerr << " - Inactive file " << it->second->mName << " moved to end of the queue" << std::endl ;
|
||||
std::cerr << " new position: " << it->second->mQueuePosition << std::endl ;
|
||||
std::cerr << " new state: " << it->second->mState << std::endl ;
|
||||
#endif
|
||||
it->second->mCreator->resetRecvTimeStamp() ; // very important!
|
||||
++nb_moved ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,7 +462,8 @@ void ftController::setQueueSize(uint32_t s)
|
|||
std::cerr << "Settign new queue size to " << s << std::endl ;
|
||||
#endif
|
||||
for(uint32_t p=std::min(s,old_s);p<=std::max(s,old_s);++p)
|
||||
locked_checkQueueElement(p);
|
||||
if(p < _queue.size())
|
||||
locked_checkQueueElement(p);
|
||||
}
|
||||
else
|
||||
std::cerr << "ftController::setQueueSize(): cannot set queue to size " << s << std::endl ;
|
||||
|
@ -540,11 +549,6 @@ void ftController::locked_swapQueue(uint32_t pos1,uint32_t pos2)
|
|||
locked_checkQueueElement(pos2) ;
|
||||
}
|
||||
|
||||
//void ftController::checkQueueElements()
|
||||
//{
|
||||
// for(uint32_t pos=0;pos<_queue.size();++pos)
|
||||
// checkQueueElement(pos) ;
|
||||
//}
|
||||
void ftController::locked_checkQueueElement(uint32_t pos)
|
||||
{
|
||||
_queue[pos]->mQueuePosition = pos ;
|
||||
|
@ -1147,6 +1151,8 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||
ftFileCreator *fc = new ftFileCreator(savepath, size, hash);
|
||||
ftTransferModule *tm = new ftTransferModule(fc, mDataplex,this);
|
||||
|
||||
fc->setChunkStrategy(mDefaultChunkStrategy) ;
|
||||
|
||||
/* add into maps */
|
||||
ftFileControl *ftfc = new ftFileControl(fname, savepath, destination, size, hash, flags, fc, tm, callbackCode);
|
||||
ftfc->mCreateTime = time(NULL);
|
||||
|
@ -1726,6 +1732,7 @@ bool ftController::CancelCacheFile(RsPeerId id, std::string path, std::string ha
|
|||
const std::string download_dir_ss("DOWN_DIR");
|
||||
const std::string partial_dir_ss("PART_DIR");
|
||||
const std::string share_dwl_dir("SHARE_DWL_DIR");
|
||||
const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY");
|
||||
|
||||
|
||||
/* p3Config Interface */
|
||||
|
@ -1757,6 +1764,7 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
|
|||
configMap[download_dir_ss] = getDownloadDirectory();
|
||||
configMap[partial_dir_ss] = getPartialsDirectory();
|
||||
configMap[share_dwl_dir] = mShareDownloadDir ? "YES" : "NO";
|
||||
configMap[default_chunk_strategy_ss] = (mDefaultChunkStrategy==FileChunksInfo::CHUNK_STRATEGY_STREAMING) ? "STREAMING" : "RANDOM";
|
||||
|
||||
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
|
||||
|
||||
|
@ -1940,15 +1948,39 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
|
|||
}
|
||||
}
|
||||
|
||||
if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss)))
|
||||
{
|
||||
if(mit->second == "STREAMING")
|
||||
setDefaultChunkStrategy(FileChunksInfo::CHUNK_STRATEGY_STREAMING) ;
|
||||
else if(mit->second == "RANDOM")
|
||||
setDefaultChunkStrategy(FileChunksInfo::CHUNK_STRATEGY_RANDOM) ;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FileChunksInfo::ChunkStrategy ftController::defaultChunkStrategy()
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
return mDefaultChunkStrategy ;
|
||||
}
|
||||
void ftController::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy S)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
mDefaultChunkStrategy = S ;
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
|
||||
void ftController::setShareDownloadDirectory(bool value)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
mShareDownloadDir = value;
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
|
||||
bool ftController::getShareDownloadDirectory()
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
return mShareDownloadDir;
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,8 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
bool alreadyHaveFile(const std::string& hash) ;
|
||||
|
||||
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
||||
void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s);
|
||||
FileChunksInfo::ChunkStrategy defaultChunkStrategy();
|
||||
|
||||
bool FileCancel(std::string hash);
|
||||
bool FileControl(std::string hash, uint32_t flags);
|
||||
|
@ -265,6 +267,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||
|
||||
/* share incoming directory */
|
||||
bool mShareDownloadDir;
|
||||
FileChunksInfo::ChunkStrategy mDefaultChunkStrategy ;
|
||||
|
||||
uint32_t _max_active_downloads ; // maximum number of simultaneous downloads
|
||||
};
|
||||
|
|
|
@ -58,6 +58,11 @@ time_t ftFileCreator::lastRecvTimeStamp()
|
|||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
return _last_recv_time_t ;
|
||||
}
|
||||
void ftFileCreator::resetRecvTimeStamp()
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
_last_recv_time_t = time(NULL) ;
|
||||
}
|
||||
|
||||
void ftFileCreator::closeFile()
|
||||
{
|
||||
|
|
|
@ -76,8 +76,9 @@ class ftFileCreator: public ftFileProvider
|
|||
// removes the designated file source from the chunkmap.
|
||||
void removeFileSource(const std::string& peer_id) ;
|
||||
|
||||
// Returns the time stamp of the last data receive.
|
||||
// Returns resets the time stamp of the last data receive.
|
||||
time_t lastRecvTimeStamp() ;
|
||||
void resetRecvTimeStamp() ;
|
||||
|
||||
// actually store data in the file, and update chunks info
|
||||
//
|
||||
|
|
|
@ -272,6 +272,14 @@ bool ftServer::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStr
|
|||
{
|
||||
return mFtController->setChunkStrategy(hash,s);
|
||||
}
|
||||
void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy)
|
||||
{
|
||||
mFtController->defaultChunkStrategy() ;
|
||||
}
|
||||
FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy()
|
||||
{
|
||||
return mFtController->defaultChunkStrategy() ;
|
||||
}
|
||||
|
||||
bool ftServer::FileCancel(std::string hash)
|
||||
{
|
||||
|
|
|
@ -125,6 +125,9 @@ virtual bool FileCancel(std::string hash);
|
|||
virtual bool FileControl(std::string hash, uint32_t flags);
|
||||
virtual bool FileClearCompleted();
|
||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s) ;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) ;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ;
|
||||
|
||||
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
|
|
|
@ -113,6 +113,8 @@ class RsFiles
|
|||
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list<std::string> srcIds) = 0;
|
||||
virtual bool FileCancel(std::string hash) = 0;
|
||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
||||
virtual void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy) = 0;
|
||||
virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() = 0;
|
||||
virtual bool FileControl(std::string hash, uint32_t flags) = 0;
|
||||
virtual bool FileClearCompleted() = 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue