2013-03-06 18:33:23 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/gxs: rsgxsutil.h
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface. Generic routines that are useful in GXS
|
|
|
|
*
|
|
|
|
* Copyright 2013-2013 by Christopher Evi-Parker
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GXSUTIL_H_
|
|
|
|
#define GXSUTIL_H_
|
|
|
|
|
|
|
|
#include <vector>
|
2013-03-20 18:26:24 -04:00
|
|
|
#include "serialiser/rsnxsitems.h"
|
|
|
|
#include "rsgds.h"
|
2013-03-06 18:33:23 -05:00
|
|
|
|
2015-12-15 12:31:03 -05:00
|
|
|
class RsGixs ;
|
|
|
|
|
2013-03-06 18:33:23 -05:00
|
|
|
/*!
|
|
|
|
* Handy function for cleaning out meta result containers
|
|
|
|
* @param container
|
|
|
|
*/
|
|
|
|
template <class Container, class Item>
|
|
|
|
void freeAndClearContainerResource(Container container)
|
|
|
|
{
|
|
|
|
typename Container::iterator meta_it = container.begin();
|
|
|
|
|
2014-10-24 18:07:26 -04:00
|
|
|
for(; meta_it != container.end(); ++meta_it)
|
2013-03-06 18:33:23 -05:00
|
|
|
{
|
|
|
|
delete meta_it->second;
|
|
|
|
|
|
|
|
}
|
|
|
|
container.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline RsGxsGrpMsgIdPair getMsgIdPair(RsNxsMsg& msg)
|
|
|
|
{
|
|
|
|
return RsGxsGrpMsgIdPair(std::make_pair(msg.grpId, msg.msgId));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline RsGxsGrpMsgIdPair getMsgIdPair(RsGxsMsgItem& msg)
|
|
|
|
{
|
|
|
|
return RsGxsGrpMsgIdPair(std::make_pair(msg.meta.mGroupId, msg.meta.mMsgId));
|
|
|
|
}
|
|
|
|
|
2013-03-20 18:26:24 -04:00
|
|
|
/*!
|
|
|
|
* Does message clean up based on individual group expirations first
|
|
|
|
* if avialable. If not then deletion s
|
|
|
|
*/
|
2015-05-22 16:54:38 -04:00
|
|
|
class RsGxsMessageCleanUp //: public RsThread
|
2013-03-20 18:26:24 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @param dataService
|
|
|
|
* @param mGroupTS
|
|
|
|
* @param chunkSize
|
|
|
|
* @param sleepPeriod
|
|
|
|
*/
|
|
|
|
RsGxsMessageCleanUp(RsGeneralDataService* const dataService, uint32_t messageStorePeriod, uint32_t chunkSize);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* On construction this should be called to progress deletions
|
|
|
|
* Deletion will process by chunk size
|
|
|
|
* @return true if no more messages to delete, false otherwise
|
|
|
|
*/
|
|
|
|
bool clean();
|
|
|
|
|
|
|
|
/*!
|
2013-06-04 17:00:43 -04:00
|
|
|
* TODO: Rather than manual progressions consider running through a thread
|
2013-03-20 18:26:24 -04:00
|
|
|
*/
|
2015-05-22 16:54:38 -04:00
|
|
|
//virtual void data_tick(){}
|
2013-03-20 18:26:24 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
RsGeneralDataService* const mDs;
|
|
|
|
const uint32_t MESSAGE_STORE_PERIOD, CHUNK_SIZE;
|
2013-03-23 10:07:52 -04:00
|
|
|
std::vector<RsGxsGrpMetaData*> mGrpMeta;
|
2013-03-20 18:26:24 -04:00
|
|
|
};
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
/*!
|
|
|
|
* Checks the integrity message and groups
|
|
|
|
* in rsDataService using computed hash
|
|
|
|
*/
|
2015-05-22 16:54:38 -04:00
|
|
|
class RsGxsIntegrityCheck : public RsSingleJobThread
|
2013-06-04 17:00:43 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
enum CheckState { CheckStart, CheckChecking };
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @param dataService
|
|
|
|
* @param mGroupTS
|
|
|
|
* @param chunkSize
|
|
|
|
* @param sleepPeriod
|
|
|
|
*/
|
2015-12-15 12:31:03 -05:00
|
|
|
RsGxsIntegrityCheck(RsGeneralDataService* const dataService, RsGixs *gixs);
|
2013-06-04 17:00:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
bool check();
|
|
|
|
bool isDone();
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
2014-09-28 08:11:29 -04:00
|
|
|
void getDeletedIds(std::list<RsGxsGroupId>& grpIds, std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgIds);
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
RsGeneralDataService* const mDs;
|
|
|
|
bool mDone;
|
|
|
|
RsMutex mIntegrityMutex;
|
2014-09-28 08:11:29 -04:00
|
|
|
std::list<RsGxsGroupId> mDeletedGrps;
|
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > mDeletedMsgs;
|
2015-12-15 12:31:03 -05:00
|
|
|
|
|
|
|
RsGixs *mGixs ;
|
2013-06-04 17:00:43 -04:00
|
|
|
};
|
2013-03-06 18:33:23 -05:00
|
|
|
|
2013-09-11 16:42:56 -04:00
|
|
|
class GroupUpdate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GroupUpdate() : oldGrpMeta(NULL), newGrp(NULL), validUpdate(false)
|
|
|
|
{}
|
|
|
|
RsGxsGrpMetaData* oldGrpMeta;
|
|
|
|
RsNxsGrp* newGrp;
|
|
|
|
bool validUpdate;
|
|
|
|
};
|
|
|
|
|
2013-10-05 07:36:31 -04:00
|
|
|
class GroupUpdatePublish
|
|
|
|
{
|
|
|
|
public:
|
2014-02-18 17:44:03 -05:00
|
|
|
GroupUpdatePublish(RsGxsGrpItem* item, uint32_t token)
|
|
|
|
: grpItem(item), mToken(token) {}
|
2013-10-05 07:36:31 -04:00
|
|
|
RsGxsGrpItem* grpItem;
|
|
|
|
uint32_t mToken;
|
|
|
|
};
|
|
|
|
|
2014-05-06 13:15:20 -04:00
|
|
|
class GroupDeletePublish
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GroupDeletePublish(RsGxsGrpItem* item, uint32_t token)
|
|
|
|
: grpItem(item), mToken(token) {}
|
|
|
|
RsGxsGrpItem* grpItem;
|
|
|
|
uint32_t mToken;
|
|
|
|
};
|
|
|
|
|
2013-03-06 18:33:23 -05:00
|
|
|
#endif /* GXSUTIL_H_ */
|