mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 16:09:35 -05:00
Added proper dl queue behavior
- suppressed old DwlQueue class - turned mDownloads into a list of pointers to allow easy cross-info update between queue and std::map of downloads - added queue functionality for moving files top/bottom/up/down - added the necessary functions in rsFiles Put back display of exact sizes in FileTransferInfoWidget Suppressed some warnings. **Warning**: this commit requires a make clean. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2493 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6c686496a9
commit
9e469d8baf
@ -56,13 +56,15 @@
|
|||||||
/******
|
/******
|
||||||
* #define CONTROL_DEBUG 1
|
* #define CONTROL_DEBUG 1
|
||||||
*****/
|
*****/
|
||||||
|
#define DEBUG_DWLQUEUE 1
|
||||||
|
|
||||||
static const uint32_t SAVE_TRANSFERS_DELAY = 61 ; // save transfer progress every 61 seconds.
|
static const uint32_t SAVE_TRANSFERS_DELAY = 61 ; // save transfer progress every 61 seconds.
|
||||||
static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // save transfer progress every 61 seconds.
|
static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // time after which an inactive chunk is released
|
||||||
|
static const uint32_t MAX_TIME_INACTIVE_REQUEUED = 60 ; // time after which an inactive ftFileControl is bt-queued
|
||||||
|
|
||||||
ftFileControl::ftFileControl()
|
ftFileControl::ftFileControl()
|
||||||
:mTransfer(NULL), mCreator(NULL),
|
:mTransfer(NULL), mCreator(NULL),
|
||||||
mState(0), mSize(0), mFlags(0),
|
mState(DOWNLOADING), mSize(0), mFlags(0),
|
||||||
mPriority(SPEED_NORMAL)
|
mPriority(SPEED_NORMAL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -73,7 +75,7 @@ ftFileControl::ftFileControl(std::string fname,
|
|||||||
uint64_t size, std::string hash, uint32_t flags,
|
uint64_t size, std::string hash, uint32_t flags,
|
||||||
ftFileCreator *fc, ftTransferModule *tm, uint32_t cb)
|
ftFileCreator *fc, ftTransferModule *tm, uint32_t cb)
|
||||||
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
||||||
mTransfer(tm), mCreator(fc), mState(0), mHash(hash),
|
mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash),
|
||||||
mSize(size), mFlags(flags), mDoCallback(false), mCallbackCode(cb),
|
mSize(size), mFlags(flags), mDoCallback(false), mCallbackCode(cb),
|
||||||
mPriority(SPEED_NORMAL) // default priority to normal
|
mPriority(SPEED_NORMAL) // default priority to normal
|
||||||
{
|
{
|
||||||
@ -91,6 +93,7 @@ ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string c
|
|||||||
mFtActive(false),
|
mFtActive(false),
|
||||||
mShareDownloadDir(true)
|
mShareDownloadDir(true)
|
||||||
{
|
{
|
||||||
|
_max_active_downloads = 5 ; // default queue size
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,12 +111,12 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator it = mDownloads.find(hash) ;
|
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash) ;
|
||||||
|
|
||||||
if(it != mDownloads.end())
|
if(it != mDownloads.end())
|
||||||
{
|
{
|
||||||
it->second.mCreator->getChunkMap(info) ;
|
it->second->mCreator->getChunkMap(info) ;
|
||||||
info.flags = it->second.mFlags ;
|
info.flags = it->second->mFlags ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
@ -124,11 +127,11 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun
|
|||||||
{
|
{
|
||||||
// This should rather be done as a static method of ChunkMap.
|
// This should rather be done as a static method of ChunkMap.
|
||||||
//
|
//
|
||||||
info.file_size = it->second.mSize ;
|
info.file_size = it->second->mSize ;
|
||||||
info.chunk_size = ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
|
info.chunk_size = ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
|
||||||
info.flags = it->second.mFlags ;
|
info.flags = it->second->mFlags ;
|
||||||
uint32_t nb_chunks = it->second.mSize/ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
|
uint32_t nb_chunks = it->second->mSize/ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
|
||||||
if(it->second.mSize % ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE != 0)
|
if(it->second->mSize % ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE != 0)
|
||||||
++nb_chunks ;
|
++nb_chunks ;
|
||||||
info.chunks.resize(nb_chunks,FileChunksInfo::CHUNK_DONE) ;
|
info.chunks.resize(nb_chunks,FileChunksInfo::CHUNK_DONE) ;
|
||||||
|
|
||||||
@ -142,8 +145,8 @@ void ftController::addFileSource(const std::string& hash,const std::string& peer
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator it;
|
std::map<std::string, ftFileControl*>::iterator it;
|
||||||
std::map<std::string, ftFileControl> currentDownloads = *(&mDownloads);
|
std::map<std::string, ftFileControl*> currentDownloads = *(&mDownloads);
|
||||||
|
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
||||||
@ -151,7 +154,7 @@ void ftController::addFileSource(const std::string& hash,const std::string& peer
|
|||||||
for(it = currentDownloads.begin(); it != currentDownloads.end(); it++)
|
for(it = currentDownloads.begin(); it != currentDownloads.end(); it++)
|
||||||
if(it->first == hash)
|
if(it->first == hash)
|
||||||
{
|
{
|
||||||
it->second.mTransfer->addFileSource(peer_id);
|
it->second->mTransfer->addFileSource(peer_id);
|
||||||
|
|
||||||
// setPeerState(it->second.mTransfer, peer_id, rate, mConnMgr->isOnline(peer_id));
|
// setPeerState(it->second.mTransfer, peer_id, rate, mConnMgr->isOnline(peer_id));
|
||||||
|
|
||||||
@ -168,8 +171,8 @@ void ftController::removeFileSource(const std::string& hash,const std::string& p
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator it;
|
std::map<std::string, ftFileControl*>::iterator it;
|
||||||
std::map<std::string, ftFileControl> currentDownloads = *(&mDownloads);
|
std::map<std::string, ftFileControl*> currentDownloads = *(&mDownloads);
|
||||||
|
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
std::cerr << "ftController: Adding source " << peer_id << " to current download hash=" << hash ;
|
||||||
@ -177,7 +180,7 @@ void ftController::removeFileSource(const std::string& hash,const std::string& p
|
|||||||
for(it = currentDownloads.begin(); it != currentDownloads.end(); it++)
|
for(it = currentDownloads.begin(); it != currentDownloads.end(); it++)
|
||||||
if(it->first == hash)
|
if(it->first == hash)
|
||||||
{
|
{
|
||||||
it->second.mTransfer->removeFileSource(peer_id);
|
it->second->mTransfer->removeFileSource(peer_id);
|
||||||
|
|
||||||
// setPeerState(it->second.mTransfer, peer_id, rate, mConnMgr->isOnline(peer_id));
|
// setPeerState(it->second.mTransfer, peer_id, rate, mConnMgr->isOnline(peer_id));
|
||||||
|
|
||||||
@ -194,6 +197,8 @@ void ftController::run()
|
|||||||
{
|
{
|
||||||
|
|
||||||
/* check the queues */
|
/* check the queues */
|
||||||
|
uint32_t cnt = 0 ;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -225,8 +230,8 @@ void ftController::run()
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
for(std::map<std::string,ftFileControl>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||||
it->second.mCreator->removeInactiveChunks() ;
|
it->second->mCreator->removeInactiveChunks() ;
|
||||||
|
|
||||||
last_clean_time = now ;
|
last_clean_time = now ;
|
||||||
}
|
}
|
||||||
@ -250,6 +255,9 @@ void ftController::run()
|
|||||||
|
|
||||||
mDone.clear();
|
mDone.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(cnt++ % 10 == 0)
|
||||||
|
checkDownloadQueue() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -258,34 +266,30 @@ void ftController::tickTransfers()
|
|||||||
{
|
{
|
||||||
// 1 - sort modules into arrays according to priority
|
// 1 - sort modules into arrays according to priority
|
||||||
|
|
||||||
// if(mPrioritiesChanged)
|
|
||||||
|
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ticking transfers." << std::endl ;
|
std::cerr << "ticking transfers." << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
mPriorityTab = std::vector<std::vector<ftTransferModule*> >(3,std::vector<ftTransferModule*>()) ;
|
std::vector<std::vector<ftTransferModule*> >priority_tab (3,std::vector<ftTransferModule*>()) ;
|
||||||
|
|
||||||
for(std::map<std::string,ftFileControl>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
// Collect all non queued files.
|
||||||
mPriorityTab[it->second.mPriority].push_back(it->second.mTransfer) ;
|
//
|
||||||
|
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin()); it != mDownloads.end(); it++)
|
||||||
|
if(it->second->mState != ftFileControl::QUEUED)
|
||||||
|
priority_tab[it->second->mPriority].push_back(it->second->mTransfer) ;
|
||||||
|
|
||||||
// 2 - tick arrays with a probability proportional to priority
|
// 2 - tick arrays with a probability proportional to priority
|
||||||
|
|
||||||
// 2.1 - decide based on probability, which category of files we handle.
|
// 2.1 - decide based on probability, which category of files we handle.
|
||||||
|
|
||||||
// static const float HIGH_PRIORITY_PROB = 0.60 ;
|
#ifdef CONTROL_DEBUG
|
||||||
// static const float NORMAL_PRIORITY_PROB = 0.25 ;
|
|
||||||
// static const float LOW_PRIORITY_PROB = 0.15 ;
|
|
||||||
// static const float SUSP_PRIORITY_PROB = 0.00 ;
|
|
||||||
|
|
||||||
#ifdef CONTROL_DEBUG
|
|
||||||
std::cerr << "Priority tabs: " ;
|
std::cerr << "Priority tabs: " ;
|
||||||
std::cerr << "Low (" << mPriorityTab[SPEED_LOW ].size() << ") " ;
|
std::cerr << "Low (" << priority_tab[SPEED_LOW ].size() << ") " ;
|
||||||
std::cerr << "Normal (" << mPriorityTab[SPEED_NORMAL].size() << ") " ;
|
std::cerr << "Normal (" << priority_tab[SPEED_NORMAL].size() << ") " ;
|
||||||
std::cerr << "High (" << mPriorityTab[SPEED_HIGH ].size() << ") " ;
|
std::cerr << "High (" << priority_tab[SPEED_HIGH ].size() << ") " ;
|
||||||
std::cerr << std::endl ;
|
std::cerr << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* tick the transferModules */
|
/* tick the transferModules */
|
||||||
|
|
||||||
@ -293,12 +297,12 @@ void ftController::tickTransfers()
|
|||||||
//
|
//
|
||||||
|
|
||||||
for(int chosen=2;chosen>=0;--chosen)
|
for(int chosen=2;chosen>=0;--chosen)
|
||||||
if(!mPriorityTab[chosen].empty())
|
if(!priority_tab[chosen].empty())
|
||||||
{
|
{
|
||||||
int start = rand() % mPriorityTab[chosen].size() ;
|
int start = rand() % priority_tab[chosen].size() ;
|
||||||
|
|
||||||
for(int i=0;i<(int)mPriorityTab[chosen].size();++i)
|
for(int i=0;i<(int)priority_tab[chosen].size();++i)
|
||||||
mPriorityTab[chosen][(i+start)%(int)mPriorityTab[chosen].size()]->tick() ;
|
priority_tab[chosen][(i+start)%(int)priority_tab[chosen].size()]->tick() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,11 +310,11 @@ bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string,ftFileControl>::iterator it(mDownloads.find(hash)) ;
|
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||||
|
|
||||||
if(it != mDownloads.end())
|
if(it != mDownloads.end())
|
||||||
{
|
{
|
||||||
p = it->second.mPriority ;
|
p = it->second->mPriority ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -320,10 +324,10 @@ void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string,ftFileControl>::iterator it(mDownloads.find(hash)) ;
|
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||||
|
|
||||||
if(it != mDownloads.end())
|
if(it != mDownloads.end())
|
||||||
it->second.mPriority = p ;
|
it->second->mPriority = p ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftController::cleanCacheDownloads()
|
void ftController::cleanCacheDownloads()
|
||||||
@ -333,20 +337,20 @@ void ftController::cleanCacheDownloads()
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
for(std::map<std::string,ftFileControl>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||||
if ((it->second).mFlags & RS_FILE_HINTS_CACHE) //check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER
|
if ((it->second)->mFlags & RS_FILE_HINTS_CACHE) //check if a cache file is downloaded, if the case, timeout the transfer after TIMOUT_CACHE_FILE_TRANSFER
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController::run() cache transfer found. age of this tranfer is :" << (int)(time(NULL) - (it->second).mCreateTime);
|
std::cerr << "ftController::run() cache transfer found. age of this tranfer is :" << (int)(time(NULL) - (it->second)->mCreateTime);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if ((time(NULL) - (it->second).mCreateTime) > TIMOUT_CACHE_FILE_TRANSFER)
|
if ((time(NULL) - (it->second)->mCreateTime) > TIMOUT_CACHE_FILE_TRANSFER)
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController::run() cache transfer to old. Cancelling transfer. Hash :" << (it->second).mHash << ", time=" << (it->second).mCreateTime << ", now = " << time(NULL) ;
|
std::cerr << "ftController::run() cache transfer to old. Cancelling transfer. Hash :" << (it->second)->mHash << ", time=" << (it->second)->mCreateTime << ", now = " << time(NULL) ;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
toCancel.push_back((it->second).mHash);
|
toCancel.push_back((it->second)->mHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,9 +362,200 @@ void ftController::cleanCacheDownloads()
|
|||||||
/* Called every 10 seconds or so */
|
/* Called every 10 seconds or so */
|
||||||
void ftController::checkDownloadQueue()
|
void ftController::checkDownloadQueue()
|
||||||
{
|
{
|
||||||
/* */
|
// We do multiple things here:
|
||||||
|
//
|
||||||
|
// 1 - are there queued files ?
|
||||||
|
// YES
|
||||||
|
// 1.1 - check for inactive files (see below).
|
||||||
|
// - select one inactive file
|
||||||
|
// - close it temporarily
|
||||||
|
// - remove it from turtle handling
|
||||||
|
// - move the ftFileControl to queued list
|
||||||
|
// - set the queue priority to 1+largest in the queue.
|
||||||
|
// 1.2 - pop from the queue the 1st file to come (according to priority)
|
||||||
|
// - enable turtle router handling for this hash
|
||||||
|
// - reset counters
|
||||||
|
// - set the file as waiting
|
||||||
|
// NO
|
||||||
|
// Do nothing, because no files are waiting.
|
||||||
|
//
|
||||||
|
// 2 - in FileRequest, if the max number of downloaded files is exceeded, put the
|
||||||
|
// file in the queue list, and don't enable the turtle router handling.
|
||||||
|
//
|
||||||
|
// Implementation:
|
||||||
|
// - locate a hash in the queue
|
||||||
|
// - move hashes in the queue up/down/top/bottom
|
||||||
|
// - now the place of each ftFileControl element in the queue to activate/desactive them
|
||||||
|
//
|
||||||
|
// So:
|
||||||
|
// - change mDownloads to be a std::map<hash,ftFileControl*>
|
||||||
|
// - sort the ftFileControl* into a std::vector
|
||||||
|
// - store the queue position of each ftFileControl* into its own structure (mQueuePosition member)
|
||||||
|
//
|
||||||
|
// We don't want the turtle router to keep openning tunnels for queued files, so we only base
|
||||||
|
// the notion of inactive on the fact that no traffic happens for the file within 5 mins.
|
||||||
|
//
|
||||||
|
// How do we detect inactive files?
|
||||||
|
// For a downld file: - no traffic for 5 min.
|
||||||
|
|
||||||
|
RsStackMutex mtx(ctrlMutex) ;
|
||||||
|
|
||||||
|
#ifdef DEBUG_DWLQUEUE
|
||||||
|
std::cerr << "Checking download queue." << std::endl ;
|
||||||
|
#endif
|
||||||
|
if(mDownloads.size() <= _max_active_downloads)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
// Check for inactive transfers.
|
||||||
|
//
|
||||||
|
time_t now = time(NULL) ;
|
||||||
|
|
||||||
|
for(std::map<std::string,ftFileControl*>::const_iterator it(mDownloads.begin());it!=mDownloads.end();++it)
|
||||||
|
if(it->second->mState != ftFileControl::QUEUED && now - it->second->mCreator->lastRecvTimeStamp() > (time_t)MAX_TIME_INACTIVE_REQUEUED)
|
||||||
|
{
|
||||||
|
locked_bottomQueue(it->second->mQueuePosition) ;
|
||||||
|
#ifdef DEBUG_DWLQUEUE
|
||||||
|
std::cerr << " - Inactive file " << it->second->mName << " moved to end of the queue" << std::endl ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftController::locked_addToQueue(ftFileControl* ftfc)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_DWLQUEUE
|
||||||
|
std::cerr << "Queueing ftfileControl " << (void*)ftfc << ", name=" << ftfc->mName << std::endl ;
|
||||||
|
#endif
|
||||||
|
_queue.push_back(ftfc) ;
|
||||||
|
locked_checkQueueElement(_queue.size()-1) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftController::locked_queueRemove(uint32_t pos)
|
||||||
|
{
|
||||||
|
for(uint32_t p=pos;p<_queue.size()-1;++p)
|
||||||
|
{
|
||||||
|
_queue[p]=_queue[p+1] ;
|
||||||
|
locked_checkQueueElement(p) ;
|
||||||
|
}
|
||||||
|
_queue.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftController::setQueueSize(uint32_t s)
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(ctrlMutex) ;
|
||||||
|
|
||||||
|
if(s > 0)
|
||||||
|
{
|
||||||
|
uint32_t old_s = _max_active_downloads ;
|
||||||
|
_max_active_downloads = s ;
|
||||||
|
#ifdef DEBUG_DWLQUEUE
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cerr << "ftController::setQueueSize(): cannot set queue to size " << s << std::endl ;
|
||||||
|
}
|
||||||
|
uint32_t ftController::getQueueSize()
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(ctrlMutex) ;
|
||||||
|
return _max_active_downloads ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftController::moveInQueue(const std::string& hash,QueueMove mv)
|
||||||
|
{
|
||||||
|
RsStackMutex mtx(ctrlMutex) ;
|
||||||
|
|
||||||
|
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
|
||||||
|
|
||||||
|
if(it == mDownloads.end())
|
||||||
|
{
|
||||||
|
std::cerr << "ftController::moveInQueue: can't find hash " << hash << " in the download list." << std::endl ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
uint32_t pos = it->second->mQueuePosition ;
|
||||||
|
|
||||||
|
#ifdef DEBUG_DWLQUEUE
|
||||||
|
std::cerr << "Moving file " << hash << ", pos=" << pos << " to new pos." << std::endl ;
|
||||||
|
#endif
|
||||||
|
switch(mv)
|
||||||
|
{
|
||||||
|
case QUEUE_TOP: locked_topQueue(pos) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case QUEUE_BOTTOM: locked_bottomQueue(pos) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case QUEUE_UP: if(pos > 0)
|
||||||
|
locked_swapQueue(pos,pos-1) ;
|
||||||
|
break ;
|
||||||
|
|
||||||
|
case QUEUE_DOWN: if(pos < _queue.size()-1)
|
||||||
|
locked_swapQueue(pos,pos+1) ;
|
||||||
|
break ;
|
||||||
|
default:
|
||||||
|
std::cerr << "ftController::moveInQueue: unknown move " << mv << std::endl ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftController::locked_topQueue(uint32_t pos)
|
||||||
|
{
|
||||||
|
ftFileControl *tmp=_queue[pos] ;
|
||||||
|
|
||||||
|
for(int p=pos;p>0;--p)
|
||||||
|
{
|
||||||
|
_queue[p]=_queue[p-1] ;
|
||||||
|
locked_checkQueueElement(p) ;
|
||||||
|
}
|
||||||
|
_queue[0]=tmp ;
|
||||||
|
locked_checkQueueElement(0) ;
|
||||||
|
}
|
||||||
|
void ftController::locked_bottomQueue(uint32_t pos)
|
||||||
|
{
|
||||||
|
ftFileControl *tmp=_queue[pos] ;
|
||||||
|
|
||||||
|
for(uint32_t p=pos;p<_queue.size()-1;++p)
|
||||||
|
{
|
||||||
|
_queue[p]=_queue[p+1] ;
|
||||||
|
locked_checkQueueElement(p) ;
|
||||||
|
}
|
||||||
|
_queue[_queue.size()-1]=tmp ;
|
||||||
|
locked_checkQueueElement(_queue.size()-1) ;
|
||||||
|
}
|
||||||
|
void ftController::locked_swapQueue(uint32_t pos1,uint32_t pos2)
|
||||||
|
{
|
||||||
|
// Swap the element at position pos with the last element of the queue
|
||||||
|
|
||||||
|
if(pos1==pos2)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
ftFileControl *tmp = _queue[pos1] ;
|
||||||
|
_queue[pos1] = _queue[pos2] ;
|
||||||
|
_queue[pos2] = tmp;
|
||||||
|
|
||||||
|
locked_checkQueueElement(pos1) ;
|
||||||
|
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 ;
|
||||||
|
|
||||||
|
if(pos < _max_active_downloads)
|
||||||
|
{
|
||||||
|
_queue[pos]->mState = ftFileControl::DOWNLOADING ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED)
|
||||||
|
{
|
||||||
|
_queue[pos]->mState = ftFileControl::QUEUED ;
|
||||||
|
_queue[pos]->mCreator->closeFile() ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftController::FlagFileComplete(std::string hash)
|
bool ftController::FlagFileComplete(std::string hash)
|
||||||
@ -472,8 +667,8 @@ bool ftController::completeFile(std::string hash)
|
|||||||
std::cerr << "ftController:completeFile(" << hash << ")";
|
std::cerr << "ftController:completeFile(" << hash << ")";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
std::map<std::string, ftFileControl>::iterator it;
|
std::map<std::string, ftFileControl*>::iterator it(mDownloads.find(hash));
|
||||||
it = mDownloads.find(hash);
|
|
||||||
if (it == mDownloads.end())
|
if (it == mDownloads.end())
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
@ -485,7 +680,7 @@ bool ftController::completeFile(std::string hash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if finished */
|
/* check if finished */
|
||||||
if (!(it->second).mCreator->finished())
|
if (!(it->second)->mCreator->finished())
|
||||||
{
|
{
|
||||||
/* not done! */
|
/* not done! */
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
@ -494,15 +689,15 @@ bool ftController::completeFile(std::string hash)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
std::cerr << "FileSize: ";
|
std::cerr << "FileSize: ";
|
||||||
std::cerr << (it->second).mCreator->getFileSize();
|
std::cerr << (it->second)->mCreator->getFileSize();
|
||||||
std::cerr << " and Recvd: ";
|
std::cerr << " and Recvd: ";
|
||||||
std::cerr << (it->second).mCreator->getRecvd();
|
std::cerr << (it->second)->mCreator->getRecvd();
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ftFileControl *fc = &(it->second);
|
ftFileControl *fc = it->second;
|
||||||
|
|
||||||
// (csoler) I've postponed this to the end of the block because deleting the
|
// (csoler) I've postponed this to the end of the block because deleting the
|
||||||
// element from the map calls the destructor of fc->mTransfer, which
|
// element from the map calls the destructor of fc->mTransfer, which
|
||||||
@ -537,10 +732,6 @@ bool ftController::completeFile(std::string hash)
|
|||||||
else
|
else
|
||||||
fc->mState = ftFileControl::ERROR_COMPLETION;
|
fc->mState = ftFileControl::ERROR_COMPLETION;
|
||||||
|
|
||||||
/* switch map */
|
|
||||||
if (!(fc->mFlags & RS_FILE_HINTS_CACHE)) /* clean up completed cache files automatically */
|
|
||||||
mCompleted[fc->mHash] = *fc;
|
|
||||||
|
|
||||||
/* for extralist additions */
|
/* for extralist additions */
|
||||||
path = fc->mDestination;
|
path = fc->mDestination;
|
||||||
//hash = fc->mHash;
|
//hash = fc->mHash;
|
||||||
@ -558,6 +749,15 @@ bool ftController::completeFile(std::string hash)
|
|||||||
|
|
||||||
mDataplex->removeTransferModule(hash_to_suppress) ;
|
mDataplex->removeTransferModule(hash_to_suppress) ;
|
||||||
uint32_t flgs = fc->mFlags ;
|
uint32_t flgs = fc->mFlags ;
|
||||||
|
|
||||||
|
locked_queueRemove(it->second->mQueuePosition) ;
|
||||||
|
|
||||||
|
/* switch map */
|
||||||
|
if (!(fc->mFlags & RS_FILE_HINTS_CACHE)) /* clean up completed cache files automatically */
|
||||||
|
mCompleted[fc->mHash] = fc;
|
||||||
|
else
|
||||||
|
delete fc ;
|
||||||
|
|
||||||
mDownloads.erase(it);
|
mDownloads.erase(it);
|
||||||
|
|
||||||
if(flgs & RS_FILE_HINTS_NETWORK_WIDE)
|
if(flgs & RS_FILE_HINTS_NETWORK_WIDE)
|
||||||
@ -679,9 +879,9 @@ bool ftController::handleAPendingRequest()
|
|||||||
if(it != mPendingChunkMaps.end())
|
if(it != mPendingChunkMaps.end())
|
||||||
{
|
{
|
||||||
RsFileTransfer *rsft = it->second ;
|
RsFileTransfer *rsft = it->second ;
|
||||||
std::map<std::string, ftFileControl>::iterator fit = mDownloads.find(rsft->file.hash);
|
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||||
|
|
||||||
if((fit==mDownloads.end() || (fit->second).mCreator == NULL))
|
if((fit==mDownloads.end() || (fit->second)->mCreator == NULL))
|
||||||
{
|
{
|
||||||
// This should never happen, because the last call to FileRequest must have created the fileCreator!!
|
// This should never happen, because the last call to FileRequest must have created the fileCreator!!
|
||||||
//
|
//
|
||||||
@ -689,8 +889,8 @@ bool ftController::handleAPendingRequest()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(fit->second).mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
|
(fit->second)->mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
|
||||||
(fit->second).mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
|
(fit->second)->mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete rsft ;
|
delete rsft ;
|
||||||
@ -720,6 +920,27 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
uint64_t size, std::string dest, uint32_t flags,
|
uint64_t size, std::string dest, uint32_t flags,
|
||||||
std::list<std::string> &srcIds)
|
std::list<std::string> &srcIds)
|
||||||
{
|
{
|
||||||
|
if(size == 0) // we treat this special case because
|
||||||
|
{
|
||||||
|
/* if no destpath - send to download directory */
|
||||||
|
std::string destination ;
|
||||||
|
|
||||||
|
if (dest == "")
|
||||||
|
destination = mDownloadPath + "/" + fname;
|
||||||
|
else
|
||||||
|
destination = dest + "/" + fname;
|
||||||
|
|
||||||
|
// create void file with the target name.
|
||||||
|
FILE *f = fopen(destination.c_str(),"w") ;
|
||||||
|
|
||||||
|
if(f == NULL)
|
||||||
|
std::cerr << "Could not open file " << destination << " for writting." << std::endl ;
|
||||||
|
else
|
||||||
|
fclose(f) ;
|
||||||
|
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
/* If file transfer is not enabled ....
|
/* If file transfer is not enabled ....
|
||||||
* save request for later. This will also
|
* save request for later. This will also
|
||||||
* mean that we will have to copy local files,
|
* mean that we will have to copy local files,
|
||||||
@ -773,8 +994,8 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator dit;
|
std::map<std::string, ftFileControl*>::iterator dit = mDownloads.find(hash);
|
||||||
dit = mDownloads.find(hash);
|
|
||||||
if (dit != mDownloads.end())
|
if (dit != mDownloads.end())
|
||||||
{
|
{
|
||||||
/* we already have it! */
|
/* we already have it! */
|
||||||
@ -792,7 +1013,7 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
for(it = srcIds.begin(); it != srcIds.end(); it++)
|
for(it = srcIds.begin(); it != srcIds.end(); it++)
|
||||||
{
|
{
|
||||||
uint32_t i, j;
|
uint32_t i, j;
|
||||||
if ((dit->second).mTransfer->getPeerState(*it, i, j))
|
if ((dit->second)->mTransfer->getPeerState(*it, i, j))
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController::FileRequest() Peer Existing";
|
std::cerr << "ftController::FileRequest() Peer Existing";
|
||||||
@ -805,9 +1026,8 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
std::cerr << "ftController::FileRequest() Adding Peer: " << *it;
|
std::cerr << "ftController::FileRequest() Adding Peer: " << *it;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
(dit->second).mTransfer->addFileSource(*it);
|
(dit->second)->mTransfer->addFileSource(*it);
|
||||||
setPeerState(dit->second.mTransfer, *it,
|
setPeerState(dit->second->mTransfer, *it, rate, mConnMgr->isOnline(*it));
|
||||||
rate, mConnMgr->isOnline(*it));
|
|
||||||
|
|
||||||
IndicateConfigChanged(); /* new peer for transfer -> save */
|
IndicateConfigChanged(); /* new peer for transfer -> save */
|
||||||
}
|
}
|
||||||
@ -904,9 +1124,7 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
|
|
||||||
/* if no destpath - send to download directory */
|
/* if no destpath - send to download directory */
|
||||||
if (dest == "")
|
if (dest == "")
|
||||||
{
|
|
||||||
destination = mDownloadPath + "/" + fname;
|
destination = mDownloadPath + "/" + fname;
|
||||||
}
|
|
||||||
} /******* UNLOCKED ********/
|
} /******* UNLOCKED ********/
|
||||||
|
|
||||||
// We check that flags are consistent. In particular, for know
|
// We check that flags are consistent. In particular, for know
|
||||||
@ -916,12 +1134,14 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
if(flags & RS_FILE_HINTS_NETWORK_WIDE)
|
if(flags & RS_FILE_HINTS_NETWORK_WIDE)
|
||||||
mTurtle->monitorFileTunnels(fname,hash,size) ;
|
mTurtle->monitorFileTunnels(fname,hash,size) ;
|
||||||
|
|
||||||
ftFileCreator *fc = new ftFileCreator(savepath, size, hash, 0);
|
ftFileCreator *fc = new ftFileCreator(savepath, size, hash);
|
||||||
ftTransferModule *tm = new ftTransferModule(fc, mDataplex,this);
|
ftTransferModule *tm = new ftTransferModule(fc, mDataplex,this);
|
||||||
|
|
||||||
/* add into maps */
|
/* add into maps */
|
||||||
ftFileControl ftfc(fname, savepath, destination, size, hash, flags, fc, tm, callbackCode);
|
ftFileControl *ftfc = new ftFileControl(fname, savepath, destination, size, hash, flags, fc, tm, callbackCode);
|
||||||
ftfc.mCreateTime = time(NULL);
|
ftfc->mCreateTime = time(NULL);
|
||||||
|
|
||||||
|
locked_addToQueue(ftfc) ;
|
||||||
|
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController::FileRequest() Created ftFileCreator @: " << fc;
|
std::cerr << "ftController::FileRequest() Created ftFileCreator @: " << fc;
|
||||||
@ -951,8 +1171,6 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
|||||||
|
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
mDownloads[hash] = ftfc;
|
mDownloads[hash] = ftfc;
|
||||||
mSlowQueue.push_back(hash);
|
|
||||||
|
|
||||||
|
|
||||||
IndicateConfigChanged(); /* completed transfer -> save */
|
IndicateConfigChanged(); /* completed transfer -> save */
|
||||||
return true;
|
return true;
|
||||||
@ -992,8 +1210,7 @@ bool ftController::setPeerState(ftTransferModule *tm, std::string id, uint32_t
|
|||||||
|
|
||||||
bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s)
|
bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s)
|
||||||
{
|
{
|
||||||
std::map<std::string,ftFileControl>::iterator mit;
|
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||||
mit=mDownloads.find(hash);
|
|
||||||
if (mit==mDownloads.end())
|
if (mit==mDownloads.end())
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
@ -1002,7 +1219,7 @@ bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::Chun
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mit->second.mCreator->setChunkStrategy(s) ;
|
mit->second->mCreator->setChunkStrategy(s) ;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1018,8 +1235,7 @@ bool ftController::FileCancel(std::string hash)
|
|||||||
{
|
{
|
||||||
RsStackMutex mtx(ctrlMutex) ;
|
RsStackMutex mtx(ctrlMutex) ;
|
||||||
|
|
||||||
std::map<std::string,ftFileControl>::iterator mit;
|
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||||
mit=mDownloads.find(hash);
|
|
||||||
if (mit==mDownloads.end())
|
if (mit==mDownloads.end())
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
@ -1029,7 +1245,7 @@ bool ftController::FileCancel(std::string hash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if finished */
|
/* check if finished */
|
||||||
if ((mit->second).mCreator->finished())
|
if ((mit->second)->mCreator->finished())
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController:FileCancel(" << hash << ")";
|
std::cerr << "ftController:FileCancel(" << hash << ")";
|
||||||
@ -1037,18 +1253,18 @@ bool ftController::FileCancel(std::string hash)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
std::cerr << "FileSize: ";
|
std::cerr << "FileSize: ";
|
||||||
std::cerr << (mit->second).mCreator->getFileSize();
|
std::cerr << (mit->second)->mCreator->getFileSize();
|
||||||
std::cerr << " and Recvd: ";
|
std::cerr << " and Recvd: ";
|
||||||
std::cerr << (mit->second).mCreator->getRecvd();
|
std::cerr << (mit->second)->mCreator->getRecvd();
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*find the point to transfer module*/
|
/*find the point to transfer module*/
|
||||||
ftTransferModule* ft=(mit->second).mTransfer;
|
ftTransferModule* ft=(mit->second)->mTransfer;
|
||||||
ft->cancelTransfer();
|
ft->cancelTransfer();
|
||||||
|
|
||||||
ftFileControl *fc = &(mit->second);
|
ftFileControl *fc = mit->second;
|
||||||
mDataplex->removeTransferModule(fc->mTransfer->hash());
|
mDataplex->removeTransferModule(fc->mTransfer->hash());
|
||||||
|
|
||||||
if (fc->mTransfer)
|
if (fc->mTransfer)
|
||||||
@ -1081,6 +1297,8 @@ bool ftController::FileCancel(std::string hash)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locked_queueRemove(fc->mQueuePosition) ;
|
||||||
|
delete fc ;
|
||||||
mDownloads.erase(mit);
|
mDownloads.erase(mit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1095,8 +1313,7 @@ bool ftController::FileControl(std::string hash, uint32_t flags)
|
|||||||
std::cerr << flags << ")"<<std::endl;
|
std::cerr << flags << ")"<<std::endl;
|
||||||
#endif
|
#endif
|
||||||
/*check if the file in the download map*/
|
/*check if the file in the download map*/
|
||||||
std::map<std::string,ftFileControl>::iterator mit;
|
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
|
||||||
mit=mDownloads.find(hash);
|
|
||||||
if (mit==mDownloads.end())
|
if (mit==mDownloads.end())
|
||||||
{
|
{
|
||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
@ -1106,7 +1323,7 @@ bool ftController::FileControl(std::string hash, uint32_t flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*find the point to transfer module*/
|
/*find the point to transfer module*/
|
||||||
ftTransferModule* ft=(mit->second).mTransfer;
|
ftTransferModule* ft=(mit->second)->mTransfer;
|
||||||
switch (flags)
|
switch (flags)
|
||||||
{
|
{
|
||||||
case RS_FILE_CTRL_PAUSE:
|
case RS_FILE_CTRL_PAUSE:
|
||||||
@ -1126,7 +1343,13 @@ bool ftController::FileClearCompleted()
|
|||||||
#ifdef CONTROL_DEBUG
|
#ifdef CONTROL_DEBUG
|
||||||
std::cerr << "ftController::FileClearCompleted()" <<std::endl;
|
std::cerr << "ftController::FileClearCompleted()" <<std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
|
for(std::map<std::string, ftFileControl*>::iterator it(mCompleted.begin());it!=mCompleted.end();++it)
|
||||||
|
delete it->second ;
|
||||||
|
|
||||||
mCompleted.clear();
|
mCompleted.clear();
|
||||||
|
|
||||||
IndicateConfigChanged();
|
IndicateConfigChanged();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1137,14 +1360,14 @@ bool ftController::FileDownloads(std::list<std::string> &hashs)
|
|||||||
{
|
{
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator it;
|
std::map<std::string, ftFileControl*>::iterator it;
|
||||||
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
|
for(it = mDownloads.begin(); it != mDownloads.end(); it++)
|
||||||
{
|
{
|
||||||
hashs.push_back(it->second.mHash);
|
hashs.push_back(it->second->mHash);
|
||||||
}
|
}
|
||||||
for(it = mCompleted.begin(); it != mCompleted.end(); it++)
|
for(it = mCompleted.begin(); it != mCompleted.end(); it++)
|
||||||
{
|
{
|
||||||
hashs.push_back(it->second.mHash);
|
hashs.push_back(it->second->mHash);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1243,8 +1466,7 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
|
|||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
bool completed = false;
|
bool completed = false;
|
||||||
std::map<std::string, ftFileControl>::iterator it;
|
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
|
||||||
it = mDownloads.find(hash);
|
|
||||||
if (it == mDownloads.end())
|
if (it == mDownloads.end())
|
||||||
{
|
{
|
||||||
/* search completed files too */
|
/* search completed files too */
|
||||||
@ -1261,17 +1483,18 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
|
|||||||
|
|
||||||
/* extract details */
|
/* extract details */
|
||||||
info.hash = hash;
|
info.hash = hash;
|
||||||
info.fname = it->second.mName;
|
info.fname = it->second->mName;
|
||||||
info.flags = it->second.mFlags;
|
info.flags = it->second->mFlags;
|
||||||
info.path = RsDirUtil::removeTopDir(it->second.mDestination); /* remove fname */
|
info.path = RsDirUtil::removeTopDir(it->second->mDestination); /* remove fname */
|
||||||
info.priority = it->second.mPriority ;
|
info.priority = it->second->mPriority ;
|
||||||
|
info.queue_position = it->second->mQueuePosition ;
|
||||||
|
|
||||||
/* get list of sources from transferModule */
|
/* get list of sources from transferModule */
|
||||||
std::list<std::string> peerIds;
|
std::list<std::string> peerIds;
|
||||||
std::list<std::string>::iterator pit;
|
std::list<std::string>::iterator pit;
|
||||||
|
|
||||||
if (!completed)
|
if (!completed)
|
||||||
it->second.mTransfer->getFileSources(peerIds);
|
it->second->mTransfer->getFileSources(peerIds);
|
||||||
|
|
||||||
double totalRate = 0;
|
double totalRate = 0;
|
||||||
uint32_t tfRate = 0;
|
uint32_t tfRate = 0;
|
||||||
@ -1282,7 +1505,7 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
|
|||||||
|
|
||||||
for(pit = peerIds.begin(); pit != peerIds.end(); pit++)
|
for(pit = peerIds.begin(); pit != peerIds.end(); pit++)
|
||||||
{
|
{
|
||||||
if (it->second.mTransfer->getPeerState(*pit, state, tfRate))
|
if (it->second->mTransfer->getPeerState(*pit, state, tfRate))
|
||||||
{
|
{
|
||||||
TransferInfo ti;
|
TransferInfo ti;
|
||||||
switch(state)
|
switch(state)
|
||||||
@ -1314,7 +1537,7 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((completed) || ((it->second).mCreator->finished()))
|
if ((completed) || ((it->second)->mCreator->finished()))
|
||||||
{
|
{
|
||||||
info.downloadStatus = FT_STATE_COMPLETE;
|
info.downloadStatus = FT_STATE_COMPLETE;
|
||||||
}
|
}
|
||||||
@ -1330,8 +1553,12 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
|
|||||||
{
|
{
|
||||||
info.downloadStatus = FT_STATE_WAITING;
|
info.downloadStatus = FT_STATE_WAITING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(it->second->mState == ftFileControl::QUEUED)
|
||||||
|
info.downloadStatus = FT_STATE_QUEUED ;
|
||||||
|
|
||||||
info.tfRate = totalRate;
|
info.tfRate = totalRate;
|
||||||
info.size = (it->second).mSize;
|
info.size = (it->second)->mSize;
|
||||||
|
|
||||||
if (completed)
|
if (completed)
|
||||||
{
|
{
|
||||||
@ -1340,7 +1567,7 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
info.transfered = (it->second).mCreator->getRecvd();
|
info.transfered = (it->second)->mCreator->getRecvd();
|
||||||
info.avail = info.transfered;
|
info.avail = info.transfered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1364,7 +1591,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||||||
uint32_t rate = FT_CNTRL_STANDARD_RATE;
|
uint32_t rate = FT_CNTRL_STANDARD_RATE;
|
||||||
|
|
||||||
/* add online to all downloads */
|
/* add online to all downloads */
|
||||||
std::map<std::string, ftFileControl>::iterator it;
|
std::map<std::string, ftFileControl*>::iterator it;
|
||||||
std::list<pqipeer>::const_iterator pit;
|
std::list<pqipeer>::const_iterator pit;
|
||||||
|
|
||||||
std::list<pqipeer> vlist ;
|
std::list<pqipeer> vlist ;
|
||||||
@ -1393,7 +1620,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||||||
std::cerr << " is Newly Connected!";
|
std::cerr << " is Newly Connected!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
setPeerState(it->second.mTransfer, pit->id, rate, true);
|
setPeerState(it->second->mTransfer, pit->id, rate, true);
|
||||||
}
|
}
|
||||||
else if (pit->actions & RS_PEER_DISCONNECTED)
|
else if (pit->actions & RS_PEER_DISCONNECTED)
|
||||||
{
|
{
|
||||||
@ -1401,7 +1628,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||||||
std::cerr << " is Just disconnected!";
|
std::cerr << " is Just disconnected!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
setPeerState(it->second.mTransfer, pit->id, rate, false);
|
setPeerState(it->second->mTransfer, pit->id, rate, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1410,7 +1637,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||||||
std::cerr << pit-> actions;
|
std::cerr << pit-> actions;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
setPeerState(it->second.mTransfer, pit->id, rate, false);
|
setPeerState(it->second->mTransfer, pit->id, rate, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1427,7 +1654,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||||||
std::cerr << " is Newly Connected!";
|
std::cerr << " is Newly Connected!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
setPeerState(it->second.mTransfer, pit->id, rate, true);
|
setPeerState(it->second->mTransfer, pit->id, rate, true);
|
||||||
}
|
}
|
||||||
else if (pit->actions & RS_PEER_DISCONNECTED)
|
else if (pit->actions & RS_PEER_DISCONNECTED)
|
||||||
{
|
{
|
||||||
@ -1435,7 +1662,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||||||
std::cerr << " is Just disconnected!";
|
std::cerr << " is Just disconnected!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
setPeerState(it->second.mTransfer, pit->id, rate, false);
|
setPeerState(it->second->mTransfer, pit->id, rate, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1444,7 +1671,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
|||||||
std::cerr << pit-> actions;
|
std::cerr << pit-> actions;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
setPeerState(it->second.mTransfer, pit->id, rate, false);
|
setPeerState(it->second->mTransfer, pit->id, rate, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1546,41 +1773,34 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
|
|||||||
/* stack mutex released each loop */
|
/* stack mutex released each loop */
|
||||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator fit;
|
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(*it);
|
||||||
fit = mDownloads.find(*it);
|
|
||||||
if (fit == mDownloads.end())
|
if (fit == mDownloads.end())
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
/* ignore callback ones */
|
/* ignore callback ones */
|
||||||
if (fit->second.mDoCallback)
|
if (fit->second->mDoCallback)
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if ((fit->second).mCreator->finished())
|
if ((fit->second)->mCreator->finished())
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
/* make RsFileTransfer item for save list */
|
/* make RsFileTransfer item for save list */
|
||||||
RsFileTransfer *rft = new RsFileTransfer();
|
RsFileTransfer *rft = new RsFileTransfer();
|
||||||
|
|
||||||
/* what data is important? */
|
/* what data is important? */
|
||||||
|
|
||||||
rft->file.name = fit->second.mName;
|
rft->file.name = fit->second->mName;
|
||||||
rft->file.hash = fit->second.mHash;
|
rft->file.hash = fit->second->mHash;
|
||||||
rft->file.filesize = fit->second.mSize;
|
rft->file.filesize = fit->second->mSize;
|
||||||
rft->file.path = RsDirUtil::removeTopDir(fit->second.mDestination); /* remove fname */
|
rft->file.path = RsDirUtil::removeTopDir(fit->second->mDestination); /* remove fname */
|
||||||
rft->flags = fit->second.mFlags;
|
rft->flags = fit->second->mFlags;
|
||||||
rft->state = fit->second.mState;
|
rft->state = fit->second->mState;
|
||||||
fit->second.mTransfer->getFileSources(rft->allPeerIds.ids);
|
fit->second->mTransfer->getFileSources(rft->allPeerIds.ids);
|
||||||
|
|
||||||
// just avoid uninitialised memory reads
|
// just avoid uninitialised memory reads
|
||||||
rft->in = 0 ;
|
rft->in = 0 ;
|
||||||
rft->cPeerId = "" ;
|
rft->cPeerId = "" ;
|
||||||
rft->transferred = fit->second.mCreator->getRecvd();
|
rft->transferred = fit->second->mCreator->getRecvd();
|
||||||
rft->crate = 0 ;
|
rft->crate = 0 ;
|
||||||
rft->lrate = 0 ;
|
rft->lrate = 0 ;
|
||||||
rft->trate = 0 ;
|
rft->trate = 0 ;
|
||||||
@ -1600,8 +1820,8 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
|
|||||||
else
|
else
|
||||||
++sit ;
|
++sit ;
|
||||||
|
|
||||||
fit->second.mCreator->getAvailabilityMap(rft->compressed_chunk_map) ;
|
fit->second->mCreator->getAvailabilityMap(rft->compressed_chunk_map) ;
|
||||||
rft->chunk_strategy = fit->second.mCreator->getChunkStrategy() ;
|
rft->chunk_strategy = fit->second->mCreator->getChunkStrategy() ;
|
||||||
|
|
||||||
saveData.push_back(rft);
|
saveData.push_back(rft);
|
||||||
}
|
}
|
||||||
@ -1649,9 +1869,9 @@ bool ftController::loadList(std::list<RsItem *> load)
|
|||||||
{
|
{
|
||||||
RsStackMutex mtx(ctrlMutex) ;
|
RsStackMutex mtx(ctrlMutex) ;
|
||||||
|
|
||||||
std::map<std::string, ftFileControl>::iterator fit = mDownloads.find(rsft->file.hash);
|
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(rsft->file.hash);
|
||||||
|
|
||||||
if((fit==mDownloads.end() || (fit->second).mCreator == NULL))
|
if((fit==mDownloads.end() || (fit->second)->mCreator == NULL))
|
||||||
{
|
{
|
||||||
std::cerr << "ftController::loadList(): Error: could not find hash " << rsft->file.hash << " in mDownloads list !" << std::endl ;
|
std::cerr << "ftController::loadList(): Error: could not find hash " << rsft->file.hash << " in mDownloads list !" << std::endl ;
|
||||||
std::cerr << "Storing the map in a wait list." << std::endl ;
|
std::cerr << "Storing the map in a wait list." << std::endl ;
|
||||||
@ -1661,8 +1881,8 @@ bool ftController::loadList(std::list<RsItem *> load)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(fit->second).mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
|
(fit->second)->mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
|
||||||
(fit->second).mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
|
(fit->second)->mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,11 @@ class ftFileControl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum {DOWNLOADING,COMPLETED,ERROR_COMPLETION};
|
enum { DOWNLOADING = 0,
|
||||||
|
COMPLETED = 1,
|
||||||
|
ERROR_COMPLETION = 2,
|
||||||
|
QUEUED = 3
|
||||||
|
};
|
||||||
|
|
||||||
ftFileControl();
|
ftFileControl();
|
||||||
ftFileControl(std::string fname, std::string tmppath, std::string dest,
|
ftFileControl(std::string fname, std::string tmppath, std::string dest,
|
||||||
@ -86,6 +90,8 @@ class ftFileControl
|
|||||||
uint32_t mCallbackCode;
|
uint32_t mCallbackCode;
|
||||||
time_t mCreateTime;
|
time_t mCreateTime;
|
||||||
DwlSpeed mPriority ;
|
DwlSpeed mPriority ;
|
||||||
|
uint32_t mQueuePriority ;
|
||||||
|
uint32_t mQueuePosition ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ftPendingRequest
|
class ftPendingRequest
|
||||||
@ -115,93 +121,106 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
|||||||
/* Setup */
|
/* Setup */
|
||||||
ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir);
|
ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir);
|
||||||
|
|
||||||
void setFtSearchNExtra(ftSearch *, ftExtraList *);
|
void setFtSearchNExtra(ftSearch *, ftExtraList *);
|
||||||
void setTurtleRouter(p3turtle *) ;
|
void setTurtleRouter(p3turtle *) ;
|
||||||
bool activate();
|
bool activate();
|
||||||
bool isActiveAndNoPending();
|
bool isActiveAndNoPending();
|
||||||
|
|
||||||
void setShareDownloadDirectory(bool value);
|
void setShareDownloadDirectory(bool value);
|
||||||
bool getShareDownloadDirectory();
|
bool getShareDownloadDirectory();
|
||||||
|
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/********************** Controller Access **********************/
|
/********************** Controller Access **********************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
bool FileRequest(std::string fname, std::string hash,
|
bool FileRequest(std::string fname, std::string hash,
|
||||||
uint64_t size, std::string dest, uint32_t flags,
|
uint64_t size, std::string dest, uint32_t flags,
|
||||||
std::list<std::string> &sourceIds);
|
std::list<std::string> &sourceIds);
|
||||||
|
|
||||||
/// Do we already have this file, either in download or in file lists ?
|
/// Do we already have this file, either in download or in file lists ?
|
||||||
bool alreadyHaveFile(const std::string& hash) ;
|
bool alreadyHaveFile(const std::string& hash) ;
|
||||||
|
|
||||||
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy s);
|
||||||
|
|
||||||
bool FileCancel(std::string hash);
|
bool FileCancel(std::string hash);
|
||||||
bool FileControl(std::string hash, uint32_t flags);
|
bool FileControl(std::string hash, uint32_t flags);
|
||||||
bool FileClearCompleted();
|
bool FileClearCompleted();
|
||||||
bool FlagFileComplete(std::string hash);
|
bool FlagFileComplete(std::string hash);
|
||||||
bool getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info);
|
bool getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info);
|
||||||
|
|
||||||
bool getPriority(const std::string& hash,DwlSpeed& p);
|
// Download speed
|
||||||
void setPriority(const std::string& hash,DwlSpeed p);
|
bool getPriority(const std::string& hash,DwlSpeed& p);
|
||||||
|
void setPriority(const std::string& hash,DwlSpeed p);
|
||||||
|
|
||||||
|
// Action on queue position
|
||||||
|
//
|
||||||
|
void moveInQueue(const std::string& hash,QueueMove mv) ;
|
||||||
|
void clearQueue() ;
|
||||||
|
void setQueueSize(uint32_t size) ;
|
||||||
|
uint32_t getQueueSize() ;
|
||||||
|
|
||||||
/* get Details of File Transfers */
|
/* get Details of File Transfers */
|
||||||
bool FileDownloads(std::list<std::string> &hashs);
|
bool FileDownloads(std::list<std::string> &hashs);
|
||||||
|
|
||||||
/* Directory Handling */
|
/* Directory Handling */
|
||||||
bool setDownloadDirectory(std::string path);
|
bool setDownloadDirectory(std::string path);
|
||||||
bool setPartialsDirectory(std::string path);
|
bool setPartialsDirectory(std::string path);
|
||||||
std::string getDownloadDirectory();
|
std::string getDownloadDirectory();
|
||||||
std::string getPartialsDirectory();
|
std::string getPartialsDirectory();
|
||||||
bool FileDetails(std::string hash, FileInfo &info);
|
bool FileDetails(std::string hash, FileInfo &info);
|
||||||
|
|
||||||
bool moveFile(const std::string& source,const std::string& dest) ;
|
bool moveFile(const std::string& source,const std::string& dest) ;
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/********************** Cache Transfer *************************/
|
/********************** Cache Transfer *************************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
/// Returns true is full source availability can be assumed for this peer.
|
/// Returns true is full source availability can be assumed for this peer.
|
||||||
///
|
///
|
||||||
bool assumeAvailability(const std::string& peer_id) const ;
|
bool assumeAvailability(const std::string& peer_id) const ;
|
||||||
|
|
||||||
protected:
|
/* pqiMonitor callback (also provided mConnMgr pointer!) */
|
||||||
|
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||||
|
void addFileSource(const std::string& hash,const std::string& peer_id) ;
|
||||||
|
void removeFileSource(const std::string& hash,const std::string& peer_id) ;
|
||||||
|
|
||||||
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
protected:
|
||||||
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
|
||||||
|
|
||||||
void cleanCacheDownloads() ;
|
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||||
void tickTransfers() ;
|
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
|
||||||
|
|
||||||
|
void cleanCacheDownloads() ;
|
||||||
|
void tickTransfers() ;
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/********************** Controller Access **********************/
|
/********************** Controller Access **********************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
||||||
/* pqiMonitor callback (also provided mConnMgr pointer!) */
|
|
||||||
public:
|
|
||||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
|
||||||
void addFileSource(const std::string& hash,const std::string& peer_id) ;
|
|
||||||
void removeFileSource(const std::string& hash,const std::string& peer_id) ;
|
|
||||||
|
|
||||||
|
|
||||||
/* p3Config Interface */
|
/* p3Config Interface */
|
||||||
protected:
|
virtual RsSerialiser *setupSerialiser();
|
||||||
virtual RsSerialiser *setupSerialiser();
|
virtual std::list<RsItem *> saveList(bool &cleanup);
|
||||||
virtual std::list<RsItem *> saveList(bool &cleanup);
|
virtual bool loadList(std::list<RsItem *> load);
|
||||||
virtual bool loadList(std::list<RsItem *> load);
|
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
||||||
bool loadConfigMap(std::map<std::string, std::string> &configMap);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/* RunTime Functions */
|
/* RunTime Functions */
|
||||||
void checkDownloadQueue();
|
void checkDownloadQueue(); // check the whole queue for inactive files
|
||||||
bool completeFile(std::string hash);
|
|
||||||
bool handleAPendingRequest();
|
|
||||||
|
|
||||||
bool setPeerState(ftTransferModule *tm, std::string id,
|
void locked_addToQueue(ftFileControl*) ; // insert this one into the queue
|
||||||
|
void locked_bottomQueue(uint32_t pos) ; // bottom queue file which is at this position
|
||||||
|
void locked_topQueue(uint32_t pos) ; // top queue file which is at this position
|
||||||
|
void locked_checkQueueElement(uint32_t pos) ; // check the state of this element in the queue
|
||||||
|
void locked_queueRemove(uint32_t pos) ; // delete this element from the queue
|
||||||
|
void locked_swapQueue(uint32_t pos1,uint32_t pos2) ; // swap position of the two elements
|
||||||
|
|
||||||
|
bool completeFile(std::string hash);
|
||||||
|
bool handleAPendingRequest();
|
||||||
|
|
||||||
|
bool setPeerState(ftTransferModule *tm, std::string id,
|
||||||
uint32_t maxrate, bool online);
|
uint32_t maxrate, bool online);
|
||||||
|
|
||||||
time_t last_save_time ;
|
time_t last_save_time ;
|
||||||
@ -215,9 +234,11 @@ bool setPeerState(ftTransferModule *tm, std::string id,
|
|||||||
|
|
||||||
RsMutex ctrlMutex;
|
RsMutex ctrlMutex;
|
||||||
|
|
||||||
std::list<FileInfo> incomingQueue;
|
// std::list<FileInfo> incomingQueue;
|
||||||
std::map<std::string, ftFileControl> mCompleted;
|
|
||||||
std::map<std::string, ftFileControl> mDownloads;
|
std::map<std::string, ftFileControl*> mCompleted;
|
||||||
|
std::map<std::string, ftFileControl*> mDownloads;
|
||||||
|
std::vector<ftFileControl*> _queue ;
|
||||||
|
|
||||||
//std::map<std::string, ftTransferModule *> mTransfers;
|
//std::map<std::string, ftTransferModule *> mTransfers;
|
||||||
//std::map<std::string, ftFileCreator *> mFileCreators;
|
//std::map<std::string, ftFileCreator *> mFileCreators;
|
||||||
@ -227,9 +248,9 @@ bool setPeerState(ftTransferModule *tm, std::string id,
|
|||||||
std::string mPartialsPath;
|
std::string mPartialsPath;
|
||||||
|
|
||||||
/**** SPEED QUEUES ****/
|
/**** SPEED QUEUES ****/
|
||||||
std::list<std::string> mSlowQueue;
|
// std::list<std::string> mSlowQueue;
|
||||||
std::list<std::string> mStreamQueue;
|
// std::list<std::string> mStreamQueue;
|
||||||
std::list<std::string> mFastQueue;
|
// std::list<std::string> mFastQueue;
|
||||||
|
|
||||||
/* callback list (for File Completion) */
|
/* callback list (for File Completion) */
|
||||||
RsMutex doneMutex;
|
RsMutex doneMutex;
|
||||||
@ -244,9 +265,7 @@ bool setPeerState(ftTransferModule *tm, std::string id,
|
|||||||
/* share incoming directory */
|
/* share incoming directory */
|
||||||
bool mShareDownloadDir;
|
bool mShareDownloadDir;
|
||||||
|
|
||||||
// priority handling
|
uint32_t _max_active_downloads ; // maximum number of simultaneous downloads
|
||||||
//
|
|
||||||
std::vector< std::vector<ftTransferModule*> > mPriorityTab ;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
***********************************************************/
|
***********************************************************/
|
||||||
|
|
||||||
ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash, uint64_t recvd)
|
ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash)
|
||||||
: ftFileProvider(path,size,hash), chunkMap(size)
|
: ftFileProvider(path,size,hash), chunkMap(size)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -32,8 +32,8 @@ ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash,
|
|||||||
std::cerr << "\thash: " << hash;
|
std::cerr << "\thash: " << hash;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||||
|
_last_recv_time_t = time(NULL) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftFileCreator::getFileData(uint64_t offset, uint32_t &chunk_size, void *data)
|
bool ftFileCreator::getFileData(uint64_t offset, uint32_t &chunk_size, void *data)
|
||||||
@ -53,6 +53,22 @@ bool ftFileCreator::getFileData(uint64_t offset, uint32_t &chunk_size, void *dat
|
|||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t ftFileCreator::lastRecvTimeStamp()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||||
|
return _last_recv_time_t ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ftFileCreator::closeFile()
|
||||||
|
{
|
||||||
|
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
if(fd != NULL)
|
||||||
|
fclose(fd) ;
|
||||||
|
|
||||||
|
fd = NULL ;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t ftFileCreator::getRecvd()
|
uint64_t ftFileCreator::getRecvd()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||||
@ -69,10 +85,9 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
|
|||||||
std::cerr << " this: " << this;
|
std::cerr << " this: " << this;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/* dodgey checking outside of mutex...
|
/* dodgey checking outside of mutex... much check again inside FileAttrs(). */
|
||||||
* much check again inside FileAttrs().
|
|
||||||
*/
|
|
||||||
/* Check File is open */
|
/* Check File is open */
|
||||||
|
|
||||||
if (fd == NULL)
|
if (fd == NULL)
|
||||||
if (!initializeFileAttrs())
|
if (!initializeFileAttrs())
|
||||||
return false;
|
return false;
|
||||||
@ -98,15 +113,6 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t pos;
|
|
||||||
pos = ftello64(fd);
|
|
||||||
/*
|
|
||||||
* add the data
|
|
||||||
*/
|
|
||||||
//void *data2 = malloc(chunk_size);
|
|
||||||
//std::cerr << "data2: " << data2 << std::endl;
|
|
||||||
//if (1 != fwrite(data2, chunk_size, 1, this->fd))
|
|
||||||
|
|
||||||
if (1 != fwrite(data, chunk_size, 1, this->fd))
|
if (1 != fwrite(data, chunk_size, 1, this->fd))
|
||||||
{
|
{
|
||||||
std::cerr << "ftFileCreator::addFileData() Bad fwrite" << std::endl;
|
std::cerr << "ftFileCreator::addFileData() Bad fwrite" << std::endl;
|
||||||
@ -115,8 +121,6 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = ftello64(fd);
|
|
||||||
|
|
||||||
#ifdef FILE_DEBUG
|
#ifdef FILE_DEBUG
|
||||||
std::cerr << "ftFileCreator::addFileData() added Data...";
|
std::cerr << "ftFileCreator::addFileData() added Data...";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
@ -204,6 +208,7 @@ int ftFileCreator::initializeFileAttrs()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
fd = fopen64(file_name.c_str(), "r+b");
|
fd = fopen64(file_name.c_str(), "r+b");
|
||||||
|
|
||||||
if (!fd)
|
if (!fd)
|
||||||
{
|
{
|
||||||
std::cerr << "ftFileCreator::initializeFileAttrs() Failed to open (r+b): ";
|
std::cerr << "ftFileCreator::initializeFileAttrs() Failed to open (r+b): ";
|
||||||
@ -230,21 +235,15 @@ int ftFileCreator::initializeFileAttrs()
|
|||||||
* move to the end
|
* move to the end
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (0 != fseeko64(fd, 0L, SEEK_END))
|
// if (0 != fseeko64(fd, 0L, SEEK_END))
|
||||||
{
|
// {
|
||||||
std::cerr << "ftFileCreator::initializeFileAttrs() Seek Failed" << std::endl;
|
// std::cerr << "ftFileCreator::initializeFileAttrs() Seek Failed" << std::endl;
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
//uint64_t recvdsize = ftello64(fd);
|
#ifdef FILE_DEBUG
|
||||||
|
|
||||||
#ifdef FILE_DEBUG
|
|
||||||
std::cerr << "ftFileCreator::initializeFileAttrs() File Expected Size: " << mSize << " RecvdSize: " << recvdsize << std::endl;
|
std::cerr << "ftFileCreator::initializeFileAttrs() File Expected Size: " << mSize << " RecvdSize: " << recvdsize << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* start from there! */
|
|
||||||
// mStart = recvdsize;
|
|
||||||
// mEnd = recvdsize;
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -294,6 +293,8 @@ int ftFileCreator::locked_notifyReceived(uint64_t offset, uint32_t chunk_size)
|
|||||||
else // notify the chunkmap that the slice is finished
|
else // notify the chunkmap that the slice is finished
|
||||||
chunkMap.dataReceived(chunk.id) ;
|
chunkMap.dataReceived(chunk.id) ;
|
||||||
|
|
||||||
|
_last_recv_time_t = time(NULL) ;
|
||||||
|
|
||||||
/* otherwise there is another earlier block to go
|
/* otherwise there is another earlier block to go
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class ftFileCreator: public ftFileProvider
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ftFileCreator(std::string savepath, uint64_t size, std::string hash, uint64_t recvd);
|
ftFileCreator(std::string savepath, uint64_t size, std::string hash);
|
||||||
|
|
||||||
~ftFileCreator();
|
~ftFileCreator();
|
||||||
|
|
||||||
@ -49,6 +49,9 @@ class ftFileCreator: public ftFileProvider
|
|||||||
bool finished() ;
|
bool finished() ;
|
||||||
uint64_t getRecvd();
|
uint64_t getRecvd();
|
||||||
|
|
||||||
|
/// (temporarily) close the file, to save file descriptors.
|
||||||
|
void closeFile() ;
|
||||||
|
|
||||||
void getChunkMap(FileChunksInfo& info) ;
|
void getChunkMap(FileChunksInfo& info) ;
|
||||||
|
|
||||||
void setChunkStrategy(FileChunksInfo::ChunkStrategy s) ;
|
void setChunkStrategy(FileChunksInfo::ChunkStrategy s) ;
|
||||||
@ -70,6 +73,9 @@ class ftFileCreator: public ftFileProvider
|
|||||||
//
|
//
|
||||||
void removeInactiveChunks() ;
|
void removeInactiveChunks() ;
|
||||||
|
|
||||||
|
// Returns the time stamp of the last data receive.
|
||||||
|
time_t lastRecvTimeStamp() ;
|
||||||
|
|
||||||
// actually store data in the file, and update chunks info
|
// actually store data in the file, and update chunks info
|
||||||
//
|
//
|
||||||
bool addFileData(uint64_t offset, uint32_t chunk_size, void *data);
|
bool addFileData(uint64_t offset, uint32_t chunk_size, void *data);
|
||||||
@ -105,6 +111,8 @@ class ftFileCreator: public ftFileProvider
|
|||||||
std::map<uint64_t, ftChunk> mChunks;
|
std::map<uint64_t, ftChunk> mChunks;
|
||||||
|
|
||||||
ChunkMap chunkMap ;
|
ChunkMap chunkMap ;
|
||||||
|
|
||||||
|
time_t _last_recv_time_t ; /// last time stamp when data was received.
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FT_FILE_CREATOR_HEADER
|
#endif // FT_FILE_CREATOR_HEADER
|
||||||
|
@ -35,7 +35,7 @@ const int ftserverzone = 29539;
|
|||||||
#include "ft/ftcontroller.h"
|
#include "ft/ftcontroller.h"
|
||||||
#include "ft/ftfileprovider.h"
|
#include "ft/ftfileprovider.h"
|
||||||
#include "ft/ftdatamultiplex.h"
|
#include "ft/ftdatamultiplex.h"
|
||||||
#include "ft/ftdwlqueue.h"
|
//#include "ft/ftdwlqueue.h"
|
||||||
#include "turtle/p3turtle.h"
|
#include "turtle/p3turtle.h"
|
||||||
|
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
|||||||
mConnMgr->addMonitor(mFtController);
|
mConnMgr->addMonitor(mFtController);
|
||||||
mConnMgr->addMonitor(mCacheStrapper);
|
mConnMgr->addMonitor(mCacheStrapper);
|
||||||
|
|
||||||
mFtDwlQueue = new ftDwlQueue(mFtController);
|
// mFtDwlQueue = new ftDwlQueue(mFtController);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -160,7 +160,6 @@ void ftServer::connectToTurtleRouter(p3turtle *fts)
|
|||||||
{
|
{
|
||||||
mTurtleRouter = fts ;
|
mTurtleRouter = fts ;
|
||||||
|
|
||||||
// mFtSearch->addSearchMode(fts, RS_FILE_HINTS_TURTLE);
|
|
||||||
mFtController->setTurtleRouter(fts) ;
|
mFtController->setTurtleRouter(fts) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +184,8 @@ void ftServer::StartupThreads()
|
|||||||
/* Dataplex */
|
/* Dataplex */
|
||||||
mFtDataplex->start();
|
mFtDataplex->start();
|
||||||
|
|
||||||
/* Download Queue */
|
// /* Download Queue */
|
||||||
mFtDwlQueue->start();
|
// mFtDwlQueue->start();
|
||||||
|
|
||||||
/* start own thread */
|
/* start own thread */
|
||||||
start();
|
start();
|
||||||
@ -263,12 +262,9 @@ bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size, s
|
|||||||
|
|
||||||
std::cerr << "Requesting " << fname << std::endl ;
|
std::cerr << "Requesting " << fname << std::endl ;
|
||||||
|
|
||||||
if(mFtController->alreadyHaveFile(hash))
|
if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds))
|
||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
const DwlDetails details(fname, hash, size, dest, flags, srcIds, PRIORITY_NORMAL);
|
|
||||||
mFtDwlQueue->insertDownload(details);
|
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +277,6 @@ bool ftServer::FileCancel(std::string hash)
|
|||||||
{
|
{
|
||||||
// Remove from both queue and ftController, by default.
|
// Remove from both queue and ftController, by default.
|
||||||
//
|
//
|
||||||
mFtDwlQueue->clearDownload(hash);
|
|
||||||
mFtController->FileCancel(hash);
|
mFtController->FileCancel(hash);
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
@ -297,10 +292,19 @@ bool ftServer::FileClearCompleted()
|
|||||||
return mFtController->FileClearCompleted();
|
return mFtController->FileClearCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Control of Downloads Priority. */
|
void ftServer::setQueueSize(uint32_t s)
|
||||||
bool ftServer::changeQueuePriority(const std::string hash, int priority)
|
|
||||||
{
|
{
|
||||||
return mFtDwlQueue->changePriority(hash,(DwlPriority)priority) ;
|
mFtController->setQueueSize(s) ;
|
||||||
|
}
|
||||||
|
uint32_t ftServer::getQueueSize()
|
||||||
|
{
|
||||||
|
return mFtController->getQueueSize() ;
|
||||||
|
}
|
||||||
|
/* Control of Downloads Priority. */
|
||||||
|
bool ftServer::changeQueuePosition(const std::string hash, QueueMove mv)
|
||||||
|
{
|
||||||
|
mFtController->moveInQueue(hash,mv) ;
|
||||||
|
return true ;
|
||||||
}
|
}
|
||||||
bool ftServer::changeDownloadSpeed(const std::string hash, int speed)
|
bool ftServer::changeDownloadSpeed(const std::string hash, int speed)
|
||||||
{
|
{
|
||||||
@ -316,29 +320,15 @@ bool ftServer::getDownloadSpeed(const std::string hash, int & speed)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool ftServer::getQueuePriority(const std::string hash, int & priority)
|
|
||||||
{
|
|
||||||
DwlPriority _priority;
|
|
||||||
int ret = mFtDwlQueue->getPriority(hash, _priority);
|
|
||||||
if (ret)
|
|
||||||
priority = _priority;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
bool ftServer::clearDownload(const std::string hash)
|
bool ftServer::clearDownload(const std::string hash)
|
||||||
{
|
{
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ftServer::clearQueue()
|
//void ftServer::getDwlDetails(std::list<DwlDetails> & details)
|
||||||
{
|
//{
|
||||||
mFtDwlQueue->clearQueue();
|
// mFtDwlQueue->getDwlDetails(details);
|
||||||
}
|
//}
|
||||||
|
|
||||||
void ftServer::getDwlDetails(std::list<DwlDetails> & details)
|
|
||||||
{
|
|
||||||
mFtDwlQueue->getDwlDetails(details);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ftServer::FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
bool ftServer::FileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info)
|
||||||
{
|
{
|
||||||
@ -1041,7 +1031,7 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr)
|
|||||||
cfgmgr->addConfiguration("ft_shared.cfg", mFiMon);
|
cfgmgr->addConfiguration("ft_shared.cfg", mFiMon);
|
||||||
cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra);
|
cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra);
|
||||||
cfgmgr->addConfiguration("ft_transfers.cfg", mFtController);
|
cfgmgr->addConfiguration("ft_transfers.cfg", mFtController);
|
||||||
cfgmgr->addConfiguration("ft_dwlqueue.cfg", mFtDwlQueue);
|
// cfgmgr->addConfiguration("ft_dwlqueue.cfg", mFtDwlQueue);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -129,13 +129,13 @@ virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrat
|
|||||||
/***
|
/***
|
||||||
* Control of Downloads Priority.
|
* Control of Downloads Priority.
|
||||||
***/
|
***/
|
||||||
virtual bool changeQueuePriority(const std::string hash, int priority);
|
virtual uint32_t getQueueSize() ;
|
||||||
|
virtual void setQueueSize(uint32_t s) ;
|
||||||
|
virtual bool changeQueuePosition(const std::string hash, QueueMove queue_mv);
|
||||||
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
virtual bool changeDownloadSpeed(const std::string hash, int speed);
|
||||||
virtual bool getQueuePriority(const std::string hash, int & priority);
|
|
||||||
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
virtual bool getDownloadSpeed(const std::string hash, int & speed);
|
||||||
virtual bool clearDownload(const std::string hash);
|
virtual bool clearDownload(const std::string hash);
|
||||||
virtual void clearQueue();
|
//virtual void getDwlDetails(std::list<DwlDetails> & details);
|
||||||
virtual void getDwlDetails(std::list<DwlDetails> & details);
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Download/Upload Details
|
* Download/Upload Details
|
||||||
|
@ -178,7 +178,7 @@ HEADERS += dbase/cachestrapper.h \
|
|||||||
ft/ftchunkmap.h \
|
ft/ftchunkmap.h \
|
||||||
ft/ftserver.h \
|
ft/ftserver.h \
|
||||||
ft/fttransfermodule.h \
|
ft/fttransfermodule.h \
|
||||||
ft/ftdwlqueue.h \
|
# ft/ftdwlqueue.h \
|
||||||
pqi/authssl.h \
|
pqi/authssl.h \
|
||||||
pqi/authgpg.h \
|
pqi/authgpg.h \
|
||||||
pqi/cleanupxpgp.h \
|
pqi/cleanupxpgp.h \
|
||||||
@ -323,7 +323,7 @@ SOURCES += \
|
|||||||
ft/ftdata.cc \
|
ft/ftdata.cc \
|
||||||
ft/ftchunkmap.cc \
|
ft/ftchunkmap.cc \
|
||||||
ft/ftfileprovider.cc \
|
ft/ftfileprovider.cc \
|
||||||
ft/ftdwlqueue.cc \
|
# ft/ftdwlqueue.cc \
|
||||||
dht/opendhtmgr.cc \
|
dht/opendhtmgr.cc \
|
||||||
upnp/upnphandler.cc \
|
upnp/upnphandler.cc \
|
||||||
dht/opendht.cc \
|
dht/opendht.cc \
|
||||||
|
@ -119,13 +119,13 @@ class RsFiles
|
|||||||
/***
|
/***
|
||||||
* Control of Downloads Priority.
|
* Control of Downloads Priority.
|
||||||
***/
|
***/
|
||||||
virtual bool changeQueuePriority(const std::string hash, int priority) = 0;
|
virtual uint32_t getQueueSize() = 0 ;
|
||||||
|
virtual void setQueueSize(uint32_t s) = 0 ;
|
||||||
|
virtual bool changeQueuePosition(const std::string hash, QueueMove mv) = 0;
|
||||||
virtual bool changeDownloadSpeed(const std::string hash, int speed) = 0;
|
virtual bool changeDownloadSpeed(const std::string hash, int speed) = 0;
|
||||||
virtual bool getQueuePriority(const std::string hash, int & priority) = 0;
|
|
||||||
virtual bool getDownloadSpeed(const std::string hash, int & speed) = 0;
|
virtual bool getDownloadSpeed(const std::string hash, int & speed) = 0;
|
||||||
virtual bool clearDownload(const std::string hash) = 0;
|
virtual bool clearDownload(const std::string hash) = 0;
|
||||||
virtual void clearQueue() = 0;
|
// virtual void getDwlDetails(std::list<DwlDetails> & details) = 0;
|
||||||
virtual void getDwlDetails(std::list<DwlDetails> & details) = 0;
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Download / Upload Details.
|
* Download / Upload Details.
|
||||||
|
@ -39,13 +39,12 @@ typedef std::string RsChanId;
|
|||||||
typedef std::string RsMsgId;
|
typedef std::string RsMsgId;
|
||||||
typedef std::string RsAuthId;
|
typedef std::string RsAuthId;
|
||||||
|
|
||||||
#ifndef FT_STATE_FAILED
|
const uint32_t FT_STATE_FAILED = 0x0000 ;
|
||||||
const uint32_t FT_STATE_FAILED = 0x0000;
|
const uint32_t FT_STATE_OKAY = 0x0001 ;
|
||||||
const uint32_t FT_STATE_OKAY = 0x0001;
|
const uint32_t FT_STATE_WAITING = 0x0002 ;
|
||||||
const uint32_t FT_STATE_WAITING = 0x0002;
|
const uint32_t FT_STATE_DOWNLOADING = 0x0003 ;
|
||||||
const uint32_t FT_STATE_DOWNLOADING = 0x0003;
|
const uint32_t FT_STATE_COMPLETE = 0x0004 ;
|
||||||
const uint32_t FT_STATE_COMPLETE = 0x0004;
|
const uint32_t FT_STATE_QUEUED = 0x0005 ;
|
||||||
#endif
|
|
||||||
|
|
||||||
class TransferInfo
|
class TransferInfo
|
||||||
{
|
{
|
||||||
@ -57,10 +56,10 @@ class TransferInfo
|
|||||||
int status; /* FT_STATE_... */
|
int status; /* FT_STATE_... */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DwlPriority { PRIORITY_LOW = 0x00,
|
enum QueueMove { QUEUE_TOP = 0x00,
|
||||||
PRIORITY_NORMAL = 0x01,
|
QUEUE_UP = 0x01,
|
||||||
PRIORITY_HIGH = 0x02,
|
QUEUE_DOWN = 0x02,
|
||||||
PRIORITY_AUTO = 0x03
|
QUEUE_BOTTOM = 0x03
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DwlSpeed { SPEED_LOW = 0x00,
|
enum DwlSpeed { SPEED_LOW = 0x00,
|
||||||
@ -106,6 +105,7 @@ class FileInfo
|
|||||||
|
|
||||||
double rank;
|
double rank;
|
||||||
int age;
|
int age;
|
||||||
|
uint32_t queue_position ;
|
||||||
|
|
||||||
/* Transfer Stuff */
|
/* Transfer Stuff */
|
||||||
uint64_t transfered;
|
uint64_t transfered;
|
||||||
@ -336,9 +336,9 @@ class DwlDetails {
|
|||||||
public:
|
public:
|
||||||
DwlDetails() { return; }
|
DwlDetails() { return; }
|
||||||
DwlDetails(std::string fname, std::string hash, int count, std::string dest,
|
DwlDetails(std::string fname, std::string hash, int count, std::string dest,
|
||||||
uint32_t flags, std::list<std::string> srcIds, DwlPriority priority)
|
uint32_t flags, std::list<std::string> srcIds, uint32_t queue_pos)
|
||||||
: fname(fname), hash(hash), count(count), dest(dest), flags(flags),
|
: fname(fname), hash(hash), count(count), dest(dest), flags(flags),
|
||||||
srcIds(srcIds), priority(priority), retries(0) { return; }
|
srcIds(srcIds), queue_position(queue_pos), retries(0) { return; }
|
||||||
|
|
||||||
/* download details */
|
/* download details */
|
||||||
std::string fname;
|
std::string fname;
|
||||||
@ -349,7 +349,7 @@ public:
|
|||||||
std::list<std::string> srcIds;
|
std::list<std::string> srcIds;
|
||||||
|
|
||||||
/* internally used in download queue */
|
/* internally used in download queue */
|
||||||
DwlPriority priority;
|
uint32_t queue_position;
|
||||||
|
|
||||||
/* how many times a failed dwl will be requeued */
|
/* how many times a failed dwl will be requeued */
|
||||||
unsigned int retries;
|
unsigned int retries;
|
||||||
|
@ -172,14 +172,6 @@ virtual RsItem * deserialise(void *data, uint32_t *size);
|
|||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
#ifndef FT_STATE_FAILED
|
|
||||||
#define FT_STATE_FAILED 0
|
|
||||||
#define FT_STATE_OKAY 1
|
|
||||||
#define FT_STATE_WAITING 2
|
|
||||||
#define FT_STATE_DOWNLOADING 3
|
|
||||||
#define FT_STATE_COMPLETE 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class RsFileTransfer: public RsItem
|
class RsFileTransfer: public RsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -1763,10 +1763,7 @@ void p3turtle::getInfo( std::vector<std::vector<std::string> >& hashes_info,
|
|||||||
hashes.push_back(printNumber(it->second.tunnels.size())) ;
|
hashes.push_back(printNumber(it->second.tunnels.size())) ;
|
||||||
hashes.push_back(printNumber(now - it->second.time_stamp)+" secs ago") ;
|
hashes.push_back(printNumber(now - it->second.time_stamp)+" secs ago") ;
|
||||||
}
|
}
|
||||||
#ifdef A_VOIR
|
|
||||||
for(std::map<TurtleFileHash,FileInfo>::const_iterator it(_outgoing_file_hashes.begin());it!=_outgoing_file_hashes.end();++it)
|
|
||||||
std::cerr << " hash=0x" << it->first << ", name=" << it->second.fname << ", size=" << it->second.size << std::endl ;
|
|
||||||
#endif
|
|
||||||
tunnels_info.clear();
|
tunnels_info.clear();
|
||||||
|
|
||||||
for(std::map<TurtleTunnelId,TurtleTunnel>::const_iterator it(_local_tunnels.begin());it!=_local_tunnels.end();++it)
|
for(std::map<TurtleTunnelId,TurtleTunnel>::const_iterator it(_local_tunnels.begin());it!=_local_tunnels.end();++it)
|
||||||
|
@ -219,13 +219,13 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
|
|||||||
y += block_sep ;
|
y += block_sep ;
|
||||||
y += text_height ; painter->drawText(20,y,tr("File hash: ")) ; painter->drawText(tab_size,y,QString::fromStdString(nfo.hash)) ;
|
y += text_height ; painter->drawText(20,y,tr("File hash: ")) ; painter->drawText(tab_size,y,QString::fromStdString(nfo.hash)) ;
|
||||||
y += block_sep ;
|
y += block_sep ;
|
||||||
y += text_height ; painter->drawText(20,y,tr("File size: ")) ; painter->drawText(tab_size,y,misc::friendlyUnit(info.file_size)) ;
|
y += text_height ; painter->drawText(20,y,tr("File size: ")) ; painter->drawText(tab_size,y,QString::number(info.file_size)) ;
|
||||||
y += block_sep ;
|
y += block_sep ;
|
||||||
y += text_height ; painter->drawText(20,y,tr("Chunk size: ")) ; painter->drawText(tab_size,y,misc::friendlyUnit(info.chunk_size)) ;
|
y += text_height ; painter->drawText(20,y,tr("Chunk size: ")) ; painter->drawText(tab_size,y,QString::number(info.chunk_size)) ;
|
||||||
y += block_sep ;
|
y += block_sep ;
|
||||||
y += text_height ; painter->drawText(20,y,tr("Number of chunks: ")) ; painter->drawText(tab_size,y,QString::number(info.chunks.size())) ;
|
y += text_height ; painter->drawText(20,y,tr("Number of chunks: ")) ; painter->drawText(tab_size,y,QString::number(info.chunks.size())) ;
|
||||||
y += block_sep ;
|
y += block_sep ;
|
||||||
y += text_height ; painter->drawText(20,y,tr("Transfered: ")) ; painter->drawText(tab_size,y,misc::friendlyUnit(nfo.transfered)) ;
|
y += text_height ; painter->drawText(20,y,tr("Transfered: ")) ; painter->drawText(tab_size,y,QString::number(nfo.transfered)) ;
|
||||||
y += block_sep ;
|
y += block_sep ;
|
||||||
y += text_height ; painter->drawText(20,y,tr("Number of sources: ")) ; painter->drawText(tab_size,y,QString::number(info.compressed_peer_availability_maps.size())) ;
|
y += text_height ; painter->drawText(20,y,tr("Number of sources: ")) ; painter->drawText(tab_size,y,QString::number(info.compressed_peer_availability_maps.size())) ;
|
||||||
y += block_sep ;
|
y += block_sep ;
|
||||||
|
@ -92,7 +92,7 @@ TransfersDialog::TransfersDialog(QWidget *parent)
|
|||||||
DLListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress / Availability", "i.e: % downloaded"));
|
DLListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress / Availability", "i.e: % downloaded"));
|
||||||
DLListModel->setHeaderData(SOURCES, Qt::Horizontal, tr("Sources", "i.e: Sources"));
|
DLListModel->setHeaderData(SOURCES, Qt::Horizontal, tr("Sources", "i.e: Sources"));
|
||||||
DLListModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status"));
|
DLListModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status"));
|
||||||
DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Speed / Queue priority"));
|
DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Speed / Queue position"));
|
||||||
DLListModel->setHeaderData(REMAINING, Qt::Horizontal, tr("Remaining"));
|
DLListModel->setHeaderData(REMAINING, Qt::Horizontal, tr("Remaining"));
|
||||||
DLListModel->setHeaderData(DOWNLOADTIME, Qt::Horizontal, tr("Download time", "i.e: Estimated Time of Arrival / Time left"));
|
DLListModel->setHeaderData(DOWNLOADTIME, Qt::Horizontal, tr("Download time", "i.e: Estimated Time of Arrival / Time left"));
|
||||||
DLListModel->setHeaderData(ID, Qt::Horizontal, tr("Core-ID"));
|
DLListModel->setHeaderData(ID, Qt::Horizontal, tr("Core-ID"));
|
||||||
@ -302,17 +302,17 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
|
|||||||
|
|
||||||
QMenu *viewMenu = new QMenu( tr("View"), this );
|
QMenu *viewMenu = new QMenu( tr("View"), this );
|
||||||
|
|
||||||
clearQueueAct = new QAction(QIcon(), tr("Remove all queued"), this);
|
// clearQueueAct = new QAction(QIcon(), tr("Remove all queued"), this);
|
||||||
connect(clearQueueAct, SIGNAL(triggered()), this, SLOT(clearQueue()));
|
// connect(clearQueueAct, SIGNAL(triggered()), this, SLOT(clearQueue()));
|
||||||
|
|
||||||
priorityLowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Low"), this);
|
priorityLowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Down"), this);
|
||||||
connect(priorityLowAct, SIGNAL(triggered()), this, SLOT(priorityQueueLow()));
|
connect(priorityLowAct, SIGNAL(triggered()), this, SLOT(priorityQueueDown()));
|
||||||
priorityNormalAct = new QAction(QIcon(IMAGE_PRIORITYNORMAL), tr("Normal"), this);
|
priorityNormalAct = new QAction(QIcon(IMAGE_PRIORITYNORMAL), tr("Up"), this);
|
||||||
connect(priorityNormalAct, SIGNAL(triggered()), this, SLOT(priorityQueueNormal()));
|
connect(priorityNormalAct, SIGNAL(triggered()), this, SLOT(priorityQueueUp()));
|
||||||
priorityHighAct = new QAction(QIcon(IMAGE_PRIORITYHIGH), tr("High"), this);
|
priorityHighAct = new QAction(QIcon(IMAGE_PRIORITYHIGH), tr("Top"), this);
|
||||||
connect(priorityHighAct, SIGNAL(triggered()), this, SLOT(priorityQueueHigh()));
|
connect(priorityHighAct, SIGNAL(triggered()), this, SLOT(priorityQueueTop()));
|
||||||
priorityAutoAct = new QAction(QIcon(IMAGE_PRIORITYAUTO), tr("Auto"), this);
|
priorityAutoAct = new QAction(QIcon(IMAGE_PRIORITYAUTO), tr("Bottom"), this);
|
||||||
connect(priorityAutoAct, SIGNAL(triggered()), this, SLOT(priorityQueueAuto()));
|
connect(priorityAutoAct, SIGNAL(triggered()), this, SLOT(priorityQueueBottom()));
|
||||||
|
|
||||||
prioritySlowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Slower"), this);
|
prioritySlowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Slower"), this);
|
||||||
connect(prioritySlowAct, SIGNAL(triggered()), this, SLOT(speedSlow()));
|
connect(prioritySlowAct, SIGNAL(triggered()), this, SLOT(speedSlow()));
|
||||||
@ -321,14 +321,14 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
|
|||||||
priorityFastAct = new QAction(QIcon(IMAGE_PRIORITYHIGH), tr("Faster"), this);
|
priorityFastAct = new QAction(QIcon(IMAGE_PRIORITYHIGH), tr("Faster"), this);
|
||||||
connect(priorityFastAct, SIGNAL(triggered()), this, SLOT(speedFast()));
|
connect(priorityFastAct, SIGNAL(triggered()), this, SLOT(speedFast()));
|
||||||
|
|
||||||
QMenu *priorityQueueMenu = new QMenu(tr("Priority (Queue)"), this);
|
QMenu *priorityQueueMenu = new QMenu(tr("Move in queue..."), this);
|
||||||
priorityQueueMenu->setIcon(QIcon(IMAGE_PRIORITY));
|
priorityQueueMenu->setIcon(QIcon(IMAGE_PRIORITY));
|
||||||
priorityQueueMenu->addAction(priorityLowAct);
|
priorityQueueMenu->addAction(priorityLowAct);
|
||||||
priorityQueueMenu->addAction(priorityNormalAct);
|
priorityQueueMenu->addAction(priorityNormalAct);
|
||||||
priorityQueueMenu->addAction(priorityHighAct);
|
priorityQueueMenu->addAction(priorityHighAct);
|
||||||
priorityQueueMenu->addAction(priorityAutoAct);
|
priorityQueueMenu->addAction(priorityAutoAct);
|
||||||
|
|
||||||
QMenu *prioritySpeedMenu = new QMenu(tr("Priority (Speed)"), this);
|
QMenu *prioritySpeedMenu = new QMenu(tr("Priority (Speed)..."), this);
|
||||||
prioritySpeedMenu->setIcon(QIcon(IMAGE_PRIORITY));
|
prioritySpeedMenu->setIcon(QIcon(IMAGE_PRIORITY));
|
||||||
prioritySpeedMenu->addAction(prioritySlowAct);
|
prioritySpeedMenu->addAction(prioritySlowAct);
|
||||||
prioritySpeedMenu->addAction(priorityMediumAct);
|
prioritySpeedMenu->addAction(priorityMediumAct);
|
||||||
@ -386,7 +386,10 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
|
|||||||
contextMnu.addAction( pauseAct);
|
contextMnu.addAction( pauseAct);
|
||||||
if(!all_downld)
|
if(!all_downld)
|
||||||
contextMnu.addAction( resumeAct);
|
contextMnu.addAction( resumeAct);
|
||||||
|
|
||||||
|
if(info.downloadStatus != FT_STATE_COMPLETE)
|
||||||
contextMnu.addAction( cancelAct);
|
contextMnu.addAction( cancelAct);
|
||||||
|
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,7 +413,7 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
|
|||||||
#endif
|
#endif
|
||||||
contextMnu.addAction( pastelinkAct);
|
contextMnu.addAction( pastelinkAct);
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();
|
||||||
contextMnu.addAction( clearQueueAct);
|
// contextMnu.addAction( clearQueueAct);
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();
|
||||||
contextMnu.addMenu( viewMenu);
|
contextMnu.addMenu( viewMenu);
|
||||||
|
|
||||||
@ -491,13 +494,16 @@ bool TransfersDialog::addPeerToItem(int row, const QString& name, const QString&
|
|||||||
//try to find the item
|
//try to find the item
|
||||||
int childRow = -1;
|
int childRow = -1;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
QStandardItem* childId=NULL ;
|
||||||
|
|
||||||
while (QStandardItem* childId = dlItem->child(count, ID)) {
|
for(count=0; (childId = dlItem->child(count, ID)) != NULL;++count)
|
||||||
if (childId->data(Qt::DisplayRole).toString() == coreID) {
|
{
|
||||||
|
std::cerr << "data = " << childId->data(Qt::DisplayRole).toString().toStdString() << ", compared to " << coreID.toStdString() << std::endl ;
|
||||||
|
if (childId->data(Qt::DisplayRole).toString() == coreID)
|
||||||
|
{
|
||||||
childRow = count;
|
childRow = count;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
if (childRow == -1) {
|
if (childRow == -1) {
|
||||||
//set this false if you want to expand on double click
|
//set this false if you want to expand on double click
|
||||||
@ -513,7 +519,8 @@ bool TransfersDialog::addPeerToItem(int row, const QString& name, const QString&
|
|||||||
QStandardItem *i7 = new QStandardItem(); i7->setData(QVariant((QString)status), Qt::DisplayRole);
|
QStandardItem *i7 = new QStandardItem(); i7->setData(QVariant((QString)status), Qt::DisplayRole);
|
||||||
QStandardItem *i8 = new QStandardItem(); i8->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority
|
QStandardItem *i8 = new QStandardItem(); i8->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority
|
||||||
QStandardItem *i9 = new QStandardItem(); i9->setData(QVariant(QString()), Qt::DisplayRole);
|
QStandardItem *i9 = new QStandardItem(); i9->setData(QVariant(QString()), Qt::DisplayRole);
|
||||||
QStandardItem *i10 = new QStandardItem(); i10->setData(QVariant((QString)coreID), Qt::DisplayRole);
|
QStandardItem *i10 = new QStandardItem(); i10->setData(QVariant(QString()), Qt::DisplayRole);
|
||||||
|
QStandardItem *i11 = new QStandardItem(); i11->setData(QVariant((QString)coreID), Qt::DisplayRole);
|
||||||
|
|
||||||
/* set status icon in the name field */
|
/* set status icon in the name field */
|
||||||
if (status == "Downloading") {
|
if (status == "Downloading") {
|
||||||
@ -539,6 +546,7 @@ bool TransfersDialog::addPeerToItem(int row, const QString& name, const QString&
|
|||||||
items.append(i8);
|
items.append(i8);
|
||||||
items.append(i9);
|
items.append(i9);
|
||||||
items.append(i10);
|
items.append(i10);
|
||||||
|
items.append(i11);
|
||||||
dlItem->appendRow(items);
|
dlItem->appendRow(items);
|
||||||
} else {
|
} else {
|
||||||
//just update the child (peer)
|
//just update the child (peer)
|
||||||
@ -604,13 +612,14 @@ void TransfersDialog::updateDisplay()
|
|||||||
{
|
{
|
||||||
insertTransfers();
|
insertTransfers();
|
||||||
}
|
}
|
||||||
void TransfersDialog::insertTransfers() {
|
void TransfersDialog::insertTransfers()
|
||||||
|
{
|
||||||
/* get the download lists */
|
/* get the download lists */
|
||||||
std::list<std::string> downHashes;
|
std::list<std::string> downHashes;
|
||||||
rsFiles->FileDownloads(downHashes);
|
rsFiles->FileDownloads(downHashes);
|
||||||
|
|
||||||
std::list<DwlDetails> dwlDetails;
|
// std::list<DwlDetails> dwlDetails;
|
||||||
rsFiles->getDwlDetails(dwlDetails);
|
// rsFiles->getDwlDetails(dwlDetails);
|
||||||
|
|
||||||
//first clean the model in case some files are not download anymore
|
//first clean the model in case some files are not download anymore
|
||||||
//remove items that are not fiends anymore
|
//remove items that are not fiends anymore
|
||||||
@ -625,16 +634,16 @@ void TransfersDialog::insertTransfers() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
// if (!found) {
|
||||||
//look in the queued files
|
// //look in the queued files
|
||||||
std::list<DwlDetails>::iterator dwlDetailsIt;
|
// std::list<DwlDetails>::iterator dwlDetailsIt;
|
||||||
for (dwlDetailsIt = dwlDetails.begin(); dwlDetailsIt != dwlDetails.end(); dwlDetailsIt++) {
|
// for (dwlDetailsIt = dwlDetails.begin(); dwlDetailsIt != dwlDetails.end(); dwlDetailsIt++) {
|
||||||
if (hash == dwlDetailsIt->hash) {
|
// if (hash == dwlDetailsIt->hash) {
|
||||||
found = true;
|
// found = true;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (!found) {
|
if (!found) {
|
||||||
DLListModel->takeRow(removeIndex);
|
DLListModel->takeRow(removeIndex);
|
||||||
} else {
|
} else {
|
||||||
@ -642,6 +651,7 @@ void TransfersDialog::insertTransfers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear all source peers.
|
||||||
|
|
||||||
std::list<std::string>::iterator it;
|
std::list<std::string>::iterator it;
|
||||||
for (it = downHashes.begin(); it != downHashes.end(); it++) {
|
for (it = downHashes.begin(); it != downHashes.end(); it++) {
|
||||||
@ -670,7 +680,7 @@ void TransfersDialog::insertTransfers() {
|
|||||||
online++;
|
online++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QString sources = QString("%1 (%2)").arg(online).arg(info.peers.size() - online);
|
QString sources = QString("%1 (%2)").arg(online).arg(info.peers.size());
|
||||||
|
|
||||||
QString status;
|
QString status;
|
||||||
switch (info.downloadStatus) {
|
switch (info.downloadStatus) {
|
||||||
@ -679,11 +689,17 @@ void TransfersDialog::insertTransfers() {
|
|||||||
case FT_STATE_WAITING: status = tr("Waiting"); break;
|
case FT_STATE_WAITING: status = tr("Waiting"); break;
|
||||||
case FT_STATE_DOWNLOADING: status = tr("Downloading"); break;
|
case FT_STATE_DOWNLOADING: status = tr("Downloading"); break;
|
||||||
case FT_STATE_COMPLETE: status = tr("Complete"); break;
|
case FT_STATE_COMPLETE: status = tr("Complete"); break;
|
||||||
|
case FT_STATE_QUEUED: status = tr("Queued"); break;
|
||||||
default: status = tr("Unknown"); break;
|
default: status = tr("Unknown"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString priority;
|
QString priority;
|
||||||
switch (info.priority) {
|
|
||||||
|
if(info.downloadStatus == FT_STATE_QUEUED)
|
||||||
|
priority = QString::number(info.queue_position) ;
|
||||||
|
else
|
||||||
|
switch (info.priority)
|
||||||
|
{
|
||||||
case SPEED_LOW: priority = tr("Slower");break;
|
case SPEED_LOW: priority = tr("Slower");break;
|
||||||
case SPEED_NORMAL: priority = tr("Average");break;
|
case SPEED_NORMAL: priority = tr("Average");break;
|
||||||
case SPEED_HIGH: priority = tr("Faster");break;
|
case SPEED_HIGH: priority = tr("Faster");break;
|
||||||
@ -694,7 +710,6 @@ void TransfersDialog::insertTransfers() {
|
|||||||
qlonglong remaining = info.size - info.transfered;
|
qlonglong remaining = info.size - info.transfered;
|
||||||
qlonglong downloadtime = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
qlonglong downloadtime = (info.size - info.transfered) / (info.tfRate * 1024.0);
|
||||||
|
|
||||||
|
|
||||||
FileChunksInfo fcinfo ;
|
FileChunksInfo fcinfo ;
|
||||||
if(!rsFiles->FileDownloadChunksDetails(*it,fcinfo))
|
if(!rsFiles->FileDownloadChunksDetails(*it,fcinfo))
|
||||||
continue ;
|
continue ;
|
||||||
@ -743,13 +758,14 @@ void TransfersDialog::insertTransfers() {
|
|||||||
peerpinfo.progress = 0.0 ; // we don't display completion for sources.
|
peerpinfo.progress = 0.0 ; // we don't display completion for sources.
|
||||||
peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size();
|
peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size();
|
||||||
|
|
||||||
// std::cerr << std::endl ;
|
// std::cerr << std::endl ;
|
||||||
// std::cerr << "Source " << pit->peerId << " as map " << peerpinfo.cmap._map.size() << " compressed chunks" << std::endl ;
|
// std::cerr << "Source " << pit->peerId << " as map " << peerpinfo.cmap._map.size() << " compressed chunks" << std::endl ;
|
||||||
// for(uint j=0;j<peerpinfo.cmap._map.size();++j)
|
// for(uint j=0;j<peerpinfo.cmap._map.size();++j)
|
||||||
// std::cerr << peerpinfo.cmap._map[j] ;
|
// std::cerr << peerpinfo.cmap._map[j] ;
|
||||||
// std::cerr << std::endl ;
|
// std::cerr << std::endl ;
|
||||||
// std::cerr << std::endl ;
|
// std::cerr << std::endl ;
|
||||||
|
|
||||||
|
std::cout << "adding peer " << peerName.toStdString() << " to row " << addedRow << ", hashfile and peerid=" << hashFileAndPeerId.toStdString() << std::endl ;
|
||||||
addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, status, peerpinfo);
|
addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, status, peerpinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -757,26 +773,26 @@ void TransfersDialog::insertTransfers() {
|
|||||||
/* here i will insert files from the download queue - which are
|
/* here i will insert files from the download queue - which are
|
||||||
* not started yet and can't be find in FileDownloads
|
* not started yet and can't be find in FileDownloads
|
||||||
* */
|
* */
|
||||||
std::list<DwlDetails>::iterator dit;
|
// std::list<DwlDetails>::iterator dit;
|
||||||
for (dit = dwlDetails.begin(); dit != dwlDetails.end(); dit ++)
|
// for (dit = dwlDetails.begin(); dit != dwlDetails.end(); dit ++)
|
||||||
{
|
// {
|
||||||
// switch (dit->priority) {
|
//// switch (dit->priority) {
|
||||||
// case 0: priority = tr("Low"); break;
|
//// case 0: priority = tr("Low"); break;
|
||||||
// case 1: priority = tr("Normal"); break;
|
//// case 1: priority = tr("Normal"); break;
|
||||||
// case 2: priority = tr("High"); break;
|
//// case 2: priority = tr("High"); break;
|
||||||
// case 3: priority = tr("Auto"); break;
|
//// case 3: priority = tr("Auto"); break;
|
||||||
// default: priority = tr("Auto"); break;
|
//// default: priority = tr("Auto"); break;
|
||||||
// }
|
//// }
|
||||||
|
//
|
||||||
FileProgressInfo pinfo ;
|
// FileProgressInfo pinfo ;
|
||||||
pinfo.progress = 0.0 ;
|
// pinfo.progress = 0.0 ;
|
||||||
pinfo.nb_chunks = 0 ;
|
// pinfo.nb_chunks = 0 ;
|
||||||
|
//
|
||||||
addItem("", QString::fromUtf8(dit->fname.c_str()),
|
// addItem("", QString::fromUtf8(dit->fname.c_str()),
|
||||||
QString::fromStdString(dit->hash), dit->count, pinfo, 0, 0,
|
// QString::fromStdString(dit->hash), dit->count, pinfo, 0, 0,
|
||||||
tr("Queued"), "", 0, 0, 0);
|
// tr("Queued"), "", 0, 0, 0);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
std::list<std::string> upHashes;
|
std::list<std::string> upHashes;
|
||||||
rsFiles->FileUploads(upHashes);
|
rsFiles->FileUploads(upHashes);
|
||||||
@ -1261,10 +1277,10 @@ void TransfersDialog::openTransfer()
|
|||||||
// rsFiles->clearDownload(hash);
|
// rsFiles->clearDownload(hash);
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
void TransfersDialog::clearQueue()
|
//void TransfersDialog::clearQueue()
|
||||||
{
|
//{
|
||||||
rsFiles->clearQueue();
|
// rsFiles->clearQueue();
|
||||||
}
|
//}
|
||||||
|
|
||||||
void TransfersDialog::chunkStreaming()
|
void TransfersDialog::chunkStreaming()
|
||||||
{
|
{
|
||||||
@ -1299,21 +1315,21 @@ void TransfersDialog::speedFast()
|
|||||||
changeSpeed(2);
|
changeSpeed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransfersDialog::priorityQueueLow()
|
void TransfersDialog::priorityQueueUp()
|
||||||
{
|
{
|
||||||
changeQueuePriority(0);
|
changeQueuePosition(QUEUE_UP);
|
||||||
}
|
}
|
||||||
void TransfersDialog::priorityQueueNormal()
|
void TransfersDialog::priorityQueueDown()
|
||||||
{
|
{
|
||||||
changeQueuePriority(1);
|
changeQueuePosition(QUEUE_DOWN);
|
||||||
}
|
}
|
||||||
void TransfersDialog::priorityQueueHigh()
|
void TransfersDialog::priorityQueueTop()
|
||||||
{
|
{
|
||||||
changeQueuePriority(2);
|
changeQueuePosition(QUEUE_TOP);
|
||||||
}
|
}
|
||||||
void TransfersDialog::priorityQueueAuto()
|
void TransfersDialog::priorityQueueBottom()
|
||||||
{
|
{
|
||||||
changeQueuePriority(3);
|
changeQueuePosition(QUEUE_BOTTOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransfersDialog::changeSpeed(int speed)
|
void TransfersDialog::changeSpeed(int speed)
|
||||||
@ -1322,15 +1338,17 @@ void TransfersDialog::changeSpeed(int speed)
|
|||||||
std::set<QStandardItem *>::iterator it;
|
std::set<QStandardItem *>::iterator it;
|
||||||
getIdOfSelectedItems(items);
|
getIdOfSelectedItems(items);
|
||||||
|
|
||||||
for (it = items.begin(); it != items.end(); it ++) {
|
for (it = items.begin(); it != items.end(); it ++)
|
||||||
|
{
|
||||||
std::string hash = (*it)->data(Qt::DisplayRole).toString().toStdString();
|
std::string hash = (*it)->data(Qt::DisplayRole).toString().toStdString();
|
||||||
rsFiles->changeDownloadSpeed(hash, speed);
|
rsFiles->changeDownloadSpeed(hash, speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TransfersDialog::changeQueuePriority(int priority)
|
void TransfersDialog::changeQueuePosition(QueueMove mv)
|
||||||
{
|
{
|
||||||
|
std::cerr << "In changeQueuePosition (gui)"<< std::endl ;
|
||||||
std::set<QStandardItem *> items;
|
std::set<QStandardItem *> items;
|
||||||
std::set<QStandardItem *>::iterator it;
|
std::set<QStandardItem *>::iterator it;
|
||||||
getIdOfSelectedItems(items);
|
getIdOfSelectedItems(items);
|
||||||
@ -1338,7 +1356,7 @@ void TransfersDialog::changeQueuePriority(int priority)
|
|||||||
for (it = items.begin(); it != items.end(); it ++)
|
for (it = items.begin(); it != items.end(); it ++)
|
||||||
{
|
{
|
||||||
std::string hash = (*it)->data(Qt::DisplayRole).toString().toStdString();
|
std::string hash = (*it)->data(Qt::DisplayRole).toString().toStdString();
|
||||||
rsFiles->changeQueuePriority(hash, priority);
|
rsFiles->changeQueuePosition(hash, mv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,20 +84,20 @@ private slots:
|
|||||||
void previewTransfer();
|
void previewTransfer();
|
||||||
|
|
||||||
/** clear download or all queue - for pending dwls */
|
/** clear download or all queue - for pending dwls */
|
||||||
void clearQueue();
|
// void clearQueue();
|
||||||
|
|
||||||
/** modify download priority actions */
|
/** modify download priority actions */
|
||||||
void priorityQueueLow();
|
void priorityQueueUp();
|
||||||
void priorityQueueNormal();
|
void priorityQueueDown();
|
||||||
void priorityQueueHigh();
|
void priorityQueueTop();
|
||||||
void priorityQueueAuto();
|
void priorityQueueBottom();
|
||||||
|
|
||||||
void speedSlow();
|
void speedSlow();
|
||||||
void speedAverage();
|
void speedAverage();
|
||||||
void speedFast();
|
void speedFast();
|
||||||
|
|
||||||
void changeSpeed(int) ;
|
void changeSpeed(int) ;
|
||||||
void changeQueuePriority(int) ;
|
void changeQueuePosition(QueueMove) ;
|
||||||
|
|
||||||
void chunkRandom();
|
void chunkRandom();
|
||||||
void chunkStreaming();
|
void chunkStreaming();
|
||||||
@ -143,8 +143,8 @@ private:
|
|||||||
QAction *openfolderAct;
|
QAction *openfolderAct;
|
||||||
QAction *openfileAct;
|
QAction *openfileAct;
|
||||||
QAction *previewfileAct;
|
QAction *previewfileAct;
|
||||||
QAction *clearQueuedDwlAct;
|
// QAction *clearQueuedDwlAct;
|
||||||
QAction *clearQueueAct;
|
// QAction *clearQueueAct;
|
||||||
QAction *changePriorityAct;
|
QAction *changePriorityAct;
|
||||||
QAction *prioritySlowAct;
|
QAction *prioritySlowAct;
|
||||||
QAction *priorityMediumAct;
|
QAction *priorityMediumAct;
|
||||||
|
@ -137,7 +137,7 @@ LogicalOperator ExpressionWidget::getOperator()
|
|||||||
|
|
||||||
Expression* ExpressionWidget::getRsExpression()
|
Expression* ExpressionWidget::getRsExpression()
|
||||||
{
|
{
|
||||||
Expression * expr;
|
Expression * expr = NULL;
|
||||||
|
|
||||||
std::list<std::string> wordList;
|
std::list<std::string> wordList;
|
||||||
int lowVal = 0;
|
int lowVal = 0;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "rsiface/rsiface.h"
|
#include "rsiface/rsiface.h"
|
||||||
|
#include "rsiface/rsfiles.h"
|
||||||
#include "rsiface/rspeers.h"
|
#include "rsiface/rspeers.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@ -43,6 +44,9 @@ TransferPage::TransferPage(QWidget * parent, Qt::WFlags flags)
|
|||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
|
||||||
|
ui._queueSize_SB->setValue(rsFiles->getQueueSize()) ;
|
||||||
|
|
||||||
|
QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
|
||||||
|
|
||||||
/* Hide platform specific features */
|
/* Hide platform specific features */
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
@ -50,6 +54,11 @@ TransferPage::TransferPage(QWidget * parent, Qt::WFlags flags)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransferPage::updateQueueSize(int s)
|
||||||
|
{
|
||||||
|
rsFiles->setQueueSize(s) ;
|
||||||
|
}
|
||||||
|
|
||||||
void TransferPage::closeEvent (QCloseEvent * event)
|
void TransferPage::closeEvent (QCloseEvent * event)
|
||||||
{
|
{
|
||||||
QWidget::closeEvent(event);
|
QWidget::closeEvent(event);
|
||||||
|
@ -42,6 +42,7 @@ class TransferPage: public ConfigPage
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
|
void updateQueueSize(int) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="Seite">
|
<widget class="QWidget" name="Seite">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@ -38,15 +38,18 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QSpinBox" name="queuespinBox">
|
<widget class="QSpinBox" name="_queueSize_SB">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="singleStep">
|
<property name="singleStep">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>7</number>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -236,6 +236,11 @@ void xProgressBar::paint()
|
|||||||
painter->setPen(textColor);
|
painter->setPen(textColor);
|
||||||
painter->drawText(rect, Qt::AlignCenter, locale.toString(_pinfo.progress, 'f', 2) + "%");
|
painter->drawText(rect, Qt::AlignCenter, locale.toString(_pinfo.progress, 'f', 2) + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backgroundColor.setRgb(255, 255, 255);
|
||||||
|
painter->setBrush(backgroundColor);
|
||||||
|
backgroundBorderColor.setRgb(0, 0, 0);
|
||||||
|
painter->setPen(backgroundBorderColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void xProgressBar::setColorSchema(const int value)
|
void xProgressBar::setColorSchema(const int value)
|
||||||
|
Loading…
Reference in New Issue
Block a user