added more interface declarations and comments clarifying

resposibility


git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@4803 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-01-15 13:07:31 +00:00
parent 3f0c811917
commit 2504c0fd9a
7 changed files with 450 additions and 32 deletions

View file

@ -1,13 +1,53 @@
#ifndef RSGDP_H
#define RSGDP_H
/*
* 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".
*
*/
#include <string>
#include "inttypes.h"
#include "util/rssqlite.h"
/*!
* GDP: Represents the center of gxs. In as far as enabling synchronisation between peers
*
* 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
@ -18,13 +58,17 @@ public:
RsGdp();
};
class RsGxsMessage {
class RsGxsSignedMessage {
};
/*!
*
*
* 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
*/
class RsGss {
@ -39,15 +83,20 @@ public:
* @param message the message to store
* @return true if message successfully stored
*/
virtual bool store(const RsGxsMessage& message) = 0;
virtual bool store(const RsGxsSignedMessage* message) = 0;
/*!
* retrieve message from associate RsSqlite db \n
*
* @param msgId
* @param message
* @return true if successfully retrieved, false otherwise
*/
virtual bool retrieve(const std::string msgId, RsGxsMessage&) = 0;
virtual bool retrieve(const std::string msgId, RsGxsSignedMessage* message) = 0;
/*!
* Use this find out if Rss i/o status
* @return the io status
*/
uint8_t getIoStat();

View file

@ -1,19 +1,203 @@
#ifndef RSGIXS_H
#define RSGIXS_H
/*
* libretroshare/src/gxs: gxs.h
*
* General Exchange Protocol interface for RetroShare.
*
* Copyright 2011-2011 by 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".
*
*/
#include "gxs/rsgxs.h"
/*!
* Retroshare general identity exchange service
* provides a means to distribute identities among peers
* also provides encyption, decryption, verification,
* and signing functionality using any created identities
#include <openssl/ssl.h>
#include <set>
/*
* GIXP: General Identity Exchange Protocol.
*
* As we're always running into troubles with GPG signatures... we are going to
* create a layer of RSA Keys for the following properties:
*
* 1) RSA Keys can be Anonymous, Self-Signed with Pseudonym, Signed by GPG Key.
* - Anonymous & Pseudonym Keys will be shared network-wide (Hop by Hop).
- GPG signed Keys will only be shared if we can validate the signature
(providing similar behaviour to existing GPG Keys).
- GPG signed Keys can optionally be marked for Network-wide sharing.
* 2) These keys can be used anywhere, specifically in the protocols described below.
* 3) These keys can be used to sign, encrypt, verify & decrypt
* 4) Keys will never need to be directly accessed - stored in this class.
* 5) They will be cached locally and exchanged p2p, by pull request.
* 6) This class will use the generalised packet storage for efficient caching & loading.
* 7) Data will be stored encrypted.
*/
class RsGixs : RsGxs
{
public:
RsGixs();
namespace retroshare_gxs {
};
class GixsKey
{
KeyRef mKeyId;
/// public key
EVP_PKEY *mPubKey;
/// NULL if non-existant */
EVP_PKEY *mPrivKey;
};
class KeyRef {
};
class KeyRefSet {
std::set<KeyRef> mKeyRefSet;
};
class SignatureSet {
std::set<Signature> mSignatureSet;
};
class Signature {
KeyRef mKeyRef;
Signature mSignature;
};
class RsGixsProfile {
public:
KeyRef mKeyRef;
std::string mPseudonym;
/// may be superseded by newer timestamps
time_t mTimeStamp;
uint32_t mProfileType;
// TODO: add permissions members
Signature mSignature;
};
/*!
* Retroshare general identity exchange service
* provides a means to distribute identities among peers
* also provides encyption, decryption, verification,
* and signing functionality using any created identities
*/
class RsGixs : RsGxs
{
public:
RsGixs();
/*!
* creates gixs profile and shares it
* @param profile
*/
bool createKey(RsGixsProfile& profile); /* 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);
/*!
* 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);
/*!
* Use to request a given key reference
* @param keyref the KeyRef of the key being requested
* @return will
*/
bool requestKey(const KeyRef& keyref);
/*!
* Retrieves a key identity
* @param keyref
* @return a pointer to a valid profile if successful, otherwise NULL
*
*/
RsGixsProfile* getProfile(const KeyRef& keyref);
/*** process data ***/
/*!
* Use to sign data with a given key
* @param keyref the key to sign the data with
* @param data the data to be signed
* @param dataLen the length of the data
* @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);
/*!
* Verify that the data is signed by the key owner
* @param keyref
* @param data
* @param dataLen
* @param signature
* @return false if verification failed, false otherwise
*/
bool verify(const KeyRef& keyref, unsigned char* data, int dataLen, std::string& signature);
/*!
* Attempt to decrypt data with a given key
* @param keyref
* @param data data to be decrypted
* @param dataLen length of data
* @param decryptedData decrypted data
* @param decryptDataLen length of decrypted data
* @return false
*/
bool decrypt(const KeyRef& keyref, unsigned char* data, int dataLen,
unsigned char*& decryptedData, uint32_t& decyptDataLen);
/*!
* Attempt to encrypt data with a given key
* @param keyref
* @param data data to be encrypted
* @param dataLen length of data
* @param encryptedData encrypted data
* @param encryptDataLen length of encrypted data
*/
bool encrypt(const KeyRef& keyref, unsigned char* data, int dataLen,
unsigned char*& encryptedData, uint32_t& encryptDataLen);
};
}
#endif // RSGIXS_H

View file

@ -1,20 +1,42 @@
#ifndef RSGNP_H
#define RSGNP_H
#include "pqi/pqiservice.h"
#include <set>
#include "services/p3service.h"
#include "gxs/rsgdp.h"
/*!
* Retroshare general network protocol
*
* This deals with the receiving and sending
* This simply deals with the receiving and sending
* RsGxs data
*
*/
class RsGnp
class RsGnp : p3ThreadedService
{
public:
RsGnp();
/*** gdp::iterface *****/
int requestMsgs(std::set<std::string> msgId, double &delay);
void addGdp(RsGdp* gdp);
void removeGdp(RsGdp* gdp);
private:
/*** 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, gdp::id grpId, time_t from, time_t to); /* send to peers */
requestMessages(std::string peerId, gdp::id grpId, std::list<gdp::id> msgIds);
sendMessages(std::string peerId, gdp::id grpId, std::list<gdp::id> msgIds); /* send to peer, obviously permissions have been checked first */
/* Search the network */
};
#endif // RSGNP_H

View file

@ -36,8 +36,8 @@
* Retroshare general exchange service
* This forms the basic interface that classes need to inherit
* in order to use the general exchange service
* General GNP drives the service.
* GDP deals with exporting and importing
* 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
*/
@ -48,13 +48,36 @@ public:
public:
virtual void receiveMessage(RsGxsMessage*) = 0;
void sendMessage(RsGxsMessage*) = 0;
/*!
* 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
*/
virtual void receiveMessage(std::set<std::string> msgIds) = 0;
/*!
* Push a set of messages which have been written to your service
* database
*/
void push(std::set<std::string>& msgIds) = 0;
/*!
* drives synchronisation between peers
*/
void tick();
void cache(RsGxsSignedMessage*);
bool cached(std::string& msgId);
/*!
* Use to retrieve cached msgs
*
* @param msgs the cached msgs
*/
void retrieveCache(std::set<std::string>& requestIds, std::set<RsGxsSignedMessage*>& msgs);
};
#endif // RSGXS_H