mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
* Added the basics of GxsCircles service to libretroshare.
- Defined the control group stuff. - Background task to determine friend membership. - Caching of Circle info, - Added GXS interface class to gxs/rsgixs.h - TODO: Serialiser is incomplete. - TODO: SubCircles to be done in Phase 2. * Improvements to RsMemCache: - Added Value& ref(Key) to avoid data copying. - Added Statistics to check cache performance. - Fixed up bugs in tracking membership. * Improvements to RsTickEvent: - Added additional string parameter for more specificity. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5910 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
baa949eaac
commit
5a55c1b5d6
@ -58,6 +58,8 @@ bool queueRequest(uint32_t token, uint32_t req_type);
|
||||
|
||||
void checkRequests(); // must be called by
|
||||
|
||||
protected:
|
||||
|
||||
// This must be overloaded to complete the functionality.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "gxs/rsgxs.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
/*!
|
||||
@ -94,9 +96,9 @@
|
||||
* as these will be used very frequently.
|
||||
*****/
|
||||
|
||||
//typedef std::string GxsId;
|
||||
|
||||
typedef std::string PeerId;
|
||||
typedef std::string PeerId; // SHOULD BE REMOVED => RsPeerId (SSLID)
|
||||
typedef std::string RsPgpId;
|
||||
typedef std::string RsGxsId;
|
||||
|
||||
//
|
||||
//// External Interface -
|
||||
@ -119,7 +121,6 @@ typedef std::string PeerId;
|
||||
|
||||
/* Identity Interface for GXS Message Verification.
|
||||
*/
|
||||
typedef std::string RsGxsId;
|
||||
class RsGixs
|
||||
{
|
||||
public:
|
||||
@ -194,180 +195,31 @@ virtual ~RsGxsIdExchange() { return; }
|
||||
|
||||
|
||||
|
||||
/* For Circles Too */
|
||||
|
||||
// BELOW IS OLD - WILL DELETE SHORTLY
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
/*!
|
||||
* Storage class for private and public publish keys
|
||||
*
|
||||
*/
|
||||
class GixsKey
|
||||
{
|
||||
KeyRef mKeyId;
|
||||
|
||||
/// public key
|
||||
EVP_PKEY *mPubKey;
|
||||
|
||||
/// NULL if non-existant */
|
||||
EVP_PKEY *mPrivKey;
|
||||
};
|
||||
|
||||
/*!
|
||||
*
|
||||
*
|
||||
*/
|
||||
class KeyRef {
|
||||
|
||||
std::string refId;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class KeyRefSet {
|
||||
std::set<KeyRef> mKeyRefSet;
|
||||
};
|
||||
|
||||
class SignatureSet {
|
||||
std::set<RsGxsSignature> mSignatureSet;
|
||||
};
|
||||
|
||||
/*!
|
||||
*
|
||||
*
|
||||
*/
|
||||
class RsGxsSignature {
|
||||
|
||||
KeyRef mKeyRef;
|
||||
};
|
||||
|
||||
/*!
|
||||
* This is the actual identity \n
|
||||
* In a sense the group description with the GixsKey the "message"
|
||||
*/
|
||||
class RsGixsProfile {
|
||||
|
||||
public:
|
||||
|
||||
KeyRef mKeyRef;
|
||||
std::string name;
|
||||
|
||||
/// may be superseded by newer timestamps
|
||||
time_t mTimeStamp;
|
||||
uint32_t mProfileType;
|
||||
|
||||
// TODO: add permissions members
|
||||
|
||||
RsGxsSignature mSignature;
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
* Retroshare general identity exchange service
|
||||
*
|
||||
* Purpose: \n
|
||||
* Provides a means to distribute identities among peers \n
|
||||
* Also provides encyption, decryption, verification, \n
|
||||
* and signing functionality using any created or received identities \n
|
||||
*
|
||||
* This may best be implemented as a singleton like current AuthGPG? \n
|
||||
*
|
||||
*/
|
||||
class RsIdentityExchangeService : RsGxsService
|
||||
class RsGcxs
|
||||
{
|
||||
public:
|
||||
|
||||
enum IdentityType { Pseudonym, Signed, Anonymous };
|
||||
|
||||
RsGixs();
|
||||
|
||||
/*!
|
||||
* creates gixs profile and shares it
|
||||
* @param profile
|
||||
* @param type the type of profile to create, self signed, anonymous, and GPG signed
|
||||
*/
|
||||
virtual bool createKey(RsGixsProfile& profile, uint32_t type) = 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
|
||||
*/
|
||||
virtual 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
|
||||
*/
|
||||
virtual bool havePrivateKey(const KeyRef& keyref) = 0;
|
||||
|
||||
/*!
|
||||
* Use to request a given key reference
|
||||
* @param keyref the KeyRef of the key being requested
|
||||
* @return will
|
||||
*/
|
||||
virtual bool requestKey(const KeyRef& keyref) = 0;
|
||||
|
||||
/*!
|
||||
* Retrieves a key identity
|
||||
* @param keyref
|
||||
* @return a pointer to a valid profile if successful, otherwise NULL
|
||||
*
|
||||
*/
|
||||
virtual RsGixsProfile* getProfile(const KeyRef& keyref) = 0;
|
||||
|
||||
|
||||
/*** 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
|
||||
*/
|
||||
virtual 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
|
||||
* @param keyref
|
||||
* @param data
|
||||
* @param dataLen
|
||||
* @param signature
|
||||
* @return false if verification failed, false otherwise
|
||||
*/
|
||||
virtual bool verify(const KeyRef& keyref, unsigned char* data, int dataLen, std::string& signature) = 0;
|
||||
|
||||
/*!
|
||||
* 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
|
||||
*/
|
||||
virtual bool decrypt(const KeyRef& keyref, unsigned char* data, int dataLen,
|
||||
unsigned char*& decryptedData, uint32_t& decyptDataLen) = 0;
|
||||
|
||||
/*!
|
||||
* 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
|
||||
*/
|
||||
virtual bool encrypt(const KeyRef& keyref, unsigned char* data, int dataLen,
|
||||
unsigned char*& encryptedData, uint32_t& encryptDataLen) = 0;
|
||||
/* GXS Interface - for working out who can receive */
|
||||
virtual bool isLoaded(const RsGxsCircleId &circleId) = 0;
|
||||
virtual bool loadCircle(const RsGxsCircleId &circleId) = 0;
|
||||
|
||||
virtual int canSend(const RsGxsCircleId &circleId, const RsPgpId &id) = 0;
|
||||
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist) = 0;
|
||||
};
|
||||
|
||||
#endif // END OF #if 0
|
||||
|
||||
|
||||
class RsGxsCircleExchange: public RsGenExchange, public RsGcxs
|
||||
{
|
||||
public:
|
||||
RsGxsCircleExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser,
|
||||
uint16_t mServType, RsGixs* gixs, uint32_t authenPolicy)
|
||||
:RsGenExchange(gds,ns,serviceSerialiser,mServType, gixs, authenPolicy) { return; }
|
||||
virtual ~RsGxsCircleExchange() { return; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // RSGIXS_H
|
||||
|
@ -640,6 +640,16 @@ HEADERS += retroshare/rsgame.h
|
||||
SOURCES += services/p3idservice.cc \
|
||||
serialiser/rsgxsiditems.cc \
|
||||
|
||||
# GxsCircles Service
|
||||
HEADERS += services/p3gxscircles.h \
|
||||
|
||||
# serialiser/rsgxscircleitems.h
|
||||
# retroshare/rsgxscircles.h \
|
||||
|
||||
SOURCES += services/p3gxscircles.cc \
|
||||
|
||||
# serialiser/rsgxscircleitems.cc \
|
||||
|
||||
# GxsForums Service
|
||||
HEADERS += retroshare/rsgxsforums.h \
|
||||
services/p3gxsforums.h \
|
||||
|
105
libretroshare/src/retroshare/rsgxscircles.h
Normal file
105
libretroshare/src/retroshare/rsgxscircles.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef RETROSHARE_GXSCIRCLES_INTERFACE_H
|
||||
#define RETROSHARE_GXSCIRCLES_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsgxscircles.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 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.1 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 <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include "gxs/rstokenservice.h"
|
||||
#include "gxs/rsgxsifaceimpl.h"
|
||||
|
||||
#include "retroshare/rsidentity.h"
|
||||
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsGxsCircles;
|
||||
extern RsGxsCircles *rsGxsCircles;
|
||||
|
||||
|
||||
typedef std::string RsGxsCircleId;
|
||||
typedef std::string RsPeerId; // SSL ID.
|
||||
typedef std::string RsPgpId;
|
||||
typedef std::string RsCircleInternalId;
|
||||
|
||||
#define GXS_PERM_TYPE_PUBLIC 0x0001
|
||||
#define GXS_PERM_TYPE_EXTERNAL 0x0002
|
||||
#define GXS_PERM_TYPE_YOUREYESONLY 0x0003
|
||||
|
||||
/* Permissions is part of GroupMetaData
|
||||
*/
|
||||
|
||||
class GxsPermissions
|
||||
{
|
||||
public:
|
||||
uint32_t mCircleType; // PUBLIC, EXTERNAL or YOUREYESONLY.
|
||||
RsGxsCircleId mCircleId; // If EXTERNAL, otherwise Blank.
|
||||
|
||||
// BELOW IS NOT SERIALISED - BUT MUST BE STORED LOCALLY BY GXS. (If YOUREYESONLY)
|
||||
RsPeerId mOriginator;
|
||||
RsCircleInternalId mInternalCircle; // if Originator == ownId, otherwise blank.
|
||||
};
|
||||
|
||||
|
||||
class RsGxsCircleGroup
|
||||
{
|
||||
public:
|
||||
RsGroupMetaData mMeta; // includes GxsPermissions, for control of group distribution.
|
||||
|
||||
std::list<RsGxsId> mInvitedMembers;
|
||||
std::list<RsGxsCircleId> mSubCircles;
|
||||
|
||||
// Not Serialised.
|
||||
// Internally inside rsCircles, this will be turned into:
|
||||
// std::list<RsPeerId> mAllowedFriends;
|
||||
};
|
||||
|
||||
class RsGxsCircleMsg
|
||||
{
|
||||
public:
|
||||
RsMsgMetaData mMeta;
|
||||
|
||||
// Signature by user signifying that they want to be part of the group.
|
||||
// maybe Phase 3.
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class RsGxsCircles: public RsGxsIfaceImpl
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircles(RsGenExchange *gxs)
|
||||
:RsGxsIfaceImpl(gxs) { return; }
|
||||
virtual ~RsGxsCircles() { return; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -82,7 +82,7 @@ class RsGxsIdGroup
|
||||
std::string mPgpIdHash;
|
||||
std::string mPgpIdSign; // Need a signature as proof - otherwise anyone could add others Hashes.
|
||||
|
||||
// Serialised - for GUI's benefit.
|
||||
// Not Serialised - for GUI's benefit.
|
||||
bool mPgpKnown;
|
||||
std::string mPgpId;
|
||||
};
|
||||
|
408
libretroshare/src/serialiser/rsgxscircleitems.cc
Normal file
408
libretroshare/src/serialiser/rsgxscircleitems.cc
Normal file
@ -0,0 +1,408 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rswikiitems.cc
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 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.1 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 <iostream>
|
||||
|
||||
#include "rswireitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
|
||||
#define CIRCLE_DEBUG 1
|
||||
|
||||
|
||||
uint32_t RsGxsCircleSerialiser::size(RsItem *item)
|
||||
{
|
||||
RsGxsCircleGroupItem* grp_item = NULL;
|
||||
RsGxsCircleMsgItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsCircleGroupItem(grp_item);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
|
||||
{
|
||||
return sizeGxsCircleMsgItem(snap_item);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool RsGxsCircleSerialiser::serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsGxsCircleGroupItem* grp_item = NULL;
|
||||
RsGxsCircleMsgItem* snap_item = NULL;
|
||||
|
||||
if((grp_item = dynamic_cast<RsGxsCircleGroupItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsCircleGroupItem(grp_item, data, size);
|
||||
}
|
||||
else if((snap_item = dynamic_cast<RsGxsCircleMsgItem*>(item)) != NULL)
|
||||
{
|
||||
return serialiseGxsCircleMsgItem(snap_item, data, size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem* RsGxsCircleSerialiser::deserialise(void* data, uint32_t* size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialise()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
|
||||
case RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM:
|
||||
return deserialiseGxsCircleGroupItem(data, size);
|
||||
break;
|
||||
case RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM:
|
||||
return deserialiseGxsCircleMsgItem(data, size);
|
||||
break;
|
||||
default:
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialise(): unknown subtype";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsCircleGroupItem::clear()
|
||||
{
|
||||
group.mDescription.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsCircleGroupItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsCircleGroupItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Description: " << group.mDescription << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsCircleGroupItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsCircleSerialiser::sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item)
|
||||
{
|
||||
|
||||
const RsCircleGroup& group = item->group;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(group.mDescription);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsCircleSerialiser::serialiseGxsCircleGroupItem(RsGxsCircleGroupItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsCircleGroupItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsCircleGroupItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mDescription);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleGroupItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsCircleGroupItem* RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsCircleGroupItem* item = new RsGxsCircleGroupItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->group.mDescription);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleGroupItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
void RsGxsCircleMsgItem::clear()
|
||||
{
|
||||
pulse.mPulseText.clear();
|
||||
pulse.mHashTags.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsGxsCircleMsgItem::print(std::ostream& out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsGxsCircleMsgItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "Page: " << pulse.mPulseText << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "HashTags: " << pulse.mHashTags << std::endl;
|
||||
|
||||
printRsItemEnd(out ,"RsGxsCircleMsgItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsGxsCircleSerialiser::sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item)
|
||||
{
|
||||
|
||||
const RsCircleMsg& pulse = item->pulse;
|
||||
uint32_t s = 8; // header
|
||||
|
||||
s += GetTlvStringSize(pulse.mPulseText);
|
||||
s += GetTlvStringSize(pulse.mHashTags);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool RsGxsCircleSerialiser::serialiseGxsCircleMsgItem(RsGxsCircleMsgItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = sizeGxsCircleMsgItem(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if(*size < tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem()" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
*size = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* GxsCircleMsgItem */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mPulseText);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mHashTags);
|
||||
|
||||
if(offset != tlvsize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() FAIL Size Error! " << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
if (!ok)
|
||||
{
|
||||
std::cerr << "RsGxsCircleSerialiser::serialiseGxsCircleMsgItem() NOK" << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsGxsCircleMsgItem* RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem(void *data, uint32_t *size)
|
||||
{
|
||||
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem()" << std::endl;
|
||||
#endif
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong type" << std::endl;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*size < rssize) /* check size */
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL wrong size" << std::endl;
|
||||
#endif
|
||||
return NULL; /* not enough data */
|
||||
}
|
||||
|
||||
/* set the packet length */
|
||||
*size = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
RsGxsCircleMsgItem* item = new RsGxsCircleMsgItem();
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mPulseText);
|
||||
ok &= GetTlvString(data, rssize, &offset, 1, item->pulse.mHashTags);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() FAIL size mismatch" << std::endl;
|
||||
#endif
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
#ifdef CIRCLE_DEBUG
|
||||
std::cerr << "RsGxsCircleSerialiser::deserialiseGxsCircleMsgItem() NOK" << std::endl;
|
||||
#endif
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
|
93
libretroshare/src/serialiser/rsgxscircleitems.h
Normal file
93
libretroshare/src/serialiser/rsgxscircleitems.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsgxscircleitems.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 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.1 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RS_GXSCIRCLE_ITEMS_H
|
||||
#define RS_GXSCIRCLE_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
#include "rsgxsitems.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM = 0x03;
|
||||
|
||||
class RsGxsCircleGroupItem : public RsGxsGrpItem
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsGxsCircleGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_GROUP_ITEM) { return;}
|
||||
virtual ~RsGxsCircleGroupItem() { return;}
|
||||
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
|
||||
RsGxsCircleGroup group;
|
||||
};
|
||||
|
||||
class RsGxsCircleMsgItem : public RsGxsMsgItem
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleMsgItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_GXSCIRCLE,
|
||||
RS_PKT_SUBTYPE_GXSCIRCLE_MSG_ITEM) {return; }
|
||||
virtual ~RsGxsCircleMsgItem() { return;}
|
||||
void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
RsGxsCircleMsg msg;
|
||||
};
|
||||
|
||||
class RsGxsCircleSerialiser : public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_GXSCIRCLE)
|
||||
{ return; }
|
||||
virtual ~RsGxsCircleSerialiser() { return; }
|
||||
|
||||
uint32_t size(RsItem *item);
|
||||
bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
uint32_t sizeGxsCircleGroupItem(RsGxsCircleGroupItem *item);
|
||||
bool serialiseGxsCircleGroupItem (RsGxsCircleGroupItem *item, void *data, uint32_t *size);
|
||||
RsGxsCircleGroupItem * deserialiseGxsCircleGroupItem(void *data, uint32_t *size);
|
||||
|
||||
uint32_t sizeGxsCircleMsgItem(RsGxsCircleMsgItem *item);
|
||||
bool serialiseGxsCircleMsgItem (RsGxsCircleMsgItem *item, void *data, uint32_t *size);
|
||||
RsGxsCircleMsgItem * deserialiseGxsCircleMsgItem(void *data, uint32_t *size);
|
||||
};
|
||||
|
||||
#endif /* RS_GXSCIRCLE_ITEMS_H */
|
@ -138,14 +138,16 @@ const uint16_t RS_SERVICE_GXSV1_TYPE_WIRE = 0xf304;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_FORUMS = 0xf305;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_POSTED = 0xf306;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_CHANNELS = 0xf307;
|
||||
const uint16_t RS_SERVICE_GXSV1_TYPE_GXSCIRCLE = 0xf307;
|
||||
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSID = 0xf311;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_PHOTO = 0xf312;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_WIKI = 0xf313;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_WIRE = 0xf314;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf315;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf316;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf317;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_GXSCIRCLE = 0xf312;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_PHOTO = 0xf313;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_WIKI = 0xf314;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_WIRE = 0xf315;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_FORUMS = 0xf316;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_POSTED = 0xf317;
|
||||
const uint16_t RS_SERVICE_GXSV2_TYPE_CHANNELS = 0xf318;
|
||||
|
||||
/* Example Versions (VEG) of New Cache Services */
|
||||
const uint16_t RS_SERVICE_VEG_TYPE_IDENTITY = 0xf320;
|
||||
|
@ -1,208 +0,0 @@
|
||||
/*
|
||||
* libretroshare/src/services: p3circles.h
|
||||
*
|
||||
* Identity interface for RetroShare.
|
||||
*
|
||||
* Copyright 2012-2012 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.1 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef P3_CIRCLES_SERVICE_HEADER
|
||||
#define P3_CIRCLES_SERVICE_HEADER
|
||||
|
||||
|
||||
#include "retroshare/rscircles.h" // External Interfaces.
|
||||
#include "gxs/rsgenexchange.h" // GXS service.
|
||||
#include "gxs/rsgixs.h" // Internal Interfaces.
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* Circles Identity Service
|
||||
*
|
||||
* A collection of notes:
|
||||
*
|
||||
* We want to be able to express the following types of Circles.
|
||||
*
|
||||
* - Public
|
||||
* - Groups & Messages can be passed onto anyone. ( No Restrictions. )
|
||||
* - GXS Notes:
|
||||
* - This is what we have currently.
|
||||
*
|
||||
* - External Circle
|
||||
* - List of Identities that can receive the Group / Messages.
|
||||
* - This list will be defined via a set of RsIdentities - which have PGPHashes set.
|
||||
* - We need the PGPHashes to be able to identify which peers can receive msgs.
|
||||
* - Messages are passed to the Intersection of (Identified PGPHashes & Friends)
|
||||
* - Distribution of Circle Definitions can be also be restricted via circles.
|
||||
* - You can have Public External Groups, or Groups that only the Members know about.
|
||||
* - Control of these External Groups is determined by Admin / Publish Keys.
|
||||
* - The Danger with External Groups, is your ID wll be associated with other people...
|
||||
* - Leaking information!!!
|
||||
* - GXS Notes:
|
||||
* - p3Circles will provide a distrib list for a given Circle Group.
|
||||
*
|
||||
* - Personal Circle or "Your Eyes Only".
|
||||
* - Same as an Internal Circle Definition. (What will be used for File Sharing initially)
|
||||
* - Each peer will have a bunch of these, Friends, Family, etc.
|
||||
*
|
||||
* - The list is not publically shared, only the originator of the message will distribute.
|
||||
* - You can communicate back to the originator, who will share with the other members.
|
||||
* but you mustn't discuss / share content with anyone else.
|
||||
* - This is quite a Weak / Fragile Group, as there is only one distributor.
|
||||
* - GXS NOTES:
|
||||
* - TO make this work, we need GXS or RsCircles to maintain extra info:
|
||||
* - GXS stores the original source, so communications can go back there.
|
||||
* - If Originator, GXS store a REFERENCE, Circles turn this into a distrib list of peers.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Like RsIdentities are used to validation messages,
|
||||
* RsCircles will be used to determine if a peer can receive a group / messages.
|
||||
*
|
||||
* bool RsCircles::canSend(RsCircleId, RsPeerId)
|
||||
* bool RsCircles::canSend(RsCircleInternalId, RsPeerId)
|
||||
*
|
||||
* or maybe just:
|
||||
*
|
||||
* bool RsCircles::recipients(GxsPermission &perms, std::list<RsPeerId> friendlist);
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Permissions is part of GroupMetaData
|
||||
*/
|
||||
|
||||
#define GXS_PERM_TYPE_PUBLIC 0x0001
|
||||
#define GXS_PERM_TYPE_EXTERNAL 0x0002
|
||||
#define GXS_PERM_TYPE_YOUREYESONLY 0x0003
|
||||
|
||||
class GxsPermissions
|
||||
{
|
||||
public:
|
||||
uint32_t mType; // PUBLIC, EXTERNAL or YOUREYESONLY, Mutually exclusive.
|
||||
RsCircleId mCircleId; // If EXTERNAL, otherwise Blank.
|
||||
|
||||
// BELOW IS NOT SERIALISED - BUT MUST BE STORED LOCALLY BY GXS. (If YOUREYESONLY)
|
||||
RsPeerId mOriginator;
|
||||
RsCircleInternalId mInternalCircle; // if Originator == ownId, otherwise blank.
|
||||
};
|
||||
|
||||
|
||||
class RsGxsCircleGroup
|
||||
{
|
||||
public:
|
||||
GroupMetaData mMeta; // includes GxsPermissions, for control of group distribution.
|
||||
|
||||
std::list<RsGxsId> mMembers;
|
||||
std::list<RsCircleId> mCircleMembers;
|
||||
|
||||
|
||||
// Not Serialised.
|
||||
// Internally inside rsCircles, this will be turned into:
|
||||
// std::list<RsPeerId> mAllowedFriends;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class rsCircle
|
||||
{
|
||||
public:
|
||||
|
||||
/* GXS Interface - for working out who can receive */
|
||||
|
||||
bool canSend(RsCircleId, RsPeerId)
|
||||
bool canSend(RsCircleInternalId, RsPeerId)
|
||||
bool recipients(GxsPermission &perms, std::list<RsPeerId> friendlist);
|
||||
|
||||
/* Functions to handle Local / Internal Circles == Same as for file permissions. */
|
||||
createLocalCircle()
|
||||
addToLocalCircle()
|
||||
removeFromLocalCircle()
|
||||
getLocalCirclePeers()
|
||||
getListOfLocalCircles()
|
||||
|
||||
/* similar functions for External Groups */
|
||||
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group);
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*** IGNORE BELOW HERE *****/
|
||||
|
||||
class p3Circles: public RsGxsCircleExchange, public RsCircles
|
||||
{
|
||||
public:
|
||||
p3Circles(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
|
||||
|
||||
virtual void service_tick(); // needed for background processing.
|
||||
|
||||
|
||||
/* General Interface is provided by RsIdentity / RsGxsIfaceImpl. */
|
||||
|
||||
/* Data Specific Interface */
|
||||
|
||||
// These are exposed via RsIdentity.
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
|
||||
|
||||
// These are local - and not exposed via RsIdentity.
|
||||
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
|
||||
virtual bool createGroup(uint32_t& token, RsGxsIdGroup &group);
|
||||
virtual bool createMsg(uint32_t& token, RsGxsIdOpinion &opinion);
|
||||
|
||||
/**************** RsIdentity External Interface.
|
||||
* Notes:
|
||||
*/
|
||||
|
||||
/**************** RsGixs Implementation
|
||||
* Notes:
|
||||
* Interface is only suggestion at the moment, will be changed as necessary.
|
||||
* Results should be cached / preloaded for maximum speed.
|
||||
*
|
||||
*/
|
||||
|
||||
/**************** RsGixsReputation Implementation
|
||||
* Notes:
|
||||
* Again should be cached if possible.
|
||||
*/
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/** Notifications **/
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // P3_IDENTITY_SERVICE_HEADER
|
||||
|
||||
|
||||
|
1305
libretroshare/src/services/p3gxscircles.cc
Normal file
1305
libretroshare/src/services/p3gxscircles.cc
Normal file
File diff suppressed because it is too large
Load Diff
224
libretroshare/src/services/p3gxscircles.h
Normal file
224
libretroshare/src/services/p3gxscircles.h
Normal file
@ -0,0 +1,224 @@
|
||||
/*
|
||||
* libretroshare/src/services: p3circles.h
|
||||
*
|
||||
* Identity interface for RetroShare.
|
||||
*
|
||||
* Copyright 2012-2012 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.1 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef P3_CIRCLES_SERVICE_HEADER
|
||||
#define P3_CIRCLES_SERVICE_HEADER
|
||||
|
||||
|
||||
#include "retroshare/rsgxscircles.h" // External Interfaces.
|
||||
#include "gxs/rsgenexchange.h" // GXS service.
|
||||
#include "gxs/rsgixs.h" // Internal Interfaces.
|
||||
|
||||
#include "services/p3idservice.h" // For constructing Caches
|
||||
|
||||
#include "gxs/gxstokenqueue.h"
|
||||
#include "util/rstickevent.h"
|
||||
#include "util/rsmemcache.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* Circles Identity Service
|
||||
*
|
||||
* A collection of notes:
|
||||
*
|
||||
* We want to be able to express the following types of Circles.
|
||||
*
|
||||
* - Public
|
||||
* - Groups & Messages can be passed onto anyone. ( No Restrictions. )
|
||||
* - GXS Notes:
|
||||
* - This is what we have currently.
|
||||
*
|
||||
* - External Circle
|
||||
* - List of Identities that can receive the Group / Messages.
|
||||
* - This list will be defined via a set of RsIdentities - which have PGPHashes set.
|
||||
* - We need the PGPHashes to be able to identify which peers can receive msgs.
|
||||
* - Messages are passed to the Intersection of (Identified PGPHashes & Friends)
|
||||
* - Distribution of Circle Definitions can be also be restricted via circles.
|
||||
* - You can have Public External Groups, or Groups that only the Members know about.
|
||||
* - Control of these External Groups is determined by Admin / Publish Keys.
|
||||
* - The Danger with External Groups, is your ID wll be associated with other people...
|
||||
* - Leaking information!!!
|
||||
* - GXS Notes:
|
||||
* - p3Circles will provide a distrib list for a given Circle Group.
|
||||
*
|
||||
* - Personal Circle or "Your Eyes Only".
|
||||
* - Same as an Internal Circle Definition. (What will be used for File Sharing initially)
|
||||
* - Each peer will have a bunch of these, Friends, Family, etc.
|
||||
*
|
||||
* - The list is not publically shared, only the originator of the message will distribute.
|
||||
* - You can communicate back to the originator, who will share with the other members.
|
||||
* but you mustn't discuss / share content with anyone else.
|
||||
* - This is quite a Weak / Fragile Group, as there is only one distributor.
|
||||
* - GXS NOTES:
|
||||
* - TO make this work, we need GXS or RsCircles to maintain extra info:
|
||||
* - GXS stores the original source, so communications can go back there.
|
||||
* - If Originator, GXS store a REFERENCE, Circles turn this into a distrib list of peers.
|
||||
*
|
||||
*
|
||||
*
|
||||
* Like RsIdentities are used to validation messages,
|
||||
* RsCircles will be used to determine if a peer can receive a group / messages.
|
||||
*
|
||||
* bool RsCircles::canSend(RsGxsCircleId, RsPeerId)
|
||||
* bool RsCircles::canSend(RsCircleInternalId, RsPeerId)
|
||||
*
|
||||
* or maybe just:
|
||||
*
|
||||
* bool RsCircles::recipients(GxsPermission &perms, std::list<RsPeerId> friendlist);
|
||||
*
|
||||
*/
|
||||
|
||||
/* Permissions is part of GroupMetaData
|
||||
*/
|
||||
|
||||
class RsGxsCircleCache
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsCircleCache();
|
||||
bool loadBaseCircle(const RsGxsCircleGroup &circle);
|
||||
bool loadSubCircle(const RsGxsCircleCache &subcircle);
|
||||
|
||||
bool getAllowedPeersList(std::list<RsPgpId> &friendlist);
|
||||
bool isAllowedPeer(const RsPgpId &id);
|
||||
bool addAllowedPeer(const RsPgpId &pgpid, const RsGxsId &gxsId);
|
||||
|
||||
RsGxsCircleId mCircleId;
|
||||
|
||||
time_t mUpdateTime;
|
||||
std::set<RsGxsCircleId> mUnprocessedCircles;
|
||||
std::set<RsGxsId> mUnprocessedPeers;
|
||||
|
||||
std::set<RsGxsCircleId> mProcessedCircles;
|
||||
std::set<RsGxsId> mUnknownPeers;
|
||||
std::map<RsPgpId, std::list<RsGxsId> > mAllowedPeers;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RsCircles
|
||||
{
|
||||
/* Functions to handle Local / Internal Circles == Same as for file permissions. */
|
||||
public:
|
||||
virtual void createLocalCircle() = 0;
|
||||
virtual void addToLocalCircle() = 0;
|
||||
virtual void removeFromLocalCircle() = 0;
|
||||
virtual void getLocalCirclePeers() = 0;
|
||||
virtual void getListOfLocalCircles() = 0;
|
||||
|
||||
/* similar functions for External Groups */
|
||||
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group) = 0;
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
|
||||
public GxsTokenQueue, public RsTickEvent
|
||||
{
|
||||
public:
|
||||
p3GxsCircles(RsGeneralDataService* gds, RsNetworkExchangeService* nes,
|
||||
p3IdService *identities);
|
||||
|
||||
virtual void service_tick(); // needed for background processing.
|
||||
|
||||
protected:
|
||||
|
||||
static uint32_t circleAuthenPolicy();
|
||||
|
||||
/** Notifications **/
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
/** Overloaded to add PgpIdHash to Group Definition **/
|
||||
virtual void service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
virtual bool isLoaded(const RsGxsCircleId &circleId);
|
||||
virtual bool loadCircle(const RsGxsCircleId &circleId);
|
||||
|
||||
virtual int canSend(const RsGxsCircleId &circleId, const RsPgpId &id);
|
||||
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist);
|
||||
|
||||
/*** External Interface */
|
||||
|
||||
virtual void createLocalCircle();
|
||||
virtual void addToLocalCircle();
|
||||
virtual void removeFromLocalCircle();
|
||||
virtual void getLocalCirclePeers();
|
||||
virtual void getListOfLocalCircles();
|
||||
|
||||
/* similar functions for External Groups */
|
||||
virtual bool createGroup(uint32_t& token, RsGxsCircleGroup &group);
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups);
|
||||
|
||||
private:
|
||||
|
||||
// Need some crazy arsed cache to store the circle info.
|
||||
// so we don't have to keep loading groups.
|
||||
|
||||
int cache_tick();
|
||||
|
||||
bool cache_request_load(const RsGxsCircleId &id);
|
||||
bool cache_start_load();
|
||||
bool cache_load_for_token(uint32_t token);
|
||||
bool cache_reloadids(const std::string &circleId);
|
||||
|
||||
|
||||
p3IdService *mIdentities; // Needed for constructing Circle Info,
|
||||
|
||||
RsMutex mCircleMtx; /* Locked Below Here */
|
||||
|
||||
/***** Caching Circle Info, *****/
|
||||
// initial load queue
|
||||
std::list<RsGxsCircleId> mCacheLoad_ToCache;
|
||||
|
||||
// waiting for subcircle to load. (first is part of each of the second list)
|
||||
// TODO.
|
||||
//std::map<RsGxsCircleId, std::list<RsGxsCircleId> > mCacheLoad_SubCircle;
|
||||
|
||||
// Circles that are being loaded.
|
||||
std::map<RsGxsCircleId, RsGxsCircleCache> mLoadingCache;
|
||||
|
||||
// actual cache.
|
||||
RsMemCache<RsGxsCircleId, RsGxsCircleCache> mCircleCache;
|
||||
|
||||
private:
|
||||
|
||||
virtual void generateDummyData();
|
||||
std::string genRandomId();
|
||||
|
||||
};
|
||||
|
||||
#endif // P3_CIRCLES_SERVICE_HEADER
|
@ -447,7 +447,7 @@ bool p3GxsForums::generateGroup(uint32_t &token, std::string groupName)
|
||||
|
||||
|
||||
// Overloaded from RsTickEvent for Event callbacks.
|
||||
void p3GxsForums::handle_event(uint32_t event_type)
|
||||
void p3GxsForums::handle_event(uint32_t event_type, const std::string &elabel)
|
||||
{
|
||||
std::cerr << "p3GxsForums::handle_event(" << event_type << ")";
|
||||
std::cerr << std::endl;
|
||||
|
@ -46,10 +46,15 @@ class p3GxsForums: public RsGenExchange, public RsGxsForums,
|
||||
|
||||
p3GxsForums(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
|
||||
|
||||
virtual void service_tick();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
virtual void service_tick();
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
public:
|
||||
|
||||
@ -70,8 +75,6 @@ virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group);
|
||||
virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg);
|
||||
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -109,7 +109,9 @@ RsIdentity *rsIdentity = NULL;
|
||||
|
||||
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
||||
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXSV1_TYPE_GXSID),
|
||||
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(), mIdMtx("p3IdService")
|
||||
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(), mIdMtx("p3IdService"),
|
||||
mPublicKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPublicKeyCache"),
|
||||
mPrivateKeyCache(DEFAULT_MEM_CACHE_SIZE, "GxsIdPrivateKeyCache")
|
||||
{
|
||||
mBgSchedule_Mode = 0;
|
||||
mBgSchedule_Active = false;
|
||||
@ -702,11 +704,13 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
|
||||
// Create Cache Data.
|
||||
RsGxsIdCache pubcache(item, pubkey);
|
||||
mPublicKeyCache.store(id, pubcache);
|
||||
mPublicKeyCache.resize();
|
||||
|
||||
if (full_key_ok)
|
||||
{
|
||||
RsGxsIdCache fullcache(item, fullkey);
|
||||
mPrivateKeyCache.store(id, fullcache);
|
||||
mPrivateKeyCache.resize();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -809,10 +813,6 @@ bool p3IdService::cache_load_for_token(uint32_t token)
|
||||
cache_store(item);
|
||||
delete item;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
||||
mPrivateKeyCache.resize();
|
||||
mPublicKeyCache.resize();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2430,7 +2430,7 @@ void p3IdService::handleResponse(uint32_t token, uint32_t req_type)
|
||||
|
||||
|
||||
// Overloaded from RsTickEvent for Event callbacks.
|
||||
void p3IdService::handle_event(uint32_t event_type)
|
||||
void p3IdService::handle_event(uint32_t event_type, const std::string &elabel)
|
||||
{
|
||||
std::cerr << "p3IdService::handle_event(" << event_type << ")";
|
||||
std::cerr << std::endl;
|
||||
|
@ -221,13 +221,6 @@ virtual int getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key);
|
||||
virtual bool getReputation(const RsGxsId &id, const GixsReputation &rep);
|
||||
|
||||
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type);
|
||||
|
||||
protected:
|
||||
|
||||
/** Notifications **/
|
||||
@ -236,6 +229,12 @@ virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
/** Overloaded to add PgpIdHash to Group Definition **/
|
||||
virtual void service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
private:
|
||||
|
||||
/************************************************************************
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
|
||||
/************************************************************************************/
|
||||
/************************************************************************************/
|
||||
@ -49,11 +50,16 @@ template<class Key, class Value> class RsMemCache
|
||||
{
|
||||
public:
|
||||
|
||||
RsMemCache(uint32_t max_size = DEFAULT_MEM_CACHE_SIZE)
|
||||
:mDataCount(0), mMaxSize(max_size) { return; }
|
||||
RsMemCache(uint32_t max_size = DEFAULT_MEM_CACHE_SIZE, std::string name = "UnknownMemCache")
|
||||
:mDataCount(0), mMaxSize(max_size), mName(name)
|
||||
{
|
||||
clearStats();
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_cached(const Key &key) const;
|
||||
bool fetch(const Key &key, Value &data);
|
||||
Value &ref(const Key &key); // like map[] installs empty one if non-existent.
|
||||
bool store(const Key &key, const Value &data);
|
||||
|
||||
bool resize(); // should be called periodically to cleanup old entries.
|
||||
@ -80,6 +86,18 @@ template<class Key, class Value> class RsMemCache
|
||||
std::multimap<time_t, Key> mLruMap;
|
||||
uint32_t mDataCount;
|
||||
uint32_t mMaxSize;
|
||||
std::string mName;
|
||||
|
||||
// some statistics.
|
||||
void printStats(std::ostream &out);
|
||||
void clearStats();
|
||||
|
||||
mutable uint32_t mStats_inserted;
|
||||
mutable uint32_t mStats_dropped;
|
||||
mutable uint32_t mStats_iscached;
|
||||
mutable uint32_t mStats_cachemiss;
|
||||
mutable uint32_t mStats_access;
|
||||
mutable uint32_t mStats_accessmiss;
|
||||
};
|
||||
|
||||
|
||||
@ -92,10 +110,12 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::is_cached(const Ke
|
||||
std::cerr << "RsMemCache::is_cached(" << key << ") false";
|
||||
std::cerr << std::endl;
|
||||
|
||||
mStats_cachemiss++;
|
||||
return false;
|
||||
}
|
||||
std::cerr << "RsMemCache::is_cached(" << key << ") false";
|
||||
std::cerr << std::endl;
|
||||
mStats_iscached++;
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -103,6 +123,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::is_cached(const Ke
|
||||
|
||||
template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &key, Value &data)
|
||||
{
|
||||
printStats(std::cerr);
|
||||
typename std::map<Key, cache_data>::iterator it;
|
||||
it = mDataMap.find(key);
|
||||
if (it == mDataMap.end())
|
||||
@ -110,6 +131,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &k
|
||||
std::cerr << "RsMemCache::fetch(" << key << ") false";
|
||||
std::cerr << std::endl;
|
||||
|
||||
mStats_accessmiss++;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -125,13 +147,54 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &k
|
||||
|
||||
update_lrumap(key, old_ts, new_ts);
|
||||
|
||||
mStats_access++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Key, class Value> Value &RsMemCache<Key, Value>::ref(const Key &key)
|
||||
{
|
||||
printStats(std::cerr);
|
||||
typename std::map<Key, cache_data>::iterator it;
|
||||
it = mDataMap.find(key);
|
||||
if (it == mDataMap.end())
|
||||
{
|
||||
std::cerr << "RsMemCache::ref(" << key << ") ERROR missing Key inserting Empty Data in LRU slot";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// insert operation.
|
||||
time_t new_ts = 0;
|
||||
Value data;
|
||||
mDataMap[key] = cache_data(key, data, new_ts);
|
||||
mDataCount++;
|
||||
|
||||
update_lrumap(key, 0, new_ts);
|
||||
it = mDataMap.find(key);
|
||||
|
||||
mStats_accessmiss++;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsMemCache::ref(" << key << ") OK";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* update ts on data */
|
||||
time_t old_ts = it->second.ts;
|
||||
time_t new_ts = time(NULL);
|
||||
it->second.ts = new_ts;
|
||||
|
||||
update_lrumap(key, old_ts, new_ts);
|
||||
|
||||
mStats_access++;
|
||||
}
|
||||
return it->second.data;
|
||||
}
|
||||
|
||||
template<class Key, class Value> bool RsMemCache<Key, Value>::store(const Key &key, const Value &data)
|
||||
{
|
||||
std::cerr << "RsMemCache::store()";
|
||||
std::cerr << std::endl;
|
||||
printStats(std::cerr);
|
||||
|
||||
/* update lrumap entry */
|
||||
time_t old_ts = 0;
|
||||
@ -148,13 +211,16 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::store(const Key &k
|
||||
|
||||
old_ts = it->second.ts;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
mDataCount++;
|
||||
}
|
||||
|
||||
mDataMap[key] = cache_data(key, data, new_ts);
|
||||
mDataCount++;
|
||||
|
||||
update_lrumap(key, old_ts, new_ts);
|
||||
|
||||
mStats_inserted++;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -203,6 +269,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::resize()
|
||||
{
|
||||
std::cerr << "RsMemCache::resize()";
|
||||
std::cerr << std::endl;
|
||||
printStats(std::cerr);
|
||||
|
||||
int count_to_clear = 0;
|
||||
{
|
||||
@ -259,6 +326,7 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::discard_LRU(int co
|
||||
std::cerr << std::endl;
|
||||
mDataMap.erase(it);
|
||||
mDataCount--;
|
||||
mStats_dropped++;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -273,6 +341,39 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::discard_LRU(int co
|
||||
return true;
|
||||
}
|
||||
|
||||
// These aren't templated functions.
|
||||
template<class Key, class Value> void RsMemCache<Key, Value>::printStats(std::ostream &out)
|
||||
{
|
||||
typename std::multimap<time_t, Key>::iterator mit = mLruMap.begin();
|
||||
time_t age = 0;
|
||||
if (mit != mLruMap.end())
|
||||
{
|
||||
age = time(NULL) - mit->first;
|
||||
}
|
||||
|
||||
out << "RsMemCache<" << mName << ">::printStats() Size: " << mDataCount << " Size2: " << mDataMap.size() << " Size3: " << mLruMap.size() << " MaxSize: " << mMaxSize << " LRU Age: " << age;
|
||||
out << std::endl;
|
||||
|
||||
out << "\tInsertions: " << mStats_inserted << " Drops: " << mStats_dropped;
|
||||
out << std::endl;
|
||||
|
||||
out << "\tCache Hits: " << mStats_iscached << " Misses: " << mStats_cachemiss;
|
||||
out << std::endl;
|
||||
|
||||
out << "\tAccess Hits: " << mStats_access << " Misses: " << mStats_accessmiss;
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
template<class Key, class Value> void RsMemCache<Key, Value>::clearStats()
|
||||
{
|
||||
mStats_inserted = 0;
|
||||
mStats_dropped = 0;
|
||||
mStats_iscached = 0;
|
||||
mStats_cachemiss = 0;
|
||||
mStats_access = 0;
|
||||
mStats_accessmiss = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -67,16 +67,16 @@ void RsTickEvent::tick_events()
|
||||
}
|
||||
}
|
||||
|
||||
std::list<uint32_t> toProcess;
|
||||
std::list<uint32_t>::iterator it;
|
||||
std::list<EventData> toProcess;
|
||||
std::list<EventData>::iterator it;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mEventMtx); /********** STACK LOCKED MTX ******/
|
||||
while((!mEvents.empty()) && (mEvents.begin()->first <= now))
|
||||
{
|
||||
std::multimap<time_t, uint32_t>::iterator it = mEvents.begin();
|
||||
uint32_t event_type = it->second;
|
||||
toProcess.push_back(event_type);
|
||||
std::multimap<time_t, EventData>::iterator it = mEvents.begin();
|
||||
uint32_t event_type = it->second.mEventType;
|
||||
toProcess.push_back(it->second);
|
||||
mEvents.erase(it);
|
||||
|
||||
count_adjust_locked(event_type, -1);
|
||||
@ -86,40 +86,53 @@ void RsTickEvent::tick_events()
|
||||
for(it = toProcess.begin(); it != toProcess.end(); it++)
|
||||
{
|
||||
std::cerr << "RsTickEvent::tick_events() calling handle_event(";
|
||||
std::cerr << *it << ")";
|
||||
std::cerr << it->mEventType << ", " << it->mEventLabel << ")";
|
||||
std::cerr << std::endl;
|
||||
handle_event(*it);
|
||||
handle_event(it->mEventType, it->mEventLabel);
|
||||
}
|
||||
}
|
||||
|
||||
void RsTickEvent::schedule_now(uint32_t event_type)
|
||||
{
|
||||
RsTickEvent::schedule_in(event_type, 0);
|
||||
std::string elabel;
|
||||
RsTickEvent::schedule_in(event_type, 0, elabel);
|
||||
}
|
||||
|
||||
void RsTickEvent::schedule_event(uint32_t event_type, time_t when)
|
||||
|
||||
void RsTickEvent::schedule_now(uint32_t event_type, const std::string &elabel)
|
||||
{
|
||||
RsTickEvent::schedule_in(event_type, 0, elabel);
|
||||
}
|
||||
|
||||
void RsTickEvent::schedule_event(uint32_t event_type, time_t when, const std::string &elabel)
|
||||
{
|
||||
RsStackMutex stack(mEventMtx); /********** STACK LOCKED MTX ******/
|
||||
mEvents.insert(std::make_pair(when, event_type));
|
||||
mEvents.insert(std::make_pair(when, EventData(event_type, elabel)));
|
||||
|
||||
count_adjust_locked(event_type, 1);
|
||||
}
|
||||
|
||||
void RsTickEvent::schedule_in(uint32_t event_type, uint32_t in_secs)
|
||||
{
|
||||
std::cerr << "RsTickEvent::schedule_in(" << event_type << ") in " << in_secs << " secs";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsStackMutex stack(mEventMtx); /********** STACK LOCKED MTX ******/
|
||||
time_t event_time = time(NULL) + in_secs;
|
||||
mEvents.insert(std::make_pair(event_time, event_type));
|
||||
|
||||
count_adjust_locked(event_type, 1);
|
||||
std::string elabel;
|
||||
RsTickEvent::schedule_in(event_type, in_secs, elabel);
|
||||
}
|
||||
|
||||
void RsTickEvent::handle_event(uint32_t event_type)
|
||||
|
||||
void RsTickEvent::schedule_in(uint32_t event_type, uint32_t in_secs, const std::string &elabel)
|
||||
{
|
||||
std::cerr << "RsTickEvent::handle_event(" << event_type << ") ERROR Not Handled";
|
||||
std::cerr << "RsTickEvent::schedule_in(" << event_type << ", " << elabel << ") in " << in_secs << " secs";
|
||||
std::cerr << std::endl;
|
||||
|
||||
time_t event_time = time(NULL) + in_secs;
|
||||
RsTickEvent::schedule_event(event_type, event_time, elabel);
|
||||
}
|
||||
|
||||
|
||||
void RsTickEvent::handle_event(uint32_t event_type, const std::string &elabel)
|
||||
{
|
||||
std::cerr << "RsTickEvent::handle_event(" << event_type << ", " << elabel;
|
||||
std::cerr << ") ERROR Not Handled";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
|
@ -44,24 +44,41 @@ class RsTickEvent
|
||||
void tick_events();
|
||||
|
||||
void schedule_now(uint32_t event_type);
|
||||
void schedule_event(uint32_t event_type, time_t when);
|
||||
void schedule_now(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
void schedule_event(uint32_t event_type, time_t when, const std::string &elabel);
|
||||
|
||||
void schedule_in(uint32_t event_type, uint32_t in_secs);
|
||||
void schedule_in(uint32_t event_type, uint32_t in_secs, const std::string &elabel);
|
||||
|
||||
int32_t event_count(uint32_t event_type);
|
||||
bool prev_event_ago(uint32_t event_type, int32_t &age);
|
||||
|
||||
protected:
|
||||
|
||||
// Overloaded to handle the events.
|
||||
virtual void handle_event(uint32_t event_type);
|
||||
virtual void handle_event(uint32_t event_type, const std::string &event_label);
|
||||
|
||||
private:
|
||||
|
||||
class EventData
|
||||
{
|
||||
public:
|
||||
EventData() :mEventType(0) { return; }
|
||||
EventData(uint32_t etype) :mEventType(etype) { return; }
|
||||
EventData(uint32_t etype, std::string elabel) :mEventLabel(elabel), mEventType(etype) { return; }
|
||||
|
||||
std::string mEventLabel;
|
||||
uint32_t mEventType;
|
||||
};
|
||||
|
||||
void count_adjust_locked(uint32_t event_type, int32_t change);
|
||||
void note_event_locked(uint32_t event_type);
|
||||
|
||||
RsMutex mEventMtx;
|
||||
std::map<uint32_t, int32_t> mEventCount;
|
||||
std::map<uint32_t, time_t> mPreviousEvent;
|
||||
std::multimap<time_t, uint32_t> mEvents;
|
||||
std::multimap<time_t, EventData> mEvents;
|
||||
};
|
||||
|
||||
#endif // RS_UTIL_TICK_EVENT
|
||||
|
Loading…
Reference in New Issue
Block a user