2012-05-17 18:45:48 -04:00
|
|
|
#ifndef RSGDS_H
|
|
|
|
#define RSGDS_H
|
2012-01-11 18:01:29 -05:00
|
|
|
|
2012-01-15 08:07:31 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/gxp: gxp.h
|
|
|
|
*
|
|
|
|
* General Data service, interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2011-2011 by Robert Fernie, Evi-Parker Christopher
|
|
|
|
*
|
|
|
|
* 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-01-18 18:20:53 -05:00
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2012-01-11 18:01:29 -05:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "inttypes.h"
|
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
#include "serialiser/rsgxsitems.h"
|
|
|
|
#include "serialiser/rsnxsitems.h"
|
2012-06-26 15:52:01 -04:00
|
|
|
#include "gxs/rsgxsdata.h"
|
2012-07-28 16:01:30 -04:00
|
|
|
#include "rsgxs.h"
|
2012-10-21 15:45:35 -04:00
|
|
|
#include "util/contentvalue.h"
|
2012-01-15 08:07:31 -05:00
|
|
|
|
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
class RsGxsSearchModule {
|
2012-04-01 17:10:55 -04:00
|
|
|
|
2012-06-11 17:56:23 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
virtual ~RsGxsSearchModule();
|
|
|
|
|
|
|
|
|
|
|
|
};
|
2012-04-01 17:10:55 -04:00
|
|
|
|
2012-07-26 17:48:54 -04:00
|
|
|
/*!
|
|
|
|
* This allows modification of local
|
|
|
|
* meta data items of a message
|
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
class MsgLocMetaData {
|
|
|
|
|
2012-08-19 18:15:37 -04:00
|
|
|
public:
|
2012-08-21 17:32:07 -04:00
|
|
|
MsgLocMetaData(const MsgLocMetaData& meta){ msgId = meta.msgId; val = meta.val;}
|
|
|
|
MsgLocMetaData() {}
|
2012-08-19 18:15:37 -04:00
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
ContentValue val;
|
2012-06-26 15:52:01 -04:00
|
|
|
};
|
|
|
|
|
2012-07-26 17:48:54 -04:00
|
|
|
/*!
|
|
|
|
* This allows modification of local
|
|
|
|
* meta data items of a group
|
|
|
|
*/
|
2012-06-26 15:52:01 -04:00
|
|
|
class GrpLocMetaData {
|
|
|
|
|
2012-08-19 18:15:37 -04:00
|
|
|
public:
|
2012-08-21 17:32:07 -04:00
|
|
|
GrpLocMetaData(const GrpLocMetaData& meta){ grpId = meta.grpId; val = meta.val;}
|
|
|
|
GrpLocMetaData(){}
|
2012-08-19 18:15:37 -04:00
|
|
|
RsGxsGroupId grpId;
|
|
|
|
ContentValue val;
|
2012-06-26 15:52:01 -04:00
|
|
|
|
2012-08-19 18:15:37 -04:00
|
|
|
};
|
2012-07-28 16:01:30 -04:00
|
|
|
|
2014-12-16 01:54:15 -05:00
|
|
|
/*!
|
|
|
|
* This is used to query network statistics for a given group. This is useful to e.g. show group
|
|
|
|
* popularity, or number of visible messages for unsubscribed group.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class RsGroupNetworkStats
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsGroupNetworkStats()
|
|
|
|
{
|
|
|
|
mMaxVisibleCount = 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t mSuppliers ;
|
|
|
|
uint32_t mMaxVisibleCount ;
|
|
|
|
};
|
|
|
|
|
2015-09-12 00:39:35 -04:00
|
|
|
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > NxsMsgDataResult;
|
2012-11-13 17:36:06 -05:00
|
|
|
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsNxsMsg*> > NxsMsgRelatedDataResult;
|
2015-09-12 00:39:35 -04:00
|
|
|
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > GxsMsgResult; // <grpId, msgs>
|
2012-04-01 17:10:55 -04:00
|
|
|
|
2012-01-15 08:07:31 -05:00
|
|
|
/*!
|
2012-02-12 10:29:49 -05:00
|
|
|
* The main role of GDS is the preparation and handing out of messages requested from
|
2012-01-19 18:32:27 -05:00
|
|
|
* RsGeneralExchangeService and RsGeneralExchangeService
|
2012-02-12 10:18:05 -05:00
|
|
|
* It is important to note that no actual messages are passed by this interface as its is expected
|
|
|
|
* architecturally to pass messages to the service via a call back
|
2012-01-18 18:20:53 -05:00
|
|
|
*
|
2012-01-19 18:32:27 -05:00
|
|
|
* It also acts as a layer between RsGeneralStorageService and its parent RsGeneralExchangeService
|
2012-01-18 18:20:53 -05:00
|
|
|
* thus allowing for non-blocking requests, etc.
|
|
|
|
* It also provides caching ability
|
2012-01-19 18:32:27 -05:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Caching feature:
|
|
|
|
* - A cache index should be maintained which is faster than normal message request
|
|
|
|
* - This should allow fast retrieval of message based on grp id or msg id
|
2012-02-12 10:18:05 -05:00
|
|
|
*
|
|
|
|
* Identity Exchange Service:
|
|
|
|
* - As this is the point where data is accessed by both the GNP and GXS the identities
|
|
|
|
* used to decrypt, encrypt and verify is handle here.
|
|
|
|
*
|
2012-04-01 17:10:55 -04:00
|
|
|
* Please note all function are blocking.
|
2012-01-11 18:01:29 -05:00
|
|
|
*/
|
2012-01-18 18:20:53 -05:00
|
|
|
class RsGeneralDataService
|
2012-01-11 18:01:29 -05:00
|
|
|
{
|
2012-04-01 17:10:55 -04:00
|
|
|
|
2012-08-21 17:32:07 -04:00
|
|
|
public:
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
static const uint32_t GXS_MAX_ITEM_SIZE;
|
|
|
|
|
2012-08-21 17:32:07 -04:00
|
|
|
static const std::string MSG_META_SERV_STRING;
|
|
|
|
static const std::string MSG_META_STATUS;
|
|
|
|
|
|
|
|
static const std::string GRP_META_SUBSCRIBE_FLAG;
|
|
|
|
static const std::string GRP_META_STATUS;
|
|
|
|
static const std::string GRP_META_SERV_STRING;
|
2014-02-22 19:08:11 -05:00
|
|
|
static const std::string GRP_META_CUTOFF_LEVEL;
|
2012-08-21 17:32:07 -04:00
|
|
|
|
2012-01-11 18:01:29 -05:00
|
|
|
public:
|
2012-01-18 18:20:53 -05:00
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
typedef std::map<RsNxsGrp*, RsGxsGrpMetaData*> GrpStoreMap;
|
2014-04-26 06:07:25 -04:00
|
|
|
typedef std::map<RsNxsMsg*, RsGxsMsgMetaData*> MsgStoreMap;
|
2014-04-18 17:58:14 -04:00
|
|
|
|
2012-06-28 17:22:55 -04:00
|
|
|
RsGeneralDataService(){}
|
2012-06-26 15:52:01 -04:00
|
|
|
virtual ~RsGeneralDataService(){return;}
|
|
|
|
|
2012-01-18 18:20:53 -05: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-04-01 17:10:55 -04:00
|
|
|
* @return error code
|
2012-01-18 18:20:53 -05:00
|
|
|
*/
|
2012-08-19 18:15:37 -04:00
|
|
|
virtual int retrieveNxsMsgs(const GxsMsgReq& reqIds, GxsMsgResult& msg, bool cache, bool withMeta=false) = 0;
|
2012-02-24 16:15:08 -05:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Retrieves all groups stored
|
|
|
|
* @param grp retrieved groups
|
2012-08-06 17:00:38 -04:00
|
|
|
* @param withMeta if true the meta handle of nxs grps is intitialised
|
2012-05-17 18:45:48 -04:00
|
|
|
* @param cache whether to store retrieval in mem for faster later retrieval
|
2012-04-01 17:10:55 -04:00
|
|
|
* @return error code
|
2012-02-24 16:15:08 -05:00
|
|
|
*/
|
2012-07-26 17:48:54 -04:00
|
|
|
virtual int retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp*>& grp, bool withMeta, bool cache) = 0;
|
2012-01-18 18:20:53 -05:00
|
|
|
|
|
|
|
/*!
|
2012-06-26 15:52:01 -04:00
|
|
|
* Retrieves meta data of all groups stored (most current versions only)
|
2012-07-22 17:38:15 -04:00
|
|
|
*
|
|
|
|
* @param grp if null grpIds entries are made, only meta for those grpId are retrieved \n
|
|
|
|
* , if grpId is failed to be retrieved it will be erased from map
|
2012-04-01 17:10:55 -04:00
|
|
|
* @return error code
|
2012-01-18 18:20:53 -05:00
|
|
|
*/
|
2012-07-22 17:38:15 -04:00
|
|
|
virtual int retrieveGxsGrpMetaData(std::map<RsGxsGroupId, RsGxsGrpMetaData*>& grp) = 0;
|
2012-01-18 18:20:53 -05: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
|
2012-04-01 17:10:55 -04:00
|
|
|
* @return error code
|
2012-01-18 18:20:53 -05:00
|
|
|
*/
|
2012-09-20 13:18:26 -04:00
|
|
|
virtual int retrieveGxsMsgMetaData(const GxsMsgReq& msgIds, GxsMsgMetaResult& msgMeta) = 0;
|
2012-01-18 18:20:53 -05:00
|
|
|
|
2012-06-03 14:09:38 -04:00
|
|
|
/*!
|
|
|
|
* remove msgs in data store listed in msgIds param
|
|
|
|
* @param msgIds ids of messages to be removed
|
|
|
|
* @return error code
|
|
|
|
*/
|
2012-07-22 17:38:15 -04:00
|
|
|
virtual int removeMsgs(const GxsMsgReq& msgIds) = 0;
|
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
|
|
|
|
*/
|
2013-09-15 17:18:20 -04:00
|
|
|
virtual int removeGroups(const std::vector<RsGxsGroupId>& grpIds) = 0;
|
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
|
|
|
|
*/
|
2013-09-15 17:18:20 -04:00
|
|
|
virtual int retrieveGroupIds(std::vector<RsGxsGroupId>& grpIds) = 0;
|
2012-06-03 14:09:38 -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
|
|
|
|
*/
|
|
|
|
virtual int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgId) = 0;
|
|
|
|
|
2012-01-18 18:20:53 -05:00
|
|
|
/*!
|
2012-05-21 18:07:43 -04:00
|
|
|
* @return the cache size set for this RsGeneralDataService in bytes
|
2012-01-18 18:20:53 -05:00
|
|
|
*/
|
2012-05-21 18:07:43 -04:00
|
|
|
virtual uint32_t cacheSize() const = 0;
|
2012-01-18 18:20:53 -05:00
|
|
|
|
2012-05-21 18:07:43 -04:00
|
|
|
/*!
|
|
|
|
* @param size size of cache to set in bytes
|
|
|
|
*/
|
|
|
|
virtual int setCacheSize(uint32_t size) = 0;
|
2012-01-18 18:20:53 -05: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
|
2012-04-01 17:10:55 -04:00
|
|
|
* @return error code
|
2012-01-18 18:20:53 -05:00
|
|
|
*/
|
2012-08-28 17:11:54 -04:00
|
|
|
virtual int storeMessage(std::map<RsNxsMsg*, RsGxsMsgMetaData*>& msgs) = 0;
|
2012-01-18 18:20:53 -05:00
|
|
|
|
|
|
|
/*!
|
2012-04-01 17:10:55 -04:00
|
|
|
* Stores a list of groups in data store
|
2012-06-26 15:52:01 -04:00
|
|
|
* @param grp map of group and decoded meta data
|
2012-04-01 17:10:55 -04:00
|
|
|
* @return error code
|
2012-01-18 18:20:53 -05:00
|
|
|
*/
|
2012-08-28 17:11:54 -04:00
|
|
|
virtual int storeGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grsp) = 0;
|
2012-06-26 15:52:01 -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
|
|
|
|
*/
|
|
|
|
virtual int updateGroup(std::map<RsNxsGrp*, RsGxsGrpMetaData*>& grsp) = 0;
|
|
|
|
|
2012-06-26 15:52:01 -04:00
|
|
|
/*!
|
|
|
|
* @param metaData
|
|
|
|
*/
|
2012-08-19 18:15:37 -04:00
|
|
|
virtual int updateMessageMetaData(MsgLocMetaData& metaData) = 0;
|
2012-06-26 15:52:01 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @param metaData
|
|
|
|
*/
|
2012-08-19 18:15:37 -04:00
|
|
|
virtual int updateGroupMetaData(GrpLocMetaData& meta) = 0;
|
2012-01-18 18:20:53 -05:00
|
|
|
|
2014-10-05 15:14:05 -04:00
|
|
|
virtual int updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurityKeySet& keys,uint32_t subscribed_flags) = 0 ;
|
2012-06-03 14:09:38 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Completely clear out data stored in
|
|
|
|
* and returns this to a state
|
|
|
|
* as it was when first constructed
|
|
|
|
*/
|
|
|
|
virtual int resetDataStore() = 0;
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
/*!
|
|
|
|
* Use to determine if message isn't over the storage
|
|
|
|
* limit for a single message item
|
|
|
|
* @param msg the message to check size validity
|
|
|
|
* @return whether the size of of msg is valid
|
|
|
|
*/
|
|
|
|
virtual bool validSize(RsNxsMsg* msg) const = 0 ;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Use to determine if group isn't over the storage limit
|
|
|
|
* for a single group item
|
|
|
|
* @param grp the group to check size validity
|
|
|
|
* @return whether the size of grp is valid for storage
|
|
|
|
*/
|
|
|
|
virtual bool validSize(RsNxsGrp* grp) const = 0 ;
|
|
|
|
|
2012-04-01 17:10:55 -04:00
|
|
|
};
|
2012-01-11 18:01:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-17 18:45:48 -04:00
|
|
|
#endif // RSGDS_H
|