mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
RsGxsIntegrityCheck
- Fixed message hash checking - Added check for existing but not loadable messages - Notify the gui when messages are deleted git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7568 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
03fc766e55
commit
e6eb0e22ff
@ -209,6 +209,27 @@ void RsGenExchange::tick()
|
||||
{
|
||||
if(mIntegrityCheck->isDone())
|
||||
{
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgIds;
|
||||
mIntegrityCheck->getDeletedIds(grpIds, msgIds);
|
||||
|
||||
if (!grpIds.empty())
|
||||
{
|
||||
RsStackMutex stack(mGenMtx);
|
||||
|
||||
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PROCESSED, false);
|
||||
gc->mGrpIdList = grpIds;
|
||||
mNotifications.push_back(gc);
|
||||
}
|
||||
|
||||
if (!msgIds.empty()) {
|
||||
RsStackMutex stack(mGenMtx);
|
||||
|
||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED, false);
|
||||
c->msgChangeMap = msgIds;
|
||||
mNotifications.push_back(c);
|
||||
}
|
||||
|
||||
mIntegrityCheck->join();
|
||||
delete mIntegrityCheck;
|
||||
mIntegrityCheck = NULL;
|
||||
|
@ -123,6 +123,8 @@ bool RsGxsIntegrityCheck::check()
|
||||
std::map<RsGxsGroupId, RsNxsGrp*> grp;
|
||||
mDs->retrieveNxsGrps(grp, true, true);
|
||||
std::vector<RsGxsGroupId> grpsToDel;
|
||||
GxsMsgReq msgIds;
|
||||
GxsMsgReq grps;
|
||||
|
||||
// compute hash and compare to stored value, if it fails then simply add it
|
||||
// to list
|
||||
@ -135,7 +137,24 @@ bool RsGxsIntegrityCheck::check()
|
||||
pHash.addData(grp->grp.bin_data, grp->grp.bin_len);
|
||||
pHash.Complete(currHash);
|
||||
|
||||
if(currHash != grp->metaData->mHash) grpsToDel.push_back(grp->grpId);
|
||||
if(currHash == grp->metaData->mHash)
|
||||
{
|
||||
// get all message ids of group
|
||||
if (mDs->retrieveMsgIds(grp->grpId, msgIds[grp->grpId]) == 1)
|
||||
{
|
||||
// store the group for retrieveNxsMsgs
|
||||
grps[grp->grpId];
|
||||
}
|
||||
else
|
||||
{
|
||||
msgIds.erase(msgIds.find(grp->grpId));
|
||||
// grpsToDel.push_back(grp->grpId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
grpsToDel.push_back(grp->grpId);
|
||||
}
|
||||
delete grp;
|
||||
}
|
||||
|
||||
@ -145,11 +164,41 @@ bool RsGxsIntegrityCheck::check()
|
||||
GxsMsgReq msgsToDel;
|
||||
GxsMsgResult msgs;
|
||||
|
||||
mDs->retrieveNxsMsgs(msgsToDel, msgs, false, true);
|
||||
mDs->retrieveNxsMsgs(grps, msgs, false, true);
|
||||
|
||||
// check msg ids and messages
|
||||
GxsMsgReq::iterator msgIdsIt;
|
||||
for (msgIdsIt = msgIds.begin(); msgIdsIt != msgIds.end(); ++msgIdsIt)
|
||||
{
|
||||
const RsGxsGroupId& grpId = msgIdsIt->first;
|
||||
std::vector<RsGxsMessageId> &msgIdV = msgIdsIt->second;
|
||||
|
||||
std::vector<RsGxsMessageId>::iterator msgIdIt;
|
||||
for (msgIdIt = msgIdV.begin(); msgIdIt != msgIdV.end(); ++msgIdIt)
|
||||
{
|
||||
const RsGxsMessageId& msgId = *msgIdIt;
|
||||
std::vector<RsNxsMsg*> &nxsMsgV = msgs[grpId];
|
||||
|
||||
std::vector<RsNxsMsg*>::iterator nxsMsgIt;
|
||||
for (nxsMsgIt = nxsMsgV.begin(); nxsMsgIt != nxsMsgV.end(); ++nxsMsgIt)
|
||||
{
|
||||
RsNxsMsg *nxsMsg = *nxsMsgIt;
|
||||
if (nxsMsg && msgId == nxsMsg->msgId)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nxsMsgIt == nxsMsgV.end())
|
||||
{
|
||||
msgsToDel[grpId].push_back(msgId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GxsMsgResult::iterator mit = msgs.begin();
|
||||
|
||||
for(; mit != msgs.begin(); mit++)
|
||||
for(; mit != msgs.end(); mit++)
|
||||
{
|
||||
std::vector<RsNxsMsg*>& msgV = mit->second;
|
||||
std::vector<RsNxsMsg*>::iterator vit = msgV.begin();
|
||||
@ -172,6 +221,13 @@ bool RsGxsIntegrityCheck::check()
|
||||
RsStackMutex stack(mIntegrityMutex);
|
||||
mDone = true;
|
||||
|
||||
std::vector<RsGxsGroupId>::iterator grpIt;
|
||||
for(grpIt = grpsToDel.begin(); grpIt != grpsToDel.end(); ++grpIt)
|
||||
{
|
||||
mDeletedGrps.push_back(*grpIt);
|
||||
}
|
||||
mDeletedMsgs = msgsToDel;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -181,3 +237,11 @@ bool RsGxsIntegrityCheck::isDone()
|
||||
return mDone;
|
||||
}
|
||||
|
||||
void RsGxsIntegrityCheck::getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgIds)
|
||||
{
|
||||
RsStackMutex stack(mIntegrityMutex);
|
||||
|
||||
grpIds = mDeletedGrps;
|
||||
msgIds = mDeletedMsgs;
|
||||
}
|
||||
|
||||
|
@ -120,13 +120,15 @@ public:
|
||||
|
||||
void run();
|
||||
|
||||
void getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgIds);
|
||||
|
||||
private:
|
||||
|
||||
RsGeneralDataService* const mDs;
|
||||
std::vector<RsNxsItem*> mItems;
|
||||
bool mDone;
|
||||
RsMutex mIntegrityMutex;
|
||||
|
||||
std::list<RsGxsGroupId> mDeletedGrps;
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > mDeletedMsgs;
|
||||
};
|
||||
|
||||
class GroupUpdate
|
||||
|
Loading…
Reference in New Issue
Block a user