mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-05 01:25:39 -05:00
improved strategy for merging pending ID load requests, fixing bug in previous commit
This commit is contained in:
parent
59d08591d2
commit
8fdd255185
@ -700,8 +700,37 @@ bool p3IdService::havePrivateKey(const RsGxsId &id)
|
||||
return mKeyCache.is_cached(id) ;
|
||||
}
|
||||
|
||||
static void mergeIds(std::map<RsGxsId,std::list<RsPeerId> >& idmap,const RsGxsId& id,const std::list<RsPeerId>& peers)
|
||||
{
|
||||
// merge the two lists (I use a std::set to make it more efficient)
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "p3IdService::requestKey(): merging list with existing pending request." << std::endl;
|
||||
#endif
|
||||
|
||||
std::list<RsPeerId>& old_peers(idmap[id]) ; // create if necessary
|
||||
std::set<RsPeerId> new_peers ;
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(peers.begin());it!=peers.end();++it)
|
||||
new_peers.insert(*it) ;
|
||||
|
||||
for(std::list<RsPeerId>::iterator it(old_peers.begin());it!=old_peers.end();++it)
|
||||
new_peers.insert(*it) ;
|
||||
|
||||
old_peers.clear();
|
||||
|
||||
for(std::set<RsPeerId>::iterator it(new_peers.begin());it!=new_peers.end();++it)
|
||||
old_peers.push_back(*it) ;
|
||||
}
|
||||
|
||||
bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers)
|
||||
{
|
||||
if(id.isNull())
|
||||
{
|
||||
std::cerr << "(EE) nul ID requested to p3IdService. This should not happen. Callstack:" << std::endl;
|
||||
print_stacktrace();
|
||||
return false ;
|
||||
}
|
||||
|
||||
if (haveKey(id))
|
||||
return true;
|
||||
else
|
||||
@ -712,14 +741,13 @@ bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers
|
||||
|
||||
if(rit != mIdsNotPresent.end())
|
||||
{
|
||||
locked_mergeIdsToRequestFromNet(id,peers) ;
|
||||
if(!peers.empty())
|
||||
mergeIds(mIdsNotPresent,id,peers) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
if(peers.empty())
|
||||
std::cerr << "(EE) empty peer list in ID request from net. This is bound to fail!" << std::endl;
|
||||
|
||||
return cache_request_load(id, peers);
|
||||
}
|
||||
|
||||
@ -734,27 +762,6 @@ bool p3IdService::isPendingNetworkRequest(const RsGxsId& gxsId)
|
||||
return false;
|
||||
}
|
||||
|
||||
void p3IdService::locked_mergeIdsToRequestFromNet(const RsGxsId& id,const std::list<RsPeerId>& peers)
|
||||
{
|
||||
// merge the two lists (I use a std::set to make it more efficient)
|
||||
|
||||
std::cerr << "p3IdService::requestKey(): merging list with existing pending request." << std::endl;
|
||||
|
||||
std::list<RsPeerId>& old_peers(mIdsNotPresent[id]) ; // create if necessary
|
||||
std::set<RsPeerId> new_peers ;
|
||||
|
||||
for(std::list<RsPeerId>::const_iterator it(peers.begin());it!=peers.end();++it)
|
||||
new_peers.insert(*it) ;
|
||||
|
||||
for(std::list<RsPeerId>::iterator it(old_peers.begin());it!=old_peers.end();++it)
|
||||
new_peers.insert(*it) ;
|
||||
|
||||
old_peers.clear();
|
||||
|
||||
for(std::set<RsPeerId>::iterator it(new_peers.begin());it!=new_peers.end();++it)
|
||||
old_peers.push_back(*it) ;
|
||||
}
|
||||
|
||||
bool p3IdService::getKey(const RsGxsId &id, RsTlvPublicRSAKey &key)
|
||||
{
|
||||
{
|
||||
@ -2048,7 +2055,8 @@ bool p3IdService::cache_request_load(const RsGxsId &id, const std::list<RsPeerId
|
||||
|
||||
{
|
||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
||||
mCacheLoad_ToCache.insert(std::make_pair(id, peers));
|
||||
|
||||
mergeIds(mCacheLoad_ToCache,id,peers) ; // merge, even if peers is empty
|
||||
}
|
||||
|
||||
if (RsTickEvent::event_count(GXSID_EVENT_CACHELOAD) > 0)
|
||||
@ -2087,10 +2095,12 @@ bool p3IdService::cache_start_load()
|
||||
std::cerr << "p3IdService::cache_start_load() GroupId: " << it->first;
|
||||
std::cerr << std::endl;
|
||||
#endif // DEBUG_IDS
|
||||
groupIds.push_back(RsGxsGroupId(it->first.toStdString())); // might need conversion?
|
||||
groupIds.push_back(RsGxsGroupId(it->first)); // might need conversion?
|
||||
}
|
||||
|
||||
mPendingCache.insert(mCacheLoad_ToCache.begin(), mCacheLoad_ToCache.end());
|
||||
for(std::map<RsGxsId,std::list<RsPeerId> >::const_iterator it(mCacheLoad_ToCache.begin());it!=mCacheLoad_ToCache.end();++it)
|
||||
mergeIds(mPendingCache,it->first,it->second) ;
|
||||
|
||||
mCacheLoad_ToCache.clear();
|
||||
}
|
||||
|
||||
@ -2160,8 +2170,11 @@ bool p3IdService::cache_load_for_token(uint32_t token)
|
||||
|
||||
RsStackMutex stack(mIdMtx);
|
||||
|
||||
// No need to merge empty peers since the request would fail.
|
||||
|
||||
for(std::map<RsGxsId,std::list<RsPeerId> >::const_iterator itt(mPendingCache.begin());itt!=mPendingCache.end();++itt)
|
||||
locked_mergeIdsToRequestFromNet(itt->first,itt->second) ;
|
||||
if(!itt->second.empty())
|
||||
mergeIds(mIdsNotPresent,itt->first,itt->second) ;
|
||||
|
||||
mPendingCache.clear();
|
||||
|
||||
|
@ -351,7 +351,6 @@ private:
|
||||
bool cache_update_if_cached(const RsGxsId &id, std::string serviceString);
|
||||
|
||||
bool isPendingNetworkRequest(const RsGxsId& gxsId);
|
||||
void locked_mergeIdsToRequestFromNet(const RsGxsId& id,const std::list<RsPeerId>& peers);
|
||||
void requestIdsFromNet();
|
||||
|
||||
// Mutex protected.
|
||||
|
Loading…
x
Reference in New Issue
Block a user