2012-05-21 18:07:43 -04:00
|
|
|
#ifndef RSGENEXCHANGE_H
|
|
|
|
#define RSGENEXCHANGE_H
|
|
|
|
|
2012-07-22 17:38:15 -04:00
|
|
|
/*
|
2012-08-06 17:00:38 -04:00
|
|
|
* libretroshare/src/gxs: rsgenexchange.h
|
2012-07-22 17:38:15 -04:00
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Christopher Evi-Parker, Robert Fernie
|
|
|
|
*
|
|
|
|
* 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-06-07 16:43:12 -04:00
|
|
|
#include <queue>
|
2012-08-25 11:48:55 -04:00
|
|
|
#include <ctime>
|
2012-05-21 18:07:43 -04:00
|
|
|
|
|
|
|
#include "rsgxs.h"
|
2012-07-05 17:26:14 -04:00
|
|
|
#include "rsgds.h"
|
|
|
|
#include "rsnxs.h"
|
|
|
|
#include "rsgxsdataaccess.h"
|
2012-08-03 02:39:50 -04:00
|
|
|
#include "rsnxsobserver.h"
|
2012-07-05 17:26:14 -04:00
|
|
|
#include "retroshare/rsgxsservice.h"
|
2012-06-07 16:43:12 -04:00
|
|
|
#include "serialiser/rsnxsitems.h"
|
|
|
|
|
2012-07-22 17:38:15 -04:00
|
|
|
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
|
|
|
|
typedef std::map<RsGxsGroupId, RsGxsGrpItem*> GxsGroupDataMap;
|
|
|
|
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
|
2012-06-07 16:43:12 -04:00
|
|
|
|
2012-08-25 11:48:55 -04:00
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
/*!
|
|
|
|
* This should form the parent class to \n
|
|
|
|
* all gxs services. This provides access to service's msg/grp data \n
|
|
|
|
* management/publishing/sync features
|
|
|
|
*
|
|
|
|
* Features: \n
|
2012-10-23 17:52:51 -04:00
|
|
|
* a. Data Access: \n
|
|
|
|
* Provided by handle to RsTokenService. This ensure consistency \n
|
|
|
|
* of requests and hiearchy of groups -> then messages which are \n
|
|
|
|
* sectioned by group ids. \n
|
|
|
|
* The one caveat is that redemption of tokens are done through \n
|
|
|
|
* the backend of this class \n
|
|
|
|
* b. Publishing: \n
|
|
|
|
* Methods are provided to publish msg and group items and also make \n
|
|
|
|
* changes to meta information of both item types \n
|
|
|
|
* c. Sync/Notification: \n
|
|
|
|
* Also notifications are made here on receipt of new data from \n
|
2012-07-05 17:26:14 -04:00
|
|
|
* connected peers
|
|
|
|
*/
|
2012-10-28 14:40:01 -04:00
|
|
|
|
|
|
|
class RsGixs;
|
|
|
|
|
2012-08-03 02:39:50 -04:00
|
|
|
class RsGenExchange : public RsGxsService, public RsNxsObserver
|
2012-05-21 18:07:43 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
/*!
|
2012-10-23 17:52:51 -04:00
|
|
|
* Constructs a RsGenExchange object, the owner ship of gds, ns, and serviceserialiser passes \n
|
2012-07-05 17:26:14 -04:00
|
|
|
* onto the constructed object
|
|
|
|
* @param gds Data service needed to act as store of message
|
|
|
|
* @param ns Network service needed to synchronise data with rs peers
|
|
|
|
* @param serviceSerialiser The users service needs this \n
|
|
|
|
* in order for gen exchange to deal with its data types
|
2012-10-23 17:52:51 -04:00
|
|
|
* @param mServType This should be service type used by the serialiser
|
|
|
|
* @param This is used for verification of msgs and groups received by Gen Exchange using identities, set to NULL if \n
|
|
|
|
* identity verification is not wanted
|
2012-07-05 17:26:14 -04:00
|
|
|
*/
|
2012-10-23 17:52:51 -04:00
|
|
|
RsGenExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser, uint16_t mServType, RsGixs* gixs = NULL);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
virtual ~RsGenExchange();
|
|
|
|
|
2012-07-17 17:27:43 -04:00
|
|
|
/** S: Observer implementation **/
|
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
/*!
|
|
|
|
* @param messages messages are deleted after function returns
|
|
|
|
*/
|
2012-08-06 17:00:38 -04:00
|
|
|
void notifyNewMessages(std::vector<RsNxsMsg*>& messages);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @param messages messages are deleted after function returns
|
|
|
|
*/
|
|
|
|
void notifyNewGroups(std::vector<RsNxsGrp*>& groups);
|
|
|
|
|
2012-07-17 17:27:43 -04:00
|
|
|
/** E: Observer implementation **/
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* This is called by Gxs service runner
|
|
|
|
* periodically, use to implement non
|
|
|
|
* blocking calls
|
|
|
|
*/
|
|
|
|
void tick();
|
|
|
|
|
2012-10-15 14:52:47 -04:00
|
|
|
/*!
|
|
|
|
* Any backgroup processing needed by
|
|
|
|
*/
|
|
|
|
virtual void service_tick() = 0;
|
|
|
|
|
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* @return handle to token service handle for making
|
|
|
|
* request to this gxs service
|
|
|
|
*/
|
2012-10-05 14:12:52 -04:00
|
|
|
RsTokenService* getTokenService();
|
2012-07-05 17:26:14 -04:00
|
|
|
|
2012-10-15 16:31:56 -04:00
|
|
|
public:
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
/** data access functions **/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Retrieve group list for a given token
|
|
|
|
* @param token
|
|
|
|
* @param groupIds
|
|
|
|
* @return false if token cannot be redeemed, if false you may have tried to redeem when not ready
|
|
|
|
*/
|
2012-07-22 17:38:15 -04:00
|
|
|
bool getGroupList(const uint32_t &token, std::list<RsGxsGroupId> &groupIds);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Retrieve msg list for a given token sectioned by group Ids
|
|
|
|
* @param token token to be redeemed
|
|
|
|
* @param msgIds a map of grpId -> msgList (vector)
|
|
|
|
*/
|
2012-07-22 17:38:15 -04:00
|
|
|
bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* retrieve group meta data associated to a request token
|
|
|
|
* @param token
|
|
|
|
* @param groupInfo
|
|
|
|
*/
|
|
|
|
bool getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* retrieves message meta data associated to a request token
|
|
|
|
* @param token token to be redeemed
|
|
|
|
* @param msgInfo the meta data to be retrieved for token store here
|
|
|
|
*/
|
2012-07-22 17:38:15 -04:00
|
|
|
bool getMsgMeta(const uint32_t &token, GxsMsgMetaMap &msgInfo);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
2012-10-15 16:31:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @param grpItem
|
2012-11-02 19:35:10 -04:00
|
|
|
* @deprecated only here temporarily for testing
|
2012-10-15 16:31:56 -04:00
|
|
|
*/
|
|
|
|
void createDummyGroup(RsGxsGrpItem* grpItem);
|
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
/*!
|
|
|
|
* retrieves group data associated to a request token
|
|
|
|
* @param token token to be redeemed for grpitem retrieval
|
|
|
|
* @param grpItem the items to be retrieved for token are stored here
|
|
|
|
*/
|
2012-08-12 16:46:21 -04:00
|
|
|
bool getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem*>& grpItem);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* retrieves message data associated to a request token
|
|
|
|
* @param token token to be redeemed for message item retrieval
|
|
|
|
* @param msgItems
|
|
|
|
*/
|
2012-07-22 17:38:15 -04:00
|
|
|
bool getMsgData(const uint32_t &token, GxsMsgDataMap& msgItems);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
2012-10-15 14:52:47 -04:00
|
|
|
/*!
|
|
|
|
* Assigns a token value to passed integer
|
|
|
|
* The status of the token can still be queried from request status feature
|
|
|
|
* @warning the token space is shared with RsGenExchange backend, so do not
|
|
|
|
* modify tokens except does you have created by calling generatePublicToken()
|
|
|
|
* @return token
|
|
|
|
*/
|
|
|
|
uint32_t generatePublicToken();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Updates the status of associate token
|
|
|
|
* @warning the token space is shared with RsGenExchange backend, so do not
|
|
|
|
* modify tokens except does you have created by calling generatePublicToken()
|
|
|
|
* @param token
|
|
|
|
* @param status
|
|
|
|
* @return false if token could not be found, true if token disposed of
|
|
|
|
*/
|
|
|
|
bool updatePublicRequestStatus(const uint32_t &token, const uint32_t &status);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* This gets rid of a publicly issued token
|
|
|
|
* @param token
|
|
|
|
* @return false if token could not found, true if token is disposed of
|
|
|
|
*/
|
|
|
|
bool disposeOfPublicToken(const uint32_t &token);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* This gives access to the data store which hold msgs and groups
|
|
|
|
* for the service
|
|
|
|
* @return Data store for retrieving msgs and groups
|
|
|
|
*/
|
|
|
|
RsGeneralDataService* getDataStore();
|
|
|
|
|
2012-10-23 17:52:51 -04:00
|
|
|
/*!
|
|
|
|
* Retrieve keys for a given group, \n
|
|
|
|
* call is blocking retrieval for underlying db
|
|
|
|
* @warning under normal circumstance a service should not need this
|
|
|
|
* @param grpId the id of the group to retrieve keys for
|
|
|
|
* @param keys this is set to the retrieved keys
|
|
|
|
* @return false if group does not exist or grpId is empty
|
|
|
|
*/
|
|
|
|
bool getGroupKeys(const RsGxsGroupId& grpId, RsTlvSecurityKeySet& keySet);
|
|
|
|
|
2012-08-18 06:01:35 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
/*!
|
2012-08-25 11:48:55 -04:00
|
|
|
* This allows the client service to acknowledge that their msgs has \n
|
2012-08-18 06:01:35 -04:00
|
|
|
* been created/modified and retrieve the create/modified msg ids
|
|
|
|
* @param token the token related to modification/create request
|
|
|
|
* @param msgIds map of grpid->msgIds of message created/modified
|
|
|
|
* @return true if token exists false otherwise
|
|
|
|
*/
|
2012-08-21 17:32:07 -04:00
|
|
|
bool acknowledgeTokenMsg(const uint32_t& token, RsGxsGrpMsgIdPair& msgId);
|
2012-08-18 06:01:35 -04:00
|
|
|
|
|
|
|
/*!
|
2012-11-02 19:35:10 -04:00
|
|
|
* This allows the client service to acknowledge that their grps has \n
|
2012-08-18 06:01:35 -04:00
|
|
|
* been created/modified and retrieve the create/modified grp ids
|
|
|
|
* @param token the token related to modification/create request
|
|
|
|
* @param msgIds vector of ids of groups created/modified
|
|
|
|
* @return true if token exists false otherwise
|
|
|
|
*/
|
|
|
|
bool acknowledgeTokenGrp(const uint32_t& token, RsGxsGroupId& grpId);
|
|
|
|
|
2012-07-22 17:38:15 -04:00
|
|
|
protected:
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
/** Modifications **/
|
|
|
|
|
|
|
|
/*!
|
2012-08-25 11:48:55 -04:00
|
|
|
* Enables publication of a group item \n
|
|
|
|
* If the item exists already this is simply versioned \n
|
|
|
|
* This will induce a related change message \n
|
|
|
|
* Ownership of item passes to this rsgenexchange \n
|
2012-08-18 06:01:35 -04:00
|
|
|
* @param token
|
2012-07-05 17:26:14 -04:00
|
|
|
* @param grpItem
|
|
|
|
*/
|
2012-08-21 17:32:07 -04:00
|
|
|
void publishGroup(uint32_t& token, RsGxsGrpItem* grpItem);
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
/*!
|
2012-08-25 11:48:55 -04:00
|
|
|
* Enables publication of a message item \n
|
|
|
|
* Setting mOrigMsgId meta member to blank \n
|
|
|
|
* leads to this msg being an original msg \n
|
|
|
|
* if mOrigMsgId is not blank the msgId then this msg is \n
|
|
|
|
* considered a versioned msg \n
|
2012-07-26 17:48:54 -04:00
|
|
|
* Ownership of item passes to this rsgenexchange
|
2012-08-18 06:01:35 -04:00
|
|
|
* @param token
|
2012-07-05 17:26:14 -04:00
|
|
|
* @param msgItem
|
|
|
|
*/
|
2012-08-21 17:32:07 -04:00
|
|
|
void publishMsg(uint32_t& token, RsGxsMsgItem* msgItem);
|
|
|
|
|
2012-10-15 16:31:56 -04:00
|
|
|
public:
|
|
|
|
|
2012-08-21 17:32:07 -04:00
|
|
|
/*!
|
|
|
|
* sets the group subscribe flag
|
|
|
|
* @param token this is set to token value associated to this request
|
2012-11-02 19:35:10 -04:00
|
|
|
* @param grpId Id of group whose subscribe file will be changed
|
|
|
|
* @param status
|
|
|
|
* @param mask
|
2012-08-21 17:32:07 -04:00
|
|
|
*/
|
2012-10-21 11:48:18 -04:00
|
|
|
void setGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask);
|
2012-08-21 17:32:07 -04:00
|
|
|
|
2012-11-02 19:35:10 -04:00
|
|
|
/*!
|
|
|
|
* sets the group subscribe flag
|
|
|
|
* @param token this is set to token value associated to this request
|
|
|
|
* @param grpId Id of group whose subscribe file will be changed
|
|
|
|
* @param status
|
|
|
|
* @param mask
|
|
|
|
*/
|
2012-10-21 11:48:18 -04:00
|
|
|
void setGroupStatusFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask);
|
2012-08-21 17:32:07 -04:00
|
|
|
|
2012-11-02 19:35:10 -04:00
|
|
|
/*!
|
|
|
|
* sets the group service string
|
|
|
|
* @param token this is set to token value associated to this request
|
|
|
|
* @param grpId Id of group whose subscribe file will be changed
|
|
|
|
* @param servString
|
|
|
|
*/
|
2012-08-21 17:32:07 -04:00
|
|
|
void setGroupServiceString(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString);
|
|
|
|
|
2012-11-02 19:35:10 -04:00
|
|
|
/*!
|
|
|
|
* sets the msg status flag
|
|
|
|
* @param token this is set to token value associated to this request
|
|
|
|
* @param grpId Id of group whose subscribe file will be changed
|
|
|
|
* @param status
|
|
|
|
* @param mask Mask to apply to status flag
|
|
|
|
*/
|
2012-10-21 11:48:18 -04:00
|
|
|
void setMsgStatusFlags(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const uint32_t& status, const uint32_t& mask);
|
2012-08-21 17:32:07 -04:00
|
|
|
|
2012-11-02 19:35:10 -04:00
|
|
|
/*!
|
|
|
|
* sets the message service string
|
|
|
|
* @param token this is set to token value associated to this request
|
|
|
|
* @param msgId Id of message whose service string will be changed
|
|
|
|
* @param servString The service string to set msg to
|
|
|
|
*/
|
2012-08-21 17:32:07 -04:00
|
|
|
void setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString );
|
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/** Notifications **/
|
|
|
|
|
|
|
|
/*!
|
2012-07-22 17:38:15 -04:00
|
|
|
* This confirms this class as an abstract one that \n
|
2012-07-05 17:26:14 -04:00
|
|
|
* should not be instantiated \n
|
|
|
|
* The deriving class should implement this function \n
|
2012-07-22 17:38:15 -04:00
|
|
|
* as it is called by the backend GXS system to \n
|
2012-07-05 17:26:14 -04:00
|
|
|
* update client of changes which should \n
|
2012-07-22 17:38:15 -04:00
|
|
|
* instigate client to retrieve new content from the system
|
2012-07-05 17:26:14 -04:00
|
|
|
* @param changes the changes that have occured to data held by this service
|
|
|
|
*/
|
2012-07-26 17:48:54 -04:00
|
|
|
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
2012-07-18 17:35:41 -04:00
|
|
|
|
2012-08-06 17:00:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2012-07-22 17:38:15 -04:00
|
|
|
|
2012-07-18 17:35:41 -04:00
|
|
|
void processRecvdData();
|
|
|
|
|
|
|
|
void processRecvdMessages();
|
|
|
|
|
|
|
|
void processRecvdGroups();
|
|
|
|
|
2012-08-12 16:46:21 -04:00
|
|
|
void publishGrps();
|
|
|
|
|
|
|
|
void publishMsgs();
|
|
|
|
|
2012-08-21 17:32:07 -04:00
|
|
|
/*!
|
|
|
|
* processes msg local meta changes
|
|
|
|
*/
|
|
|
|
void processMsgMetaChanges();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Processes group local meta changes
|
|
|
|
*/
|
|
|
|
void processGrpMetaChanges();
|
|
|
|
|
2012-11-02 19:35:10 -04:00
|
|
|
/*!
|
|
|
|
* This completes the creation of an instance on RsNxsGrp
|
|
|
|
* by assigning it a groupId and signature via SHA1 and EVP_sign respectively
|
|
|
|
* @param grp Nxs group to create
|
|
|
|
*/
|
|
|
|
bool createGroup(RsNxsGrp* grp);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* This completes the creation of an instance on RsNxsMsg
|
|
|
|
* by assigning it a groupId and signature via SHA1 and EVP_sign respectively
|
|
|
|
* What signatures are calculated are based on the authentication policy
|
|
|
|
* of the service
|
|
|
|
* @param msg the Nxs message to create
|
|
|
|
*/
|
2012-08-18 06:01:35 -04:00
|
|
|
bool createMessage(RsNxsMsg* msg);
|
2012-08-12 16:46:21 -04:00
|
|
|
|
2012-09-17 18:08:23 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* check meta change is legal
|
|
|
|
* @return false if meta change is not legal
|
|
|
|
*/
|
|
|
|
bool locked_validateGrpMetaChange(GrpLocMetaData&);
|
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
private:
|
|
|
|
|
2012-07-26 17:48:54 -04:00
|
|
|
RsMutex mGenMtx;
|
2012-07-05 17:26:14 -04:00
|
|
|
RsGxsDataAccess* mDataAccess;
|
|
|
|
RsGeneralDataService* mDataStore;
|
|
|
|
RsNetworkExchangeService *mNetService;
|
|
|
|
RsSerialType *mSerialiser;
|
2012-10-23 17:52:51 -04:00
|
|
|
RsGixs* mGixs;
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
std::vector<RsNxsMsg*> mReceivedMsgs;
|
|
|
|
std::vector<RsNxsGrp*> mReceivedGrps;
|
|
|
|
|
2012-08-18 06:01:35 -04:00
|
|
|
std::map<uint32_t, RsGxsGrpItem*> mGrpsToPublish;
|
|
|
|
std::map<uint32_t, RsGxsMsgItem*> mMsgsToPublish;
|
|
|
|
|
2012-08-21 17:32:07 -04:00
|
|
|
std::map<uint32_t, RsGxsGrpMsgIdPair > mMsgNotify;
|
|
|
|
std::map<uint32_t, RsGxsGroupId> mGrpNotify;
|
|
|
|
|
|
|
|
// for loc meta changes
|
|
|
|
std::map<uint32_t, GrpLocMetaData > mGrpLocMetaMap;
|
|
|
|
std::map<uint32_t, MsgLocMetaData> mMsgLocMetaMap;
|
2012-07-26 17:48:54 -04:00
|
|
|
|
|
|
|
std::vector<RsGxsNotify*> mNotifications;
|
|
|
|
|
|
|
|
/// service type
|
|
|
|
uint16_t mServType;
|
|
|
|
|
2012-07-05 17:26:14 -04:00
|
|
|
|
|
|
|
private:
|
2012-05-21 18:07:43 -04:00
|
|
|
|
2012-07-28 16:01:30 -04:00
|
|
|
std::vector<RsGxsNotify*> mChanges;
|
2012-05-21 18:07:43 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RSGENEXCHANGE_H
|