From 8884a324bb359a1c344400fef58fab35bc0fb797 Mon Sep 17 00:00:00 2001 From: Phenom Date: Mon, 11 Sep 2017 20:18:06 +0200 Subject: [PATCH] Fix Uninitilized Peer Max Rates. When called by /libretroshare/src/pqi/pqihandler.cc:140 --- libretroshare/src/pqi/p3peermgr.cc | 31 +++++++++++++++++------------ libretroshare/src/pqi/pqihandler.cc | 23 ++++++++++----------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 68df7f01f..d62d2ca08 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2080,19 +2080,24 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list& saveData) bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn) { - RsPgpId pgp_id ; - - { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - - std::map::const_iterator it = mFriendList.find(pid) ; - - if(it == mFriendList.end()) - return false ; - - pgp_id = it->second.gpg_id ; - } - return getMaxRates(pgp_id,maxUp,maxDn) ; + RsPgpId pgp_id ; + + { + RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ + + std::map::const_iterator it = mFriendList.find(pid) ; + + if(it == mFriendList.end()) + { + maxUp = 0; + maxDn = 0; + return false ; + } + + pgp_id = it->second.gpg_id ; + } + + return getMaxRates(pgp_id,maxUp,maxDn) ; } bool p3PeerMgrIMPL::getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn) diff --git a/libretroshare/src/pqi/pqihandler.cc b/libretroshare/src/pqi/pqihandler.cc index 11744a71b..c67bd04a2 100644 --- a/libretroshare/src/pqi/pqihandler.cc +++ b/libretroshare/src/pqi/pqihandler.cc @@ -126,23 +126,22 @@ int pqihandler::tick() } time_t now = time(NULL) ; - + 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 ****************/ for(std::map::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); - - it->second->pqi->setRateCap(maxDn,maxUp);// mind the order! Dn first, than Up. + { + // 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 = 0,maxDn =0 ; + if (rsPeers->getPeerMaximumRates(it->first,maxUp,maxDn) ) + it->second->pqi->setRateCap(maxDn,maxUp);// mind the order! Dn first, than Up. } - - mLastRateCapUpdate = now ; + + mLastRateCapUpdate = now ; } UpdateRates();