added proper talking between pqihandler and GUI for maxrates fixing

This commit is contained in:
csoler 2016-06-08 22:44:28 -04:00
parent 509266a25b
commit 5a0fa66ac0
10 changed files with 97 additions and 37 deletions

View File

@ -2075,6 +2075,20 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
return true;
}
bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */
std::map<RsPeerId, peerState>::iterator it = mFriendList.find(pid) ;
if(mFriendList.end() == it)
return false ;
maxUp = it->second.maxUpRate ;
maxDn = it->second.maxDnRate ;
return true ;
}
bool p3PeerMgrIMPL::setMaxRates(const RsPeerId& pid,uint32_t maxUp,uint32_t maxDn)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2171,7 +2185,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
setLocation(pitem->peerId, pitem->location);
}
setMaxRates(pitem->peerId,pitem->maxUploadRate,pitem->maxDownloadRate) ;
#warning needs to talk to pqihandler from here
//setMaxRates(pitem->peerId,pitem->maxUploadRate,pitem->maxDownloadRate) ;
if (pitem->netMode == RS_NET_MODE_HIDDEN)
{

View File

@ -210,6 +210,7 @@ virtual uint32_t getHiddenType(const RsPeerId &ssl_id) = 0;
virtual int getFriendCount(bool ssl, bool online) = 0;
virtual bool setMaxRates(const RsPeerId& pid,uint32_t maxR,uint32_t minR)=0;
virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxR,uint32_t& minR)=0;
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
@ -325,6 +326,7 @@ virtual int getFriendCount(bool ssl, bool online);
virtual bool haveOnceConnected();
virtual bool setMaxRates(const RsPeerId& pid,uint32_t maxR,uint32_t minR);
virtual bool getMaxRates(const RsPeerId& pid,uint32_t& maxR,uint32_t& minR);
/************************************************************************************************/
/* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */

View File

@ -27,6 +27,7 @@
#include "util/rsdebug.h"
#include "util/rsstring.h"
#include "retroshare/rspeers.h"
#include <stdlib.h>
#include <time.h>
@ -113,27 +114,30 @@ int pqihandler::tick()
moreToTick = 1;
}
#endif
}
}
// static time_t last_print_time = 0 ;
// time_t now = time(NULL) ;
// if(now > last_print_time + 3)
// {
// std::map<uint16_t,uint32_t> per_service_count ;
// std::vector<uint32_t> per_priority_count ;
//
// ExtractOutQueueStatistics(per_service_count,per_priority_count) ;
//
// std::cerr << "PQIHandler outqueues: " << std::endl;
//
// for(std::map<uint16_t,uint32_t>::const_iterator it=per_service_count.begin();it!=per_service_count.end();++it)
// std::cerr << " " << std::hex << it->first << std::dec << " " << it->second << std::endl;
//
// for(int i=0;i<per_priority_count.size();++i)
// std::cerr << " " << i << " : " << per_priority_count[i] << std::endl;
//
// last_print_time = now ;
// }
static time_t last_print_time = 0 ;
time_t now = time(NULL) ;
if(now > last_print_time + 5)
{
// every 5 secs, update the max rates for all modules
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
for(std::map<RsPeerId, SearchModule *>::iterator it = mods.begin(); it != mods.end(); ++it)
{
// This is rather inelegant, but pqihandler has searchModules that are dynamically allocated, so the max rates
// need to be updated from inside.
uint32_t maxUp,maxDn ;
rsPeers->getPeerMaximumRates(it->first,maxUp,maxDn);
std::cerr << "Updating searchModule " << it->first << " max rates to " << maxUp << " - " << maxDn << std::endl;
it->second->mMaxDnRate = maxDn ;
it->second->mMaxUpRate = maxUp ;
}
last_print_time = now ;
}
UpdateRates();
return moreToTick;
@ -502,6 +506,7 @@ int pqihandler::UpdateRates()
for(it = mods.begin(); it != mods.end(); ++it)
{
SearchModule *mod = (it -> second);
mod -> pqi -> setMaxRate(true, in_max_bw);
mod -> pqi -> setMaxRate(false, out_max_bw);
}
@ -511,18 +516,15 @@ int pqihandler::UpdateRates()
for(it = mods.begin(); it != mods.end(); ++it)
{
SearchModule *mod = (it -> second);
if (mod -> pqi -> getMaxRate(false) < max_out_effective) {
mod -> pqi -> setMaxRate(false, max_out_effective);
}
if (mod -> pqi -> getMaxRate(false) > avail_out) {
mod -> pqi -> setMaxRate(false, avail_out);
}
if (mod -> pqi -> getMaxRate(true) < max_in_effective) {
mod -> pqi -> setMaxRate(true, max_in_effective);
}
if (mod -> pqi -> getMaxRate(true) > avail_in) {
mod -> pqi -> setMaxRate(true, avail_in);
}
if (mod -> pqi -> getMaxRate(false) < max_out_effective) mod -> pqi -> setMaxRate(false, max_out_effective);
if (mod -> pqi -> getMaxRate(false) > avail_out) mod -> pqi -> setMaxRate(false, avail_out);
if (mod -> pqi -> getMaxRate(true) < max_in_effective) mod -> pqi -> setMaxRate(true, max_in_effective);
if (mod -> pqi -> getMaxRate(true) > avail_in) mod -> pqi -> setMaxRate(true, avail_in);
// Caps the allowed max speeds to the user defined values, leaving more space for other peers.
if(mod->mMaxUpRate > 0 && mod->pqi->getMaxRate(false) > mod->mMaxUpRate) mod->pqi->setMaxRate(false, mod->mMaxUpRate) ;
if(mod->mMaxDnRate > 0 && mod->pqi->getMaxRate(true ) > mod->mMaxDnRate) mod->pqi->setMaxRate(true , mod->mMaxDnRate) ;
}
return 1;

View File

@ -39,8 +39,12 @@
class SearchModule
{
public:
RsPeerId peerid;
PQInterface *pqi;
SearchModule() { mMaxUpRate=0;mMaxDnRate=0;}
RsPeerId peerid ;
PQInterface *pqi;
uint32_t mMaxUpRate ; // max allowed speeds in kB/s
uint32_t mMaxDnRate ;
};
// Presents a P3 Face to the world!
@ -71,14 +75,18 @@ class pqihandler: public P3Interface, public pqiPublisher
#endif
// rate control.
void setMaxRate(const RsPeerId& pid,bool in, uint32_t val_kBs);
void setMaxRate(bool in, float val);
float getMaxRate(bool in);
void setMaxRates(const RsPeerId& pid,bool in,float val) ;
float getMaxRates(const RsPeerId& pid,bool in) ;
void getCurrentRates(float &in, float &out);
// TESTING INTERFACE.
int ExtractRates(std::map<RsPeerId, RsBwRates> &ratemap, RsBwRates &totals);
int ExtractTrafficInfo(std::list<RSTrafficClue> &out_lst, std::list<RSTrafficClue> &in_lst);
int ExtractTrafficInfo(std::list<RSTrafficClue> &out_lst, std::list<RSTrafficClue> &in_lst);
protected:
/* check to be overloaded by those that can
@ -118,6 +126,24 @@ protected:
float ticks_per_sec ;
};
inline void pqihandler::setMaxRate(const RsPeerId& pid,bool in,uint32_t val_kBs)
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
std::map<RsPeerId, SearchModule *>::iterator it = mods.find(pid);
if(it == mods.end())
{
std::cerr << "(EE) no search module for pid " << pid << ": cannot set max rate" << std::endl;
return ;
}
if(in)
it->second->mMaxDnRate = val_kBs ;
else
it->second->mMaxUpRate = val_kBs ;
}
inline void pqihandler::setMaxRate(bool in, float val)
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/

View File

@ -293,8 +293,8 @@ public:
/* Data Rate Control - to be moved here */
virtual int SetMaxDataRates( int downKb, int upKb ) = 0;
virtual int GetMaxDataRates( int &inKb, int &outKb ) = 0;
virtual int GetCurrentDataRates( float &inKb, float &outKb ) = 0;
};
#endif

View File

@ -433,6 +433,7 @@ public:
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) = 0;
virtual bool setPeerMaximumRates(const RsPeerId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate) =0;
virtual bool getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate) =0;
};
#endif

View File

@ -241,6 +241,11 @@ bool p3Peers::isFriend(const RsPeerId &ssl_id)
return mPeerMgr->isFriend(ssl_id);
}
bool p3Peers::getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate)
{
return mPeerMgr->getMaxRates(pid,maxUploadRate,maxDownloadRate) ;
}
bool p3Peers::setPeerMaximumRates(const RsPeerId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate)
{
return mPeerMgr->setMaxRates(pid,maxUploadRate,maxDownloadRate) ;

View File

@ -140,6 +140,7 @@ public:
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags);
virtual bool setPeerMaximumRates(const RsPeerId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate);
virtual bool getPeerMaximumRates(const RsPeerId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate);
private:
p3LinkMgr *mLinkMgr;

View File

@ -503,6 +503,13 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
return true;
}
int p3ServerConfig::SetMaxDataRates(const RsPeerId& pid, int downKb, int upKb ) /* in kbrates */
{
mPqiHandler->setMaxRate(pid,true,downKb) ;
mPqiHandler->setMaxRate(pid,false,upKb) ;
return true ;
}
/* handle data rates.
* Mutex must be handled at the lower levels: TODO */

View File

@ -95,6 +95,7 @@ virtual bool setOperatingMode(uint32_t opMode);
virtual int SetMaxDataRates( int downKb, int upKb );
virtual int GetMaxDataRates( int &downKb, int &upKb );
virtual int GetCurrentDataRates( float &inKb, float &outKb );
virtual int SetMaxDataRates(const RsPeerId& pid, int downKb, int upKb );
/********************* ABOVE is RsConfig Interface *******/