mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
restaured priority queue methods, and made better context menues.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2135 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7b35b7dc6a
commit
7fd5c7ad4b
12 changed files with 207 additions and 178 deletions
|
@ -63,7 +63,7 @@ static const uint32_t INACTIVE_CHUNKS_CHECK_DELAY = 60 ; // save transfer progre
|
|||
ftFileControl::ftFileControl()
|
||||
:mTransfer(NULL), mCreator(NULL),
|
||||
mState(0), mSize(0), mFlags(0),
|
||||
mPriority(PRIORITY_NORMAL)
|
||||
mPriority(SPEED_NORMAL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ ftFileControl::ftFileControl(std::string fname,
|
|||
:mName(fname), mCurrentPath(tmppath), mDestination(dest),
|
||||
mTransfer(tm), mCreator(fc), mState(0), mHash(hash),
|
||||
mSize(size), mFlags(flags), mDoCallback(false), mCallbackCode(cb),
|
||||
mPriority(PRIORITY_NORMAL) // default priority to normal
|
||||
mPriority(SPEED_NORMAL) // default priority to normal
|
||||
{
|
||||
if (cb)
|
||||
mDoCallback = true;
|
||||
|
@ -253,39 +253,17 @@ void ftController::tickTransfers()
|
|||
|
||||
// 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 ;
|
||||
// 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 ;
|
||||
|
||||
std::cerr << "Priority tabs: " ;
|
||||
std::cerr << "Low (" << mPriorityTab[PRIORITY_LOW ].size() << ") " ;
|
||||
std::cerr << "Normal (" << mPriorityTab[PRIORITY_NORMAL].size() << ") " ;
|
||||
std::cerr << "High (" << mPriorityTab[PRIORITY_HIGH ].size() << ") " ;
|
||||
std::cerr << "Low (" << mPriorityTab[SPEED_LOW ].size() << ") " ;
|
||||
std::cerr << "Normal (" << mPriorityTab[SPEED_NORMAL].size() << ") " ;
|
||||
std::cerr << "High (" << mPriorityTab[SPEED_HIGH ].size() << ") " ;
|
||||
std::cerr << std::endl ;
|
||||
|
||||
// float probs[3] = { (!mPriorityTab[PRIORITY_LOW ].empty())* LOW_PRIORITY_PROB,
|
||||
// (!mPriorityTab[PRIORITY_NORMAL].empty())*NORMAL_PRIORITY_PROB,
|
||||
// (!mPriorityTab[PRIORITY_HIGH ].empty())* HIGH_PRIORITY_PROB } ;
|
||||
//
|
||||
// float total = probs[0]+probs[1]+probs[2] ;
|
||||
// float cumul_probs[3] = { probs[0], probs[0]+probs[1], probs[0]+probs[1]+probs[2] } ;
|
||||
//
|
||||
// float r = rand()/(float)RAND_MAX * total;
|
||||
// int chosen ;
|
||||
//
|
||||
// if(total == 0.0)
|
||||
// return ;
|
||||
//
|
||||
// if(r < cumul_probs[0])
|
||||
// chosen = 0 ;
|
||||
// else if(r < cumul_probs[1])
|
||||
// chosen = 1 ;
|
||||
// else
|
||||
// chosen = 2 ;
|
||||
//
|
||||
// std::cerr << "chosen: " << chosen << std::endl ;
|
||||
|
||||
/* tick the transferModules */
|
||||
|
||||
// start anywhere in the chosen list of transfers, so that not to favor any special transfer
|
||||
|
@ -299,31 +277,9 @@ void ftController::tickTransfers()
|
|||
for(int i=0;i<(int)mPriorityTab[chosen].size();++i)
|
||||
mPriorityTab[chosen][(i+start)%(int)mPriorityTab[chosen].size()]->tick() ;
|
||||
}
|
||||
|
||||
// {
|
||||
//
|
||||
//#ifdef CONTROL_DEBUG
|
||||
// std::cerr << "\tTicking: " << it->first;
|
||||
// std::cerr << std::endl;
|
||||
//#endif
|
||||
//
|
||||
// if (it->second.mTransfer)
|
||||
// {
|
||||
//#ifdef CONTROL_DEBUG
|
||||
// std::cerr << "\tTicking mTransfer: " << (void*)it->second.mTransfer;
|
||||
// std::cerr << std::endl;
|
||||
//#endif
|
||||
// (it->second.mTransfer)->tick();
|
||||
// }
|
||||
//#ifdef CONTROL_DEBUG
|
||||
// else
|
||||
// std::cerr << "No mTransfer for this hash." << std::endl ;
|
||||
//#endif
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
bool ftController::getPriority(const std::string& hash,DwlPriority& p)
|
||||
bool ftController::getPriority(const std::string& hash,DwlSpeed& p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
|
@ -337,7 +293,7 @@ bool ftController::getPriority(const std::string& hash,DwlPriority& p)
|
|||
else
|
||||
return false ;
|
||||
}
|
||||
void ftController::setPriority(const std::string& hash,DwlPriority p)
|
||||
void ftController::setPriority(const std::string& hash,DwlSpeed p)
|
||||
{
|
||||
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class ftFileControl
|
|||
bool mDoCallback;
|
||||
uint32_t mCallbackCode;
|
||||
time_t mCreateTime;
|
||||
DwlPriority mPriority ;
|
||||
DwlSpeed mPriority ;
|
||||
};
|
||||
|
||||
class ftPendingRequest
|
||||
|
@ -144,8 +144,8 @@ bool FileClearCompleted();
|
|||
bool FlagFileComplete(std::string hash);
|
||||
bool getFileDownloadChunksDetails(const std::string& hash,FileChunksInfo& info);
|
||||
|
||||
bool getPriority(const std::string& hash,DwlPriority& p);
|
||||
void setPriority(const std::string& hash,DwlPriority p);
|
||||
bool getPriority(const std::string& hash,DwlSpeed& p);
|
||||
void setPriority(const std::string& hash,DwlSpeed p);
|
||||
|
||||
/* get Details of File Transfers */
|
||||
bool FileDownloads(std::list<std::string> &hashs);
|
||||
|
|
|
@ -263,7 +263,12 @@ bool ftServer::setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStr
|
|||
|
||||
bool ftServer::FileCancel(std::string hash)
|
||||
{
|
||||
return mFtController->FileCancel(hash);
|
||||
// Remove from both queue and ftController, by default.
|
||||
//
|
||||
mFtDwlQueue->clearDownload(hash);
|
||||
mFtController->FileCancel(hash);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::FileControl(std::string hash, uint32_t flags)
|
||||
|
@ -277,26 +282,35 @@ bool ftServer::FileClearCompleted()
|
|||
}
|
||||
|
||||
/* Control of Downloads Priority. */
|
||||
bool ftServer::changePriority(const std::string hash, int priority)
|
||||
bool ftServer::changeQueuePriority(const std::string hash, int priority)
|
||||
{
|
||||
mFtController->setPriority(hash, (DwlPriority) priority);
|
||||
return mFtDwlQueue->changePriority(hash,(DwlPriority)priority) ;
|
||||
}
|
||||
bool ftServer::changeDownloadSpeed(const std::string hash, int speed)
|
||||
{
|
||||
mFtController->setPriority(hash, (DwlSpeed)speed);
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool ftServer::getPriority(const std::string hash, int & priority)
|
||||
bool ftServer::getDownloadSpeed(const std::string hash, int & speed)
|
||||
{
|
||||
DwlPriority _priority;
|
||||
int ret = mFtController->getPriority(hash, _priority);
|
||||
if (ret) {
|
||||
priority = _priority;
|
||||
}
|
||||
DwlSpeed _speed;
|
||||
int ret = mFtController->getPriority(hash, _speed);
|
||||
if (ret)
|
||||
speed = _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 mFtDwlQueue->clearDownload(hash);
|
||||
}
|
||||
|
||||
void ftServer::clearQueue()
|
||||
|
|
|
@ -125,8 +125,10 @@ virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrat
|
|||
/***
|
||||
* Control of Downloads Priority.
|
||||
***/
|
||||
virtual bool changePriority(const std::string hash, int priority);
|
||||
virtual bool getPriority(const std::string hash, int & priority);
|
||||
virtual bool changeQueuePriority(const std::string hash, int priority);
|
||||
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);
|
||||
|
|
|
@ -119,8 +119,10 @@ class RsFiles
|
|||
/***
|
||||
* Control of Downloads Priority.
|
||||
***/
|
||||
virtual bool changePriority(const std::string hash, int priority) = 0;
|
||||
virtual bool getPriority(const std::string hash, int & priority) = 0;
|
||||
virtual bool changeQueuePriority(const std::string hash, int priority) = 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;
|
||||
|
|
|
@ -63,6 +63,12 @@ enum DwlPriority { PRIORITY_LOW = 0x00,
|
|||
PRIORITY_AUTO = 0x03
|
||||
};
|
||||
|
||||
enum DwlSpeed { SPEED_LOW = 0x00,
|
||||
SPEED_NORMAL = 0x01,
|
||||
SPEED_HIGH = 0x02
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FileInfo
|
||||
{
|
||||
|
@ -107,7 +113,7 @@ class FileInfo
|
|||
uint32_t downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
|
||||
std::list<TransferInfo> peers;
|
||||
|
||||
DwlPriority priority ;
|
||||
DwlSpeed priority ;
|
||||
time_t lastTS;
|
||||
};
|
||||
|
||||
|
|
|
@ -950,11 +950,8 @@ bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std
|
|||
/* try to load it, and get Id */
|
||||
|
||||
std::string location;
|
||||
if (LoadCheckX509andGetLocation(cert_name.c_str(), location, sslId) == 0) {
|
||||
std::cerr << "RsInit::GenerateSSLCertificate() Cannot check own signature, maybe the files are corrupted." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = LoadCheckX509andGetLocation(cert_name.c_str(), location, sslId) ;
|
||||
|
||||
std::cout << "LoadCheckX509andGetLocation: returned " << ret << ", sslId=" << sslId << std::endl ;
|
||||
|
||||
if(!ret)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue