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:
csoler 2010-03-06 23:29:47 +00:00
parent 6c686496a9
commit 9e469d8baf
19 changed files with 904 additions and 641 deletions

View File

@ -56,13 +56,15 @@
/******
* #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 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()
:mTransfer(NULL), mCreator(NULL),
mState(0), mSize(0), mFlags(0),
mState(DOWNLOADING), mSize(0), mFlags(0),
mPriority(SPEED_NORMAL)
{
return;
@ -73,7 +75,7 @@ ftFileControl::ftFileControl(std::string fname,
uint64_t size, std::string hash, uint32_t flags,
ftFileCreator *fc, ftTransferModule *tm, uint32_t cb)
: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),
mPriority(SPEED_NORMAL) // default priority to normal
{
@ -91,6 +93,7 @@ ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string c
mFtActive(false),
mShareDownloadDir(true)
{
_max_active_downloads = 5 ; // default queue size
/* TODO */
}
@ -108,12 +111,12 @@ bool ftController::getFileDownloadChunksDetails(const std::string& hash,FileChun
{
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())
{
it->second.mCreator->getChunkMap(info) ;
info.flags = it->second.mFlags ;
it->second->mCreator->getChunkMap(info) ;
info.flags = it->second->mFlags ;
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.
//
info.file_size = it->second.mSize ;
info.file_size = it->second->mSize ;
info.chunk_size = ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
info.flags = it->second.mFlags ;
uint32_t nb_chunks = it->second.mSize/ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
if(it->second.mSize % ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE != 0)
info.flags = it->second->mFlags ;
uint32_t nb_chunks = it->second->mSize/ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE ;
if(it->second->mSize % ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE != 0)
++nb_chunks ;
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 ********/
std::map<std::string, ftFileControl>::iterator it;
std::map<std::string, ftFileControl> currentDownloads = *(&mDownloads);
std::map<std::string, ftFileControl*>::iterator it;
std::map<std::string, ftFileControl*> currentDownloads = *(&mDownloads);
#ifdef CONTROL_DEBUG
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++)
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));
@ -168,8 +171,8 @@ void ftController::removeFileSource(const std::string& hash,const std::string& p
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
std::map<std::string, ftFileControl>::iterator it;
std::map<std::string, ftFileControl> currentDownloads = *(&mDownloads);
std::map<std::string, ftFileControl*>::iterator it;
std::map<std::string, ftFileControl*> currentDownloads = *(&mDownloads);
#ifdef CONTROL_DEBUG
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++)
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));
@ -194,6 +197,8 @@ void ftController::run()
{
/* check the queues */
uint32_t cnt = 0 ;
while(1)
{
#ifdef WIN32
@ -225,8 +230,8 @@ void ftController::run()
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
for(std::map<std::string,ftFileControl>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
it->second.mCreator->removeInactiveChunks() ;
for(std::map<std::string,ftFileControl*>::iterator it(mDownloads.begin());it!=mDownloads.end();++it)
it->second->mCreator->removeInactiveChunks() ;
last_clean_time = now ;
}
@ -250,6 +255,9 @@ void ftController::run()
mDone.clear();
}
if(cnt++ % 10 == 0)
checkDownloadQueue() ;
}
}
@ -258,34 +266,30 @@ void ftController::tickTransfers()
{
// 1 - sort modules into arrays according to priority
// if(mPrioritiesChanged)
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
#ifdef CONTROL_DEBUG
#ifdef CONTROL_DEBUG
std::cerr << "ticking transfers." << std::endl ;
#endif
mPriorityTab = std::vector<std::vector<ftTransferModule*> >(3,std::vector<ftTransferModule*>()) ;
#endif
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++)
mPriorityTab[it->second.mPriority].push_back(it->second.mTransfer) ;
// Collect all non queued files.
//
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.1 - decide based on probability, which category of files we handle.
// static const float HIGH_PRIORITY_PROB = 0.60 ;
// 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
#ifdef CONTROL_DEBUG
std::cerr << "Priority tabs: " ;
std::cerr << "Low (" << mPriorityTab[SPEED_LOW ].size() << ") " ;
std::cerr << "Normal (" << mPriorityTab[SPEED_NORMAL].size() << ") " ;
std::cerr << "High (" << mPriorityTab[SPEED_HIGH ].size() << ") " ;
std::cerr << "Low (" << priority_tab[SPEED_LOW ].size() << ") " ;
std::cerr << "Normal (" << priority_tab[SPEED_NORMAL].size() << ") " ;
std::cerr << "High (" << priority_tab[SPEED_HIGH ].size() << ") " ;
std::cerr << std::endl ;
#endif
#endif
/* tick the transferModules */
@ -293,12 +297,12 @@ void ftController::tickTransfers()
//
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)
mPriorityTab[chosen][(i+start)%(int)mPriorityTab[chosen].size()]->tick() ;
for(int i=0;i<(int)priority_tab[chosen].size();++i)
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 ********/
std::map<std::string,ftFileControl>::iterator it(mDownloads.find(hash)) ;
std::map<std::string,ftFileControl*>::iterator it(mDownloads.find(hash)) ;
if(it != mDownloads.end())
{
p = it->second.mPriority ;
p = it->second->mPriority ;
return true ;
}
else
@ -320,10 +324,10 @@ void ftController::setPriority(const std::string& hash,DwlSpeed p)
{
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())
it->second.mPriority = p ;
it->second->mPriority = p ;
}
void ftController::cleanCacheDownloads()
@ -333,20 +337,20 @@ void ftController::cleanCacheDownloads()
{
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
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
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
{
#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;
#endif
if ((time(NULL) - (it->second).mCreateTime) > TIMOUT_CACHE_FILE_TRANSFER)
if ((time(NULL) - (it->second)->mCreateTime) > TIMOUT_CACHE_FILE_TRANSFER)
{
#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;
#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 */
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)
@ -472,8 +667,8 @@ bool ftController::completeFile(std::string hash)
std::cerr << "ftController:completeFile(" << hash << ")";
std::cerr << std::endl;
#endif
std::map<std::string, ftFileControl>::iterator it;
it = mDownloads.find(hash);
std::map<std::string, ftFileControl*>::iterator it(mDownloads.find(hash));
if (it == mDownloads.end())
{
#ifdef CONTROL_DEBUG
@ -485,7 +680,7 @@ bool ftController::completeFile(std::string hash)
}
/* check if finished */
if (!(it->second).mCreator->finished())
if (!(it->second)->mCreator->finished())
{
/* not done! */
#ifdef CONTROL_DEBUG
@ -494,15 +689,15 @@ bool ftController::completeFile(std::string hash)
std::cerr << std::endl;
std::cerr << "FileSize: ";
std::cerr << (it->second).mCreator->getFileSize();
std::cerr << (it->second)->mCreator->getFileSize();
std::cerr << " and Recvd: ";
std::cerr << (it->second).mCreator->getRecvd();
std::cerr << (it->second)->mCreator->getRecvd();
#endif
return false;
}
ftFileControl *fc = &(it->second);
ftFileControl *fc = it->second;
// (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
@ -537,10 +732,6 @@ bool ftController::completeFile(std::string hash)
else
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 */
path = fc->mDestination;
//hash = fc->mHash;
@ -558,6 +749,15 @@ bool ftController::completeFile(std::string hash)
mDataplex->removeTransferModule(hash_to_suppress) ;
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);
if(flgs & RS_FILE_HINTS_NETWORK_WIDE)
@ -679,9 +879,9 @@ bool ftController::handleAPendingRequest()
if(it != mPendingChunkMaps.end())
{
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!!
//
@ -689,8 +889,8 @@ bool ftController::handleAPendingRequest()
}
else
{
(fit->second).mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
(fit->second).mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
(fit->second)->mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
(fit->second)->mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
}
delete rsft ;
@ -720,6 +920,27 @@ bool ftController::FileRequest(std::string fname, std::string hash,
uint64_t size, std::string dest, uint32_t flags,
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 ....
* save request for later. This will also
* 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 ********/
std::map<std::string, ftFileControl>::iterator dit;
dit = mDownloads.find(hash);
std::map<std::string, ftFileControl*>::iterator dit = mDownloads.find(hash);
if (dit != mDownloads.end())
{
/* 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++)
{
uint32_t i, j;
if ((dit->second).mTransfer->getPeerState(*it, i, j))
if ((dit->second)->mTransfer->getPeerState(*it, i, j))
{
#ifdef CONTROL_DEBUG
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 << std::endl;
#endif
(dit->second).mTransfer->addFileSource(*it);
setPeerState(dit->second.mTransfer, *it,
rate, mConnMgr->isOnline(*it));
(dit->second)->mTransfer->addFileSource(*it);
setPeerState(dit->second->mTransfer, *it, rate, mConnMgr->isOnline(*it));
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 (dest == "")
{
destination = mDownloadPath + "/" + fname;
}
} /******* UNLOCKED ********/
// 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)
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);
/* add into maps */
ftFileControl ftfc(fname, savepath, destination, size, hash, flags, fc, tm, callbackCode);
ftfc.mCreateTime = time(NULL);
ftFileControl *ftfc = new ftFileControl(fname, savepath, destination, size, hash, flags, fc, tm, callbackCode);
ftfc->mCreateTime = time(NULL);
locked_addToQueue(ftfc) ;
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileRequest() Created ftFileCreator @: " << fc;
@ -951,8 +1171,6 @@ bool ftController::FileRequest(std::string fname, std::string hash,
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
mDownloads[hash] = ftfc;
mSlowQueue.push_back(hash);
IndicateConfigChanged(); /* completed transfer -> save */
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)
{
std::map<std::string,ftFileControl>::iterator mit;
mit=mDownloads.find(hash);
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
if (mit==mDownloads.end())
{
#ifdef CONTROL_DEBUG
@ -1002,7 +1219,7 @@ bool ftController::setChunkStrategy(const std::string& hash,FileChunksInfo::Chun
return false;
}
mit->second.mCreator->setChunkStrategy(s) ;
mit->second->mCreator->setChunkStrategy(s) ;
return true ;
}
@ -1018,8 +1235,7 @@ bool ftController::FileCancel(std::string hash)
{
RsStackMutex mtx(ctrlMutex) ;
std::map<std::string,ftFileControl>::iterator mit;
mit=mDownloads.find(hash);
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
if (mit==mDownloads.end())
{
#ifdef CONTROL_DEBUG
@ -1029,7 +1245,7 @@ bool ftController::FileCancel(std::string hash)
}
/* check if finished */
if ((mit->second).mCreator->finished())
if ((mit->second)->mCreator->finished())
{
#ifdef CONTROL_DEBUG
std::cerr << "ftController:FileCancel(" << hash << ")";
@ -1037,18 +1253,18 @@ bool ftController::FileCancel(std::string hash)
std::cerr << std::endl;
std::cerr << "FileSize: ";
std::cerr << (mit->second).mCreator->getFileSize();
std::cerr << (mit->second)->mCreator->getFileSize();
std::cerr << " and Recvd: ";
std::cerr << (mit->second).mCreator->getRecvd();
std::cerr << (mit->second)->mCreator->getRecvd();
#endif
return false;
}
/*find the point to transfer module*/
ftTransferModule* ft=(mit->second).mTransfer;
ftTransferModule* ft=(mit->second)->mTransfer;
ft->cancelTransfer();
ftFileControl *fc = &(mit->second);
ftFileControl *fc = mit->second;
mDataplex->removeTransferModule(fc->mTransfer->hash());
if (fc->mTransfer)
@ -1081,6 +1297,8 @@ bool ftController::FileCancel(std::string hash)
#endif
}
locked_queueRemove(fc->mQueuePosition) ;
delete fc ;
mDownloads.erase(mit);
}
@ -1095,8 +1313,7 @@ bool ftController::FileControl(std::string hash, uint32_t flags)
std::cerr << flags << ")"<<std::endl;
#endif
/*check if the file in the download map*/
std::map<std::string,ftFileControl>::iterator mit;
mit=mDownloads.find(hash);
std::map<std::string,ftFileControl*>::iterator mit=mDownloads.find(hash);
if (mit==mDownloads.end())
{
#ifdef CONTROL_DEBUG
@ -1106,7 +1323,7 @@ bool ftController::FileControl(std::string hash, uint32_t flags)
}
/*find the point to transfer module*/
ftTransferModule* ft=(mit->second).mTransfer;
ftTransferModule* ft=(mit->second)->mTransfer;
switch (flags)
{
case RS_FILE_CTRL_PAUSE:
@ -1126,7 +1343,13 @@ bool ftController::FileClearCompleted()
#ifdef CONTROL_DEBUG
std::cerr << "ftController::FileClearCompleted()" <<std::endl;
#endif
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
for(std::map<std::string, ftFileControl*>::iterator it(mCompleted.begin());it!=mCompleted.end();++it)
delete it->second ;
mCompleted.clear();
IndicateConfigChanged();
return false;
@ -1137,14 +1360,14 @@ bool ftController::FileDownloads(std::list<std::string> &hashs)
{
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++)
{
hashs.push_back(it->second.mHash);
hashs.push_back(it->second->mHash);
}
for(it = mCompleted.begin(); it != mCompleted.end(); it++)
{
hashs.push_back(it->second.mHash);
hashs.push_back(it->second->mHash);
}
return true;
}
@ -1243,8 +1466,7 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
bool completed = false;
std::map<std::string, ftFileControl>::iterator it;
it = mDownloads.find(hash);
std::map<std::string, ftFileControl*>::iterator it = mDownloads.find(hash);
if (it == mDownloads.end())
{
/* search completed files too */
@ -1261,17 +1483,18 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
/* extract details */
info.hash = hash;
info.fname = it->second.mName;
info.flags = it->second.mFlags;
info.path = RsDirUtil::removeTopDir(it->second.mDestination); /* remove fname */
info.priority = it->second.mPriority ;
info.fname = it->second->mName;
info.flags = it->second->mFlags;
info.path = RsDirUtil::removeTopDir(it->second->mDestination); /* remove fname */
info.priority = it->second->mPriority ;
info.queue_position = it->second->mQueuePosition ;
/* get list of sources from transferModule */
std::list<std::string> peerIds;
std::list<std::string>::iterator pit;
if (!completed)
it->second.mTransfer->getFileSources(peerIds);
it->second->mTransfer->getFileSources(peerIds);
double totalRate = 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++)
{
if (it->second.mTransfer->getPeerState(*pit, state, tfRate))
if (it->second->mTransfer->getPeerState(*pit, state, tfRate))
{
TransferInfo ti;
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;
}
@ -1330,8 +1553,12 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
{
info.downloadStatus = FT_STATE_WAITING;
}
if(it->second->mState == ftFileControl::QUEUED)
info.downloadStatus = FT_STATE_QUEUED ;
info.tfRate = totalRate;
info.size = (it->second).mSize;
info.size = (it->second)->mSize;
if (completed)
{
@ -1340,7 +1567,7 @@ bool ftController::FileDetails(std::string hash, FileInfo &info)
}
else
{
info.transfered = (it->second).mCreator->getRecvd();
info.transfered = (it->second)->mCreator->getRecvd();
info.avail = info.transfered;
}
@ -1364,7 +1591,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
uint32_t rate = FT_CNTRL_STANDARD_RATE;
/* 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> vlist ;
@ -1393,7 +1620,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
std::cerr << " is Newly Connected!";
std::cerr << std::endl;
#endif
setPeerState(it->second.mTransfer, pit->id, rate, true);
setPeerState(it->second->mTransfer, pit->id, rate, true);
}
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 << std::endl;
#endif
setPeerState(it->second.mTransfer, pit->id, rate, false);
setPeerState(it->second->mTransfer, pit->id, rate, false);
}
else
{
@ -1410,7 +1637,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
std::cerr << pit-> actions;
std::cerr << std::endl;
#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 << std::endl;
#endif
setPeerState(it->second.mTransfer, pit->id, rate, true);
setPeerState(it->second->mTransfer, pit->id, rate, true);
}
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 << std::endl;
#endif
setPeerState(it->second.mTransfer, pit->id, rate, false);
setPeerState(it->second->mTransfer, pit->id, rate, false);
}
else
{
@ -1444,7 +1671,7 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
std::cerr << pit-> actions;
std::cerr << std::endl;
#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 */
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
std::map<std::string, ftFileControl>::iterator fit;
fit = mDownloads.find(*it);
std::map<std::string, ftFileControl*>::iterator fit = mDownloads.find(*it);
if (fit == mDownloads.end())
{
continue;
}
/* ignore callback ones */
if (fit->second.mDoCallback)
{
if (fit->second->mDoCallback)
continue;
}
if ((fit->second).mCreator->finished())
{
if ((fit->second)->mCreator->finished())
continue;
}
/* make RsFileTransfer item for save list */
RsFileTransfer *rft = new RsFileTransfer();
/* what data is important? */
rft->file.name = fit->second.mName;
rft->file.hash = fit->second.mHash;
rft->file.filesize = fit->second.mSize;
rft->file.path = RsDirUtil::removeTopDir(fit->second.mDestination); /* remove fname */
rft->flags = fit->second.mFlags;
rft->state = fit->second.mState;
fit->second.mTransfer->getFileSources(rft->allPeerIds.ids);
rft->file.name = fit->second->mName;
rft->file.hash = fit->second->mHash;
rft->file.filesize = fit->second->mSize;
rft->file.path = RsDirUtil::removeTopDir(fit->second->mDestination); /* remove fname */
rft->flags = fit->second->mFlags;
rft->state = fit->second->mState;
fit->second->mTransfer->getFileSources(rft->allPeerIds.ids);
// just avoid uninitialised memory reads
rft->in = 0 ;
rft->cPeerId = "" ;
rft->transferred = fit->second.mCreator->getRecvd();
rft->transferred = fit->second->mCreator->getRecvd();
rft->crate = 0 ;
rft->lrate = 0 ;
rft->trate = 0 ;
@ -1600,8 +1820,8 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
else
++sit ;
fit->second.mCreator->getAvailabilityMap(rft->compressed_chunk_map) ;
rft->chunk_strategy = fit->second.mCreator->getChunkStrategy() ;
fit->second->mCreator->getAvailabilityMap(rft->compressed_chunk_map) ;
rft->chunk_strategy = fit->second->mCreator->getChunkStrategy() ;
saveData.push_back(rft);
}
@ -1649,9 +1869,9 @@ bool ftController::loadList(std::list<RsItem *> load)
{
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 << "Storing the map in a wait list." << std::endl ;
@ -1661,8 +1881,8 @@ bool ftController::loadList(std::list<RsItem *> load)
}
else
{
(fit->second).mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
(fit->second).mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
(fit->second)->mCreator->setAvailabilityMap(rsft->compressed_chunk_map) ;
(fit->second)->mCreator->setChunkStrategy((FileChunksInfo::ChunkStrategy)(rsft->chunk_strategy)) ;
}
}
}

View File

@ -66,7 +66,11 @@ class ftFileControl
{
public:
enum {DOWNLOADING,COMPLETED,ERROR_COMPLETION};
enum { DOWNLOADING = 0,
COMPLETED = 1,
ERROR_COMPLETION = 2,
QUEUED = 3
};
ftFileControl();
ftFileControl(std::string fname, std::string tmppath, std::string dest,
@ -86,6 +90,8 @@ class ftFileControl
uint32_t mCallbackCode;
time_t mCreateTime;
DwlSpeed mPriority ;
uint32_t mQueuePriority ;
uint32_t mQueuePosition ;
};
class ftPendingRequest
@ -115,93 +121,106 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
/* Setup */
ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir);
void setFtSearchNExtra(ftSearch *, ftExtraList *);
void setTurtleRouter(p3turtle *) ;
bool activate();
bool isActiveAndNoPending();
void setFtSearchNExtra(ftSearch *, ftExtraList *);
void setTurtleRouter(p3turtle *) ;
bool activate();
bool isActiveAndNoPending();
void setShareDownloadDirectory(bool value);
bool getShareDownloadDirectory();
void setShareDownloadDirectory(bool value);
bool getShareDownloadDirectory();
virtual void run();
virtual void run();
/***************************************************************/
/********************** 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,
std::list<std::string> &sourceIds);
/// 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 FileControl(std::string hash, uint32_t flags);
bool FileClearCompleted();
bool FlagFileComplete(std::string hash);
bool getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info);
bool FileCancel(std::string hash);
bool FileControl(std::string hash, uint32_t flags);
bool FileClearCompleted();
bool FlagFileComplete(std::string hash);
bool getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info);
bool getPriority(const std::string& hash,DwlSpeed& p);
void setPriority(const std::string& hash,DwlSpeed p);
// Download speed
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 */
bool FileDownloads(std::list<std::string> &hashs);
bool FileDownloads(std::list<std::string> &hashs);
/* Directory Handling */
bool setDownloadDirectory(std::string path);
bool setPartialsDirectory(std::string path);
std::string getDownloadDirectory();
std::string getPartialsDirectory();
bool FileDetails(std::string hash, FileInfo &info);
bool setDownloadDirectory(std::string path);
bool setPartialsDirectory(std::string path);
std::string getDownloadDirectory();
std::string getPartialsDirectory();
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 *************************/
/***************************************************************/
/// Returns true is full source availability can be assumed for this peer.
///
bool assumeAvailability(const std::string& peer_id) const ;
/// Returns true is full source availability can be assumed for this peer.
///
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);
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
protected:
void cleanCacheDownloads() ;
void tickTransfers() ;
virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size);
void cleanCacheDownloads() ;
void tickTransfers() ;
/***************************************************************/
/********************** 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 */
protected:
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
bool loadConfigMap(std::map<std::string, std::string> &configMap);
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
bool loadConfigMap(std::map<std::string, std::string> &configMap);
private:
/* RunTime Functions */
void checkDownloadQueue();
bool completeFile(std::string hash);
bool handleAPendingRequest();
void checkDownloadQueue(); // check the whole queue for inactive files
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);
time_t last_save_time ;
@ -215,9 +234,11 @@ bool setPeerState(ftTransferModule *tm, std::string id,
RsMutex ctrlMutex;
std::list<FileInfo> incomingQueue;
std::map<std::string, ftFileControl> mCompleted;
std::map<std::string, ftFileControl> mDownloads;
// std::list<FileInfo> incomingQueue;
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, ftFileCreator *> mFileCreators;
@ -227,9 +248,9 @@ bool setPeerState(ftTransferModule *tm, std::string id,
std::string mPartialsPath;
/**** SPEED QUEUES ****/
std::list<std::string> mSlowQueue;
std::list<std::string> mStreamQueue;
std::list<std::string> mFastQueue;
// std::list<std::string> mSlowQueue;
// std::list<std::string> mStreamQueue;
// std::list<std::string> mFastQueue;
/* callback list (for File Completion) */
RsMutex doneMutex;
@ -244,9 +265,7 @@ bool setPeerState(ftTransferModule *tm, std::string id,
/* share incoming directory */
bool mShareDownloadDir;
// priority handling
//
std::vector< std::vector<ftTransferModule*> > mPriorityTab ;
uint32_t _max_active_downloads ; // maximum number of simultaneous downloads
};
#endif

View File

@ -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)
{
/*
@ -32,8 +32,8 @@ ftFileCreator::ftFileCreator(std::string path, uint64_t size, std::string hash,
std::cerr << "\thash: " << hash;
std::cerr << std::endl;
#endif
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
_last_recv_time_t = time(NULL) ;
}
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 ;
}
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()
{
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 << std::endl;
#endif
/* dodgey checking outside of mutex...
* much check again inside FileAttrs().
*/
/* dodgey checking outside of mutex... much check again inside FileAttrs(). */
/* Check File is open */
if (fd == NULL)
if (!initializeFileAttrs())
return false;
@ -98,15 +113,6 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
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))
{
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;
}
pos = ftello64(fd);
#ifdef FILE_DEBUG
std::cerr << "ftFileCreator::addFileData() added Data...";
std::cerr << std::endl;
@ -204,6 +208,7 @@ int ftFileCreator::initializeFileAttrs()
*/
fd = fopen64(file_name.c_str(), "r+b");
if (!fd)
{
std::cerr << "ftFileCreator::initializeFileAttrs() Failed to open (r+b): ";
@ -230,21 +235,15 @@ int ftFileCreator::initializeFileAttrs()
* move to the end
*/
if (0 != fseeko64(fd, 0L, SEEK_END))
{
std::cerr << "ftFileCreator::initializeFileAttrs() Seek Failed" << std::endl;
return 0;
}
// if (0 != fseeko64(fd, 0L, SEEK_END))
// {
// std::cerr << "ftFileCreator::initializeFileAttrs() Seek Failed" << std::endl;
// 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;
#endif
/* start from there! */
// mStart = recvdsize;
// mEnd = recvdsize;
#endif
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
chunkMap.dataReceived(chunk.id) ;
_last_recv_time_t = time(NULL) ;
/* otherwise there is another earlier block to go
*/

View File

@ -40,7 +40,7 @@ class ftFileCreator: public ftFileProvider
{
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();
@ -49,6 +49,9 @@ class ftFileCreator: public ftFileProvider
bool finished() ;
uint64_t getRecvd();
/// (temporarily) close the file, to save file descriptors.
void closeFile() ;
void getChunkMap(FileChunksInfo& info) ;
void setChunkStrategy(FileChunksInfo::ChunkStrategy s) ;
@ -70,6 +73,9 @@ class ftFileCreator: public ftFileProvider
//
void removeInactiveChunks() ;
// Returns the time stamp of the last data receive.
time_t lastRecvTimeStamp() ;
// actually store data in the file, and update chunks info
//
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;
ChunkMap chunkMap ;
time_t _last_recv_time_t ; /// last time stamp when data was received.
};
#endif // FT_FILE_CREATOR_HEADER

View File

@ -35,7 +35,7 @@ const int ftserverzone = 29539;
#include "ft/ftcontroller.h"
#include "ft/ftfileprovider.h"
#include "ft/ftdatamultiplex.h"
#include "ft/ftdwlqueue.h"
//#include "ft/ftdwlqueue.h"
#include "turtle/p3turtle.h"
@ -151,7 +151,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
mConnMgr->addMonitor(mFtController);
mConnMgr->addMonitor(mCacheStrapper);
mFtDwlQueue = new ftDwlQueue(mFtController);
// mFtDwlQueue = new ftDwlQueue(mFtController);
return;
}
@ -160,7 +160,6 @@ void ftServer::connectToTurtleRouter(p3turtle *fts)
{
mTurtleRouter = fts ;
// mFtSearch->addSearchMode(fts, RS_FILE_HINTS_TURTLE);
mFtController->setTurtleRouter(fts) ;
}
@ -185,8 +184,8 @@ void ftServer::StartupThreads()
/* Dataplex */
mFtDataplex->start();
/* Download Queue */
mFtDwlQueue->start();
// /* Download Queue */
// mFtDwlQueue->start();
/* start own thread */
start();
@ -263,12 +262,9 @@ bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size, s
std::cerr << "Requesting " << fname << std::endl ;
if(mFtController->alreadyHaveFile(hash))
if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds))
return false ;
const DwlDetails details(fname, hash, size, dest, flags, srcIds, PRIORITY_NORMAL);
mFtDwlQueue->insertDownload(details);
return true ;
}
@ -281,7 +277,6 @@ bool ftServer::FileCancel(std::string hash)
{
// Remove from both queue and ftController, by default.
//
mFtDwlQueue->clearDownload(hash);
mFtController->FileCancel(hash);
return true ;
@ -297,10 +292,19 @@ bool ftServer::FileClearCompleted()
return mFtController->FileClearCompleted();
}
/* Control of Downloads Priority. */
bool ftServer::changeQueuePriority(const std::string hash, int priority)
void ftServer::setQueueSize(uint32_t s)
{
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)
{
@ -316,29 +320,15 @@ bool ftServer::getDownloadSpeed(const std::string hash, int & speed)
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)
{
return true ;
}
void ftServer::clearQueue()
{
mFtDwlQueue->clearQueue();
}
void ftServer::getDwlDetails(std::list<DwlDetails> & details)
{
mFtDwlQueue->getDwlDetails(details);
}
//void ftServer::getDwlDetails(std::list<DwlDetails> & details)
//{
// mFtDwlQueue->getDwlDetails(details);
//}
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_extra.cfg", mFtExtra);
cfgmgr->addConfiguration("ft_transfers.cfg", mFtController);
cfgmgr->addConfiguration("ft_dwlqueue.cfg", mFtDwlQueue);
// cfgmgr->addConfiguration("ft_dwlqueue.cfg", mFtDwlQueue);
return true;
}

View File

@ -129,13 +129,13 @@ virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrat
/***
* 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 getQueuePriority(const std::string hash, int & priority);
virtual bool getDownloadSpeed(const std::string hash, int & speed);
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

View File

@ -178,7 +178,7 @@ HEADERS += dbase/cachestrapper.h \
ft/ftchunkmap.h \
ft/ftserver.h \
ft/fttransfermodule.h \
ft/ftdwlqueue.h \
# ft/ftdwlqueue.h \
pqi/authssl.h \
pqi/authgpg.h \
pqi/cleanupxpgp.h \
@ -323,7 +323,7 @@ SOURCES += \
ft/ftdata.cc \
ft/ftchunkmap.cc \
ft/ftfileprovider.cc \
ft/ftdwlqueue.cc \
# ft/ftdwlqueue.cc \
dht/opendhtmgr.cc \
upnp/upnphandler.cc \
dht/opendht.cc \

View File

@ -119,13 +119,13 @@ class RsFiles
/***
* 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 getQueuePriority(const std::string hash, int & priority) = 0;
virtual bool getDownloadSpeed(const std::string hash, int & speed) = 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.

View File

@ -39,13 +39,12 @@ typedef std::string RsChanId;
typedef std::string RsMsgId;
typedef std::string RsAuthId;
#ifndef FT_STATE_FAILED
const uint32_t FT_STATE_FAILED = 0x0000;
const uint32_t FT_STATE_OKAY = 0x0001;
const uint32_t FT_STATE_WAITING = 0x0002;
const uint32_t FT_STATE_DOWNLOADING = 0x0003;
const uint32_t FT_STATE_COMPLETE = 0x0004;
#endif
const uint32_t FT_STATE_FAILED = 0x0000 ;
const uint32_t FT_STATE_OKAY = 0x0001 ;
const uint32_t FT_STATE_WAITING = 0x0002 ;
const uint32_t FT_STATE_DOWNLOADING = 0x0003 ;
const uint32_t FT_STATE_COMPLETE = 0x0004 ;
const uint32_t FT_STATE_QUEUED = 0x0005 ;
class TransferInfo
{
@ -57,10 +56,10 @@ class TransferInfo
int status; /* FT_STATE_... */
};
enum DwlPriority { PRIORITY_LOW = 0x00,
PRIORITY_NORMAL = 0x01,
PRIORITY_HIGH = 0x02,
PRIORITY_AUTO = 0x03
enum QueueMove { QUEUE_TOP = 0x00,
QUEUE_UP = 0x01,
QUEUE_DOWN = 0x02,
QUEUE_BOTTOM = 0x03
};
enum DwlSpeed { SPEED_LOW = 0x00,
@ -106,6 +105,7 @@ class FileInfo
double rank;
int age;
uint32_t queue_position ;
/* Transfer Stuff */
uint64_t transfered;
@ -336,9 +336,9 @@ class DwlDetails {
public:
DwlDetails() { return; }
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),
srcIds(srcIds), priority(priority), retries(0) { return; }
srcIds(srcIds), queue_position(queue_pos), retries(0) { return; }
/* download details */
std::string fname;
@ -349,7 +349,7 @@ public:
std::list<std::string> srcIds;
/* internally used in download queue */
DwlPriority priority;
uint32_t queue_position;
/* how many times a failed dwl will be requeued */
unsigned int retries;

View File

@ -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
{
public:

View File

@ -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(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();
for(std::map<TurtleTunnelId,TurtleTunnel>::const_iterator it(_local_tunnels.begin());it!=_local_tunnels.end();++it)

View File

@ -219,13 +219,13 @@ void FileTransferInfoWidget::draw(const FileInfo& nfo,const FileChunksInfo& info
y += block_sep ;
y += text_height ; painter->drawText(20,y,tr("File hash: ")) ; painter->drawText(tab_size,y,QString::fromStdString(nfo.hash)) ;
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 += 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 += text_height ; painter->drawText(20,y,tr("Number of chunks: ")) ; painter->drawText(tab_size,y,QString::number(info.chunks.size())) ;
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 += 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 ;

View File

@ -92,7 +92,7 @@ TransfersDialog::TransfersDialog(QWidget *parent)
DLListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress / Availability", "i.e: % downloaded"));
DLListModel->setHeaderData(SOURCES, Qt::Horizontal, tr("Sources", "i.e: Sources"));
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(DOWNLOADTIME, Qt::Horizontal, tr("Download time", "i.e: Estimated Time of Arrival / Time left"));
DLListModel->setHeaderData(ID, Qt::Horizontal, tr("Core-ID"));
@ -302,17 +302,17 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
QMenu *viewMenu = new QMenu( tr("View"), this );
clearQueueAct = new QAction(QIcon(), tr("Remove all queued"), this);
connect(clearQueueAct, SIGNAL(triggered()), this, SLOT(clearQueue()));
// clearQueueAct = new QAction(QIcon(), tr("Remove all queued"), this);
// connect(clearQueueAct, SIGNAL(triggered()), this, SLOT(clearQueue()));
priorityLowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Low"), this);
connect(priorityLowAct, SIGNAL(triggered()), this, SLOT(priorityQueueLow()));
priorityNormalAct = new QAction(QIcon(IMAGE_PRIORITYNORMAL), tr("Normal"), this);
connect(priorityNormalAct, SIGNAL(triggered()), this, SLOT(priorityQueueNormal()));
priorityHighAct = new QAction(QIcon(IMAGE_PRIORITYHIGH), tr("High"), this);
connect(priorityHighAct, SIGNAL(triggered()), this, SLOT(priorityQueueHigh()));
priorityAutoAct = new QAction(QIcon(IMAGE_PRIORITYAUTO), tr("Auto"), this);
connect(priorityAutoAct, SIGNAL(triggered()), this, SLOT(priorityQueueAuto()));
priorityLowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Down"), this);
connect(priorityLowAct, SIGNAL(triggered()), this, SLOT(priorityQueueDown()));
priorityNormalAct = new QAction(QIcon(IMAGE_PRIORITYNORMAL), tr("Up"), this);
connect(priorityNormalAct, SIGNAL(triggered()), this, SLOT(priorityQueueUp()));
priorityHighAct = new QAction(QIcon(IMAGE_PRIORITYHIGH), tr("Top"), this);
connect(priorityHighAct, SIGNAL(triggered()), this, SLOT(priorityQueueTop()));
priorityAutoAct = new QAction(QIcon(IMAGE_PRIORITYAUTO), tr("Bottom"), this);
connect(priorityAutoAct, SIGNAL(triggered()), this, SLOT(priorityQueueBottom()));
prioritySlowAct = new QAction(QIcon(IMAGE_PRIORITYLOW), tr("Slower"), this);
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);
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->addAction(priorityLowAct);
priorityQueueMenu->addAction(priorityNormalAct);
priorityQueueMenu->addAction(priorityHighAct);
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->addAction(prioritySlowAct);
prioritySpeedMenu->addAction(priorityMediumAct);
@ -386,7 +386,10 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
contextMnu.addAction( pauseAct);
if(!all_downld)
contextMnu.addAction( resumeAct);
if(info.downloadStatus != FT_STATE_COMPLETE)
contextMnu.addAction( cancelAct);
contextMnu.addSeparator();
}
@ -410,7 +413,7 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
#endif
contextMnu.addAction( pastelinkAct);
contextMnu.addSeparator();
contextMnu.addAction( clearQueueAct);
// contextMnu.addAction( clearQueueAct);
contextMnu.addSeparator();
contextMnu.addMenu( viewMenu);
@ -491,13 +494,16 @@ bool TransfersDialog::addPeerToItem(int row, const QString& name, const QString&
//try to find the item
int childRow = -1;
int count = 0;
QStandardItem* childId=NULL ;
while (QStandardItem* childId = dlItem->child(count, ID)) {
if (childId->data(Qt::DisplayRole).toString() == coreID) {
for(count=0; (childId = dlItem->child(count, ID)) != NULL;++count)
{
std::cerr << "data = " << childId->data(Qt::DisplayRole).toString().toStdString() << ", compared to " << coreID.toStdString() << std::endl ;
if (childId->data(Qt::DisplayRole).toString() == coreID)
{
childRow = count;
break;
}
count++;
}
if (childRow == -1) {
//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 *i8 = new QStandardItem(); i8->setData(QVariant(QString()), Qt::DisplayRole); // blank field for priority
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 */
if (status == "Downloading") {
@ -539,6 +546,7 @@ bool TransfersDialog::addPeerToItem(int row, const QString& name, const QString&
items.append(i8);
items.append(i9);
items.append(i10);
items.append(i11);
dlItem->appendRow(items);
} else {
//just update the child (peer)
@ -604,13 +612,14 @@ void TransfersDialog::updateDisplay()
{
insertTransfers();
}
void TransfersDialog::insertTransfers() {
void TransfersDialog::insertTransfers()
{
/* get the download lists */
std::list<std::string> downHashes;
rsFiles->FileDownloads(downHashes);
std::list<DwlDetails> dwlDetails;
rsFiles->getDwlDetails(dwlDetails);
// std::list<DwlDetails> dwlDetails;
// rsFiles->getDwlDetails(dwlDetails);
//first clean the model in case some files are not download anymore
//remove items that are not fiends anymore
@ -625,16 +634,16 @@ void TransfersDialog::insertTransfers() {
break;
}
}
if (!found) {
//look in the queued files
std::list<DwlDetails>::iterator dwlDetailsIt;
for (dwlDetailsIt = dwlDetails.begin(); dwlDetailsIt != dwlDetails.end(); dwlDetailsIt++) {
if (hash == dwlDetailsIt->hash) {
found = true;
break;
}
}
}
// if (!found) {
// //look in the queued files
// std::list<DwlDetails>::iterator dwlDetailsIt;
// for (dwlDetailsIt = dwlDetails.begin(); dwlDetailsIt != dwlDetails.end(); dwlDetailsIt++) {
// if (hash == dwlDetailsIt->hash) {
// found = true;
// break;
// }
// }
// }
if (!found) {
DLListModel->takeRow(removeIndex);
} else {
@ -642,6 +651,7 @@ void TransfersDialog::insertTransfers() {
}
}
// clear all source peers.
std::list<std::string>::iterator it;
for (it = downHashes.begin(); it != downHashes.end(); it++) {
@ -670,7 +680,7 @@ void TransfersDialog::insertTransfers() {
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;
switch (info.downloadStatus) {
@ -679,11 +689,17 @@ void TransfersDialog::insertTransfers() {
case FT_STATE_WAITING: status = tr("Waiting"); break;
case FT_STATE_DOWNLOADING: status = tr("Downloading"); break;
case FT_STATE_COMPLETE: status = tr("Complete"); break;
case FT_STATE_QUEUED: status = tr("Queued"); break;
default: status = tr("Unknown"); break;
}
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_NORMAL: priority = tr("Average");break;
case SPEED_HIGH: priority = tr("Faster");break;
@ -694,7 +710,6 @@ void TransfersDialog::insertTransfers() {
qlonglong remaining = info.size - info.transfered;
qlonglong downloadtime = (info.size - info.transfered) / (info.tfRate * 1024.0);
FileChunksInfo fcinfo ;
if(!rsFiles->FileDownloadChunksDetails(*it,fcinfo))
continue ;
@ -743,13 +758,14 @@ void TransfersDialog::insertTransfers() {
peerpinfo.progress = 0.0 ; // we don't display completion for sources.
peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size();
// std::cerr << 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)
// std::cerr << peerpinfo.cmap._map[j] ;
// std::cerr << std::endl ;
// std::cerr << std::endl ;
// std::cerr << 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)
// std::cerr << peerpinfo.cmap._map[j] ;
// 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);
}
}
@ -757,26 +773,26 @@ void TransfersDialog::insertTransfers() {
/* here i will insert files from the download queue - which are
* not started yet and can't be find in FileDownloads
* */
std::list<DwlDetails>::iterator dit;
for (dit = dwlDetails.begin(); dit != dwlDetails.end(); dit ++)
{
// switch (dit->priority) {
// case 0: priority = tr("Low"); break;
// case 1: priority = tr("Normal"); break;
// case 2: priority = tr("High"); break;
// case 3: priority = tr("Auto"); break;
// default: priority = tr("Auto"); break;
// }
FileProgressInfo pinfo ;
pinfo.progress = 0.0 ;
pinfo.nb_chunks = 0 ;
addItem("", QString::fromUtf8(dit->fname.c_str()),
QString::fromStdString(dit->hash), dit->count, pinfo, 0, 0,
tr("Queued"), "", 0, 0, 0);
}
// std::list<DwlDetails>::iterator dit;
// for (dit = dwlDetails.begin(); dit != dwlDetails.end(); dit ++)
// {
//// switch (dit->priority) {
//// case 0: priority = tr("Low"); break;
//// case 1: priority = tr("Normal"); break;
//// case 2: priority = tr("High"); break;
//// case 3: priority = tr("Auto"); break;
//// default: priority = tr("Auto"); break;
//// }
//
// FileProgressInfo pinfo ;
// pinfo.progress = 0.0 ;
// pinfo.nb_chunks = 0 ;
//
// addItem("", QString::fromUtf8(dit->fname.c_str()),
// QString::fromStdString(dit->hash), dit->count, pinfo, 0, 0,
// tr("Queued"), "", 0, 0, 0);
// }
//
std::list<std::string> upHashes;
rsFiles->FileUploads(upHashes);
@ -1261,10 +1277,10 @@ void TransfersDialog::openTransfer()
// rsFiles->clearDownload(hash);
// }
//}
void TransfersDialog::clearQueue()
{
rsFiles->clearQueue();
}
//void TransfersDialog::clearQueue()
//{
// rsFiles->clearQueue();
//}
void TransfersDialog::chunkStreaming()
{
@ -1299,21 +1315,21 @@ void TransfersDialog::speedFast()
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)
@ -1322,15 +1338,17 @@ void TransfersDialog::changeSpeed(int speed)
std::set<QStandardItem *>::iterator it;
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();
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 *>::iterator it;
getIdOfSelectedItems(items);
@ -1338,7 +1356,7 @@ void TransfersDialog::changeQueuePriority(int priority)
for (it = items.begin(); it != items.end(); it ++)
{
std::string hash = (*it)->data(Qt::DisplayRole).toString().toStdString();
rsFiles->changeQueuePriority(hash, priority);
rsFiles->changeQueuePosition(hash, mv);
}
}

View File

@ -84,20 +84,20 @@ private slots:
void previewTransfer();
/** clear download or all queue - for pending dwls */
void clearQueue();
// void clearQueue();
/** modify download priority actions */
void priorityQueueLow();
void priorityQueueNormal();
void priorityQueueHigh();
void priorityQueueAuto();
void priorityQueueUp();
void priorityQueueDown();
void priorityQueueTop();
void priorityQueueBottom();
void speedSlow();
void speedAverage();
void speedFast();
void changeSpeed(int) ;
void changeQueuePriority(int) ;
void changeQueuePosition(QueueMove) ;
void chunkRandom();
void chunkStreaming();
@ -143,8 +143,8 @@ private:
QAction *openfolderAct;
QAction *openfileAct;
QAction *previewfileAct;
QAction *clearQueuedDwlAct;
QAction *clearQueueAct;
// QAction *clearQueuedDwlAct;
// QAction *clearQueueAct;
QAction *changePriorityAct;
QAction *prioritySlowAct;
QAction *priorityMediumAct;

View File

@ -137,7 +137,7 @@ LogicalOperator ExpressionWidget::getOperator()
Expression* ExpressionWidget::getRsExpression()
{
Expression * expr;
Expression * expr = NULL;
std::list<std::string> wordList;
int lowVal = 0;

View File

@ -27,6 +27,7 @@
#include <sstream>
#include "rsiface/rsiface.h"
#include "rsiface/rsfiles.h"
#include "rsiface/rspeers.h"
#include <QTimer>
@ -43,6 +44,9 @@ TransferPage::TransferPage(QWidget * parent, Qt::WFlags flags)
updateStatus();
ui._queueSize_SB->setValue(rsFiles->getQueueSize()) ;
QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -50,6 +54,11 @@ TransferPage::TransferPage(QWidget * parent, Qt::WFlags flags)
#endif
}
void TransferPage::updateQueueSize(int s)
{
rsFiles->setQueueSize(s) ;
}
void TransferPage::closeEvent (QCloseEvent * event)
{
QWidget::closeEvent(event);

View File

@ -42,6 +42,7 @@ class TransferPage: public ConfigPage
public slots:
void updateStatus();
void updateQueueSize(int) ;
private:

View File

@ -17,7 +17,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="Seite">
<attribute name="title">
@ -38,15 +38,18 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="queuespinBox">
<widget class="QSpinBox" name="_queueSize_SB">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>7</number>
<number>5</number>
</property>
</widget>
</item>

View File

@ -236,6 +236,11 @@ void xProgressBar::paint()
painter->setPen(textColor);
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)