mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-24 15:05:35 -04:00
Merge pull request #2158 from csoler/v0.6-BugFixing_5
Mem leaks fixing and cpu optimization
This commit is contained in:
commit
d112357b77
4 changed files with 26 additions and 23 deletions
|
@ -3174,6 +3174,10 @@ void RsGenExchange::processRecvdMessages()
|
||||||
for(auto& nxs_msg: msgs_to_store)
|
for(auto& nxs_msg: msgs_to_store)
|
||||||
{
|
{
|
||||||
RsGxsMsgItem *item = dynamic_cast<RsGxsMsgItem*>(mSerialiser->deserialise(nxs_msg->msg.bin_data,&nxs_msg->msg.bin_len));
|
RsGxsMsgItem *item = dynamic_cast<RsGxsMsgItem*>(mSerialiser->deserialise(nxs_msg->msg.bin_data,&nxs_msg->msg.bin_len));
|
||||||
|
|
||||||
|
if(!item)
|
||||||
|
continue;
|
||||||
|
|
||||||
item->meta = *nxs_msg->metaData;
|
item->meta = *nxs_msg->metaData;
|
||||||
|
|
||||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVED_NEW, item->meta.mGroupId, item->meta.mMsgId,false);
|
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVED_NEW, item->meta.mGroupId, item->meta.mMsgId,false);
|
||||||
|
|
|
@ -556,6 +556,7 @@ void RsGxsNetTunnelService::receiveTurtleData(const RsTurtleGenericTunnelItem *i
|
||||||
mTurtle2GxsPeer[turtle_virtual_peer_id] = pid_item->virtual_peer_id ;
|
mTurtle2GxsPeer[turtle_virtual_peer_id] = pid_item->virtual_peer_id ;
|
||||||
|
|
||||||
RsGxsNetTunnelVirtualPeerInfo& vp_info(mVirtualPeers[pid_item->virtual_peer_id]) ;
|
RsGxsNetTunnelVirtualPeerInfo& vp_info(mVirtualPeers[pid_item->virtual_peer_id]) ;
|
||||||
|
delete pid_item;
|
||||||
|
|
||||||
vp_info.vpid_status = RsGxsNetTunnelVirtualPeerInfo::RS_GXS_NET_TUNNEL_VP_STATUS_ACTIVE ; // status of the peer
|
vp_info.vpid_status = RsGxsNetTunnelVirtualPeerInfo::RS_GXS_NET_TUNNEL_VP_STATUS_ACTIVE ; // status of the peer
|
||||||
vp_info.side = direction; // client/server
|
vp_info.side = direction; // client/server
|
||||||
|
|
|
@ -85,6 +85,7 @@ class RsGxsMsgChange : public RsGxsNotify
|
||||||
public:
|
public:
|
||||||
RsGxsMsgChange(NotifyType type, const RsGxsGroupId& gid, const RsGxsMessageId& msg_id,bool metaChange)
|
RsGxsMsgChange(NotifyType type, const RsGxsGroupId& gid, const RsGxsMessageId& msg_id,bool metaChange)
|
||||||
: RsGxsNotify(gid), mMsgId(msg_id), mNewMsgItem(nullptr),NOTIFY_TYPE(type), mMetaChange(metaChange) {}
|
: RsGxsNotify(gid), mMsgId(msg_id), mNewMsgItem(nullptr),NOTIFY_TYPE(type), mMetaChange(metaChange) {}
|
||||||
|
virtual ~RsGxsMsgChange() override { delete mNewMsgItem ; }
|
||||||
|
|
||||||
RsGxsMessageId mMsgId;
|
RsGxsMessageId mMsgId;
|
||||||
RsGxsMsgItem *mNewMsgItem;
|
RsGxsMsgItem *mNewMsgItem;
|
||||||
|
|
|
@ -252,7 +252,8 @@ bool RsGxsIntegrityCheck::check(uint16_t service_type, RsGixs *mgixs, RsGeneralD
|
||||||
|
|
||||||
if(currHash == grp->metaData->mHash)
|
if(currHash == grp->metaData->mHash)
|
||||||
{
|
{
|
||||||
// get all message ids of group
|
// Get all message ids of group, store them in msgIds, creating the grp entry at the same time.
|
||||||
|
|
||||||
if (mds->retrieveMsgIds(grp->grpId, msgIds[grp->grpId]) == 1)
|
if (mds->retrieveMsgIds(grp->grpId, msgIds[grp->grpId]) == 1)
|
||||||
{
|
{
|
||||||
// store the group for retrieveNxsMsgs
|
// store the group for retrieveNxsMsgs
|
||||||
|
@ -275,7 +276,8 @@ bool RsGxsIntegrityCheck::check(uint16_t service_type, RsGixs *mgixs, RsGeneralD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else msgIds.erase(msgIds.find(grp->grpId));
|
else
|
||||||
|
msgIds.erase(msgIds.find(grp->grpId)); // could not get them, so group is removed from list.
|
||||||
|
|
||||||
#ifdef RS_DEEP_CHANNEL_INDEX
|
#ifdef RS_DEEP_CHANNEL_INDEX
|
||||||
// This should be moved to p3gxschannels. It is really not the place for this here!
|
// This should be moved to p3gxschannels. It is really not the place for this here!
|
||||||
|
@ -334,30 +336,26 @@ bool RsGxsIntegrityCheck::check(uint16_t service_type, RsGixs *mgixs, RsGeneralD
|
||||||
|
|
||||||
mds->retrieveNxsMsgs(grps, msgs, false, true);
|
mds->retrieveNxsMsgs(grps, msgs, false, true);
|
||||||
|
|
||||||
// check msg ids and messages
|
// Check msg ids and messages. Go through all message IDs referred to by the db call
|
||||||
GxsMsgReq::iterator msgIdsIt;
|
// and verify that the message belongs to the nxs msg data that was just retrieved.
|
||||||
for (msgIdsIt = msgIds.begin(); msgIdsIt != msgIds.end(); ++msgIdsIt)
|
|
||||||
{
|
|
||||||
const RsGxsGroupId& grpId = msgIdsIt->first;
|
|
||||||
std::set<RsGxsMessageId> &msgIdV = msgIdsIt->second;
|
|
||||||
|
|
||||||
std::set<RsGxsMessageId>::iterator msgIdIt;
|
for(auto& msgIdsIt:msgIds)
|
||||||
for (msgIdIt = msgIdV.begin(); msgIdIt != msgIdV.end(); ++msgIdIt)
|
|
||||||
{
|
{
|
||||||
const RsGxsMessageId& msgId = *msgIdIt;
|
const RsGxsGroupId& grpId = msgIdsIt.first;
|
||||||
|
std::set<RsGxsMessageId>& msgIdV = msgIdsIt.second;
|
||||||
|
|
||||||
|
std::set<RsGxsMessageId> nxsMsgS;
|
||||||
std::vector<RsNxsMsg*>& nxsMsgV = msgs[grpId];
|
std::vector<RsNxsMsg*>& nxsMsgV = msgs[grpId];
|
||||||
|
|
||||||
std::vector<RsNxsMsg*>::iterator nxsMsgIt;
|
// To make the search efficient, we first build a set of msgIds to search in.
|
||||||
for (nxsMsgIt = nxsMsgV.begin(); nxsMsgIt != nxsMsgV.end(); ++nxsMsgIt)
|
// Set build and search are both O(n log(n)).
|
||||||
{
|
|
||||||
RsNxsMsg *nxsMsg = *nxsMsgIt;
|
|
||||||
if (nxsMsg && msgId == nxsMsg->msgId)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nxsMsgIt == nxsMsgV.end())
|
for(auto& nxsMsg:nxsMsgV)
|
||||||
|
if(nxsMsg)
|
||||||
|
nxsMsgS.insert(nxsMsg->msgId);
|
||||||
|
|
||||||
|
for (auto& msgId:msgIdV)
|
||||||
|
if(nxsMsgS.find(msgId) == nxsMsgS.end())
|
||||||
{
|
{
|
||||||
msgsToDel[grpId].insert(msgId);
|
msgsToDel[grpId].insert(msgId);
|
||||||
#ifdef RS_DEEP_CHANNEL_INDEX
|
#ifdef RS_DEEP_CHANNEL_INDEX
|
||||||
|
@ -366,7 +364,6 @@ bool RsGxsIntegrityCheck::check(uint16_t service_type, RsGixs *mgixs, RsGeneralD
|
||||||
#endif // def RS_DEEP_CHANNEL_INDEX
|
#endif // def RS_DEEP_CHANNEL_INDEX
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GxsMsgResult::iterator mit = msgs.begin();
|
GxsMsgResult::iterator mit = msgs.begin();
|
||||||
for(; mit != msgs.end(); ++mit)
|
for(; mit != msgs.end(); ++mit)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue