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; 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) bool p3PeerMgrIMPL::setMaxRates(const RsPeerId& pid,uint32_t maxUp,uint32_t maxDn)
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2171,7 +2185,8 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
setLocation(pitem->peerId, pitem->location); 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) 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 int getFriendCount(bool ssl, bool online) = 0;
virtual bool setMaxRates(const RsPeerId& pid,uint32_t maxR,uint32_t minR)=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) ********/ /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
@ -325,6 +326,7 @@ virtual int getFriendCount(bool ssl, bool online);
virtual bool haveOnceConnected(); virtual bool haveOnceConnected();
virtual bool setMaxRates(const RsPeerId& pid,uint32_t maxR,uint32_t minR); 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) */ /* Extra IMPL Functions (used by p3LinkMgr, p3NetMgr + Setup) */

View File

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

View File

@ -39,8 +39,12 @@
class SearchModule class SearchModule
{ {
public: public:
RsPeerId peerid; SearchModule() { mMaxUpRate=0;mMaxDnRate=0;}
RsPeerId peerid ;
PQInterface *pqi; PQInterface *pqi;
uint32_t mMaxUpRate ; // max allowed speeds in kB/s
uint32_t mMaxDnRate ;
}; };
// Presents a P3 Face to the world! // Presents a P3 Face to the world!
@ -71,9 +75,13 @@ class pqihandler: public P3Interface, public pqiPublisher
#endif #endif
// rate control. // rate control.
void setMaxRate(const RsPeerId& pid,bool in, uint32_t val_kBs);
void setMaxRate(bool in, float val); void setMaxRate(bool in, float val);
float getMaxRate(bool in); 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); void getCurrentRates(float &in, float &out);
// TESTING INTERFACE. // TESTING INTERFACE.
@ -118,6 +126,24 @@ protected:
float ticks_per_sec ; 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) inline void pqihandler::setMaxRate(bool in, float val)
{ {
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/

View File

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

View File

@ -433,6 +433,7 @@ public:
virtual void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags) = 0; 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 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 #endif

View File

@ -241,6 +241,11 @@ bool p3Peers::isFriend(const RsPeerId &ssl_id)
return mPeerMgr->isFriend(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) bool p3Peers::setPeerMaximumRates(const RsPeerId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate)
{ {
return mPeerMgr->setMaxRates(pid,maxUploadRate,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 void setServicePermissionFlags(const RsPgpId& gpg_id,const ServicePermissionFlags& flags);
virtual bool setPeerMaximumRates(const RsPeerId& pid,uint32_t maxUploadRate,uint32_t maxDownloadRate); 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: private:
p3LinkMgr *mLinkMgr; p3LinkMgr *mLinkMgr;

View File

@ -503,6 +503,13 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
return true; 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. /* handle data rates.
* Mutex must be handled at the lower levels: TODO */ * 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 SetMaxDataRates( int downKb, int upKb );
virtual int GetMaxDataRates( int &downKb, int &upKb ); virtual int GetMaxDataRates( int &downKb, int &upKb );
virtual int GetCurrentDataRates( float &inKb, float &outKb ); virtual int GetCurrentDataRates( float &inKb, float &outKb );
virtual int SetMaxDataRates(const RsPeerId& pid, int downKb, int upKb );
/********************* ABOVE is RsConfig Interface *******/ /********************* ABOVE is RsConfig Interface *******/