From 22ceec6c4399440b130fddec194f0ace67978d2f Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 26 Dec 2020 23:13:17 +0100 Subject: [PATCH] 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 --- libretroshare/src/gxs/rsdataservice.cc | 109 ++++--------- libretroshare/src/gxs/rsdataservice.h | 65 +++----- libretroshare/src/gxs/rsgds.h | 21 +-- libretroshare/src/gxs/rsgenexchange.cc | 71 +++------ libretroshare/src/gxs/rsgxs.h | 4 +- libretroshare/src/gxs/rsgxsdataaccess.cc | 150 ++++++------------ libretroshare/src/gxs/rsgxsdataaccess.h | 10 +- libretroshare/src/gxs/rsgxsnetservice.cc | 33 ++-- libretroshare/src/gxs/rsgxsnetservice.h | 2 +- libretroshare/src/gxs/rsgxsrequesttypes.cc | 13 +- libretroshare/src/gxs/rsgxsrequesttypes.h | 4 +- libretroshare/src/gxs/rsgxsutil.cc | 4 +- libretroshare/src/gxs/rsgxsutil.h | 6 +- .../src/retroshare/rsgxsifacetypes.h | 3 + 14 files changed, 164 insertions(+), 331 deletions(-) diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index 8cf169103..ec03e76fc 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -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 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 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(); 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 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 msgMeta; if(use_cache) msgMeta = mMsgMetaDataCache[group_id].getOrCreateMeta(msg_id); else - msgMeta = new RsGxsMsgMetaData(); + msgMeta = std::make_shared(); 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& 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& 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 &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 &grp, bool return 1; } -void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector& grps, int metaOffset){ - +void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector& grps, int metaOffset) +{ if(c){ bool valid = c->moveToFirst(); @@ -1150,7 +1150,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector 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::vectormetaData = 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& grpMeta) +void RsDataService::locked_retrieveGrpMetaList(RetroCursor *c, std::map >& grpMeta) { if(!c) { @@ -1340,15 +1340,16 @@ void RsDataService::locked_retrieveGrpMetaList(RetroCursor *c, std::mapmGroupId] = m; valid = c->moveToNext(); } } -void RsDataService::locked_retrieveMsgMetaList(RetroCursor *c, std::vector& msgMeta) + +void RsDataService::locked_retrieveMsgMetaList(RetroCursor *c, std::vector >& msgMeta) { if(!c) { @@ -1357,17 +1358,18 @@ void RsDataService::locked_retrieveMsgMetaList(RetroCursor *c, std::vectormoveToFirst(); - 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 >& 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; diff --git a/libretroshare/src/gxs/rsdataservice.h b/libretroshare/src/gxs/rsdataservice.h index b0d5bdf11..ca975bf85 100644 --- a/libretroshare/src/gxs/rsdataservice.h +++ b/libretroshare/src/gxs/rsdataservice.h @@ -38,35 +38,29 @@ public: template 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& mp) const { mp = mMetas ; } - void getFullMetaList(std::vector& mp) const { for(auto& m:mMetas) mp.push_back(m.second) ; } + void getFullMetaList(std::map >& mp) const { mp = mMetas ; } + void getFullMetaList(std::vector >& mp) const { for(auto& m:mMetas) mp.push_back(m.second) ; } - MetaDataClass *getMeta(const ID& id) + std::shared_ptr 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 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()); + } } 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(); } 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 mMetas; - std::list > mOldCachedItems ; // dead list, where items get deleted after being unused for a while. This is due to not using smart ptrs. + std::map > 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 > &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& msgMeta); + void locked_retrieveMsgMetaList(RetroCursor* c, std::vector > &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& grpMeta); + void locked_retrieveGrpMetaList(RetroCursor *c, std::map > &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 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 locked_getGrpMeta(RetroCursor& c, int colOffset, bool use_cache); /*! * extracts a msg item from a cursor at its diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index d0879b2c9..0120770f1 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -19,8 +19,8 @@ * along with this program. If not, see . * * * *******************************************************************************/ -#ifndef RSGDS_H -#define RSGDS_H + +#pragma once #include #include @@ -56,18 +56,16 @@ struct MsgLocMetaData { ContentValue val; }; -typedef std::map 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 >& 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 diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 3d3346198..b04b9aa3f 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -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 &groupInfo) { - std::list metaL; + std::list > 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& metaV = mit->second; + auto& metaV = mit->second; std::vector& msgInfoV = msgInfo[mit->first]; - std::vector::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& metaV = mit->second; + auto& metaV = mit->second; std::vector& msgInfoV = msgMeta[mit->first]; - std::vector::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& 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(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 grpMeta; bool ok = false; RsGxsGrpMetaTemporaryMap grpMetaMap; - std::map::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::iterator mit = grpMeta.find(groupId); + auto mit = grpMeta.find(groupId); - const RsGxsGrpMetaData* meta = NULL; - if(mit == grpMeta.end() || mit->second == NULL) + std::shared_ptr 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::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. diff --git a/libretroshare/src/gxs/rsgxs.h b/libretroshare/src/gxs/rsgxs.h index fd7f693f9..696f317ae 100644 --- a/libretroshare/src/gxs/rsgxs.h +++ b/libretroshare/src/gxs/rsgxs.h @@ -29,8 +29,8 @@ /* data types used throughout Gxs from netservice to genexchange */ -typedef std::map > GxsMsgMetaResult; -typedef std::map > MsgRelatedMetaResult; +typedef std::map > > GxsMsgMetaResult; +typedef std::map > > MsgRelatedMetaResult; // Default values that are used throughout GXS code diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 8cf70ac24..49d33417d 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -373,7 +373,7 @@ bool RsGxsDataAccess::locked_clearRequest(const uint32_t& token) return true; } -bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list& groupInfo) +bool RsGxsDataAccess::getGroupSummary(const uint32_t& token, std::list >& groupInfo) { RS_STACK_MUTEX(mDataMutex); @@ -908,23 +908,21 @@ bool RsGxsDataAccess::getGroupSummary(GroupMetaReq* req) if(grpIdsOut.empty()) return true; - std::list::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::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& grpIdsIn, const RsTokReqOptions& opts, std::list& 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& 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())); mDataStore->retrieveGxsMsgMetaData(msgIds, result); - std::vector& metaV = result[grpMsgIdPair.first]; - std::vector::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 outMsgIds; - const RsGxsMsgMetaData* origMeta = nullptr; + std::shared_ptr 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& 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 > origMsgTs; std::map >::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 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& metaV = mit->second; - std::vector::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& msgMetaV = mit->second; -// std::vector::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::iterator msgIdIt = msgsIdSet.begin(); msgIdIt != msgsIdSet.end(); ) { const RsGxsMessageId& msgId(*msgIdIt); - const std::map& msgsMetaMap = - cit->second; + const auto& msgsMetaMap = cit->second; bool keep = false; - std::map::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 &grpIds, const RsTokReqOptions &opts, const GrpMetaFilter &meta) const +void RsGxsDataAccess::filterGrpList(std::list &grpIds, const RsTokReqOptions &opts, const GrpMetaFilter& meta) const { - std::list::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& 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 &meta ) const { if (opts.mStatusMask) { diff --git a/libretroshare/src/gxs/rsgxsdataaccess.h b/libretroshare/src/gxs/rsgxsdataaccess.h index 727ebe605..3b801f69f 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.h +++ b/libretroshare/src/gxs/rsgxsdataaccess.h @@ -28,8 +28,8 @@ #include "rsgds.h" -typedef std::map< RsGxsGroupId, std::map > MsgMetaFilter; -typedef std::map< RsGxsGroupId, RsGxsGrpMetaData* > GrpMetaFilter; +typedef std::map< RsGxsGroupId, std::map > > MsgMetaFilter; +typedef std::map< RsGxsGroupId, std::shared_ptr > GrpMetaFilter; bool operator<(const std::pair& p1,const std::pair& p2); @@ -220,7 +220,7 @@ public: * @param token request token to be redeemed * @param groupInfo */ - bool getGroupSummary(const uint32_t &token, std::list& groupInfo); + bool getGroupSummary(const uint32_t &token, std::list > &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& 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 &meta) const; /*! diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index bdf03ff83..f2303dd06 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -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& 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(); GxsMsgMetaResult result; mDataStore->retrieveGxsMsgMetaData(reqIds, result); - std::vector &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_iterator vit = msgMetaV.begin(); std::set 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::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& 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& itemL, c } } -bool RsGxsNetService::canSendMsgIds(std::vector& msgMetas, const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId,RsGxsCircleId& should_encrypt_id) +bool RsGxsNetService::canSendMsgIds(std::vector >& 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 ; diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index e6eb36246..19a12a4d2 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -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& toVet, bool &should_encrypt); - bool canSendMsgIds(std::vector& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id); + bool canSendMsgIds(std::vector > &msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id); /*! * \brief checkPermissionsForFriendGroup diff --git a/libretroshare/src/gxs/rsgxsrequesttypes.cc b/libretroshare/src/gxs/rsgxsrequesttypes.cc index 6c3925974..e10a4efc3 100644 --- a/libretroshare/src/gxs/rsgxsrequesttypes.cc +++ b/libretroshare/src/gxs/rsgxsrequesttypes.cc @@ -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 { diff --git a/libretroshare/src/gxs/rsgxsrequesttypes.h b/libretroshare/src/gxs/rsgxsrequesttypes.h index e738a1923..dd9ddb7cd 100644 --- a/libretroshare/src/gxs/rsgxsrequesttypes.h +++ b/libretroshare/src/gxs/rsgxsrequesttypes.h @@ -55,7 +55,7 @@ public: virtual std::ostream& print(std::ostream& o) const override; public: std::list mGroupIds; - std::list mGroupMetaData; + std::list > 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; diff --git a/libretroshare/src/gxs/rsgxsutil.cc b/libretroshare/src/gxs/rsgxsutil.cc index e381b6fe3..aa79a2ffc 100644 --- a/libretroshare/src/gxs/rsgxsutil.cc +++ b/libretroshare/src/gxs/rsgxsutil.cc @@ -111,7 +111,7 @@ bool RsGxsCleanUp::clean(RsGxsGroupId& next_group_to_check,std::vector& 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::vectormMsgId)!=messages_with_kids.end()); diff --git a/libretroshare/src/gxs/rsgxsutil.h b/libretroshare/src/gxs/rsgxsutil.h index e761ff7c1..5991a82e3 100644 --- a/libretroshare/src/gxs/rsgxsutil.h +++ b/libretroshare/src/gxs/rsgxsutil.h @@ -102,10 +102,10 @@ public: } }; -typedef std::map RsGxsGrpMetaTemporaryMap; -typedef t_RsGxsGenericDataTemporaryMap RsNxsGrpDataTemporaryMap; +typedef std::map > RsGxsGrpMetaTemporaryMap; // This map doesn't need to delete elements since it holds +typedef std::map > > RsGxsMsgMetaTemporaryMap; // shared_ptr's. -typedef t_RsGxsGenericDataTemporaryMapVector RsGxsMsgMetaTemporaryMap ; +typedef t_RsGxsGenericDataTemporaryMap RsNxsGrpDataTemporaryMap; typedef t_RsGxsGenericDataTemporaryMapVector RsNxsMsgDataTemporaryMap ; typedef t_RsGxsGenericDataTemporaryList RsNxsGrpDataTemporaryList ; diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 2550f3b82..dbd071987 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -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;