Fix list overwrite in RsGxsNetService::requestGrp

When requestGrp was called with different groups for same peer multiple
  times between ticks the list was overridden and groups from previous
  call overridden by the new, as a result some requested groups may be
  never really requested. Fix the bug by using a set instead of a list
  so the newly requested groups are uniquely added to the set without
  removing the previously added.
This commit is contained in:
Gioacchino Mazzurco 2021-03-08 20:07:07 +01:00
parent 51dbbfb222
commit 74dc476282
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
2 changed files with 19 additions and 24 deletions

View File

@ -256,10 +256,8 @@
#include "util/rstime.h"
#include "util/rsmemory.h"
#include "util/stacktrace.h"
#ifdef RS_DEEP_CHANNEL_INDEX
# include "deep_search/channelsindex.hpp"
#endif
#include "util/rsdebug.h"
#include "util/cxx17retrocompat.h"
/***
* Use the following defines to debug:
@ -4806,43 +4804,40 @@ uint32_t RsGxsNetService::getKeepAge(const RsGxsGroupId& grpId)
return locked_getGrpConfig(grpId).msg_keep_delay ;
}
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId)
int RsGxsNetService::requestGrp(
const std::list<RsGxsGroupId>& grpIds, const RsPeerId& peerId )
{
RS_STACK_MUTEX(mNxsMutex) ;
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(peerId) << "RsGxsNetService::requestGrp(): adding explicit group requests to peer " << peerId << std::endl;
for(std::list<RsGxsGroupId>::const_iterator it(grpId.begin());it!=grpId.end();++it)
GXSNETDEBUG_PG(peerId,*it) << " Group ID: " << *it << std::endl;
RS_DBG("Adding explicit groups requests to peer: ", peerId);
for(auto& grpId: std::as_const(grpIds)) RS_DBG("\t Group ID: ", grpId);
#endif
mExplicitRequest[peerId].assign(grpId.begin(), grpId.end());
RS_STACK_MUTEX(mNxsMutex);
mExplicitRequest[peerId].insert(grpIds.begin(), grpIds.end());
return 1;
}
void RsGxsNetService::processExplicitGroupRequests()
{
RS_STACK_MUTEX(mNxsMutex) ;
RS_STACK_MUTEX(mNxsMutex);
std::map<RsPeerId, std::list<RsGxsGroupId> >::const_iterator cit = mExplicitRequest.begin();
for(; cit != mExplicitRequest.end(); ++cit)
for(auto& cit: std::as_const(mExplicitRequest))
{
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(cit->first) << "RsGxsNetService::sending pending explicit group requests to peer " << cit->first << std::endl;
RS_DBG("sending pending explicit group requests to peer ", cit.first);
#endif
const RsPeerId& peerId = cit->first;
const std::list<RsGxsGroupId>& groupIdList = cit->second;
const RsPeerId& peerId = cit.first;
const std::set<RsGxsGroupId>& groupIdList = cit.second;
std::list<RsNxsItem*> grpSyncItems;
std::list<RsGxsGroupId>::const_iterator git = groupIdList.begin();
uint32_t transN = locked_getTransactionId();
for(; git != groupIdList.end(); ++git)
for(auto& grpId: std::as_const(groupIdList))
{
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(peerId) << " group request for grp ID " << *git << " to peer " << peerId << std::endl;
RS_DBG("\t group request for group ID: ", grpId);
#endif
RsNxsSyncGrpItem* item = new RsNxsSyncGrpItem(mServType);
item->grpId = *git;
RsNxsSyncGrpItem* item = new RsNxsSyncGrpItem(mServType);
item->grpId = grpId;
item->PeerId(peerId);
item->flag = RsNxsSyncGrpItem::FLAG_REQUEST;
item->transactionNumber = transN;

View File

@ -584,7 +584,7 @@ private:
std::vector<AuthorPending*> mPendingResp;
std::vector<GrpCircleVetting*> mPendingCircleVets;
std::map<RsGxsGroupId,std::set<RsPeerId> > mPendingPublishKeyRecipients ;
std::map<RsPeerId, std::list<RsGxsGroupId> > mExplicitRequest;
std::map<RsPeerId, std::set<RsGxsGroupId> > mExplicitRequest;
std::map<RsPeerId, std::set<RsGxsGroupId> > mPartialMsgUpdates ;
// nxs sync optimisation