diff --git a/libretroshare/src/gxs/rsgdp.h b/libretroshare/src/gxs/rsgdp.h index d8276196e..de51eb5fc 100644 --- a/libretroshare/src/gxs/rsgdp.h +++ b/libretroshare/src/gxs/rsgdp.h @@ -26,82 +26,164 @@ * */ +#include +#include #include #include "inttypes.h" -#include "util/rssqlite.h" +#include "gxs/rsgxs.h" + +typedef std::map > MsgGrpId; +typedef std::map > SignedMsgGrp; /*! - * GDP: Represents the center of gxs. In as far as enabling synchronisation between peers + * The main role of GDP is the preparation of messages requested from + * GXS instance's storage module (RsGeneralStorageService) * - * Responsibilty: - * GDP has access to concrete RsGxs services internal messages by way of a passed - * RsGss (storage module in read only mode) - * It also receives messages from GNP which it stores in its external db which - * it passed as a handle to the concrete RsGxs service (read only for service) - * - * An important responsibility is the preparation of data for GNP as such - * permissions of messages are enforced here - * - *****/ - - -/*! - * The main role of GDP is to receive and start sync requests - * and prepare exchange data for RsGnp. - * It is also the curator (write authority) of externally received messages + * It acts as a layer between RsGeneralStorageService and its parent GXS instance + * thus allowing for non-blocking requests, etc. + * It also provides caching ability */ -class RsGdp +class RsGeneralDataService { public: - RsGdp(); + + /*! + * Retrieves signed message + * @param msgGrp this contains grp and the message to retrieve + * @return request code to be redeemed later + */ + virtual int request(const MsgGrpId& msgGrp, SignedMsgGrp& result, bool decrypted) = 0; + + + /*! + * allows for more complex queries specific to the service + * Service should implement method taking case + * @param filter generally stores parameters needed for query + * @param cacheRequest set to true to cache the messages requested + * @return request code to be redeemed later + */ + virtual int request(RequestFilter* filter, SignedMsgGrp& msgs, bool cacheRequest) = 0; + + + /*! + * stores signed message + * @param msgs signed messages to store + */ + virtual bool store(SignedMsgGrp& msgs) = 0; + + /*! + * @param grpIds set with grpIds available from storage + * @return request code to be redeemed later + */ + virtual int getGroups(std::set& grpIds) = 0; + + /*! + * + * @param msgIds gets message ids in storage + * @return request code to be redeemed later + */ + virtual int getMessageIds(std::set& msgIds) = 0; + + /*! + * caches message for faster retrieval later + * @return false if caching failed, msg may not exist, false otherwise + */ + virtual bool cacheMsg(const std::string& grpId, const std::string& msgId) = 0; + + /*! + * caches all messages of this grpId for faster retrieval later + * @param grpId all message of this grpId are cached + * @return false if caching failed, msg may not exist, false otherwise + */ + bool cacheGrp(const std::string& grpId) = 0; + + /*! + * checks if msg is cached + * @param msgId message to check if cached + * @param grpId + * @return false if caching failed, msg may not exist, false otherwise + */ + bool msgCached(const std::string& grpId, const std::string& msgId) = 0; + + /*! + * check if messages of the grpId are cached + * @param grpId all message of this grpId are checked + * @return false if caching failed, msg may not exist, false otherwise + */ + bool grpCached(const std::string& grpId) = 0; + }; -class RsGxsSignedMessage { +/*! + * Might be better off simply sending request codes + * + */ +class RequestFilter { + + /*! + * + */ + virtual int code() = 0; }; /*! - * General Storage service - * This presents an abstract interface used by both concrete Gxs services and the Gdp to store - * internally and externally generated messages respectively. - * This abstraction allows GDP to retrieve entries from an SQL lite db without knowledge of the - * service db schema (columns basically). - * Concrete services should implement this service + * + * This is implemented by the concrete GXS class to represent to define how \n + * RsGxsSignedMessage is stored and retrieved \n + * More complicated queries are enabled through the use of \n + * RequestFilter which through rtti store generic parameter used \n + * The main reason for layering RsGeneralDataService between this and service implementer \n + * is to avoid the overhead of storage access \n */ -class RsGss { +class RsGeneralStorageService { public: - RsGss(RsSqlite*, uint8_t io_stat); + /*! - * stores message in associate RsSqlite db - * if RsGss is in read only mode this function will always \n - * return false - * - * @param message the message to store - * @return true if message successfully stored + * Retrieves signed messages from storage + * @param msgGrp this contains grp and the message to retrieve */ - virtual bool store(const RsGxsSignedMessage* message) = 0; + virtual void retrieve(const MsgGrpId& msgGrp, SignedMsgGrp& result, bool decrypted) = 0; + /*! - * retrieve message from associate RsSqlite db \n - * @param msgId - * @param message - * @return true if successfully retrieved, false otherwise + * allows for more complex queries specific to the service + * Service should implement method taking case + * @param filter */ - virtual bool retrieve(const std::string msgId, RsGxsSignedMessage* message) = 0; + virtual void retrieve(RequestFilter* filter, SignedMsgGrp& msgs) = 0; + + /*! + * stores signed message in internal storage + * @param msgs signed messages to store + */ + virtual void store(SignedMsgGrp& msgs) = 0; + + /*! + * retrieves the group ids from storage + * @param grpIds set with grpIds available from storage + */ + virtual void getGroups(std::set& grpIds) = 0; + + /*! + * retrieve message in this stored in this storage + * @param msgIds gets message ids in storage + */ + virtual bool getMessageIds(std::set& msgIds) = 0; /*! * Use this find out if Rss i/o status * @return the io status */ - uint8_t getIoStat(); + virtual uint8_t getIoStat() = 0; + static uint8_t IOSTAT_READ_ONLY; + static uint8_t IOSTAT_READ_AND_WRITE; - static uint8_t READ_ONLY; - static uint8_t READ_AND_WRITE; }; #endif // RSGDP_H diff --git a/libretroshare/src/gxs/rsgixs.h b/libretroshare/src/gxs/rsgixs.h index 22faf16bf..d2788c8b3 100644 --- a/libretroshare/src/gxs/rsgixs.h +++ b/libretroshare/src/gxs/rsgixs.h @@ -6,7 +6,7 @@ * * General Exchange Protocol interface for RetroShare. * - * Copyright 2011-2011 by Robert Fernie. + * Copyright 2011-2011 by Robert Fernie, Christopher Evi-Prker * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,6 +30,7 @@ #include #include + /* * GIXP: General Identity Exchange Protocol. * @@ -48,7 +49,6 @@ * 6) This class will use the generalised packet storage for efficient caching & loading. * 7) Data will be stored encrypted. */ -namespace retroshare_gxs { class GixsKey { @@ -110,7 +110,7 @@ namespace retroshare_gxs { * also provides encyption, decryption, verification, * and signing functionality using any created identities */ - class RsGixs : RsGxs + class RsIdentityExchangeService { public: RsGixs(); @@ -119,28 +119,28 @@ namespace retroshare_gxs { * creates gixs profile and shares it * @param profile */ - bool createKey(RsGixsProfile& profile); /* fills in mKeyId, and signature */ + bool createKey(RsGixsProfile& profile) = 0; /* fills in mKeyId, and signature */ /*! * Use to query a whether given key is available by its key reference * @param keyref the keyref of key that is being checked for * @return true if available, false otherwise */ - bool haveKey(const KeyRef& keyref); + bool haveKey(const KeyRef& keyref) = 0; /*! * Use to query whether private key member of the given key reference is available * @param keyref the KeyRef of the key being checked for * @return true if private key is held here, false otherwise */ - bool havePrivateKey(const KeyRef& keyref); + bool havePrivateKey(const KeyRef& keyref) = 0; /*! * Use to request a given key reference * @param keyref the KeyRef of the key being requested * @return will */ - bool requestKey(const KeyRef& keyref); + bool requestKey(const KeyRef& keyref) = 0; /*! * Retrieves a key identity @@ -148,7 +148,7 @@ namespace retroshare_gxs { * @return a pointer to a valid profile if successful, otherwise NULL * */ - RsGixsProfile* getProfile(const KeyRef& keyref); + RsGixsProfile* getProfile(const KeyRef& keyref) = 0; /*** process data ***/ @@ -161,7 +161,7 @@ namespace retroshare_gxs { * @param signature is set with the signature from signing with keyref * @return false if signing failed, true otherwise */ - bool sign(const KeyRef& keyref, unsigned char* data, uint32_t dataLen, std::string& signature); + bool sign(const KeyRef& keyref, unsigned char* data, uint32_t dataLen, std::string& signature) = 0; /*! * Verify that the data is signed by the key owner @@ -171,7 +171,7 @@ namespace retroshare_gxs { * @param signature * @return false if verification failed, false otherwise */ - bool verify(const KeyRef& keyref, unsigned char* data, int dataLen, std::string& signature); + bool verify(const KeyRef& keyref, unsigned char* data, int dataLen, std::string& signature) = 0; /*! * Attempt to decrypt data with a given key @@ -183,7 +183,7 @@ namespace retroshare_gxs { * @return false */ bool decrypt(const KeyRef& keyref, unsigned char* data, int dataLen, - unsigned char*& decryptedData, uint32_t& decyptDataLen); + unsigned char*& decryptedData, uint32_t& decyptDataLen) = 0; /*! * Attempt to encrypt data with a given key @@ -194,10 +194,9 @@ namespace retroshare_gxs { * @param encryptDataLen length of encrypted data */ bool encrypt(const KeyRef& keyref, unsigned char* data, int dataLen, - unsigned char*& encryptedData, uint32_t& encryptDataLen); + unsigned char*& encryptedData, uint32_t& encryptDataLen) = 0; }; -} #endif // RSGIXS_H diff --git a/libretroshare/src/gxs/rsgnp.h b/libretroshare/src/gxs/rsgnp.h index 2b2c80408..c095c0d20 100644 --- a/libretroshare/src/gxs/rsgnp.h +++ b/libretroshare/src/gxs/rsgnp.h @@ -1,39 +1,115 @@ #ifndef RSGNP_H #define RSGNP_H -#include -#include -#include - -#include "services/p3service.h" -#include "gxs/rsgdp.h" - - -/*! - * Retroshare general network protocol +/* + * libretroshare/src/gxs: rsgnp.h * - * This simply deals with the receiving and sending - * RsGxs data + * General Exchange Protocol interface for RetroShare. + * + * Copyright 2011-2011 by Robert Fernie, Christopher Evi-Prker + * + * 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". * */ -class RsGnp : p3ThreadedService + +#include +#include +#include +#include +#include +#include + +#include "gxs/rsgxs.h" + +typedef std::map > PeerGrp; + +/*! + * Retroshare General Network Exchange Service: \n + * This provides a module to service peers requests for GXS message \n + * and also request GXS messages from other peers. \n + * Users can make a general request for message under a grp id for a peer, all grp ids held \n + * by a set of peers. And can also apply to timerange to them + * An interface is provided for the observer pattern is provided to alert clients this class + * when requests have been served + */ +class RsNetworktExchangeService { public: - RsGnp(); + + RsNetworkExchangeService(); + + /*! + * Queries peers for a set of grp ids + * @param pg a map of peer to a set of grp ids to query message from + * @param from start range of time + * @param to end range of time + * @return a request code to be kept to redeem query later + */ + virtual int requestAvailableMsgs(PeerGrp& pg, time_t from, time_t to) = 0; + + /*! + * Queries peer for msgs of peer grp id pairs + * @param pg peer, grp id peers + * @param from start range of time + * @param to end range of time + * @return a request code to be kept to redeem query later + */ + virtual int requestMsgs(PeerGrp& pg, time_t from, time_t to) = 0; + + /*! + * Queries peers in list for groups avaialble + * + * @param peers the peers to query + * @param from start range of time + * @param to end range of time + * @return a request code to be kept to redeem query later + */ + int requestAvailableGrps(const std::set& peers, time_t from, time_t to) = 0; - /*** gdp::iterface *****/ - int requestMsgs(std::set msgId, double &delay); - void addGdp(RsGdp* gdp) = 0; - void removeGdp(RsGdp* gdp) = 0; + /*! + * When messages are received this function should be call containing the messages + * @param msgs the messages received from peers + */ + void messageFromPeers(std::list& msgs) = 0; + public: - /*** IMPLEMENTATION DETAILS ****/ - /* Get/Send Messages */ - void getAvailableMsgs(std::string peerId, time_t from, time_t to); /* request over the network */ - void sendAvailableMsgs(std::string peerId, time_t from, time_t to); /* send to peers */ + + /*! + * attempt to retrieve requested messages + * @param requestCode + * @param msgs + * @return false if not received, true is requestCode has been redeemed + * @see RsGeneralNetExchangeService::requestAvailableGrps() + */ + bool getRequested(uint32_t requestCode, std::list& msgs) = 0; + + /*! + * Allows observer pattern for checking if a request has been satisfied + * + * @param requestCode the code returned msg request functions + * @return false if not ready, true otherwise + * @see RsGeneralNetExchangeService::requestAvailableGrps() + * @see RsGeneralNetExchangeService::requestAvailableMsgs() + */ + bool requestCodeReady(uint32_t reuqestCode); }; diff --git a/libretroshare/src/gxs/rsgxs.h b/libretroshare/src/gxs/rsgxs.h index 3b3ca5aff..d6e300d0b 100644 --- a/libretroshare/src/gxs/rsgxs.h +++ b/libretroshare/src/gxs/rsgxs.h @@ -5,6 +5,7 @@ * libretroshare/src/gxs : rsgxs.h * * GXS interface for RetroShare. + * Convenience header * * Copyright 2011 Christopher Evi-Parker * @@ -30,74 +31,23 @@ * */ -#include "rsgdp.h" -#include "util/rsthreads.h" +#include +#include /*! - * Retroshare general exchange service - * This forms the basic interface that classes need to inherit - * in order to use the general exchange service - * Generally GNP drives the service. - * GDP deals with exporting and importing msgs to and from the concrete service - * data from the derived class - * GXIP is used to maintain - * - * - * The maiin transport mechanism + * This is universal format for messages that is transported throughout + * the general exchange service chain. From concrete service to */ -class RsGxs : public RsThread -{ -public: - RsGxs(const std::string& serviceName); - -public: - - /*! - * These are messages, that have been pushed to you - * This will be called by RsGdp whenever a new msg(s) has arrived - * the list contains ids which may be queried from the external db - * - * @param msgIds the ids of the new msgs received - */ - virtual void receiveMessage(std::set& msgIds) = 0; - - /*! - * Push a set of messages which have been written to your service - * database - * @param msgIds - */ - void push(std::set& msgIds) = 0; - - - /*! - * allows for non blocking pushes, receives, and configuration changes. - */ - void run(); - - - /*! - * cache a message - * @param msg message to cache - * - */ - void cache(RsGxsSignedMessage* msg); - - /*! - * Queries if message with message id is cached - * @param msgId the id of the message to query - */ - bool cached(std::string& msgId); - - /*! - * Use to retrieve cached msgs - * If message id of messages not cached are requested, it is simply ignored - * @param requestIds The ids of messages to retrieve - * @param msgs the retrieved cached messages - */ - void retrieveCache(std::set& requestIds, std::set& msgs); - +class RsGxsSignedMessage { + uint32_t timestamp; + void* signature; + void* data; + uint32_t msg_flags; /* encrypted */ + std::string msgId; /* hash of all message data */ + std::string grpId; }; + #endif // RSGXS_H