moved memory ownership of RsGxsGrpMetaData down into RsGxsDataAccess. Avoids many copy-constructors of RsTlvSecurityKey. Will probably spare a lot of CPU on windows

This commit is contained in:
csoler 2018-01-07 21:41:41 +01:00
parent 57f41d9286
commit b42b8e3a51
14 changed files with 196 additions and 210 deletions

View File

@ -486,7 +486,7 @@ bool RsDataService::finishReleaseUpdate(int release, bool result)
return result; return result;
} }
RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c, int colOffset) RsGxsGrpMetaData* RsDataService::locked_getNewGrpMeta(RetroCursor &c, int colOffset)
{ {
#ifdef RS_DATA_SERVICE_DEBUG #ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::locked_getGrpMeta()"; std::cerr << "RsDataService::locked_getGrpMeta()";
@ -556,9 +556,10 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c, int colOffset
if(ok) if(ok)
return grpMeta; return grpMeta;
else else
{
delete grpMeta; delete grpMeta;
return NULL;
return NULL; }
} }
RsNxsGrp* RsDataService::locked_getGroup(RetroCursor &c) RsNxsGrp* RsDataService::locked_getGroup(RetroCursor &c)
@ -894,8 +895,14 @@ int RsDataService::storeGroup(const std::list<RsNxsGrp*>& grp)
void RsDataService::locked_clearGrpMetaCache(const RsGxsGroupId& gid) void RsDataService::locked_clearGrpMetaCache(const RsGxsGroupId& gid)
{ {
mGrpMetaDataCache.erase(gid) ; // cleans existing cache entry std::map<RsGxsGroupId,const RsGxsGrpMetaData*>::iterator it = mGrpMetaDataCache.find(gid) ;
mGrpMetaDataCache_ContainsAllDatabase = false;
if(it != mGrpMetaDataCache.end())
{
delete it->second ;
mGrpMetaDataCache.erase(it) ;
mGrpMetaDataCache_ContainsAllDatabase = false;
}
} }
int RsDataService::updateGroup(const std::list<RsNxsGrp *> &grp) int RsDataService::updateGroup(const std::list<RsNxsGrp *> &grp)
@ -1097,7 +1104,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>
if(g) if(g)
{ {
if (metaOffset) { if (metaOffset) {
g->metaData = locked_getGrpMeta(*c, metaOffset); g->metaData = locked_getNewGrpMeta(*c, metaOffset);
} }
grps.push_back(g); grps.push_back(g);
} }
@ -1274,7 +1281,7 @@ void RsDataService::locked_retrieveMsgMeta(RetroCursor *c, std::vector<RsGxsMsgM
} }
} }
int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData *>& grp) int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
{ {
#ifdef RS_DATA_SERVICE_DEBUG #ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::retrieveGxsGrpMetaData()"; std::cerr << "RsDataService::retrieveGxsGrpMetaData()";
@ -1297,100 +1304,110 @@ int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaDat
std::cerr << (void*)this << ": RsDataService::retrieveGxsGrpMetaData() retrieving all from cache!" << std::endl; std::cerr << (void*)this << ": RsDataService::retrieveGxsGrpMetaData() retrieving all from cache!" << std::endl;
#endif #endif
for(std::map<RsGxsGroupId,RsGxsGrpMetaData>::const_iterator it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it) grp = mGrpMetaDataCache ;
grp[it->first] = new RsGxsGrpMetaData(it->second); //for(std::map<RsGxsGroupId,RsGxsGrpMetaData>::const_iterator it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it)
// grp[it->first] = new RsGxsGrpMetaData(it->second);
} }
else else
{ {
#ifdef RS_DATA_SERVICE_DEBUG #ifdef RS_DATA_SERVICE_DEBUG
std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all" << std::endl; std::cerr << "RsDataService::retrieveGxsGrpMetaData() retrieving all" << std::endl;
#endif #endif
// clear the cache
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", ""); for(auto it(mGrpMetaDataCache.begin());it!=mGrpMetaDataCache.end();++it)
delete it->second ;
if(c) mGrpMetaDataCache.clear();
{
bool valid = c->moveToFirst();
while(valid) RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "", "");
{
RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0); if(c)
if(g) {
{ bool valid = c->moveToFirst();
grp[g->mGroupId] = g;
mGrpMetaDataCache[g->mGroupId] = *g ; while(valid)
{
RsGxsGrpMetaData* g = locked_getNewGrpMeta(*c, 0);
if(g)
{
grp[g->mGroupId] = g;
mGrpMetaDataCache[g->mGroupId] = g ;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << (void *)this << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl; std::cerr << (void *)this << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl;
#endif #endif
} }
valid = c->moveToNext(); valid = c->moveToNext();
#ifdef RS_DATA_SERVICE_DEBUG_TIME #ifdef RS_DATA_SERVICE_DEBUG_TIME
++resultCount; ++resultCount;
#endif #endif
} }
delete c; delete c;
} }
mGrpMetaDataCache_ContainsAllDatabase = true ;
}
mGrpMetaDataCache_ContainsAllDatabase = true ;
} }
else
}else
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData *>::iterator mit = grp.begin(); std::map<RsGxsGroupId, const RsGxsGrpMetaData *>::iterator mit = grp.begin();
for(; mit != grp.end(); ++mit) for(; mit != grp.end(); ++mit)
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData>::const_iterator itt = mGrpMetaDataCache.find(mit->first) ; std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::const_iterator itt = mGrpMetaDataCache.find(mit->first) ;
if(itt != mGrpMetaDataCache.end()) if(itt != mGrpMetaDataCache.end())
{ {
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first << " from cache!" << std::endl; std::cerr << "Retrieving Grp metadata grpId=" << mit->first << " from cache!" << std::endl;
#endif #endif
grp[mit->first] = new RsGxsGrpMetaData(itt->second) ; grp[mit->first] = itt->second ;
} }
else else
{ {
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << "Retrieving Grp metadata grpId=" << mit->first ; std::cerr << "Retrieving Grp metadata grpId=" << mit->first ;
#endif #endif
const RsGxsGroupId& grpId = mit->first; const RsGxsGroupId& grpId = mit->first;
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", ""); RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", "");
if(c) if(c)
{ {
bool valid = c->moveToFirst(); bool valid = c->moveToFirst();
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
if(!valid) if(!valid)
std::cerr << " Empty query! GrpId " << grpId << " is not in database" << std::endl; std::cerr << " Empty query! GrpId " << grpId << " is not in database" << std::endl;
#endif #endif
while(valid) while(valid)
{ {
RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0); RsGxsGrpMetaData* g = locked_getNewGrpMeta(*c, 0);
if(g) if(g)
{ {
grp[g->mGroupId] = g; grp[g->mGroupId] = g;
mGrpMetaDataCache[g->mGroupId] = *g ; mGrpMetaDataCache[g->mGroupId] = g ;
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
std::cerr << ". Got it. Updating cache." << std::endl; std::cerr << ". Got it. Updating cache." << std::endl;
#endif #endif
} }
valid = c->moveToNext(); valid = c->moveToNext();
#ifdef RS_DATA_SERVICE_DEBUG_TIME #ifdef RS_DATA_SERVICE_DEBUG_TIME
++resultCount; ++resultCount;
#endif #endif
} }
delete c; delete c;
} }
#ifdef RS_DATA_SERVICE_DEBUG_CACHE #ifdef RS_DATA_SERVICE_DEBUG_CACHE
else else
std::cerr << ". not found!" << std::endl; std::cerr << ". not found!" << std::endl;
#endif #endif
} }
} }
} }
@ -1607,7 +1624,7 @@ bool RsDataService::locked_removeGroupEntries(const std::vector<RsGxsGroupId>& g
mDb->sqlDelete(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", ""); mDb->sqlDelete(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
// also remove the group meta from cache. // also remove the group meta from cache.
mGrpMetaDataCache.erase(*vit) ; locked_clearGrpMetaCache(*vit) ;
} }
ret &= mDb->commitTransaction(); ret &= mDb->commitTransaction();

View File

@ -71,7 +71,7 @@ public:
* @param cache whether to store retrieval in mem for faster later retrieval * @param cache whether to store retrieval in mem for faster later retrieval
* @return error code * @return error code
*/ */
int retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData*>& grp); int retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp);
/*! /*!
* Retrieves meta data of all groups stored (most current versions only) * Retrieves meta data of all groups stored (most current versions only)
@ -208,7 +208,7 @@ private:
* extracts a grp meta item from a cursor at its * extracts a grp meta item from a cursor at its
* current position * current position
*/ */
RsGxsGrpMetaData* locked_getGrpMeta(RetroCursor& c, int colOffset); RsGxsGrpMetaData* locked_getNewGrpMeta(RetroCursor& c, int colOffset);
/*! /*!
* extracts a msg item from a cursor at its * extracts a msg item from a cursor at its
@ -347,7 +347,7 @@ private:
void locked_clearGrpMetaCache(const RsGxsGroupId& gid); void locked_clearGrpMetaCache(const RsGxsGroupId& gid);
std::map<RsGxsGroupId,RsGxsGrpMetaData> mGrpMetaDataCache ; std::map<RsGxsGroupId,const RsGxsGrpMetaData*> mGrpMetaDataCache ;
bool mGrpMetaDataCache_ContainsAllDatabase ; bool mGrpMetaDataCache_ContainsAllDatabase ;
}; };

View File

@ -36,9 +36,9 @@
#include "rsitems/rsnxsitems.h" #include "rsitems/rsnxsitems.h"
#include "gxs/rsgxsdata.h" #include "gxs/rsgxsdata.h"
#include "rsgxs.h" #include "rsgxs.h"
#include "rsgxsutil.h"
#include "util/contentvalue.h" #include "util/contentvalue.h"
class RsGxsSearchModule { class RsGxsSearchModule {
public: public:
@ -61,6 +61,8 @@ public:
ContentValue val; ContentValue val;
}; };
typedef std::map<RsGxsGroupId,const RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
/*! /*!
* This allows modification of local * This allows modification of local
* meta data items of a group * meta data items of a group
@ -168,7 +170,7 @@ public:
* , if grpId is failed to be retrieved it will be erased from map * , if grpId is failed to be retrieved it will be erased from map
* @return error code * @return error code
*/ */
virtual int retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData*>& grp) = 0; virtual int retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp) = 0;
/*! /*!
* Retrieves meta data of all groups stored (most current versions only) * Retrieves meta data of all groups stored (most current versions only)

View File

@ -533,7 +533,7 @@ int RsGenExchange::createGroupSignatures(RsTlvKeySignatureSet& signSet, RsTlvBin
} }
int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinaryData& msgData, int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinaryData& msgData,
const RsGxsMsgMetaData& msgMeta, RsGxsGrpMetaData& grpMeta) const RsGxsMsgMetaData& msgMeta, const RsGxsGrpMetaData& grpMeta)
{ {
bool needPublishSign = false, needIdentitySign = false; bool needPublishSign = false, needIdentitySign = false;
uint32_t grpFlag = grpMeta.mGroupFlags; uint32_t grpFlag = grpMeta.mGroupFlags;
@ -714,8 +714,7 @@ int RsGenExchange::createMessage(RsNxsMsg* msg)
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::createMessage() " << std::endl; std::cerr << "RsGenExchange::createMessage() " << std::endl;
#endif #endif
std::map<RsGxsGroupId, RsGxsGrpMetaData*> metaMap; RsGxsGrpMetaTemporaryMap metaMap ;
metaMap.insert(std::make_pair(id, (RsGxsGrpMetaData*)(NULL))); metaMap.insert(std::make_pair(id, (RsGxsGrpMetaData*)(NULL)));
mDataStore->retrieveGxsGrpMetaData(metaMap); mDataStore->retrieveGxsGrpMetaData(metaMap);
@ -730,7 +729,7 @@ int RsGenExchange::createMessage(RsNxsMsg* msg)
else else
{ {
// get publish key // get publish key
RsGxsGrpMetaData* grpMeta = metaMap[id]; const RsGxsGrpMetaData* grpMeta = metaMap[id];
uint32_t metaDataLen = meta.serial_size(); uint32_t metaDataLen = meta.serial_size();
uint32_t allMsgDataLen = metaDataLen + msg->msg.bin_len; uint32_t allMsgDataLen = metaDataLen + msg->msg.bin_len;
@ -763,8 +762,6 @@ int RsGenExchange::createMessage(RsNxsMsg* msg)
delete[] metaData; delete[] metaData;
delete[] allMsgData; delete[] allMsgData;
delete grpMeta;
} }
if(ret_val == SIGN_FAIL) if(ret_val == SIGN_FAIL)
@ -1196,14 +1193,14 @@ bool RsGenExchange::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult
bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo) bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
{ {
std::list<RsGxsGrpMetaData*> metaL; std::list<const RsGxsGrpMetaData*> metaL;
bool ok = mDataAccess->getGroupSummary(token, metaL); bool ok = mDataAccess->getGroupSummary(token, metaL);
RsGroupMetaData m; RsGroupMetaData m;
for( std::list<RsGxsGrpMetaData*>::iterator lit = metaL.begin(); lit != metaL.end(); ++lit) for( auto lit = metaL.begin(); lit != metaL.end(); ++lit)
{ {
RsGxsGrpMetaData& gMeta = *(*lit); const RsGxsGrpMetaData& gMeta = *(*lit);
m = gMeta; m = gMeta;
RsGroupNetworkStats sts ; RsGroupNetworkStats sts ;
@ -1223,7 +1220,6 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaDat
} }
groupInfo.push_back(m); groupInfo.push_back(m);
delete (*lit);
} }
return ok; return ok;
@ -2083,15 +2079,15 @@ bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpC
RsGxsGrpMetaData* grpMeta = NULL; RsGxsGrpMetaData* grpMeta = NULL;
bool ok = false; bool ok = false;
std::map<RsGxsGroupId, RsGxsGrpMetaData* > grpMetaMap; RsGxsGrpMetaTemporaryMap grpMetaMap;
std::map<RsGxsGroupId, RsGxsGrpMetaData* >::iterator mit; std::map<RsGxsGroupId, const RsGxsGrpMetaData* >::iterator mit;
grpMetaMap.insert(std::make_pair(grpId, (RsGxsGrpMetaData*)(NULL))); grpMetaMap.insert(std::make_pair(grpId, (RsGxsGrpMetaData*)(NULL)));
mDataStore->retrieveGxsGrpMetaData(grpMetaMap); mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
if((mit = grpMetaMap.find(grpId)) != grpMetaMap.end()) if((mit = grpMetaMap.find(grpId)) != grpMetaMap.end())
{ {
grpMeta = mit->second; const RsGxsGrpMetaData *grpMeta = mit->second;
if (!grpMeta) if (!grpMeta)
{ {
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
@ -2112,12 +2108,9 @@ bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpC
{ {
key = RsGeneralDataService::GRP_META_SUBSCRIBE_FLAG; key = RsGeneralDataService::GRP_META_SUBSCRIBE_FLAG;
currValue = grpMeta->mSubscribeFlags; currValue = grpMeta->mSubscribeFlags;
}else
{
if(grpMeta)
delete grpMeta;
return !(grpCv.empty());
} }
else
return !(grpCv.empty());
ok &= grpCv.getAsInt32(key+GXS_MASK, mask); ok &= grpCv.getAsInt32(key+GXS_MASK, mask);
@ -2129,9 +2122,6 @@ bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpC
grpCv.put(key, value); grpCv.put(key, value);
if(grpMeta)
delete grpMeta;
return ok; return ok;
} }
@ -2350,7 +2340,7 @@ void RsGenExchange::processGroupUpdatePublish()
// get keys for group update publish // get keys for group update publish
// first build meta request map for groups to be updated // first build meta request map for groups to be updated
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta; RsGxsGrpMetaTemporaryMap grpMeta;
std::vector<GroupUpdatePublish>::iterator vit = mGroupUpdatePublish.begin(); std::vector<GroupUpdatePublish>::iterator vit = mGroupUpdatePublish.begin();
for(; vit != mGroupUpdatePublish.end(); ++vit) for(; vit != mGroupUpdatePublish.end(); ++vit)
@ -2360,8 +2350,8 @@ void RsGenExchange::processGroupUpdatePublish()
grpMeta.insert(std::make_pair(groupId, (RsGxsGrpMetaData*)(NULL))); grpMeta.insert(std::make_pair(groupId, (RsGxsGrpMetaData*)(NULL)));
} }
if(grpMeta.empty()) if(grpMeta.empty())
return; return;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
@ -2371,20 +2361,18 @@ void RsGenExchange::processGroupUpdatePublish()
{ {
GroupUpdatePublish& gup = *vit; GroupUpdatePublish& gup = *vit;
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId; const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId); std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId);
RsGxsGrpMetaData* meta = NULL; const RsGxsGrpMetaData* meta = NULL;
if(mit == grpMeta.end() || mit->second == NULL) if(mit == grpMeta.end() || mit->second == NULL)
{ {
std::cerr << "Error! could not find meta of old group to update!" << std::endl; std::cerr << "Error! could not find meta of old group to update!" << std::endl;
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED); mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
delete gup.grpItem; delete gup.grpItem;
continue; continue;
}else
{
meta = mit->second;
} }
else
meta = mit->second;
//gup.grpItem->meta = *meta; //gup.grpItem->meta = *meta;
GxsGrpPendingSign ggps(gup.grpItem, gup.mToken); GxsGrpPendingSign ggps(gup.grpItem, gup.mToken);
@ -2402,14 +2390,13 @@ void RsGenExchange::processGroupUpdatePublish()
ggps.mToken = gup.mToken; ggps.mToken = gup.mToken;
mGrpsToPublish.push_back(ggps); mGrpsToPublish.push_back(ggps);
} }
else else
{ {
std::cerr << "(EE) publish group fails because RS cannot find the private publish and author keys" << std::endl; std::cerr << "(EE) publish group fails because RS cannot find the private publish and author keys" << std::endl;
delete gup.grpItem; delete gup.grpItem;
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED); mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
} }
delete meta;
} }
mGroupUpdatePublish.clear(); mGroupUpdatePublish.clear();
@ -2814,23 +2801,20 @@ bool RsGenExchange::getGroupKeys(const RsGxsGroupId &grpId, RsTlvSecurityKeySet
RS_STACK_MUTEX(mGenMtx) ; RS_STACK_MUTEX(mGenMtx) ;
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta; RsGxsGrpMetaTemporaryMap grpMeta;
grpMeta[grpId] = NULL; grpMeta[grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
if(grpMeta.empty()) if(grpMeta.empty())
return false; return false;
RsGxsGrpMetaData* meta = grpMeta[grpId]; const RsGxsGrpMetaData* meta = grpMeta[grpId];
if(meta == NULL) if(meta == NULL)
return false; return false;
keySet = meta->keys; keySet = meta->keys;
GxsSecurity::createPublicKeysFromPrivateKeys(keySet) ; GxsSecurity::createPublicKeysFromPrivateKeys(keySet) ;
for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator it=grpMeta.begin();it!=grpMeta.end();++it)
delete it->second ;
return true; return true;
} }
@ -2944,7 +2928,7 @@ void RsGenExchange::processRecvdMessages()
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ; std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
#endif #endif
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId); std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl; std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
@ -2958,11 +2942,12 @@ void RsGenExchange::processRecvdMessages()
continue ; continue ;
} }
RsGxsGrpMetaData *grpMeta = mit->second; const RsGxsGrpMetaData *grpMeta = mit->second;
RsTlvSecurityKeySet keys = grpMeta->keys ;
GxsSecurity::createPublicKeysFromPrivateKeys(grpMeta->keys); // make sure we have the public keys that correspond to the private ones, as it happens. Most of the time this call does nothing. GxsSecurity::createPublicKeysFromPrivateKeys(keys); // make sure we have the public keys that correspond to the private ones, as it happens. Most of the time this call does nothing.
int validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->mSignFlags, grpMeta->keys); int validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->mSignFlags, keys);
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " grpMeta.mSignFlags: " << std::hex << grpMeta->mSignFlags << std::dec << std::endl; std::cerr << " grpMeta.mSignFlags: " << std::hex << grpMeta->mSignFlags << std::dec << std::endl;
@ -3176,7 +3161,7 @@ void RsGenExchange::processRecvdGroups()
void RsGenExchange::performUpdateValidation() void RsGenExchange::performUpdateValidation()
{ {
RS_STACK_MUTEX(mGenMtx) ; RS_STACK_MUTEX(mGenMtx) ;
if(mGroupUpdates.empty()) if(mGroupUpdates.empty())
return; return;
@ -3185,7 +3170,7 @@ void RsGenExchange::performUpdateValidation()
std::cerr << "RsGenExchange::performUpdateValidation() " << std::endl; std::cerr << "RsGenExchange::performUpdateValidation() " << std::endl;
#endif #endif
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas; RsGxsGrpMetaTemporaryMap grpMetas;
std::vector<GroupUpdate>::iterator vit = mGroupUpdates.begin(); std::vector<GroupUpdate>::iterator vit = mGroupUpdates.begin();
for(; vit != mGroupUpdates.end(); ++vit) for(; vit != mGroupUpdates.end(); ++vit)
@ -3200,8 +3185,7 @@ void RsGenExchange::performUpdateValidation()
for(; vit != mGroupUpdates.end(); ++vit) for(; vit != mGroupUpdates.end(); ++vit)
{ {
GroupUpdate& gu = *vit; GroupUpdate& gu = *vit;
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMetas.find(gu.newGrp->grpId);
grpMetas.find(gu.newGrp->grpId);
gu.oldGrpMeta = mit->second; gu.oldGrpMeta = mit->second;
gu.validUpdate = updateValid(*(gu.oldGrpMeta), *(gu.newGrp)); gu.validUpdate = updateValid(*(gu.oldGrpMeta), *(gu.newGrp));
} }
@ -3223,51 +3207,51 @@ void RsGenExchange::performUpdateValidation()
if(gu.newGrp->metaData->mCircleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY) if(gu.newGrp->metaData->mCircleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
gu.newGrp->metaData->mOriginator = gu.newGrp->PeerId(); gu.newGrp->metaData->mOriginator = gu.newGrp->PeerId();
// Keep subscriptionflag to what it was. This avoids clearing off the flag when updates to group meta information // Keep subscriptionflag to what it was. This avoids clearing off the flag when updates to group meta information
// is received. // is received.
gu.newGrp->metaData->mSubscribeFlags = gu.oldGrpMeta->mSubscribeFlags ; gu.newGrp->metaData->mSubscribeFlags = gu.oldGrpMeta->mSubscribeFlags ;
grps.push_back(gu.newGrp); grps.push_back(gu.newGrp);
} }
else else
{ {
delete gu.newGrp; delete gu.newGrp;
gu.newGrp = NULL ; gu.newGrp = NULL ;
} }
delete gu.oldGrpMeta; delete gu.oldGrpMeta;
gu.oldGrpMeta = NULL ; gu.oldGrpMeta = NULL ;
} }
// notify the client // notify the client
RsGxsGroupChange* c = new RsGxsGroupChange(RsGxsNotify::TYPE_RECEIVE, true); RsGxsGroupChange* c = new RsGxsGroupChange(RsGxsNotify::TYPE_RECEIVE, true);
for(uint32_t i=0;i<mGroupUpdates.size();++i) for(uint32_t i=0;i<mGroupUpdates.size();++i)
if(mGroupUpdates[i].newGrp != NULL) if(mGroupUpdates[i].newGrp != NULL)
{ {
c->mGrpIdList.push_back(mGroupUpdates[i].newGrp->grpId) ; c->mGrpIdList.push_back(mGroupUpdates[i].newGrp->grpId) ;
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " " << mGroupUpdates[i].newGrp->grpId << std::endl; std::cerr << " " << mGroupUpdates[i].newGrp->grpId << std::endl;
#endif #endif
} }
mNotifications.push_back(c); mNotifications.push_back(c);
// Warning: updateGroup will destroy the objects in grps. Dont use it afterwards! // Warning: updateGroup will destroy the objects in grps. Dont use it afterwards!
mDataStore->updateGroup(grps); mDataStore->updateGroup(grps);
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << " adding the following grp ids to notification: " << std::endl; std::cerr << " adding the following grp ids to notification: " << std::endl;
#endif #endif
// cleanup // cleanup
mGroupUpdates.clear(); mGroupUpdates.clear();
} }
bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp) const bool RsGenExchange::updateValid(const RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp) const
{ {
std::map<SignType, RsTlvKeySignature>& signSet = newGrp.metaData->signSet.keySignSet; std::map<SignType, RsTlvKeySignature>& signSet = newGrp.metaData->signSet.keySignSet;
std::map<SignType, RsTlvKeySignature>::iterator mit = signSet.find(INDEX_AUTHEN_ADMIN); std::map<SignType, RsTlvKeySignature>::iterator mit = signSet.find(INDEX_AUTHEN_ADMIN);
@ -3283,10 +3267,11 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp)
} }
RsTlvKeySignature adminSign = mit->second; RsTlvKeySignature adminSign = mit->second;
RsTlvSecurityKeySet old_keys = oldGrpMeta.keys ;
GxsSecurity::createPublicKeysFromPrivateKeys(oldGrpMeta.keys); // make sure we have the public keys that correspond to the private ones, as it happens. Most of the time this call does nothing. GxsSecurity::createPublicKeysFromPrivateKeys(old_keys); // make sure we have the public keys that correspond to the private ones, as it happens. Most of the time this call does nothing.
std::map<RsGxsId, RsTlvPublicRSAKey>& keys = oldGrpMeta.keys.public_keys; std::map<RsGxsId, RsTlvPublicRSAKey>& keys = old_keys.public_keys;
std::map<RsGxsId, RsTlvPublicRSAKey>::iterator keyMit = keys.find(RsGxsId(oldGrpMeta.mGroupId)); std::map<RsGxsId, RsTlvPublicRSAKey>::iterator keyMit = keys.find(RsGxsId(oldGrpMeta.mGroupId));
if(keyMit == keys.end()) if(keyMit == keys.end())

View File

@ -223,7 +223,7 @@ public:
* @param groupInfo * @param groupInfo
* @return false if could not redeem token * @return false if could not redeem token
*/ */
bool getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo); bool getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData>& groupInfo);
/*! /*!
* retrieves message meta data associated to a request token * retrieves message meta data associated to a request token
@ -765,7 +765,7 @@ private:
* SIGN_FAIL_TRY_LATER for Id sign key not avail (but requested), try later * SIGN_FAIL_TRY_LATER for Id sign key not avail (but requested), try later
*/ */
int createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinaryData& msgData, int createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinaryData& msgData,
const RsGxsMsgMetaData& msgMeta, RsGxsGrpMetaData& grpMeta); const RsGxsMsgMetaData& msgMeta, const RsGxsGrpMetaData& grpMeta);
/*! /*!
* convenience function to create sign for groups * convenience function to create sign for groups
@ -835,7 +835,7 @@ private:
* @param newGrp the new group that updates the old group (must have meta data member initialised) * @param newGrp the new group that updates the old group (must have meta data member initialised)
* @return * @return
*/ */
bool updateValid(RsGxsGrpMetaData& oldGrp, RsNxsGrp& newGrp) const; bool updateValid(const RsGxsGrpMetaData& oldGrp, RsNxsGrp& newGrp) const;
/*! /*!
* convenience function for checking private publish and admin keys are present * convenience function for checking private publish and admin keys are present

View File

@ -33,7 +33,7 @@ RsGxsGrpMetaData::RsGxsGrpMetaData()
clear(); clear();
} }
uint32_t RsGxsGrpMetaData::serial_size(uint32_t api_version) uint32_t RsGxsGrpMetaData::serial_size(uint32_t api_version) const
{ {
uint32_t s = 8; // header size uint32_t s = 8; // header size

View File

@ -51,7 +51,7 @@ public:
RsGxsGrpMetaData(); RsGxsGrpMetaData();
bool deserialise(void *data, uint32_t &pktsize); bool deserialise(void *data, uint32_t &pktsize);
bool serialise(void* data, uint32_t &pktsize, uint32_t api_version); bool serialise(void* data, uint32_t &pktsize, uint32_t api_version);
uint32_t serial_size(uint32_t api_version); uint32_t serial_size(uint32_t api_version) const;
void clear(); void clear();
void operator =(const RsGroupMetaData& rMeta); void operator =(const RsGroupMetaData& rMeta);

View File

@ -25,6 +25,7 @@
#include <time.h> #include <time.h>
#include "rsgxsutil.h"
#include "rsgxsdataaccess.h" #include "rsgxsdataaccess.h"
#include "retroshare/rsgxsflags.h" #include "retroshare/rsgxsflags.h"
@ -377,7 +378,7 @@ bool RsGxsDataAccess::clearRequest(const uint32_t& token)
return true; return true;
} }
bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<RsGxsGrpMetaData*>& groupInfo) bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<const RsGxsGrpMetaData*>& groupInfo)
{ {
RS_STACK_MUTEX(mDataMutex); RS_STACK_MUTEX(mDataMutex);
@ -1000,23 +1001,22 @@ bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req) bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req)
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta; RsGxsGrpMetaTemporaryMap grpMeta;
std::list<RsGxsGroupId> grpIdsOut;
std::list<RsGxsGroupId> grpIdsOut; getGroupList(req->mGroupIds, req->Options, grpIdsOut);
getGroupList(req->mGroupIds, req->Options, grpIdsOut); if(grpIdsOut.empty())
return true;
if(grpIdsOut.empty()) std::list<RsGxsGroupId>::const_iterator lit = grpIdsOut.begin();
return true;
std::list<RsGxsGroupId>::const_iterator lit = grpIdsOut.begin(); for(; lit != grpIdsOut.end(); ++lit)
for(; lit != grpIdsOut.end(); ++lit)
grpMeta[*lit] = NULL; grpMeta[*lit] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin(); std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
for(; mit != grpMeta.end(); ++mit) for(; mit != grpMeta.end(); ++mit)
req->mGroupMetaData.push_back(mit->second); req->mGroupMetaData.push_back(mit->second);
@ -1033,29 +1033,18 @@ bool RsGxsDataAccess::getGroupList(GroupIdReq* req)
bool RsGxsDataAccess::getGroupList(const std::list<RsGxsGroupId>& grpIdsIn, const RsTokReqOptions& opts, std::list<RsGxsGroupId>& grpIdsOut) bool RsGxsDataAccess::getGroupList(const std::list<RsGxsGroupId>& grpIdsIn, const RsTokReqOptions& opts, std::list<RsGxsGroupId>& grpIdsOut)
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta; RsGxsGrpMetaTemporaryMap grpMeta;
std::list<RsGxsGroupId>::const_iterator lit = grpIdsIn.begin(); for(auto lit = grpIdsIn.begin(); lit != grpIdsIn.end(); ++lit)
grpMeta[*lit] = NULL;
for(; lit != grpIdsIn.end(); ++lit)
grpMeta[*lit] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin(); for(auto mit = grpMeta.begin() ; mit != grpMeta.end(); ++mit)
grpIdsOut.push_back(mit->first);
for(; mit != grpMeta.end(); ++mit)
{
grpIdsOut.push_back(mit->first);
}
filterGrpList(grpIdsOut, opts, grpMeta); filterGrpList(grpIdsOut, opts, grpMeta);
for(mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
{
delete mit->second; // so wasteful!!
}
return true; return true;
} }
@ -1622,12 +1611,10 @@ bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req)
// potentially very expensive! // potentially very expensive!
bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req) bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req)
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta; RsGxsGrpMetaTemporaryMap grpMeta ;
mDataStore->retrieveGxsGrpMetaData(grpMeta); mDataStore->retrieveGxsGrpMetaData(grpMeta);
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
req->mServiceStatistic.mNumGrps = grpMeta.size(); req->mServiceStatistic.mNumGrps = grpMeta.size();
req->mServiceStatistic.mNumMsgs = 0; req->mServiceStatistic.mNumMsgs = 0;
req->mServiceStatistic.mSizeOfGrps = 0; req->mServiceStatistic.mSizeOfGrps = 0;
@ -1638,9 +1625,9 @@ bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req)
req->mServiceStatistic.mNumChildMsgsNew = 0; req->mServiceStatistic.mNumChildMsgsNew = 0;
req->mServiceStatistic.mNumChildMsgsUnread = 0; req->mServiceStatistic.mNumChildMsgsUnread = 0;
for(; mit != grpMeta.end(); ++mit) for(auto mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
{ {
RsGxsGrpMetaData* m = mit->second; const RsGxsGrpMetaData* m = mit->second;
req->mServiceStatistic.mSizeOfGrps += m->mGrpSize + m->serial_size(RS_GXS_GRP_META_DATA_CURRENT_API_VERSION); req->mServiceStatistic.mSizeOfGrps += m->mGrpSize + m->serial_size(RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
if (IS_GROUP_SUBSCRIBED(m->mSubscribeFlags)) if (IS_GROUP_SUBSCRIBED(m->mSubscribeFlags))
@ -1658,8 +1645,6 @@ bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req)
req->mServiceStatistic.mNumChildMsgsNew += gr.mGroupStatistic.mNumChildMsgsNew; req->mServiceStatistic.mNumChildMsgsNew += gr.mGroupStatistic.mNumChildMsgsNew;
req->mServiceStatistic.mNumChildMsgsUnread += gr.mGroupStatistic.mNumChildMsgsUnread; req->mServiceStatistic.mNumChildMsgsUnread += gr.mGroupStatistic.mNumChildMsgsUnread;
} }
delete m;
} }
req->mServiceStatistic.mSizeStore = req->mServiceStatistic.mSizeOfGrps + req->mServiceStatistic.mSizeOfMsgs; req->mServiceStatistic.mSizeStore = req->mServiceStatistic.mSizeOfGrps + req->mServiceStatistic.mSizeOfMsgs;

View File

@ -32,7 +32,7 @@
typedef std::map< RsGxsGroupId, std::map<RsGxsMessageId, RsGxsMsgMetaData*> > MsgMetaFilter; typedef std::map< RsGxsGroupId, std::map<RsGxsMessageId, RsGxsMsgMetaData*> > MsgMetaFilter;
typedef std::map< RsGxsGroupId, RsGxsGrpMetaData* > GrpMetaFilter; typedef std::map< RsGxsGroupId, const RsGxsGrpMetaData* > GrpMetaFilter;
class RsGxsDataAccess : public RsTokenService class RsGxsDataAccess : public RsTokenService
{ {
@ -209,7 +209,7 @@ public:
* @param token request token to be redeemed * @param token request token to be redeemed
* @param groupInfo * @param groupInfo
*/ */
bool getGroupSummary(const uint32_t &token, std::list<RsGxsGrpMetaData*> &groupInfo); bool getGroupSummary(const uint32_t &token, std::list<const RsGxsGrpMetaData*>& groupInfo);
/*! /*!
* *

View File

@ -559,7 +559,7 @@ void RsGxsNetService::syncWithPeers()
for(RsGxsGrpMetaTemporaryMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit) for(RsGxsGrpMetaTemporaryMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
{ {
RsGxsGrpMetaData* meta = mit->second; const RsGxsGrpMetaData* meta = mit->second;
// This was commented out because we want to know how many messages are available for unsubscribed groups. // This was commented out because we want to know how many messages are available for unsubscribed groups.
@ -689,7 +689,7 @@ void RsGxsNetService::syncGrpStatistics()
time_t now = time(NULL) ; time_t now = time(NULL) ;
for(std::map<RsGxsGroupId,RsGxsGrpMetaData*>::const_iterator it(grpMeta.begin());it!=grpMeta.end();++it) for(auto it(grpMeta.begin());it!=grpMeta.end();++it)
{ {
const RsGxsGrpConfig& rec = locked_getGrpConfig(it->first) ; const RsGxsGrpConfig& rec = locked_getGrpConfig(it->first) ;
@ -755,7 +755,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
mDataStore->retrieveGxsGrpMetaData(grpMetas); mDataStore->retrieveGxsGrpMetaData(grpMetas);
RsGxsGrpMetaData* grpMeta = grpMetas[grs->grpId]; const RsGxsGrpMetaData* grpMeta = grpMetas[grs->grpId];
if(grpMeta == NULL) if(grpMeta == NULL)
{ {
@ -1951,7 +1951,7 @@ void RsGxsNetService::updateServerSyncTS()
// finally, update timestamps. // finally, update timestamps.
bool change = false; bool change = false;
for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator mit = gxsMap.begin();mit != gxsMap.end(); ++mit) for(auto mit = gxsMap.begin();mit != gxsMap.end(); ++mit)
{ {
// Check if the group is subscribed and restricted to a circle. If the circle has changed, update the // Check if the group is subscribed and restricted to a circle. If the circle has changed, update the
// global TS to reflect that change to clients who may be able to see/subscribe to that particular group. // global TS to reflect that change to clients who may be able to see/subscribe to that particular group.
@ -2722,7 +2722,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
grpMetaMap[grpId] = NULL; grpMetaMap[grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetaMap); mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
RsGxsGrpMetaData* grpMeta = grpMetaMap[grpId]; const RsGxsGrpMetaData* grpMeta = grpMetaMap[grpId];
if(grpMeta == NULL) // this should not happen, but just in case... if(grpMeta == NULL) // this should not happen, but just in case...
{ {
@ -3028,7 +3028,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
RsNxsSyncGrpItem*& grpSyncItem = *llit; RsNxsSyncGrpItem*& grpSyncItem = *llit;
const RsGxsGroupId& grpId = grpSyncItem->grpId; const RsGxsGroupId& grpId = grpSyncItem->grpId;
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator metaIter = grpMetaMap.find(grpId); std::map<RsGxsGroupId, const RsGxsGrpMetaData*>::const_iterator metaIter = grpMetaMap.find(grpId);
bool haveItem = false; bool haveItem = false;
bool latestVersion = false; bool latestVersion = false;
@ -3825,9 +3825,9 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item)
GXSNETDEBUG_P_(peer) << " Group list beings being sent: " << std::endl; GXSNETDEBUG_P_(peer) << " Group list beings being sent: " << std::endl;
#endif #endif
for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grp.begin(); mit != grp.end(); ++mit) for(auto mit = grp.begin(); mit != grp.end(); ++mit)
{ {
RsGxsGrpMetaData* grpMeta = mit->second; const RsGxsGrpMetaData* grpMeta = mit->second;
// Only send info about subscribed groups. // Only send info about subscribed groups.
@ -3899,7 +3899,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item)
bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& /* toVet */, bool& should_encrypt) bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, const RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& /* toVet */, bool& should_encrypt)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendGrpId()"<< std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendGrpId()"<< std::endl;
@ -4092,7 +4092,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_
grpMetas[item->grpId] = NULL; grpMetas[item->grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetas); mDataStore->retrieveGxsGrpMetaData(grpMetas);
RsGxsGrpMetaData* grpMeta = grpMetas[item->grpId]; const RsGxsGrpMetaData* grpMeta = grpMetas[item->grpId];
if(grpMeta == NULL) if(grpMeta == NULL)
{ {
@ -4633,7 +4633,7 @@ void RsGxsNetService::sharePublishKeysPending()
// Find the publish keys in the retrieved info // Find the publish keys in the retrieved info
RsGxsGrpMetaData *grpMeta = grpMetaMap[mit->first] ; const RsGxsGrpMetaData *grpMeta = grpMetaMap[mit->first] ;
if(grpMeta == NULL) if(grpMeta == NULL)
{ {
@ -4718,7 +4718,7 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
// update the publish keys in this group meta info // update the publish keys in this group meta info
RsGxsGrpMetaData *grpMeta = grpMetaMap[item->grpId] ; const RsGxsGrpMetaData *grpMeta = grpMetaMap[item->grpId] ;
if (!grpMeta) { if (!grpMeta) {
std::cerr << "(EE) RsGxsNetService::handleRecvPublishKeys() grpMeta not found." << std::endl; std::cerr << "(EE) RsGxsNetService::handleRecvPublishKeys() grpMeta not found." << std::endl;
return ; return ;
@ -4760,9 +4760,10 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
// Store/update the info. // Store/update the info.
grpMeta->keys.private_keys[item->private_key.keyId] = item->private_key ; RsTlvSecurityKeySet keys = grpMeta->keys ;
keys.private_keys[item->private_key.keyId] = item->private_key ;
bool ret = mDataStore->updateGroupKeys(item->grpId,grpMeta->keys, grpMeta->mSubscribeFlags | GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) ; bool ret = mDataStore->updateGroupKeys(item->grpId,keys, grpMeta->mSubscribeFlags | GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) ;
if(ret) if(ret)
{ {

View File

@ -370,7 +370,7 @@ private:
* @param toVet groupid/peer to vet are stored here if their circle id is not cached * @param toVet groupid/peer to vet are stored here if their circle id is not cached
* @return false, if you cannot send to this peer, true otherwise * @return false, if you cannot send to this peer, true otherwise
*/ */
bool canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool &should_encrypt); bool canSendGrpId(const RsPeerId& sslId, const RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool &should_encrypt);
bool canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id); bool canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id);
/*! /*!

View File

@ -52,7 +52,7 @@ public:
public: public:
std::list<RsGxsGroupId> mGroupIds; std::list<RsGxsGroupId> mGroupIds;
std::list<RsGxsGrpMetaData*> mGroupMetaData; std::list<const RsGxsGrpMetaData*> mGroupMetaData;
}; };
class GroupIdReq : public GxsRequest class GroupIdReq : public GxsRequest

View File

@ -42,13 +42,10 @@ static const uint32_t MAX_GXS_IDS_REQUESTS_NET = 10 ; // max number of reques
RsGxsMessageCleanUp::RsGxsMessageCleanUp(RsGeneralDataService* const dataService, RsGenExchange *genex, uint32_t chunkSize) RsGxsMessageCleanUp::RsGxsMessageCleanUp(RsGeneralDataService* const dataService, RsGenExchange *genex, uint32_t chunkSize)
: mDs(dataService), mGenExchangeClient(genex), CHUNK_SIZE(chunkSize) : mDs(dataService), mGenExchangeClient(genex), CHUNK_SIZE(chunkSize)
{ {
RsGxsGrpMetaTemporaryMap grpMeta;
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
mDs->retrieveGxsGrpMetaData(grpMeta); mDs->retrieveGxsGrpMetaData(grpMeta);
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator cit = grpMeta.begin(); for(auto cit=grpMeta.begin();cit != grpMeta.end(); ++cit)
for(;cit != grpMeta.end(); ++cit)
mGrpMeta.push_back(cit->second); mGrpMeta.push_back(cit->second);
} }
@ -64,7 +61,7 @@ bool RsGxsMessageCleanUp::clean()
#endif #endif
while(!mGrpMeta.empty()) while(!mGrpMeta.empty())
{ {
RsGxsGrpMetaData* grpMeta = mGrpMeta.back(); const RsGxsGrpMetaData* grpMeta = mGrpMeta.back();
const RsGxsGroupId& grpId = grpMeta->mGroupId; const RsGxsGroupId& grpId = grpMeta->mGroupId;
mGrpMeta.pop_back(); mGrpMeta.pop_back();
GxsMsgReq req; GxsMsgReq req;
@ -137,8 +134,6 @@ bool RsGxsMessageCleanUp::clean()
mDs->removeMsgs(req); mDs->removeMsgs(req);
delete grpMeta;
i++; i++;
if(i > CHUNK_SIZE) break; if(i > CHUNK_SIZE) break;
} }

View File

@ -32,6 +32,7 @@
class RsGixs ; class RsGixs ;
class RsGenExchange ; class RsGenExchange ;
class RsGeneralDataService ;
// temporary holds a map of pointers to class T, and destroys all pointers on delete. // temporary holds a map of pointers to class T, and destroys all pointers on delete.
@ -104,7 +105,7 @@ public:
} }
}; };
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsGxsGrpMetaData> RsGxsGrpMetaTemporaryMap; typedef std::map<RsGxsGroupId,const RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> RsNxsGrpDataTemporaryMap; typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> RsNxsGrpDataTemporaryMap;
typedef t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> RsGxsMsgMetaTemporaryMap ; typedef t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> RsGxsMsgMetaTemporaryMap ;
@ -178,7 +179,7 @@ private:
RsGeneralDataService* const mDs; RsGeneralDataService* const mDs;
RsGenExchange *mGenExchangeClient; RsGenExchange *mGenExchangeClient;
uint32_t CHUNK_SIZE; uint32_t CHUNK_SIZE;
std::vector<RsGxsGrpMetaData*> mGrpMeta; std::vector<const RsGxsGrpMetaData*> mGrpMeta;
}; };
/*! /*!
@ -226,7 +227,7 @@ class GroupUpdate
public: public:
GroupUpdate() : oldGrpMeta(NULL), newGrp(NULL), validUpdate(false) GroupUpdate() : oldGrpMeta(NULL), newGrp(NULL), validUpdate(false)
{} {}
RsGxsGrpMetaData* oldGrpMeta; const RsGxsGrpMetaData* oldGrpMeta;
RsNxsGrp* newGrp; RsNxsGrp* newGrp;
bool validUpdate; bool validUpdate;
}; };