diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 4c3ed995e..62c97a810 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -137,16 +137,15 @@ PUBLIC_HEADERS = retroshare/rsblogs.h \ retroshare/rstypes.h \ retroshare/rsdht.h \ retroshare/rsdsdv.h \ - retroshare/rsconfig.h \ - retroshare/rsphotoV2.h + retroshare/rsconfig.h + HEADERS += plugins/pluginmanager.h \ plugins/dlfcn_win32.h \ serialiser/rspluginitems.h HEADERS += $$PUBLIC_HEADERS # public headers to be... -HEADERS += retroshare/rsgame.h \ - retroshare/rsphoto.h +HEADERS += retroshare/rsgame.h # ################################ Linux ########################################## linux-* { @@ -610,16 +609,12 @@ HEADERS += retroshare/rsgame.h \ gxs/rsgxsdataaccess.h \ retroshare/rsgxsservice.h \ serialiser/rsgxsitems.h \ - serialiser/rsphotov2items.h \ util/retrodb.h \ util/contentvalue.h \ gxs/gxscoreserver.h \ gxs/gxssecurity.h \ gxs/rsgxsifaceimpl.h \ gxs/gxstokenqueue.h \ - services/p3posted.h \ - retroshare/rsposted.h \ - serialiser/rsposteditems.h SOURCES += serialiser/rsnxsitems.cc \ @@ -628,17 +623,13 @@ HEADERS += retroshare/rsgame.h \ gxs/rsgxsnetservice.cc \ gxs/rsgxsdata.cc \ serialiser/rsgxsitems.cc \ - services/p3photoserviceV2.cc \ gxs/rsgxsdataaccess.cc \ - serialiser/rsphotov2items.cc \ util/retrodb.cc \ util/contentvalue.cc \ gxs/gxscoreserver.cc \ gxs/gxssecurity.cc \ gxs/rsgxsifaceimpl.cc \ gxs/gxstokenqueue.cc \ - services/p3posted.cc \ - serialiser/rsposteditems.cc # Identity Service HEADERS += retroshare/rsidentity.h \ @@ -665,26 +656,34 @@ HEADERS += retroshare/rsgame.h \ SOURCES += services/p3wiki.cc \ serialiser/rswikiitems.cc \ + # Wiki Service + HEADERS += retroshare/rswire.h \ + services/p3wire.h \ + serialiser/rswireitems.h + + SOURCES += services/p3wire.cc \ + serialiser/rswireitems.cc \ + + # Posted Service + HEADERS += services/p3posted.h \ + retroshare/rsposted.h \ + serialiser/rsposteditems.h + + SOURCES += services/p3posted.cc \ + serialiser/rsposteditems.cc + + #Photo Service + HEADERS += services/p3photoservice.h \ + retroshare/rsphoto.h \ + serialiser/rsphotoitems.h \ + + SOURCES += services/p3photoservice.cc \ + serialiser/rsphotoitems.cc \ } newservices { - HEADERS += services/p3photoserviceV2.h \ - retroshare/rsphotoVEG.h \ - services/p3gxsserviceVEG.h \ - services/p3wikiserviceVEG.h \ - retroshare/rswikiVEG.h \ - retroshare/rswireVEG.h \ - services/p3wireVEG.h \ - retroshare/rsforumsVEG.h \ - services/p3forumsVEG.h - # Do I need this? - #serialiser/rsphotoitemsVEG.h \ + # source code for p3gxsserviceVEG / p3postedVEG will be maintained + # until they are finished - for reference... but it wont compile. - SOURCES += services/p3gxsserviceVEG.cc \ - services/p3wikiserviceVEG.cc \ - services/p3wireVEG.cc \ - services/p3forumsVEG.cc - # Do I need this? - # serialiser/rsphotoitemsVEG.cc \ } diff --git a/libretroshare/src/retroshare/rsforumsVEG.h b/libretroshare/src/retroshare/rsforumsVEG.h deleted file mode 100644 index 1f12377cc..000000000 --- a/libretroshare/src/retroshare/rsforumsVEG.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef RETROSHARE_FORUMV2_GUI_INTERFACE_H -#define RETROSHARE_FORUMV2_GUI_INTERFACE_H - -/* - * libretroshare/src/retroshare: rsforumv2.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 -#include -#include - -#include - -/* The Main Interface Class - for information about your Peers */ -class RsForumsVEG; -extern RsForumsVEG *rsForumsVEG; - -class RsForumV2Group -{ - public: - - // All the MetaData is Stored here: - RsGroupMetaData mMeta; - - // THESE ARE IN THE META DATA. - //std::string mGroupId; - //std::string mName; - - std::string mDescription; - - // THESE ARE CURRENTLY UNUSED. - //std::string mCategory; - //std::string mHashTags; -}; - -class RsForumV2Msg -{ - public: - - // All the MetaData is Stored here: - RsMsgMetaData mMeta; - - // THESE ARE IN THE META DATA. - //std::string mGroupId; - //std::string mMsgId; - //std::string mOrigMsgId; - //std::string mThreadId; - //std::string mParentId; - //std::string mName; (aka. Title) - - std::string mMsg; // all the text is stored here. - - // THESE ARE CURRENTLY UNUSED. - //std::string mHashTags; -}; - -class RsForumsVEG: public RsTokenServiceVEG -{ - public: - - RsForumsVEG() { return; } -virtual ~RsForumsVEG() { return; } - - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group) = 0; -virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg) = 0; - - - // ONES THAT WE ARE NOT IMPLEMENTING. (YET!) -//virtual bool getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status) = 0; - -// THINK WE CAN GENERALISE THIS TO: a list function, and you can just count the list entries... -// requestGroupList(groupId, UNREAD, ...) -//virtual bool getMessageCount(const std::string &groupId, unsigned int &newCount, unsigned int &unreadCount) = 0; - - -/* details are updated in group - to choose GroupID */ -virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew) = 0; -virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew) = 0; - -}; - - - -#endif diff --git a/libretroshare/src/retroshare/rsidentityVEG.h b/libretroshare/src/retroshare/rsidentityVEG.h deleted file mode 100644 index 6cb50fc42..000000000 --- a/libretroshare/src/retroshare/rsidentityVEG.h +++ /dev/null @@ -1,534 +0,0 @@ -#ifndef RETROSHARE_IDENTITY_GUI_VEG_INTERFACE_H -#define RETROSHARE_IDENTITY_GUI_VEG_INTERFACE_H - -/* - * libretroshare/src/retroshare: rsidentity.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 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 -#include -#include - -// FLAGS WILL BE REUSED FROM RSDISTRIB -> FOR NOW. -#include - -/********** Generic Token Request Interface *********************** - * This is packaged here, as most TokenServices will require ID Services too. - * The requests can be generic, but the reponses are service specific (dependent on data types). - */ - -// This bit will be filled out over time. -#define RS_TOKREQOPT_MSG_VERSIONS 0x0001 // MSGRELATED: Returns All MsgIds with OrigMsgId = MsgId. -#define RS_TOKREQOPT_MSG_ORIGMSG 0x0002 // MSGLIST: All Unique OrigMsgIds in a Group. -#define RS_TOKREQOPT_MSG_LATEST 0x0004 // MSGLIST: All Latest MsgIds in Group. MSGRELATED: Latest MsgIds for Input Msgs. - -#define RS_TOKREQOPT_MSG_THREAD 0x0010 // MSGRELATED: All Msgs in Thread. MSGLIST: All Unique Thread Ids in Group. -#define RS_TOKREQOPT_MSG_PARENT 0x0020 // MSGRELATED: All Children Msgs. - -#define RS_TOKREQOPT_MSG_AUTHOR 0x0040 // MSGLIST: Messages from this AuthorId - - -// Status Filtering... should it be a different Option Field. -#define RS_TOKREQOPT_GROUP_UPDATED 0x0100 // GROUPLIST: Groups that have been updated. -#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups. -#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups. - - - -// Read Status. -#define RS_TOKREQOPT_READ 0x0001 -#define RS_TOKREQOPT_UNREAD 0x0002 - -#define RS_TOKREQ_ANSTYPE_LIST 0x0001 -#define RS_TOKREQ_ANSTYPE_SUMMARY 0x0002 -#define RS_TOKREQ_ANSTYPE_DATA 0x0003 - - - -class RsTokReqOptionsVEG -{ - public: - RsTokReqOptionsVEG() - { - mOptions = 0; - mStatusFilter = 0; mStatusMask = 0; - mFlagsFilter = 0; mFlagsMask = 0; - mSubscribeFilter = 0; - mBefore = 0; mAfter = 0; - } - - uint32_t mOptions; - - // Request specific matches with Group / Message Status. - // Should be usable with any Options... applied afterwards. - uint32_t mStatusFilter; - uint32_t mStatusMask; - - // MsgFlags or GroupsFlags, depends on Request. - uint32_t mFlagsFilter; - uint32_t mFlagsMask; - - uint32_t mSubscribeFilter; // Only for Groups. - - // Time range... again applied after Options. - time_t mBefore; - time_t mAfter; -}; - - -/********************************************************* - * Documentation for Groups Definitions. - * - * A Group is defined by: - * - TWO RSA Keys. (Admin Key & Publish Key) - * - Publish TS: Used to select the latest definition. - * - * - Operating Mode: - * - Circle (Public, External, Private). - * - Publish Mode: Encrypted / All-Signed / Only ThreadHead / None Required. - * - AuthorId: GPG Required / Any Required / Only if no Publish Signature. - * - * - Description: - * - Name & Description. - * - Optional AuthorId. - * - * Most of this information is contained inside the GroupMetaData. - * except for Actual Admin / Publish Keys, which are maintained internally. - * - ******* - * - Group Definition must be signed by Admin Key, otherwise invalid. - * - Circle Definition controls distribution of Group and Messages, see section on this for more details. - * - Public parts of Keys are distributed with Definition. - * - Private parts can be distributed to select people via alternative channels. - * - A Message Requires at least one signature: publish or Author. This signature will be used as MsgId. - * - * Groups will operate in the following modes: - * 1) Public Forum: PublishMode = None Required, AuthorId: Required. - * 2) Closed Forum: PublishMode = All-Signed, AuthorId: Required. - * 3) Private Forum: PublishMode = Encrypted, AuthorId: Required. - * - * 4) Anon Channel: PublishMode = All-Signed, AuthorId: None. - * 5) Anon Channel with Comments: PublishMode = Only ThreadHead, AuthorId: If No Publish Signature. - * 6) Private Channel: PublishMode = Encrypted. - * - * 7) Personal Photos - with comments: PublishMode = Only ThreadHead, AuthorId: Required. - * 8) Personal Photos - no comments: PublishMode = All-Signed, AuthorId: Required. - * - * 9 ) Public Wiki: PublishMode = None Required, AuthorId: Required. - * 10) Closed Wiki: PublishMode = All-Signed, AuthorId: Required. - * 11) Private Wiki: PublishMode = Encrypted, AuthorId: Required. - * - * 12) Twitter: PublishMode = Only ThreadHead, AuthorId: Required. - * - * 13) Posted: PublishMode = None Required, AuthorId: Required. - * - * - ****** - * - * Additionally to this information. The MetaData also contains several fields which can - * be used to store local information for the benefit of the service. - * - * In Particular: MsgStatus & GroupStatus inform the service if the user has read the message or if anything has changed. - * - ***/ - - -// Control of Publish Signatures. -#define RSGXS_GROUP_SIGN_PUBLISH_MASK 0x000000ff -#define RSGXS_GROUP_SIGN_PUBLISH_ENCRYPTED 0x00000001 -#define RSGXS_GROUP_SIGN_PUBLISH_ALLSIGNED 0x00000002 -#define RSGXS_GROUP_SIGN_PUBLISH_THREADHEAD 0x00000004 -#define RSGXS_GROUP_SIGN_PUBLISH_NONEREQ 0x00000008 - -// Author Signature. -#define RSGXS_GROUP_SIGN_AUTHOR_MASK 0x0000ff00 -#define RSGXS_GROUP_SIGN_AUTHOR_GPG 0x00000100 -#define RSGXS_GROUP_SIGN_AUTHOR_REQUIRED 0x00000200 -#define RSGXS_GROUP_SIGN_AUTHOR_IFNOPUBSIGN 0x00000400 -#define RSGXS_GROUP_SIGN_AUTHOR_NONE 0x00000800 - -// NB: That one signature is required... -// so some combinations are not possible. e.g. -// SIGN_PUBLISH_NONEREQ && SIGN_AUTHOR_NONE is not allowed. -// SIGN_PUBLISH_THREADHEAD && SIGN_AUTHOR_NONE is also invalid. - -#define RSGXS_GROUP_SIGN_RESERVED_MASK 0xffff0000 - - -// STATUS FLAGS: There is space here for Service specific flags - if they so desire. -// -// Msgs: UNREAD_BY_USER & PROCESSED are useful. -// Groups: NEW_MESSAGES & GROUP_UPDATED. - -#define RSGXS_MSG_STATUS_MASK 0x0000000f -#define RSGXS_MSG_STATUS_READ 0x00000001 // New or Not New -#define RSGXS_MSG_STATUS_UNREAD_BY_USER 0x00000002 -#define RSGXS_MSG_STATUS_UNPROCESSED 0x00000004 // By the Service. - -#define RSGXS_MSG_STATUS_SERVICE_MASK 0xffff0000 - -#define RSGXS_GROUP_STATUS_MASK 0x0000000f -#define RSGXS_GROUP_STATUS_UPDATED 0x00000001 -#define RSGXS_GROUP_STATUS_NEWGROUP 0x00000002 -#define RSGXS_GROUP_STATUS_NEWMSG 0x00000004 - -#define RSGXS_GROUP_STATUS_SERVICE_MASK 0xffff0000 - - - -// Subscription Flags. (LOCAL) -#define RSGXS_GROUP_SUBSCRIBE_MASK 0x0000000f -#define RSGXS_GROUP_SUBSCRIBE_ADMIN 0x00000001 -#define RSGXS_GROUP_SUBSCRIBE_PUBLISH 0x00000002 -#define RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED 0x00000004 -#define RSGXS_GROUP_SUBSCRIBE_MONITOR 0x00000008 - - -// Some MACROS for EASE OF USE. (USED BY FORUMSV2 At the moment. -// MOVED TO REAL GXS STUFF -//#define IS_MSG_UNREAD(status) ((status & RSGXS_MSG_STATUS_READ) == 0 || (status & RSGXS_MSG_STATUS_UNREAD_BY_USER)) -//#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & RSGXS_GROUP_SUBSCRIBE_ADMIN) -//#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & (RSGXS_GROUP_SUBSCRIBE_ADMIN | RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED)) - - - -#define RSGXS_MAX_SERVICE_STRING 200 // Sensible limit for dbase usage. - -#include "serialiser/rsgxsitems.h" - -//class RsGroupMetaData -//{ -// public: -// -// RsGroupMetaData() -// { -// mGroupFlags = 0; -// mSignFlags = 0; -// mSubscribeFlags = 0; -// -// mPop = 0; -// mMsgCount = 0; -// mLastPost = 0; -// mGroupStatus = 0; -// -// //mPublishTs = 0; -// } -// -// std::string mGroupId; -// std::string mGroupName; -// uint32_t mGroupFlags; // Service Specific Options ???? -// uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK. -// -// time_t mPublishTs; // Mandatory. -// std::string mAuthorId; // Optional. -// -// // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. -// -// uint32_t mSubscribeFlags; -// -// uint32_t mPop; // HOW DO WE DO THIS NOW. -// uint32_t mMsgCount; // ??? -// time_t mLastPost; // ??? -// -// uint32_t mGroupStatus; -// -// std::string mServiceString; // Service Specific Free-Form extra storage. -//}; -// -// -// -// -//class RsMsgMetaData -//{ -// public: -// -// RsMsgMetaData() -// { -// mPublishTs = 0; -// mMsgFlags = 0; -// mMsgStatus = 0; -// mChildTs = 0; -// } -// -// std::string mGroupId; -// std::string mMsgId; -// -// std::string mThreadId; -// std::string mParentId; -// std::string mOrigMsgId; -// -// std::string mAuthorId; -// -// std::string mMsgName; -// time_t mPublishTs; -// -// uint32_t mMsgFlags; // Whats this for? (Optional Service Specific - e.g. flag MsgType) -// -// // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. -// // normally READ / UNREAD flags. LOCAL Data. -// uint32_t mMsgStatus; -// time_t mChildTs; -// -// std::string mServiceString; // Service Specific Free-Form extra storage. -// -//}; - -//std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta); -//std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta); - -class RsTokenServiceVEG -{ - public: - - RsTokenServiceVEG() { return; } -virtual ~RsTokenServiceVEG() { return; } - - /* changed? */ -virtual bool updated() = 0; - - /* Data Requests */ -virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) = 0; -virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) = 0; -virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds) = 0; - - /* Generic Lists */ -virtual bool getGroupList( const uint32_t &token, std::list &groupIds) = 0; -virtual bool getMsgList( const uint32_t &token, std::list &msgIds) = 0; - - /* Generic Summary */ -virtual bool getGroupSummary( const uint32_t &token, std::list &groupInfo) = 0; -virtual bool getMsgSummary( const uint32_t &token, std::list &msgInfo) = 0; - - /* Actual Data -> specific to Interface */ - - - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token) = 0; - - /* Cancel Request */ -virtual bool cancelRequest(const uint32_t &token) = 0; - - - ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ - // Groups Changed is now part of requestGroupInfo request. -//virtual bool groupsChanged(std::list &groupIds) = 0; - - // Message/Group Status - is retrived via requests... - // These operations could have a token, but for the moment we are going to assume - // they are async and always succeed - (or fail silently). -virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) = 0; -virtual bool setGroupStatus(const std::string &grpId, const uint32_t status, const uint32_t statusMask) = 0; - -virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) = 0; - -virtual bool setMessageServiceString(const std::string &msgId, const std::string &str) = 0; -virtual bool setGroupServiceString(const std::string &grpId, const std::string &str) = 0; - - // (FUTURE WORK). -virtual bool groupRestoreKeys(const std::string &groupId) = 0; -virtual bool groupShareKeys(const std::string &groupId, std::list& peers) = 0; - - - - -}; - - - - -/* The Main Interface Class - for information about your Peers */ -class RsIdentityVEG; -extern RsIdentityVEG *rsIdentityVEG; - -#define RSID_TYPE_MASK 0xff00 -#define RSID_RELATION_MASK 0x00ff - -#define RSID_TYPE_REALID 0x0100 -#define RSID_TYPE_PSEUDONYM 0x0200 - -#define RSID_RELATION_YOURSELF 0x0001 -#define RSID_RELATION_FRIEND 0x0002 -#define RSID_RELATION_FOF 0x0004 -#define RSID_RELATION_OTHER 0x0008 -#define RSID_RELATION_UNKNOWN 0x0010 - -std::string rsIdTypeToString(uint32_t idtype); - -class RsIdGroup -{ - public: - - - RsGroupMetaData mMeta; - - // In GroupMetaData. - //std::string mNickname; (mGroupName) - //std::string mKeyId; (mGroupId) - - uint32_t mIdType; - - std::string mGpgIdHash; // SHA(KeyId + Gpg Fingerprint) -> can only be IDed if GPG known. - - // NOTE: These cannot be transmitted as part of underlying messages.... - // Must use ServiceString. - bool mGpgIdKnown; // if GpgIdHash has been identified. - std::string mGpgId; // if known. - std::string mGpgName; // if known. - std::string mGpgEmail; // if known. -}; - - - -class RsIdMsg -{ - public: - - RsMsgMetaData mMeta; - - // In MsgMetaData. - //std::string mKeyId; (mGroupId) - //std::string mPeerId; (mAuthorId) ??? - - int mOpinion; - double mReputation; - //int mRating; - //int mPeersRating; - //std::string mComment; -}; - - - -std::ostream &operator<<(std::ostream &out, const RsIdGroup &meta); -std::ostream &operator<<(std::ostream &out, const RsIdMsg &meta); - - - -#if 0 -class RsIdReputation -{ - public: - std::string mKeyId; - - int mYourRating; - int mPeersRating; - int mFofRating; - int mTotalRating; - - std::string mComment; -}; - -class RsIdOpinion -{ - public: - - std::string mKeyId; - std::string mPeerId; - - int mRating; - int mPeersRating; - std::string mComment; -}; - -#endif - - -class RsIdentityVEG: public RsTokenServiceVEG -{ - public: - - RsIdentityVEG() { return; } -virtual ~RsIdentityVEG() { return; } - - - /* INCLUDES INTERFACE FROM RS TOKEN SERVICE */ - ////////////////////////////////////////////////////////////////////////////// - - - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsIdGroup &group) = 0; -virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg) = 0; - -virtual bool createGroup(uint32_t &token, RsIdGroup &group, bool isNew) = 0; -virtual bool createMsg(uint32_t &token, RsIdMsg &msg, bool isNew) = 0; - - /* In the Identity System - You don't access the Messages Directly. - * as they represent idividuals opinions.... - * This is reflected in the TokenService calls returning false. - * - * Below is the additional interface to look at reputation. - */ - - /* So we will want to cache much of the identity stuff, so that we have quick access to the results. - * The following bits of data will not use the request/response interface, and should be available immediately. - * - * ID => Nickname, knownGPG, reputation. - * - * This will require quite a bit of data... - * 20 Bytes + 50 + 1 + 4 Bytes? (< 100 Bytes). - * x 10,000 IDs. => ~1 MB of cache (Good). - * x 100,000 IDs. => ~10 MB of cache (Good). - * x 1,000,000 IDs. => ~100 MB of cache (Too Big). - * - * We also need to store quick access to your OwnIds. - */ - -//virtual uint32_t getIdDetails(const std::string &id, std::string &nickname, bool &isGpgKnown, -// uint32_t &ownOpinion, float &reputation); -//virtual uint32_t getOwnIds(std::list &ownIds); -//virtual bool setOpinion(const std::string &id, uint32_t opinion); - - -virtual void generateDummyData() = 0; - -#if 0 - - /* Data Requests */ -virtual bool requestIdentityList(uint32_t &token) = 0; -virtual bool requestIdentities(uint32_t &token, const std::list &ids) = 0; -virtual bool requestIdReputations(uint32_t &token, const std::list &ids) = 0; -virtual bool requestIdPeerOpinion(uint32_t &token, const std::string &aboutId, const std::string &peerId) = 0; -//virtual bool requestIdGpgDetails(uint32_t &token, const std::list &ids) = 0; - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token) = 0; - - /* Retrieve Data */ -virtual bool getIdentityList(const uint32_t token, std::list &ids) = 0; -virtual bool getIdentity(const uint32_t token, RsIdData &data) = 0; -virtual bool getIdReputation(const uint32_t token, RsIdReputation &reputation) = 0; -virtual bool getIdPeerOpinion(const uint32_t token, RsIdOpinion &opinion) = 0; - - /* Updates */ -virtual bool updateIdentity(RsIdData &data) = 0; -virtual bool updateOpinion(RsIdOpinion &opinion) = 0; - -#endif - -}; - - - -#endif diff --git a/libretroshare/src/retroshare/rswikiVEG.h b/libretroshare/src/retroshare/rswikiVEG.h deleted file mode 100644 index 8431ee3d8..000000000 --- a/libretroshare/src/retroshare/rswikiVEG.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef RETROSHARE_WIKI_VEG_GUI_INTERFACE_H -#define RETROSHARE_WIKI_VEG_GUI_INTERFACE_H - -/* - * libretroshare/src/retroshare: rswiki.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 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 -#include -#include - -#include - -/* The Main Interface Class - for information about your Peers */ -class RsWikiVEG; -extern RsWikiVEG *rsWikiVEG; - -class RsWikiGroupShare -{ - public: - - uint32_t mShareType; - std::string mShareGroupId; - std::string mPublishKey; - uint32_t mCommentMode; - uint32_t mResizeMode; -}; - -class RsWikiGroup -{ - public: - - RsGroupMetaData mMeta; - - //std::string mGroupId; - //std::string mName; - - std::string mDescription; - std::string mCategory; - - std::string mHashTags; - - RsWikiGroupShare mShareOptions; -}; - -class RsWikiPage -{ - public: - - RsMsgMetaData mMeta; - - // IN META DATA. - //std::string mGroupId; - //std::string mOrigPageId; - //std::string mPageId; - //std::string mName; - - // WE SHOULD SWITCH TO USING THREAD/PARENT IDS HERE.... - std::string mPrevId; - - std::string mPage; // all the text is stored here. - - std::string mHashTags; -}; - -class RsWikiVEG: public RsTokenServiceVEG -{ - public: - - RsWikiVEG() { return; } -virtual ~RsWikiVEG() { return; } - - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group) = 0; -virtual bool getMsgData(const uint32_t &token, RsWikiPage &page) = 0; - -virtual bool createGroup(uint32_t &token, RsWikiGroup &group, bool isNew) = 0; -virtual bool createPage(uint32_t &token, RsWikiPage &page, bool isNew) = 0; - - -}; - - - -#endif diff --git a/libretroshare/src/retroshare/rswireVEG.h b/libretroshare/src/retroshare/rswire.h similarity index 62% rename from libretroshare/src/retroshare/rswireVEG.h rename to libretroshare/src/retroshare/rswire.h index 314e8dc1c..d30b496fa 100644 --- a/libretroshare/src/retroshare/rswireVEG.h +++ b/libretroshare/src/retroshare/rswire.h @@ -30,38 +30,20 @@ #include #include -#include +#include "gxs/rstokenservice.h" +#include "gxs/rsgxsifaceimpl.h" + /* The Main Interface Class - for information about your Peers */ -class RsWireVEG; -extern RsWireVEG *rsWireVEG; - -class RsWireGroupShare -{ - public: - - uint32_t mShareType; - std::string mShareGroupId; - std::string mPublishKey; - uint32_t mCommentMode; - uint32_t mResizeMode; -}; +class RsWire; +extern RsWire *rsWire; class RsWireGroup { public: RsGroupMetaData mMeta; - - //std::string mGroupId; - //std::string mName; - std::string mDescription; - std::string mCategory; - - std::string mHashTags; - - RsWireGroupShare mShareOptions; }; @@ -102,46 +84,40 @@ class RsWirePulse RsMsgMetaData mMeta; - //std::string mGroupId; - //std::string mOrigPageId; - //std::string mPrevId; - //std::string mPageId; - //std::string mName; + std::string mPulseText; // all the text is stored here. + std::string mHashTags; - std::string mPulse; // all the text is stored here. +// These will be added at some point. +// std::string mInReplyPulse; - std::string mInReplyPulse; +// uint32_t mPulseFlags; - uint32_t mPulseFlags; +// std::list mMentions; +// std::list mHashTags; +// std::list mUrls; - std::list mMentions; - std::list mHashTags; - std::list mUrls; - - RsWirePlace mPlace; +// RsWirePlace mPlace; }; +std::ostream &operator<<(std::ostream &out, const RsWireGroup &group); +std::ostream &operator<<(std::ostream &out, const RsWirePulse &pulse); - -class RsWireVEG: public RsTokenServiceVEG +class RsWire: public RsGxsIfaceImpl { public: - RsWireVEG() { return; } -virtual ~RsWireVEG() { return; } + RsWire(RsGenExchange *gxs): RsGxsIfaceImpl(gxs) { return; } +virtual ~RsWire() { return; } /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsWireGroup &group) = 0; -virtual bool getMsgData(const uint32_t &token, RsWirePulse &pulse) = 0; +virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; +virtual bool getPulseData(const uint32_t &token, std::vector &pulses) = 0; - /* Create Stuff */ -virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew) = 0; -virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew) = 0; +virtual bool createGroup(uint32_t &token, RsWireGroup &group) = 0; +virtual bool createPulse(uint32_t &token, RsWirePulse &pulse) = 0; }; - - #endif diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index eb353f7a7..874f60f24 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1829,12 +1829,7 @@ RsTurtle *rsTurtle = NULL ; #include "services/p3posted.h" #include "services/p3photoservice.h" #include "services/p3gxsforums.h" - -// Not too many to convert now! -#include "services/p3wikiserviceVEG.h" -#include "services/p3wireVEG.h" -//#include "services/p3idserviceVEG.h" -//#include "services/p3forumsVEG.h" +#include "services/p3wire.h" #endif #ifndef PQI_DISABLE_TUNNEL @@ -2284,7 +2279,8 @@ int RsServer::StartupRetroShare() // empty and matches an exist directory location // the given ssl user id then this directory is cleaned // and deleted - std::string priorGxsDir = "./" + mLinkMgr->getOwnId() + "/", currGxsDir = RsInitConfig::configDir + "/GXS_phase1"; + std::string priorGxsDir = "./" + mLinkMgr->getOwnId() + "/"; + std::string currGxsDir = RsInitConfig::configDir + "/GXS_phase1"; bool cleanUpGxsDir = false; if(!priorGxsDir.empty()) @@ -2298,21 +2294,6 @@ int RsServer::StartupRetroShare() else rmdir(priorGxsDir.c_str()); - RsDirUtil::checkCreateDirectory(currGxsDir); - - // Testing New Cache Services. - //p3WikiServiceVEG *mWikis = new p3WikiServiceVEG(RS_SERVICE_GXSV1_TYPE_WIKI); - //pqih -> addService(mWikis); - - // Testing New Cache Services. - p3WireVEG *mWire = new p3WireVEG(RS_SERVICE_GXSV1_TYPE_WIRE); - pqih -> addService(mWire); - - // Testing New Cache Services. - //p3ForumsVEG *mForumsV2 = new p3ForumsVEG(RS_SERVICE_GXSV1_TYPE_FORUMS); - //pqih -> addService(mForumsV2); - - // TODO: temporary to store GXS service data, remove RsDirUtil::checkCreateDirectory(currGxsDir); @@ -2339,7 +2320,6 @@ int RsServer::StartupRetroShare() /**** Photo service ****/ // create photo authentication policy - uint32_t photoAuthenPolicy = 0; uint8_t flag = 0; @@ -2404,6 +2384,23 @@ int RsServer::StartupRetroShare() RsGxsNetService* wiki_ns = new RsGxsNetService( RS_SERVICE_GXSV1_TYPE_WIKI, wiki_ds, nxsMgr, mWiki); + + /**** Wire GXS service ****/ + + p3Wire *mWire = NULL; + + RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db", + RS_SERVICE_GXSV1_TYPE_WIRE); + + wire_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing + + mWire = new p3Wire(wire_ds, NULL); + + // create GXS photo service + RsGxsNetService* wire_ns = new RsGxsNetService( + RS_SERVICE_GXSV1_TYPE_WIRE, wire_ds, nxsMgr, mWire); + + /**** Forum GXS service ****/ p3GxsForums *mGxsForums = NULL; @@ -2425,19 +2422,13 @@ int RsServer::StartupRetroShare() #ifdef ENABLE_GXS_CORE /*** start up GXS core runner ***/ - -// GxsCoreServer* mGxsCore = new GxsCoreServer(); - //mGxsCore->addService(mGxsIdService); #if ENABLE_OTHER_GXS_SERVICES createThread(*mGxsIdService); createThread(*mPhoto); createThread(*mPosted); createThread(*mWiki); + createThread(*mWire); createThread(*mGxsForums); -// -// mGxsCore->addService(mPhoto); -// mGxsCore->addService(mPosted); -// mGxsCore->addService(mWiki); #endif // cores ready start up GXS net servers @@ -2446,6 +2437,7 @@ int RsServer::StartupRetroShare() createThread(*photo_ns); createThread(*posted_ns); createThread(*wiki_ns); + createThread(*wire_ns); createThread(*gxsforums_ns); #endif @@ -2458,8 +2450,6 @@ int RsServer::StartupRetroShare() pqih->addService(gxsforums_ns); #endif - // start up gxs core server - //createThread(*mGxsCore); #endif @@ -2728,10 +2718,9 @@ int RsServer::StartupRetroShare() rsPosted = mPosted; rsPhoto = mPhoto; rsGxsForums = mGxsForums; + rsWire = mWire; #endif - rsWireVEG = mWire; - //rsForumsVEG = mForumsV2; #endif // ENABLE_GXS_SERVICES @@ -2748,7 +2737,6 @@ int RsServer::StartupRetroShare() rsGameLauncher = NULL; #endif - /* put a welcome message in! */ if (RsInitConfig::firsttime_run) { diff --git a/libretroshare/src/serialiser/rswikiitems.cc b/libretroshare/src/serialiser/rswikiitems.cc index 56d20bb6b..66c7f9309 100644 --- a/libretroshare/src/serialiser/rswikiitems.cc +++ b/libretroshare/src/serialiser/rswikiitems.cc @@ -198,7 +198,7 @@ bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem #ifdef GXSID_DEBUG if (!ok) { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsIdcollectionItem() NOK" << std::endl; + std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl; } #endif @@ -354,7 +354,7 @@ bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *it #ifdef GXSID_DEBUG if (!ok) { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; + std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl; } #endif @@ -502,7 +502,7 @@ bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item #ifdef GXSID_DEBUG if (!ok) { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; + std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl; } #endif diff --git a/libretroshare/src/serialiser/rswikiitems.h b/libretroshare/src/serialiser/rswikiitems.h index 2b356c400..4b57c968d 100644 --- a/libretroshare/src/serialiser/rswikiitems.h +++ b/libretroshare/src/serialiser/rswikiitems.h @@ -7,7 +7,7 @@ * * 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. + * 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 diff --git a/libretroshare/src/serialiser/rswireitems.cc b/libretroshare/src/serialiser/rswireitems.cc new file mode 100644 index 000000000..068499bf8 --- /dev/null +++ b/libretroshare/src/serialiser/rswireitems.cc @@ -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 + +#include "rswireitems.h" +#include "serialiser/rstlvbase.h" +#include "serialiser/rsbaseserial.h" + +#define WIRE_DEBUG 1 + + +uint32_t RsGxsWireSerialiser::size(RsItem *item) +{ + RsGxsWireGroupItem* grp_item = NULL; + RsGxsWirePulseItem* snap_item = NULL; + + if((grp_item = dynamic_cast(item)) != NULL) + { + return sizeGxsWireGroupItem(grp_item); + } + else if((snap_item = dynamic_cast(item)) != NULL) + { + return sizeGxsWirePulseItem(snap_item); + } + return NULL; +} + +bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size) +{ + RsGxsWireGroupItem* grp_item = NULL; + RsGxsWirePulseItem* snap_item = NULL; + + if((grp_item = dynamic_cast(item)) != NULL) + { + return serialiseGxsWireGroupItem(grp_item, data, size); + } + else if((snap_item = dynamic_cast(item)) != NULL) + { + return serialiseGxsWirePulseItem(snap_item, data, size); + } + return false; +} + +RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size) +{ + +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::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_WIRE != getRsItemService(rstype))) + { + return NULL; /* wrong type */ + } + + switch(getRsItemSubType(rstype)) + { + + case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: + return deserialiseGxsWireGroupItem(data, size); + break; + case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: + return deserialiseGxsWirePulseItem(data, size); + break; + default: +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype"; + std::cerr << std::endl; +#endif + break; + } + return NULL; +} + + + +/*****************************************************************************************/ +/*****************************************************************************************/ +/*****************************************************************************************/ + + +void RsGxsWireGroupItem::clear() +{ + group.mDescription.clear(); +} + +std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent) +{ + printRsItemBase(out, "RsGxsWireGroupItem", indent); + uint16_t int_Indent = indent + 2; + + printIndent(out, int_Indent); + out << "Description: " << group.mDescription << std::endl; + + printRsItemEnd(out ,"RsGxsWireGroupItem", indent); + return out; +} + + +uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item) +{ + + const RsWireGroup& group = item->group; + uint32_t s = 8; // header + + s += GetTlvStringSize(group.mDescription); + + return s; +} + +bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size) +{ + +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl; +#endif + + uint32_t tlvsize = sizeGxsWireGroupItem(item); + uint32_t offset = 0; + + if(*size < tlvsize) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl; +#endif + return false; + } + + *size = tlvsize; + + bool ok = true; + + ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); + + /* skip the header */ + offset += 8; + + /* GxsWireGroupItem */ + ok &= SetTlvString(data, tlvsize, &offset, 1, item->group.mDescription); + + if(offset != tlvsize) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl; +#endif + ok = false; + } + +#ifdef WIRE_DEBUG + if (!ok) + { + std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl; + } +#endif + + return ok; + } + +RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size) +{ + +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << 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_WIRE != getRsItemService(rstype)) || + (RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype))) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl; +#endif + return NULL; /* wrong type */ + } + + if (*size < rssize) /* check size */ + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl; +#endif + return NULL; /* not enough data */ + } + + /* set the packet length */ + *size = rssize; + + bool ok = true; + + RsGxsWireGroupItem* item = new RsGxsWireGroupItem(); + /* skip the header */ + offset += 8; + + ok &= GetTlvString(data, rssize, &offset, 1, item->group.mDescription); + + if (offset != rssize) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl; +#endif + /* error */ + delete item; + return NULL; + } + + if (!ok) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl; +#endif + delete item; + return NULL; + } + + return item; +} + + + +/*****************************************************************************************/ +/*****************************************************************************************/ +/*****************************************************************************************/ + + +void RsGxsWirePulseItem::clear() +{ + pulse.mPulseText.clear(); + pulse.mHashTags.clear(); +} + +std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent) +{ + printRsItemBase(out, "RsGxsWirePulseItem", 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 ,"RsGxsWirePulseItem", indent); + return out; +} + + +uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item) +{ + + const RsWirePulse& pulse = item->pulse; + uint32_t s = 8; // header + + s += GetTlvStringSize(pulse.mPulseText); + s += GetTlvStringSize(pulse.mHashTags); + + return s; +} + +bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size) +{ + +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl; +#endif + + uint32_t tlvsize = sizeGxsWirePulseItem(item); + uint32_t offset = 0; + + if(*size < tlvsize) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl; +#endif + return false; + } + + *size = tlvsize; + + bool ok = true; + + ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); + + /* skip the header */ + offset += 8; + + /* GxsWirePulseItem */ + ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mPulseText); + ok &= SetTlvString(data, tlvsize, &offset, 1, item->pulse.mHashTags); + + if(offset != tlvsize) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl; +#endif + ok = false; + } + +#ifdef WIRE_DEBUG + if (!ok) + { + std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl; + } +#endif + + return ok; + } + +RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size) +{ + +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << 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_WIRE != getRsItemService(rstype)) || + (RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype))) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl; +#endif + return NULL; /* wrong type */ + } + + if (*size < rssize) /* check size */ + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl; +#endif + return NULL; /* not enough data */ + } + + /* set the packet length */ + *size = rssize; + + bool ok = true; + + RsGxsWirePulseItem* item = new RsGxsWirePulseItem(); + /* 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 WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl; +#endif + /* error */ + delete item; + return NULL; + } + + if (!ok) + { +#ifdef WIRE_DEBUG + std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl; +#endif + delete item; + return NULL; + } + + return item; +} + + +/*****************************************************************************************/ +/*****************************************************************************************/ +/*****************************************************************************************/ + diff --git a/libretroshare/src/serialiser/rswireitems.h b/libretroshare/src/serialiser/rswireitems.h new file mode 100644 index 000000000..c7dfc4f03 --- /dev/null +++ b/libretroshare/src/serialiser/rswireitems.h @@ -0,0 +1,93 @@ +/* + * libretroshare/src/serialiser: rswireitems.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_WIRE_ITEMS_H +#define RS_WIRE_ITEMS_H + +#include + +#include "serialiser/rsserviceids.h" +#include "serialiser/rsserial.h" +#include "serialiser/rstlvtypes.h" + +#include "rsgxsitems.h" +#include "retroshare/rswire.h" + +const uint8_t RS_PKT_SUBTYPE_WIRE_GROUP_ITEM = 0x02; +const uint8_t RS_PKT_SUBTYPE_WIRE_PULSE_ITEM = 0x03; + +class RsGxsWireGroupItem : public RsGxsGrpItem +{ + +public: + + RsGxsWireGroupItem(): RsGxsGrpItem(RS_SERVICE_GXSV1_TYPE_WIRE, + RS_PKT_SUBTYPE_WIRE_GROUP_ITEM) { return;} + virtual ~RsGxsWireGroupItem() { return;} + + void clear(); + std::ostream &print(std::ostream &out, uint16_t indent = 0); + + + RsWireGroup group; +}; + +class RsGxsWirePulseItem : public RsGxsMsgItem +{ +public: + + RsGxsWirePulseItem(): RsGxsMsgItem(RS_SERVICE_GXSV1_TYPE_WIRE, + RS_PKT_SUBTYPE_WIRE_PULSE_ITEM) {return; } + virtual ~RsGxsWirePulseItem() { return;} + void clear(); + std::ostream &print(std::ostream &out, uint16_t indent = 0); + RsWirePulse pulse; +}; + +class RsGxsWireSerialiser : public RsSerialType +{ +public: + + RsGxsWireSerialiser() + :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_GXSV1_TYPE_WIRE) + { return; } + virtual ~RsGxsWireSerialiser() { 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 sizeGxsWireGroupItem(RsGxsWireGroupItem *item); + bool serialiseGxsWireGroupItem (RsGxsWireGroupItem *item, void *data, uint32_t *size); + RsGxsWireGroupItem * deserialiseGxsWireGroupItem(void *data, uint32_t *size); + + uint32_t sizeGxsWirePulseItem(RsGxsWirePulseItem *item); + bool serialiseGxsWirePulseItem (RsGxsWirePulseItem *item, void *data, uint32_t *size); + RsGxsWirePulseItem * deserialiseGxsWirePulseItem(void *data, uint32_t *size); +}; + +#endif /* RS_WIKI_ITEMS_H */ diff --git a/libretroshare/src/services/p3forumsVEG.cc b/libretroshare/src/services/p3forumsVEG.cc deleted file mode 100644 index 2e3a81ceb..000000000 --- a/libretroshare/src/services/p3forumsVEG.cc +++ /dev/null @@ -1,805 +0,0 @@ -/* - * libretroshare/src/services p3forumsv2.cc - * - * ForumsV2 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". - * - */ - -#include "services/p3forumsVEG.h" - -#include "util/rsrandom.h" -#include - -/**** - * #define FORUMV2_DEBUG 1 - ****/ - -RsForumsVEG *rsForumsVEG = NULL; - - - -/********************************************************************************/ -/******************* Startup / Tick ******************************************/ -/********************************************************************************/ - -p3ForumsVEG::p3ForumsVEG(uint16_t type) - :p3GxsDataServiceVEG(type, new ForumDataProxy()), mForumMtx("p3ForumsV2"), mUpdated(true) -{ - { - RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/ - - mForumProxy = (ForumDataProxy *) mProxy; - } - - generateDummyData(); - - return; -} - - -int p3ForumsVEG::tick() -{ - //std::cerr << "p3ForumsVEG::tick()"; - //std::cerr << std::endl; - - fakeprocessrequests(); - - return 0; -} - -bool p3ForumsVEG::updated() -{ - RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/ - - if (mUpdated) - { - mUpdated = false; - return true; - } - return false; -} - - - - /* Data Requests */ -bool p3ForumsVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3ForumsVEG::requestGroupInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - return true; -} - -bool p3ForumsVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3ForumsVEG::requestMsgInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds); - - return true; -} - -bool p3ForumsVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds) -{ - generateToken(token); - std::cerr << "p3ForumsVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - /* Generic Lists */ -bool p3ForumsVEG::getGroupList( const uint32_t &token, std::list &groupIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3ForumsVEG::getGroupList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3ForumsVEG::getGroupList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3ForumsVEG::getGroupList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - - -bool p3ForumsVEG::getMsgList( const uint32_t &token, std::list &msgIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3ForumsVEG::getMsgList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3ForumsVEG::getMsgList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3ForumsVEG::getMsgList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - /* Generic Summary */ -bool p3ForumsVEG::getGroupSummary( const uint32_t &token, std::list &groupInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3ForumsVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3ForumsVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3ForumsVEG::getGroupSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list groupIds; - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsGroupMetaData */ - mProxy->getGroupSummary(groupIds, groupInfo); - - return ans; -} - -bool p3ForumsVEG::getMsgSummary( const uint32_t &token, std::list &msgInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3ForumsVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3ForumsVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3ForumsVEG::getMsgSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list msgIds; - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsMsgMetaData */ - mProxy->getMsgSummary(msgIds, msgInfo); - - return ans; -} - - - /* Specific Service Data */ -bool p3ForumsVEG::getGroupData(const uint32_t &token, RsForumV2Group &group) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3ForumsVEG::getGroupData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3ForumsVEG::getGroupData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3ForumsVEG::getGroupData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsForumAlbum */ - bool ans = mForumProxy->getForumGroup(id, group); - return ans; -} - - -bool p3ForumsVEG::getMsgData(const uint32_t &token, RsForumV2Msg &msg) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3ForumsVEG::getMsgData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3ForumsVEG::getMsgData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3ForumsVEG::getMsgData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsForumAlbum */ - bool ans = mForumProxy->getForumMsg(id, msg); - return ans; -} - - - - /* Poll */ -uint32_t p3ForumsVEG::requestStatus(const uint32_t token) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - return status; -} - - - /* Cancel Request */ -bool p3ForumsVEG::cancelRequest(const uint32_t &token) -{ - return clearRequest(token); -} - - ////////////////////////////////////////////////////////////////////////////// - -bool p3ForumsVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) -{ - return mForumProxy->setMessageStatus(msgId, status, statusMask); -} - -bool p3ForumsVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) -{ - return mForumProxy->setGroupStatus(groupId, status, statusMask); -} - -bool p3ForumsVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) -{ - return mForumProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); -} - -bool p3ForumsVEG::setMessageServiceString(const std::string &msgId, const std::string &str) -{ - return mForumProxy->setMessageServiceString(msgId, str); -} - -bool p3ForumsVEG::setGroupServiceString(const std::string &grpId, const std::string &str) -{ - return mForumProxy->setGroupServiceString(grpId, str); -} - - - -bool p3ForumsVEG::groupRestoreKeys(const std::string &groupId) -{ - return false; -} - -bool p3ForumsVEG::groupShareKeys(const std::string &groupId, std::list& peers) -{ - return false; -} - - - - -/********************************************************************************************/ - - -std::string p3ForumsVEG::genRandomId() -{ - std::string randomId; - for(int i = 0; i < 20; i++) - { - randomId += (char) ('a' + (RSRandom::random_u32() % 26)); - } - - return randomId; -} - -bool p3ForumsVEG::createGroup(uint32_t &token, RsForumV2Group &group, bool isNew) -{ - if (group.mMeta.mGroupId.empty()) - { - /* new photo */ - - /* generate a temp id */ - group.mMeta.mGroupId = genRandomId(); - } - else - { - std::cerr << "p3ForumsVEG::createGroup() Group with existing Id... dropping"; - std::cerr << std::endl; - return false; - } - - { - RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mForumProxy->addForumGroup(group); - } - - // Fake a request to return the GroupMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list groupIds; - groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. - - std::cerr << "p3ForumsVEG::createGroup() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - return true; -} - - - - -bool p3ForumsVEG::createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew) -{ - if (msg.mMeta.mGroupId.empty()) - { - /* new photo */ - std::cerr << "p3ForumsVEG::createForumMsg() Missing MsgID"; - std::cerr << std::endl; - return false; - } - - /* check if its a mod or new msg */ - if (msg.mMeta.mOrigMsgId.empty()) - { - std::cerr << "p3ForumsVEG::createForumMsg() New Msg"; - std::cerr << std::endl; - - /* new msg, generate a new OrigMsgId */ - msg.mMeta.mOrigMsgId = genRandomId(); - msg.mMeta.mMsgId = msg.mMeta.mOrigMsgId; - } - else - { - std::cerr << "p3ForumsVEG::createForumMsg() Modified Msg"; - std::cerr << std::endl; - - /* mod msg, keep orig msg id, generate a new MsgId */ - msg.mMeta.mMsgId = genRandomId(); - } - - std::cerr << "p3ForumsVEG::createForumMsg() GroupId: " << msg.mMeta.mGroupId; - std::cerr << std::endl; - std::cerr << "p3ForumsVEG::createForumMsg() MsgId: " << msg.mMeta.mMsgId; - std::cerr << std::endl; - std::cerr << "p3ForumsVEG::createForumMsg() OrigMsgId: " << msg.mMeta.mOrigMsgId; - std::cerr << std::endl; - - { - RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mForumProxy->addForumMsg(msg); - } - - // Fake a request to return the MsgMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list msgIds; - msgIds.push_back(msg.mMeta.mMsgId); // It will just return this one. - - std::cerr << "p3ForumsVEG::createMsg() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - - -/********************************************************************************************/ - - -bool ForumDataProxy::getForumGroup(const std::string &id, RsForumV2Group &group) -{ - void *groupData = NULL; - RsGroupMetaData meta; - if (getGroupData(id, groupData) && getGroupSummary(id, meta)) - { - RsForumV2Group *pG = (RsForumV2Group *) groupData; - group = *pG; - - // update definitive version of the metadata. - group.mMeta = meta; - - std::cerr << "ForumDataProxy::getForumGroup() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << groupData; - std::cerr << std::endl; - return true; - } - - std::cerr << "ForumDataProxy::getForumGroup() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool ForumDataProxy::getForumMsg(const std::string &id, RsForumV2Msg &page) -{ - void *msgData = NULL; - RsMsgMetaData meta; - if (getMsgData(id, msgData) && getMsgSummary(id, meta)) - { - RsForumV2Msg *pP = (RsForumV2Msg *) msgData; - // Shallow copy of thumbnail. - page = *pP; - - // update definitive version of the metadata. - page.mMeta = meta; - - std::cerr << "ForumDataProxy::getForumMsg() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << msgData; - std::cerr << std::endl; - return true; - } - - std::cerr << "ForumDataProxy::getForumMsg() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool ForumDataProxy::addForumGroup(const RsForumV2Group &group) -{ - // Make duplicate. - RsForumV2Group *pG = new RsForumV2Group(); - *pG = group; - - std::cerr << "ForumDataProxy::addForumGroup()"; - std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG; - std::cerr << std::endl; - - return createGroup(pG); -} - - -bool ForumDataProxy::addForumMsg(const RsForumV2Msg &msg) -{ - // Make duplicate. - RsForumV2Msg *pM = new RsForumV2Msg(); - *pM = msg; - - std::cerr << "ForumDataProxy::addForumMsg()"; - std::cerr << " MetaData: " << pM->mMeta << " DataPointer: " << pM; - std::cerr << std::endl; - - return createMsg(pM); -} - - - - /* These Functions must be overloaded to complete the service */ -bool ForumDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta) -{ - RsForumV2Group *group = (RsForumV2Group *) groupData; - meta = group->mMeta; - - return true; -} - -bool ForumDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta) -{ - RsForumV2Msg *page = (RsForumV2Msg *) msgData; - meta = page->mMeta; - - return true; -} - - -/********************************************************************************************/ - - - -bool p3ForumsVEG::generateDummyData() -{ - /* so we want to generate 100's of forums */ -#define MAX_FORUMS 10 //100 -#define MAX_THREADS 10 //1000 -#define MAX_MSGS 100 //10000 - - std::list mGroups; - std::list::iterator git; - - std::list mMsgs; - std::list::iterator mit; - -#define DUMMY_NAME_MAX_LEN 10000 - char name[DUMMY_NAME_MAX_LEN]; - int i, j; - time_t now = time(NULL); - - for(i = 0; i < MAX_FORUMS; i++) - { - /* generate a new forum */ - RsForumV2Group forum; - - /* generate a temp id */ - forum.mMeta.mGroupId = genRandomId(); - - snprintf(name, DUMMY_NAME_MAX_LEN, "TestForum_%d", i+1); - - forum.mMeta.mGroupId = genRandomId(); - forum.mMeta.mGroupName = name; - - forum.mMeta.mPublishTs = now - (RSRandom::random_f32() * 100000); - /* key fields to fill in: - * GroupId. - * Name. - * Flags. - * Pop. - */ - - - - /* use probability to decide which are subscribed / own / popularity. - */ - - float rnd = RSRandom::random_f32(); - if (rnd < 0.1) - { - forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN; - - } - else if (rnd < 0.3) - { - forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; - } - else - { - forum.mMeta.mSubscribeFlags = 0; - } - - forum.mMeta.mPop = (int) (RSRandom::random_f32() * 10.0); - - mGroups.push_back(forum); - - - //std::cerr << "p3ForumsVEG::generateDummyData() Generated Forum: " << forum.mMeta; - //std::cerr << std::endl; - } - - - for(i = 0; i < MAX_THREADS; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsForumV2Group head = mGroups.front(); - mGroups.pop_front(); - mGroups.push_back(head); - } - - RsForumV2Group forum = mGroups.front(); - - /* now create a new thread */ - - RsForumV2Msg msg; - - /* fill in key data - * GroupId - * MsgId - * OrigMsgId - * ThreadId - * ParentId - * PublishTS (take Forum TS + a bit ). - * - * ChildTS ???? - */ - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => ThreadMsg_%d", forum.mMeta.mGroupName.c_str(), i+1); - msg.mMeta.mMsgName = name; - - msg.mMeta.mGroupId = forum.mMeta.mGroupId; - msg.mMeta.mMsgId = genRandomId(); - msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId; - msg.mMeta.mThreadId = msg.mMeta.mMsgId; - msg.mMeta.mParentId = ""; - - msg.mMeta.mPublishTs = forum.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (msg.mMeta.mPublishTs > now) - msg.mMeta.mPublishTs = now - 1; - - mMsgs.push_back(msg); - - //std::cerr << "p3ForumsVEG::generateDummyData() Generated Thread: " << msg.mMeta; - //std::cerr << std::endl; - - } - - for(i = 0; i < MAX_MSGS; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsForumV2Msg head = mMsgs.front(); - mMsgs.pop_front(); - mMsgs.push_back(head); - } - - RsForumV2Msg parent = mMsgs.front(); - - /* now create a new child msg */ - - RsForumV2Msg msg; - - /* fill in key data - * GroupId - * MsgId - * OrigMsgId - * ThreadId - * ParentId - * PublishTS (take Forum TS + a bit ). - * - * ChildTS ???? - */ - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Msg_%d", parent.mMeta.mMsgName.c_str(), i+1); - msg.mMeta.mMsgName = name; - msg.mMsg = name; - - msg.mMeta.mGroupId = parent.mMeta.mGroupId; - msg.mMeta.mMsgId = genRandomId(); - msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId; - msg.mMeta.mThreadId = parent.mMeta.mThreadId; - msg.mMeta.mParentId = parent.mMeta.mOrigMsgId; - - msg.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (msg.mMeta.mPublishTs > now) - msg.mMeta.mPublishTs = now - 1; - - mMsgs.push_back(msg); - - //std::cerr << "p3ForumsVEG::generateDummyData() Generated Child Msg: " << msg.mMeta; - //std::cerr << std::endl; - - } - - - mUpdated = true; - - /* Then - at the end, we push them all into the Proxy */ - for(git = mGroups.begin(); git != mGroups.end(); git++) - { - /* pushback */ - mForumProxy->addForumGroup(*git); - - } - - for(mit = mMsgs.begin(); mit != mMsgs.end(); mit++) - { - /* pushback */ - mForumProxy->addForumMsg(*mit); - } - - return true; -} - diff --git a/libretroshare/src/services/p3forumsVEG.h b/libretroshare/src/services/p3forumsVEG.h deleted file mode 100644 index 4bf01a5b1..000000000 --- a/libretroshare/src/services/p3forumsVEG.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * libretroshare/src/services: p3forumsv2.h - * - * Wiki 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 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_FORUMSV2_SERVICE_HEADER -#define P3_FORUMSV2_SERVICE_HEADER - -#include "services/p3gxsserviceVEG.h" - -#include "retroshare/rsforumsVEG.h" - -#include -#include - -/* - * - */ - -class ForumDataProxy: public GxsDataProxyVEG -{ - public: - - bool getForumGroup(const std::string &id, RsForumV2Group &group); - bool getForumMsg(const std::string &id, RsForumV2Msg &msg); - - bool addForumGroup(const RsForumV2Group &group); - bool addForumMsg(const RsForumV2Msg &msg); - - /* These Functions must be overloaded to complete the service */ -virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta); -virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta); - -}; - - - - - -class p3ForumsVEG: public p3GxsDataServiceVEG, public RsForumsVEG -{ - public: - - p3ForumsVEG(uint16_t type); - -virtual int tick(); - - public: - - -virtual bool updated(); - - - /* Data Requests */ -virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds); - - /* Generic Lists */ -virtual bool getGroupList( const uint32_t &token, std::list &groupIds); -virtual bool getMsgList( const uint32_t &token, std::list &msgIds); - - /* Generic Summary */ -virtual bool getGroupSummary( const uint32_t &token, std::list &groupInfo); -virtual bool getMsgSummary( const uint32_t &token, std::list &msgInfo); - - /* Actual Data -> specific to Interface */ - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group); -virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg); - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token); - - /* Cancel Request */ -virtual bool cancelRequest(const uint32_t &token); - - ////////////////////////////////////////////////////////////////////////////// -virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); -virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); -virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); - -virtual bool groupRestoreKeys(const std::string &groupId); -virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - -virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew); -virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew); - - private: - -std::string genRandomId(); -bool generateDummyData(); - - ForumDataProxy *mForumProxy; - - RsMutex mForumMtx; - - /***** below here is locked *****/ - - bool mUpdated; - -}; - -#endif diff --git a/libretroshare/src/services/p3idserviceVEG.cc b/libretroshare/src/services/p3idserviceVEG.cc deleted file mode 100644 index 27b16a6a4..000000000 --- a/libretroshare/src/services/p3idserviceVEG.cc +++ /dev/null @@ -1,1552 +0,0 @@ -/* - * libretroshare/src/services p3idservice.cc - * - * Id 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". - * - */ - -#include "services/p3idserviceVEG.h" - -#include "util/rsrandom.h" -#include -#include -#include - -/**** - * #define ID_DEBUG 1 - ****/ - -#define ID_REQUEST_LIST 0x0001 -#define ID_REQUEST_IDENTITY 0x0002 -#define ID_REQUEST_REPUTATION 0x0003 -#define ID_REQUEST_OPINION 0x0004 - -RsIdentityVEG *rsIdentityVEG = NULL; - - -/********************************************************************************/ -/******************* Startup / Tick ******************************************/ -/********************************************************************************/ - -p3IdServiceVEG::p3IdServiceVEG(uint16_t type) - :p3GxsDataServiceVEG(type, new IdDataProxy()), mIdMtx("p3IdService"), mUpdated(true) -{ - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - mIdProxy = (IdDataProxy *) mProxy; - return; -} - - -int p3IdServiceVEG::tick() -{ - //std::cerr << "p3IdServiceVEG::tick()"; - //std::cerr << std::endl; - - fakeprocessrequests(); - // Disable for now. - // background_tick(); - - return 0; -} - -bool p3IdServiceVEG::updated() -{ - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - if (mUpdated) - { - mUpdated = false; - return true; - } - return false; -} - - - - /* Data Requests */ -bool p3IdServiceVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3IdServiceVEG::requestGroupInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - return true; -} - -bool p3IdServiceVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3IdServiceVEG::requestMsgInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds); - - return true; -} - -bool p3IdServiceVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds) -{ - generateToken(token); - std::cerr << "p3IdServiceVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - /* Generic Lists */ -bool p3IdServiceVEG::getGroupList( const uint32_t &token, std::list &groupIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3IdServiceVEG::getGroupList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3IdServiceVEG::getGroupList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3IdServiceVEG::getGroupList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - - -bool p3IdServiceVEG::getMsgList( const uint32_t &token, std::list &msgIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3IdServiceVEG::getMsgList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3IdServiceVEG::getMsgList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3IdServiceVEG::getMsgList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - /* Generic Summary */ -bool p3IdServiceVEG::getGroupSummary( const uint32_t &token, std::list &groupInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3IdServiceVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3IdServiceVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3IdServiceVEG::getGroupSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list groupIds; - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsGroupMetaData */ - mProxy->getGroupSummary(groupIds, groupInfo); - - return ans; -} - -bool p3IdServiceVEG::getMsgSummary( const uint32_t &token, std::list &msgInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3IdServiceVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3IdServiceVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3IdServiceVEG::getMsgSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list msgIds; - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsMsgMetaData */ - mProxy->getMsgSummary(msgIds, msgInfo); - - return ans; -} - - - /* Specific Service Data */ -bool p3IdServiceVEG::getGroupData(const uint32_t &token, RsIdGroup &group) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3IdServiceVEG::getGroupData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3IdServiceVEG::getGroupData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3IdServiceVEG::getGroupData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsIdGroup */ - bool ans = mIdProxy->getGroup(id, group); - return ans; -} - - -bool p3IdServiceVEG::getMsgData(const uint32_t &token, RsIdMsg &msg) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3IdServiceVEG::getMsgData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3IdServiceVEG::getMsgData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3IdServiceVEG::getMsgData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsIdMsg */ - bool ans = mIdProxy->getMsg(id, msg); - return ans; -} - - - - /* Poll */ -uint32_t p3IdServiceVEG::requestStatus(const uint32_t token) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - return status; -} - - - /* Cancel Request */ -bool p3IdServiceVEG::cancelRequest(const uint32_t &token) -{ - return clearRequest(token); -} - - ////////////////////////////////////////////////////////////////////////////// -bool p3IdServiceVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) -{ - return mIdProxy->setMessageStatus(msgId, status, statusMask); -} - -bool p3IdServiceVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) -{ - return mIdProxy->setGroupStatus(groupId, status, statusMask); -} - -bool p3IdServiceVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) -{ - return mIdProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); -} - -bool p3IdServiceVEG::setMessageServiceString(const std::string &msgId, const std::string &str) -{ - return mIdProxy->setMessageServiceString(msgId, str); -} - -bool p3IdServiceVEG::setGroupServiceString(const std::string &grpId, const std::string &str) -{ - return mIdProxy->setGroupServiceString(grpId, str); -} - - -bool p3IdServiceVEG::groupRestoreKeys(const std::string &groupId) -{ - return false; -} - -bool p3IdServiceVEG::groupShareKeys(const std::string &groupId, std::list& peers) -{ - return false; -} - - -/********************************************************************************************/ - - -std::string p3IdServiceVEG::genRandomId() -{ - std::string randomId; - for(int i = 0; i < 20; i++) - { - randomId += (char) ('a' + (RSRandom::random_u32() % 26)); - } - - return randomId; -} - -bool p3IdServiceVEG::createGroup(uint32_t &token, RsIdGroup &group, bool isNew) -{ - if (group.mMeta.mGroupId.empty()) - { - /* new photo */ - - /* generate a temp id */ - group.mMeta.mGroupId = genRandomId(); - } - else - { - std::cerr << "p3IdServiceVEG::createGroup() Group with existing Id... dropping"; - std::cerr << std::endl; - return false; - } - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mIdProxy->addGroup(group); - } - - // Fake a request to return the GroupMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list groupIds; - groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. - - std::cerr << "p3IdServiceVEG::createGroup() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - - return true; -} - - - - -bool p3IdServiceVEG::createMsg(uint32_t &token, RsIdMsg &msg, bool isNew) -{ - if (msg.mMeta.mGroupId.empty()) - { - /* new photo */ - std::cerr << "p3IdServiceVEG::createMsg() Missing MsgID"; - std::cerr << std::endl; - return false; - } - - /* check if its a mod or new msg */ - if (msg.mMeta.mOrigMsgId.empty()) - { - std::cerr << "p3IdServiceVEG::createMsg() New Msg"; - std::cerr << std::endl; - - /* new msg, generate a new OrigMsgId */ - msg.mMeta.mOrigMsgId = genRandomId(); - msg.mMeta.mMsgId = msg.mMeta.mOrigMsgId; - } - else - { - std::cerr << "p3IdServiceVEG::createMsg() Modified Msg"; - std::cerr << std::endl; - - /* mod msg, keep orig msg id, generate a new MsgId */ - msg.mMeta.mMsgId = genRandomId(); - } - - std::cerr << "p3IdServiceVEG::createMsg() GroupId: " << msg.mMeta.mGroupId; - std::cerr << std::endl; - std::cerr << "p3IdServiceVEG::createMsg() MsgId: " << msg.mMeta.mMsgId; - std::cerr << std::endl; - std::cerr << "p3IdServiceVEG::createMsg() OrigMsgId: " << msg.mMeta.mOrigMsgId; - std::cerr << std::endl; - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mIdProxy->addMsg(msg); - } - - // Fake a request to return the MsgMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list msgIds; - msgIds.push_back(msg.mMeta.mMsgId); // It will just return this one. - - std::cerr << "p3IdServiceVEG::createMsg() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - - -/********************************************************************************************/ - - - -bool IdDataProxy::getGroup(const std::string &id, RsIdGroup &group) -{ - void *groupData = NULL; - RsGroupMetaData meta; - if (getGroupData(id, groupData) && getGroupSummary(id, meta)) - { - RsIdGroup *pG = (RsIdGroup *) groupData; - group = *pG; - - // update definitive version of the metadata. - group.mMeta = meta; - - std::cerr << "IdDataProxy::getGroup() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << groupData; - std::cerr << std::endl; - return true; - } - - std::cerr << "IdDataProxy::getGroup() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool IdDataProxy::getMsg(const std::string &id, RsIdMsg &msg) -{ - void *msgData = NULL; - RsMsgMetaData meta; - if (getMsgData(id, msgData) && getMsgSummary(id, meta)) - { - RsIdMsg *pM = (RsIdMsg *) msgData; - // Shallow copy of thumbnail. - msg = *pM; - - // update definitive version of the metadata. - msg.mMeta = meta; - - std::cerr << "IdDataProxy::getMsg() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << msgData; - std::cerr << std::endl; - return true; - } - - std::cerr << "IdDataProxy::getMsg() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool IdDataProxy::addGroup(const RsIdGroup &group) -{ - // Make duplicate. - RsIdGroup *pG = new RsIdGroup(); - *pG = group; - - std::cerr << "IdDataProxy::addGroup()"; - std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG; - std::cerr << std::endl; - - return createGroup(pG); -} - - -bool IdDataProxy::addMsg(const RsIdMsg &msg) -{ - // Make duplicate. - RsIdMsg *pM = new RsIdMsg(); - *pM = msg; - - std::cerr << "IdDataProxy::addMsg()"; - std::cerr << " MetaData: " << pM->mMeta << " DataPointer: " << pM; - std::cerr << std::endl; - - return createMsg(pM); -} - - - - /* These Functions must be overloaded to complete the service */ -bool IdDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta) -{ - RsIdGroup *group = (RsIdGroup *) groupData; - meta = group->mMeta; - - return true; -} - -bool IdDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta) -{ - RsIdMsg *page = (RsIdMsg *) msgData; - meta = page->mMeta; - - return true; -} - - - - -/************************************************************************************/ -/************************************************************************************/ -/************************************************************************************/ -/************************************************************************************/ -/************************************************************************************/ - -#if 0 - -/* details are updated */ -bool p3IdServiceVEG::updateIdentity(RsIdData &data) -{ - if (data.mKeyId.empty()) - { - /* new photo */ - - /* generate a temp id */ - data.mKeyId = genRandomId(); - - if (data.mIdType & RSID_TYPE_REALID) - { - data.mGpgIdHash = genRandomId(); - } - else - { - data.mGpgIdHash = ""; - } - - } - - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - - /* add / modify */ - mIds[data.mKeyId] = data; - - return true; -} - - - - -bool p3IdServiceVEG::updateOpinion(RsIdOpinion &opinion) -{ - if (opinion.mKeyId.empty()) - { - /* new photo */ - std::cerr << "p3IdServiceVEG::updateOpinion() Missing KeyId"; - std::cerr << std::endl; - return false; - } - - /* check if its a mod or new page */ - if (opinion.mPeerId.empty()) - { - std::cerr << "p3IdServiceVEG::updateOpinion() Missing PeerId"; - std::cerr << std::endl; - return false; - } - - std::cerr << "p3IdServiceVEG::updateOpinion() KeyId: " << opinion.mKeyId; - std::cerr << std::endl; - std::cerr << "p3IdServiceVEG::updateOpinion() PeerId: " << opinion.mPeerId; - std::cerr << std::endl; - - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - - std::map >::iterator it; - std::map::iterator oit; - - it = mOpinions.find(opinion.mKeyId); - if (it == mOpinions.end()) - { - std::map emptyMap; - mOpinions[opinion.mKeyId] = emptyMap; - - it = mOpinions.find(opinion.mKeyId); - } - - (it->second)[opinion.mPeerId] = opinion; - return true; -} - - -#endif - - - -void p3IdServiceVEG::generateDummyData() -{ - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - /* grab all the gpg ids... and make some ids */ - - std::list gpgids; - std::list::iterator it; - - rsPeers->getGPGAllList(gpgids); - - std::string ownId = rsPeers->getGPGOwnId(); - gpgids.push_back(ownId); - - int i; - for(it = gpgids.begin(); it != gpgids.end(); it++) - { - /* create one or two for each one */ - int nIds = 1 + (RSRandom::random_u32() % 2); - for(i = 0; i < nIds; i++) - { - RsIdGroup id; - - RsPeerDetails details; - - //id.mKeyId = genRandomId(); - id.mMeta.mGroupId = genRandomId(); - id.mIdType = RSID_TYPE_REALID; - id.mGpgIdHash = genRandomId(); - - if (rsPeers->getPeerDetails(*it, details)) - { - std::ostringstream out; - out << details.name << "_" << i + 1; - - //id.mNickname = out.str(); - id.mMeta.mGroupName = out.str(); - - id.mGpgIdKnown = true; - - id.mGpgId = *it; - id.mGpgName = details.name; - id.mGpgEmail = details.email; - - if (*it == ownId) - { - id.mIdType |= RSID_RELATION_YOURSELF; - } - else if (rsPeers->isGPGAccepted(*it)) - { - id.mIdType |= RSID_RELATION_FRIEND; - } - else - { - id.mIdType |= RSID_RELATION_OTHER; - } - - } - else - { - std::cerr << "p3IdServiceVEG::generateDummyData() missing" << std::endl; - std::cerr << std::endl; - - id.mIdType |= RSID_RELATION_OTHER; - //id.mNickname = genRandomId(); - id.mMeta.mGroupName = genRandomId(); - id.mGpgIdKnown = false; - } - - //mIds[id.mKeyId] = id; - mIdProxy->addGroup(id); - } - } - -#define MAX_RANDOM_GPGIDS 10 //1000 -#define MAX_RANDOM_PSEUDOIDS 50 //5000 - - int nFakeGPGs = (RSRandom::random_u32() % MAX_RANDOM_GPGIDS); - int nFakePseudoIds = (RSRandom::random_u32() % MAX_RANDOM_PSEUDOIDS); - - /* make some fake gpg ids */ - for(i = 0; i < nFakeGPGs; i++) - { - RsIdGroup id; - - RsPeerDetails details; - - //id.mKeyId = genRandomId(); - id.mMeta.mGroupId = genRandomId(); - id.mIdType = RSID_TYPE_REALID; - id.mGpgIdHash = genRandomId(); - - id.mIdType |= RSID_RELATION_OTHER; - //id.mNickname = genRandomId(); - id.mMeta.mGroupName = genRandomId(); - id.mGpgIdKnown = false; - id.mGpgId = ""; - id.mGpgName = ""; - id.mGpgEmail = ""; - - //mIds[id.mKeyId] = id; - mIdProxy->addGroup(id); - } - - /* make lots of pseudo ids */ - for(i = 0; i < nFakePseudoIds; i++) - { - RsIdGroup id; - - RsPeerDetails details; - - //id.mKeyId = genRandomId(); - id.mMeta.mGroupId = genRandomId(); - id.mIdType = RSID_TYPE_PSEUDONYM; - id.mGpgIdHash = ""; - - //id.mNickname = genRandomId(); - id.mMeta.mGroupName = genRandomId(); - id.mGpgIdKnown = false; - id.mGpgId = ""; - id.mGpgName = ""; - id.mGpgEmail = ""; - - //mIds[id.mKeyId] = id; - mIdProxy->addGroup(id); - } - - mUpdated = true; - - return; -} - - - -std::string rsIdTypeToString(uint32_t idtype) -{ - std::string str; - if (idtype & RSID_TYPE_REALID) - { - str += "GPGID "; - } - if (idtype & RSID_TYPE_PSEUDONYM) - { - str += "PSEUDO "; - } - if (idtype & RSID_RELATION_YOURSELF) - { - str += "YOURSELF "; - } - if (idtype & RSID_RELATION_FRIEND) - { - str += "FRIEND "; - } - if (idtype & RSID_RELATION_FOF) - { - str += "FOF "; - } - if (idtype & RSID_RELATION_OTHER) - { - str += "OTHER "; - } - if (idtype & RSID_RELATION_UNKNOWN) - { - str += "UNKNOWN "; - } - return str; -} - - - - - - - - -/************************************************************************************/ -/************************************************************************************/ -/************************************************************************************/ -/************************************************************************************/ - - -/* here we are running a background process that calculates the reputation scores - * for each of the IDs.... - * - * As this class will be extensively used by many other threads... it is best - * that we don't block at all. This should be in a background thread. - * Perhaps a generic method to handle this will be advisable.... but we do that later. - * - * To start with we will work from the Posted service. - * - * - * - * So Reputation.... - * Three components: - * 1) Your Opinion: Should override everything else. - * 2) Implicit Factors: Know the associated GPG Key. - * 3) Your Friends Opinions: - * 4) Your Friends Calculated Reputation Scores. - * - * Must make sure that there is no Feedback loop in the Reputation calculation. - * - * So: Our Score + Friends Scores => Local Reputation. - * Local Reputation + Friends Reputations => Final Reputation? - * - * Do we need to 'ignore' Non-scores? - * ---> This becomes like the "Best Comment" algorithm from Reddit... - * Use a statistical mechanism to work out a lower bound on Reputation. - * - * But what if your opinion is wrong?.... well likely your friends will - * get their messages and reply... you'll see the missing message - request it - check reputation etc. - * - * So we are going to have three different scores (Own, Peers, (the neighbour) Hood)... - * - * So next question, when do we need to incrementally calculate the score? - * .... how often do we need to recalculate everything -> this could lead to a flux of messages. - * - * - * - * MORE NOTES: - * - * The Opinion Messages will have to be signed by PGP or SSL Keys, to guarantee that we don't - * multiple votes per person... As the message system doesn't handle uniqueness in this respect, - * we might have to do FULL_CALC for everything - This bit TODO. - * - * This will make IdService quite different to the other GXS services. - */ - -/************************************************************************************/ -/* - * Processing Algorithm: - * - Grab all Groups which have received messages. - * (opt 1)-> grab latest msgs for each of these and process => score. - * (opt 2)-> try incremental system (people probably won't change opinions often -> just set them once) - * --> if not possible, fallback to full calculation. - * - * - */ - - -#define ID_BACKGROUND_PERIOD 60 - -int p3IdServiceVEG::background_tick() -{ - std::cerr << "p3IdServiceVEG::background_tick()"; - std::cerr << std::endl; - - // Run Background Stuff. - background_checkTokenRequest(); - - /* every minute - run a background check */ - time_t now = time(NULL); - bool doCheck = false; - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - if (now - mLastBgCheck > ID_BACKGROUND_PERIOD) - { - doCheck = true; - mLastBgCheck = now; - } - } - - if (doCheck) - { - //addExtraDummyData(); - background_requestGroups(); - } - - - - // Add in new votes + comments. - return 0; -} - - - - -/***** Background Processing **** - * - * Process Each Message - as it arrives. - * - * Update - * - */ -#define ID_BG_IDLE 0 -#define ID_BG_REQUEST_GROUPS 1 -#define ID_BG_REQUEST_UNPROCESSED 2 -#define ID_BG_REQUEST_FULLCALC 3 - -bool p3IdServiceVEG::background_checkTokenRequest() -{ - uint32_t token = 0; - uint32_t phase = 0; - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - if (!mBgProcessing) - { - return false; - } - - token = mBgToken; - phase = mBgPhase; - } - - - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (status == GXS_REQUEST_STATUS_COMPLETE) - { - switch(phase) - { - case ID_BG_REQUEST_GROUPS: - background_requestNewMessages(); - break; - case ID_BG_REQUEST_UNPROCESSED: - background_processNewMessages(); - break; - case ID_BG_REQUEST_FULLCALC: - background_processFullCalc(); - break; - default: - break; - } - } - return true; -} - - -bool p3IdServiceVEG::background_requestGroups() -{ - std::cerr << "p3IdServiceVEG::background_requestGroups()"; - std::cerr << std::endl; - - // grab all the subscribed groups. - uint32_t token = 0; - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - if (mBgProcessing) - { - std::cerr << "p3IdServiceVEG::background_requestGroups() ERROR Already processing, Skip this cycle"; - std::cerr << std::endl; - return false; - } - - mBgProcessing = true; - mBgPhase = ID_BG_REQUEST_GROUPS; - mBgToken = 0; - } - - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; - std::list groupIds; - - opts.mStatusFilter = RSGXS_GROUP_STATUS_NEWMSG; - opts.mStatusMask = RSGXS_GROUP_STATUS_NEWMSG; - - requestGroupInfo(token, ansType, opts, groupIds); - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - mBgToken = token; - } - - return true; -} - - - -bool p3IdServiceVEG::background_requestNewMessages() -{ - std::cerr << "p3IdServiceVEG::background_requestNewMessages()"; - std::cerr << std::endl; - - std::list modGroupList; - std::list::iterator it; - - std::list groupIds; - uint32_t token = 0; - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - token = mBgToken; - } - - if (!getGroupSummary(token, modGroupList)) - { - std::cerr << "p3IdServiceVEG::background_requestNewMessages() ERROR No Group List"; - std::cerr << std::endl; - background_cleanup(); - return false; - } - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - mBgPhase = ID_BG_REQUEST_UNPROCESSED; - mBgToken = 0; - - /* now we process the modGroupList -> a map so we can use it easily later, and create id list too */ - for(it = modGroupList.begin(); it != modGroupList.end(); it++) - { - setGroupStatus(it->mGroupId, 0, RSGXS_GROUP_STATUS_NEWMSG); - - mBgGroupMap[it->mGroupId] = *it; - groupIds.push_back(it->mGroupId); - } - } - - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; - token = 0; - - opts.mStatusFilter = RSGXS_MSG_STATUS_UNPROCESSED; - opts.mStatusMask = RSGXS_MSG_STATUS_UNPROCESSED; - - requestMsgInfo(token, ansType, opts, groupIds); - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - mBgToken = token; - } - return true; -} - - -bool p3IdServiceVEG::background_processNewMessages() -{ - std::cerr << "p3IdServiceVEG::background_processNewMessages()"; - std::cerr << std::endl; - - std::list newMsgList; - std::list::iterator it; - uint32_t token = 0; - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - token = mBgToken; - } - - if (!getMsgSummary(token, newMsgList)) - { - std::cerr << "p3IdServiceVEG::background_processNewMessages() ERROR No New Msgs"; - std::cerr << std::endl; - background_cleanup(); - return false; - } - - - /* iterate through the msgs.. update the mBgGroupMap with new data, - * and flag these items as modified - so we rewrite them to the db later. - * - * If a message is not an original -> store groupId for requiring full analysis later. - */ - - std::map::iterator mit; - for(it = newMsgList.begin(); it != newMsgList.end(); it++) - { - std::cerr << "p3IdServiceVEG::background_processNewMessages() new MsgId: " << it->mMsgId; - std::cerr << std::endl; - - /* flag each new vote as processed */ - setMessageStatus(it->mMsgId, 0, RSGXS_MSG_STATUS_UNPROCESSED); - - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - mit = mBgGroupMap.find(it->mGroupId); - if (mit == mBgGroupMap.end()) - { - std::cerr << "p3IdServiceVEG::background_processNewMessages() ERROR missing GroupId: "; - std::cerr << it->mGroupId; - std::cerr << std::endl; - - /* error */ - continue; - } - - if (mit->second.mGroupStatus & ID_LOCAL_STATUS_FULL_CALC_FLAG) - { - std::cerr << "p3IdServiceVEG::background_processNewMessages() Group Already marked FULL_CALC"; - std::cerr << std::endl; - - /* already marked */ - continue; - } - - if (it->mMsgId != it->mOrigMsgId) - { - /* - * not original -> hard, redo calc (alt: could substract previous score) - */ - - std::cerr << "p3IdServiceVEG::background_processNewMessages() Update, mark for FULL_CALC"; - std::cerr << std::endl; - - mit->second.mGroupStatus |= ID_LOCAL_STATUS_FULL_CALC_FLAG; - } - else - { - /* - * Try incremental calculation. - * - extract parameters from group. - * - increment, & save back. - * - flag group as modified. - */ - - std::cerr << "p3IdServiceVEG::background_processNewMessages() NewOpt, Try Inc Calc"; - std::cerr << std::endl; - - mit->second.mGroupStatus |= ID_LOCAL_STATUS_INC_CALC_FLAG; - - std::string serviceString; - IdGroupServiceStrData ssData; - - if (!extractIdGroupCache(serviceString, ssData)) - { - /* error */ - std::cerr << "p3IdServiceVEG::background_processNewMessages() ERROR Extracting"; - std::cerr << std::endl; - } - - /* do calcs */ - std::cerr << "p3IdServiceVEG::background_processNewMessages() Extracted: "; - std::cerr << std::endl; - - /* store it back in */ - std::cerr << "p3IdServiceVEG::background_processNewMessages() Stored: "; - std::cerr << std::endl; - - if (!encodeIdGroupCache(serviceString, ssData)) - { - /* error */ - std::cerr << "p3IdServiceVEG::background_processNewMessages() ERROR Storing"; - std::cerr << std::endl; - } - } - } - - - /* now iterate through groups again - * -> update status as we go - * -> record one requiring a full analyssis - */ - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - std::cerr << "p3IdServiceVEG::background_processNewMessages() Checking Groups for Calc Type"; - std::cerr << std::endl; - - for(mit = mBgGroupMap.begin(); mit != mBgGroupMap.end(); mit++) - { - if (mit->second.mGroupStatus & ID_LOCAL_STATUS_FULL_CALC_FLAG) - { - std::cerr << "p3IdServiceVEG::background_processNewMessages() FullCalc for: "; - std::cerr << mit->second.mGroupId; - std::cerr << std::endl; - - mBgFullCalcGroups.push_back(mit->second.mGroupId); - } - else if (mit->second.mGroupStatus & ID_LOCAL_STATUS_INC_CALC_FLAG) - { - std::cerr << "p3IdServiceVEG::background_processNewMessages() IncCalc done for: "; - std::cerr << mit->second.mGroupId; - std::cerr << std::endl; - - /* set Cache */ - setGroupServiceString(mit->second.mGroupId, mit->second.mServiceString); - } - else - { - /* why is it here? error. */ - std::cerr << "p3IdServiceVEG::background_processNewMessages() ERROR for: "; - std::cerr << mit->second.mGroupId; - std::cerr << std::endl; - } - } - } - - return background_FullCalcRequest(); -} - - -bool p3IdServiceVEG::encodeIdGroupCache(std::string &str, const IdGroupServiceStrData &data) -{ - char line[RSGXS_MAX_SERVICE_STRING]; - - snprintf(line, RSGXS_MAX_SERVICE_STRING, "v1 {%s} {Y:%d O:%d %d %f %f R:%d %d %f %f}", - data.pgpId.c_str(), data.ownScore, - data.opinion.count, data.opinion.nullcount, data.opinion.sum, data.opinion.sumsq, - data.reputation.count, data.reputation.nullcount, data.reputation.sum, data.reputation.sumsq); - - str = line; - return true; -} - - -bool p3IdServiceVEG::extractIdGroupCache(std::string &str, IdGroupServiceStrData &data) -{ - char pgpline[RSGXS_MAX_SERVICE_STRING]; - char scoreline[RSGXS_MAX_SERVICE_STRING]; - - uint32_t iOwnScore; - IdRepCumulScore iOpin; - IdRepCumulScore iRep; - - // split into two parts. - if (2 != sscanf(str.c_str(), "v1 {%[^}]} {%[^}]", pgpline, scoreline)) - { - std::cerr << "p3IdServiceVEG::extractIdGroupCache() Failed to extract Two Parts"; - std::cerr << std::endl; - return false; - } - - std::cerr << "p3IdServiceVEG::extractIdGroupCache() pgpline: " << pgpline; - std::cerr << std::endl; - std::cerr << "p3IdServiceVEG::extractIdGroupCache() scoreline: " << scoreline; - std::cerr << std::endl; - - std::string pgptmp = pgpline; - if (pgptmp.length() > 5) - { - std::cerr << "p3IdServiceVEG::extractIdGroupCache() Believe to have pgpId: " << pgptmp; - std::cerr << std::endl; - data.pgpIdKnown = true; - data.pgpId = pgptmp; - } - else - { - std::cerr << "p3IdServiceVEG::extractIdGroupCache() Think pgpId Invalid"; - std::cerr << std::endl; - data.pgpIdKnown = false; - } - - - if (9 == sscanf(scoreline, " Y:%d O:%d %d %lf %lf R:%d %d %lf %lf", &iOwnScore, - &(iOpin.count), &(iOpin.nullcount), &(iOpin.sum), &(iOpin.sumsq), - &(iRep.count), &(iRep.nullcount), &(iRep.sum), &(iRep.sumsq))) - { - data.ownScore = iOwnScore; - data.opinion = iOpin; - data.reputation = iRep; - return true; - } - - std::cerr << "p3IdServiceVEG::extractIdGroupCache() Failed to extract scores"; - std::cerr << std::endl; - - return false; -} - - - -bool p3IdServiceVEG::background_FullCalcRequest() -{ - /* - * grab an GroupId from List. - * - If empty, we are finished. - * - request all latest mesgs - */ - - std::list groupIds; - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - mBgPhase = ID_BG_REQUEST_FULLCALC; - mBgToken = 0; - mBgGroupMap.clear(); - - if (mBgFullCalcGroups.empty()) - { - /* finished! */ - background_cleanup(); - return true; - - } - - groupIds.push_back(mBgFullCalcGroups.front()); - mBgFullCalcGroups.pop_front(); - - } - - /* request the summary info from the parents */ - uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA; - uint32_t token = 0; - RsTokReqOptionsVEG opts; - opts.mOptions = RS_TOKREQOPT_MSG_LATEST; - - requestMsgInfo(token, ansType, opts, groupIds); - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - mBgToken = token; - } - return true; -} - - - - -bool p3IdServiceVEG::background_processFullCalc() -{ - std::cerr << "p3IdServiceVEG::background_processFullCalc()"; - std::cerr << std::endl; - - std::list msgList; - std::list::iterator it; - - RsIdMsg msg; - - bool validmsgs = false; - - /* calc variables */ - uint32_t opinion_count = 0; - uint32_t opinion_nullcount = 0; - double opinion_sum = 0; - double opinion_sumsq = 0; - - uint32_t rep_count = 0; - uint32_t rep_nullcount = 0; - double rep_sum = 0; - double rep_sumsq = 0; - - while(getMsgData(mBgToken, msg)) - { - std::cerr << "p3IdServiceVEG::background_processFullCalc() Msg:"; - std::cerr << msg; - std::cerr << std::endl; - - validmsgs = true; - - /* for each msg ... extract score, and reputation */ - if (msg.mOpinion != 0) - { - opinion_count++; - opinion_sum += msg.mOpinion; - opinion_sum += (msg.mOpinion * msg.mOpinion); - } - else - { - opinion_nullcount++; - } - - - /* for each msg ... extract score, and reputation */ - if (msg.mReputation != 0) - { - rep_nullcount++; - rep_sum += msg.mReputation; - rep_sum += (msg.mReputation * msg.mReputation); - } - else - { - rep_nullcount++; - } - } - - double opinion_avg = 0; - double opinion_var = 0; - double opinion_frac = 0; - - double rep_avg = 0; - double rep_var = 0; - double rep_frac = 0; - - - if (opinion_count) - { - opinion_avg = opinion_sum / opinion_count; - opinion_var = (opinion_sumsq - opinion_count * opinion_avg * opinion_avg) / opinion_count; - opinion_frac = opinion_count / ((float) (opinion_count + opinion_nullcount)); - } - - if (rep_count) - { - rep_avg = rep_sum / rep_count; - rep_var = (rep_sumsq - rep_count * rep_avg * rep_avg) / rep_count; - rep_frac = rep_count / ((float) (rep_count + rep_nullcount)); - } - - - if (validmsgs) - { - std::string groupId = msg.mMeta.mGroupId; - - std::string serviceString; - IdGroupServiceStrData ssData; - - - if (!encodeIdGroupCache(serviceString, ssData)) - { - std::cerr << "p3IdServiceVEG::background_updateVoteCounts() Failed to encode Votes"; - std::cerr << std::endl; - } - else - { - std::cerr << "p3IdServiceVEG::background_updateVoteCounts() Encoded String: " << serviceString; - std::cerr << std::endl; - /* store new result */ - setGroupServiceString(it->mMsgId, serviceString); - } - } - - { - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - mBgPhase = ID_BG_IDLE; - mBgToken = 0; - } - - return background_FullCalcRequest(); -} - - -bool p3IdServiceVEG::background_cleanup() -{ - std::cerr << "p3IdServiceVEG::background_cleanup()"; - std::cerr << std::endl; - - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - // Cleanup. - mBgProcessing = false; - mBgPhase = ID_BG_IDLE; - mBgToken = 0; - mBgGroupMap.clear(); - mBgFullCalcGroups.clear(); - - return true; -} - - -std::ostream &operator<<(std::ostream &out, const RsIdGroup &grp) -{ - out << "RsIdGroup: Meta: " << grp.mMeta; - out << " IdType: " << grp.mIdType << " GpgIdHash: " << grp.mGpgIdHash; - out << "(((Unusable: ( GpgIdKnown: " << grp.mGpgIdKnown << " GpgId: " << grp.mGpgId; - out << " GpgName: " << grp.mGpgName << " GpgEmail: " << grp.mGpgEmail << ") )))"; - out << std::endl; - - return out; -} - -std::ostream &operator<<(std::ostream &out, const RsIdMsg &msg) -{ - out << "RsIdMsg: Meta: " << msg.mMeta; - //out << " IdType: " << grp.mIdType << " GpgIdHash: " << grp.mGpgIdHash; - out << std::endl; - - return out; -} - diff --git a/libretroshare/src/services/p3idserviceVEG.h b/libretroshare/src/services/p3idserviceVEG.h deleted file mode 100644 index d0618b1d4..000000000 --- a/libretroshare/src/services/p3idserviceVEG.h +++ /dev/null @@ -1,186 +0,0 @@ -/* - * libretroshare/src/services: p3idservice.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 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_IDENTITY_SERVICE_VEG_HEADER -#define P3_IDENTITY_SERVICE_VEG_HEADER - -#include "services/p3service.h" -#include "services/p3gxsserviceVEG.h" - -#include "retroshare/rsidentityVEG.h" - -#include -#include - -/* - * Identity Service - * - */ - -class IdDataProxy: public GxsDataProxyVEG -{ - public: - - bool getGroup(const std::string &id, RsIdGroup &group); - bool getMsg(const std::string &id, RsIdMsg &msg); - - bool addGroup(const RsIdGroup &group); - bool addMsg(const RsIdMsg &msg); - - /* These Functions must be overloaded to complete the service */ -virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta); -virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta); -}; - - - -// INTERNAL DATA TYPES... -// Describes data stored in GroupServiceString. -class IdRepCumulScore -{ -public: - uint32_t count; - uint32_t nullcount; - double sum; - double sumsq; - - // derived parameters: -}; - - -class IdGroupServiceStrData -{ -public: - IdGroupServiceStrData() { pgpIdKnown = false; } - bool pgpIdKnown; - std::string pgpId; - - uint32_t ownScore; - IdRepCumulScore opinion; - IdRepCumulScore reputation; - -}; - -#define ID_LOCAL_STATUS_FULL_CALC_FLAG 0x00010000 -#define ID_LOCAL_STATUS_INC_CALC_FLAG 0x00020000 - -class p3IdServiceVEG: public p3GxsDataServiceVEG, public RsIdentityVEG -{ - public: - - p3IdServiceVEG(uint16_t type); - -virtual int tick(); - - public: - - - /* changed? */ -virtual bool updated(); - - /* From RsTokenService */ - /* Data Requests */ -virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds); - - /* Generic Lists */ -virtual bool getGroupList( const uint32_t &token, std::list &groupIds); -virtual bool getMsgList( const uint32_t &token, std::list &msgIds); - - /* Generic Summary */ -virtual bool getGroupSummary( const uint32_t &token, std::list &groupInfo); -virtual bool getMsgSummary( const uint32_t &token, std::list &msgInfo); - - /* Actual Data -> specific to Interface */ -virtual bool getGroupData(const uint32_t &token, RsIdGroup &group); -virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg); - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token); - - /* Cancel Request */ -virtual bool cancelRequest(const uint32_t &token); - - ////////////////////////////////////////////////////////////////////////////// -virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); -virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); -virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); - -virtual bool groupRestoreKeys(const std::string &groupId); -virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - -virtual bool createGroup(uint32_t &token, RsIdGroup &group, bool isNew); -virtual bool createMsg(uint32_t &token, RsIdMsg &msg, bool isNew); - - - private: - -virtual void generateDummyData(); - -std::string genRandomId(); - - int background_tick(); - bool background_checkTokenRequest(); - bool background_requestGroups(); - bool background_requestNewMessages(); - bool background_processNewMessages(); - bool background_FullCalcRequest(); - bool background_processFullCalc(); - - bool background_cleanup(); - - bool encodeIdGroupCache(std::string &str, const IdGroupServiceStrData &data); - bool extractIdGroupCache(std::string &str, IdGroupServiceStrData &data); - - IdDataProxy *mIdProxy; - - RsMutex mIdMtx; - - /***** below here is locked *****/ - bool mLastBgCheck; - bool mBgProcessing; - - uint32_t mBgToken; - uint32_t mBgPhase; - - std::map mBgGroupMap; - std::list mBgFullCalcGroups; - - - bool mUpdated; - -#if 0 - std::map mIds; - std::map > mOpinions; - - std::map mReputations; // this is created locally. -#endif - -}; - -#endif diff --git a/libretroshare/src/services/p3wiki.cc b/libretroshare/src/services/p3wiki.cc index 29cc0200e..9b3f01aa4 100644 --- a/libretroshare/src/services/p3wiki.cc +++ b/libretroshare/src/services/p3wiki.cc @@ -7,7 +7,7 @@ * * 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. + * 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 diff --git a/libretroshare/src/services/p3wiki.h b/libretroshare/src/services/p3wiki.h index 01d82767e..5700563bc 100644 --- a/libretroshare/src/services/p3wiki.h +++ b/libretroshare/src/services/p3wiki.h @@ -7,7 +7,7 @@ * * 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. + * 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 diff --git a/libretroshare/src/services/p3wikiserviceVEG.cc b/libretroshare/src/services/p3wikiserviceVEG.cc deleted file mode 100644 index dc0a1f7b9..000000000 --- a/libretroshare/src/services/p3wikiserviceVEG.cc +++ /dev/null @@ -1,595 +0,0 @@ -/* - * libretroshare/src/services p3wikiservice.cc - * - * Wiki 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 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 "services/p3wikiserviceVEG.h" - -#include "util/rsrandom.h" - -/**** - * #define WIKI_DEBUG 1 - ****/ - -RsWikiVEG *rsWikiVEG = NULL; - - -/********************************************************************************/ -/******************* Startup / Tick ******************************************/ -/********************************************************************************/ - -p3WikiServiceVEG::p3WikiServiceVEG(uint16_t type) - :p3GxsDataServiceVEG(type, new WikiDataProxy()), mWikiMtx("p3WikiService"), mUpdated(true) -{ - RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ - - mWikiProxy = (WikiDataProxy *) mProxy; - return; -} - - -int p3WikiServiceVEG::tick() -{ - //std::cerr << "p3WikiServiceVEG::tick()"; - //std::cerr << std::endl; - - fakeprocessrequests(); - - return 0; -} - -bool p3WikiServiceVEG::updated() -{ - RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ - - if (mUpdated) - { - mUpdated = false; - return true; - } - return false; -} - - - - /* Data Requests */ -bool p3WikiServiceVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3WikiServiceVEG::requestGroupInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - return true; -} - -bool p3WikiServiceVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3WikiServiceVEG::requestMsgInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds); - - return true; -} - -bool p3WikiServiceVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds) -{ - generateToken(token); - std::cerr << "p3WikiServiceVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - /* Generic Lists */ -bool p3WikiServiceVEG::getGroupList( const uint32_t &token, std::list &groupIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3WikiServiceVEG::getGroupList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3WikiServiceVEG::getGroupList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WikiServiceVEG::getGroupList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - - -bool p3WikiServiceVEG::getMsgList( const uint32_t &token, std::list &msgIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3WikiServiceVEG::getMsgList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3WikiServiceVEG::getMsgList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WikiServiceVEG::getMsgList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - /* Generic Summary */ -bool p3WikiServiceVEG::getGroupSummary( const uint32_t &token, std::list &groupInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WikiServiceVEG::getGroupSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list groupIds; - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsGroupMetaData */ - mProxy->getGroupSummary(groupIds, groupInfo); - - return ans; -} - -bool p3WikiServiceVEG::getMsgSummary( const uint32_t &token, std::list &msgInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WikiServiceVEG::getMsgSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list msgIds; - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsMsgMetaData */ - mProxy->getMsgSummary(msgIds, msgInfo); - - return ans; -} - - - /* Specific Service Data */ -bool p3WikiServiceVEG::getGroupData(const uint32_t &token, RsWikiGroup &group) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3WikiServiceVEG::getGroupData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3WikiServiceVEG::getGroupData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WikiServiceVEG::getGroupData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsWikiAlbum */ - bool ans = mWikiProxy->getGroup(id, group); - return ans; -} - - -bool p3WikiServiceVEG::getMsgData(const uint32_t &token, RsWikiPage &page) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3WikiServiceVEG::getMsgData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3WikiServiceVEG::getMsgData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WikiServiceVEG::getMsgData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsWikiAlbum */ - bool ans = mWikiProxy->getPage(id, page); - return ans; -} - - - - /* Poll */ -uint32_t p3WikiServiceVEG::requestStatus(const uint32_t token) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - return status; -} - - - /* Cancel Request */ -bool p3WikiServiceVEG::cancelRequest(const uint32_t &token) -{ - return clearRequest(token); -} - - - ////////////////////////////////////////////////////////////////////////////// -bool p3WikiServiceVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) -{ - return mWikiProxy->setMessageStatus(msgId, status, statusMask); -} - -bool p3WikiServiceVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) -{ - return mWikiProxy->setGroupStatus(groupId, status, statusMask); -} - -bool p3WikiServiceVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) -{ - return mWikiProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); -} - -bool p3WikiServiceVEG::setMessageServiceString(const std::string &msgId, const std::string &str) -{ - return mWikiProxy->setMessageServiceString(msgId, str); -} - -bool p3WikiServiceVEG::setGroupServiceString(const std::string &grpId, const std::string &str) -{ - return mWikiProxy->setGroupServiceString(grpId, str); -} - - -bool p3WikiServiceVEG::groupRestoreKeys(const std::string &groupId) -{ - return false; -} - -bool p3WikiServiceVEG::groupShareKeys(const std::string &groupId, std::list& peers) -{ - return false; -} - - -/********************************************************************************************/ - - -std::string p3WikiServiceVEG::genRandomId() -{ - std::string randomId; - for(int i = 0; i < 20; i++) - { - randomId += (char) ('a' + (RSRandom::random_u32() % 26)); - } - - return randomId; -} - -bool p3WikiServiceVEG::createGroup(uint32_t &token, RsWikiGroup &group, bool isNew) -{ - if (group.mMeta.mGroupId.empty()) - { - /* new photo */ - - /* generate a temp id */ - group.mMeta.mGroupId = genRandomId(); - } - else - { - std::cerr << "p3WikiServiceVEG::createGroup() Group with existing Id... dropping"; - std::cerr << std::endl; - return false; - } - - { - RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mWikiProxy->addGroup(group); - } - - // Fake a request to return the GroupMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list groupIds; - groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. - - std::cerr << "p3WikiServiceVEG::createGroup() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - return true; -} - - - -bool p3WikiServiceVEG::createPage(uint32_t &token, RsWikiPage &page, bool isNew) -{ - if (page.mMeta.mGroupId.empty()) - { - /* new photo */ - std::cerr << "p3WikiServiceVEG::createPage() Missing PageID"; - std::cerr << std::endl; - return false; - } - - /* check if its a mod or new page */ - if (page.mMeta.mOrigMsgId.empty()) - { - std::cerr << "p3WikiServiceVEG::createPage() New Page"; - std::cerr << std::endl; - - /* new page, generate a new OrigPageId */ - page.mMeta.mOrigMsgId = genRandomId(); - page.mMeta.mMsgId = page.mMeta.mOrigMsgId; - } - else - { - std::cerr << "p3WikiServiceVEG::createPage() Modified Page"; - std::cerr << std::endl; - - /* mod page, keep orig page id, generate a new PageId */ - page.mMeta.mMsgId = genRandomId(); - } - - std::cerr << "p3WikiServiceVEG::createPage() GroupId: " << page.mMeta.mGroupId; - std::cerr << std::endl; - std::cerr << "p3WikiServiceVEG::createPage() PageId: " << page.mMeta.mMsgId; - std::cerr << std::endl; - std::cerr << "p3WikiServiceVEG::createPage() OrigPageId: " << page.mMeta.mOrigMsgId; - std::cerr << std::endl; - - { - RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mWikiProxy->addPage(page); - } - - // Fake a request to return the MsgMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list msgIds; - msgIds.push_back(page.mMeta.mMsgId); // It will just return this one. - - std::cerr << "p3WikiServiceVEG::createPage() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - - -/********************************************************************************************/ - - - -bool WikiDataProxy::getGroup(const std::string &id, RsWikiGroup &group) -{ - void *groupData = NULL; - RsGroupMetaData meta; - if (getGroupData(id, groupData) && getGroupSummary(id, meta)) - { - RsWikiGroup *pG = (RsWikiGroup *) groupData; - group = *pG; - - // update definitive version of the metadata. - group.mMeta = meta; - - std::cerr << "WikiDataProxy::getGroup() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << groupData; - std::cerr << std::endl; - return true; - } - - std::cerr << "WikiDataProxy::getGroup() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool WikiDataProxy::getPage(const std::string &id, RsWikiPage &page) -{ - void *msgData = NULL; - RsMsgMetaData meta; - if (getMsgData(id, msgData) && getMsgSummary(id, meta)) - { - RsWikiPage *pP = (RsWikiPage *) msgData; - // Shallow copy of thumbnail. - page = *pP; - - // update definitive version of the metadata. - page.mMeta = meta; - - std::cerr << "WikiDataProxy::getPage() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << msgData; - std::cerr << std::endl; - return true; - } - - std::cerr << "WikiDataProxy::getPage() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool WikiDataProxy::addGroup(const RsWikiGroup &group) -{ - // Make duplicate. - RsWikiGroup *pG = new RsWikiGroup(); - *pG = group; - - std::cerr << "WikiDataProxy::addGroup()"; - std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG; - std::cerr << std::endl; - - return createGroup(pG); -} - - -bool WikiDataProxy::addPage(const RsWikiPage &page) -{ - // Make duplicate. - RsWikiPage *pP = new RsWikiPage(); - *pP = page; - - std::cerr << "WikiDataProxy::addPage()"; - std::cerr << " MetaData: " << pP->mMeta << " DataPointer: " << pP; - std::cerr << std::endl; - - return createMsg(pP); -} - - - - /* These Functions must be overloaded to complete the service */ -bool WikiDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta) -{ - RsWikiGroup *group = (RsWikiGroup *) groupData; - meta = group->mMeta; - - return true; -} - -bool WikiDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta) -{ - RsWikiPage *page = (RsWikiPage *) msgData; - meta = page->mMeta; - - return true; -} diff --git a/libretroshare/src/services/p3wikiserviceVEG.h b/libretroshare/src/services/p3wikiserviceVEG.h deleted file mode 100644 index f172f4d3f..000000000 --- a/libretroshare/src/services/p3wikiserviceVEG.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * libretroshare/src/services: p3wikiservice.h - * - * Wiki 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 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_WIKI_SERVICE_VEG_HEADER -#define P3_WIKI_SERVICE_VEG_HEADER - -#include "services/p3gxsserviceVEG.h" -#include "retroshare/rswikiVEG.h" - -#include -#include - -/* - * Wiki Service - * - * This is an example service for the new cache system. - * For the moment, it will only hold data passed to it from the GUI. - * and spew that back when asked.... - * - * We are doing it like this - so we can check the required interface functionality. - * - * Expect it won't take long before it'll be properly linked into the backend! - * - * This will be transformed into a Plugin Service, once the basics have been worked out. - * - */ - -class WikiDataProxy: public GxsDataProxyVEG -{ - public: - - bool getGroup(const std::string &id, RsWikiGroup &group); - bool getPage(const std::string &id, RsWikiPage &wiki); - - bool addGroup(const RsWikiGroup &group); - bool addPage(const RsWikiPage &page); - - /* These Functions must be overloaded to complete the service */ -virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta); -virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta); -}; - - -class p3WikiServiceVEG: public p3GxsDataServiceVEG, public RsWikiVEG -{ - public: - - p3WikiServiceVEG(uint16_t type); - -virtual int tick(); - - public: - - -virtual bool updated(); - - /* Data Requests */ -virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds); - - /* Generic Lists */ -virtual bool getGroupList( const uint32_t &token, std::list &groupIds); -virtual bool getMsgList( const uint32_t &token, std::list &msgIds); - - /* Generic Summary */ -virtual bool getGroupSummary( const uint32_t &token, std::list &groupInfo); -virtual bool getMsgSummary( const uint32_t &token, std::list &msgInfo); - - /* Actual Data -> specific to Interface */ - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group); -virtual bool getMsgData(const uint32_t &token, RsWikiPage &page); - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token); - - /* Cancel Request */ -virtual bool cancelRequest(const uint32_t &token); - - ////////////////////////////////////////////////////////////////////////////// -virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); -virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); -virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); - -virtual bool groupRestoreKeys(const std::string &groupId); -virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - -virtual bool createGroup(uint32_t &token, RsWikiGroup &group, bool isNew); -virtual bool createPage(uint32_t &token, RsWikiPage &page, bool isNew); - - private: - -std::string genRandomId(); - - WikiDataProxy *mWikiProxy; - - RsMutex mWikiMtx; - - bool mUpdated; - - -}; - -#endif diff --git a/libretroshare/src/services/p3wire.cc b/libretroshare/src/services/p3wire.cc new file mode 100644 index 000000000..a25fe9112 --- /dev/null +++ b/libretroshare/src/services/p3wire.cc @@ -0,0 +1,207 @@ +/* + * libretroshare/src/services p3wire.cc + * + * Wire 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". + * + */ + +#include "services/p3wire.h" +#include "serialiser/rswireitems.h" + +#include "util/rsrandom.h" + +/**** + * #define WIRE_DEBUG 1 + ****/ + +RsWire *rsWire = NULL; + + +p3Wire::p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes) + :RsGenExchange(gds, nes, new RsGxsWireSerialiser(), RS_SERVICE_GXSV1_TYPE_WIRE), RsWire(this), mWireMtx("WireMtx") +{ + +} + +void p3Wire::service_tick() +{ + return; +} + + +void p3Wire::notifyChanges(std::vector& changes) +{ + std::cerr << "p3Wire::notifyChanges() New stuff"; + std::cerr << std::endl; + + receiveChanges(changes); +} + + /* Specific Service Data */ +bool p3Wire::getGroupData(const uint32_t &token, std::vector &groups) +{ + std::cerr << "p3Wire::getGroupData()"; + std::cerr << std::endl; + + std::vector grpData; + bool ok = RsGenExchange::getGroupData(token, grpData); + + if(ok) + { + std::vector::iterator vit = grpData.begin(); + + for(; vit != grpData.end(); vit++) + { + RsGxsWireGroupItem* item = dynamic_cast(*vit); + + if (item) + { + RsWireGroup group = item->group; + group.mMeta = item->meta; + delete item; + groups.push_back(group); + + std::cerr << "p3Wire::getGroupData() Adding WireGroup to Vector: "; + std::cerr << std::endl; + std::cerr << group; + std::cerr << std::endl; + } + else + { + std::cerr << "Not a WireGroupItem, deleting!" << std::endl; + delete *vit; + } + + } + } + return ok; +} + + +bool p3Wire::getPulseData(const uint32_t &token, std::vector &pulses) +{ + GxsMsgDataMap msgData; + bool ok = RsGenExchange::getMsgData(token, msgData); + + if(ok) + { + GxsMsgDataMap::iterator mit = msgData.begin(); + + for(; mit != msgData.end(); mit++) + { + RsGxsGroupId grpId = mit->first; + std::vector& msgItems = mit->second; + std::vector::iterator vit = msgItems.begin(); + + for(; vit != msgItems.end(); vit++) + { + RsGxsWirePulseItem* item = dynamic_cast(*vit); + + if(item) + { + RsWirePulse pulse = item->pulse; + pulse.mMeta = item->meta; + pulses.push_back(pulse); + delete item; + } + else + { + std::cerr << "Not a WikiPulse Item, deleting!" << std::endl; + delete *vit; + } + } + } + } + return ok; +} + + +bool p3Wire::createGroup(uint32_t &token, RsWireGroup &group) +{ + RsGxsWireGroupItem* groupItem = new RsGxsWireGroupItem(); + groupItem->group = group; + groupItem->meta = group.mMeta; + + std::cerr << "p3Wire::createGroup(): "; + std::cerr << std::endl; + std::cerr << group; + std::cerr << std::endl; + + std::cerr << "p3Wire::createGroup() pushing to RsGenExchange"; + std::cerr << std::endl; + + RsGenExchange::publishGroup(token, groupItem); + return true; +} + + +bool p3Wire::createPulse(uint32_t &token, RsWirePulse &pulse) +{ + std::cerr << "p3Wire::createPulse(): " << pulse; + std::cerr << std::endl; + + RsGxsWirePulseItem* pulseItem = new RsGxsWirePulseItem(); + pulseItem->pulse = pulse; + pulseItem->meta = pulse.mMeta; + + RsGenExchange::publishMsg(token, pulseItem); + return true; +} + + +std::ostream &operator<<(std::ostream &out, const RsWireGroup &group) +{ + out << "RsWireGroup [ "; + out << " Name: " << group.mMeta.mGroupName; + out << " Desc: " << group.mDescription; + //out << " Category: " << group.mCategory; + out << " ]"; + return out; +} + +std::ostream &operator<<(std::ostream &out, const RsWirePulse &pulse) +{ + out << "RsWirePulse [ "; + out << "Title: " << pulse.mMeta.mMsgName; + out << "PulseText: " << pulse.mPulseText; + out << "]"; + return out; +} + +/***** FOR TESTING *****/ + +std::string p3Wire::genRandomId() +{ + std::string randomId; + for(int i = 0; i < 20; i++) + { + randomId += (char) ('a' + (RSRandom::random_u32() % 26)); + } + + return randomId; +} + +void p3Wire::generateDummyData() +{ + +} + + diff --git a/libretroshare/src/services/p3wire.h b/libretroshare/src/services/p3wire.h new file mode 100644 index 000000000..8d93961e8 --- /dev/null +++ b/libretroshare/src/services/p3wire.h @@ -0,0 +1,71 @@ +/* + * libretroshare/src/services: p3wire.h + * + * Wiki 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_WIRE_SERVICE_HEADER +#define P3_WIRE_SERVICE_HEADER + +#include "retroshare/rswire.h" +#include "gxs/rsgenexchange.h" + +#include +#include + +/* + * Wiki Service + * + * + */ + +class p3Wire: public RsGenExchange, public RsWire +{ +public: + p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes); + +protected: + +virtual void notifyChanges(std::vector& changes) ; + +public: + +virtual void service_tick(); + + /* Specific Service Data */ +virtual bool getGroupData(const uint32_t &token, std::vector &groups); +virtual bool getPulseData(const uint32_t &token, std::vector &pulses); + +virtual bool createGroup(uint32_t &token, RsWireGroup &group); +virtual bool createPulse(uint32_t &token, RsWirePulse &pulse); + + private: + +virtual void generateDummyData(); +std::string genRandomId(); + + RsMutex mWireMtx; + + +}; + +#endif diff --git a/libretroshare/src/services/p3wireVEG.cc b/libretroshare/src/services/p3wireVEG.cc deleted file mode 100644 index 3aec51a0a..000000000 --- a/libretroshare/src/services/p3wireVEG.cc +++ /dev/null @@ -1,939 +0,0 @@ -/* - * libretroshare/src/services p3wire.cc - * - * Wire 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". - * - */ - -#include "services/p3wireVEG.h" - -#include "util/rsrandom.h" - -/**** - * #define WIKI_DEBUG 1 - ****/ - -RsWireVEG *rsWireVEG = NULL; - - -/********************************************************************************/ -/******************* Startup / Tick ******************************************/ -/********************************************************************************/ - -p3WireVEG::p3WireVEG(uint16_t type) - :p3GxsDataServiceVEG(type, new WireDataProxy()), mWireMtx("p3Wire"), mUpdated(true) -{ - RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ - - mWireProxy = (WireDataProxy *) mProxy; - return; -} - - -int p3WireVEG::tick() -{ - //std::cerr << "p3WireVEG::tick()"; - //std::cerr << std::endl; - - fakeprocessrequests(); - - return 0; -} - -bool p3WireVEG::updated() -{ - RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ - - if (mUpdated) - { - mUpdated = false; - return true; - } - return false; -} - - - - /* Data Requests */ -bool p3WireVEG::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3WireVEG::requestGroupInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - return true; -} - -bool p3WireVEG::requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds) -{ - generateToken(token); - std::cerr << "p3WireVEG::requestMsgInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGS, groupIds); - - return true; -} - -bool p3WireVEG::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds) -{ - generateToken(token); - std::cerr << "p3WireVEG::requestMsgRelatedInfo() gets Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - /* Generic Lists */ -bool p3WireVEG::getGroupList( const uint32_t &token, std::list &groupIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3WireVEG::getGroupList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3WireVEG::getGroupList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WireVEG::getGroupList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - - -bool p3WireVEG::getMsgList( const uint32_t &token, std::list &msgIds) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_LIST) - { - std::cerr << "p3WireVEG::getMsgList() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3WireVEG::getMsgList() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WireVEG::getMsgList() ERROR Status Incomplete" << std::endl; - return false; - } - - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - return ans; -} - - - /* Generic Summary */ -bool p3WireVEG::getGroupSummary( const uint32_t &token, std::list &groupInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3WireVEG::getGroupSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3WireVEG::getGroupSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WireVEG::getGroupSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list groupIds; - bool ans = loadRequestOutList(token, groupIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsGroupMetaData */ - mProxy->getGroupSummary(groupIds, groupInfo); - - return ans; -} - -bool p3WireVEG::getMsgSummary( const uint32_t &token, std::list &msgInfo) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - if (anstype != RS_TOKREQ_ANSTYPE_SUMMARY) - { - std::cerr << "p3WireVEG::getMsgSummary() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3WireVEG::getMsgSummary() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WireVEG::getMsgSummary() ERROR Status Incomplete" << std::endl; - return false; - } - - std::list msgIds; - bool ans = loadRequestOutList(token, msgIds); - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - - /* convert to RsMsgMetaData */ - mProxy->getMsgSummary(msgIds, msgInfo); - - return ans; -} - - - /* Specific Service Data */ -bool p3WireVEG::getGroupData(const uint32_t &token, RsWireGroup &group) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3WireVEG::getGroupData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if (reqtype != GXS_REQUEST_TYPE_GROUPS) - { - std::cerr << "p3WireVEG::getGroupData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WireVEG::getGroupData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsWireGroup */ - bool ans = mWireProxy->getGroup(id, group); - return ans; -} - - -bool p3WireVEG::getMsgData(const uint32_t &token, RsWirePulse &pulse) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - - if (anstype != RS_TOKREQ_ANSTYPE_DATA) - { - std::cerr << "p3WireVEG::getMsgData() ERROR AnsType Wrong" << std::endl; - return false; - } - - if ((reqtype != GXS_REQUEST_TYPE_MSGS) && (reqtype != GXS_REQUEST_TYPE_MSGRELATED)) - { - std::cerr << "p3WireVEG::getMsgData() ERROR ReqType Wrong" << std::endl; - return false; - } - - if (status != GXS_REQUEST_STATUS_COMPLETE) - { - std::cerr << "p3WireVEG::getMsgData() ERROR Status Incomplete" << std::endl; - return false; - } - - std::string id; - if (!popRequestOutList(token, id)) - { - /* finished */ - updateRequestStatus(token, GXS_REQUEST_STATUS_DONE); - return false; - } - - /* convert to RsWirePulse */ - bool ans = mWireProxy->getPulse(id, pulse); - return ans; -} - - - - /* Poll */ -uint32_t p3WireVEG::requestStatus(const uint32_t token) -{ - uint32_t status; - uint32_t reqtype; - uint32_t anstype; - time_t ts; - checkRequestStatus(token, status, reqtype, anstype, ts); - - return status; -} - - - /* Cancel Request */ -bool p3WireVEG::cancelRequest(const uint32_t &token) -{ - return clearRequest(token); -} - - ////////////////////////////////////////////////////////////////////////////// - -bool p3WireVEG::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) -{ - return mWireProxy->setMessageStatus(msgId, status, statusMask); -} - - -bool p3WireVEG::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) -{ - return mWireProxy->setGroupStatus(groupId, status, statusMask); -} - -bool p3WireVEG::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) -{ - return mWireProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); -} - -bool p3WireVEG::setMessageServiceString(const std::string &msgId, const std::string &str) -{ - return mWireProxy->setMessageServiceString(msgId, str); -} - -bool p3WireVEG::setGroupServiceString(const std::string &grpId, const std::string &str) -{ - return mWireProxy->setGroupServiceString(grpId, str); -} - - -bool p3WireVEG::groupRestoreKeys(const std::string &groupId) -{ - return false; -} - -bool p3WireVEG::groupShareKeys(const std::string &groupId, std::list& peers) -{ - return false; -} - - -/********************************************************************************************/ - - -std::string p3WireVEG::genRandomId() -{ - std::string randomId; - for(int i = 0; i < 20; i++) - { - randomId += (char) ('a' + (RSRandom::random_u32() % 26)); - } - - return randomId; -} - - -bool p3WireVEG::createGroup(uint32_t &token, RsWireGroup &group, bool isNew) -{ - if (group.mMeta.mGroupId.empty()) - { - /* new photo */ - - /* generate a temp id */ - group.mMeta.mGroupId = genRandomId(); - } - else - { - std::cerr << "p3WireVEG::createGroup() Group with existing Id... dropping"; - std::cerr << std::endl; - return false; - } - - { - RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mWireProxy->addGroup(group); - } - - // Fake a request to return the GroupMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list groupIds; - groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. - - std::cerr << "p3Wiree::createGroup() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - - return true; -} - - - - -bool p3WireVEG::createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew) -{ - if (pulse.mMeta.mGroupId.empty()) - { - /* new photo */ - std::cerr << "p3WireVEG::createPulse() Missing PulseID"; - std::cerr << std::endl; - return false; - } - - /* check if its a mod or new pulse */ - if (pulse.mMeta.mOrigMsgId.empty()) - { - std::cerr << "p3WireVEG::createPulse() New Pulse"; - std::cerr << std::endl; - - /* new pulse, generate a new OrigPulseId */ - pulse.mMeta.mOrigMsgId = genRandomId(); - pulse.mMeta.mMsgId = pulse.mMeta.mOrigMsgId; - } - else - { - std::cerr << "p3WireVEG::createPulse() Modified Pulse"; - std::cerr << std::endl; - - /* mod pulse, keep orig pulse id, generate a new PulseId */ - pulse.mMeta.mMsgId = genRandomId(); - } - - std::cerr << "p3WireVEG::createPulse() GroupId: " << pulse.mMeta.mGroupId; - std::cerr << std::endl; - std::cerr << "p3WireVEG::createPulse() PulseId: " << pulse.mMeta.mMsgId; - std::cerr << std::endl; - std::cerr << "p3WireVEG::createPulse() OrigPulseId: " << pulse.mMeta.mOrigMsgId; - std::cerr << std::endl; - - { - RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - mWireProxy->addPulse(pulse); - } - - // Fake a request to return the MsgMetaData. - generateToken(token); - uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; - RsTokReqOptionsVEG opts; // NULL is good. - std::list msgIds; - msgIds.push_back(pulse.mMeta.mMsgId); // It will just return this one. - - std::cerr << "p3WireVEG::createPulse() Generating Request Token: " << token << std::endl; - storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - - return true; -} - - - -/********************************************************************************************/ - - - -bool WireDataProxy::getGroup(const std::string &id, RsWireGroup &group) -{ - void *groupData = NULL; - RsGroupMetaData meta; - if (getGroupData(id, groupData) && getGroupSummary(id, meta)) - { - RsWireGroup *pG = (RsWireGroup *) groupData; - group = *pG; - - // update definitive version of the metadata. - group.mMeta = meta; - - std::cerr << "WireDataProxy::getGroup() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << groupData; - std::cerr << std::endl; - return true; - } - - std::cerr << "WireDataProxy::getGroup() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool WireDataProxy::getPulse(const std::string &id, RsWirePulse &pulse) -{ - void *msgData = NULL; - RsMsgMetaData meta; - if (getMsgData(id, msgData) && getMsgSummary(id, meta)) - { - RsWirePulse *pP = (RsWirePulse *) msgData; - // Shallow copy of thumbnail. - pulse = *pP; - - // update definitive version of the metadata. - pulse.mMeta = meta; - - std::cerr << "WireDataProxy::getPulse() Id: " << id; - std::cerr << " MetaData: " << meta << " DataPointer: " << msgData; - std::cerr << std::endl; - return true; - } - - std::cerr << "WireDataProxy::getPulse() FAILED Id: " << id; - std::cerr << std::endl; - - return false; -} - -bool WireDataProxy::addGroup(const RsWireGroup &group) -{ - // Make duplicate. - RsWireGroup *pG = new RsWireGroup(); - *pG = group; - - std::cerr << "WireDataProxy::addGroup()"; - std::cerr << " MetaData: " << pG->mMeta << " DataPointer: " << pG; - std::cerr << std::endl; - - return createGroup(pG); -} - - -bool WireDataProxy::addPulse(const RsWirePulse &pulse) -{ - // Make duplicate. - RsWirePulse *pP = new RsWirePulse(); - *pP = pulse; - - std::cerr << "WireDataProxy::addPulse()"; - std::cerr << " MetaData: " << pP->mMeta << " DataPointer: " << pP; - std::cerr << std::endl; - - return createMsg(pP); -} - - - - /* These Functions must be overloaded to complete the service */ -bool WireDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta) -{ - RsWireGroup *group = (RsWireGroup *) groupData; - meta = group->mMeta; - - return true; -} - -bool WireDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta) -{ - RsWirePulse *page = (RsWirePulse *) msgData; - meta = page->mMeta; - - return true; -} - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - - -#if 0 - -bool p3WireVEG::generateDummyData() -{ -#define MAX_GROUPS 100 -#define MAX_POSTS 1000 - -#define MAX_BASE_COMMENTS 1000 //10000 -#define MAX_COMMENTS 4000 //10000 - -#define MAX_VOTES 10000 //10000 - - std::list mGroups; - std::list::iterator git; - - std::list mPosts; - std::list::iterator pit; - - std::list mVotes; - std::list::iterator vit; - - std::list mComments; - std::list::iterator cit; - -#define DUMMY_NAME_MAX_LEN 10000 - char name[DUMMY_NAME_MAX_LEN]; - int i, j; - time_t now = time(NULL); - - for(i = 0; i < MAX_GROUPS; i++) - { - /* generate a new forum */ - RsPostedGroup group; - - snprintf(name, DUMMY_NAME_MAX_LEN, "TestTopic_%d", i+1); - - group.mMeta.mGroupId = genRandomId(); - group.mMeta.mGroupName = name; - - group.mMeta.mPublishTs = now - (RSRandom::random_f32() * 100000); - /* key fields to fill in: - * GroupId. - * Name. - * Flags. - * Pop. - */ - - - - /* use probability to decide which are subscribed / own / popularity. - */ - - float rnd = RSRandom::random_f32(); - if (rnd < 0.1) - { - group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN | RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; - - } - else if (rnd < 0.3) - { - group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; - } - else - { - group.mMeta.mSubscribeFlags = 0; - } - - group.mMeta.mPop = (int) (RSRandom::random_f32() * 10.0); - mGroups.push_back(group); - - } - - for(i = 0; i < MAX_POSTS; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsPostedGroup head = mGroups.front(); - mGroups.pop_front(); - mGroups.push_back(head); - } - - RsPostedGroup group = mGroups.front(); - - /* now create a new thread */ - - RsPostedPost post; - - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Post_%d", group.mMeta.mGroupName.c_str(), i+1); - post.mMeta.mMsgName = name; - - post.mMeta.mGroupId = group.mMeta.mGroupId; - post.mMeta.mMsgId = genRandomId(); - post.mMeta.mOrigMsgId = post.mMeta.mMsgId; - post.mMeta.mThreadId = post.mMeta.mMsgId; - post.mMeta.mParentId = ""; - - post.mMeta.mPublishTs = group.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (post.mMeta.mPublishTs > now) - post.mMeta.mPublishTs = now - 1; - - mPosts.push_back(post); - - } - - for(i = 0; i < MAX_BASE_COMMENTS; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsPostedPost head = mPosts.front(); - mPosts.pop_front(); - mPosts.push_back(head); - } - - RsPostedPost parent = mPosts.front(); - - /* now create a new child msg */ - - RsPostedComment comment; - - /* fill in key data - * GroupId - * MsgId - * OrigMsgId - * ThreadId - * ParentId - * PublishTS (take Forum TS + a bit ). - * - * ChildTS ???? - */ - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Comment_%d", parent.mMeta.mMsgName.c_str(), i+1); - comment.mMeta.mMsgName = name; - //comment.mMsg = name; - - comment.mMeta.mGroupId = parent.mMeta.mGroupId; - comment.mMeta.mMsgId = genRandomId(); - comment.mMeta.mOrigMsgId = comment.mMeta.mMsgId; - comment.mMeta.mThreadId = parent.mMeta.mThreadId; - comment.mMeta.mParentId = parent.mMeta.mOrigMsgId; - - comment.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (comment.mMeta.mPublishTs > now) - comment.mMeta.mPublishTs = now - 1; - - mComments.push_back(comment); - } - - - for(i = 0; i < MAX_COMMENTS; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsPostedComment head = mComments.front(); - mComments.pop_front(); - mComments.push_back(head); - } - - RsPostedComment parent = mComments.front(); - - /* now create a new child msg */ - - RsPostedComment comment; - - /* fill in key data - * GroupId - * MsgId - * OrigMsgId - * ThreadId - * ParentId - * PublishTS (take Forum TS + a bit ). - * - * ChildTS ???? - */ - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Comment_%d", parent.mMeta.mMsgName.c_str(), i+1); - comment.mMeta.mMsgName = name; - //comment.mMsg = name; - - comment.mMeta.mGroupId = parent.mMeta.mGroupId; - comment.mMeta.mMsgId = genRandomId(); - comment.mMeta.mOrigMsgId = comment.mMeta.mMsgId; - comment.mMeta.mThreadId = parent.mMeta.mThreadId; - comment.mMeta.mParentId = parent.mMeta.mOrigMsgId; - - comment.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (comment.mMeta.mPublishTs > now) - comment.mMeta.mPublishTs = now - 1; - - mComments.push_back(comment); - } - - - for(i = 0; i < MAX_VOTES; i++) - { - /* generate a base thread */ - - /* rotate the Forum Groups Around, then pick one. - */ - - int rnd = (int) (RSRandom::random_f32() * 10.0); - - for(j = 0; j < rnd; j++) - { - RsPostedPost head = mPosts.front(); - mPosts.pop_front(); - mPosts.push_back(head); - } - - RsPostedPost parent = mPosts.front(); - - /* now create a new child msg */ - - RsPostedVote vote; - - snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Vote_%d", parent.mMeta.mMsgName.c_str(), i+1); - vote.mMeta.mMsgName = name; - //vote.mMsg = name; - - vote.mMeta.mGroupId = parent.mMeta.mGroupId; - vote.mMeta.mMsgId = genRandomId(); - vote.mMeta.mOrigMsgId = vote.mMeta.mMsgId; - vote.mMeta.mThreadId = parent.mMeta.mThreadId; - vote.mMeta.mParentId = parent.mMeta.mOrigMsgId; - - vote.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000); - if (vote.mMeta.mPublishTs > now) - vote.mMeta.mPublishTs = now - 1; - - mVotes.push_back(vote); - } - - - mUpdated = true; - - /* Then - at the end, we push them all into the Proxy */ - for(git = mGroups.begin(); git != mGroups.end(); git++) - { - /* pushback */ - mPostedProxy->addGroup(*git); - - } - - for(pit = mPosts.begin(); pit != mPosts.end(); pit++) - { - /* pushback */ - mPostedProxy->addPost(*pit); - } - - for(cit = mComments.begin(); cit != mComments.end(); cit++) - { - /* pushback */ -#define COMMENT_FRAC_FOR_LATER (0.70) - if (RSRandom::random_f32() > COMMENT_FRAC_FOR_LATER) - { - mPostedProxy->addComment(*cit); - } - else - { - mDummyLaterComments.push_back(*cit); - } - } - - - for(vit = mVotes.begin(); vit != mVotes.end(); vit++) - { - /* pushback */ - -#define VOTE_FRAC_FOR_LATER (0.70) - if (RSRandom::random_f32() > VOTE_FRAC_FOR_LATER) - { - mPostedProxy->addVote(*vit); - } - else - { - mDummyLaterVotes.push_back(*vit); - } - } - - return true; -} - -#define EXTRA_COMMENT_ADD (20) -#define EXTRA_VOTE_ADD (50) - -bool p3PostedService::addExtraDummyData() -{ - std::cerr << "p3PostedService::addExtraDummyData()"; - std::cerr << std::endl; - - int i = 0; - - std::list::iterator vit; - std::list::iterator cit; - - for(cit = mDummyLaterComments.begin(); (cit != mDummyLaterComments.end()) && (i < EXTRA_COMMENT_ADD); i++) - { - mPostedProxy->addComment(*cit); - cit = mDummyLaterComments.erase(cit); - } - - i = 0; - for(vit = mDummyLaterVotes.begin(); (vit != mDummyLaterVotes.end()) && (i < EXTRA_VOTE_ADD); i++) - { - mPostedProxy->addVote(*vit); - vit = mDummyLaterVotes.erase(vit); - } - - return true; -} - -#endif - - diff --git a/libretroshare/src/services/p3wireVEG.h b/libretroshare/src/services/p3wireVEG.h deleted file mode 100644 index b009b116f..000000000 --- a/libretroshare/src/services/p3wireVEG.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * libretroshare/src/services: p3wire.h - * - * Wire 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 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_WIRE_SERVICE_VEG_HEADER -#define P3_WIRE_SERVICE_VEG_HEADER - -#include "services/p3gxsserviceVEG.h" - -#include "retroshare/rswireVEG.h" - -#include -#include - -/* - * Wire Service - * - */ -class WireDataProxy: public GxsDataProxyVEG -{ - public: - - bool getGroup(const std::string &id, RsWireGroup &group); - bool getPulse(const std::string &id, RsWirePulse &pulse); - - bool addGroup(const RsWireGroup &group); - bool addPulse(const RsWirePulse &pulse); - - /* These Functions must be overloaded to complete the service */ -virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta); -virtual bool convertMsgToMetaData(void *msgData, RsMsgMetaData &meta); -}; - - -class p3WireVEG: public p3GxsDataServiceVEG, public RsWireVEG -{ - public: - - p3WireVEG(uint16_t type); - -virtual int tick(); - - public: - - -virtual bool updated(); - - /* Data Requests */ -virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &groupIds); -virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptionsVEG &opts, const std::list &msgIds); - - /* Generic Lists */ -virtual bool getGroupList( const uint32_t &token, std::list &groupIds); -virtual bool getMsgList( const uint32_t &token, std::list &msgIds); - - /* Generic Summary */ -virtual bool getGroupSummary( const uint32_t &token, std::list &groupInfo); -virtual bool getMsgSummary( const uint32_t &token, std::list &msgInfo); - - /* Actual Data -> specific to Interface */ - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsWireGroup &group); -virtual bool getMsgData(const uint32_t &token, RsWirePulse &page); - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token); - - /* Cancel Request */ -virtual bool cancelRequest(const uint32_t &token); - - ////////////////////////////////////////////////////////////////////////////// -virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); -virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); -virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); -virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); - -virtual bool groupRestoreKeys(const std::string &groupId); -virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - -virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew); -virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew); - - private: - -std::string genRandomId(); - - WireDataProxy *mWireProxy; - - RsMutex mWireMtx; - - /***** below here is locked *****/ - - bool mUpdated; - -}; - -#endif