2012-05-17 18:45:48 -04:00
|
|
|
#ifndef RSDATASERVICE_H
|
|
|
|
#define RSDATASERVICE_H
|
|
|
|
|
2012-08-06 17:00:38 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/gxs: rsdataservice.h
|
|
|
|
*
|
|
|
|
* General Data service, interface for RetroShare.
|
|
|
|
*
|
2012-11-11 18:45:22 -05:00
|
|
|
* Copyright 2011-2012 by Evi-Parker Christopher
|
2012-08-06 17:00:38 -04:00
|
|
|
*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-07-12 16:18:58 -04:00
|
|
|
#include "gxs/rsgds.h"
|
2012-05-17 18:45:48 -04:00
|
|
|
#include "util/retrodb.h"
|
|
|
|
|
2013-03-20 18:26:24 -04:00
|
|
|
class MsgUpdate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2013-10-11 13:29:38 -04:00
|
|
|
//MsgUpdate(){}
|
|
|
|
//MsgUpdate(const MsgUpdate& ){}//hier müsste ein echter constructor sein
|
2013-03-20 18:26:24 -04:00
|
|
|
RsGxsMessageId msgId;
|
|
|
|
ContentValue cv;
|
|
|
|
};
|
2012-09-04 18:32:52 -04:00
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
class RsDataService : public RsGeneralDataService
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
RsDataService(const std::string& serviceDir, const std::string& dbName, uint16_t serviceType,
|
|
|
|
RsGxsSearchModule* mod = NULL, const std::string& key = "");
|
2012-08-06 17:00:38 -04:00
|
|
|
virtual ~RsDataService();
|
2012-05-17 18:45:48 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Retrieves all msgs
|
|
|
|
* @param reqIds requested msg ids (grpId,msgId), leave msg list empty to get all msgs for the grp
|
2012-05-17 18:45:48 -04:00
|
|
|
* @param msg result of msg retrieval
|
2012-06-26 15:52:01 -04:00
|
|
|
* @param cache whether to store results of this retrieval in memory for faster later retrieval
|
2012-05-17 18:45:48 -04:00
|
|
|
* @return error code
|
|
|
|
*/
|
2012-08-19 18:15:37 -04:00
|
|
|
int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache, bool withMeta = false);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
|
|
|
/*!
|
2012-07-14 13:59:54 -04:00
|
|
|
* Retrieves groups, if empty, retrieves all grps, if map is not empty
|
2012-07-15 08:38:20 -04:00
|
|
|
* only retrieve entries, if entry cannot be found, it is removed from map
|
2012-06-26 15:52:01 -04:00
|
|
|
* @param grp retrieved groups
|
2012-07-26 17:48:54 -04:00
|
|
|
* @param withMeta this initialise the metaData member of the nxsgroups retrieved
|
2012-05-17 18:45:48 -04:00
|
|
|
* @param cache whether to store retrieval in mem for faster later retrieval
|
|
|
|
* @return error code
|
|
|
|
*/
|
2014-03-17 16:56:06 -04:00
|
|
|
int retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp*>& grp, bool withMeta, bool cache);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Retrieves meta data of all groups stored (most current versions only)
|
|
|
|
* @param cache whether to store retrieval in mem for faster later retrieval
|
|
|
|
* @return error code
|
2012-05-17 18:45:48 -04:00
|
|
|
*/
|
2018-01-07 15:41:41 -05:00
|
|
|
int retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2012-05-21 18:07:43 -04:00
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Retrieves meta data of all groups stored (most current versions only)
|
|
|
|
* @param grpIds grpIds for which to retrieve meta data
|
|
|
|
* @param msgMeta meta data result as map of grpIds to array of metadata for that grpId
|
|
|
|
* @param cache whether to store retrieval in mem for faster later retrieval
|
|
|
|
* @return error code
|
2012-05-21 18:07:43 -04:00
|
|
|
*/
|
2012-09-20 13:18:26 -04:00
|
|
|
int retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaResult& msgMeta);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2012-06-03 14:09:38 -04:00
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* remove msgs in data store
|
|
|
|
* @param grpId group Id of message to be removed
|
2012-06-03 14:09:38 -04:00
|
|
|
* @param msgIds ids of messages to be removed
|
|
|
|
* @return error code
|
|
|
|
*/
|
2012-08-06 17:00:38 -04:00
|
|
|
int removeMsgs(const GxsMsgReq& msgIds);
|
2012-06-03 14:09:38 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* remove groups in data store listed in grpIds param
|
|
|
|
* @param grpIds ids of groups to be removed
|
|
|
|
* @return error code
|
|
|
|
*/
|
2012-08-06 17:00:38 -04:00
|
|
|
int removeGroups(const std::vector<RsGxsGroupId>& grpIds);
|
2012-06-03 14:09:38 -04:00
|
|
|
|
2013-09-11 16:42:56 -04:00
|
|
|
/*!
|
|
|
|
* Retrieves all group ids in store
|
|
|
|
* @param grpIds all grpids in store is inserted into this vector
|
|
|
|
* @return error code
|
|
|
|
*/
|
2014-03-17 16:56:06 -04:00
|
|
|
int retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds);
|
2013-09-11 16:42:56 -04:00
|
|
|
|
2014-04-26 06:07:25 -04:00
|
|
|
/*!
|
|
|
|
* Retrives all msg ids in store
|
|
|
|
* @param grpId groupId of message ids to retrieve
|
|
|
|
* @param msgId msgsids retrieved
|
|
|
|
* @return error code
|
|
|
|
*/
|
|
|
|
int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgId);
|
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* @return the cache size set for this RsGeneralDataService in bytes
|
2012-05-17 18:45:48 -04:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
uint32_t cacheSize() const;
|
2012-05-17 18:45:48 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* @param size size of cache to set in bytes
|
2012-05-17 18:45:48 -04:00
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
int setCacheSize(uint32_t size);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Stores a list of signed messages into data store
|
|
|
|
* @param msg map of message and decoded meta data information
|
|
|
|
* @return error code
|
2012-05-17 18:45:48 -04:00
|
|
|
*/
|
2017-07-24 18:07:53 -04:00
|
|
|
int storeMessage(const std::list<RsNxsMsg*>& msg);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2012-05-21 18:07:43 -04:00
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Stores a list of groups in data store
|
|
|
|
* @param grp map of group and decoded meta data
|
|
|
|
* @return error code
|
2012-05-21 18:07:43 -04:00
|
|
|
*/
|
2017-07-24 18:07:53 -04:00
|
|
|
int storeGroup(const std::list<RsNxsGrp*>& grp);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2013-09-11 16:42:56 -04:00
|
|
|
/*!
|
|
|
|
* Updates group entries in Db
|
|
|
|
* @param grp map of group and decoded meta data
|
|
|
|
* @return error code
|
|
|
|
*/
|
2017-07-24 18:07:53 -04:00
|
|
|
int updateGroup(const std::list<RsNxsGrp*>& grsp);
|
2013-09-11 16:42:56 -04:00
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* @param metaData The meta data item to update
|
2012-05-17 18:45:48 -04:00
|
|
|
* @return error code
|
|
|
|
*/
|
2012-08-19 18:15:37 -04:00
|
|
|
int updateMessageMetaData(MsgLocMetaData& metaData);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* @param metaData The meta data item to update
|
2012-05-17 18:45:48 -04:00
|
|
|
* @return error code
|
|
|
|
*/
|
2012-08-19 18:15:37 -04:00
|
|
|
int updateGroupMetaData(GrpLocMetaData& meta);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2012-06-03 14:09:38 -04:00
|
|
|
/*!
|
|
|
|
* Completely clear out data stored in
|
2012-06-26 15:52:01 -04:00
|
|
|
* and returns this to a state
|
2012-06-03 14:09:38 -04:00
|
|
|
* as it was when first constructed
|
2012-06-26 15:52:01 -04:00
|
|
|
* @return error code
|
2012-06-03 14:09:38 -04:00
|
|
|
*/
|
|
|
|
int resetDataStore();
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
bool validSize(RsNxsMsg* msg) const;
|
|
|
|
bool validSize(RsNxsGrp* grp) const;
|
|
|
|
|
2014-10-05 15:14:05 -04:00
|
|
|
/*!
|
|
|
|
* Convenience function used to only update group keys. This is used when sending
|
|
|
|
* publish keys between peers.
|
|
|
|
* @return SQL error code
|
|
|
|
*/
|
|
|
|
|
|
|
|
int updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurityKeySet& keys, uint32_t subscribe_flags) ;
|
2013-02-07 18:04:16 -05:00
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
private:
|
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
/*!
|
|
|
|
* Retrieves all the msg results from a cursor
|
|
|
|
* @param c cursor to result set
|
|
|
|
* @param msgs messages retrieved from cursor are stored here
|
|
|
|
*/
|
2015-09-05 06:46:18 -04:00
|
|
|
void locked_retrieveMessages(RetroCursor* c, std::vector<RsNxsMsg*>& msgs, int metaOffset);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2012-07-14 13:59:54 -04:00
|
|
|
/*!
|
2012-08-19 18:15:37 -04:00
|
|
|
* Retrieves all the grp results from a cursor
|
2012-08-06 17:00:38 -04:00
|
|
|
* @param c cursor to result set
|
2012-08-19 18:15:37 -04:00
|
|
|
* @param grps groups retrieved from cursor are stored here
|
2015-09-05 06:46:18 -04:00
|
|
|
* @param withMeta this initialise the metaData member of the nxsgroups retrieved
|
2012-08-19 18:15:37 -04:00
|
|
|
*/
|
2015-09-05 06:46:18 -04:00
|
|
|
void locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>& grps, int metaOffset);
|
2012-08-19 18:15:37 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Retrieves all the msg meta results from a cursor
|
|
|
|
* @param c cursor to result set
|
|
|
|
* @param metaSet message metadata retrieved from cursor are stored here
|
2012-08-06 17:00:38 -04:00
|
|
|
*/
|
2013-03-23 10:07:52 -04:00
|
|
|
void locked_retrieveMsgMeta(RetroCursor* c, std::vector<RsGxsMsgMetaData*>& msgMeta);
|
2012-07-14 13:59:54 -04:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
/*!
|
|
|
|
* extracts a msg meta item from a cursor at its
|
|
|
|
* current position
|
|
|
|
*/
|
2015-09-05 06:46:18 -04:00
|
|
|
RsGxsMsgMetaData* locked_getMsgMeta(RetroCursor& c, int colOffset);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
/*!
|
|
|
|
* extracts a grp meta item from a cursor at its
|
|
|
|
* current position
|
|
|
|
*/
|
2018-01-09 18:10:08 -05:00
|
|
|
RsGxsGrpMetaData* locked_getGrpMeta(RetroCursor& c, int colOffset, bool use_cache);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* extracts a msg item from a cursor at its
|
|
|
|
* current position
|
|
|
|
*/
|
2013-03-23 10:07:52 -04:00
|
|
|
RsNxsMsg* locked_getMessage(RetroCursor& c);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* extracts a grp item from a cursor at its
|
|
|
|
* current position
|
|
|
|
*/
|
2013-03-23 10:07:52 -04:00
|
|
|
RsNxsGrp* locked_getGroup(RetroCursor& c);
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Creates an sql database and its associated file
|
|
|
|
* also creates the message and groups table
|
2015-08-16 07:27:04 -04:00
|
|
|
* @param isNewDatabase is new database
|
2012-06-26 15:52:01 -04:00
|
|
|
*/
|
2015-08-16 07:27:04 -04:00
|
|
|
void initialise(bool isNewDatabase);
|
2012-05-17 18:45:48 -04:00
|
|
|
|
2013-03-20 18:26:24 -04:00
|
|
|
/*!
|
|
|
|
* Remove entries for data base
|
|
|
|
* @param msgIds
|
|
|
|
*/
|
2013-03-23 10:07:52 -04:00
|
|
|
bool locked_removeMessageEntries(const GxsMsgReq& msgIds);
|
2014-03-17 16:56:06 -04:00
|
|
|
bool locked_removeGroupEntries(const std::vector<RsGxsGroupId>& grpIds);
|
2013-03-20 18:26:24 -04:00
|
|
|
|
2015-08-16 07:27:04 -04:00
|
|
|
private:
|
2013-03-20 18:26:24 -04:00
|
|
|
/*!
|
2015-08-16 07:27:04 -04:00
|
|
|
* Start release update
|
|
|
|
* @param release
|
|
|
|
* @return true/false
|
2013-03-20 18:26:24 -04:00
|
|
|
*/
|
2015-08-16 07:27:04 -04:00
|
|
|
bool startReleaseUpdate(int release);
|
2013-03-20 18:26:24 -04:00
|
|
|
|
2015-08-16 07:27:04 -04:00
|
|
|
/*!
|
|
|
|
* Finish release update
|
|
|
|
* @param release
|
|
|
|
* @param result
|
|
|
|
* @return true/false
|
|
|
|
*/
|
|
|
|
bool finishReleaseUpdate(int release, bool result);
|
2013-03-20 18:26:24 -04:00
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
private:
|
|
|
|
|
2012-10-15 14:52:47 -04:00
|
|
|
RsMutex mDbMutex;
|
|
|
|
|
2015-08-23 13:05:37 -04:00
|
|
|
std::list<std::string> mMsgColumns;
|
|
|
|
std::list<std::string> mMsgMetaColumns;
|
2015-09-05 06:46:18 -04:00
|
|
|
std::list<std::string> mMsgColumnsWithMeta;
|
2014-04-26 06:07:25 -04:00
|
|
|
std::list<std::string> mMsgIdColumn;
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2015-08-23 13:05:37 -04:00
|
|
|
std::list<std::string> mGrpColumns;
|
|
|
|
std::list<std::string> mGrpMetaColumns;
|
2015-09-05 06:46:18 -04:00
|
|
|
std::list<std::string> mGrpColumnsWithMeta;
|
2015-08-23 13:05:37 -04:00
|
|
|
std::list<std::string> mGrpIdColumn;
|
|
|
|
|
|
|
|
// Message meta column
|
|
|
|
int mColMsgMeta_GrpId;
|
|
|
|
int mColMsgMeta_TimeStamp;
|
|
|
|
int mColMsgMeta_NxsFlags;
|
|
|
|
int mColMsgMeta_SignSet;
|
|
|
|
int mColMsgMeta_NxsIdentity;
|
|
|
|
int mColMsgMeta_NxsHash;
|
|
|
|
int mColMsgMeta_MsgId;
|
|
|
|
int mColMsgMeta_OrigMsgId;
|
|
|
|
int mColMsgMeta_MsgStatus;
|
|
|
|
int mColMsgMeta_ChildTs;
|
|
|
|
int mColMsgMeta_MsgParentId;
|
|
|
|
int mColMsgMeta_MsgThreadId;
|
|
|
|
int mColMsgMeta_Name;
|
|
|
|
int mColMsgMeta_NxsServString;
|
|
|
|
int mColMsgMeta_RecvTs;
|
|
|
|
int mColMsgMeta_NxsDataLen;
|
|
|
|
|
|
|
|
// Message columns
|
|
|
|
int mColMsg_GrpId;
|
|
|
|
int mColMsg_NxsData;
|
|
|
|
int mColMsg_MetaData;
|
|
|
|
int mColMsg_MsgId;
|
|
|
|
|
2015-09-05 06:46:18 -04:00
|
|
|
// Message columns with meta
|
|
|
|
int mColMsg_WithMetaOffset;
|
|
|
|
|
2015-08-23 13:05:37 -04:00
|
|
|
// Group meta columns
|
|
|
|
int mColGrpMeta_GrpId;
|
|
|
|
int mColGrpMeta_TimeStamp;
|
|
|
|
int mColGrpMeta_NxsFlags;
|
|
|
|
// int mColGrpMeta_SignSet;
|
|
|
|
int mColGrpMeta_NxsIdentity;
|
|
|
|
int mColGrpMeta_NxsHash;
|
|
|
|
int mColGrpMeta_KeySet;
|
|
|
|
int mColGrpMeta_SubscrFlag;
|
|
|
|
int mColGrpMeta_Pop;
|
|
|
|
int mColGrpMeta_MsgCount;
|
|
|
|
int mColGrpMeta_Status;
|
|
|
|
int mColGrpMeta_Name;
|
|
|
|
int mColGrpMeta_LastPost;
|
|
|
|
int mColGrpMeta_OrigGrpId;
|
|
|
|
int mColGrpMeta_ServString;
|
|
|
|
int mColGrpMeta_SignFlags;
|
|
|
|
int mColGrpMeta_CircleId;
|
|
|
|
int mColGrpMeta_CircleType;
|
|
|
|
int mColGrpMeta_InternCircle;
|
|
|
|
int mColGrpMeta_Originator;
|
|
|
|
int mColGrpMeta_AuthenFlags;
|
|
|
|
int mColGrpMeta_ParentGrpId;
|
|
|
|
int mColGrpMeta_RecvTs;
|
|
|
|
int mColGrpMeta_RepCutoff;
|
|
|
|
int mColGrpMeta_NxsDataLen;
|
|
|
|
|
|
|
|
// Group columns
|
|
|
|
int mColGrp_GrpId;
|
|
|
|
int mColGrp_NxsData;
|
|
|
|
int mColGrp_MetaData;
|
|
|
|
|
2015-09-05 06:46:18 -04:00
|
|
|
// Group columns with meta
|
|
|
|
int mColGrp_WithMetaOffset;
|
|
|
|
|
2015-08-23 13:05:37 -04:00
|
|
|
// Group id columns
|
|
|
|
int mColGrpId_GrpId;
|
|
|
|
|
|
|
|
// Msg id columns
|
|
|
|
int mColMsgId_MsgId;
|
2012-05-21 18:07:43 -04:00
|
|
|
|
2015-08-13 05:03:57 -04:00
|
|
|
std::string mServiceDir;
|
|
|
|
std::string mDbName;
|
|
|
|
std::string mDbPath;
|
2012-05-21 18:07:43 -04:00
|
|
|
uint16_t mServType;
|
2013-06-04 17:00:43 -04:00
|
|
|
|
|
|
|
RetroDb* mDb;
|
2016-07-01 23:38:10 -04:00
|
|
|
|
|
|
|
// used to store metadata instead of reading it from the database.
|
|
|
|
// The boolean variable below is also used to force re-reading when
|
|
|
|
// the entre list of grp metadata is requested (which happens quite often)
|
|
|
|
|
2016-07-22 17:49:07 -04:00
|
|
|
void locked_clearGrpMetaCache(const RsGxsGroupId& gid);
|
2018-01-09 18:10:08 -05:00
|
|
|
void locked_updateGrpMetaCache(const RsGxsGrpMetaData& meta);
|
2016-07-22 17:49:07 -04:00
|
|
|
|
2018-01-09 18:10:08 -05:00
|
|
|
std::map<RsGxsGroupId,RsGxsGrpMetaData*> mGrpMetaDataCache ;
|
2016-07-01 23:38:10 -04:00
|
|
|
bool mGrpMetaDataCache_ContainsAllDatabase ;
|
2012-05-17 18:45:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RSDATASERVICE_H
|