Fix Uninitilized Peer Max Rates.

When called by /libretroshare/src/pqi/pqihandler.cc:140
This commit is contained in:
Phenom 2017-09-11 20:18:06 +02:00
parent 66bf1884a8
commit 8884a324bb
2 changed files with 29 additions and 25 deletions

View file

@ -2080,19 +2080,24 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn) bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn)
{ {
RsPgpId pgp_id ; RsPgpId pgp_id ;
{ {
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::map<RsPeerId, peerState>::const_iterator it = mFriendList.find(pid) ; std::map<RsPeerId, peerState>::const_iterator it = mFriendList.find(pid) ;
if(it == mFriendList.end()) if(it == mFriendList.end())
return false ; {
maxUp = 0;
pgp_id = it->second.gpg_id ; maxDn = 0;
} return false ;
return getMaxRates(pgp_id,maxUp,maxDn) ; }
pgp_id = it->second.gpg_id ;
}
return getMaxRates(pgp_id,maxUp,maxDn) ;
} }
bool p3PeerMgrIMPL::getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn) bool p3PeerMgrIMPL::getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn)

View file

@ -126,23 +126,22 @@ int pqihandler::tick()
} }
time_t now = time(NULL) ; time_t now = time(NULL) ;
if(now > mLastRateCapUpdate + 5) if(now > mLastRateCapUpdate + 5)
{ {
// every 5 secs, update the max rates for all modules // every 5 secs, update the max rates for all modules
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
for(std::map<RsPeerId, SearchModule *>::iterator it = mods.begin(); it != mods.end(); ++it) 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 // This is rather inelegant, but pqihandler has searchModules that are dynamically allocated, so the max rates
// need to be updated from inside. // need to be updated from inside.
uint32_t maxUp,maxDn ; uint32_t maxUp = 0,maxDn =0 ;
rsPeers->getPeerMaximumRates(it->first,maxUp,maxDn); if (rsPeers->getPeerMaximumRates(it->first,maxUp,maxDn) )
it->second->pqi->setRateCap(maxDn,maxUp);// mind the order! Dn first, than Up.
it->second->pqi->setRateCap(maxDn,maxUp);// mind the order! Dn first, than Up.
} }
mLastRateCapUpdate = now ; mLastRateCapUpdate = now ;
} }
UpdateRates(); UpdateRates();