attempt at fixing circle cache loop. Renamed a few variables and fixed logic. Not yet fully working

This commit is contained in:
csoler 2016-03-14 23:19:37 -04:00
parent 83e39d8ae5
commit bdb326a989
8 changed files with 121 additions and 106 deletions

View File

@ -1139,6 +1139,8 @@ void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
}
delete n;
}
changes.clear() ;
RsServer::notify()->notifyGxsChange(out);
}
@ -2798,12 +2800,14 @@ void RsGenExchange::processRecvdGroups()
// group has been validated. Let's notify the global router for the clue
if(!meta->mAuthorId.isNull())
{
#ifdef GEN_EXCH_DEBUG
std::cerr << "Group routage info: Identity=" << meta->mAuthorId << " from " << grp->PeerId() << std::endl;
std::cerr << "Group routage info: Identity=" << meta->mAuthorId << " from " << grp->PeerId() << std::endl;
#endif
if(!meta->mAuthorId.isNull())
mRoutingClues[meta->mAuthorId].insert(grp->PeerId()) ;
mRoutingClues[meta->mAuthorId].insert(grp->PeerId()) ;
}
// This has been moved here (as opposed to inside part for new groups below) because it is used to update the server TS when updates
// of grp metadata arrive.

View File

@ -111,8 +111,8 @@ class RsGxsCircleDetails
&& mCircleName == rGxsDetails.mCircleName
&& mCircleType == rGxsDetails.mCircleType
&& mIsExternal == rGxsDetails.mIsExternal
&& mUnknownPeers == rGxsDetails.mUnknownPeers
&& mAllowedPeers == rGxsDetails.mAllowedPeers
&& mAllowedAnonPeers == rGxsDetails.mAllowedAnonPeers
&& mAllowedSignedPeers == rGxsDetails.mAllowedSignedPeers
);
}
@ -121,13 +121,13 @@ class RsGxsCircleDetails
|| mCircleName != rGxsDetails.mCircleName
|| mCircleType != rGxsDetails.mCircleType
|| mIsExternal != rGxsDetails.mIsExternal
|| mUnknownPeers != rGxsDetails.mUnknownPeers
|| mAllowedPeers != rGxsDetails.mAllowedPeers
|| mAllowedAnonPeers != rGxsDetails.mAllowedAnonPeers
|| mAllowedSignedPeers != rGxsDetails.mAllowedSignedPeers
);
}
std::set<RsGxsId> mUnknownPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedPeers;
std::set<RsGxsId> mAllowedAnonPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedSignedPeers;
};
class RsGxsCircles: public RsGxsIfaceHelper

View File

@ -177,66 +177,72 @@ void p3GxsCircles::service_tick()
void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::notifyChanges()";
std::cerr << std::endl;
std::cerr << "p3GxsCircles::notifyChanges()";
std::cerr << std::endl;
#endif
std::vector<RsGxsNotify *>::iterator it;
for(it = changes.begin(); it != changes.end(); ++it)
{
RsGxsGroupChange *groupChange = dynamic_cast<RsGxsGroupChange *>(*it);
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
if (msgChange && !msgChange->metaChange())
{
std::vector<RsGxsNotify *>::iterator it;
for(it = changes.begin(); it != changes.end(); ++it)
{
RsGxsGroupChange *groupChange = dynamic_cast<RsGxsGroupChange *>(*it);
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
if (msgChange && !msgChange->metaChange())
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::notifyChanges() Found Message Change Notification";
std::cerr << std::endl;
std::cerr << " Found Message Change Notification";
std::cerr << std::endl;
#endif
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::notifyChanges() Msgs for Group: " << mit->first;
std::cerr << std::endl;
std::cerr << " Msgs for Group: " << mit->first;
std::cerr << std::endl;
#endif
}
}
}
}
/* add groups to ExternalIdList (Might get Personal Circles here until NetChecks in place) */
if (groupChange && !groupChange->metaChange())
{
/* add groups to ExternalIdList (Might get Personal Circles here until NetChecks in place) */
if (groupChange && !groupChange->metaChange())
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::notifyChanges() Found Group Change Notification";
std::cerr << std::endl;
std::cerr << " Found Group Change Notification";
std::cerr << std::endl;
#endif
std::list<RsGxsGroupId> &groupList = groupChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for(git = groupList.begin(); git != groupList.end(); ++git)
{
std::list<RsGxsGroupId> &groupList = groupChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for(git = groupList.begin(); git != groupList.end(); ++git)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::notifyChanges() Incoming Group: " << *git << ". Forcing cache load." << std::endl;
std::cerr << " Incoming Group: " << *git << ". Forcing cache load." << std::endl;
#endif
// for new circles we need to add them to the list.
// we don't know the type of this circle here
// original behavior was to add all ids to the external ids list
addCircleIdToList(RsGxsCircleId(*git), 0);
cache_request_load(RsGxsCircleId(*git)) ;
// reset the cached circle data for this id
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleCache.erase(RsGxsCircleId(*git));
}
}
}
}
RsGxsIfaceHelper::receiveChanges(changes);
// for new circles we need to add them to the list.
// we don't know the type of this circle here
// original behavior was to add all ids to the external ids list
addCircleIdToList(RsGxsCircleId(*git), 0);
// reset the cached circle data for this id
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleCache.erase(RsGxsCircleId(*git));
}
}
}
if(groupChange)
for(std::list<RsGxsGroupId>::const_iterator git(groupChange->mGrpIdList.begin());git!=groupChange->mGrpIdList.end();++git)
{
#ifdef DEBUG_CIRCLES
std::cerr << " forcing cache loading for circle " << *git << " in order to trigger subscribe update." << std::endl;
#endif
cache_request_load(RsGxsCircleId(*git)) ;
}
}
RsGxsIfaceHelper::receiveChanges(changes); // this clear up the vector and delete its elements
}
/********************************************************************************/
@ -264,8 +270,8 @@ bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails
details.mCircleType = data.mCircleType;
details.mIsExternal = data.mIsExternal;
details.mUnknownPeers = data.mUnknownPeers;
details.mAllowedPeers = data.mAllowedPeers;
details.mAllowedAnonPeers = data.mAllowedAnonPeers;
details.mAllowedSignedPeers = data.mAllowedSignedPeers;
return true;
}
}
@ -392,10 +398,10 @@ bool p3GxsCircles::recipients(const RsGxsCircleId& circleId, std::list<RsGxsId>&
if(!getCircleDetails(circleId, details))
return false;
for(std::set<RsGxsId>::const_iterator it(details.mUnknownPeers.begin());it!=details.mUnknownPeers.end();++it)
for(std::set<RsGxsId>::const_iterator it(details.mAllowedAnonPeers.begin());it!=details.mAllowedAnonPeers.end();++it)
gxs_ids.push_back(*it) ;
for(std::map<RsPgpId,std::list<RsGxsId> >::const_iterator it(details.mAllowedPeers.begin());it!=details.mAllowedPeers.end();++it)
for(std::map<RsPgpId,std::list<RsGxsId> >::const_iterator it(details.mAllowedSignedPeers.begin());it!=details.mAllowedSignedPeers.end();++it)
for(std::list<RsGxsId>::const_iterator it2(it->second.begin());it2!=it->second.end();++it2)
gxs_ids.push_back(*it2) ;
@ -525,7 +531,7 @@ bool RsGxsCircleCache::loadBaseCircle(const RsGxsCircleGroup &circle)
mCircleId = RsGxsCircleId(circle.mMeta.mGroupId);
mCircleName = circle.mMeta.mGroupName;
mUpdateTime = time(NULL);
mProcessedCircles.insert(mCircleId);
// mProcessedCircles.insert(mCircleId);
mCircleType = circle.mMeta.mCircleType;
mIsExternal = (mCircleType != GXS_CIRCLE_TYPE_LOCAL);
@ -556,7 +562,7 @@ bool RsGxsCircleCache::loadSubCircle(const RsGxsCircleCache &subcircle)
bool RsGxsCircleCache::getAllowedPeersList(std::list<RsPgpId> &friendlist)
{
std::map<RsPgpId, std::list<RsGxsId> >::iterator it;
for(it = mAllowedPeers.begin(); it != mAllowedPeers.end(); ++it)
for(it = mAllowedSignedPeers.begin(); it != mAllowedSignedPeers.end(); ++it)
{
friendlist.push_back(it->first);
}
@ -565,8 +571,8 @@ bool RsGxsCircleCache::getAllowedPeersList(std::list<RsPgpId> &friendlist)
bool RsGxsCircleCache::isAllowedPeer(const RsPgpId &id)
{
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = mAllowedPeers.find(id);
if (it != mAllowedPeers.end())
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = mAllowedSignedPeers.find(id);
if (it != mAllowedSignedPeers.end())
{
return true;
}
@ -576,7 +582,7 @@ bool RsGxsCircleCache::isAllowedPeer(const RsPgpId &id)
bool RsGxsCircleCache::addAllowedPeer(const RsPgpId &pgpId, const RsGxsId &gxsId)
{
/* created if doesn't exist */
std::list<RsGxsId> &gxsList = mAllowedPeers[pgpId];
std::list<RsGxsId> &gxsList = mAllowedSignedPeers[pgpId];
gxsList.push_back(gxsId);
return true;
}
@ -585,7 +591,7 @@ bool RsGxsCircleCache::addAllowedPeer(const RsPgpId &pgpId, const RsGxsId &gxsId
bool RsGxsCircleCache::addLocalFriend(const RsPgpId &pgpId)
{
/* empty list as no GxsID associated */
std::list<RsGxsId> &gxsList = mAllowedPeers[pgpId];
std::list<RsGxsId> &gxsList = mAllowedSignedPeers[pgpId];
return true;
}
@ -965,7 +971,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
std::cerr << "p3GxsCircles::cache_load_for_token() Is Unknown -> UnknownPeer: " << *pit;
std::cerr << std::endl;
#endif
cache.mUnknownPeers.insert(*pit);
cache.mAllowedAnonPeers.insert(*pit);
}
}
else
@ -1123,9 +1129,7 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
RsGxsCircleCache &cache = it->second;
/* try reload Ids */
std::set<RsGxsId>::const_iterator pit;
for(pit = cache.mUnprocessedPeers.begin();
pit != cache.mUnprocessedPeers.end(); ++pit)
for(std::set<RsGxsId>::const_iterator pit = cache.mUnprocessedPeers.begin(); pit != cache.mUnprocessedPeers.end(); ++pit)
{
/* check cache */
if (mIdentities->haveKey(*pit))
@ -1146,7 +1150,7 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
}
else
{
cache.mUnknownPeers.insert(*pit);
cache.mAllowedAnonPeers.insert(*pit);
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_reloadids() UnknownPeer: ";
@ -1176,8 +1180,10 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
cache.mUnprocessedPeers.clear();
// If sub-circles are complete too.
#ifdef SUBSCIRCLES
if (cache.mUnprocessedCircles.empty())
{
#endif
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_reloadids() Adding to cache Id: ";
std::cerr << circleId;
@ -1192,6 +1198,7 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
/* remove from loading queue */
mLoadingCache.erase(it);
#ifdef SUBSCIRCLES
}
else
{
@ -1199,6 +1206,7 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
std::cerr << circleId;
std::cerr << std::endl;
}
#endif
return true;
}
@ -1208,17 +1216,14 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId)
bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : ";
std::cerr << cache.mCircleId;
std::cerr << std::endl;
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : "<< cache.mCircleId << std::endl;
#endif
/* if processed already - ignore */
if (!(cache.mGroupStatus & GXS_SERV::GXS_GRP_STATUS_UNPROCESSED))
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : Already Processed";
std::cerr << std::endl;
std::cerr << " Already Processed" << std::endl;
#endif
return false;
@ -1228,8 +1233,7 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
if (!cache.mIsExternal)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : Personal Circle";
std::cerr << std::endl;
std::cerr << " Personal Circle. Nothing to do." << std::endl;
#endif
return false;
@ -1238,9 +1242,9 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
/* if we appear in the group - then autosubscribe, and mark as processed */
const RsPgpId& ownId = mPgpUtils->getPGPOwnId();
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedPeers.find(ownId);
bool am_I_allowed = it != cache.mAllowedPeers.end() ;
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedSignedPeers.find(ownId);
bool am_I_allowed = it != cache.mAllowedSignedPeers.end() ;
if(!am_I_allowed)
{
@ -1249,48 +1253,53 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
rsIdentity->getOwnIds(own_gxs_ids) ;
for(std::list<RsGxsId>::const_iterator it(own_gxs_ids.begin());it!=own_gxs_ids.end();++it)
if(cache.mUnknownPeers.end() != cache.mUnknownPeers.find(*it))
if(cache.mAllowedAnonPeers.end() != cache.mAllowedAnonPeers.find(*it))
{
am_I_allowed = true ;
#ifdef DEBUG_CIRCLES
std::cerr << " found own GxsId " << *it << " as being in the circle" << std::endl;
#endif
break ;
}
}
#ifdef DEBUG_CIRCLES
else
std::cerr << " found own PGP id as signed to one of the circle's GxsIds" << std::endl;
#endif
if(am_I_allowed)
{
#ifdef DEBUG_CIRCLES
/* we are part of this group - subscribe, clear unprocessed flag */
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() Found OwnId -> AutoSubscribe!";
std::cerr << std::endl;
std::cerr << " I'm allowed in this circle => AutoSubscribing!" << std::endl;
#endif
uint32_t token, token2;
RsGenExchange::subscribeToGroup(token, RsGxsGroupId(cache.mCircleId), true);
RsGenExchange::setGroupStatusFlags(token2, RsGxsGroupId(cache.mCircleId), 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
cache.mGroupStatus ^= GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
return true;
}
else if (cache.mUnknownPeers.empty())
else if (cache.mUnprocessedPeers.empty())
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() Know All Peers -> Processed";
std::cerr << std::endl;
std::cerr << " Not part of the group! Let's unsubscribe this circle of unfriendly Napoleons!" << std::endl;
#endif
/* we know all the peers - we are not part - we can flag as PROCESSED. */
uint32_t token;
uint32_t token,token2;
RsGenExchange::setGroupStatusFlags(token, RsGxsGroupId(cache.mCircleId.toStdString()), 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
RsGenExchange::subscribeToGroup(token2, RsGxsGroupId(cache.mCircleId), false);
cache.mGroupStatus ^= GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
return true ;
}
else
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() Leaving Unprocessed";
std::cerr << std::endl;
std::cerr << " Leaving Unprocessed" << std::endl;
#endif
// Don't clear UNPROCESSED - as we might not know all the peers.
// TODO - work out when we flag as PROCESSED.
}

View File

@ -146,12 +146,14 @@ class RsGxsCircleCache
uint32_t mGroupStatus;
time_t mUpdateTime;
#ifdef SUBSCIRCLES
std::set<RsGxsCircleId> mUnprocessedCircles;
std::set<RsGxsId> mUnprocessedPeers;
std::set<RsGxsCircleId> mProcessedCircles;
std::set<RsGxsId> mUnknownPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedPeers;
#endif
std::set<RsGxsId> mUnprocessedPeers;
std::set<RsGxsId> mAllowedAnonPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedSignedPeers;
};

View File

@ -315,7 +315,7 @@ void mark_circle_item(QTreeWidgetItem *item, const std::set<RsPgpId> &names)
std::set<RsPgpId>::iterator it;
for(it = names.begin(); it != names.end(); ++it)
{
if (details.mAllowedPeers.end() != details.mAllowedPeers.find(*it))
if (details.mAllowedSignedPeers.end() != details.mAllowedSignedPeers.find(*it))
{
set_item_background(item, GREEN_BACKGROUND);
std::cerr << "CirclesDialog mark_circle_item: found match: " << id;
@ -389,7 +389,7 @@ void CirclesDialog::circle_selected()
/* now mark all the members */
std::set<RsPgpId> members;
std::map<RsPgpId, std::list<RsGxsId> >::iterator it;
for(it = details.mAllowedPeers.begin(); it != details.mAllowedPeers.end(); ++it)
for(it = details.mAllowedSignedPeers.begin(); it != details.mAllowedSignedPeers.end(); ++it)
{
members.insert(it->first);
std::cerr << "Circle member: " << it->first;

View File

@ -281,8 +281,8 @@ void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype,
void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails)
{
typedef std::set<RsGxsId>::iterator itUnknownPeers;
for (itUnknownPeers it = cirDetails.mUnknownPeers.begin()
; it != cirDetails.mUnknownPeers.end()
for (itUnknownPeers it = cirDetails.mAllowedAnonPeers.begin()
; it != cirDetails.mAllowedAnonPeers.end()
; ++it) {
RsGxsId gxs_id = *it;
RsIdentityDetails gxs_details ;
@ -298,8 +298,8 @@ void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails)
}//for (itUnknownPeers it = cirDetails.mUnknownPeers.begin()
typedef std::map<RsPgpId, std::list<RsGxsId> >::const_iterator itAllowedPeers;
for (itAllowedPeers it = cirDetails.mAllowedPeers.begin()
; it != cirDetails.mAllowedPeers.end()
for (itAllowedPeers it = cirDetails.mAllowedSignedPeers.begin()
; it != cirDetails.mAllowedSignedPeers.end()
; ++it ) {
RsPgpId gpg_id = it->first;
RsPeerDetails details ;

View File

@ -532,9 +532,9 @@ void IdDialog::circle_selected()
/* now mark all the members */
std::set<RsGxsId> members = details.mUnknownPeers;
std::set<RsGxsId> members = details.mAllowedAnonPeers;
for(std::map<RsPgpId, std::list<RsGxsId> >::iterator it = details.mAllowedPeers.begin(); it != details.mAllowedPeers.end(); ++it)
for(std::map<RsPgpId, std::list<RsGxsId> >::iterator it = details.mAllowedSignedPeers.begin(); it != details.mAllowedSignedPeers.end(); ++it)
for(std::list<RsGxsId>::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
{
members.insert( (*it2) ) ;

View File

@ -54,8 +54,8 @@ void CircleWidget::updateData(const RsGroupMetaData& gxs_group_info
if (_circle_details != details) {
_circle_details=details;
typedef std::set<RsGxsId>::iterator itUnknownPeers;
for (itUnknownPeers it = _circle_details.mUnknownPeers.begin()
; it != _circle_details.mUnknownPeers.end()
for (itUnknownPeers it = _circle_details.mAllowedAnonPeers.begin()
; it != _circle_details.mAllowedAnonPeers.end()
; ++it) {
RsGxsId gxs_id = *it;
if(!gxs_id.isNull()) {
@ -64,8 +64,8 @@ void CircleWidget::updateData(const RsGroupMetaData& gxs_group_info
}//for (itUnknownPeers it = _circle_details.mUnknownPeers.begin()
typedef std::map<RsPgpId, std::list<RsGxsId> >::const_iterator itAllowedPeers;
for (itAllowedPeers it = _circle_details.mAllowedPeers.begin()
; it != _circle_details.mAllowedPeers.end()
for (itAllowedPeers it = _circle_details.mAllowedSignedPeers.begin()
; it != _circle_details.mAllowedSignedPeers.end()
; ++it ) {
RsPgpId pgp_id = it->first;
emit askForPGPIdentityWidget(pgp_id);