mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
replaced GxsMetaData pointers by shared_ptrs in dataaccess and dataservice, so that we can easily disable caching, more freely get rid of cache items, and have a simpler memory management scheme
This commit is contained in:
parent
4a15c59356
commit
22ceec6c43
@ -482,7 +482,7 @@ bool RsDataService::finishReleaseUpdate(int release, bool result)
|
||||
return result;
|
||||
}
|
||||
|
||||
RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c, int colOffset,bool use_cache)
|
||||
std::shared_ptr<RsGxsGrpMetaData> RsDataService::locked_getGrpMeta(RetroCursor& c, int colOffset,bool use_cache)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
std::cerr << "RsDataService::locked_getGrpMeta()" << std::endl;
|
||||
@ -499,7 +499,7 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c, int colOffset
|
||||
std::string tempId;
|
||||
c.getString(mColGrpMeta_GrpId + colOffset, tempId);
|
||||
|
||||
RsGxsGrpMetaData* grpMeta ;
|
||||
std::shared_ptr<RsGxsGrpMetaData> grpMeta ;
|
||||
RsGxsGroupId grpId(tempId) ;
|
||||
|
||||
if(grpId.isNull()) // not in the DB!
|
||||
@ -508,7 +508,7 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c, int colOffset
|
||||
if(use_cache)
|
||||
grpMeta = mGrpMetaDataCache.getOrCreateMeta(grpId);
|
||||
else
|
||||
grpMeta = new RsGxsGrpMetaData();
|
||||
grpMeta = std::make_shared<RsGxsGrpMetaData>();
|
||||
|
||||
if(!grpMeta->mGroupId.isNull()) // the grpMeta is already initialized because it comes from the cache
|
||||
return grpMeta;
|
||||
@ -596,11 +596,7 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c, int colOffset
|
||||
if(ok)
|
||||
return grpMeta;
|
||||
else
|
||||
{
|
||||
if(!use_cache)
|
||||
delete grpMeta;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
RsNxsGrp* RsDataService::locked_getGroup(RetroCursor &c)
|
||||
@ -645,9 +641,8 @@ RsNxsGrp* RsDataService::locked_getGroup(RetroCursor &c)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RsGxsMsgMetaData* RsDataService::locked_getMsgMeta(RetroCursor &c, int colOffset,bool use_cache)
|
||||
std::shared_ptr<RsGxsMsgMetaData> RsDataService::locked_getMsgMeta(RetroCursor &c, int colOffset,bool use_cache)
|
||||
{
|
||||
|
||||
bool ok = true;
|
||||
uint32_t data_len = 0,
|
||||
offset = 0;
|
||||
@ -667,12 +662,12 @@ RsGxsMsgMetaData* RsDataService::locked_getMsgMeta(RetroCursor &c, int colOffset
|
||||
if(group_id.isNull() || msg_id.isNull())
|
||||
return nullptr;
|
||||
|
||||
RsGxsMsgMetaData* msgMeta = nullptr;
|
||||
std::shared_ptr<RsGxsMsgMetaData> msgMeta;
|
||||
|
||||
if(use_cache)
|
||||
msgMeta = mMsgMetaDataCache[group_id].getOrCreateMeta(msg_id);
|
||||
else
|
||||
msgMeta = new RsGxsMsgMetaData();
|
||||
msgMeta = std::make_shared<RsGxsMsgMetaData>();
|
||||
|
||||
if(!msgMeta->mGroupId.isNull()) // we cannot do that because the cursor needs to advance. Is there a method to skip some data in the db?
|
||||
return msgMeta;
|
||||
@ -712,8 +707,8 @@ RsGxsMsgMetaData* RsDataService::locked_getMsgMeta(RetroCursor &c, int colOffset
|
||||
|
||||
if(ok)
|
||||
return msgMeta;
|
||||
else if(!use_cache)
|
||||
delete msgMeta;
|
||||
else
|
||||
return nullptr;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -842,8 +837,9 @@ int RsDataService::storeMessage(const std::list<RsNxsMsg*>& msg)
|
||||
|
||||
// This is needed so that mLastPost is correctly updated in the group meta when it is re-loaded.
|
||||
|
||||
mGrpMetaDataCache.clear(msgMetaPtr->mGroupId);
|
||||
mMsgMetaDataCache[msgMetaPtr->mGroupId].updateMeta(msgMetaPtr->mMsgId,*msgMetaPtr);
|
||||
|
||||
delete *mit;
|
||||
}
|
||||
|
||||
// finish transaction
|
||||
@ -944,6 +940,8 @@ int RsDataService::storeGroup(const std::list<RsNxsGrp*>& grp)
|
||||
std::cerr << "\t For GroupId: " << grpMetaPtr->mGroupId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
delete *sit;
|
||||
}
|
||||
// finish transaction
|
||||
bool ret = mDb->commitTransaction();
|
||||
@ -1020,6 +1018,8 @@ int RsDataService::updateGroup(const std::list<RsNxsGrp *> &grp)
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpPtr->grpId.toStdString() + "'", cv);
|
||||
|
||||
mGrpMetaDataCache.updateMeta(grpMetaPtr->mGroupId,*grpMetaPtr);
|
||||
|
||||
delete *sit;
|
||||
}
|
||||
// finish transaction
|
||||
bool ret = mDb->commitTransaction();
|
||||
@ -1138,8 +1138,8 @@ int RsDataService::retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp *> &grp, bool
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps, int metaOffset){
|
||||
|
||||
void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps, int metaOffset)
|
||||
{
|
||||
if(c){
|
||||
bool valid = c->moveToFirst();
|
||||
|
||||
@ -1150,7 +1150,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>
|
||||
if(g)
|
||||
{
|
||||
if (metaOffset)
|
||||
g->metaData = locked_getGrpMeta(*c, metaOffset,false);
|
||||
g->metaData = new RsGxsGrpMetaData(*locked_getGrpMeta(*c, metaOffset,true));
|
||||
else
|
||||
g->metaData = nullptr;
|
||||
|
||||
@ -1238,7 +1238,7 @@ void RsDataService::locked_retrieveMessages(RetroCursor *c, std::vector<RsNxsMsg
|
||||
|
||||
if(m){
|
||||
if (metaOffset)
|
||||
m->metaData = locked_getMsgMeta(*c, metaOffset,false);
|
||||
m->metaData = new RsGxsMsgMetaData(*locked_getMsgMeta(*c, metaOffset,false));
|
||||
else
|
||||
m->metaData = nullptr;
|
||||
|
||||
@ -1297,7 +1297,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
{
|
||||
const RsGxsMessageId& msgId = *sit;
|
||||
|
||||
RsGxsMsgMetaData *meta = cache.getMeta(msgId);
|
||||
auto meta = cache.getMeta(msgId);
|
||||
|
||||
if(meta)
|
||||
metaSet.push_back(meta);
|
||||
@ -1306,7 +1306,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, mMsgMetaColumns, KEY_GRP_ID+ "='" + grpId.toStdString() + "' AND " + KEY_MSG_ID + "='" + msgId.toStdString() + "'", "");
|
||||
|
||||
c->moveToFirst();
|
||||
RsGxsMsgMetaData* meta = locked_getMsgMeta(*c, 0,true);
|
||||
auto meta = locked_getMsgMeta(*c, 0,true);
|
||||
|
||||
if(meta)
|
||||
metaSet.push_back(meta);
|
||||
@ -1328,7 +1328,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RsDataService::locked_retrieveGrpMetaList(RetroCursor *c, std::map<RsGxsGroupId,RsGxsGrpMetaData *>& grpMeta)
|
||||
void RsDataService::locked_retrieveGrpMetaList(RetroCursor *c, std::map<RsGxsGroupId,std::shared_ptr<RsGxsGrpMetaData> >& grpMeta)
|
||||
{
|
||||
if(!c)
|
||||
{
|
||||
@ -1340,15 +1340,16 @@ void RsDataService::locked_retrieveGrpMetaList(RetroCursor *c, std::map<RsGxsGro
|
||||
|
||||
while(valid)
|
||||
{
|
||||
RsGxsGrpMetaData* m = locked_getGrpMeta(*c, 0,true);
|
||||
auto m = locked_getGrpMeta(*c, 0,true);
|
||||
|
||||
if(m)
|
||||
if(m != nullptr)
|
||||
grpMeta[m->mGroupId] = m;
|
||||
|
||||
valid = c->moveToNext();
|
||||
}
|
||||
}
|
||||
void RsDataService::locked_retrieveMsgMetaList(RetroCursor *c, std::vector<const RsGxsMsgMetaData *>& msgMeta)
|
||||
|
||||
void RsDataService::locked_retrieveMsgMetaList(RetroCursor *c, std::vector<std::shared_ptr<RsGxsMsgMetaData> >& msgMeta)
|
||||
{
|
||||
if(!c)
|
||||
{
|
||||
@ -1357,17 +1358,18 @@ void RsDataService::locked_retrieveMsgMetaList(RetroCursor *c, std::vector<const
|
||||
}
|
||||
|
||||
bool valid = c->moveToFirst();
|
||||
while(valid){
|
||||
const RsGxsMsgMetaData* m = locked_getMsgMeta(*c, 0,true);
|
||||
while(valid)
|
||||
{
|
||||
auto m = locked_getMsgMeta(*c, 0,true);
|
||||
|
||||
if(m != NULL)
|
||||
if(m != nullptr)
|
||||
msgMeta.push_back(m);
|
||||
|
||||
valid = c->moveToNext();
|
||||
}
|
||||
}
|
||||
|
||||
int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
int RsDataService::retrieveGxsGrpMetaData(std::map<RsGxsGroupId,std::shared_ptr<RsGxsGrpMetaData> >& grp)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
std::cerr << "RsDataService::retrieveGxsGrpMetaData()";
|
||||
@ -1412,33 +1414,13 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
resultCount += grp.size();
|
||||
#endif
|
||||
|
||||
// if(c)
|
||||
// {
|
||||
// bool valid = c->moveToFirst();
|
||||
//
|
||||
// while(valid)
|
||||
// {
|
||||
// RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0,true);
|
||||
//
|
||||
// if(g)
|
||||
// {
|
||||
// grp[g->mGroupId] = g;
|
||||
//#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
// std::cerr << (void *)this << " " << mDbName << ": Retrieving (all) Grp metadata grpId=" << g->mGroupId << std::endl;
|
||||
//#endif
|
||||
// }
|
||||
// valid = c->moveToNext();
|
||||
//
|
||||
// }
|
||||
// delete c;
|
||||
// }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(auto mit(grp.begin()); mit != grp.end(); ++mit)
|
||||
{
|
||||
RsGxsGrpMetaData *meta = mGrpMetaDataCache.getMeta(mit->first) ;
|
||||
auto meta = mGrpMetaDataCache.getMeta(mit->first) ;
|
||||
|
||||
if(meta)
|
||||
mit->second = meta;
|
||||
@ -1452,7 +1434,7 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
RetroCursor* c = mDb->sqlQuery(GRP_TABLE_NAME, mGrpMetaColumns, "grpId='" + grpId.toStdString() + "'", "");
|
||||
|
||||
c->moveToFirst();
|
||||
RsGxsGrpMetaData* meta = locked_getGrpMeta(*c, 0,true);
|
||||
auto meta = locked_getGrpMeta(*c, 0,true);
|
||||
|
||||
if(meta)
|
||||
mit->second = meta;
|
||||
@ -1463,33 +1445,6 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
||||
|
||||
delete c;
|
||||
|
||||
// if(c)
|
||||
// {
|
||||
// bool valid = c->moveToFirst();
|
||||
//
|
||||
//#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
// if(!valid)
|
||||
// std::cerr << " Empty query! GrpId " << grpId << " is not in database" << std::endl;
|
||||
//#endif
|
||||
// while(valid)
|
||||
// {
|
||||
// RsGxsGrpMetaData* g = locked_getGrpMeta(*c, 0,true);
|
||||
//
|
||||
// if(g)
|
||||
// {
|
||||
// grp[g->mGroupId] = g;
|
||||
//#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
// std::cerr << ". Got it. Updating cache." << std::endl;
|
||||
//#endif
|
||||
// }
|
||||
// valid = c->moveToNext();
|
||||
//
|
||||
//#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
// ++resultCount;
|
||||
//#endif
|
||||
// }
|
||||
// delete c;
|
||||
// }
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_CACHE
|
||||
else
|
||||
std::cerr << ". not found!" << std::endl;
|
||||
|
@ -38,35 +38,29 @@ public:
|
||||
template<class ID, class MetaDataClass> class t_MetaDataCache
|
||||
{
|
||||
public:
|
||||
t_MetaDataCache() : mCache_ContainsAllMetas(false) {}
|
||||
virtual ~t_MetaDataCache()
|
||||
{
|
||||
for(auto it: mMetas)
|
||||
delete it.second;
|
||||
|
||||
for(auto it: mOldCachedItems)
|
||||
delete it.second;
|
||||
}
|
||||
t_MetaDataCache()
|
||||
: mCache_ContainsAllMetas(false)
|
||||
{}
|
||||
virtual ~t_MetaDataCache() = default;
|
||||
|
||||
bool isCacheUpToDate() const { return mCache_ContainsAllMetas ; }
|
||||
void setCacheUpToDate(bool b) { mCache_ContainsAllMetas = b; }
|
||||
|
||||
void getFullMetaList(std::map<ID,MetaDataClass*>& mp) const { mp = mMetas ; }
|
||||
void getFullMetaList(std::vector<const MetaDataClass*>& mp) const { for(auto& m:mMetas) mp.push_back(m.second) ; }
|
||||
void getFullMetaList(std::map<ID,std::shared_ptr<MetaDataClass> >& mp) const { mp = mMetas ; }
|
||||
void getFullMetaList(std::vector<std::shared_ptr<MetaDataClass> >& mp) const { for(auto& m:mMetas) mp.push_back(m.second) ; }
|
||||
|
||||
MetaDataClass *getMeta(const ID& id)
|
||||
std::shared_ptr<MetaDataClass> getMeta(const ID& id)
|
||||
{
|
||||
auto itt = mMetas.find(id);
|
||||
|
||||
if(itt != mMetas.end())
|
||||
return itt->second ;
|
||||
else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MetaDataClass *getOrCreateMeta(const ID& id)
|
||||
std::shared_ptr<MetaDataClass> getOrCreateMeta(const ID& id)
|
||||
{
|
||||
MetaDataClass *meta = nullptr;
|
||||
auto it = mMetas.find(id) ;
|
||||
|
||||
if(it != mMetas.end())
|
||||
@ -74,18 +68,15 @@ public:
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
RsDbg() << __PRETTY_FUNCTION__ << ": getting group meta " << grpId << " from cache." << std::endl;
|
||||
#endif
|
||||
meta = it->second ;
|
||||
return it->second ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
RsDbg() << __PRETTY_FUNCTION__ << ": group meta " << grpId << " not in cache. Loading it from DB..." << std::endl;
|
||||
#endif
|
||||
meta = new MetaDataClass();
|
||||
mMetas[id] = meta ;
|
||||
}
|
||||
|
||||
return meta;
|
||||
return (mMetas[id] = std::make_shared<MetaDataClass>());
|
||||
}
|
||||
}
|
||||
|
||||
void updateMeta(const ID& id,const MetaDataClass& meta)
|
||||
@ -95,7 +86,7 @@ public:
|
||||
if(it != mMetas.end())
|
||||
*(it->second) = meta ;
|
||||
else
|
||||
mMetas[id] = new MetaDataClass(meta) ;
|
||||
mMetas[id] = std::make_shared<MetaDataClass>();
|
||||
}
|
||||
|
||||
void clear(const ID& id)
|
||||
@ -114,39 +105,21 @@ public:
|
||||
std::cerr << "(II) moving database cache entry " << (void*)(*it).second << " to dead list." << std::endl;
|
||||
#endif
|
||||
|
||||
mOldCachedItems.push_back(std::make_pair(now,it->second)) ;
|
||||
|
||||
mMetas.erase(it) ;
|
||||
mCache_ContainsAllMetas = false;
|
||||
}
|
||||
|
||||
// We also take that opportunity to delete old entries.
|
||||
|
||||
auto it2(mOldCachedItems.begin());
|
||||
|
||||
while(it2!=mOldCachedItems.end() && (*it2).first + CACHE_ENTRY_GRACE_PERIOD < now)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG
|
||||
std::cerr << "(II) deleting old GXS database cache entry " << (void*)(*it2).second << ", " << now - (*it2).first << " seconds old." << std::endl;
|
||||
#endif
|
||||
delete (*it2).second ;
|
||||
it2 = mOldCachedItems.erase(it2) ;
|
||||
}
|
||||
}
|
||||
|
||||
void debug_computeSize(uint32_t& nb_items, uint32_t& nb_items_on_deadlist, uint64_t& total_size,uint64_t& total_size_of_deadlist) const
|
||||
{
|
||||
nb_items = mMetas.size();
|
||||
nb_items_on_deadlist = mOldCachedItems.size();
|
||||
total_size = 0;
|
||||
total_size_of_deadlist = 0;
|
||||
|
||||
for(auto it:mMetas) total_size += it.second->serial_size();
|
||||
for(auto it:mOldCachedItems) total_size_of_deadlist += it.second->serial_size();
|
||||
}
|
||||
private:
|
||||
std::map<ID,MetaDataClass*> mMetas;
|
||||
std::list<std::pair<rstime_t,MetaDataClass*> > mOldCachedItems ; // dead list, where items get deleted after being unused for a while. This is due to not using smart ptrs.
|
||||
std::map<ID,std::shared_ptr<MetaDataClass> > mMetas;
|
||||
|
||||
static const uint32_t CACHE_ENTRY_GRACE_PERIOD = 600 ; // Unused items are deleted 10 minutes after last usage.
|
||||
|
||||
@ -189,7 +162,7 @@ public:
|
||||
* @param cache whether to store retrieval in mem for faster later retrieval
|
||||
* @return error code
|
||||
*/
|
||||
int retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp);
|
||||
int retrieveGxsGrpMetaData(std::map<RsGxsGroupId, std::shared_ptr<RsGxsGrpMetaData> > &grp);
|
||||
|
||||
/*!
|
||||
* Retrieves meta data of all groups stored (most current versions only)
|
||||
@ -316,26 +289,26 @@ private:
|
||||
* @param c cursor to result set
|
||||
* @param msgMeta message metadata retrieved from cursor are stored here
|
||||
*/
|
||||
void locked_retrieveMsgMetaList(RetroCursor* c, std::vector<const RsGxsMsgMetaData*>& msgMeta);
|
||||
void locked_retrieveMsgMetaList(RetroCursor* c, std::vector<std::shared_ptr<RsGxsMsgMetaData> > &msgMeta);
|
||||
|
||||
/*!
|
||||
* Retrieves all the grp meta results from a cursor
|
||||
* @param c cursor to result set
|
||||
* @param grpMeta group metadata retrieved from cursor are stored here
|
||||
*/
|
||||
void locked_retrieveGrpMetaList(RetroCursor *c, std::map<RsGxsGroupId,RsGxsGrpMetaData *>& grpMeta);
|
||||
void locked_retrieveGrpMetaList(RetroCursor *c, std::map<RsGxsGroupId, std::shared_ptr<RsGxsGrpMetaData> > &grpMeta);
|
||||
|
||||
/*!
|
||||
* extracts a msg meta item from a cursor at its
|
||||
* current position
|
||||
*/
|
||||
RsGxsMsgMetaData* locked_getMsgMeta(RetroCursor& c, int colOffset, bool use_cache);
|
||||
std::shared_ptr<RsGxsMsgMetaData> locked_getMsgMeta(RetroCursor& c, int colOffset, bool use_cache);
|
||||
|
||||
/*!
|
||||
* extracts a grp meta item from a cursor at its
|
||||
* current position
|
||||
*/
|
||||
RsGxsGrpMetaData* locked_getGrpMeta(RetroCursor& c, int colOffset, bool use_cache);
|
||||
std::shared_ptr<RsGxsGrpMetaData> locked_getGrpMeta(RetroCursor& c, int colOffset, bool use_cache);
|
||||
|
||||
/*!
|
||||
* extracts a msg item from a cursor at its
|
||||
|
@ -19,8 +19,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RSGDS_H
|
||||
#define RSGDS_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
@ -56,18 +56,16 @@ struct MsgLocMetaData {
|
||||
ContentValue val;
|
||||
};
|
||||
|
||||
typedef std::map<RsGxsGroupId,RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
|
||||
|
||||
/*!
|
||||
* This allows modification of local
|
||||
* meta data items of a group
|
||||
*/
|
||||
struct GrpLocMetaData {
|
||||
GrpLocMetaData() = default;
|
||||
GrpLocMetaData(const GrpLocMetaData& meta): grpId(meta.grpId), val(meta.val) {}
|
||||
GrpLocMetaData() = default;
|
||||
GrpLocMetaData(const GrpLocMetaData& meta): grpId(meta.grpId), val(meta.val) {}
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
ContentValue val;
|
||||
RsGxsGroupId grpId;
|
||||
ContentValue val;
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -166,7 +164,7 @@ public:
|
||||
* , if grpId is failed to be retrieved it will be erased from map
|
||||
* @return error code
|
||||
*/
|
||||
virtual int retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp) = 0;
|
||||
virtual int retrieveGxsGrpMetaData(std::map<RsGxsGroupId,std::shared_ptr<RsGxsGrpMetaData> >& grp) = 0;
|
||||
|
||||
/*!
|
||||
* Retrieves meta data of all groups stored (most current versions only)
|
||||
@ -274,8 +272,3 @@ public:
|
||||
virtual bool validSize(RsNxsGrp* grp) const = 0 ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // RSGDS_H
|
||||
|
@ -809,12 +809,13 @@ int RsGenExchange::createMessage(RsNxsMsg* msg)
|
||||
else
|
||||
{
|
||||
// get publish key
|
||||
const RsGxsGrpMetaData* grpMeta = metaMap[id];
|
||||
const auto& grpMeta = metaMap[id];
|
||||
|
||||
uint32_t metaDataLen = meta.serial_size();
|
||||
uint32_t allMsgDataLen = metaDataLen + msg->msg.bin_len;
|
||||
char* metaData = new char[metaDataLen];
|
||||
char* allMsgData = new char[allMsgDataLen]; // msgData + metaData
|
||||
|
||||
RsTemporaryMemory metaData(metaDataLen);
|
||||
RsTemporaryMemory allMsgData(allMsgDataLen);
|
||||
|
||||
meta.serialise(metaData, &metaDataLen);
|
||||
|
||||
@ -839,9 +840,6 @@ int RsGenExchange::createMessage(RsNxsMsg* msg)
|
||||
|
||||
// assign msg id to msg meta
|
||||
msg->metaData->mMsgId = msg->msgId;
|
||||
|
||||
delete[] metaData;
|
||||
delete[] allMsgData;
|
||||
}
|
||||
|
||||
if(ret_val == SIGN_FAIL)
|
||||
@ -1299,16 +1297,14 @@ bool RsGenExchange::getPublishedGroupMeta(const uint32_t& token,RsGroupMetaData&
|
||||
|
||||
bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
|
||||
{
|
||||
std::list<const RsGxsGrpMetaData*> metaL;
|
||||
std::list<std::shared_ptr<RsGxsGrpMetaData> > metaL;
|
||||
bool ok = mDataAccess->getGroupSummary(token, metaL);
|
||||
|
||||
RsGroupMetaData m;
|
||||
|
||||
for( auto lit = metaL.begin(); lit != metaL.end(); ++lit)
|
||||
{
|
||||
const RsGxsGrpMetaData& gMeta = *(*lit);
|
||||
|
||||
m = gMeta;
|
||||
RsGroupMetaData m(gMeta);
|
||||
RsGroupNetworkStats sts ;
|
||||
|
||||
if(mNetService != NULL && mNetService->getGroupNetworkStats(gMeta.mGroupId,sts))
|
||||
@ -1341,24 +1337,15 @@ bool RsGenExchange::getMsgMeta(const uint32_t &token,
|
||||
GxsMsgMetaResult result;
|
||||
bool ok = mDataAccess->getMsgSummary(token, result);
|
||||
|
||||
GxsMsgMetaResult::iterator mit = result.begin();
|
||||
|
||||
for(; mit != result.end(); ++mit)
|
||||
for(auto mit=result.begin(); mit != result.end(); ++mit)
|
||||
{
|
||||
std::vector<const RsGxsMsgMetaData*>& metaV = mit->second;
|
||||
auto& metaV = mit->second;
|
||||
|
||||
std::vector<RsMsgMetaData>& msgInfoV = msgInfo[mit->first];
|
||||
|
||||
std::vector<const RsGxsMsgMetaData*>::iterator vit = metaV.begin();
|
||||
RsMsgMetaData meta;
|
||||
for(; vit != metaV.end(); ++vit)
|
||||
{
|
||||
const RsGxsMsgMetaData& m = *(*vit);
|
||||
meta = m;
|
||||
msgInfoV.push_back(meta);
|
||||
//delete *vit;
|
||||
}
|
||||
metaV.clear();
|
||||
for(auto vit=metaV.begin(); vit != metaV.end(); ++vit)
|
||||
msgInfoV.push_back(RsMsgMetaData(*(*vit)));
|
||||
}
|
||||
|
||||
return ok;
|
||||
@ -1373,20 +1360,12 @@ bool RsGenExchange::getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMa
|
||||
|
||||
for(; mit != result.end(); ++mit)
|
||||
{
|
||||
std::vector<const RsGxsMsgMetaData*>& metaV = mit->second;
|
||||
auto& metaV = mit->second;
|
||||
|
||||
std::vector<RsMsgMetaData>& msgInfoV = msgMeta[mit->first];
|
||||
|
||||
std::vector<const RsGxsMsgMetaData*>::iterator vit = metaV.begin();
|
||||
RsMsgMetaData meta;
|
||||
for(; vit != metaV.end(); ++vit)
|
||||
{
|
||||
const RsGxsMsgMetaData& m = *(*vit);
|
||||
meta = m;
|
||||
msgInfoV.push_back(meta);
|
||||
//delete *vit;
|
||||
}
|
||||
metaV.clear();
|
||||
for(auto vit=metaV.begin(); vit != metaV.end(); ++vit)
|
||||
msgInfoV.push_back(RsMsgMetaData(*(*vit)));
|
||||
}
|
||||
|
||||
return ok;
|
||||
@ -2107,15 +2086,14 @@ void RsGenExchange::processMsgMetaChanges()
|
||||
|
||||
if(mit != result.end())
|
||||
{
|
||||
std::vector<const RsGxsMsgMetaData*>& msgMetaV = mit->second;
|
||||
const auto& msgMetaV = mit->second;
|
||||
|
||||
if(!msgMetaV.empty())
|
||||
{
|
||||
const RsGxsMsgMetaData* meta = *(msgMetaV.begin());
|
||||
const auto& meta = *(msgMetaV.begin());
|
||||
value = (meta->mMsgStatus & ~mask) | (mask & value);
|
||||
changed = (static_cast<int64_t>(meta->mMsgStatus) != value);
|
||||
m.val.put(RsGeneralDataService::MSG_META_STATUS, value);
|
||||
//delete meta;
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
@ -2210,16 +2188,16 @@ bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpC
|
||||
// first find out which mask is involved
|
||||
int32_t value, mask, currValue;
|
||||
std::string key;
|
||||
const RsGxsGrpMetaData* grpMeta = NULL;
|
||||
std::shared_ptr<RsGxsGrpMetaData> grpMeta;
|
||||
bool ok = false;
|
||||
|
||||
RsGxsGrpMetaTemporaryMap grpMetaMap;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData* >::iterator mit;
|
||||
grpMetaMap.insert(std::make_pair(grpId, (RsGxsGrpMetaData*)(NULL)));
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||
auto mit = grpMetaMap.find(grpId);
|
||||
|
||||
if((mit = grpMetaMap.find(grpId)) != grpMetaMap.end())
|
||||
if(mit != grpMetaMap.end())
|
||||
{
|
||||
grpMeta = mit->second;
|
||||
|
||||
@ -2501,10 +2479,11 @@ void RsGenExchange::processGroupUpdatePublish()
|
||||
{
|
||||
GroupUpdatePublish& gup = *vit;
|
||||
const RsGxsGroupId& groupId = gup.grpItem->meta.mGroupId;
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.find(groupId);
|
||||
auto mit = grpMeta.find(groupId);
|
||||
|
||||
const RsGxsGrpMetaData* meta = NULL;
|
||||
if(mit == grpMeta.end() || mit->second == NULL)
|
||||
std::shared_ptr<RsGxsGrpMetaData> meta;
|
||||
|
||||
if(mit == grpMeta.end() || mit->second == nullptr)
|
||||
{
|
||||
std::cerr << "Error! could not find meta of old group to update!" << std::endl;
|
||||
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::FAILED);
|
||||
@ -2960,7 +2939,7 @@ bool RsGenExchange::getGroupKeys(const RsGxsGroupId &grpId, RsTlvSecurityKeySet
|
||||
if(grpMeta.empty())
|
||||
return false;
|
||||
|
||||
const RsGxsGrpMetaData* meta = grpMeta[grpId];
|
||||
const auto& meta = grpMeta[grpId];
|
||||
|
||||
if(meta == NULL)
|
||||
return false;
|
||||
@ -3086,7 +3065,7 @@ void RsGenExchange::processRecvdMessages()
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " deserialised info: grp id=" << msg->grpId << ", msg id=" << msg->msgId ;
|
||||
#endif
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
|
||||
auto mit = grpMetas.find(msg->grpId);
|
||||
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
|
||||
@ -3100,7 +3079,7 @@ void RsGenExchange::processRecvdMessages()
|
||||
continue ;
|
||||
}
|
||||
|
||||
const RsGxsGrpMetaData *grpMeta = mit->second;
|
||||
const auto& grpMeta = mit->second;
|
||||
RsTlvSecurityKeySet keys = grpMeta->keys ;
|
||||
|
||||
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.
|
||||
|
@ -29,8 +29,8 @@
|
||||
|
||||
/* data types used throughout Gxs from netservice to genexchange */
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<const RsGxsMsgMetaData*> > GxsMsgMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<const RsGxsMsgMetaData*> > MsgRelatedMetaResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<std::shared_ptr<RsGxsMsgMetaData> > > GxsMsgMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<std::shared_ptr<RsGxsMsgMetaData> > > MsgRelatedMetaResult;
|
||||
|
||||
// Default values that are used throughout GXS code
|
||||
|
||||
|
@ -373,7 +373,7 @@ bool RsGxsDataAccess::locked_clearRequest(const uint32_t& token)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<const RsGxsGrpMetaData*>& groupInfo)
|
||||
bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list<std::shared_ptr<RsGxsGrpMetaData> >& groupInfo)
|
||||
{
|
||||
RS_STACK_MUTEX(mDataMutex);
|
||||
|
||||
@ -908,23 +908,21 @@ bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req)
|
||||
if(grpIdsOut.empty())
|
||||
return true;
|
||||
|
||||
std::list<RsGxsGroupId>::const_iterator lit = grpIdsOut.begin();
|
||||
|
||||
for(; lit != grpIdsOut.end(); ++lit)
|
||||
for(auto lit = grpIdsOut.begin();lit != grpIdsOut.end(); ++lit)
|
||||
grpMeta[*lit] = nullptr;
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMeta);
|
||||
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMeta.begin();
|
||||
|
||||
for(; mit != grpMeta.end(); ++mit)
|
||||
for(auto mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
|
||||
req->mGroupMetaData.push_back(mit->second);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getGroupList(GroupIdReq* req)
|
||||
{ return getGroupList(req->mGroupIds, req->Options, req->mGroupIdResult); }
|
||||
{
|
||||
return getGroupList(req->mGroupIds, req->Options, req->mGroupIdResult);
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getGroupList(const std::list<RsGxsGroupId>& grpIdsIn, const RsTokReqOptions& opts, std::list<RsGxsGroupId>& grpIdsOut)
|
||||
{
|
||||
@ -1030,7 +1028,7 @@ bool RsGxsDataAccess::getMsgMetaDataList( const GxsMsgReq& msgIds, const RsTokRe
|
||||
|
||||
//auto& filter( metaFilter[grpId] ); // does the initialization of metaFilter[grpId] and avoids further O(log(n)) calls
|
||||
|
||||
std::vector<const RsGxsMsgMetaData*>& metaV = meta_it->second;
|
||||
auto& metaV = meta_it->second;
|
||||
|
||||
if (onlyLatestMsgs) // if we only consider latest messages, we need to first filter out messages with "children"
|
||||
{
|
||||
@ -1124,7 +1122,7 @@ bool RsGxsDataAccess::getMsgMetaDataList( const GxsMsgReq& msgIds, const RsTokRe
|
||||
for(uint32_t i=0;i<metaV.size();++i)
|
||||
if(metaV[i] != nullptr)
|
||||
{
|
||||
const RsGxsMsgMetaData* msgMeta = metaV[i];
|
||||
const auto& msgMeta = metaV[i];
|
||||
bool add = false;
|
||||
|
||||
/* if we are grabbing thread Head... then parentId == empty. */
|
||||
@ -1291,8 +1289,7 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
||||
GxsMsgReq msgIds;
|
||||
msgIds.insert(std::make_pair(grpMsgIdPair.first, std::set<RsGxsMessageId>()));
|
||||
mDataStore->retrieveGxsMsgMetaData(msgIds, result);
|
||||
std::vector<const RsGxsMsgMetaData*>& metaV = result[grpMsgIdPair.first];
|
||||
std::vector<const RsGxsMsgMetaData*>::iterator vit_meta;
|
||||
auto& metaV = result[grpMsgIdPair.first];
|
||||
|
||||
// msg id to relate to
|
||||
const RsGxsMessageId& msgId = grpMsgIdPair.second;
|
||||
@ -1300,18 +1297,14 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
||||
|
||||
std::set<RsGxsMessageId> outMsgIds;
|
||||
|
||||
const RsGxsMsgMetaData* origMeta = nullptr;
|
||||
std::shared_ptr<RsGxsMsgMetaData> origMeta;
|
||||
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
{
|
||||
const RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
if(msgId == meta->mMsgId)
|
||||
for(auto vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
if(msgId == (*vit_meta)->mMsgId)
|
||||
{
|
||||
origMeta = meta;
|
||||
origMeta = *vit_meta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!origMeta)
|
||||
{
|
||||
@ -1320,7 +1313,7 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
||||
}
|
||||
|
||||
const RsGxsMessageId& origMsgId = origMeta->mOrigMsgId;
|
||||
std::map<RsGxsMessageId, const RsGxsMsgMetaData*>& metaMap = filterMap[grpId];
|
||||
auto& metaMap = filterMap[grpId];
|
||||
|
||||
if (onlyLatestMsgs)
|
||||
{
|
||||
@ -1329,10 +1322,10 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
||||
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
||||
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, rstime_t> > origMsgTs;
|
||||
std::map<RsGxsMessageId, std::pair<RsGxsMessageId, rstime_t> >::iterator oit;
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
{
|
||||
|
||||
const RsGxsMsgMetaData* meta = *vit_meta;
|
||||
for(auto vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
{
|
||||
auto meta = *vit_meta;
|
||||
|
||||
// skip msgs that aren't children.
|
||||
if (onlyChildMsgs)
|
||||
@ -1400,38 +1393,31 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
||||
/* first guess is potentially better than Orig (can't be worse!) */
|
||||
rstime_t latestTs = 0;
|
||||
RsGxsMessageId latestMsgId;
|
||||
const RsGxsMsgMetaData* latestMeta=nullptr;
|
||||
std::shared_ptr<RsGxsMsgMetaData> latestMeta;
|
||||
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
{
|
||||
const RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
if (meta->mOrigMsgId == origMsgId)
|
||||
for(auto vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
if ((*vit_meta)->mOrigMsgId == origMsgId)
|
||||
{
|
||||
if (meta->mPublishTs > latestTs)
|
||||
if ((*vit_meta)->mPublishTs > latestTs)
|
||||
{
|
||||
latestTs = meta->mPublishTs;
|
||||
latestMsgId = meta->mMsgId;
|
||||
latestMeta = meta;
|
||||
latestTs = (*vit_meta)->mPublishTs;
|
||||
latestMsgId = (*vit_meta)->mMsgId;
|
||||
latestMeta = (*vit_meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outMsgIds.insert(latestMsgId);
|
||||
metaMap.insert(std::make_pair(latestMsgId, latestMeta));
|
||||
}
|
||||
}
|
||||
else if (onlyAllVersions)
|
||||
{
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
{
|
||||
const RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
if (meta->mOrigMsgId == origMsgId)
|
||||
for(auto vit_meta = metaV.begin(); vit_meta != metaV.end(); ++vit_meta)
|
||||
if ((*vit_meta)->mOrigMsgId == origMsgId)
|
||||
{
|
||||
outMsgIds.insert(meta->mMsgId);
|
||||
metaMap.insert(std::make_pair(meta->mMsgId, meta));
|
||||
outMsgIds.insert((*vit_meta)->mMsgId);
|
||||
metaMap.insert(std::make_pair((*vit_meta)->mMsgId, (*vit_meta)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GxsMsgIdResult filteredOutMsgIds;
|
||||
@ -1495,7 +1481,7 @@ bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req)
|
||||
|
||||
for(uint32_t i = 0; i < msgMetaV.size(); ++i)
|
||||
{
|
||||
const RsGxsMsgMetaData* m = msgMetaV[i];
|
||||
const auto& m = msgMetaV[i];
|
||||
req->mGroupStatistic.mTotalSizeOfMsgs += m->mMsgSize + m->serial_size();
|
||||
|
||||
if(obsolete_msgs.find(m->mMsgId) != obsolete_msgs.end()) // skip obsolete messages.
|
||||
@ -1504,24 +1490,19 @@ bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req)
|
||||
if (IS_MSG_NEW(m->mMsgStatus))
|
||||
{
|
||||
if (m->mParentId.isNull())
|
||||
{
|
||||
++req->mGroupStatistic.mNumThreadMsgsNew;
|
||||
} else {
|
||||
else
|
||||
++req->mGroupStatistic.mNumChildMsgsNew;
|
||||
}
|
||||
}
|
||||
if (IS_MSG_UNREAD(m->mMsgStatus))
|
||||
{
|
||||
if (m->mParentId.isNull())
|
||||
{
|
||||
++req->mGroupStatistic.mNumThreadMsgsUnread;
|
||||
} else {
|
||||
else
|
||||
++req->mGroupStatistic.mNumChildMsgsUnread;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//cleanseMsgMetaMap(metaResult);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1544,7 +1525,7 @@ bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req)
|
||||
|
||||
for(auto mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
|
||||
{
|
||||
const RsGxsGrpMetaData* m = mit->second;
|
||||
const auto& m = mit->second;
|
||||
req->mServiceStatistic.mSizeOfGrps += m->mGrpSize + m->serial_size(RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
|
||||
|
||||
if (IS_GROUP_SUBSCRIBED(m->mSubscribeFlags))
|
||||
@ -1573,23 +1554,15 @@ bool RsGxsDataAccess::getMsgIdList(MsgIdReq* req)
|
||||
{
|
||||
|
||||
GxsMsgMetaResult result;
|
||||
|
||||
mDataStore->retrieveGxsMsgMetaData(req->mMsgIds, result);
|
||||
|
||||
GxsMsgMetaResult::iterator mit = result.begin(), mit_end = result.end();
|
||||
|
||||
for(; mit != mit_end; ++mit)
|
||||
for(auto mit = result.begin(); mit != result.end(); ++mit)
|
||||
{
|
||||
const RsGxsGroupId grpId = mit->first;
|
||||
std::vector<const RsGxsMsgMetaData*>& metaV = mit->second;
|
||||
std::vector<const RsGxsMsgMetaData*>::iterator vit = metaV.begin(),
|
||||
vit_end = metaV.end();
|
||||
auto& metaV = mit->second;
|
||||
|
||||
for(; vit != vit_end; ++vit)
|
||||
{
|
||||
const RsGxsMsgMetaData* meta = *vit;
|
||||
req->mMsgIdResult[grpId].insert(meta->mMsgId);
|
||||
}
|
||||
for(auto vit=metaV.begin(); vit != metaV.end(); ++vit)
|
||||
req->mMsgIdResult[grpId].insert((*vit)->mMsgId);
|
||||
}
|
||||
|
||||
GxsMsgReq msgIdOut;
|
||||
@ -1601,25 +1574,6 @@ bool RsGxsDataAccess::getMsgIdList(MsgIdReq* req)
|
||||
return true;
|
||||
}
|
||||
|
||||
// void RsGxsDataAccess::cleanseMsgMetaMap(GxsMsgMetaResult& result)
|
||||
// {
|
||||
// GxsMsgMetaResult::iterator mit = result.begin();
|
||||
//
|
||||
// for(; mit !=result.end(); ++mit)
|
||||
// {
|
||||
//
|
||||
// std::vector<RsGxsMsgMetaData*>& msgMetaV = mit->second;
|
||||
// std::vector<RsGxsMsgMetaData*>::iterator vit = msgMetaV.begin();
|
||||
// for(; vit != msgMetaV.end(); ++vit)
|
||||
// {
|
||||
// delete *vit;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// result.clear();
|
||||
// return;
|
||||
// }
|
||||
|
||||
void RsGxsDataAccess::filterMsgIdList( GxsMsgIdResult& resultsMap, const RsTokReqOptions& opts, const MsgMetaFilter& msgMetas ) const
|
||||
{
|
||||
for( GxsMsgIdResult::iterator grpIt = resultsMap.begin(); grpIt != resultsMap.end(); ++grpIt )
|
||||
@ -1638,16 +1592,13 @@ void RsGxsDataAccess::filterMsgIdList( GxsMsgIdResult& resultsMap, const RsTokRe
|
||||
for( std::set<RsGxsMessageId>::iterator msgIdIt = msgsIdSet.begin(); msgIdIt != msgsIdSet.end(); )
|
||||
{
|
||||
const RsGxsMessageId& msgId(*msgIdIt);
|
||||
const std::map<RsGxsMessageId, const RsGxsMsgMetaData*>& msgsMetaMap =
|
||||
cit->second;
|
||||
const auto& msgsMetaMap = cit->second;
|
||||
|
||||
bool keep = false;
|
||||
std::map<RsGxsMessageId, const RsGxsMsgMetaData*>::const_iterator msgsMetaMapIt;
|
||||
auto msgsMetaMapIt = msgsMetaMap.find(msgId);
|
||||
|
||||
if( (msgsMetaMapIt = msgsMetaMap.find(msgId)) != msgsMetaMap.end() )
|
||||
{
|
||||
if( msgsMetaMapIt != msgsMetaMap.end() )
|
||||
keep = checkMsgFilter(opts, msgsMetaMapIt->second);
|
||||
}
|
||||
|
||||
if(keep)
|
||||
++msgIdIt;
|
||||
@ -1663,29 +1614,21 @@ void RsGxsDataAccess::filterMsgIdList( GxsMsgIdResult& resultsMap, const RsTokRe
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsDataAccess::filterGrpList(std::list<RsGxsGroupId> &grpIds, const RsTokReqOptions &opts, const GrpMetaFilter &meta) const
|
||||
void RsGxsDataAccess::filterGrpList(std::list<RsGxsGroupId> &grpIds, const RsTokReqOptions &opts, const GrpMetaFilter& meta) const
|
||||
{
|
||||
std::list<RsGxsGroupId>::iterator lit = grpIds.begin();
|
||||
|
||||
for(; lit != grpIds.end(); )
|
||||
for(auto lit = grpIds.begin(); lit != grpIds.end(); )
|
||||
{
|
||||
GrpMetaFilter::const_iterator cit = meta.find(*lit);
|
||||
auto cit = meta.find(*lit);
|
||||
|
||||
bool keep = false;
|
||||
|
||||
if(cit != meta.end())
|
||||
{
|
||||
keep = checkGrpFilter(opts, cit->second);
|
||||
}
|
||||
|
||||
if(keep)
|
||||
{
|
||||
++lit;
|
||||
}else
|
||||
{
|
||||
else
|
||||
lit = grpIds.erase(lit);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1843,7 +1786,7 @@ bool RsGxsDataAccess::disposeOfPublicToken(uint32_t token)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::checkGrpFilter(const RsTokReqOptions &opts, const RsGxsGrpMetaData *meta) const
|
||||
bool RsGxsDataAccess::checkGrpFilter(const RsTokReqOptions &opts, const std::shared_ptr<RsGxsGrpMetaData>& meta) const
|
||||
{
|
||||
|
||||
bool subscribeMatch = false;
|
||||
@ -1863,8 +1806,7 @@ bool RsGxsDataAccess::checkGrpFilter(const RsTokReqOptions &opts, const RsGxsGrp
|
||||
|
||||
return subscribeMatch;
|
||||
}
|
||||
bool RsGxsDataAccess::checkMsgFilter(
|
||||
const RsTokReqOptions& opts, const RsGxsMsgMetaData* meta ) const
|
||||
bool RsGxsDataAccess::checkMsgFilter(const RsTokReqOptions& opts, const std::shared_ptr<RsGxsMsgMetaData> &meta ) const
|
||||
{
|
||||
if (opts.mStatusMask)
|
||||
{
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include "rsgds.h"
|
||||
|
||||
|
||||
typedef std::map< RsGxsGroupId, std::map<RsGxsMessageId, const RsGxsMsgMetaData*> > MsgMetaFilter;
|
||||
typedef std::map< RsGxsGroupId, RsGxsGrpMetaData* > GrpMetaFilter;
|
||||
typedef std::map< RsGxsGroupId, std::map<RsGxsMessageId, std::shared_ptr<RsGxsMsgMetaData> > > MsgMetaFilter;
|
||||
typedef std::map< RsGxsGroupId, std::shared_ptr<RsGxsGrpMetaData> > GrpMetaFilter;
|
||||
|
||||
bool operator<(const std::pair<uint32_t,GxsRequest*>& p1,const std::pair<uint32_t,GxsRequest*>& p2);
|
||||
|
||||
@ -220,7 +220,7 @@ public:
|
||||
* @param token request token to be redeemed
|
||||
* @param groupInfo
|
||||
*/
|
||||
bool getGroupSummary(const uint32_t &token, std::list<const RsGxsGrpMetaData*>& groupInfo);
|
||||
bool getGroupSummary(const uint32_t &token, std::list<std::shared_ptr<RsGxsGrpMetaData> > &groupInfo);
|
||||
|
||||
/*!
|
||||
*
|
||||
@ -478,7 +478,7 @@ private:
|
||||
* @param meta meta containing currently defined options for msg
|
||||
* @return true if msg meta passes all options
|
||||
*/
|
||||
bool checkMsgFilter(const RsTokReqOptions& opts, const RsGxsMsgMetaData* meta) const;
|
||||
bool checkMsgFilter(const RsTokReqOptions& opts, const std::shared_ptr<RsGxsMsgMetaData>& meta) const;
|
||||
|
||||
/*!
|
||||
* This applies the options to the meta to find out if the given group satisfies
|
||||
@ -487,7 +487,7 @@ private:
|
||||
* @param meta meta containing currently defined options for group
|
||||
* @return true if group meta passes all options
|
||||
*/
|
||||
bool checkGrpFilter(const RsTokReqOptions& opts, const RsGxsGrpMetaData* meta) const;
|
||||
bool checkGrpFilter(const RsTokReqOptions& opts, const std::shared_ptr<RsGxsGrpMetaData> &meta) const;
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -637,7 +637,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
|
||||
for(RsGxsGrpMetaTemporaryMap::iterator mit = grpMeta.begin(); mit != grpMeta.end(); ++mit)
|
||||
{
|
||||
RsGxsGrpMetaData* meta = mit->second;
|
||||
const auto& meta = mit->second;
|
||||
|
||||
// This was commented out because we want to know how many messages are available for unsubscribed groups.
|
||||
|
||||
@ -674,7 +674,7 @@ void RsGxsNetService::syncWithPeers()
|
||||
RsGxsGrpMetaTemporaryMap::const_iterator mmit = toRequest.begin();
|
||||
for(; mmit != toRequest.end(); ++mmit)
|
||||
{
|
||||
const RsGxsGrpMetaData* meta = mmit->second;
|
||||
const auto& meta = mmit->second;
|
||||
const RsGxsGroupId& grpId = mmit->first;
|
||||
RsGxsCircleId encrypt_to_this_circle_id ;
|
||||
|
||||
@ -928,7 +928,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||
|
||||
const RsGxsGrpMetaData* grpMeta = grpMetas[grs->grpId];
|
||||
const auto& grpMeta = grpMetas[grs->grpId];
|
||||
|
||||
if(grpMeta == NULL)
|
||||
{
|
||||
@ -959,7 +959,7 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs)
|
||||
#endif
|
||||
mDataStore->retrieveGxsMsgMetaData(reqIds, result);
|
||||
|
||||
const std::vector<const RsGxsMsgMetaData*>& vec(result[grs->grpId]) ;
|
||||
const auto& vec(result[grs->grpId]) ;
|
||||
|
||||
if(vec.empty()) // that means we don't have any, or there isn't any, but since the default is always 0, no need to send.
|
||||
return ;
|
||||
@ -2196,7 +2196,7 @@ void RsGxsNetService::updateServerSyncTS()
|
||||
|
||||
RS_STACK_MUTEX(mNxsMutex) ;
|
||||
|
||||
const RsGxsGrpMetaData* grpMeta = mit->second;
|
||||
const auto& grpMeta = mit->second;
|
||||
#ifdef TO_REMOVE
|
||||
// That accounts for modification of the meta data.
|
||||
|
||||
@ -2924,7 +2924,7 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
grpMetaMap[grpId] = NULL;
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
|
||||
const RsGxsGrpMetaData* grpMeta = grpMetaMap[grpId];
|
||||
const auto& grpMeta = grpMetaMap[grpId];
|
||||
|
||||
if(grpMeta == NULL) // this should not happen, but just in case...
|
||||
{
|
||||
@ -2956,17 +2956,16 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
|
||||
reqIds[grpId] = std::set<RsGxsMessageId>();
|
||||
GxsMsgMetaResult result;
|
||||
mDataStore->retrieveGxsMsgMetaData(reqIds, result);
|
||||
std::vector<const RsGxsMsgMetaData*> &msgMetaV = result[grpId];
|
||||
auto& msgMetaV = result[grpId];
|
||||
|
||||
#ifdef NXS_NET_DEBUG_1
|
||||
GXSNETDEBUG_PG(item->PeerId(),grpId) << " retrieving grp message list..." << std::endl;
|
||||
GXSNETDEBUG_PG(item->PeerId(),grpId) << " grp locally contains " << msgMetaV.size() << " messsages." << std::endl;
|
||||
#endif
|
||||
std::vector<const RsGxsMsgMetaData*>::const_iterator vit = msgMetaV.begin();
|
||||
std::set<RsGxsMessageId> msgIdSet;
|
||||
|
||||
// put ids in set for each searching
|
||||
for(; vit != msgMetaV.end(); ++vit)
|
||||
for(auto vit=msgMetaV.begin(); vit != msgMetaV.end(); ++vit)
|
||||
msgIdSet.insert((*vit)->mMsgId);
|
||||
|
||||
msgMetaV.clear();
|
||||
@ -3230,7 +3229,7 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
|
||||
RsNxsSyncGrpItem*& grpSyncItem = *llit;
|
||||
const RsGxsGroupId& grpId = grpSyncItem->grpId;
|
||||
|
||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator metaIter = grpMetaMap.find(grpId);
|
||||
auto metaIter = grpMetaMap.find(grpId);
|
||||
bool haveItem = false;
|
||||
bool latestVersion = false;
|
||||
|
||||
@ -4050,7 +4049,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrpReqItem *item)
|
||||
|
||||
for(auto mit = grp.begin(); mit != grp.end(); ++mit)
|
||||
{
|
||||
const RsGxsGrpMetaData* grpMeta = mit->second;
|
||||
const auto& grpMeta = mit->second;
|
||||
|
||||
// Only send info about subscribed groups.
|
||||
|
||||
@ -4369,7 +4368,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_
|
||||
grpMetas[item->grpId] = NULL;
|
||||
|
||||
mDataStore->retrieveGxsGrpMetaData(grpMetas);
|
||||
const RsGxsGrpMetaData* grpMeta = grpMetas[item->grpId];
|
||||
const auto& grpMeta = grpMetas[item->grpId];
|
||||
|
||||
if(grpMeta == NULL)
|
||||
{
|
||||
@ -4402,7 +4401,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_
|
||||
|
||||
GxsMsgMetaResult metaResult;
|
||||
mDataStore->retrieveGxsMsgMetaData(req, metaResult);
|
||||
std::vector<const RsGxsMsgMetaData*>& msgMetas = metaResult[item->grpId];
|
||||
auto& msgMetas = metaResult[item->grpId];
|
||||
|
||||
#ifdef NXS_NET_DEBUG_0
|
||||
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << " retrieving message meta data." << std::endl;
|
||||
@ -4432,7 +4431,7 @@ void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsgReqItem *item,bool item_
|
||||
{
|
||||
for(auto vit = msgMetas.begin();vit != msgMetas.end(); ++vit)
|
||||
{
|
||||
const RsGxsMsgMetaData* m = *vit;
|
||||
const auto& m = *vit;
|
||||
|
||||
// Check reputation
|
||||
|
||||
@ -4577,7 +4576,7 @@ void RsGxsNetService::locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, c
|
||||
}
|
||||
}
|
||||
|
||||
bool RsGxsNetService::canSendMsgIds(std::vector<const RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId,RsGxsCircleId& should_encrypt_id)
|
||||
bool RsGxsNetService::canSendMsgIds(std::vector<std::shared_ptr<RsGxsMsgMetaData> >& msgMetas, const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId,RsGxsCircleId& should_encrypt_id)
|
||||
{
|
||||
#ifdef NXS_NET_DEBUG_4
|
||||
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendMsgIds() CIRCLE VETTING" << std::endl;
|
||||
@ -4929,7 +4928,7 @@ void RsGxsNetService::sharePublishKeysPending()
|
||||
|
||||
// Find the publish keys in the retrieved info
|
||||
|
||||
const RsGxsGrpMetaData *grpMeta = grpMetaMap[mit->first] ;
|
||||
const auto& grpMeta = grpMetaMap[mit->first] ;
|
||||
|
||||
if(grpMeta == NULL)
|
||||
{
|
||||
@ -5014,7 +5013,7 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
|
||||
|
||||
// update the publish keys in this group meta info
|
||||
|
||||
const RsGxsGrpMetaData *grpMeta = grpMetaMap[item->grpId] ;
|
||||
const auto& grpMeta = grpMetaMap[item->grpId] ;
|
||||
if (!grpMeta) {
|
||||
std::cerr << "(EE) RsGxsNetService::handleRecvPublishKeys() grpMeta not found." << std::endl;
|
||||
return ;
|
||||
|
@ -399,7 +399,7 @@ private:
|
||||
* @return false, if you cannot send to this peer, true otherwise
|
||||
*/
|
||||
bool canSendGrpId(const RsPeerId& sslId, const RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool &should_encrypt);
|
||||
bool canSendMsgIds(std::vector<const RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id);
|
||||
bool canSendMsgIds(std::vector<std::shared_ptr<RsGxsMsgMetaData> > &msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id);
|
||||
|
||||
/*!
|
||||
* \brief checkPermissionsForFriendGroup
|
||||
|
@ -156,13 +156,6 @@ GroupDataReq::~GroupDataReq()
|
||||
rsstd::delete_all(mGroupData.begin(), mGroupData.end());
|
||||
}
|
||||
|
||||
MsgMetaReq::~MsgMetaReq()
|
||||
{
|
||||
for (GxsMsgMetaResult::iterator it = mMsgMetaData.begin(); it != mMsgMetaData.end(); ++it) {
|
||||
rsstd::delete_all(it->second.begin(), it->second.end());
|
||||
}
|
||||
}
|
||||
|
||||
MsgDataReq::~MsgDataReq()
|
||||
{
|
||||
for (NxsMsgDataResult::iterator it = mMsgData.begin(); it != mMsgData.end(); ++it) {
|
||||
@ -172,12 +165,8 @@ MsgDataReq::~MsgDataReq()
|
||||
|
||||
MsgRelatedInfoReq::~MsgRelatedInfoReq()
|
||||
{
|
||||
for (MsgRelatedMetaResult::iterator metaIt = mMsgMetaResult.begin(); metaIt != mMsgMetaResult.end(); ++metaIt) {
|
||||
rsstd::delete_all(metaIt->second.begin(), metaIt->second.end());
|
||||
}
|
||||
for (NxsMsgRelatedDataResult::iterator dataIt = mMsgDataResult.begin(); dataIt != mMsgDataResult.end(); ++dataIt) {
|
||||
for (NxsMsgRelatedDataResult::iterator dataIt = mMsgDataResult.begin(); dataIt != mMsgDataResult.end(); ++dataIt)
|
||||
rsstd::delete_all(dataIt->second.begin(), dataIt->second.end());
|
||||
}
|
||||
}
|
||||
std::ostream& MessageSetFlagReq::print(std::ostream& o) const
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
virtual std::ostream& print(std::ostream& o) const override;
|
||||
public:
|
||||
std::list<RsGxsGroupId> mGroupIds;
|
||||
std::list<const RsGxsGrpMetaData*> mGroupMetaData;
|
||||
std::list<std::shared_ptr<RsGxsGrpMetaData> > mGroupMetaData;
|
||||
};
|
||||
|
||||
class GroupIdReq : public GxsRequest
|
||||
@ -98,7 +98,7 @@ public:
|
||||
class MsgMetaReq : public GxsRequest
|
||||
{
|
||||
public:
|
||||
virtual ~MsgMetaReq();
|
||||
virtual ~MsgMetaReq() = default;
|
||||
|
||||
virtual std::ostream& print(std::ostream& o) const override;
|
||||
|
||||
|
@ -111,7 +111,7 @@ bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check,std::vector<RsGxsGrou
|
||||
|
||||
for(; mit != result.end(); ++mit)
|
||||
{
|
||||
std::vector<const RsGxsMsgMetaData*>& metaV = mit->second;
|
||||
auto& metaV = mit->second;
|
||||
|
||||
// First, make a map of which message have a child message. This allows to only delete messages that dont have child messages.
|
||||
// A more accurate way to go would be to compute the time of the oldest message and possibly delete all the branch, but in the
|
||||
@ -125,7 +125,7 @@ bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check,std::vector<RsGxsGrou
|
||||
|
||||
for( uint32_t i=0;i<metaV.size();++i)
|
||||
{
|
||||
const RsGxsMsgMetaData* meta = metaV[i];
|
||||
const auto& meta = metaV[i];
|
||||
|
||||
bool have_kids = (messages_with_kids.find(meta->mMsgId)!=messages_with_kids.end());
|
||||
|
||||
|
@ -102,10 +102,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<RsGxsGroupId,RsGxsGrpMetaData*> RsGxsGrpMetaTemporaryMap;
|
||||
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> RsNxsGrpDataTemporaryMap;
|
||||
typedef std::map<RsGxsGroupId, std::shared_ptr<RsGxsGrpMetaData> > RsGxsGrpMetaTemporaryMap; // This map doesn't need to delete elements since it holds
|
||||
typedef std::map<RsGxsGroupId,std::vector<std::shared_ptr<RsGxsMsgMetaData> > > RsGxsMsgMetaTemporaryMap; // shared_ptr's.
|
||||
|
||||
typedef t_RsGxsGenericDataTemporaryMapVector<RsGxsMsgMetaData> RsGxsMsgMetaTemporaryMap ;
|
||||
typedef t_RsGxsGenericDataTemporaryMap<RsGxsGroupId,RsNxsGrp> RsNxsGrpDataTemporaryMap;
|
||||
typedef t_RsGxsGenericDataTemporaryMapVector<RsNxsMsg> RsNxsMsgDataTemporaryMap ;
|
||||
|
||||
typedef t_RsGxsGenericDataTemporaryList<RsNxsGrp> RsNxsGrpDataTemporaryList ;
|
||||
|
@ -66,6 +66,7 @@ struct RsGroupMetaData : RsSerializable
|
||||
virtual ~RsGroupMetaData() {}
|
||||
|
||||
void operator =(const RsGxsGrpMetaData& rGxsMeta);
|
||||
RsGroupMetaData(const RsGxsGrpMetaData& rGxsMeta) { operator=(rGxsMeta); }
|
||||
|
||||
RsGxsGroupId mGroupId;
|
||||
std::string mGroupName;
|
||||
@ -138,7 +139,9 @@ struct RsMsgMetaData : RsSerializable
|
||||
RsMsgMetaData() : mPublishTs(0), mMsgFlags(0), mMsgStatus(0), mChildTs(0) {}
|
||||
|
||||
virtual ~RsMsgMetaData() {}
|
||||
|
||||
void operator =(const RsGxsMsgMetaData& rGxsMeta);
|
||||
RsMsgMetaData(const RsGxsMsgMetaData& rGxsMeta) { operator=(rGxsMeta); }
|
||||
|
||||
RsGxsGroupId mGroupId;
|
||||
RsGxsMessageId mMsgId;
|
||||
|
Loading…
Reference in New Issue
Block a user